Skip to content

Commit

Permalink
[feature|optimize] Support check update; convert about screen, more s…
Browse files Browse the repository at this point in the history
…creen to Compose
  • Loading branch information
SkyD666 committed Apr 18, 2024
1 parent d6e2853 commit 17bda1a
Show file tree
Hide file tree
Showing 55 changed files with 2,157 additions and 808 deletions.
8 changes: 6 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ android {
applicationId = "com.skyd.anivu"
minSdk = 24
targetSdk = 34
versionCode = 11
versionName = "1.1-beta08"
versionCode = 12
versionName = "1.1-beta09"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -144,9 +144,11 @@ dependencies {
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.navigation:navigation-fragment-ktx:2.7.7")
implementation("androidx.navigation:navigation-ui-ktx:2.7.7")
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.7.0")
implementation("androidx.compose.ui:ui:1.6.5")
implementation("androidx.compose.material3:material3:1.2.1")
implementation("androidx.compose.material3:material3-window-size-class:1.2.1")
implementation("androidx.compose.material:material-icons-extended:1.6.5")
implementation("com.materialkolor:material-kolor:1.4.4")
implementation("androidx.room:room-runtime:2.6.1")
implementation("androidx.room:room-ktx:2.6.1")
Expand All @@ -167,6 +169,7 @@ dependencies {

implementation("com.google.dagger:hilt-android:2.51")
ksp("com.google.dagger:hilt-android-compiler:2.51")
implementation("androidx.hilt:hilt-navigation-compose:1.2.0")

implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation("com.squareup.okhttp3:okhttp-coroutines-jvm:5.0.0-alpha.12")
Expand All @@ -176,6 +179,7 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")

implementation("io.coil-kt:coil:2.6.0")
implementation("io.coil-kt:coil-compose:2.6.0")
implementation("com.rometools:rome:2.1.0")
implementation("net.dankito.readability4j:readability4j:1.0.8")

Expand Down
3 changes: 3 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,8 @@ public static final ** CREATOR;
-keep class com.skyd.anivu.ui.adapter.variety.VarietyAdapter$Proxy { *; }
-keep class com.skyd.anivu.ui.adapter.variety.AsyncListDiffer { *; }

-keep class * extends com.skyd.anivu.ui.component.lazyverticalgrid.adapter.LazyGridAdapter$Proxy
-keep class com.skyd.anivu.ui.component.lazyverticalgrid.adapter.LazyGridAdapter$Proxy { *; }

# Retrofit
-keep, allowobfuscation, allowshrinking interface retrofit2.Call
21 changes: 21 additions & 0 deletions app/src/main/java/com/skyd/anivu/base/BaseComposeFragment.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.skyd.anivu.base

import android.os.Bundle
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.fragment.app.Fragment
import androidx.navigation.NavHostController
import com.skyd.anivu.ext.findMainNavController
Expand All @@ -19,6 +21,8 @@ abstract class BaseComposeFragment : Fragment() {
fun setContentBase(content: @Composable () -> Unit): ComposeView {
navController = findMainNavController() as NavHostController
return ComposeView(requireContext()).apply {
// Dispose of the Composition when the view's LifecycleOwner is destroyed
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
CompositionLocalProvider(
LocalNavController provides navController,
Expand All @@ -29,4 +33,21 @@ abstract class BaseComposeFragment : Fragment() {
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
transitionProvider?.let { provider ->
enterTransition = provider.enterTransition
returnTransition = provider.returnTransition
exitTransition = provider.exitTransition
reenterTransition = provider.reenterTransition
}
}

private val defaultTransitionProvider = BaseFragment.TransitionProvider()

protected val nullTransitionProvider: BaseFragment.TransitionProvider? = null

protected open val transitionProvider: BaseFragment.TransitionProvider? =
defaultTransitionProvider
}
33 changes: 32 additions & 1 deletion app/src/main/java/com/skyd/anivu/base/mvi/MviIntent.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
package com.skyd.anivu.base.mvi

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import com.skyd.anivu.ext.startWith
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.consumeAsFlow
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.withContext

/**
* Immutable object which represent an view's intent.
*/
interface MviIntent
interface MviIntent

@Composable
fun <I : MviIntent, S : MviViewState, E : MviSingleEvent>
AbstractMviViewModel<I, S, E>.getDispatcher(startWith: I): (I) -> Unit {
val intentChannel = remember { Channel<I>(Channel.UNLIMITED) }
LaunchedEffect(Unit) {
withContext(Dispatchers.Main.immediate) {
intentChannel
.consumeAsFlow()
.startWith(startWith)
.onEach(this@getDispatcher::processIntent)
.collect()
}
}
return remember {
{ intent: I ->
intentChannel.trySend(intent).getOrThrow()
}
}
}
3 changes: 3 additions & 0 deletions app/src/main/java/com/skyd/anivu/config/Const.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import java.io.File

object Const {
const val GITHUB_REPO = "https://github.com/SkyD666/AniVu"
const val GITHUB_LATEST_RELEASE = "https://api.github.com/repos/SkyD666/AniVu/releases/latest"
const val GITHUB_NEW_ISSUE_URL = "https://github.com/SkyD666/AniVu/issues/new"
const val TELEGRAM_GROUP = "https://t.me/SkyD666Chat"
const val DISCORD_SERVER = "https://discord.gg/pEWEjeJTa3"
const val AFADIAN_LINK = "https://afdian.net/a/SkyD666"
const val BUY_ME_A_COFFEE_LINK = "https://www.buymeacoffee.com/SkyD666"

const val RAYS_ANDROID_URL = "https://github.com/SkyD666/Rays-Android"
const val RACA_ANDROID_URL = "https://github.com/SkyD666/Raca-Android"
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/skyd/anivu/ext/ContextExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.content.res.Configuration
import android.graphics.Point
import android.os.Build
import androidx.core.content.ContextCompat
import androidx.core.content.pm.PackageInfoCompat

val Context.activity: Activity
get() {
Expand Down Expand Up @@ -64,6 +65,19 @@ fun Context.getAppVersionName(): String {
return appVersionName
}

fun Context.getAppVersionCode(): Long {
var appVersionCode: Long = 0
try {
val packageInfo = applicationContext
.packageManager
.getPackageInfo(packageName, 0)
appVersionCode = PackageInfoCompat.getLongVersionCode(packageInfo)
} catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace()
}
return appVersionCode
}

fun Context.getAppName(): String? {
return try {
val packageInfo: PackageInfo = packageManager.getPackageInfo(packageName, 0)
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/skyd/anivu/ext/PreferenceExt.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.skyd.anivu.ext

import androidx.datastore.preferences.core.Preferences
import com.skyd.anivu.model.preference.IgnoreUpdateVersionPreference
import com.skyd.anivu.model.preference.Settings
import com.skyd.anivu.model.preference.appearance.DarkModePreference
import com.skyd.anivu.model.preference.appearance.ThemePreference
Expand All @@ -10,5 +11,8 @@ fun Preferences.toSettings(): Settings {
// Theme
theme = ThemePreference.fromPreferences(this),
darkMode = DarkModePreference.fromPreferences(this),

// Update
ignoreUpdateVersion = IgnoreUpdateVersionPreference.fromPreferences(this),
)
}
46 changes: 46 additions & 0 deletions app/src/main/java/com/skyd/anivu/ext/SnackbarExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.skyd.anivu.ext

import androidx.compose.material3.SnackbarDuration
import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

fun SnackbarHostState.showSnackbar(
scope: CoroutineScope,
message: String,
actionLabel: String? = null,
withDismissAction: Boolean = true,
duration: SnackbarDuration = if (actionLabel == null) SnackbarDuration.Short else SnackbarDuration.Indefinite
) {
scope.launch {
showSnackbar(
message = message,
actionLabel = actionLabel,
withDismissAction = withDismissAction,
duration = duration,
)
}
}

@Composable
fun SnackbarHostState.showSnackbarWithLaunchedEffect(
message: String,
key1: Any? = this,
key2: Any? = null,
key3: Any? = null,
actionLabel: String? = null,
withDismissAction: Boolean = true,
duration: SnackbarDuration = if (actionLabel == null) SnackbarDuration.Short else SnackbarDuration.Indefinite
): SnackbarHostState {
LaunchedEffect(key1, key2, key3) {
showSnackbar(
message = message,
actionLabel = actionLabel,
withDismissAction = withDismissAction,
duration = duration,
)
}
return this
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/skyd/anivu/ext/WindowExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.skyd.anivu.ext

import androidx.compose.material3.windowsizeclass.WindowSizeClass
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass

val WindowSizeClass.isCompact: Boolean
get() = widthSizeClass == WindowWidthSizeClass.Compact

val WindowSizeClass.isMedium: Boolean
get() = widthSizeClass == WindowWidthSizeClass.Medium

val WindowSizeClass.isExpanded: Boolean
get() = widthSizeClass == WindowWidthSizeClass.Expanded
16 changes: 8 additions & 8 deletions app/src/main/java/com/skyd/anivu/model/bean/MoreBean.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.skyd.anivu.model.bean

import android.graphics.drawable.Drawable
import androidx.annotation.ColorInt
import androidx.annotation.IdRes
import androidx.annotation.DrawableRes
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import com.skyd.anivu.base.BaseBean

data class MoreBean(
val icon: Drawable,
@ColorInt val iconTint: Int,
val title: String,
@IdRes val navigateId: Int,
val background: Drawable,
@ColorInt val backgroundTint: Int,
@DrawableRes val icon: Int,
val iconTint: Color,
val shape: Shape,
val shapeColor: Color,
val action: () -> Unit,
) : BaseBean
4 changes: 2 additions & 2 deletions app/src/main/java/com/skyd/anivu/model/bean/OtherWorksBean.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.skyd.anivu.model.bean

import android.graphics.drawable.Drawable
import androidx.annotation.DrawableRes
import com.skyd.anivu.base.BaseBean

data class OtherWorksBean(
val name: String,
val icon: Drawable,
@DrawableRes val icon: Int,
val description: String,
val url: String,
) : BaseBean
42 changes: 42 additions & 0 deletions app/src/main/java/com/skyd/anivu/model/bean/UpdateBean.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.skyd.anivu.model.bean

import androidx.annotation.Keep
import com.skyd.anivu.base.BaseBean
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Keep
@Serializable
data class UpdateBean(
@SerialName("tag_name")
var tagName: String,
@SerialName("name")
var name: String,
@SerialName("html_url")
var htmlUrl: String,
@SerialName("published_at")
var publishedAt: String,
@SerialName("assets")
var assets: List<AssetsBean>,
@SerialName("body")
var body: String
) : BaseBean {

@Keep
@Serializable
class AssetsBean(
@SerialName("name")
var name: String,
@SerialName("size")
var size: Long,
@SerialName("download_count")
var downloadCount: Long?,
@SerialName("browser_download_url")
var browserDownloadUrl: String,
@SerialName("created_at")
var createdAt: String?,
@SerialName("updated_at")
var updatedAt: String?
) : BaseBean

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.skyd.anivu.model.preference

import android.content.Context
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.longPreferencesKey
import com.skyd.anivu.base.BasePreference
import com.skyd.anivu.ext.dataStore
import com.skyd.anivu.ext.put
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

object IgnoreUpdateVersionPreference : BasePreference<Long> {
private const val IGNORE_UPDATE_VERSION = "ignoreUpdateVersion"
override val default = 0L

val key = longPreferencesKey(IGNORE_UPDATE_VERSION)

fun put(context: Context, scope: CoroutineScope, value: Long) {
scope.launch(Dispatchers.IO) {
context.dataStore.put(key, value)
}
}

override fun fromPreferences(preferences: Preferences): Long = preferences[key] ?: default
}
5 changes: 5 additions & 0 deletions app/src/main/java/com/skyd/anivu/model/preference/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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.LocalIgnoreUpdateVersion
import com.skyd.anivu.ui.local.LocalTheme
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.map
Expand All @@ -19,6 +20,8 @@ data class Settings(
// Theme
val theme: String = ThemePreference.default,
val darkMode: Int = DarkModePreference.default,
// Update
val ignoreUpdateVersion: Long = IgnoreUpdateVersionPreference.default,
)

@Composable
Expand All @@ -33,6 +36,8 @@ fun SettingsProvider(
// Theme
LocalTheme provides settings.theme,
LocalDarkMode provides settings.darkMode,
// Update
LocalIgnoreUpdateVersion provides settings.ignoreUpdateVersion,
) {
content()
}
Expand Down
Loading

0 comments on commit 17bda1a

Please sign in to comment.