-
-
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|build] Support right swipe on Article items; support swipe t…
…o mark read, favorite (#58); update Kotlin version to 2.0.0; update dependencies
- Loading branch information
Showing
15 changed files
with
288 additions
and
99 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
47 changes: 47 additions & 0 deletions
47
...ain/java/com/skyd/anivu/model/preference/behavior/article/ArticleSwipeActionPreference.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,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 | ||
|
||
} |
30 changes: 3 additions & 27 deletions
30
...java/com/skyd/anivu/model/preference/behavior/article/ArticleSwipeLeftActionPreference.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,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) | ||
} |
19 changes: 19 additions & 0 deletions
19
...ava/com/skyd/anivu/model/preference/behavior/article/ArticleSwipeRightActionPreference.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,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) | ||
} |
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
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/skyd/anivu/ui/component/SwipeToDismissBox.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,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) | ||
} | ||
} |
Oops, something went wrong.