Skip to content

Commit

Permalink
[feature|build] Support right swipe on Article items; support swipe t…
Browse files Browse the repository at this point in the history
…o mark read, favorite (#58); update Kotlin version to 2.0.0; update dependencies
  • Loading branch information
SkyD666 committed Jun 8, 2024
1 parent fe2c2d5 commit e85cedc
Show file tree
Hide file tree
Showing 15 changed files with 288 additions and 99 deletions.
17 changes: 11 additions & 6 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.compose")
id("kotlinx-serialization")
id("kotlin-parcelize")
id("com.google.devtools.ksp")
Expand All @@ -21,7 +22,7 @@ android {
minSdk = 24
targetSdk = 34
versionCode = 18
versionName = "1.1-beta47"
versionName = "1.1-beta48"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -104,9 +105,6 @@ android {
viewBinding = true
buildConfig = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.14"
}
packaging {
resources.excludes += mutableSetOf(
"DebugProbesKt.bin",
Expand All @@ -130,6 +128,13 @@ android {
// ndkVersion = "26.3.11579264"
}

composeCompiler {
enableStrongSkippingMode = true

reportsDestination = layout.buildDirectory.dir("compose_compiler")
// stabilityConfigurationFile = rootProject.layout.projectDirectory.file("stability_config.conf")
}

tasks.withType(KotlinCompile::class.java).configureEach {
kotlinOptions {
freeCompilerArgs += listOf(
Expand Down Expand Up @@ -167,7 +172,7 @@ dependencies {
implementation("androidx.compose.material3.adaptive:adaptive-layout:1.0.0-beta01")
implementation("androidx.compose.material3.adaptive:adaptive-navigation:1.0.0-beta01")
implementation("androidx.compose.material:material-icons-extended:1.6.7")
implementation("com.materialkolor:material-kolor:1.6.1")
implementation("com.materialkolor:material-kolor:1.6.2")
implementation("androidx.room:room-runtime:2.6.1")
implementation("androidx.room:room-ktx:2.6.1")
implementation("androidx.room:room-paging:2.6.1")
Expand All @@ -191,7 +196,7 @@ dependencies {
implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
implementation("com.squareup.retrofit2:retrofit:2.11.0")
implementation("com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:1.0.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-guava:1.8.1")

implementation("com.github.aniyomiorg:aniyomi-mpv-lib:1.15.n")
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/skyd/anivu/ext/PreferenceExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.skyd.anivu.model.preference.appearance.search.SearchListTonalElevatio
import com.skyd.anivu.model.preference.appearance.search.SearchTopBarTonalElevationPreference
import com.skyd.anivu.model.preference.behavior.PickImageMethodPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleSwipeLeftActionPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleSwipeRightActionPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleTapActionPreference
import com.skyd.anivu.model.preference.behavior.article.DeduplicateTitleInDescPreference
import com.skyd.anivu.model.preference.behavior.feed.HideEmptyDefaultPreference
Expand Down Expand Up @@ -58,6 +59,7 @@ fun Preferences.toSettings(): Settings {
deduplicateTitleInDesc = DeduplicateTitleInDescPreference.fromPreferences(this),
articleTapAction = ArticleTapActionPreference.fromPreferences(this),
articleSwipeLeftAction = ArticleSwipeLeftActionPreference.fromPreferences(this),
articleSwipeRightAction = ArticleSwipeRightActionPreference.fromPreferences(this),
hideEmptyDefault = HideEmptyDefaultPreference.fromPreferences(this),
pickImageMethod = PickImageMethodPreference.fromPreferences(this),

Expand Down
4 changes: 4 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 @@ -25,6 +25,7 @@ import com.skyd.anivu.model.preference.appearance.search.SearchListTonalElevatio
import com.skyd.anivu.model.preference.appearance.search.SearchTopBarTonalElevationPreference
import com.skyd.anivu.model.preference.behavior.PickImageMethodPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleSwipeLeftActionPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleSwipeRightActionPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleTapActionPreference
import com.skyd.anivu.model.preference.behavior.article.DeduplicateTitleInDescPreference
import com.skyd.anivu.model.preference.behavior.feed.HideEmptyDefaultPreference
Expand All @@ -39,6 +40,7 @@ import com.skyd.anivu.model.preference.player.PlayerShowScreenshotButtonPreferen
import com.skyd.anivu.ui.local.LocalArticleItemTonalElevation
import com.skyd.anivu.ui.local.LocalArticleListTonalElevation
import com.skyd.anivu.ui.local.LocalArticleSwipeLeftAction
import com.skyd.anivu.ui.local.LocalArticleSwipeRightAction
import com.skyd.anivu.ui.local.LocalArticleTapAction
import com.skyd.anivu.ui.local.LocalArticleTopBarTonalElevation
import com.skyd.anivu.ui.local.LocalAutoDeleteArticleBefore
Expand Down Expand Up @@ -91,6 +93,7 @@ data class Settings(
val deduplicateTitleInDesc: Boolean = DeduplicateTitleInDescPreference.default,
val articleTapAction: String = ArticleTapActionPreference.default,
val articleSwipeLeftAction: String = ArticleSwipeLeftActionPreference.default,
val articleSwipeRightAction: String = ArticleSwipeRightActionPreference.default,
val hideEmptyDefault: Boolean = HideEmptyDefaultPreference.default,
val pickImageMethod: String = PickImageMethodPreference.default,
// Player
Expand Down Expand Up @@ -136,6 +139,7 @@ fun SettingsProvider(
LocalDeduplicateTitleInDesc provides settings.deduplicateTitleInDesc,
LocalArticleTapAction provides settings.articleTapAction,
LocalArticleSwipeLeftAction provides settings.articleSwipeLeftAction,
LocalArticleSwipeRightAction provides settings.articleSwipeRightAction,
LocalHideEmptyDefault provides settings.hideEmptyDefault,
LocalPickImageMethod provides settings.pickImageMethod,
// Player
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.skyd.anivu.model.preference.behavior.article

import android.content.Context
import androidx.datastore.preferences.core.Preferences
import com.skyd.anivu.R
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

abstract class ArticleSwipeActionPreference : BasePreference<String> {

companion object {
const val NONE = "None"
const val READ = "Read"
const val SHOW_ENCLOSURES = "ShowEnclosures"
const val SWITCH_READ_STATE = "SwitchReadState"
const val SWITCH_FAVORITE_STATE = "SwitchFavoriteState"

fun toDisplayName(
context: Context,
value: String,
): String = when (value) {
NONE -> context.getString(R.string.none)
READ -> context.getString(R.string.article_action_read)
SHOW_ENCLOSURES -> context.getString(R.string.article_action_show_enclosures)
SWITCH_READ_STATE -> context.getString(R.string.article_action_switch_read_state)
SWITCH_FAVORITE_STATE -> context.getString(R.string.article_action_switch_favorite_state)
else -> context.getString(R.string.unknown)
}
}

val values = arrayOf(NONE, READ, SHOW_ENCLOSURES, SWITCH_READ_STATE, SWITCH_FAVORITE_STATE)

abstract val key: Preferences.Key<String>

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

override fun fromPreferences(preferences: Preferences): String = preferences[key] ?: default

}
Original file line number Diff line number Diff line change
@@ -1,43 +1,19 @@
package com.skyd.anivu.model.preference.behavior.article

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

object ArticleSwipeLeftActionPreference : BasePreference<String> {
object ArticleSwipeLeftActionPreference : ArticleSwipeActionPreference() {
private const val ARTICLE_SWIPE_LEFT_ACTION = "articleSwipeLeftAction"

const val READ = "Read"
const val SHOW_ENCLOSURES = "ShowEnclosures"

val values = arrayOf(READ, SHOW_ENCLOSURES)

override val default = SHOW_ENCLOSURES

val key = stringPreferencesKey(ARTICLE_SWIPE_LEFT_ACTION)

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

override fun fromPreferences(preferences: Preferences): String = preferences[key] ?: default
override val key = stringPreferencesKey(ARTICLE_SWIPE_LEFT_ACTION)

fun toDisplayName(
context: Context,
value: String = context.dataStore.getOrDefault(this),
): String = when (value) {
READ -> context.getString(R.string.article_action_read)
SHOW_ENCLOSURES -> context.getString(R.string.article_action_show_enclosures)
else -> context.getString(R.string.unknown)
}
): String = ArticleSwipeActionPreference.toDisplayName(context, value)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.skyd.anivu.model.preference.behavior.article

import android.content.Context
import androidx.datastore.preferences.core.stringPreferencesKey
import com.skyd.anivu.ext.dataStore
import com.skyd.anivu.ext.getOrDefault

object ArticleSwipeRightActionPreference : ArticleSwipeActionPreference() {
private const val ARTICLE_SWIPE_RIGHT_ACTION = "articleSwipeRightAction"

override val default = SWITCH_FAVORITE_STATE

override val key = stringPreferencesKey(ARTICLE_SWIPE_RIGHT_ACTION)

fun toDisplayName(
context: Context,
value: String = context.dataStore.getOrDefault(this),
): String = ArticleSwipeActionPreference.toDisplayName(context, value)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ import com.skyd.anivu.ext.visible


class ColorPaletteView : MaterialCardView {
private val iconImage = ImageView(context).apply {
setBackgroundResource(R.drawable.shape_fill_circle)
setPadding(7.dp)
backgroundTintList = ColorStateList.valueOf(iconBackgroundColor)
}
private val iconImage = ImageView(context)
var icon: Drawable?
get() = iconImage.drawable
set(value) {
Expand Down Expand Up @@ -72,6 +68,11 @@ class ColorPaletteView : MaterialCardView {
attrs,
defStyleAttr
) {
with(iconImage) {
setBackgroundResource(R.drawable.shape_fill_circle)
setPadding(7.dp)
backgroundTintList = ColorStateList.valueOf(iconBackgroundColor)
}
val a = context.obtainStyledAttributes(
attrs, R.styleable.ColorPaletteView, defStyleAttr, 0
)
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/java/com/skyd/anivu/ui/component/SwipeToDismissBox.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.skyd.anivu.ui.component

import androidx.compose.material3.SwipeToDismissBoxDefaults
import androidx.compose.material3.SwipeToDismissBoxState
import androidx.compose.material3.SwipeToDismissBoxValue
import androidx.compose.runtime.Composable
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.platform.LocalDensity

@Composable
fun rememberSwipeToDismissBoxState(
vararg inputs: Any?,
initialValue: SwipeToDismissBoxValue = SwipeToDismissBoxValue.Settled,
confirmValueChange: (SwipeToDismissBoxValue) -> Boolean = { true },
positionalThreshold: (totalDistance: Float) -> Float =
SwipeToDismissBoxDefaults.positionalThreshold,
): SwipeToDismissBoxState {
val density = LocalDensity.current
return rememberSaveable(
inputs = inputs,
saver = SwipeToDismissBoxState.Saver(
confirmValueChange = confirmValueChange,
density = density,
positionalThreshold = positionalThreshold
)
) {
SwipeToDismissBoxState(initialValue, density, confirmValueChange, positionalThreshold)
}
}
Loading

0 comments on commit e85cedc

Please sign in to comment.