-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] Introducing Jetpack Compose
- Loading branch information
Showing
22 changed files
with
918 additions
and
185 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
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/skyd/anivu/base/BaseComposeFragment.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,32 @@ | ||
package com.skyd.anivu.base | ||
|
||
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.ui.platform.ComposeView | ||
import androidx.fragment.app.Fragment | ||
import androidx.navigation.NavHostController | ||
import com.skyd.anivu.ext.findMainNavController | ||
import com.skyd.anivu.model.preference.SettingsProvider | ||
import com.skyd.anivu.ui.local.LocalDarkMode | ||
import com.skyd.anivu.ui.local.LocalNavController | ||
import com.skyd.anivu.ui.local.LocalWindowSizeClass | ||
import com.skyd.anivu.ui.theme.AniVuTheme | ||
|
||
|
||
abstract class BaseComposeFragment : Fragment() { | ||
private lateinit var navController: NavHostController | ||
fun setContentBase(content: @Composable () -> Unit): ComposeView { | ||
navController = findMainNavController() as NavHostController | ||
return ComposeView(requireContext()).apply { | ||
setContent { | ||
CompositionLocalProvider( | ||
LocalNavController provides navController, | ||
LocalWindowSizeClass provides calculateWindowSizeClass(requireActivity()) | ||
) { | ||
SettingsProvider { AniVuTheme(darkTheme = LocalDarkMode.current, content) } | ||
} | ||
} | ||
} | ||
} | ||
} |
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 com.skyd.anivu.ext | ||
|
||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.calculateEndPadding | ||
import androidx.compose.foundation.layout.calculateStartPadding | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.platform.LocalLayoutDirection | ||
|
||
@Composable | ||
operator fun PaddingValues.plus(other: PaddingValues): PaddingValues = PaddingValues( | ||
top = calculateTopPadding() + other.calculateTopPadding(), | ||
bottom = calculateBottomPadding() + other.calculateBottomPadding(), | ||
start = calculateStartPadding(LocalLayoutDirection.current) + | ||
other.calculateStartPadding(LocalLayoutDirection.current), | ||
end = calculateEndPadding(LocalLayoutDirection.current) + | ||
other.calculateEndPadding(LocalLayoutDirection.current) | ||
) |
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,14 @@ | ||
package com.skyd.anivu.ext | ||
|
||
import androidx.datastore.preferences.core.Preferences | ||
import com.skyd.anivu.model.preference.Settings | ||
import com.skyd.anivu.model.preference.appearance.DarkModePreference | ||
import com.skyd.anivu.model.preference.appearance.ThemePreference | ||
|
||
fun Preferences.toSettings(): Settings { | ||
return Settings( | ||
// Theme | ||
theme = ThemePreference.fromPreferences(this), | ||
darkMode = DarkModePreference.fromPreferences(this), | ||
) | ||
} |
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/skyd/anivu/model/preference/Settings.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,39 @@ | ||
package com.skyd.anivu.model.preference | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.platform.LocalContext | ||
import com.skyd.anivu.ext.dataStore | ||
import com.skyd.anivu.ext.toSettings | ||
import com.skyd.anivu.model.preference.appearance.DarkModePreference | ||
import com.skyd.anivu.model.preference.appearance.ThemePreference | ||
import com.skyd.anivu.ui.local.LocalDarkMode | ||
import com.skyd.anivu.ui.local.LocalTheme | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.map | ||
|
||
data class Settings( | ||
// Theme | ||
val theme: String = ThemePreference.default, | ||
val darkMode: Int = DarkModePreference.default, | ||
) | ||
|
||
@Composable | ||
fun SettingsProvider( | ||
content: @Composable () -> Unit, | ||
) { | ||
val context = LocalContext.current | ||
val settings by remember { context.dataStore.data.map { it.toSettings() } } | ||
.collectAsState(initial = Settings(), context = Dispatchers.Default) | ||
|
||
CompositionLocalProvider( | ||
// Theme | ||
LocalTheme provides settings.theme, | ||
LocalDarkMode provides settings.darkMode, | ||
) { | ||
content() | ||
} | ||
} |
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
42 changes: 0 additions & 42 deletions
42
app/src/main/java/com/skyd/anivu/ui/adapter/variety/proxy/License1Proxy.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.