-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
204 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/example/buspayment/realtimeDB/responses/RealtimePaymentListResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.example.buspayment.realtimeDB.responses | ||
|
||
data class RealtimePaymentListResponse( | ||
val payment: PaymentResponse?, | ||
val key: String? = "", | ||
) { | ||
data class PaymentResponse( | ||
val status: String? = "", | ||
val fromUser: String? = "", | ||
val toUser: String? = "", | ||
val from: String? = "", | ||
val to: String? = "", | ||
val paid: Double? = 0.0, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 57 additions & 22 deletions
79
app/src/main/java/com/example/buspayment/screens/conductor/PaymentListScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,78 @@ | ||
package com.example.buspayment.screens.conductor | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Box | ||
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.height | ||
import androidx.compose.foundation.layout.width | ||
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.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.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.dp | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.navigation.NavController | ||
import com.example.buspayment.navigations.Screens | ||
import com.example.buspayment.realtimeDB.responses.RealtimePaymentListResponse | ||
import com.example.buspayment.realtimeDB.ui.RealtimeViewModel | ||
|
||
@Composable | ||
fun PaymentListScreen(navController: NavController) { | ||
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.TopCenter) { | ||
fun PaymentListScreen( | ||
navController: NavController, | ||
viewModel: RealtimeViewModel = hiltViewModel() | ||
) { | ||
val res = viewModel.payres.value | ||
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 = "Manage buses", style = MaterialTheme.typography.headlineSmall) | ||
Text(text = "", style = MaterialTheme.typography.headlineSmall) | ||
} | ||
Column { | ||
Box( | ||
Modifier | ||
.height(400.dp) | ||
.width(400.dp) | ||
) { | ||
|
||
Text( | ||
text = "Waiting for approval", | ||
textAlign = TextAlign.Center, | ||
style = MaterialTheme.typography.headlineSmall, | ||
modifier = Modifier | ||
.clickable { | ||
navController.navigate(Screens.UHome.route) | ||
if (res.payment.isNotEmpty()) { | ||
// val paymentList = res.payment.filter { item -> item.payment!!.status == "Pending" } | ||
LazyColumn() { | ||
items( | ||
res.payment, | ||
key = { | ||
it.key!! | ||
} | ||
.fillMaxWidth() | ||
) | ||
) { res -> | ||
PaymentListRow(itemState = res.payment!!) | ||
} | ||
} | ||
} else if (res.isLoading) { | ||
CircularProgressIndicator() | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun PaymentListRow( | ||
itemState: RealtimePaymentListResponse.PaymentResponse | ||
) { | ||
Text(itemState.fromUser!!) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,11 @@ | |
package com.example.buspayment.screens.user | ||
|
||
import android.Manifest | ||
import android.app.Application | ||
import android.content.pm.PackageManager | ||
import android.util.Log | ||
import android.util.Size | ||
import android.widget.Toast | ||
import androidx.activity.compose.rememberLauncherForActivityResult | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import androidx.camera.core.CameraSelector | ||
|
@@ -40,8 +42,10 @@ 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 | ||
|
@@ -56,25 +60,37 @@ import androidx.compose.ui.unit.toSize | |
import androidx.compose.ui.viewinterop.AndroidView | ||
import androidx.core.content.ContextCompat | ||
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.funtions.QrCodeAnalysis | ||
import com.example.buspayment.navigations.Screens | ||
import com.example.buspayment.realtimeDB.responses.RealtimePaymentListResponse | ||
import com.example.buspayment.realtimeDB.ui.RealtimeViewModel | ||
import com.example.buspayment.ui.theme.Typography | ||
import com.example.buspayment.utils.ResultState | ||
import com.google.android.gms.location.LocationServices | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import kotlin.math.abs | ||
|
||
@Composable | ||
fun ScanScreen( | ||
navController: NavController, | ||
viewModel: RealtimeViewModel = hiltViewModel() | ||
) { | ||
val context = LocalContext.current | ||
val res = viewModel.distRes.value | ||
val scope = rememberCoroutineScope() | ||
val buses = viewModel.busRes.value | ||
var user by remember { mutableStateOf(listOf<User>()) } | ||
val mUserViewModel: UserViewModel = | ||
viewModel(factory = UserViewModel.UserViewModelFactory(context.applicationContext as Application)) | ||
user = mUserViewModel.readUser.observeAsState(listOf()).value | ||
var code by remember { mutableStateOf("") } | ||
var isExpanded by remember { mutableStateOf(false) } | ||
var isToExpanded by remember { mutableStateOf(false) } | ||
val context = LocalContext.current | ||
val lifeCycleOwner = LocalLifecycleOwner.current | ||
val fromList = mutableListOf<String>() | ||
val toList = mutableListOf<String>() | ||
|
@@ -238,7 +254,33 @@ fun ScanScreen( | |
modifier = Modifier.fillMaxWidth() | ||
) { | ||
OutlinedButton( | ||
onClick = { navController.navigate(Screens.UHome.route) }, | ||
onClick = { | ||
scope.launch(Dispatchers.Main) { | ||
viewModel.submitPayment( | ||
RealtimePaymentListResponse.PaymentResponse( | ||
"Pending", | ||
from = selectedFrom, | ||
to = selectedTo, | ||
fromUser = user[0].email, | ||
toUser = "[email protected]", | ||
paid = price, | ||
) | ||
).collect { response -> | ||
when (response) { | ||
is ResultState.Success -> { | ||
Toast.makeText(context, "Payment successful", Toast.LENGTH_SHORT).show() | ||
navController.navigate(Screens.UHome.route) | ||
} | ||
|
||
is ResultState.Failure -> { | ||
Toast.makeText(context, "Failed", Toast.LENGTH_SHORT).show() | ||
} | ||
|
||
is ResultState.Loading -> {} | ||
} | ||
} | ||
} | ||
}, | ||
enabled = price > 0 | ||
) { | ||
Text(text = "Proceed to payment $price taka") | ||
|