Skip to content

Commit

Permalink
[fix]: monet setting not being applied to compose screens
Browse files Browse the repository at this point in the history
  • Loading branch information
F0x1d committed Nov 9, 2024
1 parent dd4d55d commit 65667b9
Show file tree
Hide file tree
Showing 21 changed files with 105 additions and 71 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies {
implementation(projects.feature.setup)

implementation(libs.timber)
implementation(libs.gson)
implementation(libs.viewpump)
implementation(libs.coil)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.f0x1d.logfox.arch.di
package com.f0x1d.logfox.di

import com.f0x1d.logfox.arch.annotations.GsonSkip
import com.f0x1d.logfox.database.annotations.GsonSkip
import com.google.gson.ExclusionStrategy
import com.google.gson.FieldAttributes
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import dagger.Module
import dagger.Provides
Expand All @@ -16,7 +17,7 @@ object GsonModule {

@Provides
@Singleton
fun provideGson() = GsonBuilder()
fun provideGson(): Gson = GsonBuilder()
.addSerializationExclusionStrategy(
object : ExclusionStrategy {
override fun shouldSkipField(f: FieldAttributes) = f.getAnnotation(GsonSkip::class.java) != null
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/com/f0x1d/logfox/receiver/BootReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class BootReceiver: BroadcastReceiver() {
class BootReceiver : BroadcastReceiver() {

@Inject
lateinit var appPreferences: AppPreferences
Expand All @@ -26,7 +26,7 @@ class BootReceiver: BroadcastReceiver() {
}

if (context.hasPermissionToReadLogs) {
Intent(context, com.f0x1d.logfox.feature.logging.service.presentation.LoggingService::class.java).let {
Intent(context, LoggingService::class.java).let {
if (startForegroundServiceAvailable)
context.startForegroundService(it)
else
Expand Down
5 changes: 4 additions & 1 deletion core/arch/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ plugins {
android.namespace = "com.f0x1d.logfox.arch"

dependencies {
implementation(projects.core.ui)
implementation(projects.core.uiCompose)
implementation(projects.core.preferences)

implementation(libs.insetter)
implementation(libs.viewpump)
implementation(libs.gson)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import javax.inject.Qualifier

@Module
@InstallIn(SingletonComponent::class)
object DispatchersModule {
internal object DispatchersModule {

@MainDispatcher
@Provides
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.f0x1d.logfox.arch.di

import com.f0x1d.logfox.arch.presentation.ui.fragment.compose.DynamicColorAvailabilityProvider
import com.f0x1d.logfox.preferences.shared.AppPreferences
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
internal object DynamicColorAvailabilityProviderModule {

@Provides
@Singleton
fun provideDynamicColorAvailabilityProvider(
appPreferences: AppPreferences,
): DynamicColorAvailabilityProvider = object : DynamicColorAvailabilityProvider {
override fun isDynamicColorAvailable(): Boolean = appPreferences.monetEnabled
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import javax.inject.Qualifier

@Module
@InstallIn(SingletonComponent::class)
object UtilsModule {
internal object UtilsModule {

@NullString
@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@ abstract class BaseActivity<T : ViewBinding>: AppCompatActivity(), SimpleLifecyc
}

override fun attachBaseContext(newBase: Context) {
val entryPoint = EntryPointAccessors.fromApplication(
context = newBase,
entryPoint = ViewPumpEntryPoint::class.java,
)
val entryPoint = EntryPointAccessors.fromApplication<ViewPumpEntryPoint>(newBase)

super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase, entryPoint.viewPump()))
super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase, entryPoint.viewPump))
}

protected fun snackbar(text: String) = binding.root.snackbar(text).apply {
Expand All @@ -65,6 +62,6 @@ abstract class BaseActivity<T : ViewBinding>: AppCompatActivity(), SimpleLifecyc
@EntryPoint
@InstallIn(SingletonComponent::class)
internal interface ViewPumpEntryPoint {
fun viewPump(): ViewPump
val viewPump: ViewPump
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,34 @@ import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import com.f0x1d.logfox.arch.databinding.FragmentComposeBinding
import com.f0x1d.logfox.arch.presentation.ui.fragment.BaseFragment
import com.f0x1d.logfox.ui.compose.theme.LogFoxTheme
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
import dagger.hilt.android.EntryPointAccessors
import dagger.hilt.components.SingletonComponent

abstract class BaseComposeFragment : BaseFragment<FragmentComposeBinding>() {

private val dynamicColorAvailabilityProvider: DynamicColorAvailabilityProvider by lazy {
EntryPointAccessors
.fromApplication<BaseComposeFragmentEntryPoint>(requireContext())
.dynamicColorAvailabilityProvider
}

override fun inflateBinding(
inflater: LayoutInflater,
container: ViewGroup?,
) = FragmentComposeBinding.inflate(inflater, container, false)

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.composeView.setup { Content() }
binding.composeView.setup {
LogFoxTheme(
dynamicColor = dynamicColorAvailabilityProvider.isDynamicColorAvailable(),
) {
Content()
}
}
}

@Composable
Expand All @@ -32,4 +49,10 @@ abstract class BaseComposeFragment : BaseFragment<FragmentComposeBinding>() {

setContent(content)
}

@EntryPoint
@InstallIn(SingletonComponent::class)
internal interface BaseComposeFragmentEntryPoint {
val dynamicColorAvailabilityProvider: DynamicColorAvailabilityProvider
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.f0x1d.logfox.arch.presentation.ui.fragment.compose

interface DynamicColorAvailabilityProvider {
fun isDynamicColorAvailable(): Boolean
}
2 changes: 0 additions & 2 deletions core/database/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ android {
}

dependencies {
implementation(projects.core.arch)

compileOnly(libs.androidx.compose.runtime)

implementation(libs.androidx.room)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.f0x1d.logfox.arch.annotations
package com.f0x1d.logfox.database.annotations

@Target(AnnotationTarget.FIELD)
annotation class GsonSkip
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.room.PrimaryKey
import androidx.room.Query
import androidx.room.TypeConverter
import androidx.room.Update
import com.f0x1d.logfox.arch.annotations.GsonSkip
import com.f0x1d.logfox.database.annotations.GsonSkip
import com.f0x1d.logfox.model.Identifiable
import com.f0x1d.logfox.model.logline.LogLevel
import kotlinx.coroutines.flow.Flow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import dagger.hilt.InstallIn
import dagger.hilt.android.EntryPointAccessors
import dagger.hilt.components.SingletonComponent

val Context.dateTimeFormatter get() = EntryPointAccessors.fromApplication(
context = this,
entryPoint = DateTimeFormatterEntryPoint::class.java,
).dateTimeFormatter()
val Context.dateTimeFormatter get() = EntryPointAccessors
.fromApplication<DateTimeFormatterEntryPoint>(this)
.dateTimeFormatter

@EntryPoint
@InstallIn(SingletonComponent::class)
private interface DateTimeFormatterEntryPoint {
fun dateTimeFormatter(): DateTimeFormatter
val dateTimeFormatter: DateTimeFormatter
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import dagger.hilt.InstallIn
import dagger.hilt.android.EntryPointAccessors
import dagger.hilt.components.SingletonComponent

val Context.appPreferences get() = EntryPointAccessors.fromApplication(
context = this,
entryPoint = AppPreferencesEntryPoint::class.java,
).appPreferences()
val Context.appPreferences get() = EntryPointAccessors
.fromApplication<AppPreferencesEntryPoint>(this)
.appPreferences

@EntryPoint
@InstallIn(SingletonComponent::class)
private interface AppPreferencesEntryPoint {
fun appPreferences(): AppPreferences
val appPreferences: AppPreferences
}
1 change: 0 additions & 1 deletion core/ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ plugins {
android.namespace = "com.f0x1d.logfox.ui"

dependencies {
implementation(projects.core.arch)
implementation(projects.core.preferences)

implementation(libs.insetter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.f0x1d.logfox.ui.view

import android.view.LayoutInflater
import android.view.inputmethod.InputMethodManager
import androidx.core.content.getSystemService
import androidx.preference.Preference
import com.f0x1d.logfox.arch.inputMethodManager
import com.f0x1d.logfox.strings.Strings
import com.f0x1d.logfox.ui.databinding.DialogTextBinding
import com.google.android.material.dialog.MaterialAlertDialogBuilder
Expand Down Expand Up @@ -35,7 +35,7 @@ fun Preference.setupAsEditTextPreference(
setSelection(text?.length ?: 0)

postDelayed({
context.inputMethodManager.showSoftInput(
context.getSystemService<InputMethodManager>()?.showSoftInput(
this,
InputMethodManager.SHOW_IMPLICIT
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.f0x1d.logfox.feature.apps.picker.AppsPickerResultHandler
import com.f0x1d.logfox.feature.apps.picker.presentation.AppsPickerState
import com.f0x1d.logfox.feature.apps.picker.presentation.AppsPickerViewModel
import com.f0x1d.logfox.feature.apps.picker.presentation.ui.compose.AppsPickerScreenContent
import com.f0x1d.logfox.ui.compose.theme.LogFoxTheme
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.collections.immutable.toImmutableSet
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -57,14 +56,12 @@ class AppsPickerFragment : BaseComposeFragment() {

@Composable
override fun Content() {
LogFoxTheme {
val state by uiState.collectAsState(initial = viewModel.currentState)
val state by uiState.collectAsState(initial = viewModel.currentState)

AppsPickerScreenContent(
state = state,
listener = listener,
)
}
AppsPickerScreenContent(
state = state,
listener = listener,
)
}

@SuppressLint("RestrictedApi")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import com.f0x1d.logfox.feature.recordings.list.presentation.RecordingsAction
import com.f0x1d.logfox.feature.recordings.list.presentation.RecordingsViewModel
import com.f0x1d.logfox.feature.recordings.list.presentation.ui.compose.RecordingsScreenContent
import com.f0x1d.logfox.navigation.Directions
import com.f0x1d.logfox.ui.compose.theme.LogFoxTheme
import com.f0x1d.logfox.ui.dialog.showAreYouSureClearDialog
import com.f0x1d.logfox.ui.dialog.showAreYouSureDeleteDialog
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -63,15 +62,13 @@ class RecordingsFragment : BaseComposeFragment() {

@Composable
override fun Content() {
LogFoxTheme {
val state by viewModel.state.collectAsState()
val state by viewModel.state.collectAsState()

RecordingsScreenContent(
state = state,
listener = listener,
snackbarHostState = snackbarHostState,
)
}
RecordingsScreenContent(
state = state,
listener = listener,
snackbarHostState = snackbarHostState,
)
}

private fun openDetails(recording: LogRecording?) = recording?.id?.also {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.f0x1d.logfox.arch.presentation.ui.fragment.compose.BaseComposeFragmen
import com.f0x1d.logfox.feature.setup.presentation.SetupAction
import com.f0x1d.logfox.feature.setup.presentation.SetupViewModel
import com.f0x1d.logfox.feature.setup.presentation.ui.compose.SetupScreenContent
import com.f0x1d.logfox.ui.compose.theme.LogFoxTheme
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -48,14 +47,12 @@ class SetupFragment : BaseComposeFragment() {

@Composable
override fun Content() {
LogFoxTheme {
val state by viewModel.state.collectAsState()

SetupScreenContent(
state = state,
listener = listener,
snackbarHostState = snackbarHostState,
)
}
val state by viewModel.state.collectAsState()

SetupScreenContent(
state = state,
listener = listener,
snackbarHostState = snackbarHostState,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,17 @@ const val SetupAdbDialogTestTag = "SetupAdbDialog"

@DayNightPreview
@Composable
private fun SetupScreenContentPreview() {
LogFoxTheme {
SetupScreenContent()
}
private fun SetupScreenContentPreview() = LogFoxTheme {
SetupScreenContent()
}

@DayNightPreview
@Composable
private fun SetupScreenContentWithDialogPreview() {
LogFoxTheme {
SetupScreenContent(
state = SetupState(
showAdbDialog = true,
adbCommand = "HESOYAM",
)
private fun SetupScreenContentWithDialogPreview() = LogFoxTheme {
SetupScreenContent(
state = SetupState(
showAdbDialog = true,
adbCommand = "HESOYAM",
)
}
)
}

0 comments on commit 65667b9

Please sign in to comment.