Skip to content

Commit

Permalink
Merge pull request #163 from Semper-Viventem/update-deppendencies
Browse files Browse the repository at this point in the history
The app patch 0.27.0-beta
  • Loading branch information
Semper-Viventem authored Jan 24, 2025
2 parents 9fd6400 + 5abd8a3 commit 10b3901
Show file tree
Hide file tree
Showing 37 changed files with 1,186 additions and 132 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ android {
minSdk = 29
targetSdk = 35

versionCode = 1708536361
versionName = "0.26.5-beta"
versionCode = 1708536362
versionName = "0.27.0-beta"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down
15 changes: 7 additions & 8 deletions app/src/main/java/f/cking/software/TheApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,24 @@ import org.koin.android.ext.android.getKoin
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin
import org.koin.core.context.stopKoin
import org.koin.dsl.module
import timber.log.Timber

class TheApp : Application() {

override fun onCreate() {
super.onCreate()
instance = this
applyDynamicColors()
initDi()
initTimber()
saveFirstLaunchTime()
}

fun restartKoin() {
stopKoin()
initDi()
}

private fun applyDynamicColors() {
DynamicColors.applyToActivitiesIfAvailable(this)
}
Expand All @@ -38,6 +43,7 @@ class TheApp : Application() {
DataModule(SHARED_PREF_NAME, DATABASE_NAME).module,
InteractorsModule.module,
UiModule.module,
module { single { this@TheApp } }
)
}
}
Expand All @@ -48,14 +54,7 @@ class TheApp : Application() {
}
}

fun restartKoin() {
stopKoin()
initDi()
}

companion object {
lateinit var instance: TheApp

const val SHARED_PREF_NAME = "app-prefs"
const val DATABASE_NAME = "app-database"
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/f/cking/software/data/DataModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class DataModule(
single { DevicesRepository(get()) }
single { PermissionHelper(get(), get(), get()) }
single { ActivityProvider() }
single { IntentHelper(get()) }
single { IntentHelper(get(), get()) }
single { RadarProfilesRepository(get()) }
single { LocationProvider(get(), get(), get(), get()) }
single { LocationRepository(get()) }
single { JournalRepository(get()) }
single { NotificationsHelper(get(), get()) }
single { NotificationsHelper(get(), get(), get()) }
single { PowerModeHelper(get()) }
single { TagsRepository(get()) }
}
Expand Down
56 changes: 55 additions & 1 deletion app/src/main/java/f/cking/software/data/helpers/IntentHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@ import android.bluetooth.BluetoothAdapter
import android.content.Intent
import android.net.Uri
import android.provider.Settings
import f.cking.software.data.helpers.IntentHelper.ScreenNavigation.BACKGROUND_LOCATION_DESCRIPTION
import f.cking.software.data.helpers.IntentHelper.ScreenNavigation.Companion.toNavigationCommand
import f.cking.software.data.helpers.IntentHelper.ScreenNavigation.MAIN
import f.cking.software.data.helpers.IntentHelper.ScreenNavigation.entries
import f.cking.software.openUrl
import f.cking.software.ui.MainActivity
import f.cking.software.ui.ScreenNavigationCommands
import f.cking.software.utils.navigation.NavigationCommand
import f.cking.software.utils.navigation.Router

class IntentHelper(private val activityProvider: ActivityProvider) {
class IntentHelper(
private val activityProvider: ActivityProvider,
private val router: Router,
) {

/**
* TODO: this code us unsafe
Expand Down Expand Up @@ -63,6 +74,46 @@ class IntentHelper(private val activityProvider: ActivityProvider) {
activity.openUrl(url)
}

fun openScreenIntent(screenName: ScreenNavigation): Intent {
val intent = Intent(activityProvider.requireActivity(), MainActivity::class.java)
intent.setAction(ACTION_OPEN_SCREEN)
intent.putExtra(SCREEN_NAME, screenName.name)
return intent
}

fun tryHandleIntent(intent: Intent): Boolean {
if (intent.isScreenNavigation()) {
val screenNavigation = ScreenNavigation.fromIntent(intent) ?: return false
router.navigate(screenNavigation.toNavigationCommand())
return true
}
return false
}

private fun Intent.isScreenNavigation(): Boolean {
return action == ACTION_OPEN_SCREEN
}

enum class ScreenNavigation {
MAIN,
BACKGROUND_LOCATION_DESCRIPTION;

companion object {

fun fromIntent(intent: Intent): ScreenNavigation? {
val name = intent.getStringExtra(SCREEN_NAME) ?: return null
return entries.firstOrNull { it.name == name }
}

fun ScreenNavigation.toNavigationCommand(): NavigationCommand {
return when (this) {
MAIN -> ScreenNavigationCommands.OpenMainScreen
BACKGROUND_LOCATION_DESCRIPTION -> ScreenNavigationCommands.OpenBackgroundLocationScreen
}
}
}
}

fun handleActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
val consumer = pendingConsumers[requestCode]
if (resultCode == Activity.RESULT_OK) {
Expand All @@ -76,5 +127,8 @@ class IntentHelper(private val activityProvider: ActivityProvider) {
private const val ACTIVITY_RESULT_SELECT_DIRECTORY = 1
private const val ACTIVITY_RESULT_SELECT_FILE = 2
private const val ACTIVITY_RESULT_CREATE_FILE = 3

private const val ACTION_OPEN_SCREEN = "action_open_screen"
private const val SCREEN_NAME = "screen_name"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ class LocationProvider(
}

fun isLocationAvailable(): Boolean {
return (locationManager?.isProviderEnabled(provider()) ?: false)
&& (locationManager?.isLocationEnabled ?: false)
return (locationManager?.isProviderEnabled(provider()) == true)
&& locationManager.isLocationEnabled
}

fun isActive(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import android.content.Intent
import android.provider.Settings
import androidx.core.app.NotificationCompat
import f.cking.software.R
import f.cking.software.data.helpers.IntentHelper.ScreenNavigation
import f.cking.software.domain.interactor.CheckProfileDetectionInteractor
import f.cking.software.ui.MainActivity
import kotlin.random.Random

class NotificationsHelper(
private val context: Context,
private val powerModeHelper: PowerModeHelper,
private val intentHelper: IntentHelper,
) {

private val notificationManager by lazy { context.getSystemService(NotificationManager::class.java) }
Expand All @@ -42,6 +44,7 @@ class NotificationsHelper(
is ServiceNotificationContent.NoDataYet -> context.getString(R.string.ble_scanner_is_started_but_no_data)
is ServiceNotificationContent.BluetoothIsTurnedOff -> context.getString(R.string.bluetooth_is_not_available_title)
is ServiceNotificationContent.LocationIsTurnedOff -> context.getString(R.string.location_is_turned_off_title)
is ServiceNotificationContent.BackgroundLocationIsRestricted -> context.getString(R.string.background_location_is_restricted)
}

val title = if (powerModeHelper.powerMode() == PowerModeHelper.PowerMode.POWER_SAVING) {
Expand Down Expand Up @@ -111,6 +114,17 @@ class NotificationsHelper(
)
}

fun notifyBackgroundLocationIsRestricted() {
notifyError(
title = context.getString(R.string.background_location_restricted_title),
content = context.getString(R.string.background_location_restricted_content),
button = NotificationButton(
intent = intentHelper.openScreenIntent(ScreenNavigation.BACKGROUND_LOCATION_DESCRIPTION),
text = context.getString(R.string.background_location_restricted_button),
)
)
}

fun notifyBluetoothIsTurnedOff() {
notifyError(
title = context.getString(R.string.bluetooth_is_not_available_title),
Expand Down Expand Up @@ -213,6 +227,8 @@ class NotificationsHelper(
object BluetoothIsTurnedOff : ServiceNotificationContent

object LocationIsTurnedOff : ServiceNotificationContent

object BackgroundLocationIsRestricted : ServiceNotificationContent
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import android.provider.Settings
import android.widget.Toast
import androidx.core.app.ActivityCompat
import f.cking.software.R
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow

class PermissionHelper(
private val context: Context,
Expand All @@ -21,6 +23,7 @@ class PermissionHelper(

private var pending: (() -> Unit)? = null
private var permissionRequestTime: Long? = null
private val backgroundPermissionState = MutableStateFlow(checkBackgroundLocationPermition())

fun checkBlePermissions(
onRequestPermissions: (permissions: Array<String>, permissionRequestCode: Int, pendingFun: () -> Unit) -> Unit = ::requestPermissions,
Expand Down Expand Up @@ -51,7 +54,7 @@ class PermissionHelper(
}
}

fun onPermissionGranted(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
fun onPermissionResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
val allPermissionsGranted = grantResults.all { it == PackageManager.PERMISSION_GRANTED }
val requestTime = permissionRequestTime
if (requestCode == PERMISSIONS_REQUEST_CODE) {
Expand All @@ -62,6 +65,7 @@ class PermissionHelper(
intentHelper.openAppSettings()
}
}
fetchBackgroundLocationPermission()
}

private fun requestPermissions(
Expand All @@ -82,6 +86,18 @@ class PermissionHelper(
return (BLE_PERMISSIONS + BACKGROUND_LOCATION).all { checkPermission(it) }
}

fun observeBackgroundLocationPermission(): Flow<Boolean> {
return backgroundPermissionState
}

fun checkBackgroundLocationPermition(): Boolean {
return checkPermission(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
}

private fun fetchBackgroundLocationPermission() {
backgroundPermissionState.value = checkBackgroundLocationPermition()
}

fun checkLocationPermission(): Boolean {
return checkPermission(Manifest.permission.ACCESS_FINE_LOCATION)
}
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/f/cking/software/data/repo/SettingsRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class SettingsRepository(
) {

private val silentModeState = MutableStateFlow(getSilentMode())
private val hideBackgroundLocationWarning = MutableStateFlow(getHideBackgroundLocationWarning())

fun setGarbagingTime(time: Long) {
sharedPreferences.edit().putLong(KEY_GARBAGING_TIME, time).apply()
Expand Down Expand Up @@ -60,6 +61,19 @@ class SettingsRepository(
sharedPreferences.edit().putBoolean(KEY_ENJOY_THE_APP_ANSWERED, value).apply()
}

fun setHideBackgroundLocationWarning(value: Long) {
sharedPreferences.edit().putLong(KEY_HIDE_BACKGROUND_LOCATION_WARNING, value).apply()
hideBackgroundLocationWarning.tryEmit(value)
}

fun getHideBackgroundLocationWarning(): Long {
return sharedPreferences.getLong(KEY_HIDE_BACKGROUND_LOCATION_WARNING, 0L)
}

fun observeHideBackgroundLocationWarning(): Flow<Long> {
return hideBackgroundLocationWarning
}

fun getEnjoyTheAppStartingPoint(): Long {
return sharedPreferences.getLong(KEY_ENJOY_THE_APP_STARTING_POINT, NO_ENJOY_THE_APP_STARTING_POINT)
}
Expand Down Expand Up @@ -99,6 +113,7 @@ class SettingsRepository(
private const val KEY_ENJOY_THE_APP_STARTING_POINT = "key_enjoy_the_app_starting_point"
private const val KEY_SILENT_NETWORK_MODE = "silent_network_mode"
private const val KEY_CURRENT_BATCH_SORTING_STRATEGY_ID = "key_current_batch_sorting_strategy_id"
private const val KEY_HIDE_BACKGROUND_LOCATION_WARNING = "key_hide_background_location_warning"

const val NO_APP_LAUNCH_TIME = -1L
const val NO_ENJOY_THE_APP_STARTING_POINT = -1L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object InteractorsModule {
factory { BackupDatabaseInteractor(get(), get()) }
factory { CreateBackupFileInteractor(get(), get()) }
factory { SelectBackupFileInteractor(get(), get()) }
factory { RestoreDatabaseInteractor(get(), get(), get()) }
factory { RestoreDatabaseInteractor(get(), get()) }
factory { SaveRadarProfile(get(), get()) }
factory { DeleteRadarProfile(get(), get()) }
factory { CheckDeviceLocationHistoryInteractor(get()) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
package f.cking.software.domain.interactor

import android.content.Context
import android.net.Uri
import com.jakewharton.processphoenix.ProcessPhoenix
import f.cking.software.TheApp
import f.cking.software.data.database.AppDatabase
import f.cking.software.data.helpers.IntentHelper
import f.cking.software.service.BgScanService

class RestoreDatabaseInteractor(
private val appDatabase: AppDatabase,
private val context: Context,
private val intentHelper: IntentHelper,
private val application: TheApp,
) {

suspend fun execute(uri: Uri) {
BgScanService.stop(context)
appDatabase.restoreDatabase(uri, context)
TheApp.instance.restartKoin()
ProcessPhoenix.triggerRebirth(context)
BgScanService.stop(application)
appDatabase.restoreDatabase(uri, application)
application.restartKoin()
ProcessPhoenix.triggerRebirth(application)
}
}
Loading

0 comments on commit 10b3901

Please sign in to comment.