mirror of
https://github.com/hmalik144/Driver.git
synced 2025-12-10 02:45:20 +00:00
- minor bug fixes
Took 3 hours 24 minutes
This commit is contained in:
@@ -6,9 +6,12 @@ import android.view.*
|
||||
import android.widget.EditText
|
||||
import android.widget.LinearLayout
|
||||
import androidx.core.view.MenuProvider
|
||||
import androidx.core.widget.doOnTextChanged
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import com.firebase.ui.common.ChangeEventType
|
||||
import com.firebase.ui.database.FirebaseRecyclerAdapter
|
||||
import com.firebase.ui.database.FirebaseRecyclerOptions
|
||||
import com.google.firebase.database.DataSnapshot
|
||||
import h_mal.appttude.com.driver.R
|
||||
import h_mal.appttude.com.driver.base.BaseFirebaseAdapter
|
||||
import h_mal.appttude.com.driver.base.BaseFragment
|
||||
@@ -56,6 +59,15 @@ class HomeSuperUserFragment : BaseFragment<SuperUserViewModel, FragmentHomeSuper
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
applyBinding {
|
||||
if (recyclerView.adapter != null) {
|
||||
adapter.startListening()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
adapter.stopListening()
|
||||
@@ -75,13 +87,10 @@ class HomeSuperUserFragment : BaseFragment<SuperUserViewModel, FragmentHomeSuper
|
||||
usernameText.text = userDetails?.profileName
|
||||
emailaddressText.text = userDetails?.profileEmail
|
||||
driverNo.run {
|
||||
val number = model.driver_number ?: "0"
|
||||
val number = if (model.driver_number.isNullOrBlank()) "#N/A" else model.driver_number
|
||||
text = number
|
||||
setOnClickListener {
|
||||
val uid = getKeyAtPosition(position)
|
||||
if (uid != null) {
|
||||
showChangeNumberDialog(uid, number)
|
||||
}
|
||||
getKeyAtPosition(position)?.let { showChangeNumberDialog(number!!, it) }
|
||||
}
|
||||
}
|
||||
root.setOnClickListener {
|
||||
@@ -100,11 +109,20 @@ class HomeSuperUserFragment : BaseFragment<SuperUserViewModel, FragmentHomeSuper
|
||||
if (itemCount == 0) {
|
||||
emptyView.root.visibility = if (itemCount == 0) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
progressCircular.hide()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onChildChanged(
|
||||
type: ChangeEventType,
|
||||
snapshot: DataSnapshot,
|
||||
newIndex: Int,
|
||||
oldIndex: Int
|
||||
) {
|
||||
super.onChildChanged(type, snapshot, newIndex, oldIndex)
|
||||
applyBinding { progressCircular.hide() }
|
||||
}
|
||||
|
||||
override fun connectionLost() {
|
||||
requireContext().displayToast("No connection available")
|
||||
}
|
||||
@@ -115,6 +133,7 @@ class HomeSuperUserFragment : BaseFragment<SuperUserViewModel, FragmentHomeSuper
|
||||
val inputText = EditText(context).apply {
|
||||
setText(defaultNumber)
|
||||
setSelectAllOnFocus(true)
|
||||
doOnTextChanged { _, _, count, _ -> if (count > 6) context.displayToast("Identifier cannot be larger than 6") }
|
||||
}
|
||||
val layout = LinearLayout(context).apply {
|
||||
orientation = LinearLayout.VERTICAL
|
||||
@@ -122,11 +141,12 @@ class HomeSuperUserFragment : BaseFragment<SuperUserViewModel, FragmentHomeSuper
|
||||
addView(inputText)
|
||||
}
|
||||
|
||||
AlertDialog.Builder(context).setTitle("Change Driver Number")
|
||||
AlertDialog.Builder(requireContext(), R.style.AppTheme_AppBarOverlay)
|
||||
.setTitle("Change Driver Identifier")
|
||||
.setView(layout)
|
||||
.setPositiveButton("Submit") { _, _ ->
|
||||
val input = inputText.text?.toString()
|
||||
viewModel.updateDriverNumber(uid, input)
|
||||
input?.let { viewModel.updateDriverNumber(uid, it) }
|
||||
}.create().show()
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,12 @@ class SuperUserViewModel(
|
||||
onError("No driver identifier provided")
|
||||
return@doTryOperation
|
||||
}
|
||||
firebaseDatabaseSource.postToDatabaseRed(firebaseDatabaseSource.getUserRef(uid), input)
|
||||
val text = if (input.length > 6) input.substring(0,7) else input
|
||||
|
||||
firebaseDatabaseSource.run {
|
||||
postToDatabaseRed(getDriverNumberRef(uid), text)
|
||||
onSuccess(Unit)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,13 +137,15 @@ abstract class BaseFragment<V : BaseViewModel, VB : ViewBinding> : Fragment(), K
|
||||
open fun onImageGalleryResult(imageUris: List<Uri>?) {}
|
||||
|
||||
fun openGalleryForImage() {
|
||||
registerForActivityResult(getResultsContract()) { result ->
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
when (result) {
|
||||
is Uri -> onImageGalleryResult(result)
|
||||
is List<*> -> onImageGalleryResult(result as List<Uri>)
|
||||
}
|
||||
}.launch(multipleImage)
|
||||
permissionRequest.launch(multipleImage)
|
||||
}
|
||||
|
||||
private val permissionRequest = registerForActivityResult(getResultsContract()) { result ->
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
when (result) {
|
||||
is Uri -> onImageGalleryResult(result)
|
||||
is List<*> -> onImageGalleryResult(result as List<Uri>)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getResultsContract(): ActivityResultContract<Boolean, Any?> {
|
||||
@@ -156,7 +158,7 @@ abstract class BaseFragment<V : BaseViewModel, VB : ViewBinding> : Fragment(), K
|
||||
}
|
||||
|
||||
override fun parseResult(resultCode: Int, intent: Intent?): Any? {
|
||||
intent?.clipData?.convertToList()?.let { clip ->
|
||||
intent?.clipData?.takeIf { it.itemCount > 1 }?.convertToList()?.let { clip ->
|
||||
val list = clip.takeIf { it.size > 10 }?.let {
|
||||
clip.subList(0, 9)
|
||||
} ?: clip
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#000b85</color>
|
||||
<color name="colorPrimaryDark">#010057</color>
|
||||
<color name="colorAccent">#03a9f4</color>
|
||||
<color name="colorPrimary">#548C2F</color>
|
||||
<color name="colorPrimaryDark">#104911</color>
|
||||
<color name="colorAccent">#548C2F</color>
|
||||
|
||||
|
||||
<color name="colour_one">#03a9f4</color>
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
|
||||
<item name="android:windowBackground">@drawable/background_with_curve</item>
|
||||
<item name="android:actionMenuTextColor">@android:color/white</item>
|
||||
<item name="android:textColorHint">@android:color/white</item>
|
||||
<item name="android:textColor">@android:color/white</item>
|
||||
</style>
|
||||
@@ -35,8 +34,18 @@
|
||||
<!--<item name="android:autofilledHighlight">@android:color/transparent</item>-->
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
|
||||
<style name="AppTheme.AppBarOverlay" parent="Theme.MaterialComponents.Dialog.Alert">
|
||||
<item name="windowActionBar">true</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="materialAlertDialogBodyTextStyle">@style/AlertDialogTextStyle</item>
|
||||
<item name="materialAlertDialogTitleTextStyle">@style/AlertDialogTextStyle</item>
|
||||
<item name="android:textColor">@color/colour_nine</item>
|
||||
</style>
|
||||
|
||||
<style name="AlertDialogTextStyle">
|
||||
<item name="android:textColor">#000000</item>
|
||||
<item name="android:textColorPrimary">#595959</item>
|
||||
<item name="android:colorAccent">#1b5e20</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
||||
|
||||
Reference in New Issue
Block a user