-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): add line height multiple preference for reading page (#620)
- Loading branch information
1 parent
53523e4
commit 098ec08
Showing
8 changed files
with
99 additions
and
7 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
25 changes: 25 additions & 0 deletions
25
app/src/main/java/me/ash/reader/infrastructure/preference/ReadingTextLineHeightPreference.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,25 @@ | ||
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 | ||
|
||
data object ReadingTextLineHeightPreference { | ||
const val default = 1f | ||
private val range = 0.8f..2f | ||
|
||
fun put(context: Context, scope: CoroutineScope, value: Float) { | ||
scope.launch { | ||
context.dataStore.put(DataStoreKeys.ReadingLineHeight, value) | ||
} | ||
} | ||
|
||
fun Float.coerceToRange() = coerceIn(range) | ||
|
||
fun fromPreferences(preferences: Preferences) = | ||
preferences[DataStoreKeys.ReadingLineHeight.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
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