-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[issue-406] Introduce Dynamic Color #777
Merged
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6287142
feat: add "setting_item_dynamic_color" to strings.xml
6dd7144
feat: create DynamicColorSetting Composable
9f475b8
fix: change the order of modifiers
c93a652
feat: create ViewModel and UiState
a8a96cc
refactor: use ViewModel and UiState
51b88d0
refactor: rename
287c212
refactor: state hoisting and replace old class
575691e
feat: enable to switch Dynamic Color
9c4524f
feat: add Dynamic Color setting to SettingsDatastore
db6c954
feat: create DynamicColorSettingRepository
1b3bc45
feat: control DynamicColorSetting from ViewModel
d52d4c7
Merge branch 'main' into issue-406_dynamic_color
mona-apk 959db16
style: code format
d72b132
Merge remote-tracking branch 'origin/issue-406_dynamic_color' into is…
188fbe0
feat: add NewApi SuppressLint
b7502a6
Refactor and add tricks
takahirom cf43ce3
Merge remote-tracking branch 'origin/main' into issue-406_dynamic_color
takahirom ae0f0b3
Refactor default logic
takahirom 88275c5
Make AppViewModel single source of truth
takahirom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems difficult to apply dynamicLightColorScheme because Color.White is set in Text Composables 🤔