forked from Ashinch/ReadYou
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): swipe to star/unstar, swipe to unread (Ashinch#594)
* feat(ui): swipe to star & unstar * feat(ui): swipe to unread * feat(ui): add haptic feedback to swipe gesture * fix(ui): disable swipe gestures when scroll in progress * feat(ui): configure swipe gestures * fix(ui): workaround for swipe animation & remove text label * fix(ui): app initialize with toggle starred
- Loading branch information
1 parent
c21e22d
commit 8c11757
Showing
11 changed files
with
998 additions
and
106 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
98 changes: 98 additions & 0 deletions
98
app/src/main/java/me/ash/reader/infrastructure/preference/SwipeActionPreference.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,98 @@ | ||
package me.ash.reader.infrastructure.preference | ||
|
||
import android.content.Context | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.datastore.preferences.core.Preferences | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
import me.ash.reader.R | ||
import me.ash.reader.ui.ext.DataStoreKeys | ||
import me.ash.reader.ui.ext.dataStore | ||
import me.ash.reader.ui.ext.put | ||
|
||
data object SwipeGestureActions { | ||
const val None = 0 | ||
const val ToggleRead = 1 | ||
const val ToggleStarred = 2 | ||
} | ||
|
||
sealed class SwipeEndActionPreference(val action: Int) : Preference() { | ||
override fun put(context: Context, scope: CoroutineScope) { | ||
scope.launch { | ||
context.dataStore.put( | ||
DataStoreKeys.SwipeEndAction, action | ||
) | ||
} | ||
} | ||
|
||
data object None : SwipeEndActionPreference(SwipeGestureActions.None) | ||
data object ToggleRead : SwipeEndActionPreference(SwipeGestureActions.ToggleRead) | ||
data object ToggleStarred : | ||
SwipeEndActionPreference(SwipeGestureActions.ToggleStarred) | ||
|
||
val desc: String | ||
@Composable get() = when (this) { | ||
None -> stringResource(id = R.string.none) | ||
ToggleRead -> stringResource(id = R.string.toggle_read) | ||
ToggleStarred -> stringResource(id = R.string.toggle_starred) | ||
} | ||
|
||
companion object { | ||
val default: SwipeEndActionPreference = ToggleRead | ||
val values = listOf( | ||
None, | ||
ToggleRead, | ||
ToggleStarred | ||
) | ||
|
||
fun fromPreferences(preferences: Preferences): SwipeEndActionPreference { | ||
return when (preferences[DataStoreKeys.SwipeEndAction.key]) { | ||
SwipeGestureActions.None -> None | ||
SwipeGestureActions.ToggleRead -> ToggleRead | ||
SwipeGestureActions.ToggleStarred -> ToggleStarred | ||
else -> default | ||
} | ||
} | ||
} | ||
} | ||
|
||
sealed class SwipeStartActionPreference(val action: Int) : Preference() { | ||
override fun put(context: Context, scope: CoroutineScope) { | ||
scope.launch { | ||
context.dataStore.put( | ||
DataStoreKeys.SwipeStartAction, action | ||
) | ||
} | ||
} | ||
|
||
data object None : SwipeStartActionPreference(SwipeGestureActions.None) | ||
data object ToggleRead : SwipeStartActionPreference(SwipeGestureActions.ToggleRead) | ||
data object ToggleStarred : | ||
SwipeStartActionPreference(SwipeGestureActions.ToggleStarred) | ||
|
||
val desc: String | ||
@Composable get() = when (this) { | ||
None -> stringResource(id = R.string.none) | ||
ToggleRead -> stringResource(id = R.string.toggle_read) | ||
ToggleStarred -> stringResource(id = R.string.toggle_starred) | ||
} | ||
|
||
companion object { | ||
val default: SwipeStartActionPreference = ToggleStarred | ||
val values = listOf( | ||
None, | ||
ToggleRead, | ||
ToggleStarred | ||
) | ||
|
||
fun fromPreferences(preferences: Preferences): SwipeStartActionPreference { | ||
return when (preferences[DataStoreKeys.SwipeStartAction.key]) { | ||
SwipeGestureActions.None -> None | ||
SwipeGestureActions.ToggleRead -> ToggleRead | ||
SwipeGestureActions.ToggleStarred -> ToggleStarred | ||
else -> 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.