Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major project update and ui fixes #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 0 additions & 72 deletions app/build.gradle

This file was deleted.

74 changes: 74 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("androidx.navigation.safeargs")
}


android {
namespace = "com.mindorks.sample.whatsapp"
compileSdk = 34

defaultConfig {
applicationId = "com.mindorks.sample.whatsapp"
minSdk = 24
targetSdk = 30
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.14"
}
}

dependencies {
implementation(libs.androidx.legacy.support.v4)

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.lifecycle.viewmodel)
implementation(libs.androidx.lifecycle.livedata)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.fragment.ktx)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
implementation(libs.glide)
implementation(libs.androidx.navigation.fragment.ktx)
implementation(libs.androidx.navigation.ui.ktx)
implementation(libs.androidx.runtime.livedata)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)

//Loading images by url
implementation(libs.coil.compose)
}
2 changes: 1 addition & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
# proguardFiles setting in build.gradle.kts.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mindorks.sample.whatsapp.data.local


import com.mindorks.sample.whatsapp.R
import com.mindorks.sample.whatsapp.data.model.Call
import com.mindorks.sample.whatsapp.data.model.Chat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.ui.platform.ComposeView
import androidx.fragment.app.Fragment
import com.mindorks.sample.whatsapp.data.local.addChat
import com.mindorks.sample.whatsapp.data.model.User
import com.mindorks.sample.whatsapp.screen.chat.ui.ChatScreenView
import com.mindorks.sample.whatsapp.ui.WhatsAppTheme

@ExperimentalFoundationApi
class ChatFragment : Fragment() {

class ChatFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
): View {

val userName = arguments?.getString("userName") ?: ""
val userImage = arguments?.getString("userImage") ?: ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.mindorks.sample.whatsapp.screen.chat.ui

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.material.Scaffold
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.mindorks.sample.whatsapp.data.local.chat
import com.mindorks.sample.whatsapp.data.model.User

@ExperimentalFoundationApi

@Composable
fun ChatScreenView(user: User, onBackIconClick: () -> Unit, onMessageSend: (String) -> Unit) {
Scaffold(
bottomBar = { EditText(onMessageSend) },
bottomBar = { ChatTextField(onMessageSend) },
topBar = {
ChatTopBar(user, onBackIconClick)
},
bodyContent = {
ChatsScrollView(chat.toList())
}
content = {
ChatsScrollView(modifier = Modifier.padding(it), chat.toList())
},
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.mindorks.sample.whatsapp.screen.chat.ui


import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.mindorks.sample.whatsapp.R
import com.mindorks.sample.whatsapp.ui.BrightGreen
import com.mindorks.sample.whatsapp.ui.DarkestGreen
import com.mindorks.sample.whatsapp.ui.Gray
import com.mindorks.sample.whatsapp.ui.White
import kotlinx.coroutines.launch


@Composable
fun ChatTextField(onMessageSend: (String) -> Unit) {
val textState = remember { mutableStateOf(TextFieldValue()) }
val scrollState = rememberScrollState()
val scope = rememberCoroutineScope()

Row(
modifier = Modifier
.background(DarkestGreen)
.fillMaxWidth()
.padding(4.dp),
verticalAlignment = Alignment.CenterVertically,
) {
TextField(
value = textState.value,
modifier = Modifier
.clip(RoundedCornerShape(32.dp))
.weight(1f),
onValueChange = {
textState.value = it
},
placeholder = {
Text(text = "Message", color = Gray)
},
colors = TextFieldDefaults.colors(
unfocusedContainerColor = White,
focusedIndicatorColor = Color.Transparent
)
)

Spacer(modifier = Modifier.width(4.dp))

IconButton(
modifier = Modifier
.clip(CircleShape)
.background(BrightGreen),
onClick = {
onMessageSend(textState.value.text)
scope.launch {
scrollState.animateScrollTo(0)
}
},
) {
Icon(
modifier = Modifier.size(24.dp),
painter = painterResource(id = R.drawable.ic_send),
tint = White,
contentDescription = null
)
}
}
}

@Preview
@Composable
private fun ChatTextFieldPreview() {
ChatTextField() {}
}
Loading