Skip to content

Commit

Permalink
Update project
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbel committed Nov 25, 2024
1 parent 3f62bbe commit a5e5e35
Show file tree
Hide file tree
Showing 51 changed files with 510 additions and 492 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@file:Suppress("DEPRECATION")

package org.michaelbel.movies.common.ktx

import android.content.Context
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os.Build

private val Context.packageInfo: PackageInfo
get() {
return if (Build.VERSION.SDK_INT >= 33) {
packageManager.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(0L))
} else {
packageManager.getPackageInfo(packageName, 0)
}
}

val Context.versionName: String
get() = packageInfo.versionName.orEmpty()

val Context.versionCode: Long
get() = if (Build.VERSION.SDK_INT >= 28) packageInfo.longVersionCode else packageInfo.versionCode.toLong()
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.michaelbel.movies.common.ktx

import android.content.Context
import android.content.Intent
import android.os.Build
import android.provider.Settings

val Context.appNotificationSettingsIntent: Intent
get() {
val intent = Intent()
when {
Build.VERSION.SDK_INT >= 26 -> {
intent.action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
intent.putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
}
else -> {
intent.action = "android.settings.APP_NOTIFICATION_SETTINGS"
intent.putExtra("app_package", packageName)
intent.putExtra("app_uid", applicationInfo.uid)
}
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
return intent
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,29 @@ import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module
import org.michaelbel.movies.analytics.di.moviesAnalyticsKoinModule
import org.michaelbel.movies.common.dispatchers.di.dispatchersKoinModule
import org.michaelbel.movies.interactor.AboutInteractor
import org.michaelbel.movies.interactor.LocaleInteractor
import org.michaelbel.movies.interactor.SettingsUiInteractor
import org.michaelbel.movies.interactor.impl.AboutInteractorImpl
import org.michaelbel.movies.interactor.impl.LocaleInteractorImpl
import org.michaelbel.movies.interactor.impl.SettingsUiInteractorImpl
import org.michaelbel.movies.persistence.database.di.moviesDatabaseKoinModule
import org.michaelbel.movies.repository.di.repositoryKoinModule

actual val interactorLocaleKoinModule = module {
actual val localeInteractorKoinModule = module {
includes(
dispatchersKoinModule,
repositoryKoinModule,
moviesDatabaseKoinModule,
moviesAnalyticsKoinModule
)
singleOf(::LocaleInteractorImpl) { bind<LocaleInteractor>() }
}

actual val aboutInteractorKoinModule = module {
singleOf(::AboutInteractorImpl) { bind<AboutInteractor>() }
}

actual val settingsUiInteractorKoinModule = module {
singleOf(::SettingsUiInteractorImpl) { bind<SettingsUiInteractor>() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.michaelbel.movies.interactor.impl

import android.content.Context
import org.michaelbel.movies.common.ktx.versionCode
import org.michaelbel.movies.common.ktx.versionName
import org.michaelbel.movies.interactor.AboutInteractor

class AboutInteractorImpl(
private val context: Context
): AboutInteractor {

override val versionName: String
get() = context.versionName

override val versionCode: Long
get() = context.versionCode
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package org.michaelbel.movies.interactor.impl

import android.Manifest
import android.app.Activity
import android.os.Build
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.ChecksSdkIntAtLeast
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import org.michaelbel.movies.common.ktx.appNotificationSettingsIntent
import org.michaelbel.movies.interactor.SettingsUiInteractor

class SettingsUiInteractorImpl: SettingsUiInteractor {

override val isNavigationIconVisible: Boolean
get() = false

override val isLanguageFeatureEnabled: Boolean
get() = true

override val isThemeFeatureEnabled: Boolean
get() = true

override val isFeedViewFeatureEnabled: Boolean
get() = true

override val isMovieListFeatureEnabled: Boolean
get() = true

override val isGenderFeatureEnabled: Boolean
@ChecksSdkIntAtLeast(34) get() = Build.VERSION.SDK_INT >= 34

override val isNotificationsFeatureEnabled: Boolean
@ChecksSdkIntAtLeast(33) get() = Build.VERSION.SDK_INT >= 33

override val isBiometricFeatureEnabled: Boolean
get() = true

override val isWidgetFeatureEnabled: Boolean
@ChecksSdkIntAtLeast(26) get() = Build.VERSION.SDK_INT >= 26

override val isTileFeatureEnabled: Boolean
@ChecksSdkIntAtLeast(33) get() = Build.VERSION.SDK_INT >= 33

override val isAppIconFeatureEnabled: Boolean
get() = true

override val isScreenshotFeatureEnabled: Boolean
get() = true

override val isGithubFeatureEnabled: Boolean
get() = true

override val isReviewAppFeatureEnabled: Boolean
get() = true

override val isUpdateAppFeatureEnabled: Boolean
get() = true

override val isAboutFeatureEnabled: Boolean
get() = true

override val bottomBarModifier: Modifier
get() = Modifier

@Composable
override fun navigateToAppNotificationSettings(): () -> Unit {
val resultContract = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {}
val context = LocalContext.current
return { resultContract.launch(context.appNotificationSettingsIntent) }
}

@Composable
override fun rememberPostNotificationsPermissionHandler(
areNotificationsEnabled: Boolean,
onPermissionGranted: () -> Unit,
onPermissionDenied: () -> Unit
): () -> Unit {
val context = LocalContext.current
val postNotificationsPermissionLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.RequestPermission()
) { granted ->
when {
granted -> onPermissionGranted()
else -> {
if (Build.VERSION.SDK_INT >= 33) {
val shouldRequest = (context as Activity).shouldShowRequestPermissionRationale(
Manifest.permission.POST_NOTIFICATIONS)
if (!shouldRequest) {
onPermissionDenied()
}
}
}
}
}
val resultContract = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {}
return {
if (areNotificationsEnabled) {
val intent = context.appNotificationSettingsIntent
resultContract.launch(intent)
} else if (Build.VERSION.SDK_INT >= 33) {
postNotificationsPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.michaelbel.movies.interactor

interface AboutInteractor {

val versionName: String

val versionCode: Long
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,19 @@ interface SettingsInteractor {

suspend fun isBiometricEnabledAsync(): Boolean

suspend fun selectTheme(
appTheme: AppTheme
)
suspend fun selectTheme(appTheme: AppTheme)

suspend fun selectFeedView(
feedView: FeedView
)
suspend fun selectFeedView(feedView: FeedView)

suspend fun selectMovieList(
movieList: MovieList
)
suspend fun selectMovieList(movieList: MovieList)

suspend fun setDynamicColors(
value: Boolean
)
suspend fun setDynamicColors(value: Boolean)

suspend fun setPaletteKey(
paletteKey: Int
)
suspend fun setPaletteKey(paletteKey: Int)

suspend fun setSeedColor(
seedColor: Int
)
suspend fun setSeedColor(seedColor: Int)

suspend fun setBiometricEnabled(
enabled: Boolean
)
suspend fun setBiometricEnabled(enabled: Boolean)

suspend fun setScreenshotBlockEnabled(
enabled: Boolean
)
suspend fun setScreenshotBlockEnabled(enabled: Boolean)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.michaelbel.movies.interactor

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier

interface SettingsUiInteractor {

val isNavigationIconVisible: Boolean

val isLanguageFeatureEnabled: Boolean

val isThemeFeatureEnabled: Boolean

val isFeedViewFeatureEnabled: Boolean

val isMovieListFeatureEnabled: Boolean

val isGenderFeatureEnabled: Boolean

val isNotificationsFeatureEnabled: Boolean

val isBiometricFeatureEnabled: Boolean

val isWidgetFeatureEnabled: Boolean

val isTileFeatureEnabled: Boolean

val isAppIconFeatureEnabled: Boolean

val isScreenshotFeatureEnabled: Boolean

val isGithubFeatureEnabled: Boolean

val isReviewAppFeatureEnabled: Boolean

val isUpdateAppFeatureEnabled: Boolean

val isAboutFeatureEnabled: Boolean

val bottomBarModifier: Modifier

@Composable
fun navigateToAppNotificationSettings(): () -> Unit

@Composable
fun rememberPostNotificationsPermissionHandler(
areNotificationsEnabled: Boolean,
onPermissionGranted: () -> Unit,
onPermissionDenied: () -> Unit
): () -> Unit
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.michaelbel.movies.interactor.di

import org.koin.core.module.Module
import org.koin.core.module.dsl.bind
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module
Expand Down Expand Up @@ -32,7 +33,9 @@ val interactorKoinModule = module {
repositoryKoinModule,
moviesDatabaseKoinModule,
moviesAnalyticsKoinModule,
interactorLocaleKoinModule
localeInteractorKoinModule,
aboutInteractorKoinModule,
settingsUiInteractorKoinModule
)
singleOf(::AccountInteractorImpl) { bind<AccountInteractor>() }
singleOf(::AuthenticationInteractorImpl) { bind<AuthenticationInteractor>() }
Expand All @@ -55,4 +58,8 @@ val interactorKoinModule = module {
get<LocaleInteractor>()
)
}
}
}

expect val localeInteractorKoinModule: Module
expect val aboutInteractorKoinModule: Module
expect val settingsUiInteractorKoinModule: Module

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,27 @@ import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module
import org.michaelbel.movies.analytics.di.moviesAnalyticsKoinModule
import org.michaelbel.movies.common.dispatchers.di.dispatchersKoinModule
import org.michaelbel.movies.interactor.AboutInteractor
import org.michaelbel.movies.interactor.LocaleInteractor
import org.michaelbel.movies.interactor.SettingsUiInteractor
import org.michaelbel.movies.interactor.impl.AboutInteractorImpl
import org.michaelbel.movies.interactor.impl.LocaleInteractorImpl
import org.michaelbel.movies.interactor.impl.SettingsUiInteractorImpl
import org.michaelbel.movies.persistence.database.di.moviesDatabaseKoinModule

actual val interactorLocaleKoinModule = module {
actual val localeInteractorKoinModule = module {
includes(
dispatchersKoinModule,
moviesDatabaseKoinModule,
moviesAnalyticsKoinModule
)
singleOf(::LocaleInteractorImpl) { bind<LocaleInteractor>() }
}

actual val aboutInteractorKoinModule = module {
singleOf(::AboutInteractorImpl) { bind<AboutInteractor>() }
}

actual val settingsUiInteractorKoinModule = module {
singleOf(::SettingsUiInteractorImpl) { bind<SettingsUiInteractor>() }
}
Loading

0 comments on commit a5e5e35

Please sign in to comment.