Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
robinsrk committed Feb 24, 2023
1 parent db01645 commit 33f1271
Show file tree
Hide file tree
Showing 11 changed files with 237 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.example.buspayment.screens.common.ConductorRegistrationScreen
import com.example.buspayment.screens.common.LoginScreen
import com.example.buspayment.screens.common.SplashScreen
import com.example.buspayment.screens.common.UserRegistrationScreen
import com.example.buspayment.screens.conductor.AllPaymentListScreen
import com.example.buspayment.screens.conductor.ConductorHomeScreen
import com.example.buspayment.screens.conductor.ConductorQRCode
import com.example.buspayment.screens.conductor.PaymentListScreen
Expand Down Expand Up @@ -43,6 +44,12 @@ fun SetupNavGraph(navController: NavHostController) {
) {
UserRegistrationScreen(navController)
}

composable(
route = Screens.allPm.route
) {
AllPaymentListScreen(navController)
}
composable(
route = Screens.regCon.route
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sealed class Screens(val route: String) {
object UHistory : Screens(route = "user_history_screen")
object Login : Screens(route = "login_screen")
object regUser : Screens(route = "register_user_screen")
object allPm : Screens(route = "all_payment_screen")
object regCon : Screens(route = "register_conductor_screen")
object map : Screens(route = "map_screen")
object AHome : Screens(route = "admin_home_screen")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DBRepository @Inject constructor(
}


override fun getConductorPaymentList(email: String): Flow<ResultState<List<RealtimePaymentResponse>>> =
override fun getConductorPaymentList(): Flow<ResultState<List<RealtimePaymentResponse>>> =
callbackFlow {
trySend(ResultState.Loading)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface Repository {
to: String
): Flow<ResultState<String>>

fun getConductorPaymentList(email: String): Flow<ResultState<List<RealtimePaymentResponse>>>
fun getConductorPaymentList(): Flow<ResultState<List<RealtimePaymentResponse>>>
fun getPaymentHistoryByUser(email: String): Flow<ResultState<List<RealtimePaymentResponse>>>
fun updatePayment(email: String, res: RealtimePaymentResponse): Flow<ResultState<String>>
fun deleteUser(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ data class RealtimePaymentResponse(
data class PaymentResponse(
val status: String? = "",
val time: String? = "",
val date: String? = "",
val passNum: Int? = 0,
val fromUser: String? = "",
val toUser: String? = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ class RealtimeViewModel @Inject constructor(
}
}

fun getConductorPaymentList(email: String) {
fun getConductorPaymentList() {
viewModelScope.launch {
repo.getConductorPaymentList(email).collect {
repo.getConductorPaymentList().collect {
when (it) {
is ResultState.Success -> {
_payRes.value = PaymentState(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
@file:OptIn(ExperimentalFoundationApi::class)

package com.example.buspayment.screens.conductor

import android.app.Application
import android.widget.Toast
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.ArrowForward
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Done
import androidx.compose.material.icons.filled.HourglassBottom
import androidx.compose.material3.Card
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import com.example.buspayment.data.User
import com.example.buspayment.data.UserViewModel
import com.example.buspayment.realtimeDB.responses.RealtimePaymentResponse
import com.example.buspayment.realtimeDB.ui.RealtimeViewModel
import com.example.buspayment.utils.ResultState
import kotlinx.coroutines.launch
@Composable
fun AllPaymentListScreen(
navController: NavController,
viewModel: RealtimeViewModel = hiltViewModel()
) {
val res = viewModel.payres.value
val context = LocalContext.current
var total by remember {mutableStateOf(0.0)}
var user by remember { mutableStateOf(listOf<User>()) }
val mUserViewModel: UserViewModel =
viewModel(factory = UserViewModel.UserViewModelFactory(context.applicationContext as Application))
user = mUserViewModel.readUser.observeAsState(emptyList()).value
var email by remember { mutableStateOf("") }
LaunchedEffect(user) {
if (user.isNotEmpty()) {
email = user[0].email
viewModel.getConductorPaymentList()
}

}
Column(Modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally) {
Row(
Modifier
.fillMaxWidth()
.background(Color.Red, RoundedCornerShape(0.dp, 0.dp, 30.dp, 30.dp))
.padding(20.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
Icon(
modifier = Modifier.clickable {
navController.popBackStack()
}, imageVector = Icons.Filled.ArrowBack, contentDescription = "Back button"
)
Text(text = "Pending payments", style = MaterialTheme.typography.headlineSmall)
Text(text = "Total: $total")
}
Column {
if (res.payment.isNotEmpty()) {
val paymentList =
res.payment.filter { item ->
item.payment!!.toUser == email.substringBefore(
"@"
)
}
LazyColumn(reverseLayout = true) {
items(
paymentList,
key = {
it.key!!
}
) { res ->
Card(
modifier = Modifier
.fillMaxWidth()
.padding(10.dp)
) {
Column() {
Row(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.padding(10.dp)
) {
Text(res.payment?.fromUser!!, style = MaterialTheme.typography.bodyLarge)
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(res.payment.date.toString())
Text(res.payment.time.toString())
}

Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(res.payment.paid!!.toString() + " Taka")
Text("${res.payment.from!!} -> ${res.payment.to!!}")
}
when (res.payment.status) {
"Accepted" -> {
Icon(imageVector = Icons.Filled.Done, contentDescription = "Accepted", tint = Color.Green)
}

"Rejected" -> Icon(
imageVector = Icons.Filled.Close,
contentDescription = "Accepted",
tint = Color.Red
)

else -> Icon(
imageVector = Icons.Filled.HourglassBottom,
contentDescription = "Accepted",
)
}
}
}
}
}
}
} else if (res.isLoading) {
CircularProgressIndicator()
}
}
}
}

@Composable
fun AllPaymentListRow(
itemState: RealtimePaymentResponse,
total: Double
) {
// total += itemState.payment!!.paid!!
Card(
modifier = Modifier
.fillMaxWidth()
.padding(10.dp)
) {
Column() {
Row(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.padding(10.dp)
) {
Text(itemState.payment?.fromUser!!, style = MaterialTheme.typography.bodyLarge)
Text(itemState.payment.time.toString())
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(itemState.payment.paid!!.toString() + " Taka")
Text("${itemState.payment.from!!} -> ${itemState.payment.to!!}")
}
when (itemState.payment.status) {
"Accepted" -> {
Icon(imageVector = Icons.Filled.Done, contentDescription = "Accepted", tint = Color.Green)
}

"Rejected" -> Icon(
imageVector = Icons.Filled.Close,
contentDescription = "Accepted",
tint = Color.Red
)

else -> Icon(
imageVector = Icons.Filled.HourglassBottom,
contentDescription = "Accepted",
)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import com.example.buspayment.data.User
import com.example.buspayment.data.UserViewModel
import com.example.buspayment.navigations.Screens
import com.example.buspayment.realtimeDB.responses.RealtimePaymentResponse
import com.example.buspayment.realtimeDB.ui.RealtimeViewModel
import com.example.buspayment.utils.ResultState
Expand All @@ -64,7 +65,7 @@ fun PaymentListScreen(
LaunchedEffect(user) {
if (user.isNotEmpty()) {
email = user[0].email
viewModel.getConductorPaymentList(user[0].email.substringBefore("@"))
viewModel.getConductorPaymentList()
}

}
Expand All @@ -85,7 +86,7 @@ fun PaymentListScreen(
Text(text = "Pending payments", style = MaterialTheme.typography.headlineSmall)
Icon(
modifier = Modifier.clickable {
navController.popBackStack()
navController.navigate(Screens.allPm.route )
}, imageVector = Icons.Filled.ArrowForward, contentDescription = "Back button"
)
}
Expand Down Expand Up @@ -135,7 +136,11 @@ fun PaymentListRow(
.padding(10.dp)
) {
Text(itemState.payment?.fromUser!!, style = MaterialTheme.typography.bodyLarge)
Text(itemState.payment.time.toString())
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(itemState.payment.date.toString())
Text(itemState.payment.time.toString())
}

Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(itemState.payment.paid!!.toString() + " Taka")
Text("${itemState.payment.from!!} -> ${itemState.payment.to!!}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -44,13 +45,17 @@ import com.example.buspayment.data.UserViewModel
import com.example.buspayment.navigations.Screens
import com.example.buspayment.realtimeDB.responses.RealtimeUserResponse
import com.example.buspayment.realtimeDB.ui.RealtimeViewModel
import com.example.buspayment.utils.ResultState
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

@Composable
fun ProfileScreen(
navController: NavController,
viewModel: RealtimeViewModel = hiltViewModel()
) {
val userResponse = viewModel.userRes.value
val scope = rememberCoroutineScope()
val context = LocalContext.current
var email by remember { mutableStateOf("") }
var userName by remember { mutableStateOf("") }
Expand All @@ -64,8 +69,9 @@ fun ProfileScreen(
email = user[0].email
}
LaunchedEffect(user){
if(email.isNotEmpty())
viewModel.getUser(email)
if(email.isNotEmpty()){
viewModel.getUser(email)
}
}
LaunchedEffect(userResponse){
if(userResponse.user.isNotEmpty()){
Expand Down Expand Up @@ -144,7 +150,7 @@ fun ProfileScreen(
Text(text = "Name: ")
OutlinedTextField(
value = userName,
onValueChange = { }
onValueChange = { text -> userName = text }
)
}
Row(
Expand All @@ -170,7 +176,7 @@ fun ProfileScreen(
Text(text = "Phone: ")
OutlinedTextField(
value = phone,
onValueChange = { }
onValueChange = { text -> phone = text }
)
}
Row(
Expand Down Expand Up @@ -200,16 +206,6 @@ fun ProfileScreen(
}
OutlinedButton(
onClick = {
viewModel.updateUser(
RealtimeUserResponse(
RealtimeUserResponse.UserResponse(
userName = userName,
email = email,
userId = id,
phone = phone,
)
)
)
},
Modifier.padding(10.dp)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ fun ScanScreen(
val distance = viewModel.distRes.value
val scope = rememberCoroutineScope()
val buses = viewModel.busRes.value
val time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("hh:mm"))
val time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("hh:mm a"))
val date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd/MM/YYYY"))
var user by remember { mutableStateOf(listOf<User>()) }
var bus by remember { mutableStateOf(RealtimeBusResponse.BusResponse()) }
val mUserViewModel: UserViewModel =
Expand Down Expand Up @@ -410,6 +411,7 @@ fun ScanScreen(
paid = price,
bus = bus.name,
time = time,
date = date,
passNum = person.toInt(),
code = Random.nextInt(1000, 10000).toString()
), from = user[0].email.substringBefore("@"), to = code
Expand Down
Loading

0 comments on commit 33f1271

Please sign in to comment.