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.EditText
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import androidx.core.view.MenuProvider
|
import androidx.core.view.MenuProvider
|
||||||
|
import androidx.core.widget.doOnTextChanged
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
|
import com.firebase.ui.common.ChangeEventType
|
||||||
import com.firebase.ui.database.FirebaseRecyclerAdapter
|
import com.firebase.ui.database.FirebaseRecyclerAdapter
|
||||||
import com.firebase.ui.database.FirebaseRecyclerOptions
|
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.R
|
||||||
import h_mal.appttude.com.driver.base.BaseFirebaseAdapter
|
import h_mal.appttude.com.driver.base.BaseFirebaseAdapter
|
||||||
import h_mal.appttude.com.driver.base.BaseFragment
|
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() {
|
override fun onStop() {
|
||||||
super.onStop()
|
super.onStop()
|
||||||
adapter.stopListening()
|
adapter.stopListening()
|
||||||
@@ -75,13 +87,10 @@ class HomeSuperUserFragment : BaseFragment<SuperUserViewModel, FragmentHomeSuper
|
|||||||
usernameText.text = userDetails?.profileName
|
usernameText.text = userDetails?.profileName
|
||||||
emailaddressText.text = userDetails?.profileEmail
|
emailaddressText.text = userDetails?.profileEmail
|
||||||
driverNo.run {
|
driverNo.run {
|
||||||
val number = model.driver_number ?: "0"
|
val number = if (model.driver_number.isNullOrBlank()) "#N/A" else model.driver_number
|
||||||
text = number
|
text = number
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
val uid = getKeyAtPosition(position)
|
getKeyAtPosition(position)?.let { showChangeNumberDialog(number!!, it) }
|
||||||
if (uid != null) {
|
|
||||||
showChangeNumberDialog(uid, number)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
root.setOnClickListener {
|
root.setOnClickListener {
|
||||||
@@ -100,11 +109,20 @@ class HomeSuperUserFragment : BaseFragment<SuperUserViewModel, FragmentHomeSuper
|
|||||||
if (itemCount == 0) {
|
if (itemCount == 0) {
|
||||||
emptyView.root.visibility = if (itemCount == 0) View.VISIBLE else View.GONE
|
emptyView.root.visibility = if (itemCount == 0) View.VISIBLE else View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
progressCircular.hide()
|
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() {
|
override fun connectionLost() {
|
||||||
requireContext().displayToast("No connection available")
|
requireContext().displayToast("No connection available")
|
||||||
}
|
}
|
||||||
@@ -115,6 +133,7 @@ class HomeSuperUserFragment : BaseFragment<SuperUserViewModel, FragmentHomeSuper
|
|||||||
val inputText = EditText(context).apply {
|
val inputText = EditText(context).apply {
|
||||||
setText(defaultNumber)
|
setText(defaultNumber)
|
||||||
setSelectAllOnFocus(true)
|
setSelectAllOnFocus(true)
|
||||||
|
doOnTextChanged { _, _, count, _ -> if (count > 6) context.displayToast("Identifier cannot be larger than 6") }
|
||||||
}
|
}
|
||||||
val layout = LinearLayout(context).apply {
|
val layout = LinearLayout(context).apply {
|
||||||
orientation = LinearLayout.VERTICAL
|
orientation = LinearLayout.VERTICAL
|
||||||
@@ -122,11 +141,12 @@ class HomeSuperUserFragment : BaseFragment<SuperUserViewModel, FragmentHomeSuper
|
|||||||
addView(inputText)
|
addView(inputText)
|
||||||
}
|
}
|
||||||
|
|
||||||
AlertDialog.Builder(context).setTitle("Change Driver Number")
|
AlertDialog.Builder(requireContext(), R.style.AppTheme_AppBarOverlay)
|
||||||
|
.setTitle("Change Driver Identifier")
|
||||||
.setView(layout)
|
.setView(layout)
|
||||||
.setPositiveButton("Submit") { _, _ ->
|
.setPositiveButton("Submit") { _, _ ->
|
||||||
val input = inputText.text?.toString()
|
val input = inputText.text?.toString()
|
||||||
viewModel.updateDriverNumber(uid, input)
|
input?.let { viewModel.updateDriverNumber(uid, it) }
|
||||||
}.create().show()
|
}.create().show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,12 @@ class SuperUserViewModel(
|
|||||||
onError("No driver identifier provided")
|
onError("No driver identifier provided")
|
||||||
return@doTryOperation
|
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>?) {}
|
open fun onImageGalleryResult(imageUris: List<Uri>?) {}
|
||||||
|
|
||||||
fun openGalleryForImage() {
|
fun openGalleryForImage() {
|
||||||
registerForActivityResult(getResultsContract()) { result ->
|
permissionRequest.launch(multipleImage)
|
||||||
@Suppress("UNCHECKED_CAST")
|
}
|
||||||
when (result) {
|
|
||||||
is Uri -> onImageGalleryResult(result)
|
private val permissionRequest = registerForActivityResult(getResultsContract()) { result ->
|
||||||
is List<*> -> onImageGalleryResult(result as List<Uri>)
|
@Suppress("UNCHECKED_CAST")
|
||||||
}
|
when (result) {
|
||||||
}.launch(multipleImage)
|
is Uri -> onImageGalleryResult(result)
|
||||||
|
is List<*> -> onImageGalleryResult(result as List<Uri>)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getResultsContract(): ActivityResultContract<Boolean, Any?> {
|
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? {
|
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 {
|
val list = clip.takeIf { it.size > 10 }?.let {
|
||||||
clip.subList(0, 9)
|
clip.subList(0, 9)
|
||||||
} ?: clip
|
} ?: clip
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<color name="colorPrimary">#000b85</color>
|
<color name="colorPrimary">#548C2F</color>
|
||||||
<color name="colorPrimaryDark">#010057</color>
|
<color name="colorPrimaryDark">#104911</color>
|
||||||
<color name="colorAccent">#03a9f4</color>
|
<color name="colorAccent">#548C2F</color>
|
||||||
|
|
||||||
|
|
||||||
<color name="colour_one">#03a9f4</color>
|
<color name="colour_one">#03a9f4</color>
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
<item name="colorAccent">@color/colorAccent</item>
|
<item name="colorAccent">@color/colorAccent</item>
|
||||||
|
|
||||||
<item name="android:windowBackground">@drawable/background_with_curve</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:textColorHint">@android:color/white</item>
|
||||||
<item name="android:textColor">@android:color/white</item>
|
<item name="android:textColor">@android:color/white</item>
|
||||||
</style>
|
</style>
|
||||||
@@ -35,8 +34,18 @@
|
|||||||
<!--<item name="android:autofilledHighlight">@android:color/transparent</item>-->
|
<!--<item name="android:autofilledHighlight">@android:color/transparent</item>-->
|
||||||
</style>
|
</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>
|
||||||
|
|
||||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
||||||
|
|||||||
Reference in New Issue
Block a user