mirror of
https://github.com/hmalik144/Driver.git
synced 2026-03-18 15:36:03 +00:00
Driver admin complete
- empty view for no users - edit user identifier - test for driver admin added
This commit is contained in:
@@ -4,7 +4,6 @@ import android.app.Application
|
||||
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
|
||||
|
||||
@@ -8,15 +8,20 @@ import androidx.recyclerview.widget.RecyclerView.ViewHolder
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.firebase.ui.database.FirebaseRecyclerAdapter
|
||||
import com.firebase.ui.database.FirebaseRecyclerOptions
|
||||
import com.google.firebase.database.DatabaseError
|
||||
import h_mal.appttude.com.driver.utils.GenericsHelper.getGenericClassAt
|
||||
import h_mal.appttude.com.driver.utils.GenericsHelper.inflateBindingByType
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
|
||||
open class BaseFirebaseAdapter<T: Any, VB : ViewBinding>(options: FirebaseRecyclerOptions<T>, private val layoutInflater: LayoutInflater):
|
||||
open class BaseFirebaseAdapter<T : Any, VB : ViewBinding>(
|
||||
options: FirebaseRecyclerOptions<T>,
|
||||
private val layoutInflater: LayoutInflater
|
||||
) :
|
||||
FirebaseRecyclerAdapter<T, CustomViewHolder<VB>>(options) {
|
||||
|
||||
private val connectivityManager = layoutInflater.context.getSystemService(ConnectivityManager::class.java) as ConnectivityManager
|
||||
private val connectivityManager =
|
||||
layoutInflater.context.getSystemService(ConnectivityManager::class.java) as ConnectivityManager
|
||||
|
||||
private var _binding: VB? = null
|
||||
val binding: VB
|
||||
@@ -32,7 +37,7 @@ open class BaseFirebaseAdapter<T: Any, VB : ViewBinding>(options: FirebaseRecycl
|
||||
return CustomViewHolder(requireNotNull(_binding))
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: CustomViewHolder<VB>, position: Int, model: T) { }
|
||||
override fun onBindViewHolder(holder: CustomViewHolder<VB>, position: Int, model: T) {}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
return snapshots.getSnapshot(position).key?.toByteArray()
|
||||
@@ -50,6 +55,26 @@ open class BaseFirebaseAdapter<T: Any, VB : ViewBinding>(options: FirebaseRecycl
|
||||
}
|
||||
|
||||
open fun connectionLost() {}
|
||||
override fun onDataChanged() {
|
||||
super.onDataChanged()
|
||||
if (itemCount == 0) emptyList()
|
||||
}
|
||||
override fun onError(error: DatabaseError) {
|
||||
super.onError(error)
|
||||
when (error.code) {
|
||||
DatabaseError.PERMISSION_DENIED -> permissionsDenied()
|
||||
DatabaseError.DISCONNECTED, DatabaseError.UNAVAILABLE, DatabaseError.NETWORK_ERROR -> noConnection()
|
||||
DatabaseError.EXPIRED_TOKEN, DatabaseError.OPERATION_FAILED, DatabaseError.INVALID_TOKEN, DatabaseError.MAX_RETRIES -> authorizationError()
|
||||
else -> cannotRetrieve()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
open fun permissionsDenied() {}
|
||||
open fun noConnection() {}
|
||||
open fun cannotRetrieve() {}
|
||||
open fun authorizationError() {}
|
||||
open fun emptyList() {}
|
||||
}
|
||||
|
||||
class CustomViewHolder<VB : ViewBinding>(val viewBinding: VB): ViewHolder(viewBinding.root)
|
||||
class CustomViewHolder<VB : ViewBinding>(val viewBinding: VB) : ViewHolder(viewBinding.root)
|
||||
@@ -20,6 +20,9 @@ abstract class BaseViewModel : ViewModel() {
|
||||
uiState.postValue(ViewState.HasError(Event(error)))
|
||||
}
|
||||
|
||||
/*
|
||||
* All in one function for trying an operation and handling its start and failure
|
||||
*/
|
||||
suspend fun doTryOperation(
|
||||
defaultErrorMessage: String?,
|
||||
operation: suspend () -> Unit
|
||||
|
||||
@@ -2,7 +2,11 @@ package h_mal.appttude.com.driver.data
|
||||
|
||||
import android.net.Uri
|
||||
import com.google.android.gms.tasks.Task
|
||||
import com.google.firebase.auth.*
|
||||
import com.google.firebase.auth.AuthResult
|
||||
import com.google.firebase.auth.EmailAuthProvider
|
||||
import com.google.firebase.auth.FirebaseAuth
|
||||
import com.google.firebase.auth.FirebaseUser
|
||||
import com.google.firebase.auth.UserProfileChangeRequest
|
||||
import java.io.IOException
|
||||
|
||||
class FirebaseAuthSource : FirebaseAuthentication {
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package h_mal.appttude.com.driver.utils
|
||||
|
||||
import com.google.firebase.database.DatabaseError
|
||||
|
||||
class FirebaseException(
|
||||
private val databaseError: DatabaseError
|
||||
) : RuntimeException(databaseError.message, databaseError.toException()) {
|
||||
|
||||
fun getCode() = databaseError.code
|
||||
fun getDetails() = databaseError.details
|
||||
|
||||
fun getErrorStatus(): Status {
|
||||
return Status.getByScore(getCode()) ?: Status.UNKNOWN_ERROR
|
||||
}
|
||||
|
||||
enum class Status(private val code: Int) {
|
||||
DATA_STALE(-1),
|
||||
/** The server indicated that this operation failed */
|
||||
OPERATION_FAILED(-2),
|
||||
/** This client does not have permission to perform this operation */
|
||||
PERMISSION_DENIED(-3),
|
||||
/** The operation had to be aborted due to a network disconnect */
|
||||
DISCONNECTED(-4),
|
||||
/** The supplied auth token has expired */
|
||||
EXPIRED_TOKEN (-6),
|
||||
/**
|
||||
* The specified authentication token is invalid. This can occur when the token is malformed,
|
||||
* expired, or the secret that was used to generate it has been revoked.
|
||||
*/
|
||||
INVALID_TOKEN(-7),
|
||||
/** The transaction had too many retries */
|
||||
MAX_RETRIES(-8),
|
||||
/** The transaction was overridden by a subsequent set */
|
||||
OVERRIDDEN_BY_SET(-9),
|
||||
/** The service is unavailable */
|
||||
UNAVAILABLE(-10),
|
||||
/** An exception occurred in user code */
|
||||
USER_CODE_EXCEPTION(-11),
|
||||
/** The operation could not be performed due to a network error. */
|
||||
NETWORK_ERROR(-24),
|
||||
/** The write was canceled locally */
|
||||
WRITE_CANCELED(-25),
|
||||
/**
|
||||
* An unknown error occurred. Please refer to the error message and error details for more
|
||||
* information.
|
||||
*/
|
||||
UNKNOWN_ERROR(-999);
|
||||
|
||||
companion object {
|
||||
infix fun getByScore(value: Int): Status? =
|
||||
Status.values().firstOrNull { it.code == value }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,7 +30,6 @@ suspend fun DatabaseReference.singleValueEvent(): EventResponse = suspendCorouti
|
||||
/**
|
||||
* Read database reference once {@link #DatabaseReference.addListenerForSingleValueEvent}
|
||||
*
|
||||
*
|
||||
* @return T
|
||||
*/
|
||||
suspend inline fun <reified T : Any> DatabaseReference.getDataFromDatabaseRef(): T? {
|
||||
@@ -39,7 +38,23 @@ suspend inline fun <reified T : Any> DatabaseReference.getDataFromDatabaseRef():
|
||||
response.snapshot.getValue(T::class.java)
|
||||
}
|
||||
is EventResponse.Cancelled -> {
|
||||
throw response.error.toException()
|
||||
throw FirebaseException(response.error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read database reference once {@link #DatabaseReference.addListenerForSingleValueEvent}
|
||||
*
|
||||
* @return T
|
||||
*/
|
||||
suspend inline fun <reified T : Any> DatabaseReference.getListDataFromDatabaseRef(): List<T?> {
|
||||
return when (val response: EventResponse = singleValueEvent()) {
|
||||
is EventResponse.Changed -> {
|
||||
response.snapshot.children.map { it.getValue(T::class.java) }
|
||||
}
|
||||
is EventResponse.Cancelled -> {
|
||||
throw FirebaseException(response.error)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +65,7 @@ suspend fun <T: Any> DatabaseReference.getDataFromDatabaseRef(clazz : Class<T>):
|
||||
response.snapshot.getValue(clazz)
|
||||
}
|
||||
is EventResponse.Cancelled -> {
|
||||
throw response.error.toException()
|
||||
throw FirebaseException(response.error)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package h_mal.appttude.com.driver.utils
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Bitmap
|
||||
@@ -16,7 +15,6 @@ import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.EditText
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.fragment.app.Fragment
|
||||
|
||||
BIN
app/src/main/res/drawable-hdpi/splash_screen.png
Normal file
BIN
app/src/main/res/drawable-hdpi/splash_screen.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 41 KiB |
BIN
app/src/main/res/drawable-mdpi/splash_screen.png
Normal file
BIN
app/src/main/res/drawable-mdpi/splash_screen.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
BIN
app/src/main/res/drawable-xhdpi/splash_screen.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/splash_screen.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 64 KiB |
BIN
app/src/main/res/drawable-xxhdpi/splash_screen.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/splash_screen.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 127 KiB |
BIN
app/src/main/res/drawable-xxxhdpi/splash_screen.png
Normal file
BIN
app/src/main/res/drawable-xxxhdpi/splash_screen.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 185 KiB |
5
app/src/main/res/drawable/baseline_inbox_24.xml
Normal file
5
app/src/main/res/drawable/baseline_inbox_24.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<vector android:height="72dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="72dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M19,3L4.99,3c-1.11,0 -1.98,0.89 -1.98,2L3,19c0,1.1 0.88,2 1.99,2L19,21c1.1,0 2,-0.9 2,-2L21,5c0,-1.11 -0.9,-2 -2,-2zM19,15h-4c0,1.66 -1.35,3 -3,3s-3,-1.34 -3,-3L4.99,15L4.99,5L19,5v10z"/>
|
||||
</vector>
|
||||
@@ -105,4 +105,15 @@
|
||||
<string name="approve">Approve</string>
|
||||
<string name="deny">Deny</string>
|
||||
<string name="decline">Decline</string>
|
||||
<string name="no_drivers_to_show">No drivers to show</string>
|
||||
<string name="no_drivers_subtext">There are no drivers present for your organisation.</string>
|
||||
<string name="no_permission">You do not have permissions to view</string>
|
||||
<string name="no_permission_subtext">You are not a super user. Contact us to get super user access.</string>
|
||||
<string name="cannot_retrieve">Cannot retrieve data.</string>
|
||||
<string name="cannot_retrieve_subtext">Check you are logged in correctly and have a working connection.</string>
|
||||
<string name="no_connection">No connection</string>
|
||||
<string name="no_connection_subtext">Make you have a valid internet connection.</string>
|
||||
<string name="no_authorization">Authentication has failed</string>
|
||||
<string name="no_authorization_subtext">There is a problem with authentication.</string>
|
||||
<string name="image_icon_for_feedback_view">Image icon for feedback view.</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user