-
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.
Redone location permission settings with user intervention. This arch…
…itecture will help in FGService control as well
- Loading branch information
Showing
15 changed files
with
609 additions
and
104 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
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
309 changes: 229 additions & 80 deletions
309
app/src/main/java/me/itissid/privyloci/MainActivity.kt
Large diffs are not rendered by default.
Oops, something went wrong.
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,3 @@ | ||
package me.itissid.privyloci | ||
|
||
class Permissions |
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,92 @@ | ||
package me.itissid.privyloci | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.booleanPreferencesKey | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.preferencesDataStore | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.withContext | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
// Per SO Answer: https://arc.net/l/quote/kebwdeqe | ||
private val Context.privyLociDataStore by preferencesDataStore("user_preferences") | ||
|
||
@Singleton | ||
class UserPreferences @Inject constructor( | ||
@ApplicationContext context: Context | ||
) { | ||
private val dataStore: DataStore<Preferences> = context.privyLociDataStore | ||
|
||
val wasFGPerrmissionRationaleDismissed = dataStore.data.map { | ||
it[fgPerrmissionRationaleDismissedKey] ?: false | ||
} | ||
val wasFGPersistentNotificationDismissed = dataStore.data.map { | ||
it[fgPersistentNotificationDismissedKey] ?: false | ||
} | ||
val wasReactivateFGRationaleDismissed = dataStore.data.map { | ||
it[reactivateFGRationaleDismissedKey] ?: false | ||
} | ||
|
||
val userPausedLocationCollection = dataStore.data.map { | ||
it[pausedLocationCollectionKey] ?: false | ||
} | ||
|
||
val userVisitedPermissionLauncher = dataStore.data.map { | ||
it[visitedPermissionLauncher] ?: false | ||
} | ||
|
||
|
||
suspend fun setFGPermissionRationaleDismissed(dismissed: Boolean) = | ||
withContext(Dispatchers.IO) { | ||
dataStore.edit { | ||
it[fgPerrmissionRationaleDismissedKey] = dismissed | ||
} | ||
} | ||
|
||
suspend fun setFGPersistentNotificationDismissed(dismissed: Boolean) = | ||
withContext(Dispatchers.IO) { | ||
dataStore.edit { | ||
it[fgPersistentNotificationDismissedKey] = dismissed | ||
} | ||
} | ||
|
||
suspend fun setReactivateFGRationaleDismissed(dismissed: Boolean) = | ||
withContext(Dispatchers.IO) { | ||
dataStore.edit { | ||
it[reactivateFGRationaleDismissedKey] = dismissed | ||
} | ||
} | ||
|
||
suspend fun setUserVisitedPermissionLauncher(dismissed: Boolean) = | ||
withContext(Dispatchers.IO) { | ||
dataStore.edit { | ||
it[visitedPermissionLauncher] = dismissed | ||
} | ||
} | ||
|
||
suspend fun setUserPausedLocationCollection(paused: Boolean) = | ||
withContext(Dispatchers.IO) { | ||
dataStore.edit { | ||
it[pausedLocationCollectionKey] = paused | ||
} | ||
} | ||
|
||
private companion object { | ||
val fgPerrmissionRationaleDismissedKey = | ||
booleanPreferencesKey("fg_permission_rationale_dismissed") | ||
val fgPersistentNotificationDismissedKey = | ||
booleanPreferencesKey("fg_persistent_notification_dismissed") | ||
val reactivateFGRationaleDismissedKey = | ||
booleanPreferencesKey("reactivate_fg_rationale_dismissed") | ||
|
||
val visitedPermissionLauncher = booleanPreferencesKey("visited_permission_launcher") | ||
val pausedLocationCollectionKey = booleanPreferencesKey("paused_location_collection") | ||
// More keys for other sensors and permissions. | ||
|
||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/me/itissid/privyloci/data/DataStoreModule.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,29 @@ | ||
package me.itissid.privyloci.data | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.PreferenceDataStoreFactory | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.preferencesDataStore | ||
import androidx.datastore.preferences.preferencesDataStoreFile | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object DataStoreModule { | ||
// Add DataStore related bindings here | ||
// private val Context.dataStore by preferencesDataStore("settings") | ||
|
||
// @Provides | ||
// @Singleton | ||
// fun providePreferencesDataStore(@ApplicationContext appContext: Context): DataStore<Preferences> = | ||
// PreferenceDataStoreFactory.create( | ||
// produceFIle = { appContext.preferencesDataStoreFile("user_preferences") } | ||
// ) | ||
// | ||
} |
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
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
Oops, something went wrong.