Skip to content

Commit

Permalink
Add MovedFile.originalName & fix saveQuickMoveDestination
Browse files Browse the repository at this point in the history
  • Loading branch information
w2sv committed Oct 12, 2024
1 parent a1ff78b commit f24eb01
Show file tree
Hide file tree
Showing 18 changed files with 157 additions and 38 deletions.
5 changes: 1 addition & 4 deletions .idea/deploymentTargetSelector.xml

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

2 changes: 1 addition & 1 deletion app/src/main/kotlin/com/w2sv/filenavigator/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private fun useDarkTheme(theme: Theme): Boolean {
}
}

private class SwipeRightSplashScreenExitAnimation(private val onAnimationEnd: () -> Unit) :
private class SwipeRightSplashScreenExitAnimation(private val onAnimationEnd: () -> Unit = {}) :
SplashScreen.OnExitAnimationListener {
override fun onSplashScreenExit(splashScreenViewProvider: SplashScreenViewProvider) {
ObjectAnimator.ofFloat(
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<style name="Theme.App.SplashScreen" parent="Theme.SplashScreen">
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_app_foreground_108</item>
<item name="windowSplashScreenBackground">@color/ic_launcher_background</item>
<item name="postSplashScreenTheme">@style/Theme.AppCompat</item>
<item name="postSplashScreenTheme">@style/Theme.AppCompat.DayNight.NoActionBar</item>
</style>
</resources>
12 changes: 9 additions & 3 deletions core/database/schemas/com.w2sv.database.AppDatabase/5.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"formatVersion": 1,
"database": {
"version": 5,
"identityHash": "beddb7fbaf7eb898c488863ea61100c3",
"identityHash": "baf06b9c9598808e35a51d2ea98f893f",
"entities": [
{
"tableName": "MovedFileEntity",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`documentUri` TEXT NOT NULL, `name` TEXT NOT NULL, `type` TEXT NOT NULL, `sourceType` TEXT NOT NULL, `moveDateTime` TEXT NOT NULL, `autoMoved` INTEGER NOT NULL, `local_mediaUri` TEXT, `local_moveDestination` TEXT, `external_providerPackageName` TEXT, `external_providerAppLabel` TEXT, PRIMARY KEY(`moveDateTime`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`documentUri` TEXT NOT NULL, `name` TEXT NOT NULL, `originalName` TEXT, `type` TEXT NOT NULL, `sourceType` TEXT NOT NULL, `moveDateTime` TEXT NOT NULL, `autoMoved` INTEGER NOT NULL, `local_mediaUri` TEXT, `local_moveDestination` TEXT, `external_providerPackageName` TEXT, `external_providerAppLabel` TEXT, PRIMARY KEY(`moveDateTime`))",
"fields": [
{
"fieldPath": "documentUri",
Expand All @@ -20,6 +20,12 @@
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "originalName",
"columnName": "originalName",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "type",
"columnName": "type",
Expand Down Expand Up @@ -82,7 +88,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'beddb7fbaf7eb898c488863ea61100c3')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'baf06b9c9598808e35a51d2ea98f893f')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ internal class MigrationTest {
// Validate that the data exists and matches the original
assertTrue(migratedData.moveToFirst())
assertEquals(fileName, migratedData.getString("name"))
assertEquals("null", migratedData.getString("originalName"))
assertEquals(fileType, migratedData.getString("type"))
assertEquals(sourceType, migratedData.getString("sourceType"))
assertEquals(destinationDocumentUri, migratedData.getString("local_moveDestination"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import java.time.LocalDateTime
internal data class MovedFileEntity(
val documentUri: Uri,
val name: String,
val originalName: String?,
val type: FileType,
val sourceType: SourceType,
@PrimaryKey val moveDateTime: LocalDateTime,
Expand All @@ -34,6 +35,7 @@ internal data class MovedFileEntity(
constructor(movedFile: MovedFile) : this(
documentUri = movedFile.documentUri.uri,
name = movedFile.name,
originalName = movedFile.originalName,
type = movedFile.type,
sourceType = movedFile.sourceType,
moveDateTime = movedFile.moveDateTime,
Expand All @@ -56,6 +58,7 @@ internal data class MovedFileEntity(
documentUri = documentUri.documentUri,
mediaUri = local.mediaUri.mediaUri,
name = name,
originalName = originalName,
type = type,
sourceType = sourceType,
moveDestination = LocalDestination(local.moveDestination.documentUri),
Expand All @@ -72,6 +75,7 @@ internal data class MovedFileEntity(
providerAppLabel = external?.providerAppLabel
),
name = name,
originalName = originalName,
type = type,
sourceType = sourceType,
moveDateTime = moveDateTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ internal object Migrations {
"""CREATE TABLE IF NOT EXISTS $VERSION_5_TABLE_NAME (
documentUri TEXT NOT NULL,
name TEXT NOT NULL,
originalName TEXT DEFAULT NULL,
type TEXT NOT NULL,
sourceType TEXT NOT NULL,
moveDateTime TEXT NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ internal class RoomMovedFileRepositoryTest {
documentUri = DocumentUri.parse("kjhasdfkjh"),
mediaUri = MediaUri.parse("kjasdf"),
name = "someFile.jpg",
originalName = null,
type = FileType.Image,
sourceType = SourceType.Screenshot,
moveDestination = LocalDestination.parse("kjhasdfkjh"),
Expand All @@ -72,6 +73,7 @@ internal class RoomMovedFileRepositoryTest {
providerAppLabel = "Drive"
),
name = "someFile.jpg",
originalName = "previousName.jpg",
type = FileType.Image,
sourceType = SourceType.Screenshot,
moveDateTime = LocalDateTime.now()
Expand All @@ -83,6 +85,7 @@ internal class RoomMovedFileRepositoryTest {
providerAppLabel = null
),
name = "someFile.jpg",
originalName = null,
type = FileType.Image,
sourceType = SourceType.Screenshot,
moveDateTime = LocalDateTime.now()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal class NavigatorPreferencesToProtoMigration(
),
sourceConfig.enabled
),
lastMoveDestinations = preferences[PreMigrationNavigatorPreferencesKey.lastMoveDestination(
quickMoveDestinations = preferences[PreMigrationNavigatorPreferencesKey.lastMoveDestination(
fileType = fileType,
sourceType = sourceType
)]?.let { lastMoveDestination ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.w2sv.datastore.proto.navigatorconfig

import androidx.annotation.VisibleForTesting
import androidx.datastore.core.DataStore
import com.w2sv.common.util.log
import com.w2sv.datastore.NavigatorConfigProto
import com.w2sv.domain.model.FileType
import com.w2sv.domain.model.movedestination.LocalDestinationApi
import com.w2sv.domain.model.SourceType
import com.w2sv.domain.model.movedestination.LocalDestinationApi
import com.w2sv.domain.model.navigatorconfig.AutoMoveConfig
import com.w2sv.domain.model.navigatorconfig.NavigatorConfig
import com.w2sv.domain.repository.NavigatorConfigDataSource
Expand Down Expand Up @@ -54,19 +56,10 @@ internal class NavigatorConfigDataSourceImpl @Inject constructor(private val nav
sourceType
) { sourceConfig ->
sourceConfig.copy(
lastMoveDestinations = sourceConfig.lastMoveDestinations.let { currentDestinations ->
when (destination) {
currentDestinations.firstOrNull() -> currentDestinations
currentDestinations.getOrNull(1) -> currentDestinations.reversed()
else -> buildList {
add(destination)
currentDestinations.firstOrNull()
?.let { firstCurrentElement ->
add(firstCurrentElement)
}
}
}
}
quickMoveDestinations = updatedQuickMoveDestinations(
currentDestinations = sourceConfig.quickMoveDestinations,
destination = destination
)
)
}
}
Expand All @@ -81,7 +74,7 @@ internal class NavigatorConfigDataSourceImpl @Inject constructor(private val nav
fileType,
sourceType
) {
it.copy(lastMoveDestinations = listOf())
it.copy(quickMoveDestinations = listOf())
}
}
}
Expand All @@ -90,8 +83,22 @@ internal class NavigatorConfigDataSourceImpl @Inject constructor(private val nav
fileType: FileType,
sourceType: SourceType
): Flow<List<LocalDestinationApi>> =
navigatorConfig.map { it.sourceConfig(fileType, sourceType).lastMoveDestinations }
navigatorConfig.map { it.sourceConfig(fileType, sourceType).quickMoveDestinations }
}



@VisibleForTesting
internal fun updatedQuickMoveDestinations(
currentDestinations: List<LocalDestinationApi>,
destination: LocalDestinationApi
): List<LocalDestinationApi> =
when (destination.documentUri) {
currentDestinations.firstOrNull()?.documentUri -> currentDestinations
currentDestinations.getOrNull(1)?.documentUri -> currentDestinations.reversed()
else -> buildList {
add(destination)
currentDestinations.firstOrNull()
?.let { firstCurrentElement ->
add(firstCurrentElement)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private object SourceConfigMapper :
override fun toExternal(proto: SourceConfigProto): SourceConfig =
SourceConfig(
enabled = proto.enabled,
lastMoveDestinations = proto.lastMoveDestinationsList.map { LocalDestination.parse(it) },
quickMoveDestinations = proto.lastMoveDestinationsList.map { LocalDestination.parse(it) },
autoMoveConfig = AutoMoveConfigMapper.toExternal(proto.autoMoveConfig)
)

Expand All @@ -87,7 +87,7 @@ private object SourceConfigMapper :
this.enabled = external.enabled
this.lastMoveDestinations.apply {
clear()
addAll(external.lastMoveDestinations.map { it.uriString })
addAll(external.quickMoveDestinations.map { it.uriString })
}
this.autoMoveConfig = AutoMoveConfigMapper.toProto(external.autoMoveConfig)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.w2sv.datastore.proto.navigatorconfig

import com.w2sv.domain.model.movedestination.LocalDestination
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner

@RunWith(RobolectricTestRunner::class)
class NavigatorConfigDataSourceImplTest {

private val localDestinationA =
LocalDestination.parse("content://com.android.externalstorage.documents/document/primary%3AMoved%2FGIFs")
private val localDestinationB =
LocalDestination.parse("content://com.android.externalstorage.documents/document/primary%3AMoved%2FScreenshots")
private val localDestinationC =
LocalDestination.parse("content://com.android.externalstorage.documents/document/primary%3AMoved")

@Test
fun testUpdatedQuickMoveDestinations() {
// When current destinations empty -> destination is added
assertEquals(
listOf(localDestinationA),
updatedQuickMoveDestinations(
currentDestinations = emptyList(),
destination = localDestinationA
)
)

// When new destination equals first destination -> list stays as is
assertEquals(
listOf(localDestinationA),
updatedQuickMoveDestinations(
currentDestinations = listOf(localDestinationA),
destination = localDestinationA
)
)

// When new destination equals first destination -> list stays as is
assertEquals(
listOf(localDestinationA, localDestinationB),
updatedQuickMoveDestinations(
currentDestinations = listOf(localDestinationA, localDestinationB),
destination = localDestinationA
)
)

// When new destination equals second destination -> list gets reversed
assertEquals(
listOf(localDestinationB, localDestinationA),
updatedQuickMoveDestinations(
currentDestinations = listOf(localDestinationA, localDestinationB),
destination = localDestinationB
)
)

// When new destination not in list -> second is removed, first becomes second, new becomes first
assertEquals(
listOf(localDestinationC, localDestinationA),
updatedQuickMoveDestinations(
currentDestinations = listOf(localDestinationA, localDestinationB),
destination = localDestinationC
)
)

// When new destination not in list -> first becomes second, new becomes first
assertEquals(
listOf(localDestinationB, localDestinationA),
updatedQuickMoveDestinations(
currentDestinations = listOf(localDestinationA),
destination = localDestinationB
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal class NavigatorConfigMapperTest {
.copyWithAlteredSourceConfig(FileType.Audio, SourceType.Recording) {
it.copy(
enabled = false,
lastMoveDestinations = listOf(
quickMoveDestinations = listOf(
LocalDestination.parse("last/move/destination"),
LocalDestination.parse("before/last/move/destination")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.time.LocalDateTime
sealed interface MovedFile {
val documentUri: DocumentUri
val name: String
val originalName: String?
val type: FileType
val sourceType: SourceType
val moveDestination: MoveDestinationApi
Expand All @@ -33,6 +34,7 @@ sealed interface MovedFile {
override val documentUri: DocumentUri,
val mediaUri: MediaUri,
override val name: String,
override val originalName: String?,
override val type: FileType,
override val sourceType: SourceType,
override val moveDestination: LocalDestinationApi,
Expand All @@ -46,6 +48,7 @@ sealed interface MovedFile {
*/
data class External(
override val name: String,
override val originalName: String?,
override val type: FileType,
override val sourceType: SourceType,
override val moveDestination: ExternalDestinationApi,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import com.w2sv.domain.model.movedestination.LocalDestinationApi

data class SourceConfig(
val enabled: Boolean = true,
val lastMoveDestinations: List<LocalDestinationApi> = emptyList(),
val quickMoveDestinations: List<LocalDestinationApi> = emptyList(),
val autoMoveConfig: AutoMoveConfig = AutoMoveConfig.Empty
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import com.w2sv.common.util.documentUri
import com.w2sv.common.util.emit
import com.w2sv.common.util.log
import com.w2sv.common.util.takePersistableReadAndWriteUriPermission
import com.w2sv.navigator.moving.model.NavigatorMoveDestination
import com.w2sv.navigator.MoveResultChannel
import com.w2sv.navigator.moving.model.DestinationSelectionManner
import com.w2sv.navigator.moving.model.MediaIdWithMediaType
import com.w2sv.navigator.moving.model.MoveBundle
import com.w2sv.navigator.moving.model.MoveFile
import com.w2sv.navigator.moving.model.MoveResult
import com.w2sv.navigator.moving.model.NavigatorMoveDestination
import com.w2sv.navigator.moving.receiver.MoveBroadcastReceiver
import com.w2sv.navigator.notifications.NotificationResources
import dagger.hilt.android.AndroidEntryPoint
Expand Down
Loading

0 comments on commit f24eb01

Please sign in to comment.