Driver admin complete

- empty view for no users
 - edit user identifier
 - test for driver admin added
This commit is contained in:
2023-06-23 17:02:39 +01:00
parent a72252a26c
commit 5dc71169bb
61 changed files with 325 additions and 1756 deletions

View File

@@ -1,14 +1,6 @@
package h_mal.appttude.com.driver.application
import android.app.Application
import android.content.res.Resources
import h_mal.appttude.com.driver.data.FirebaseAuthSource
import h_mal.appttude.com.driver.data.FirebaseDatabaseSource
import h_mal.appttude.com.driver.data.FirebaseStorageSource
import h_mal.appttude.com.driver.data.prefs.PreferenceProvider
import org.kodein.di.Kodein
import org.kodein.di.KodeinAware
import org.kodein.di.android.x.androidXModule
import org.kodein.di.generic.bind
import org.kodein.di.generic.instance
import org.kodein.di.generic.provider

View File

@@ -0,0 +1,27 @@
package h_mal.appttude.com.driver.model
import h_mal.appttude.com.driver.R
enum class DatabaseStatus(val drawable: Int, val header: Int, val subtext: Int) {
NO_CONNECTION(R.drawable.baseline_inbox_24, R.string.no_connection, R.string.no_connection_subtext),
NO_PERMISSION(
R.drawable.baseline_inbox_24,
R.string.no_permission,
R.string.no_permission_subtext
),
CANNOT_RETRIEVE(
R.drawable.baseline_inbox_24,
R.string.cannot_retrieve,
R.string.cannot_retrieve_subtext
),
NO_AUTHORIZATION(
R.drawable.baseline_inbox_24,
R.string.no_authorization,
R.string.no_authorization_subtext
),
EMPTY_RESULTS(
R.drawable.baseline_inbox_24,
R.string.no_drivers_to_show,
R.string.no_drivers_subtext
)
}

View File

@@ -1,6 +1,12 @@
package h_mal.appttude.com.driver.objects
import h_mal.appttude.com.driver.model.*
import h_mal.appttude.com.driver.model.DriversLicense
import h_mal.appttude.com.driver.model.Insurance
import h_mal.appttude.com.driver.model.Logbook
import h_mal.appttude.com.driver.model.Mot
import h_mal.appttude.com.driver.model.PrivateHireLicense
import h_mal.appttude.com.driver.model.PrivateHireVehicle
import h_mal.appttude.com.driver.model.VehicleProfile
data class ArchiveObject(

View File

@@ -1,6 +1,9 @@
package h_mal.appttude.com.driver.objects.wholeObject
import h_mal.appttude.com.driver.model.*
import h_mal.appttude.com.driver.model.Insurance
import h_mal.appttude.com.driver.model.Logbook
import h_mal.appttude.com.driver.model.Mot
import h_mal.appttude.com.driver.model.PrivateHireVehicle
import h_mal.appttude.com.driver.model.VehicleProfile
data class VehicleProfile (

View File

@@ -1,6 +1,5 @@
package h_mal.appttude.com.driver.ui
import com.google.android.material.snackbar.Snackbar
import h_mal.appttude.com.driver.base.BaseFragment
import h_mal.appttude.com.driver.databinding.FragmentApproverBinding
import h_mal.appttude.com.driver.model.ApprovalStatus

View File

@@ -19,6 +19,8 @@ import h_mal.appttude.com.driver.base.CustomViewHolder
import h_mal.appttude.com.driver.data.USER_CONST
import h_mal.appttude.com.driver.databinding.FragmentHomeSuperUserBinding
import h_mal.appttude.com.driver.databinding.ListItemLayoutBinding
import h_mal.appttude.com.driver.model.DatabaseStatus
import h_mal.appttude.com.driver.model.DatabaseStatus.*
import h_mal.appttude.com.driver.model.SortOption
import h_mal.appttude.com.driver.objects.UserObject
import h_mal.appttude.com.driver.objects.WholeDriverObject
@@ -27,7 +29,8 @@ import h_mal.appttude.com.driver.viewmodels.SuperUserViewModel
import java.util.*
class HomeSuperUserFragment : BaseFragment<SuperUserViewModel, FragmentHomeSuperUserBinding>(), MenuProvider {
class HomeSuperUserFragment : BaseFragment<SuperUserViewModel, FragmentHomeSuperUserBinding>(),
MenuProvider {
private lateinit var adapter: FirebaseRecyclerAdapter<WholeDriverObject, CustomViewHolder<ListItemLayoutBinding>>
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@@ -42,6 +45,17 @@ class HomeSuperUserFragment : BaseFragment<SuperUserViewModel, FragmentHomeSuper
is FirebaseRecyclerOptions<*> -> setAdapterToRecyclerView(data)
}
}
private fun setNonView(status: DatabaseStatus) {
applyBinding {
emptyView.run {
root.setOnClickListener(null)
root.visibility = View.VISIBLE
icon.setImageResource(status.drawable)
header.setText(status.header)
subtext.setText(status.subtext)
}
}
}
@Suppress("UNCHECKED_CAST")
private fun setAdapterToRecyclerView(options: FirebaseRecyclerOptions<*>) {
@@ -74,8 +88,8 @@ class HomeSuperUserFragment : BaseFragment<SuperUserViewModel, FragmentHomeSuper
}
private fun createAdapter(options: FirebaseRecyclerOptions<WholeDriverObject>): BaseFirebaseAdapter<WholeDriverObject, ListItemLayoutBinding> {
return object : BaseFirebaseAdapter<WholeDriverObject, ListItemLayoutBinding>(options, layoutInflater) {
return object :
BaseFirebaseAdapter<WholeDriverObject, ListItemLayoutBinding>(options, layoutInflater) {
override fun onBindViewHolder(
holder: CustomViewHolder<ListItemLayoutBinding>,
position: Int,
@@ -87,7 +101,8 @@ class HomeSuperUserFragment : BaseFragment<SuperUserViewModel, FragmentHomeSuper
usernameText.text = userDetails?.profileName
emailaddressText.text = userDetails?.profileEmail
driverNo.run {
val number = if (model.driver_number.isNullOrBlank()) "#N/A" else model.driver_number
val number =
if (model.driver_number.isNullOrBlank()) "#N/A" else model.driver_number
text = number
setOnClickListener {
getKeyAtPosition(position)?.let { showChangeNumberDialog(number!!, it) }
@@ -121,8 +136,24 @@ class HomeSuperUserFragment : BaseFragment<SuperUserViewModel, FragmentHomeSuper
applyBinding { progressCircular.hide() }
}
override fun connectionLost() {
showToast("No connection available")
override fun authorizationError() {
setNonView(NO_AUTHORIZATION)
}
override fun cannotRetrieve() {
setNonView(CANNOT_RETRIEVE)
}
override fun noConnection() {
setNonView(NO_CONNECTION)
}
override fun permissionsDenied() {
setNonView(NO_PERMISSION)
}
override fun emptyList() {
setNonView(EMPTY_RESULTS)
}
}
}

View File

@@ -14,7 +14,11 @@ import h_mal.appttude.com.driver.objects.ApprovalsObject
import h_mal.appttude.com.driver.ui.driverprofile.DriverLicenseFragment
import h_mal.appttude.com.driver.ui.driverprofile.DriverProfileFragment
import h_mal.appttude.com.driver.ui.driverprofile.PrivateHireLicenseFragment
import h_mal.appttude.com.driver.ui.vehicleprofile.*
import h_mal.appttude.com.driver.ui.vehicleprofile.InsuranceFragment
import h_mal.appttude.com.driver.ui.vehicleprofile.LogbookFragment
import h_mal.appttude.com.driver.ui.vehicleprofile.MotFragment
import h_mal.appttude.com.driver.ui.vehicleprofile.PrivateHireVehicleFragment
import h_mal.appttude.com.driver.ui.vehicleprofile.VehicleProfileFragment
import h_mal.appttude.com.driver.utils.Coroutines.io
import h_mal.appttude.com.driver.utils.FRAGMENT
import h_mal.appttude.com.driver.utils.getDataFromDatabaseRef

View File

@@ -22,7 +22,7 @@ class SuperUserViewModel(
}
fun createFirebaseOptions(sort: SortOption? = null) {
val ref = firebaseDatabaseSource.getUsersRef()
val ref = firebaseDatabaseSource.getUsersRef().orderByChild("role").startAt("driver").endAt("driver")
sort?.isNotNull { preferenceProvider.setSortOption(it.label) }
@@ -33,7 +33,7 @@ class SuperUserViewModel(
// }
val options = FirebaseRecyclerOptions.Builder<WholeDriverObject>()
.setQuery(ref.orderByKey(), WholeDriverObject::class.java)
.setQuery(ref, WholeDriverObject::class.java)
.build()
onSuccess(options)
@@ -47,7 +47,7 @@ class SuperUserViewModel(
onError("No driver identifier provided")
return@doTryOperation
}
val text = if (input.length > 6) input.substring(0,7) else input
val text = if (input.length > 6) input.substring(0, 7) else input
firebaseDatabaseSource.run {
postToDatabaseRed(getDriverNumberRef(uid), text)

View File

@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_with_curve"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:src="@drawable/splash_screen"
android:scaleType="centerCrop"
android:paddingTop="@dimen/default_indicator_margin_horizontal"
android:layout_marginTop="@dimen/default_indicator_margin_horizontal"
app:layout_constraintHeight_percent="0.5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:importantForAccessibility="no" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/constraint_container">
<ImageView
android:id="@+id/icon"
android:layout_width="80dp"
android:layout_height="80dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="@id/header"
android:src="@drawable/baseline_inbox_24"
android:contentDescription="@string/image_icon_for_feedback_view" />
<TextView
android:id="@+id/header"
style="@style/headerStyle"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:gravity="center"
android:text="@string/no_drivers_to_show"/>
<TextView
android:id="@+id/subtext"
style="@style/subheader"
app:layout_constraintTop_toBottomOf="@id/header"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:gravity="center"
android:text="@string/no_drivers_subtext"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".ui.HomeSuperUserFragment">
@@ -28,9 +29,9 @@
<include
android:id="@+id/empty_view"
layout="@layout/empty_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/empty_users_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
@@ -38,5 +39,4 @@
android:visibility="gone"
tools:visibility="visible"/>
</androidx.constraintlayout.widget.ConstraintLayout>