2022-04-22 17:29:24 -04:00
|
|
|
package eu.kanade.presentation.theme
|
|
|
|
|
2022-10-15 22:38:01 +07:00
|
|
|
import androidx.appcompat.view.ContextThemeWrapper
|
2022-04-22 17:29:24 -04:00
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
|
import androidx.compose.runtime.Composable
|
2022-10-15 22:38:01 +07:00
|
|
|
import androidx.compose.runtime.remember
|
2022-04-22 17:29:24 -04:00
|
|
|
import androidx.compose.ui.platform.LocalContext
|
2022-06-12 09:59:55 -04:00
|
|
|
import androidx.compose.ui.platform.LocalLayoutDirection
|
2022-04-22 17:29:24 -04:00
|
|
|
import com.google.android.material.composethemeadapter3.createMdc3Theme
|
2022-10-15 22:38:01 +07:00
|
|
|
import eu.kanade.domain.ui.model.AppTheme
|
|
|
|
import eu.kanade.tachiyomi.ui.base.delegate.ThemingDelegate
|
|
|
|
import uy.kohesive.injekt.api.get
|
2022-04-22 17:29:24 -04:00
|
|
|
|
|
|
|
@Composable
|
|
|
|
fun TachiyomiTheme(content: @Composable () -> Unit) {
|
|
|
|
val context = LocalContext.current
|
2022-06-12 09:59:55 -04:00
|
|
|
val layoutDirection = LocalLayoutDirection.current
|
|
|
|
|
2022-04-22 17:29:24 -04:00
|
|
|
val (colorScheme, typography) = createMdc3Theme(
|
2022-04-24 20:35:59 +02:00
|
|
|
context = context,
|
2022-06-12 09:59:55 -04:00
|
|
|
layoutDirection = layoutDirection,
|
2022-04-22 17:29:24 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
MaterialTheme(
|
|
|
|
colorScheme = colorScheme!!,
|
|
|
|
typography = typography!!,
|
2022-04-24 14:39:51 -04:00
|
|
|
content = content,
|
2022-04-22 17:29:24 -04:00
|
|
|
)
|
|
|
|
}
|
2022-10-15 22:38:01 +07:00
|
|
|
|
|
|
|
@Composable
|
|
|
|
fun TachiyomiTheme(
|
|
|
|
appTheme: AppTheme,
|
|
|
|
amoled: Boolean,
|
|
|
|
content: @Composable () -> Unit,
|
|
|
|
) {
|
|
|
|
val originalContext = LocalContext.current
|
|
|
|
val layoutDirection = LocalLayoutDirection.current
|
|
|
|
val themedContext = remember(appTheme, originalContext) {
|
|
|
|
val themeResIds = ThemingDelegate.getThemeResIds(appTheme, amoled)
|
|
|
|
themeResIds.fold(originalContext) { context, themeResId ->
|
|
|
|
ContextThemeWrapper(context, themeResId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
val (colorScheme, typography) = createMdc3Theme(
|
|
|
|
context = themedContext,
|
|
|
|
layoutDirection = layoutDirection,
|
|
|
|
)
|
|
|
|
|
|
|
|
MaterialTheme(
|
|
|
|
colorScheme = colorScheme!!,
|
|
|
|
typography = typography!!,
|
|
|
|
content = content,
|
|
|
|
)
|
|
|
|
}
|