-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #777 from mona-apk/issue-406_dynamic_color
[issue-406] Introduce Dynamic Color
- Loading branch information
Showing
14 changed files
with
210 additions
and
14 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
24 changes: 24 additions & 0 deletions
24
...ndroidMain/kotlin/io/github/droidkaigi/confsched2022/data/setting/di/SettingDataModule.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,24 @@ | ||
package io.github.droidkaigi.confsched2022.data.setting.di | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import io.github.droidkaigi.confsched2022.data.SettingsDatastore | ||
import io.github.droidkaigi.confsched2022.data.setting.DataDynamicColorSettingRepository | ||
import io.github.droidkaigi.confsched2022.model.DynamicColorSettingRepository | ||
import javax.inject.Singleton | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
public class SettingDataModule { | ||
@Provides | ||
@Singleton | ||
public fun provideSessionsRepository( | ||
settingsDatastore: SettingsDatastore | ||
): DynamicColorSettingRepository { | ||
return DataDynamicColorSettingRepository( | ||
settingsDatastore = settingsDatastore | ||
) | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
...tlin/io/github/droidkaigi/confsched2022/data/setting/DataDynamicColorSettingRepository.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,17 @@ | ||
package io.github.droidkaigi.confsched2022.data.setting | ||
|
||
import io.github.droidkaigi.confsched2022.data.SettingsDatastore | ||
import io.github.droidkaigi.confsched2022.model.DynamicColorSettingRepository | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
public class DataDynamicColorSettingRepository( | ||
private val settingsDatastore: SettingsDatastore | ||
) : DynamicColorSettingRepository { | ||
override fun dynamicEnabledFlow(): Flow<Boolean> { | ||
return settingsDatastore.dynamicColorEnabled() | ||
} | ||
|
||
override suspend fun setDynamicColorEnabled(dynamicColorEnabled: Boolean) { | ||
settingsDatastore.setDynamicColorEnabled(dynamicColorEnabled = dynamicColorEnabled) | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
...mmonMain/kotlin/io/github/droidkaigi/confsched2022/model/DynamicColorSettingRepository.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,8 @@ | ||
package io.github.droidkaigi.confsched2022.model | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
|
||
public interface DynamicColorSettingRepository { | ||
public fun dynamicEnabledFlow(): Flow<Boolean> | ||
public suspend fun setDynamicColorEnabled(dynamicColorEnabled: Boolean) | ||
} |
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
5 changes: 5 additions & 0 deletions
5
...re/setting/src/main/java/io/github/droidkaigi/confsched2022/feature/setting/AppUiModel.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,5 @@ | ||
package io.github.droidkaigi.confsched2022.feature.setting | ||
|
||
data class AppUiModel( | ||
val isDynamicColorEnabled: Boolean, | ||
) |
49 changes: 49 additions & 0 deletions
49
...ing/src/main/java/io/github/droidkaigi/confsched2022/feature/setting/KaigiAppViewModel.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,49 @@ | ||
package io.github.droidkaigi.confsched2022.feature.setting | ||
|
||
import android.os.Build | ||
import android.os.Build.VERSION_CODES | ||
import androidx.annotation.ChecksSdkIntAtLeast | ||
import androidx.compose.runtime.State | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import app.cash.molecule.AndroidUiDispatcher | ||
import app.cash.molecule.RecompositionClock.ContextClock | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import io.github.droidkaigi.confsched2022.model.DroidKaigi2022Day | ||
import io.github.droidkaigi.confsched2022.model.DynamicColorSettingRepository | ||
import io.github.droidkaigi.confsched2022.ui.moleculeComposeState | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class KaigiAppViewModel @Inject constructor( | ||
private val dynamicColorSettingRepository: DynamicColorSettingRepository, | ||
) : ViewModel() { | ||
private val moleculeScope = | ||
CoroutineScope(viewModelScope.coroutineContext + AndroidUiDispatcher.Main) | ||
|
||
private val dynamicColorEnabledFlow: Flow<Boolean> = | ||
dynamicColorSettingRepository.dynamicEnabledFlow() | ||
|
||
val uiModel: State<AppUiModel> = moleculeScope.moleculeComposeState(clock = ContextClock) { | ||
val dynamicColorSettingEnabled by dynamicColorEnabledFlow.collectAsState( | ||
initial = DroidKaigi2022Day.defaultDyamicThemeDate() | ||
) | ||
AppUiModel(isDynamicColorEnabled = dynamicColorSettingEnabled && isSupportedDynamicColor()) | ||
} | ||
|
||
fun onDynamicColorToggle(isDynamic: Boolean) { | ||
viewModelScope.launch { | ||
dynamicColorSettingRepository.setDynamicColorEnabled(isDynamic) | ||
} | ||
} | ||
|
||
@ChecksSdkIntAtLeast(api = VERSION_CODES.S) | ||
private fun isSupportedDynamicColor(): Boolean { | ||
return Build.VERSION.SDK_INT >= VERSION_CODES.S | ||
} | ||
} |
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.