Skip to content

Commit

Permalink
Update project
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbel committed Nov 24, 2024
1 parent 46f92d0 commit 80b3a75
Show file tree
Hide file tree
Showing 19 changed files with 173 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.michaelbel.movies.common.notify.di

import org.koin.core.module.dsl.bind
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module
import org.michaelbel.movies.common.notify.NotifyManager
import org.michaelbel.movies.common.notify.impl.NotifyManagerImpl

actual val notifyKoinModule = module {
singleOf(::NotifyManagerImpl) { bind<NotifyManager>() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.michaelbel.movies.common.notify.impl

import android.content.Context
import org.michaelbel.movies.common.ktx.notificationManager
import org.michaelbel.movies.common.notify.NotifyManager

internal class NotifyManagerImpl(
private val context: Context
): NotifyManager {

override val areNotificationsEnabled: Boolean
get() = context.notificationManager.areNotificationsEnabled()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.michaelbel.movies.common.notify

interface NotifyManager {

val areNotificationsEnabled: Boolean
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.michaelbel.movies.common.notify.di

import org.koin.core.module.Module

expect val notifyKoinModule: Module
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.michaelbel.movies.common.notify.di

import org.koin.core.module.dsl.bind
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module
import org.michaelbel.movies.common.notify.NotifyManager
import org.michaelbel.movies.common.notify.impl.NotifyManagerImpl

actual val notifyKoinModule = module {
singleOf(::NotifyManagerImpl) { bind<NotifyManager>() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.michaelbel.movies.common.notify.impl

import org.michaelbel.movies.common.notify.NotifyManager

internal class NotifyManagerImpl: NotifyManager {

override val areNotificationsEnabled: Boolean
get() = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.michaelbel.movies.common.notify.di

import org.koin.core.module.dsl.bind
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module
import org.michaelbel.movies.common.notify.NotifyManager
import org.michaelbel.movies.common.notify.impl.NotifyManagerImpl

actual val notifyKoinModule = module {
singleOf(::NotifyManagerImpl) { bind<NotifyManager>() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.michaelbel.movies.common.notify.impl

import org.michaelbel.movies.common.notify.NotifyManager

internal class NotifyManagerImpl: NotifyManager {

override val areNotificationsEnabled: Boolean
get() = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.michaelbel.movies.common.notify.di

import org.koin.core.module.dsl.bind
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module
import org.michaelbel.movies.common.notify.NotifyManager
import org.michaelbel.movies.common.notify.impl.NotifyManagerImpl

actual val notifyKoinModule = module {
singleOf(::NotifyManagerImpl) { bind<NotifyManager>() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.michaelbel.movies.common.notify.impl

import org.michaelbel.movies.common.notify.NotifyManager

internal class NotifyManagerImpl: NotifyManager {

override val areNotificationsEnabled: Boolean
get() = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.michaelbel.movies.common.notify.di

import org.koin.core.module.dsl.bind
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module
import org.michaelbel.movies.common.notify.NotifyManager
import org.michaelbel.movies.common.notify.impl.NotifyManagerImpl

actual val notifyKoinModule = module {
singleOf(::NotifyManagerImpl) { bind<NotifyManager>() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.michaelbel.movies.common.notify.impl

import org.michaelbel.movies.common.notify.NotifyManager

internal class NotifyManagerImpl: NotifyManager {

override val areNotificationsEnabled: Boolean
get() = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.michaelbel.movies.settings.ktx

import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import org.michaelbel.movies.ui.ktx.appNotificationSettingsIntent

@Composable
actual fun openAppNotificationSettings(): () -> Unit {
val resultContract = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {}
val context = LocalContext.current
return { resultContract.launch(context.appNotificationSettingsIntent) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import org.koin.androidx.compose.koinViewModel
import org.michaelbel.movies.common.MOVIES_GITHUB_URL
import org.michaelbel.movies.common.browser.openUrl
import org.michaelbel.movies.common.gender.GrammaticalGender
import org.michaelbel.movies.common.ktx.notificationManager
import org.michaelbel.movies.interactor.entity.AppLanguage
import org.michaelbel.movies.notifications.ktx.rememberPostNotificationsPermissionHandler
import org.michaelbel.movies.settings.SettingsViewModel
import org.michaelbel.movies.settings.ktx.currentGrammaticalGender
import org.michaelbel.movies.settings.ktx.iconSnackbarTextRes
import org.michaelbel.movies.settings.ktx.isDebug
import org.michaelbel.movies.settings.ktx.openAppNotificationSettings
import org.michaelbel.movies.settings.ktx.requestTileService
import org.michaelbel.movies.settings.ktx.supportSetRequestedApplicationGrammaticalGender
import org.michaelbel.movies.settings.ktx.versionCode
Expand All @@ -53,7 +53,6 @@ import org.michaelbel.movies.settings.model.isWidgetFeatureEnabled
import org.michaelbel.movies.ui.appicon.IconAlias
import org.michaelbel.movies.ui.appicon.enabledIcon
import org.michaelbel.movies.ui.appicon.setIcon
import org.michaelbel.movies.ui.ktx.appNotificationSettingsIntent
import org.michaelbel.movies.ui.ktx.collectAsStateCommon
import org.michaelbel.movies.ui.ktx.displayCutoutWindowInsets
import org.michaelbel.movies.ui.lifecycle.OnResume
Expand All @@ -74,14 +73,13 @@ fun SettingsRoute(
val isBiometricEnabled by viewModel.isBiometricEnabled.collectAsStateCommon()
val isScreenshotBlockEnabled by viewModel.isScreenshotBlockEnabled.collectAsStateCommon()
val appVersionData by viewModel.appVersionData.collectAsStateCommon()
var areNotificationsEnabled by remember { mutableStateOf(viewModel.areNotificationsEnabled) }
val openAppNotificationSettings = openAppNotificationSettings()

val context = LocalContext.current
val resultContract = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {}
val toolbarColor = MaterialTheme.colorScheme.primary.toArgb()

val notificationManager by remember { mutableStateOf(context.notificationManager) }
var areNotificationsEnabled by remember { mutableStateOf(notificationManager.areNotificationsEnabled()) }

val scope = rememberCoroutineScope()
val snackbarHostState = remember { SnackbarHostState() }
val permissionMessage = stringResource(MoviesStrings.settings_post_notifications_should_request)
Expand All @@ -94,15 +92,11 @@ fun SettingsRoute(
duration = SnackbarDuration.Long
)
if (result == SnackbarResult.ActionPerformed) {
resultContract.launch(context.appNotificationSettingsIntent)
openAppNotificationSettings()
}
}
}

OnResume {
areNotificationsEnabled = notificationManager.areNotificationsEnabled()
}

val currentGrammaticalGender by remember { mutableStateOf(context.currentGrammaticalGender) }

val onShowSnackbar: (String) -> Unit = { message ->
Expand Down Expand Up @@ -172,7 +166,7 @@ fun SettingsRoute(
isEnabled = areNotificationsEnabled,
onClick = rememberPostNotificationsPermissionHandler(
areNotificationsEnabled = areNotificationsEnabled,
onPermissionGranted = { areNotificationsEnabled = notificationManager.areNotificationsEnabled() },
onPermissionGranted = { areNotificationsEnabled = viewModel.areNotificationsEnabled },
onPermissionDenied = onShowPermissionSnackbar
)
),
Expand Down Expand Up @@ -233,4 +227,8 @@ fun SettingsRoute(
isNavigationIconVisible = false,
modifier = modifier
)

OnResume {
areNotificationsEnabled = viewModel.areNotificationsEnabled
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.michaelbel.movies.common.ThemeData
import org.michaelbel.movies.common.appearance.FeedView
import org.michaelbel.movies.common.biometric.BiometricController2
import org.michaelbel.movies.common.list.MovieList
import org.michaelbel.movies.common.notify.NotifyManager
import org.michaelbel.movies.common.theme.AppTheme
import org.michaelbel.movies.common.version.AppVersionData
import org.michaelbel.movies.common.viewmodel.BaseViewModel
Expand All @@ -26,15 +27,21 @@ import org.michaelbel.movies.platform.update.UpdateService

class SettingsViewModel(
biometricController: BiometricController2,
private val notifyManager: NotifyManager,
private val interactor: Interactor,
private val reviewService: ReviewService,
private val updateService: UpdateService,
appService: AppService
private val appService: AppService
): BaseViewModel(), DefaultLifecycleObserver {

val isReviewFeatureEnabled = appService.flavor == Flavor.Gms
val isReviewFeatureEnabled: Boolean
get() = appService.flavor == Flavor.Gms

val isUpdateFeatureEnabled = appService.flavor == Flavor.Gms
val isUpdateFeatureEnabled: Boolean
get() = appService.flavor == Flavor.Gms

val areNotificationsEnabled: Boolean
get() = notifyManager.areNotificationsEnabled

val themeData: StateFlow<ThemeData> = interactor.themeData
.stateIn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package org.michaelbel.movies.settings.di
import org.koin.core.module.dsl.viewModel
import org.koin.dsl.module
import org.michaelbel.movies.common.biometric.di.biometricKoinModule2
import org.michaelbel.movies.common.notify.di.notifyKoinModule
import org.michaelbel.movies.interactor.di.interactorKoinModule
import org.michaelbel.movies.settings.SettingsViewModel

val settingsKoinModule = module {
includes(
biometricKoinModule2,
notifyKoinModule,
interactorKoinModule
)
viewModel { SettingsViewModel(get(), get(), get(), get(), get()) }
viewModel { SettingsViewModel(get(), get(), get(), get(), get(), get()) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.michaelbel.movies.settings.ktx

import androidx.compose.runtime.Composable

@Composable
expect fun openAppNotificationSettings(): () -> Unit
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.michaelbel.movies.settings.ktx

import androidx.compose.runtime.Composable

@Composable
actual fun openAppNotificationSettings(): () -> Unit {
return {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.michaelbel.movies.settings.ktx

import androidx.compose.runtime.Composable

@Composable
actual fun openAppNotificationSettings(): () -> Unit {
return {}
}

0 comments on commit 80b3a75

Please sign in to comment.