forked from openMF/android-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
733 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
core/data/src/main/java/com/mifos/core/data/repository/PathTrackingRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.mifos.core.data.repository | ||
|
||
import com.mifos.core.objects.user.UserLocation | ||
|
||
/** | ||
* Created by Aditya Gupta on 06/08/23. | ||
*/ | ||
interface PathTrackingRepository { | ||
|
||
suspend fun getUserPathTracking(userId: Int): List<UserLocation> | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 11 additions & 54 deletions
65
core/database/src/main/java/com/mifos/core/objects/user/UserLocation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,24 @@ | ||
package com.mifos.core.objects.user | ||
|
||
import android.os.Parcel | ||
import android.os.Parcelable | ||
import android.os.Parcelable.Creator | ||
import com.google.gson.annotations.SerializedName | ||
import kotlinx.parcelize.Parcelize | ||
|
||
/** | ||
* Created by Rajan Maurya on 24/01/17. | ||
*/ | ||
class UserLocation : Parcelable { | ||
@SerializedName("user_id") | ||
var userId: Int? = null | ||
@Parcelize | ||
data class UserLocation( | ||
var user_id: Int? = null, | ||
|
||
@SerializedName("latlng") | ||
var latlng: String? = null | ||
var latlng: String? = null, | ||
|
||
@SerializedName("start_time") | ||
var startTime: String? = null | ||
var start_time: String? = null, | ||
|
||
@SerializedName("stop_time") | ||
var stopTime: String? = null | ||
var stop_time: String? = null, | ||
|
||
@SerializedName("date") | ||
var date: String? = null | ||
var dateFormat: String? = "dd MMMM yyyy HH:mm" | ||
var locale: String? = "en" | ||
|
||
constructor() {} | ||
|
||
override fun describeContents(): Int { | ||
return 0 | ||
} | ||
var date: String? = null, | ||
|
||
override fun writeToParcel(dest: Parcel, flags: Int) { | ||
dest.writeValue(userId) | ||
dest.writeString(latlng) | ||
dest.writeString(startTime) | ||
dest.writeString(stopTime) | ||
dest.writeString(date) | ||
dest.writeString(dateFormat) | ||
dest.writeString(locale) | ||
} | ||
var dateFormat: String? = "dd MMMM yyyy HH:mm", | ||
|
||
protected constructor(`in`: Parcel) { | ||
userId = `in`.readValue(Int::class.java.classLoader) as Int? | ||
latlng = `in`.readString() | ||
startTime = `in`.readString() | ||
stopTime = `in`.readString() | ||
date = `in`.readString() | ||
dateFormat = `in`.readString() | ||
locale = `in`.readString() | ||
} | ||
|
||
companion object { | ||
@JvmField | ||
val CREATOR: Creator<UserLocation> = object : Creator<UserLocation> { | ||
override fun createFromParcel(source: Parcel): UserLocation? { | ||
return UserLocation(source) | ||
} | ||
|
||
override fun newArray(size: Int): Array<UserLocation?> { | ||
return arrayOfNulls(size) | ||
} | ||
} | ||
} | ||
} | ||
var locale: String? = "en" | ||
) : Parcelable |
144 changes: 144 additions & 0 deletions
144
core/designsystem/src/main/java/com/mifos/core/designsystem/component/MifosPermissionBox.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package com.mifos.core.designsystem.component | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import android.content.pm.PackageManager | ||
import android.net.Uri | ||
import android.provider.Settings | ||
import androidx.activity.compose.rememberLauncherForActivityResult | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.DisposableEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.platform.LocalLifecycleOwner | ||
import androidx.core.app.ActivityCompat | ||
import androidx.core.content.ContextCompat | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleEventObserver | ||
|
||
@Composable | ||
fun PermissionBox( | ||
requiredPermissions: List<String>, | ||
title: Int, | ||
description: Int? = null, | ||
confirmButtonText: Int, | ||
dismissButtonText: Int, | ||
onGranted: @Composable (() -> Unit)? = null, | ||
) { | ||
val context = LocalContext.current | ||
val lifecycleOwner = LocalLifecycleOwner.current | ||
|
||
var permissionGranted by remember { | ||
mutableStateOf( | ||
requiredPermissions.all { | ||
ContextCompat.checkSelfPermission( | ||
context, | ||
it | ||
) == PackageManager.PERMISSION_GRANTED | ||
} | ||
) | ||
} | ||
|
||
var shouldShowPermissionRationale = | ||
requiredPermissions.all { | ||
(context as? Activity)?.let { it1 -> | ||
ActivityCompat.shouldShowRequestPermissionRationale( | ||
it1, it | ||
) | ||
} == true | ||
} | ||
|
||
var shouldDirectUserToApplicationSettings by remember { | ||
mutableStateOf(false) | ||
} | ||
|
||
val decideCurrentPermissionStatus: (Boolean, Boolean) -> String = | ||
{ permissionGranted, shouldShowPermissionRationale -> | ||
if (permissionGranted) "Granted" | ||
else if (shouldShowPermissionRationale) "Rejected" | ||
else "Denied" | ||
} | ||
|
||
var currentPermissionStatus by remember { | ||
mutableStateOf( | ||
decideCurrentPermissionStatus( | ||
permissionGranted, | ||
shouldShowPermissionRationale | ||
) | ||
) | ||
} | ||
|
||
val multiplePermissionLauncher = rememberLauncherForActivityResult( | ||
contract = ActivityResultContracts.RequestMultiplePermissions(), | ||
onResult = { permissionResults -> | ||
val isGranted = | ||
requiredPermissions.all { permissionResults[it] ?: false } | ||
|
||
permissionGranted = isGranted | ||
|
||
if (!isGranted) { | ||
shouldShowPermissionRationale = | ||
requiredPermissions.all { | ||
ActivityCompat.shouldShowRequestPermissionRationale( | ||
context as Activity, | ||
it | ||
) | ||
} | ||
} | ||
shouldDirectUserToApplicationSettings = | ||
!shouldShowPermissionRationale && !permissionGranted | ||
currentPermissionStatus = decideCurrentPermissionStatus( | ||
permissionGranted, | ||
shouldShowPermissionRationale | ||
) | ||
}) | ||
|
||
DisposableEffect(key1 = lifecycleOwner, effect = { | ||
val observer = LifecycleEventObserver { _, event -> | ||
if (event == Lifecycle.Event.ON_START && | ||
!permissionGranted && | ||
!shouldShowPermissionRationale | ||
) { | ||
multiplePermissionLauncher.launch(requiredPermissions.toTypedArray()) | ||
} | ||
} | ||
lifecycleOwner.lifecycle.addObserver(observer) | ||
onDispose { | ||
lifecycleOwner.lifecycle.removeObserver(observer) | ||
} | ||
}) | ||
|
||
if (shouldShowPermissionRationale) { | ||
MifosDialogBox( | ||
showDialogState = shouldShowPermissionRationale, | ||
onDismiss = { shouldShowPermissionRationale = false }, | ||
title = title, | ||
message = description, | ||
confirmButtonText = confirmButtonText, | ||
onConfirm = { | ||
shouldShowPermissionRationale = false | ||
multiplePermissionLauncher.launch(requiredPermissions.toTypedArray()) | ||
}, | ||
dismissButtonText = dismissButtonText | ||
) | ||
} | ||
|
||
if (shouldDirectUserToApplicationSettings) { | ||
Intent( | ||
Settings.ACTION_APPLICATION_DETAILS_SETTINGS, | ||
Uri.fromParts("package", context.packageName, null) | ||
).also { | ||
context.startActivity(it) | ||
} | ||
} | ||
|
||
if (permissionGranted) { | ||
if (onGranted != null) { | ||
onGranted() | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
core/domain/src/main/java/com/mifos/core/domain/use_cases/GetUserPathTrackingUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.mifos.core.domain.use_cases | ||
|
||
import com.mifos.core.common.utils.Resource | ||
import com.mifos.core.data.repository.PathTrackingRepository | ||
import com.mifos.core.objects.user.UserLocation | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import javax.inject.Inject | ||
|
||
class GetUserPathTrackingUseCase @Inject constructor(private val repository: PathTrackingRepository) { | ||
|
||
suspend operator fun invoke(userId: Int): Flow<Resource<List<UserLocation>>> = flow { | ||
try { | ||
emit(Resource.Loading()) | ||
val response = repository.getUserPathTracking(userId) | ||
emit(Resource.Success(response)) | ||
} catch (exception: Exception) { | ||
emit(Resource.Error(exception.message.toString())) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
plugins { | ||
alias(libs.plugins.mifos.android.feature) | ||
alias(libs.plugins.mifos.android.library.compose) | ||
alias(libs.plugins.mifos.android.library.jacoco) | ||
} | ||
|
||
android { | ||
namespace = "com.mifos.feature.path.tracking" | ||
} | ||
|
||
dependencies { | ||
implementation(projects.core.domain) | ||
|
||
implementation(libs.androidx.material) | ||
implementation(libs.accompanist.permission) | ||
|
||
implementation(libs.coil.kt.compose) | ||
testImplementation(libs.hilt.android.testing) | ||
testImplementation(projects.core.testing) | ||
androidTestImplementation(projects.core.testing) | ||
|
||
implementation(libs.maps.compose) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Oops, something went wrong.