Skip to content

Commit

Permalink
[FEAT] Added destination Trash
Browse files Browse the repository at this point in the history
- Implemented MediaProvider.restore functionality.
- Introduced TrashViewModel.
- Added trash screen for managing deleted items.

[REFACTOR] Extracted common functionality to MainViewModel
- Moved FileActions and SelectionTracker from TimelineViewModel to a new superclass called MainViewModel.
- This refactor was necessary to centralize shared functionalities among various view models.

[FEAT] Added rudimentary implementation of Viewer Destination
- Basic implementation to support viewing files in the new destination.
  • Loading branch information
iZakirSheikh committed Jul 27, 2024
1 parent cc5c81d commit 229bc8a
Show file tree
Hide file tree
Showing 23 changed files with 1,627 additions and 331 deletions.
263 changes: 263 additions & 0 deletions .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 23 additions & 4 deletions api/src/main/java/com/zs/api/store/MediaProviderImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.zs.api.store.MediaProvider.Companion.COLUMN_DATE_ADDED
import com.zs.api.store.MediaProvider.Companion.COLUMN_DATE_EXPIRES
import com.zs.api.store.MediaProvider.Companion.COLUMN_DATE_MODIFIED
import com.zs.api.store.MediaProvider.Companion.COLUMN_DATE_TAKEN
import com.zs.api.store.MediaProvider.Companion.COLUMN_DURATION
import com.zs.api.store.MediaProvider.Companion.COLUMN_HEIGHT
import com.zs.api.store.MediaProvider.Companion.COLUMN_ID
import com.zs.api.store.MediaProvider.Companion.COLUMN_IS_TRASHED
Expand Down Expand Up @@ -89,7 +90,8 @@ private val Cursor.toTrashedFile: Trashed
expires = getLong(2) * 1000,
path = getString(3),
size = getLong(4),
mimeType = getString(5)
mimeType = getString(5),
duration = getInt(6)
)

private val MEDIA_PROJECTION =
Expand Down Expand Up @@ -117,6 +119,7 @@ private val TRASHED_PROJECTION =
COLUMN_PATH, // 3
COLUMN_SIZE, // 4
COLUMN_MIME_TYPE, // 5
COLUMN_DURATION // 6
)

/**
Expand Down Expand Up @@ -284,8 +287,24 @@ internal class MediaProviderImpl(
}
}

override suspend fun fetchTrashedFiles(offset: Int, limit: Int): List<Trashed> {
TODO("Not yet implemented")
override suspend fun fetchTrashedFiles(
offset: Int, limit: Int
): List<Trashed> {
return resolver.query2(
EXTERNAL_CONTENT_URI,
TRASHED_PROJECTION,
selection = "$COLUMN_IS_TRASHED = 1",
offset = offset,
limit = limit,
order = MediaProvider.COLUMN_DATE_EXPIRES,
ascending = false,
transform = { c ->
List(c.count) { index ->
c.moveToPosition(index)
c.toTrashedFile
}
}
)
}

override suspend fun fetchFilesFromDirectory(
Expand Down Expand Up @@ -450,7 +469,7 @@ internal class MediaProviderImpl(
// Count items after deletion (including trashed)
val after = count(true)
// Return the number of deleted items
if (Activity.RESULT_OK == result.resultCode) return before - after
if (Activity.RESULT_OK == result.resultCode) return after - before
// Log for debugging if result is unexpected
Log.d(TAG, "delete: before: $before, after: $after")
// Deletion failed for an unknown reason
Expand Down
3 changes: 2 additions & 1 deletion api/src/main/java/com/zs/api/store/Trashed.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package com.zs.api.store
* Represents a trashed file.
*
* @property id The unique identifier of the trashed file.
* @propertyname The name of the trashed file.
* @property name The name of the trashed file.
* @property expires The timestamp (in milliseconds) when the trashed file will be permanently deleted.
* @property path The absolute path to the trashed file.
* @property size The size of the trashed file in bytes.
Expand All @@ -35,6 +35,7 @@ data class Trashed(
val path: String,
val size: Long,
val mimeType: String,
val duration: Int,
)

val Trashed.isImage get() = mimeType.startsWith("image/")
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
applicationId = "com.googol.android.apps.photos"
minSdk = 21
targetSdk = 34
versionCode = 4
versionName = "0.1.0-dev04"
versionCode = 5
versionName = "0.1.0-dev05"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/zs/gallery/Home.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import androidx.navigation.NavController
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.google.accompanist.permissions.ExperimentalPermissionsApi
Expand All @@ -85,6 +86,8 @@ import com.zs.compose_ktx.navigation.NavRailItem
import com.zs.compose_ktx.navigation.NavigationItemDefaults
import com.zs.compose_ktx.navigation.NavigationSuiteScaffold
import com.zs.compose_ktx.toast.ToastHostState
import com.zs.gallery.bin.RouteTrash
import com.zs.gallery.bin.Trash
import com.zs.gallery.common.LocalNavController
import com.zs.gallery.common.LocalSystemFacade
import com.zs.gallery.common.NightMode
Expand All @@ -106,6 +109,7 @@ import com.zs.gallery.impl.FolderViewModel
import com.zs.gallery.impl.FoldersViewModel
import com.zs.gallery.impl.SettingsViewModel
import com.zs.gallery.impl.TimelineViewModel
import com.zs.gallery.impl.TrashViewModel
import com.zs.gallery.impl.ViewerViewModel
import com.zs.gallery.preview.RouteViewer
import com.zs.gallery.preview.Viewer
Expand Down Expand Up @@ -391,6 +395,12 @@ private val NavGraphBuilder: NavGraphBuilder.() -> Unit = {
val state = koinViewModel<AlbumViewModel>()
Album(viewState = state)
}

// Trash
composable(RouteTrash){
val state = koinViewModel<TrashViewModel>()
Trash(viewState = state)
}
}

// Default Enter/Exit Transitions.
Expand Down
Loading

0 comments on commit 229bc8a

Please sign in to comment.