Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

ARK-Retouch#75: ARK Filepicker enhancements #19

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fcd0d3d
Forgetting roots and favorites
shubertm Dec 20, 2022
ed2ef71
Updating forget keys
shubertm Dec 21, 2022
ae5662d
Minor changes around forgetting roots and favorites
shubertm Dec 26, 2022
f5e3e8b
Adding actions to a group
shubertm Dec 27, 2022
efb7d1c
Adding actions to a group
shubertm Dec 27, 2022
dc8d0d5
Adding actions to a group
shubertm Dec 28, 2022
3c3fb2a
Adding actions to a group
shubertm Dec 28, 2022
008b368
Adding actions to a group
shubertm Dec 28, 2022
6e685ae
Adding actions to a group
shubertm Dec 28, 2022
528e798
Adding actions to a group
shubertm Dec 28, 2022
b95d11e
Adding actions to a group
shubertm Dec 28, 2022
fde52fe
Merge remote-tracking branch 'origin/grouping-root-and-fav-actions' i…
shubertm Dec 29, 2022
0ccdfce
Fixing forget root
shubertm Dec 31, 2022
606e34f
Fixing forget root
shubertm Dec 31, 2022
4532acd
Fixing forget root
shubertm Dec 31, 2022
dfafb01
Fixing forget root
shubertm Dec 31, 2022
5703d78
Fixing forget root
shubertm Dec 31, 2022
d5b9e8c
Fixing forget root
shubertm Dec 31, 2022
6767700
Fixing forget root
shubertm Dec 31, 2022
81b7946
Fixing forget root
shubertm Dec 31, 2022
5b495a1
Fixing folder options
shubertm Jan 1, 2023
7536fc4
Fixing folder options
shubertm Jan 1, 2023
982098e
Minor fixes
mdrlzy Jan 2, 2023
db50f75
Merge remote-tracking branch 'origin/main' into grouping-root-and-fav…
shubertm Jan 15, 2023
252f27e
Merge changes from main
shubertm Jan 15, 2023
6a89236
Checking roots availability
shubertm Aug 29, 2023
ba67926
Merge remote-tracking branch 'origin/main' into roots-availability
shubertm Aug 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package space.taran.arkfilepicker

object LogTags {
const val FILES: String = "files"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package space.taran.arkfilepicker.folders

import android.util.Log
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.withContext
import space.taran.arkfilepicker.FileUtils
import space.taran.arkfilepicker.LogTags
import space.taran.arkfilepicker.arkFolder
import java.nio.file.Path
import java.util.LinkedList
import java.util.Queue
import kotlin.io.path.exists
import kotlin.io.path.isDirectory
import kotlin.io.path.listDirectoryEntries

class ArkRootsScan {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scanning in Filepicker should work like this:

  1. Filepicker should start in classic mode.
  2. If user switches to ARK mode, we check presence of the roots file.
  3. If the roots file exists, we just take roots from it.
  4. Otherwise, we suggest scanning to the user.
  5. We do scanning, write to the roots file.

Also, Navigator should call the code from Filepicker in order to avoid duplication.

@ShubertMunthali @mdrlzy does it work like this now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user doesn't switch to ARK mode, scanning should not happen and should not be suggested.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filepicker should also remember in which mode it was used last time.
If last time was ARK mode, the user should start in ARK mode next time.
If last time was classic mode, the user starts in classic mode.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it works that way now, only that user cannot choose to use ARK-Mode or not

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this? We need new preference for this, I guess.

Filepicker should also remember in which mode it was used last time.
If last time was ARK mode, the user should start in ARK mode next time.
If last time was classic mode, the user starts in classic mode.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes


private val roots = mutableListOf<Path>()
private val queue: Queue<Path> = LinkedList()

fun getRoots() = roots

suspend fun scan(devices: List<Path>) = withContext(Dispatchers.IO) {
queue.addAll(devices)

while (queue.isNotEmpty()) {
ensureActive()
scanFolder(queue.poll()!!)
}
}

private fun scanFolder(folder: Path) = try {
if (folder.arkFolder().exists()) {
roots.add(folder)
} else
queue.addAll(folder.listDirectoryEntries().filter(Path::isDirectory))
} catch (e: Exception) {
Log.w(LogTags.FILES, "Can't scan $folder due to $e")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package space.taran.arkfilepicker.presentation.filepicker
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.util.Log
import android.util.TypedValue
import android.view.KeyEvent
import android.view.LayoutInflater
Expand All @@ -28,6 +29,7 @@ import com.mikepenz.fastadapter.GenericItem
import com.mikepenz.fastadapter.adapters.ItemAdapter
import com.mikepenz.fastadapter.binding.AbstractBindingItem
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.orbitmvi.orbit.viewmodel.observe
import space.taran.arkfilepicker.ArkFilePickerConfig
import space.taran.arkfilepicker.presentation.DevicesPopup
Expand Down Expand Up @@ -206,7 +208,6 @@ open class ArkFilePickerFragment :
}
}


private fun displayPath(state: FilePickerState) = binding.apply {
layoutPath.removeViews(1, layoutPath.childCount - 1)
val pathWithoutDevice =
Expand Down Expand Up @@ -310,7 +311,11 @@ open class ArkFilePickerFragment :

fun newInstance(config: ArkFilePickerConfig) =
ArkFilePickerFragment().apply {
setConfig(config)
runBlocking {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdrlzy is blocking fine here?

val roots = FoldersRepo.instance.provideFolders()
setConfig(config)
showRoots = config.showRoots && roots.isNotEmpty()
}
}

private const val DIALOG_WIDTH = 300f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.orbitmvi.orbit.syntax.simple.postSideEffect
import org.orbitmvi.orbit.syntax.simple.reduce
import org.orbitmvi.orbit.viewmodel.container
import space.taran.arkfilepicker.FileUtils
import space.taran.arkfilepicker.folders.ArkRootsScan
import space.taran.arkfilepicker.listChildren
import space.taran.arkfilepicker.folders.FoldersRepo
import java.nio.file.Path
Expand All @@ -29,6 +30,7 @@ internal data class FilePickerState(
val rootsWithFavs: Map<Path, List<Path>>
) {
val currentDevice get() = devices[selectedDevicePos]
val arkRootsAvailable get() = rootsWithFavs.isNotEmpty()
}

internal sealed class FilePickerSideEffect {
Expand All @@ -45,6 +47,8 @@ internal class ArkFilePickerViewModel(

private val foldersRepo = FoldersRepo.instance

private val arkRootsScanner = ArkRootsScan()

override val container: Container<FilePickerState, FilePickerSideEffect> =
container(initialState())

Expand Down Expand Up @@ -107,6 +111,12 @@ internal class ArkFilePickerViewModel(
}
}

private fun onScanArkRoots() {
viewModelScope.launch {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty coroutine?

}
}

private fun onPathPicked(path: Path) = intent {
postSideEffect(FilePickerSideEffect.NotifyPathPicked(path))
postSideEffect(FilePickerSideEffect.DismissDialog)
Expand Down
Loading