-
-
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|optimize] Support check update; convert about screen, more s…
…creen to Compose
- Loading branch information
Showing
55 changed files
with
2,157 additions
and
808 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
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
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() | ||
} | ||
} | ||
} |
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
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,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 | ||
} |
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,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 |
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 |
---|---|---|
@@ -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
4
app/src/main/java/com/skyd/anivu/model/bean/OtherWorksBean.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 |
---|---|---|
@@ -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 |
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,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 | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/skyd/anivu/model/preference/IgnoreUpdateVersionPreference.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,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 | ||
} |
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
Oops, something went wrong.