mirror of
https://github.com/Docile-Alligator/Infinity-For-Reddit.git
synced 2026-02-05 01:45:39 +00:00
Fix theme issues in AppTheme.
This commit is contained in:
@ -23,6 +23,7 @@ import ml.docilealligator.infinityforreddit.commentfilter.CommentFilterUsage;
|
||||
import ml.docilealligator.infinityforreddit.commentfilter.CommentFilterUsageDao;
|
||||
import ml.docilealligator.infinityforreddit.customtheme.CustomTheme;
|
||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeDao;
|
||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeDaoKt;
|
||||
import ml.docilealligator.infinityforreddit.multireddit.AnonymousMultiredditSubreddit;
|
||||
import ml.docilealligator.infinityforreddit.multireddit.AnonymousMultiredditSubredditDao;
|
||||
import ml.docilealligator.infinityforreddit.multireddit.AnonymousMultiredditSubredditDaoKt;
|
||||
@ -85,6 +86,8 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
||||
|
||||
public abstract CustomThemeDao customThemeDao();
|
||||
|
||||
public abstract CustomThemeDaoKt customThemeDaoKt();
|
||||
|
||||
public abstract RecentSearchQueryDao recentSearchQueryDao();
|
||||
|
||||
public abstract ReadPostDao readPostDao();
|
||||
|
||||
@ -8,8 +8,6 @@ import androidx.room.Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import kotlinx.coroutines.flow.Flow;
|
||||
|
||||
@Dao
|
||||
public interface CustomThemeDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
@ -42,15 +40,6 @@ public interface CustomThemeDao {
|
||||
@Query("SELECT * FROM custom_themes WHERE is_amoled_theme = 1 LIMIT 1")
|
||||
LiveData<CustomTheme> getAmoledCustomThemeLiveData();
|
||||
|
||||
@Query("SELECT * FROM custom_themes WHERE is_light_theme = 1 LIMIT 1")
|
||||
Flow<CustomTheme> getLightCustomThemeFlow();
|
||||
|
||||
@Query("SELECT * FROM custom_themes WHERE is_dark_theme = 1 LIMIT 1")
|
||||
Flow<CustomTheme> getDarkCustomThemeFlow();
|
||||
|
||||
@Query("SELECT * FROM custom_themes WHERE is_amoled_theme = 1 LIMIT 1")
|
||||
Flow<CustomTheme> getAmoledCustomThemeFlow();
|
||||
|
||||
@Query("SELECT * FROM custom_themes WHERE name = :name COLLATE NOCASE LIMIT 1")
|
||||
CustomTheme getCustomTheme(String name);
|
||||
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
package ml.docilealligator.infinityforreddit.customtheme
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Query
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface CustomThemeDaoKt {
|
||||
@Query("SELECT * FROM custom_themes WHERE is_light_theme = 1 LIMIT 1")
|
||||
fun getLightCustomThemeFlow(): Flow<CustomTheme?>
|
||||
|
||||
@Query("SELECT * FROM custom_themes WHERE is_dark_theme = 1 LIMIT 1")
|
||||
fun getDarkCustomThemeFlow(): Flow<CustomTheme?>
|
||||
|
||||
@Query("SELECT * FROM custom_themes WHERE is_amoled_theme = 1 LIMIT 1")
|
||||
fun getAmoledCustomThemeFlow(): Flow<CustomTheme?>
|
||||
}
|
||||
@ -23,9 +23,9 @@ public class LocalCustomThemeRepository {
|
||||
mCurrentDarkCustomTheme = redditDataRoomDatabase.customThemeDao().getDarkCustomThemeLiveData();
|
||||
mCurrentAmoledCustomTheme = redditDataRoomDatabase.customThemeDao().getAmoledCustomThemeLiveData();
|
||||
|
||||
mCurrentLightCustomThemeFlow = redditDataRoomDatabase.customThemeDao().getLightCustomThemeFlow();
|
||||
mCurrentDarkCustomThemeFlow = redditDataRoomDatabase.customThemeDao().getDarkCustomThemeFlow();
|
||||
mCurrentAmoledCustomThemeFlow = redditDataRoomDatabase.customThemeDao().getAmoledCustomThemeFlow();
|
||||
mCurrentLightCustomThemeFlow = redditDataRoomDatabase.customThemeDaoKt().getLightCustomThemeFlow();
|
||||
mCurrentDarkCustomThemeFlow = redditDataRoomDatabase.customThemeDaoKt().getDarkCustomThemeFlow();
|
||||
mCurrentAmoledCustomThemeFlow = redditDataRoomDatabase.customThemeDaoKt().getAmoledCustomThemeFlow();
|
||||
}
|
||||
|
||||
LiveData<List<CustomTheme>> getAllCustomThemes() {
|
||||
|
||||
@ -6,9 +6,12 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import ml.docilealligator.infinityforreddit.Infinity
|
||||
import ml.docilealligator.infinityforreddit.customtheme.CustomTheme
|
||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper
|
||||
@ -23,17 +26,21 @@ val LocalAppTheme = staticCompositionLocalOf<CustomTheme> {
|
||||
fun AppTheme(themeType: Int, content: @Composable () -> Unit) {
|
||||
val context = LocalContext.current
|
||||
val localCustomThemeRepository = LocalCustomThemeRepository(((context.applicationContext) as Infinity).mRedditDataRoomDatabase)
|
||||
var themeLoaded by remember { mutableStateOf(false) }
|
||||
|
||||
val currentThemeFlow = when(themeType) {
|
||||
CustomThemeSharedPreferencesUtils.LIGHT -> localCustomThemeRepository.currentLightCustomThemeFlow
|
||||
CustomThemeSharedPreferencesUtils.DARK -> localCustomThemeRepository.currentDarkCustomThemeFlow
|
||||
CustomThemeSharedPreferencesUtils.AMOLED -> localCustomThemeRepository.currentAmoledCustomThemeFlow
|
||||
else -> localCustomThemeRepository.currentLightCustomThemeFlow
|
||||
}.onEach {
|
||||
themeLoaded = true
|
||||
}
|
||||
|
||||
val customTheme by currentThemeFlow.collectAsState(initial = null)
|
||||
customTheme?.let {
|
||||
CompositionLocalProvider(LocalAppTheme provides it) {
|
||||
|
||||
if (themeLoaded) {
|
||||
CompositionLocalProvider(LocalAppTheme provides (customTheme ?: getDefaultTheme(context, themeType))) {
|
||||
MaterialTheme {
|
||||
content()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user