Skip to content

Commit

Permalink
Bookmark default options
Browse files Browse the repository at this point in the history
  • Loading branch information
danielyrovas committed Apr 12, 2024
1 parent f22d1d7 commit b57775c
Show file tree
Hide file tree
Showing 14 changed files with 389 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.yrovas.linklater.data.local

import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.emptyPreferences
import androidx.datastore.preferences.core.stringPreferencesKey
Expand All @@ -17,6 +18,10 @@ import org.yrovas.linklater.AppScope
object Prefs {
val LINKDING_URL = stringPreferencesKey("linkding_url")
val LINKDING_TOKEN = stringPreferencesKey("linkding_token")
val BOOKMARK_DEFAULT_TAG_NAMES = stringPreferencesKey("bookmark_default_tag_names")
val BOOKMARK_DEFAULT_UNREAD = booleanPreferencesKey("bookmark_default_unread")
val BOOKMARK_DEFAULT_SHARED = booleanPreferencesKey("bookmark_default_shared")
val BOOKMARK_DEFAULT_ARCHIVED = booleanPreferencesKey("bookmark_default_archived")
}

@AppScope
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.yrovas.linklater.data.remote

import android.content.Context
import kotlinx.coroutines.delay
import org.yrovas.linklater.data.Bookmark
import org.yrovas.linklater.data.LocalBookmark
import org.yrovas.linklater.domain.APIError
Expand All @@ -21,8 +22,9 @@ class EmptyBookmarkAPI : BookmarkAPI {
page: Int,
query: String?,
): Res<List<Bookmark>, APIError> {
// return Ok(emptyList())
return Err(APIError.AUTH)
delay(4300)
return Ok(emptyList())
// return Err(APIError.AUTH)
}

override suspend fun getCachedBookmarks(context: Context): List<Bookmark> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.ktor.client.request.get
import io.ktor.client.request.header
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import kotlinx.coroutines.delay
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.encodeToJsonElement
Expand Down Expand Up @@ -71,6 +72,7 @@ class LinkDingAPI(
page: Int,
query: String?,
): Res<List<Bookmark>, APIError> {
// delay(4300)
if (!authProvided) return Err(APIError.AUTH)
return runCatching {
Log.d("DEBUG/net", "getBookmarks: starting request")
Expand Down
45 changes: 32 additions & 13 deletions app/src/main/java/org/yrovas/linklater/ui/common/AppBar.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package org.yrovas.linklater.ui.common

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.*
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.MaterialTheme.typography
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -22,13 +29,15 @@ fun AppBar(
content: @Composable () -> Unit = {},
) {
AppBar(left = {
Spacer(modifier = Modifier.width(padding.standard))
back?.let {
if (back != null) {
IconButton(onClick = { back() }) {
Icon(imageVector = Icons.AutoMirrored.Filled.ArrowBack,
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
tint = colorScheme.primary
)
}
} else {
Spacer(modifier = Modifier.width(padding.standard))
}
Text(
text = page,
Expand Down Expand Up @@ -67,27 +76,37 @@ fun AppBar(
}
}
}

@Composable
fun LargeHomeBar() {
}
//
//@Composable
//fun LargeHomeBar() {
//}

@ThemePreview
@Composable
fun AppBarPreview () {
fun HomeAppBarPreview() {
AppTheme {
Surface {
AppBar(page = "Settings", back = {})
AppBar(page = "Home")
}
}
}

@ThemePreview
@Composable
fun LargeHomeBarPreview() {
fun AppBarPreview () {
AppTheme {
Surface {
LargeHomeBar()
AppBar(page = "Settings", back = {})
}
}
}

//@ThemePreview
//@Composable
//fun LargeHomeBarPreview() {
// AppTheme {
// Surface {
// LargeHomeBar()
// }
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package org.yrovas.linklater.ui.common
import android.content.Context
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
Expand All @@ -16,12 +14,8 @@ import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.MaterialTheme.typography
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextOverflow
Expand All @@ -34,37 +28,6 @@ import org.yrovas.linklater.timeAgo
import org.yrovas.linklater.ui.theme.padding
import java.net.URI

@Composable
fun Frame(
appBar: @Composable () -> Unit,
fab: (@Composable () -> Unit)? = null,
snackState: SnackbarHostState,
content: @Composable () -> Unit,
) {
Surface(
modifier = Modifier.fillMaxSize(),
color = colorScheme.background,
contentColor = colorScheme.onBackground
) {
Box(modifier = Modifier.fillMaxSize()) {
Column {
appBar()
content()
}
Column(modifier = Modifier.align(Alignment.BottomStart)) {
fab?.let {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End
) { fab() }
}
SnackbarHost(hostState = snackState)
}
}
}
}


@Composable
fun BookmarkRow(
bookmark: Bookmark,
Expand Down
60 changes: 60 additions & 0 deletions app/src/main/java/org/yrovas/linklater/ui/common/Frame.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.yrovas.linklater.ui.common

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier

@Composable
fun Frame(
page: String,
back: (() -> Unit),
fab: (@Composable () -> Unit)? = null,
snackState: SnackbarHostState,
content: @Composable () -> Unit,
) {
Frame(appBar = { AppBar(page, back)},
fab = fab,
snackState = snackState) {
content()
}
}

@Composable
fun Frame(
appBar: @Composable () -> Unit,
fab: (@Composable () -> Unit)? = null,
snackState: SnackbarHostState,
content: @Composable () -> Unit,
) {
Surface(
modifier = Modifier.fillMaxSize(),
color = colorScheme.background,
contentColor = colorScheme.onBackground
) {
Box(modifier = Modifier.fillMaxSize()) {
Column {
appBar()
content()
}
Column(modifier = Modifier.align(Alignment.BottomStart)) {
fab?.let {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End
) { fab() }
}
SnackbarHost(hostState = snackState)
}
}
}
}
76 changes: 76 additions & 0 deletions app/src/main/java/org/yrovas/linklater/ui/common/RefreshIcon.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.yrovas.linklater.ui.common

import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.CubicBezierEasing
import androidx.compose.animation.core.Easing
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.tween
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch

@Composable
fun RefreshIcon(
modifier: Modifier = Modifier,
refreshing: StateFlow<Boolean>,
icon: ImageVector = Icons.Default.Refresh,
tint: Color = MaterialTheme.colorScheme.primary,
) {
val slowInFastOutEasing: Easing =
remember { CubicBezierEasing(0.25f, 0.1f, 0.25f, 1.0f) }
val linearInFastOutEasing: Easing =
remember { CubicBezierEasing(0.4f, 0.0f, 0.25f, 1.0f) }

val isRefreshing by refreshing.collectAsState()
var didRefresh by remember { mutableStateOf(false) }
val rotation = remember { Animatable(0f) }

LaunchedEffect(isRefreshing) {
launch {
val duration = 750
val target = 360f
if (isRefreshing) {
didRefresh = true
rotation.animateTo(
targetValue = 360f, animationSpec = infiniteRepeatable(
animation = tween(
durationMillis = duration, easing = slowInFastOutEasing
), repeatMode = RepeatMode.Restart
)
)
} else if (didRefresh) {
val remainingMillis: Int = ((target - rotation.value) / target * duration).toInt()
val easing = if (remainingMillis > (duration/2)) linearInFastOutEasing else LinearEasing
rotation.animateTo(
targetValue = 360f,
initialVelocity = rotation.velocity,
animationSpec = tween(
durationMillis = remainingMillis, easing = easing
)
)
rotation.snapTo(0f)
}
}
}

Icon(
imageVector = icon,
tint = tint,
modifier = modifier.rotate(rotation.value)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fun TextPreference(
info: (@Composable () -> Unit)? = null,
state: State<String>,
onSave: (String) -> Unit,
onCheck: (String) -> Boolean,
onCheck: (String) -> Boolean = { true },
) {
TextPreference(
icon = { Icon(icon) },
Expand Down Expand Up @@ -88,11 +88,13 @@ private fun TextPreference(
}
}

Surface(
Box(
modifier = Modifier
.fillMaxWidth()
.padding(padding.standard),
onClick = { showDialog = true },
.padding(padding.standard)
.clip(RoundedCornerShape(8.dp))
.clickable { showDialog = true }
,
) {
Column {
Row(
Expand Down
Loading

0 comments on commit b57775c

Please sign in to comment.