-
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): configuration for pull-to-load gesture
- Loading branch information
1 parent
2d9e3de
commit a187d38
Showing
9 changed files
with
122 additions
and
34 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
29 changes: 29 additions & 0 deletions
29
app/src/main/java/me/ash/reader/infrastructure/preference/PullToSwitchArticlePreference.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 me.ash.reader.infrastructure.preference | ||
|
||
import android.content.Context | ||
import androidx.datastore.preferences.core.Preferences | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
import me.ash.reader.ui.ext.DataStoreKeys | ||
import me.ash.reader.ui.ext.dataStore | ||
import me.ash.reader.ui.ext.put | ||
|
||
class PullToSwitchArticlePreference(val value: Boolean) : Preference() { | ||
override fun put(context: Context, scope: CoroutineScope) { | ||
scope.launch { | ||
context.dataStore.put(DataStoreKeys.PullToSwitchArticle, value) | ||
} | ||
} | ||
|
||
fun toggle(context: Context, scope: CoroutineScope) = | ||
PullToSwitchArticlePreference(!value).put(context, scope) | ||
|
||
companion object { | ||
val default = PullToSwitchArticlePreference(true) | ||
fun fromPreference(preference: Preferences): PullToSwitchArticlePreference { | ||
return PullToSwitchArticlePreference( | ||
preference[DataStoreKeys.PullToSwitchArticle.key] ?: return 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
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
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