diff --git a/.editorconfig b/.editorconfig index 8a0e6703..4d372c8c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,6 +5,7 @@ root = true +# noinspection EditorConfigKeyCorrectness [*] indent_style = space diff --git a/app/app-scripts/pre-commit b/app/app-scripts/pre-commit new file mode 100644 index 00000000..f0c34fb6 --- /dev/null +++ b/app/app-scripts/pre-commit @@ -0,0 +1,19 @@ +#!/bin/bash +echo "*********************************************************" +echo "Running git pre-commit hook, ktlintCheck in progress..." +echo "*********************************************************" + +./gradlew ktlintCheck + +status=$? + +if [ "$status" = 0 ] ; then + echo "Static analysis found no problems." + exit 0 +else + echo "*********************************************************" + echo 1>&2 "ktlintCheck found violations it could not fix." + echo "Run ./gradlew ktlintFormat to fix formatting related issues..." + echo "*********************************************************" + exit 1 +fi diff --git a/app/build.gradle b/app/build.gradle index 1732a701..3a1f0630 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -187,7 +187,7 @@ dependencies { implementation 'com.airbnb.android:lottie:6.1.0' } -task installGitHook(type: Copy) { +tasks.register('installGitHook', Copy) { def suffix = "linux" if (Os.isFamily(Os.FAMILY_WINDOWS)) { suffix = "windows" @@ -197,3 +197,5 @@ task installGitHook(type: Copy) { rename("pre-commit-$suffix", 'pre-commit') fileMode 0775 } + +build.dependsOn installGitHook diff --git a/app/src/main/java/dev/arkbuilders/navigator/data/PermissionsHelper.kt b/app/src/main/java/dev/arkbuilders/navigator/data/PermissionsHelper.kt index 8e7062cc..8264d42e 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/data/PermissionsHelper.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/data/PermissionsHelper.kt @@ -26,17 +26,17 @@ import javax.inject.Singleton @Singleton class PermissionsHelper @Inject constructor(private val appContext: Context) { - val permissionResultFlow = MutableSharedFlow() + private val permissionResultFlow = MutableSharedFlow() private var writePermLauncher: ActivityResultLauncher? = null private var writePermUsingSettingsLauncher: ActivityResultLauncher? = null - private var writePermLauncher_R: ActivityResultLauncher? = null + private var writePermLauncherR: ActivityResultLauncher? = null fun registerActivity(activity: AppCompatActivity) { writePermLauncher = buildWritePermLauncher(activity) writePermUsingSettingsLauncher = buildWritePermsUsingSettingsLauncher(activity) - writePermLauncher_R = buildWritePermLauncher_R(activity) + writePermLauncherR = buildWritePermLauncherR(activity) } fun isWritePermissionGranted(): Boolean { @@ -56,7 +56,7 @@ class PermissionsHelper @Inject constructor(private val appContext: Context) { ) { val packageUri = "package:" + BuildConfig.APPLICATION_ID if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - writePermLauncher_R!!.launch(packageUri) + writePermLauncherR!!.launch(packageUri) } else { val rationale = fragment?.shouldShowRequestPermissionRationale( @@ -120,7 +120,7 @@ class PermissionsHelper @Inject constructor(private val appContext: Context) { } } - private fun buildWritePermLauncher_R( + private fun buildWritePermLauncherR( activity: AppCompatActivity ) = activity.registerForActivityResult( diff --git a/app/src/main/java/dev/arkbuilders/navigator/data/stats/AggregatedStatsStorage.kt b/app/src/main/java/dev/arkbuilders/navigator/data/stats/AggregatedStatsStorage.kt index 2550f5d6..7012a7ec 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/data/stats/AggregatedStatsStorage.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/data/stats/AggregatedStatsStorage.kt @@ -7,7 +7,7 @@ import kotlinx.coroutines.withContext import dev.arkbuilders.arklib.data.stats.StatsEvent import dev.arkbuilders.arklib.user.tags.Tag -class AggregatedStatsStorage(val shards: List) : StatsStorage { +class AggregatedStatsStorage(private val shards: List) : StatsStorage { override suspend fun init() = withContext(Dispatchers.IO) { shards.map { launch { it.init() } }.joinAll() diff --git a/app/src/main/java/dev/arkbuilders/navigator/data/stats/PlainStatsStorage.kt b/app/src/main/java/dev/arkbuilders/navigator/data/stats/PlainStatsStorage.kt index 83310cb4..2dedeca2 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/data/stats/PlainStatsStorage.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/data/stats/PlainStatsStorage.kt @@ -27,7 +27,7 @@ class PlainStatsStorage( private val index: RootIndex, private val preferences: Preferences, private val tagStorage: RootTagsStorage, - private val statsFlow: SharedFlow + statsFlow: SharedFlow ) : StatsStorage { private val root = index.path diff --git a/app/src/main/java/dev/arkbuilders/navigator/data/stats/StatsStorageRepo.kt b/app/src/main/java/dev/arkbuilders/navigator/data/stats/StatsStorageRepo.kt index b3ecb85d..c014f98d 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/data/stats/StatsStorageRepo.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/data/stats/StatsStorageRepo.kt @@ -33,7 +33,7 @@ class StatsStorageRepo( } } - suspend fun provide( + private suspend fun provide( root: RootIndex, tagsStorage: RootTagsStorage ): PlainStatsStorage = diff --git a/app/src/main/java/dev/arkbuilders/navigator/data/stats/category/StatsCategoryStorage.kt b/app/src/main/java/dev/arkbuilders/navigator/data/stats/category/StatsCategoryStorage.kt index ba633162..2beef30b 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/data/stats/category/StatsCategoryStorage.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/data/stats/category/StatsCategoryStorage.kt @@ -16,7 +16,7 @@ private const val FLUSH_INTERVAL = 10_000L abstract class StatsCategoryStorage( val root: Path, - val scope: CoroutineScope + private val scope: CoroutineScope ) { abstract val fileName: String private val flushFlow = MutableSharedFlow().also { flow -> @@ -36,7 +36,7 @@ abstract class StatsCategoryStorage( abstract fun provideData(): T protected abstract fun flush() - fun locateStorage() = root.arkFolder().arkStats().resolve(fileName) + fun locateStorage(): Path? = root.arkFolder().arkStats().resolve(fileName) protected fun requestFlush() = scope.launch { flushFlow.emit(Unit) diff --git a/app/src/main/java/dev/arkbuilders/navigator/data/stats/category/TagLabeledNStorage.kt b/app/src/main/java/dev/arkbuilders/navigator/data/stats/category/TagLabeledNStorage.kt index d618acc1..8ba67873 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/data/stats/category/TagLabeledNStorage.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/data/stats/category/TagLabeledNStorage.kt @@ -17,7 +17,7 @@ import kotlin.io.path.writeText class TagLabeledNStorage( val index: ResourceIndex, - val tagsStorage: TagStorage, + private val tagsStorage: TagStorage, root: Path, scope: CoroutineScope ) : StatsCategoryStorage>(root, scope) { @@ -26,7 +26,7 @@ class TagLabeledNStorage( override suspend fun init() { val storage = locateStorage() - if (storage.exists()) { + if (storage?.exists() == true) { val json = Json.decodeFromStream(storage.inputStream()) tagLabeledAmount.putAll(json.data) } else { @@ -64,7 +64,7 @@ class TagLabeledNStorage( override fun flush() { val data = Json.encodeToString(JsonTagLabeledN(tagLabeledAmount)) - locateStorage().writeText(data) + locateStorage()?.writeText(data) Timber.i("flushed with $tagLabeledAmount") } } diff --git a/app/src/main/java/dev/arkbuilders/navigator/data/stats/category/TagLabeledTSStorage.kt b/app/src/main/java/dev/arkbuilders/navigator/data/stats/category/TagLabeledTSStorage.kt index c4bbe779..d2a4c563 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/data/stats/category/TagLabeledTSStorage.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/data/stats/category/TagLabeledTSStorage.kt @@ -47,7 +47,7 @@ class TagLabeledTSStorage( override fun flush() { val data = Json.encodeToString(JsonTagLabeledTS(tagLabeledTS)) - locateStorage().writeText(data) + locateStorage()?.writeText(data) Timber.i("flushed with $tagLabeledTS") } } diff --git a/app/src/main/java/dev/arkbuilders/navigator/data/stats/category/TagQueriedNStorage.kt b/app/src/main/java/dev/arkbuilders/navigator/data/stats/category/TagQueriedNStorage.kt index 63754cab..ce997e31 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/data/stats/category/TagQueriedNStorage.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/data/stats/category/TagQueriedNStorage.kt @@ -48,7 +48,7 @@ class TagQueriedNStorage( override fun flush() { val data = Json.encodeToString(JsonTagQueriedN(tagQueriedN)) - locateStorage().writeText(data) + locateStorage()?.writeText(data) Timber.i("flushed with $tagQueriedN") } } diff --git a/app/src/main/java/dev/arkbuilders/navigator/data/stats/category/TagQueriedTSStorage.kt b/app/src/main/java/dev/arkbuilders/navigator/data/stats/category/TagQueriedTSStorage.kt index 56b0cdfe..f0de9935 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/data/stats/category/TagQueriedTSStorage.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/data/stats/category/TagQueriedTSStorage.kt @@ -22,9 +22,11 @@ class TagQueriedTSStorage( override suspend fun init() { val storage = locateStorage() - if (storage.notExists()) return - val json = Json.decodeFromStream(storage.inputStream()) - tagQueriedTS.putAll(json.data) + if (storage?.notExists() == true) return + val json = storage?.let { + Json.decodeFromStream(it.inputStream()) + } + json?.let { tagQueriedTS.putAll(it.data) } Timber.i("initialized with $tagQueriedTS") } @@ -43,7 +45,7 @@ class TagQueriedTSStorage( override fun flush() { val data = Json.encodeToString(JsonTagQueriedTS(tagQueriedTS)) - locateStorage().writeText(data) + locateStorage()?.writeText(data) Timber.i("flushed with $tagQueriedTS") } } diff --git a/app/src/main/java/dev/arkbuilders/navigator/presentation/dialog/RootPickerDialogFragment.kt b/app/src/main/java/dev/arkbuilders/navigator/presentation/dialog/RootPickerDialogFragment.kt index 3f2d6a1a..62f0e21e 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/presentation/dialog/RootPickerDialogFragment.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/presentation/dialog/RootPickerDialogFragment.kt @@ -19,7 +19,7 @@ class RootPickerDialogFragment : ArkFilePickerFragment() { @Inject lateinit var foldersRepo: FoldersRepo - var rootNotFavorite = false + private var rootNotFavorite = false override fun onAttach(context: Context) { App.instance.appComponent.inject(this) diff --git a/app/src/main/java/dev/arkbuilders/navigator/presentation/dialog/tagssort/TagsSortViewModel.kt b/app/src/main/java/dev/arkbuilders/navigator/presentation/dialog/tagssort/TagsSortViewModel.kt index 5c397947..18457333 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/presentation/dialog/tagssort/TagsSortViewModel.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/presentation/dialog/tagssort/TagsSortViewModel.kt @@ -34,7 +34,7 @@ sealed class TagsSortSideEffect { } class TagsSortViewModel( - private val selectorNotEdit: Boolean, + selectorNotEdit: Boolean, private val preferences: Preferences ) : ViewModel(), ContainerHost { override val container: Container = diff --git a/app/src/main/java/dev/arkbuilders/navigator/presentation/navigation/AppNavigator.kt b/app/src/main/java/dev/arkbuilders/navigator/presentation/navigation/AppNavigator.kt index be54fe4d..2a2d558b 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/presentation/navigation/AppNavigator.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/presentation/navigation/AppNavigator.kt @@ -5,7 +5,6 @@ import android.os.Bundle import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentManager -import androidx.fragment.app.FragmentTransaction import java.util.LinkedList import ru.terrakok.cicerone.Navigator import ru.terrakok.cicerone.android.support.SupportAppScreen @@ -54,7 +53,7 @@ class AppNavigator( * * @param command the navigation command to apply */ - protected fun applyCommand(command: Command?) { + private fun applyCommand(command: Command?) { when (command) { is Forward -> { activityForward(command) @@ -74,7 +73,7 @@ class AppNavigator( } } - protected fun activityForward(command: Forward) { + private fun activityForward(command: Forward) { val screen = command.screen as SupportAppScreen val activityIntent = screen.getActivityIntent(activity) @@ -87,16 +86,10 @@ class AppNavigator( } } - protected fun fragmentForward(command: Forward) { + private fun fragmentForward(command: Forward) { val screen = command.screen as SupportAppScreen val fragment = createFragment(screen) val fragmentTransaction = fragmentManager.beginTransaction() - setupFragmentTransaction( - command, - fragmentManager.findFragmentById(containerId), - fragment, - fragmentTransaction - ) fragmentTransaction .replace(containerId, fragment!!) .addToBackStack(screen.screenKey) @@ -108,12 +101,6 @@ class AppNavigator( val screen = command.screen as SupportAppScreen val fragment = createFragment(screen) val fragmentTransaction = fragmentManager.beginTransaction() - setupFragmentTransaction( - command, - fragmentManager.findFragmentById(containerId), - fragment, - fragmentTransaction - ) fragmentTransaction .add(containerId, fragment!!) .addToBackStack(screen.screenKey) @@ -121,7 +108,7 @@ class AppNavigator( localStackCopy!!.add(screen.screenKey) } - protected fun fragmentBack() { + private fun fragmentBack() { if (localStackCopy!!.size > 0) { fragmentManager.popBackStack() localStackCopy!!.removeLast() @@ -130,11 +117,11 @@ class AppNavigator( } } - protected fun activityBack() { + private fun activityBack() { activity.finish() } - protected fun activityReplace(command: Replace) { + private fun activityReplace(command: Replace) { val screen = command.screen as SupportAppScreen val activityIntent = screen.getActivityIntent(activity) @@ -148,19 +135,13 @@ class AppNavigator( } } - protected fun fragmentReplace(command: Replace) { + private fun fragmentReplace(command: Replace) { val screen = command.screen as SupportAppScreen val fragment = createFragment(screen) if (localStackCopy!!.size > 0) { fragmentManager.popBackStack() localStackCopy!!.removeLast() val fragmentTransaction = fragmentManager.beginTransaction() - setupFragmentTransaction( - command, - fragmentManager.findFragmentById(containerId), - fragment, - fragmentTransaction - ) fragmentTransaction .replace(containerId, fragment!!) .addToBackStack(screen.screenKey) @@ -168,12 +149,6 @@ class AppNavigator( localStackCopy!!.add(screen.screenKey) } else { val fragmentTransaction = fragmentManager.beginTransaction() - setupFragmentTransaction( - command, - fragmentManager.findFragmentById(containerId), - fragment, - fragmentTransaction - ) fragmentTransaction .replace(containerId, fragment!!) .commit() @@ -183,7 +158,7 @@ class AppNavigator( /** * Performs [BackTo] command transition */ - protected fun backTo(command: BackTo) { + private fun backTo(command: BackTo) { if (command.screen == null) { backToRoot() } else { @@ -206,24 +181,6 @@ class AppNavigator( localStackCopy!!.clear() } - /** - * Override this method to setup fragment transaction [FragmentTransaction]. - * For example: setCustomAnimations(...), addSharedElement(...) or setReorderingAllowed(...) - * - * @param command current navigation command. Will be only [Forward] or [Replace] - * @param currentFragment current fragment in container - * (for [Replace] command it will be screen previous in new chain, NOT replaced screen) - * @param nextFragment next screen fragment - * @param fragmentTransaction fragment transaction - */ - protected fun setupFragmentTransaction( - command: Command?, - currentFragment: Fragment?, - nextFragment: Fragment?, - fragmentTransaction: FragmentTransaction? - ) { - } - /** * Override this method to create option for start activity * @@ -231,7 +188,7 @@ class AppNavigator( * @param activityIntent activity intent * @return transition options */ - protected fun createStartActivityOptions( + private fun createStartActivityOptions( command: Command?, activityIntent: Intent? ): Bundle? { @@ -246,31 +203,16 @@ class AppNavigator( // Check if we can start activity if (activityIntent.resolveActivity(activity.packageManager) != null) { activity.startActivity(activityIntent, options) - } else { - unexistingActivity(screen, activityIntent) } } - /** - * Called when there is no activity to open `screenKey`. - * - * @param screen screen - * @param activityIntent intent passed to start Activity for the `screenKey` - */ - protected fun unexistingActivity( - screen: SupportAppScreen?, - activityIntent: Intent? - ) { - // Do nothing by default - } - /** * Creates Fragment matching `screenKey`. * * @param screen screen * @return instantiated fragment for the passed screen */ - protected fun createFragment(screen: SupportAppScreen): Fragment? { + private fun createFragment(screen: SupportAppScreen): Fragment? { val fragment = screen.fragment if (fragment == null) { errorWhileCreatingScreen(screen) @@ -284,11 +226,11 @@ class AppNavigator( * * @param screen screen */ - protected fun backToUnexisting(screen: SupportAppScreen?) { + private fun backToUnexisting(screen: SupportAppScreen?) { backToRoot() } - protected fun errorWhileCreatingScreen(screen: SupportAppScreen) { + private fun errorWhileCreatingScreen(screen: SupportAppScreen) { throw RuntimeException("Can't create a screen: " + screen.screenKey) } } diff --git a/app/src/main/java/dev/arkbuilders/navigator/presentation/navigation/Screens.kt b/app/src/main/java/dev/arkbuilders/navigator/presentation/navigation/Screens.kt index 91a2cf53..26e0ae05 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/presentation/navigation/Screens.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/presentation/navigation/Screens.kt @@ -18,12 +18,12 @@ class Screens { override fun getFragment() = FoldersFragment.newInstance(rescan = true) } - class ResourcesScreen(val rootAndFav: RootAndFav) : SupportAppScreen() { + class ResourcesScreen(private val rootAndFav: RootAndFav) : SupportAppScreen() { override fun getFragment() = ResourcesFragment.newInstance(rootAndFav) } class ResourcesScreenWithSelectedTag( - val rootAndFav: RootAndFav, + private val rootAndFav: RootAndFav, val tag: Tag ) : SupportAppScreen() { override fun getFragment() = ResourcesFragment.newInstanceWithSelectedTag( @@ -32,19 +32,19 @@ class Screens { } class GalleryScreen( - val rootAndFav: RootAndFav, + private val rootAndFav: RootAndFav, val resources: List, - val startAt: Int + private val startAt: Int ) : SupportAppScreen() { override fun getFragment() = GalleryFragment.newInstance(rootAndFav, resources, startAt) } class GalleryScreenWithSelected( - val rootAndFav: RootAndFav, + private val rootAndFav: RootAndFav, val resources: List, - val startAt: Int, - val selectedResources: List + private val startAt: Int, + private val selectedResources: List ) : SupportAppScreen() { override fun getFragment() = GalleryFragment.newInstance( diff --git a/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/folders/FoldersViewModel.kt b/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/folders/FoldersViewModel.kt index fc35870c..f3cb98b7 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/folders/FoldersViewModel.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/folders/FoldersViewModel.kt @@ -7,27 +7,30 @@ import androidx.lifecycle.viewModelScope import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject +import dev.arkbuilders.arkfilepicker.folders.FoldersRepo +import dev.arkbuilders.arklib.data.index.ResourceIndexRepo import dev.arkbuilders.navigator.data.PermissionsHelper import dev.arkbuilders.navigator.data.preferences.PreferenceKey import dev.arkbuilders.navigator.data.preferences.Preferences import dev.arkbuilders.navigator.data.utils.DevicePathsExtractor import dev.arkbuilders.navigator.data.utils.LogTags +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import org.orbitmvi.orbit.Container import org.orbitmvi.orbit.ContainerHost import org.orbitmvi.orbit.syntax.simple.intent import org.orbitmvi.orbit.syntax.simple.postSideEffect import org.orbitmvi.orbit.syntax.simple.reduce import org.orbitmvi.orbit.viewmodel.container -import dev.arkbuilders.arkfilepicker.folders.FoldersRepo -import dev.arkbuilders.arklib.data.index.ResourceIndexRepo import java.nio.file.Path +import android.view.View class ProgressWithText(val enabled: Boolean, val text: String = "") data class FoldersState private constructor( val devices: List, val folders: Map>, - val progressWithText: ProgressWithText + val progressWithText: ProgressWithText, ) { companion object { fun initial() = @@ -50,7 +53,7 @@ class FoldersViewModel( private val resourcesIndexRepo: ResourceIndexRepo, private val preferences: Preferences, private val permsHelper: PermissionsHelper, - private val devicePathsExtractor: DevicePathsExtractor + private val devicePathsExtractor: DevicePathsExtractor, ) : ViewModel(), ContainerHost { override val container: Container = container( @@ -83,7 +86,11 @@ class FoldersViewModel( postSideEffect(FoldersSideEffect.ToastFailedPaths(folders.failed)) reduce { - state.copy(devices, folders.succeeded, ProgressWithText(false)) + state.copy( + devices = devices, + folders = folders.succeeded, + progressWithText = ProgressWithText(false) + ) } showRootsScanIfNeeded() @@ -133,7 +140,7 @@ class FoldersViewModel( fun onForgetFavorite( root: Path, favorite: Path, - deleteFromMemory: Boolean + deleteFromMemory: Boolean, ) = intent { reduce { state.copy( @@ -190,7 +197,9 @@ class FoldersViewModel( } Log.d(LogTags.FOLDERS_SCREEN, "root $root added in RootsPresenter") - val path = root.toRealPath() + val path = withContext(Dispatchers.IO) { + root.toRealPath() + } var folders = foldersRepo.provideFolders() if (folders.containsKey(path)) { @@ -231,7 +240,9 @@ class FoldersViewModel( LogTags.FOLDERS_SCREEN, "favorite $favorite added in RootsPresenter" ) - val path = favorite.toRealPath() + val path = withContext(Dispatchers.IO) { + favorite.toRealPath() + } var folders = foldersRepo.provideFolders() val root = folders.keys.find { path.startsWith(it) } @@ -277,7 +288,7 @@ class FoldersViewModelFactory @AssistedInject constructor( private val resourcesIndexRepo: ResourceIndexRepo, private val preferences: Preferences, private val permsHelper: PermissionsHelper, - private val devicePathsExtractor: DevicePathsExtractor + private val devicePathsExtractor: DevicePathsExtractor, ) : ViewModelProvider.Factory { override fun create(modelClass: Class): T { return FoldersViewModel( @@ -293,7 +304,7 @@ class FoldersViewModelFactory @AssistedInject constructor( @AssistedFactory interface Factory { fun create( - @Assisted rescanRoots: Boolean + @Assisted rescanRoots: Boolean, ): FoldersViewModelFactory } } diff --git a/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/gallery/GalleryFragment.kt b/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/gallery/GalleryFragment.kt index a623d30d..d01b4e44 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/gallery/GalleryFragment.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/gallery/GalleryFragment.kt @@ -553,7 +553,7 @@ class GalleryFragment : return TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, dpValue, - getResources().displayMetrics + resources.displayMetrics ) } diff --git a/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/gallery/GalleryPresenter.kt b/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/gallery/GalleryPresenter.kt index a8903eb9..ef821814 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/gallery/GalleryPresenter.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/gallery/GalleryPresenter.kt @@ -2,27 +2,6 @@ package dev.arkbuilders.navigator.presentation.screen.gallery import android.util.Log import androidx.recyclerview.widget.DiffUtil -import dev.arkbuilders.components.scorewidget.ScoreWidgetController -import dev.arkbuilders.navigator.data.preferences.PreferenceKey -import dev.arkbuilders.navigator.data.preferences.Preferences -import dev.arkbuilders.navigator.data.stats.StatsStorage -import dev.arkbuilders.navigator.data.stats.StatsStorageRepo -import dev.arkbuilders.navigator.data.utils.LogTags.GALLERY_SCREEN -import dev.arkbuilders.navigator.di.modules.RepoModule.Companion.MESSAGE_FLOW_NAME -import dev.arkbuilders.navigator.domain.HandleGalleryExternalChangesUseCase -import dev.arkbuilders.navigator.presentation.navigation.AppRouter -import dev.arkbuilders.navigator.presentation.navigation.Screens -import dev.arkbuilders.navigator.presentation.screen.gallery.previewpager.PreviewImageViewHolder -import dev.arkbuilders.navigator.presentation.screen.gallery.previewpager.PreviewPlainTextViewHolder -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.NonCancellable -import kotlinx.coroutines.flow.MutableSharedFlow -import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.onEach -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext -import moxy.MvpPresenter -import moxy.presenterScope import dev.arkbuilders.arkfilepicker.folders.RootAndFav import dev.arkbuilders.arklib.ResourceId import dev.arkbuilders.arklib.data.Message @@ -45,6 +24,27 @@ import dev.arkbuilders.arklib.user.tags.Tags import dev.arkbuilders.arklib.user.tags.TagsStorageRepo import dev.arkbuilders.arklib.utils.ImageUtils import dev.arkbuilders.arklib.utils.extension +import dev.arkbuilders.components.scorewidget.ScoreWidgetController +import dev.arkbuilders.navigator.data.preferences.PreferenceKey +import dev.arkbuilders.navigator.data.preferences.Preferences +import dev.arkbuilders.navigator.data.stats.StatsStorage +import dev.arkbuilders.navigator.data.stats.StatsStorageRepo +import dev.arkbuilders.navigator.data.utils.LogTags.GALLERY_SCREEN +import dev.arkbuilders.navigator.di.modules.RepoModule.Companion.MESSAGE_FLOW_NAME +import dev.arkbuilders.navigator.domain.HandleGalleryExternalChangesUseCase +import dev.arkbuilders.navigator.presentation.navigation.AppRouter +import dev.arkbuilders.navigator.presentation.navigation.Screens +import dev.arkbuilders.navigator.presentation.screen.gallery.previewpager.PreviewImageViewHolder +import dev.arkbuilders.navigator.presentation.screen.gallery.previewpager.PreviewPlainTextViewHolder +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.NonCancellable +import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import moxy.MvpPresenter +import moxy.presenterScope import timber.log.Timber import java.io.FileReader import java.nio.file.Files @@ -57,8 +57,8 @@ import kotlin.io.path.notExists class GalleryPresenter( private val rootAndFav: RootAndFav, private val resourcesIds: List, - private val startAt: Int, - var selectingEnabled: Boolean, + startAt: Int, + private var selectingEnabled: Boolean, private val selectedResources: MutableList ) : MvpPresenter() { @@ -72,14 +72,12 @@ class GalleryPresenter( private set lateinit var tagsStorage: TagStorage private set - lateinit var previewStorage: PreviewProcessor - private set + private lateinit var previewStorage: PreviewProcessor lateinit var metadataStorage: MetadataProcessor private set lateinit var statsStorage: StatsStorage private set - lateinit var scoreStorage: ScoreStorage - private set + private lateinit var scoreStorage: ScoreStorage data class GalleryItem( val resource: Resource, @@ -365,7 +363,9 @@ class GalleryPresenter( val path = index.getPath(resource) - Files.delete(path) + withContext(Dispatchers.IO) { + Files.delete(path) + } index.updateAll() viewState.notifyResourcesChanged() diff --git a/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/resources/ResourcesPresenter.kt b/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/resources/ResourcesPresenter.kt index f9e647e6..90d2c69d 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/resources/ResourcesPresenter.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/resources/ResourcesPresenter.kt @@ -92,14 +92,11 @@ class ResourcesPresenter( private set lateinit var tagStorage: TagStorage private set - lateinit var metadataProcessor: MetadataProcessor - private set - lateinit var previewProcessor: PreviewProcessor - private set + private lateinit var metadataProcessor: MetadataProcessor + private lateinit var previewProcessor: PreviewProcessor lateinit var statsStorage: StatsStorage private set - lateinit var scoreStorage: ScoreStorage - private set + private lateinit var scoreStorage: ScoreStorage val gridPresenter = ResourcesGridPresenter(folders, viewState, presenterScope, this) diff --git a/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/resources/adapter/ResourcesGridPresenter.kt b/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/resources/adapter/ResourcesGridPresenter.kt index 7f3ffe42..28ea2d46 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/resources/adapter/ResourcesGridPresenter.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/presentation/screen/resources/adapter/ResourcesGridPresenter.kt @@ -39,18 +39,17 @@ data class ResourceItem( } class ResourcesGridPresenter( - val rootAndFav: RootAndFav, - val viewState: ResourcesView, - val scope: CoroutineScope, - val resourcesPresenter: ResourcesPresenter + private val rootAndFav: RootAndFav, + private val viewState: ResourcesView, + private val scope: CoroutineScope, + private val resourcesPresenter: ResourcesPresenter ) { @Inject lateinit var preferences: Preferences var resources = listOf() private set - var selection = listOf() - private set + private var selection = listOf() val selectedResources: List get() = resources.filter { it.isSelected }.map { it.id() } @@ -357,11 +356,7 @@ class ResourcesGridPresenter( val comparator = if (bySorting != null && byScores != null) { byScores.then(bySorting) - } else if (byScores == null) { - bySorting!! - } else { - byScores - } + } else byScores ?: bySorting!! resources = resources.sortedWith(comparator) @@ -406,7 +401,7 @@ class ResourcesGridPresenter( private fun scoreComparator(): Comparator? = if (sortByScores) { - Comparator { a, b -> + Comparator { a, b -> val aScore = scoreStorage.getScore(a.id()) val bScore = scoreStorage.getScore(b.id()) aScore.compareTo(bScore) diff --git a/app/src/main/java/dev/arkbuilders/navigator/presentation/view/DefaultPopup.kt b/app/src/main/java/dev/arkbuilders/navigator/presentation/view/DefaultPopup.kt index 6ed2e123..32785815 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/presentation/view/DefaultPopup.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/presentation/view/DefaultPopup.kt @@ -15,7 +15,7 @@ class DefaultPopup( val binding: ViewBinding, @StyleRes val animationId: Int? = null, @DrawableRes val bgId: Int? = null, - val elevation: Float = 0f, + private val elevation: Float = 0f, ) { lateinit var popupWindow: PopupWindow diff --git a/app/src/main/java/dev/arkbuilders/navigator/presentation/view/DepthPageTransformer.kt b/app/src/main/java/dev/arkbuilders/navigator/presentation/view/DepthPageTransformer.kt index d5599469..bcb0a609 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/presentation/view/DepthPageTransformer.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/presentation/view/DepthPageTransformer.kt @@ -2,6 +2,7 @@ package dev.arkbuilders.navigator.presentation.view import android.view.View import androidx.viewpager2.widget.ViewPager2 +import kotlin.math.abs private const val MIN_SCALE = 0.75f @@ -28,7 +29,7 @@ class DepthPageTransformer() : ViewPager2.PageTransformer { translationZ = -1f val scaleFactor = - (MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position))) + (MIN_SCALE + (1 - MIN_SCALE) * (1 - abs(position))) scaleX = scaleFactor scaleY = scaleFactor } diff --git a/app/src/main/java/dev/arkbuilders/navigator/presentation/view/StackedToasts.kt b/app/src/main/java/dev/arkbuilders/navigator/presentation/view/StackedToasts.kt index 11e73538..870f445b 100644 --- a/app/src/main/java/dev/arkbuilders/navigator/presentation/view/StackedToasts.kt +++ b/app/src/main/java/dev/arkbuilders/navigator/presentation/view/StackedToasts.kt @@ -27,8 +27,8 @@ import java.nio.file.Path import kotlin.io.path.absolutePathString class StackedToasts( - val rv: RecyclerView, - val lifecycleScope: CoroutineScope + private val rv: RecyclerView, + private val lifecycleScope: CoroutineScope ) { private val adapter = ItemAdapter() private val toasts = mutableListOf() diff --git a/app/src/main/res/layout/dialog_info.xml b/app/src/main/res/layout/dialog_info.xml index 42bef8b5..68f2de56 100644 --- a/app/src/main/res/layout/dialog_info.xml +++ b/app/src/main/res/layout/dialog_info.xml @@ -1,6 +1,5 @@ diff --git a/app/src/main/res/xml/provider_paths.xml b/app/src/main/res/xml/provider_paths.xml index 612d3246..310c6a97 100644 --- a/app/src/main/res/xml/provider_paths.xml +++ b/app/src/main/res/xml/provider_paths.xml @@ -1,4 +1,5 @@ + = resources.mapValues { Path("") } - override fun getPath(id: ResourceId): Path? = + override fun getPath(id: ResourceId): Path = Path("") } diff --git a/build.gradle b/build.gradle index 09a52db8..4e759723 100644 --- a/build.gradle +++ b/build.gradle @@ -9,10 +9,10 @@ buildscript { gradlePluginPortal() } dependencies { - classpath 'com.android.tools.build:gradle:7.2.1' + classpath 'com.android.tools.build:gradle:7.2.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jlleitschuh.gradle:ktlint-gradle:10.2.0" - classpath "de.mannodermaus.gradle.plugins:android-junit5:1.8.2.0" + classpath "de.mannodermaus.gradle.plugins:android-junit5:1.8.2.1" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }