Skip to content

Commit 7bdb62f

Browse files
committed
Favorite folder
1 parent ca9a06d commit 7bdb62f

File tree

116 files changed

+737
-395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+737
-395
lines changed

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ android {
4141
else -> 0
4242
}
4343

44-
val vCode = 376
44+
val vCode = 379
4545
versionCode = vCode - singleAbiNum
46-
versionName = "2.0.14"
46+
versionName = "2.0.15"
4747

4848
ndk {
4949
//noinspection ChromeOsAbiSupport
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.ismartcoding.plain.data
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
6+
data class DFavoriteFolder(
7+
val rootPath: String,
8+
val fullPath: String
9+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.ismartcoding.plain.data
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
6+
data class FilePathData(
7+
val rootPath: String,
8+
val fullPath: String,
9+
val selectedPath: String
10+
)

app/src/main/java/com/ismartcoding/plain/db/DataInitializer.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class DataInitializer(val context: Context, val db: SupportSQLiteDatabase) {
1919

2020
private val tags =
2121
arrayOf(
22-
TagItem(R.string.favorites, DataType.AUDIO),
2322
TagItem(R.string.light_music, DataType.AUDIO),
2423
TagItem(R.string.movie, DataType.VIDEO),
2524
TagItem(R.string.family, DataType.IMAGE),

app/src/main/java/com/ismartcoding/plain/events/AppEvents.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ import com.ismartcoding.plain.features.bluetooth.BluetoothUtil
2727
import com.ismartcoding.plain.features.feed.FeedWorkerStatus
2828
import com.ismartcoding.plain.powerManager
2929
import com.ismartcoding.plain.services.HttpServerService
30+
import com.ismartcoding.plain.ui.models.FolderOption
3031
import com.ismartcoding.plain.web.AuthRequest
3132
import com.ismartcoding.plain.web.websocket.WebSocketHelper
3233
import io.ktor.server.websocket.DefaultWebSocketServerSession
3334
import kotlinx.coroutines.Job
3435
import kotlinx.coroutines.delay
3536
import kotlinx.coroutines.withTimeoutOrNull
3637

38+
class FolderKanbanSelectEvent(val data: FolderOption) : ChannelEvent()
39+
3740
// The events raised by the app
3841
class StartHttpServerEvent : ChannelEvent()
3942

app/src/main/java/com/ismartcoding/plain/preference/Preferences.kt

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,17 @@ import com.ismartcoding.plain.data.DScreenMirrorQuality
1919
import com.ismartcoding.plain.data.DVideo
2020
import com.ismartcoding.plain.data.NotificationFilterData
2121
import com.ismartcoding.plain.data.DPomodoroSettings
22+
import com.ismartcoding.plain.data.DFavoriteFolder
23+
import com.ismartcoding.plain.data.FilePathData
2224
import com.ismartcoding.plain.enums.AppFeatureType
2325
import com.ismartcoding.plain.enums.DarkTheme
2426
import com.ismartcoding.plain.enums.Language
2527
import com.ismartcoding.plain.enums.MediaPlayMode
2628
import com.ismartcoding.plain.enums.PasswordType
2729
import com.ismartcoding.plain.features.Permission
2830
import com.ismartcoding.plain.features.file.FileSortBy
29-
import org.json.JSONObject
3031
import java.util.Locale
3132

32-
data class FilePathData(
33-
val rootPath: String,
34-
val fullPath: String,
35-
val selectedPath: String
36-
)
3733

3834
object PasswordPreference : BasePreference<String>() {
3935
override val default = ""
@@ -477,12 +473,7 @@ object LastFilePathPreference : BasePreference<String>() {
477473
return FilePathData("", "", "")
478474
}
479475
return try {
480-
val json = JSONObject(str)
481-
FilePathData(
482-
rootPath = json.getString("root_path"),
483-
fullPath = json.getString("full_path"),
484-
selectedPath = json.getString("selected_path")
485-
)
476+
jsonDecode(str)
486477
} catch (e: Exception) {
487478
// If JSON parsing fails, return empty data
488479
FilePathData("", "", "")
@@ -493,12 +484,59 @@ object LastFilePathPreference : BasePreference<String>() {
493484
context: Context,
494485
data: FilePathData
495486
) {
496-
val json = JSONObject().apply {
497-
put("root_path", data.rootPath)
498-
put("full_path", data.fullPath)
499-
put("selected_path", data.selectedPath)
487+
putAsync(context, jsonEncode(data))
488+
}
489+
}
490+
491+
object FavoriteFoldersPreference : BasePreference<String>() {
492+
override val default = ""
493+
override val key = stringPreferencesKey("favorite_folders")
494+
495+
suspend fun getValueAsync(context: Context): List<DFavoriteFolder> {
496+
val str = getAsync(context)
497+
if (str.isEmpty()) {
498+
return listOf()
499+
}
500+
return try {
501+
jsonDecode(str)
502+
} catch (e: Exception) {
503+
listOf()
500504
}
501-
putAsync(context, json.toString())
505+
}
506+
507+
suspend fun putAsync(
508+
context: Context,
509+
value: List<DFavoriteFolder>
510+
) {
511+
putAsync(context, jsonEncode(value))
512+
}
513+
514+
suspend fun addAsync(
515+
context: Context,
516+
folder: DFavoriteFolder
517+
): List<DFavoriteFolder> {
518+
val items = getValueAsync(context).toMutableList()
519+
items.removeIf { it.fullPath == folder.fullPath }
520+
items.add(folder)
521+
putAsync(context, items)
522+
return items
523+
}
524+
525+
suspend fun removeAsync(
526+
context: Context,
527+
fullPath: String
528+
): List<DFavoriteFolder> {
529+
val items = getValueAsync(context).toMutableList()
530+
items.removeIf { it.fullPath == fullPath }
531+
putAsync(context, items)
532+
return items
533+
}
534+
535+
suspend fun isFavoriteAsync(
536+
context: Context,
537+
fullPath: String
538+
): Boolean {
539+
return getValueAsync(context).any { it.fullPath == fullPath }
502540
}
503541
}
504542

app/src/main/java/com/ismartcoding/plain/ui/base/ActionButtons.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,17 @@ fun ActionButtonCast(onClick: () -> Unit) {
190190
tint = MaterialTheme.colorScheme.onSurface,
191191
click = onClick,
192192
)
193+
}
194+
195+
@Composable
196+
fun IconTextFavoriteButton(
197+
isFavorite: Boolean = false,
198+
onClick: () -> Unit
199+
) {
200+
val icon = if (isFavorite) R.drawable.check else R.drawable.plus
201+
PIconTextActionButton(
202+
icon = icon,
203+
text = stringResource(R.string.favorites),
204+
click = onClick
205+
)
193206
}

0 commit comments

Comments
 (0)