Skip to content

Commit

Permalink
Merge branch 'master' into about
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-gupta99 authored Jun 25, 2024
2 parents fdfb53a + f260d88 commit 5e209ee
Show file tree
Hide file tree
Showing 29 changed files with 733 additions and 396 deletions.
6 changes: 6 additions & 0 deletions core/data/src/main/java/com/mifos/core/data/di/DataModule.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.mifos.core.data.di


import com.mifos.core.data.repository.CenterDetailsRepository
import com.mifos.core.data.repository.CenterListRepository
import com.mifos.core.data.repository.CheckerInboxRepository
import com.mifos.core.data.repository.CheckerInboxTasksRepository
import com.mifos.core.data.repository.GroupDetailsRepository
import com.mifos.core.data.repository.GroupsListRepository
import com.mifos.core.data.repository.NewIndividualCollectionSheetRepository
import com.mifos.core.data.repository.PathTrackingRepository
import com.mifos.core.data.repository.ReportCategoryRepository
import com.mifos.core.data.repository_imp.CenterDetailsRepositoryImp
import com.mifos.core.data.repository_imp.CenterListRepositoryImp
Expand All @@ -15,6 +17,7 @@ import com.mifos.core.data.repository_imp.CheckerInboxTasksRepositoryImp
import com.mifos.core.data.repository_imp.GroupDetailsRepositoryImp
import com.mifos.core.data.repository_imp.GroupsListRepositoryImpl
import com.mifos.core.data.repository_imp.NewIndividualCollectionSheetRepositoryImp
import com.mifos.core.data.repository_imp.PathTrackingRepositoryImp
import com.mifos.core.data.repository_imp.ReportCategoryRepositoryImp
import dagger.Binds
import dagger.Module
Expand Down Expand Up @@ -50,4 +53,7 @@ abstract class DataModule {

@Binds
internal abstract fun bindReportCategoryRepository(impl: ReportCategoryRepositoryImp): ReportCategoryRepository

@Binds
internal abstract fun bindPathTrackingRepository(impl: PathTrackingRepositoryImp): PathTrackingRepository
}
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>

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mifos.mifosxdroid.activity.pathtracking
package com.mifos.core.data.repository_imp

import com.mifos.core.data.repository.PathTrackingRepository
import com.mifos.core.network.datamanager.DataManagerDataTable
import com.mifos.core.objects.user.UserLocation
import rx.Observable
Expand All @@ -11,7 +12,7 @@ import javax.inject.Inject
class PathTrackingRepositoryImp @Inject constructor(private val dataManagerDataTable: DataManagerDataTable) :
PathTrackingRepository {

override fun getUserPathTracking(userId: Int): Observable<List<UserLocation>> {
override suspend fun getUserPathTracking(userId: Int): List<UserLocation> {
return dataManagerDataTable.getUserPathTracking(userId)
}

Expand Down
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
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()
}
}
}
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()))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class DataManagerDataTable @Inject constructor(
* @param userId UserId Id
* @return List<UserLocation>
</UserLocation> */
fun getUserPathTracking(userId: Int): Observable<List<UserLocation>> {
suspend fun getUserPathTracking(userId: Int): List<UserLocation> {
return mBaseApiManager.dataTableApi.getUserPathTracking(userId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ interface DataTableService {
): Observable<GenericResponse>

@GET(APIEndPoint.DATATABLES + "/user_tracking/{userId}")
fun getUserPathTracking(@Path("userId") userId: Int): Observable<List<UserLocation>>
suspend fun getUserPathTracking(@Path("userId") userId: Int): List<UserLocation>
}
1 change: 1 addition & 0 deletions feature/path-tracking/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
23 changes: 23 additions & 0 deletions feature/path-tracking/build.gradle.kts
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.
21 changes: 21 additions & 0 deletions feature/path-tracking/proguard-rules.pro
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
Loading

0 comments on commit 5e209ee

Please sign in to comment.