mirror of
https://github.com/hmalik144/Driver.git
synced 2026-03-18 15:36:03 +00:00
- Approver for documents as Admin (#19)
- Approver for documents as Admin - UI tests for document approving - update config.yml - update android test suite - idling resources added for toast - toast methods refactored - tests for approving updated
This commit is contained in:
@@ -9,19 +9,24 @@ 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
|
||||
import org.kodein.di.generic.singleton
|
||||
|
||||
class DriverApplication : Application(), KodeinAware {
|
||||
open class BaseApplication : Application(), KodeinAware {
|
||||
|
||||
// Kodein aware to initialise the classes used for DI
|
||||
override val kodein = Kodein.lazy {
|
||||
import(androidXModule(this@DriverApplication))
|
||||
import(parentModule)
|
||||
import(flavourModule)
|
||||
}
|
||||
|
||||
val parentModule = Kodein.Module("Parent Module") {
|
||||
import(androidXModule(this@BaseApplication))
|
||||
bind() from singleton { FirebaseAuthSource() }
|
||||
bind() from singleton { FirebaseDatabaseSource() }
|
||||
bind() from singleton { FirebaseStorageSource() }
|
||||
bind() from singleton { PreferenceProvider(this@DriverApplication) }
|
||||
bind() from provider { ApplicationViewModelFactory(instance(), instance(), instance(), instance()) }
|
||||
}
|
||||
|
||||
open val flavourModule = Kodein.Module("Flavour") {
|
||||
import(parentModule)
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,35 @@
|
||||
package h_mal.appttude.com.driver.base
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.ViewGroup.LayoutParams
|
||||
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
||||
import android.view.ViewGroup.inflate
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.ViewModelLazy
|
||||
import androidx.test.espresso.IdlingResource
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.google.android.material.snackbar.BaseTransientBottomBar.BaseCallback
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import h_mal.appttude.com.driver.R
|
||||
import h_mal.appttude.com.driver.application.ApplicationViewModelFactory
|
||||
import h_mal.appttude.com.driver.data.ViewState
|
||||
import h_mal.appttude.com.driver.utils.*
|
||||
import h_mal.appttude.com.driver.utils.BasicIdlingResource
|
||||
import h_mal.appttude.com.driver.utils.GenericsHelper.getGenericClassAt
|
||||
import h_mal.appttude.com.driver.utils.GenericsHelper.inflateBindingByType
|
||||
import h_mal.appttude.com.driver.utils.hide
|
||||
import h_mal.appttude.com.driver.utils.show
|
||||
import h_mal.appttude.com.driver.utils.triggerAnimation
|
||||
import org.kodein.di.KodeinAware
|
||||
import org.kodein.di.android.kodein
|
||||
import org.kodein.di.generic.instance
|
||||
|
||||
abstract class BaseActivity<V : BaseViewModel, VB : ViewBinding> : AppCompatActivity(), KodeinAware {
|
||||
abstract class BaseActivity<V : BaseViewModel, VB : ViewBinding> : AppCompatActivity(),
|
||||
KodeinAware {
|
||||
// The Idling Resource which will be null in production.
|
||||
private var mIdlingResource: BasicIdlingResource? = null
|
||||
private lateinit var loadingView: View
|
||||
@@ -108,7 +116,7 @@ abstract class BaseActivity<V : BaseViewModel, VB : ViewBinding> : AppCompatActi
|
||||
* Called in case of failure or some error emitted from the liveData in viewModel
|
||||
*/
|
||||
open fun onFailure(error: String?) {
|
||||
error?.let { displayToast(it) }
|
||||
error?.let { showToast(it) }
|
||||
loadingView.fadeOut()
|
||||
mIdlingResource?.setIdleState(true)
|
||||
}
|
||||
@@ -139,6 +147,42 @@ abstract class BaseActivity<V : BaseViewModel, VB : ViewBinding> : AppCompatActi
|
||||
super.onBackPressed()
|
||||
}
|
||||
|
||||
fun showToast(message: String) {
|
||||
val toast = Toast.makeText(this, message, Toast.LENGTH_LONG)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
toast.addCallback(object : Toast.Callback() {
|
||||
override fun onToastHidden() {
|
||||
super.onToastHidden()
|
||||
mIdlingResource?.setIdleState(true)
|
||||
}
|
||||
override fun onToastShown() {
|
||||
super.onToastShown()
|
||||
mIdlingResource?.setIdleState(false)
|
||||
}
|
||||
})
|
||||
}
|
||||
toast.show()
|
||||
}
|
||||
|
||||
fun showSnackBar(message: String) {
|
||||
val snackbar = Snackbar.make(
|
||||
window.decorView.findViewById(android.R.id.content),
|
||||
message,
|
||||
Snackbar.LENGTH_LONG
|
||||
)
|
||||
snackbar.addCallback(object : BaseCallback<Snackbar>() {
|
||||
override fun onShown(transientBottomBar: Snackbar?) {
|
||||
super.onShown(transientBottomBar)
|
||||
mIdlingResource?.setIdleState(false)
|
||||
}
|
||||
override fun onDismissed(transientBottomBar: Snackbar?, event: Int) {
|
||||
super.onDismissed(transientBottomBar, event)
|
||||
mIdlingResource?.setIdleState(true)
|
||||
}
|
||||
})
|
||||
snackbar.show()
|
||||
}
|
||||
|
||||
/**
|
||||
* Only called from test, creates and returns a new [BasicIdlingResource].
|
||||
*/
|
||||
|
||||
@@ -20,7 +20,6 @@ import h_mal.appttude.com.driver.utils.PermissionsUtils
|
||||
import org.kodein.di.KodeinAware
|
||||
import org.kodein.di.android.x.kodein
|
||||
import org.kodein.di.generic.instance
|
||||
import java.io.File
|
||||
|
||||
abstract class BaseFragment<V : BaseViewModel, VB : ViewBinding> : Fragment(), KodeinAware {
|
||||
|
||||
@@ -43,7 +42,6 @@ abstract class BaseFragment<V : BaseViewModel, VB : ViewBinding> : Fragment(), K
|
||||
multipleImage = true
|
||||
}
|
||||
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
@@ -169,4 +167,7 @@ abstract class BaseFragment<V : BaseViewModel, VB : ViewBinding> : Fragment(), K
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun showToast(message: String) = (activity as BaseActivity<*, *>).showToast(message)
|
||||
fun showSnackBar(message: String) = (activity as BaseActivity<*, *>).showSnackBar(message)
|
||||
}
|
||||
@@ -36,7 +36,7 @@ class FirebaseDatabaseSource {
|
||||
return data
|
||||
}
|
||||
|
||||
fun getDatabaseReferenceFromLink(link: String) = database.getReferenceFromUrl(link)
|
||||
fun getDatabaseRefFromPath(path: String) = database.getReference(path)
|
||||
|
||||
val users = database.getReference(USER_CONST)
|
||||
|
||||
@@ -46,6 +46,7 @@ class FirebaseDatabaseSource {
|
||||
fun getVehicleRef(uid: String) = getUserRef(uid).child(VEHICLE_PROFILE)
|
||||
fun getDriverRef(uid: String) = getUserRef(uid).child(DRIVER_PROFILE)
|
||||
fun getApprovalsRef(uid: String) = getUserRef(uid).child(APPROVALS)
|
||||
fun getDocumentApprovalRef(uid: String, document: String) = getApprovalsRef(uid).child(document)
|
||||
fun getArchiveRef(uid: String) = getUserRef(uid).child(ARCHIVE)
|
||||
fun getUserRoleRef(uid: String) = getUserRef(uid).child(PROFILE_ROLE)
|
||||
fun getDriverNumberRef(uid: String) = getUserRef(uid).child(DRIVER_NUMBER)
|
||||
|
||||
@@ -3,7 +3,6 @@ package h_mal.appttude.com.driver.ui.update
|
||||
import h_mal.appttude.com.driver.base.BaseActivity
|
||||
import h_mal.appttude.com.driver.data.FirebaseCompletion
|
||||
import h_mal.appttude.com.driver.databinding.UpdateActivityBinding
|
||||
import h_mal.appttude.com.driver.utils.displayToast
|
||||
import h_mal.appttude.com.driver.viewmodels.UpdateUserViewModel
|
||||
|
||||
class UpdateActivity : BaseActivity<UpdateUserViewModel, UpdateActivityBinding>() {
|
||||
@@ -11,7 +10,7 @@ class UpdateActivity : BaseActivity<UpdateUserViewModel, UpdateActivityBinding>(
|
||||
override fun onSuccess(data: Any?) {
|
||||
super.onSuccess(data)
|
||||
when (data) {
|
||||
is FirebaseCompletion.Changed -> displayToast(data.message)
|
||||
is FirebaseCompletion.Changed -> showToast(data.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,14 +33,6 @@ fun View.hide() {
|
||||
this.visibility = View.GONE
|
||||
}
|
||||
|
||||
fun Context.displayToast(message: String) {
|
||||
Toast.makeText(this, message, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
fun Fragment.displayToast(message: String) {
|
||||
requireContext().displayToast(message)
|
||||
}
|
||||
|
||||
fun EditText.setEnterPressedListener(action: () -> Unit) {
|
||||
setOnEditorActionListener(TextView.OnEditorActionListener { _, id, _ ->
|
||||
if (id == EditorInfo.IME_ACTION_DONE || id == EditorInfo.IME_NULL) {
|
||||
|
||||
5
app/src/main/res/drawable/baseline_check_24.xml
Normal file
5
app/src/main/res/drawable/baseline_check_24.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/>
|
||||
</vector>
|
||||
5
app/src/main/res/drawable/baseline_clear_24.xml
Normal file
5
app/src/main/res/drawable/baseline_clear_24.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
|
||||
</vector>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 86 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 34 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 49 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 125 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 224 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 330 KiB |
@@ -102,4 +102,7 @@
|
||||
<string name="not_submitted">Not submitted</string>
|
||||
<string name="empty_view_message">You have no drivers</string>
|
||||
<string name="approval_status">approval status</string>
|
||||
<string name="approve">Approve</string>
|
||||
<string name="deny">Deny</string>
|
||||
<string name="decline">Decline</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user