Skip to content

Commit

Permalink
- Create category exclusion feature for bookmark list
Browse files Browse the repository at this point in the history
  • Loading branch information
DesarrolloAntonio committed Jul 11, 2024
1 parent ad1e7e9 commit 2ddb523
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 24 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ android.nonTransitiveRClass=true
compileSdkVersion=34
minSdkVersion=21
targetSdkVersion=34
versionCode=43
versionName=1.33.01
versionCode=44
versionName=1.34

android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import android.content.Context
import okhttp3.OkHttpClient
import okhttp3.Request
import java.io.File
import android.os.Environment

class FileRemoteDataSource {
suspend fun downloadFile(
fun downloadFile(
context: Context,
url: String,
fileName: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.desarrollodroide.pagekeeper.ui.components

import android.util.Log
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
Expand Down Expand Up @@ -35,11 +36,12 @@ fun Categories(
onCategoriesSelectedChanged: (List<Tag>) -> Unit,
singleSelection: Boolean = false
) {
Log.v("selectedTags", "selectedTags: $selectedTags")
AnimatedVisibility(showCategories) {
Column {
FlowRow {
uniqueCategories.value.forEach { category ->
val selected = category in selectedTags.value
val selected = selectedTags.value.any { it.id == category.id }
FilterChip(
colors = FilterChipDefaults.filterChipColors(
containerColor = MaterialTheme.colorScheme.surface,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.desarrollodroide.pagekeeper.ui.feed

import android.util.Log
import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -32,6 +33,7 @@ import com.desarrollodroide.pagekeeper.ui.components.pulltorefresh.PullRefreshIn
import com.desarrollodroide.pagekeeper.ui.components.pulltorefresh.pullRefresh
import com.desarrollodroide.pagekeeper.ui.components.pulltorefresh.rememberPullRefreshState
import com.desarrollodroide.model.Bookmark
import com.desarrollodroide.model.Tag
import com.desarrollodroide.pagekeeper.ui.feed.item.BookmarkActions
import com.desarrollodroide.pagekeeper.ui.feed.item.BookmarkItem
import kotlinx.coroutines.delay
Expand All @@ -46,6 +48,7 @@ fun FeedContent(
isLegacyApi: Boolean,
token: String,
bookmarksPagingItems: LazyPagingItems<Bookmark>,
tagToHide: Tag?,
) {
val refreshCoroutineScope = rememberCoroutineScope()
var isRefreshing by remember { mutableStateOf(false) }
Expand All @@ -69,7 +72,8 @@ fun FeedContent(
) {
items(bookmarksPagingItems.itemCount) { index ->
val bookmark = bookmarksPagingItems[index]
if (bookmark != null) {
Log.v("TagToHide", "$tagToHide")
if (bookmark != null && bookmark.tags.none { it.id == tagToHide?.id }) {
BookmarkItem(
bookmark = bookmark,
serverURL = serverURL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ fun FeedScreen(
) {
val context = LocalContext.current
val tagsState by feedViewModel.tagsState.collectAsState()
val tagToHide by feedViewModel.tagToHide.collectAsState()

LaunchedEffect(Unit) {
feedViewModel.loadInitialData()
feedViewModel.getPagingBookmarks()
Expand Down Expand Up @@ -135,6 +137,7 @@ fun FeedScreen(
if (isCompactView) BookmarkViewType.SMALL else BookmarkViewType.FULL
},
bookmarksPagingItems = bookmarksPagingItems,
tagToHide = tagToHide
)
if (feedViewModel.showBookmarkEditorScreen.value && feedViewModel.bookmarkSelected.value != null) {
Box(
Expand Down Expand Up @@ -311,6 +314,7 @@ private fun FeedView(
isLegacyApi: Boolean,
token: String,
bookmarksPagingItems: LazyPagingItems<Bookmark>,
tagToHide: Tag?,
) {
if (bookmarksPagingItems.itemCount > 0) {
Column {
Expand All @@ -327,6 +331,7 @@ private fun FeedView(
token = token,
viewType = viewType,
bookmarksPagingItems = bookmarksPagingItems,
tagToHide = tagToHide
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class FeedViewModel(
val bookmarkToDelete = mutableStateOf<Bookmark?>(null)
val bookmarkToUpdateCache = mutableStateOf<Bookmark?>(null)
val isCompactView = MutableStateFlow<Boolean>(false)
val tagToHide = MutableStateFlow<Tag?>(null)

val availableTags: StateFlow<List<Tag>> = bookmarkDatabase.getAll()
.map { bookmarks ->
Expand Down Expand Up @@ -111,6 +112,7 @@ class FeedViewModel(
xSessionId = settingsPreferenceDataSource.getSession()
isLegacyApi = settingsPreferenceDataSource.getIsLegacyApi()
isCompactView.value = settingsPreferenceDataSource.getCompactView()
tagToHide.value = settingsPreferenceDataSource.getHideTag()
}
}

Expand Down Expand Up @@ -285,4 +287,5 @@ class FeedViewModel(
fun isLegacyApi(): Boolean = runBlocking {
settingsPreferenceDataSource.getIsLegacyApi()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ class LoginViewModel(
// var serverUrl = mutableStateOf("http://192.168.1.12:8080/")

// Synology
// var userName = mutableStateOf("Test")
// var password = mutableStateOf("Test")
// var serverUrl = mutableStateOf("http://192.168.1.68:18080/")
var userName = mutableStateOf("Test")
var password = mutableStateOf("Test")
var serverUrl = mutableStateOf("http://192.168.1.68:18080/")

var serverUrl = mutableStateOf("")
var userName = mutableStateOf("")
var password = mutableStateOf("")
// var serverUrl = mutableStateOf("")
// var userName = mutableStateOf("")
// var password = mutableStateOf("")

val userNameError = mutableStateOf(false)
val passwordError = mutableStateOf(false)
Expand All @@ -61,7 +61,7 @@ class LoginViewModel(
init {
viewModelScope.launch {
getUser()
getRememberUser()
//getRememberUser()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ fun FeedSection(
},
sheetState = sheetStateCategories,
) {
val categories: List<String> = tagsUiState.data?.map { it.name } ?: emptyList()
val categoriesState = remember { mutableStateOf(categories.map { Tag(it) }) }
val categories: List<Tag> = tagsUiState.data ?: emptyList()
val categoriesState = remember { mutableStateOf(categories) }
HideCategoryOptionView(
hideTag = hideTag,
uniqueCategories = categoriesState,
onApply = { selectedTag ->
scope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.desarrollodroide.model.Tag
Expand All @@ -32,8 +31,9 @@ import com.desarrollodroide.pagekeeper.ui.components.CategoriesType
fun HideCategoryOptionView(
onApply: (Tag?) -> Unit,
uniqueCategories: MutableState<List<Tag>>,
hideTag: Tag?,
) {
val selectedTags = remember { mutableStateOf(listOf<Tag>()) }
val selectedTags = remember { mutableStateOf(hideTag?.let { listOf(it) } ?: listOf()) }
Column(
modifier = Modifier
.fillMaxWidth()
Expand All @@ -42,7 +42,6 @@ fun HideCategoryOptionView(
) {
Text("Select category to hide", style = MaterialTheme.typography.headlineSmall)
Spacer(Modifier.height(8.dp))

if (uniqueCategories.value.isEmpty()) {
Row(
horizontalArrangement = Arrangement.Center,
Expand Down Expand Up @@ -116,7 +115,8 @@ fun SortAndFilterScreenPreview() {
MaterialTheme {
HideCategoryOptionView(
onApply = {},
uniqueCategories = regionOptions
uniqueCategories = regionOptions,
hideTag = null
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ fun SettingsScreenPreview() {
onNavigateToSourceCode = {},
onNavigateToTermsOfUse = {},
onNavigateToPrivacyPolicy = {},
//onCompactViewChanged = remember { MutableStateFlow(false) },
themeMode = remember { MutableStateFlow(ThemeMode.AUTO)},
goToLogin = {},
useDynamicColors = remember { MutableStateFlow(false) },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.desarrollodroide.pagekeeper.ui.settings

import android.util.Log
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.desarrollodroide.pagekeeper.helpers.ThemeManager
Expand All @@ -20,7 +18,6 @@ import com.desarrollodroide.model.Tag
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch

class SettingsViewModel(
Expand Down

0 comments on commit 2ddb523

Please sign in to comment.