diff --git a/app/build.gradle b/app/build.gradle index 234f11426..5933e148e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ dependencies { compile 'com.theartofdev.edmodo:android-image-cropper:2.3.1' compile 'com.booking:rtlviewpager:1.0.1' compile 'com.simplemobiletools:fileproperties:1.0.2@aar' - compile 'com.simplemobiletools:filepicker:1.3.8@aar' + compile 'com.simplemobiletools:filepicker:1.3.9@aar' compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" apt 'com.jakewharton:butterknife-compiler:8.0.1' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7de7d9e7b..d94205c2c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -47,10 +47,6 @@ android:name=".activities.MediaActivity" android:parentActivityName=".activities.MainActivity"/> - - () - } - - override fun onResume() { - super.onResume() - tryloadGallery() - } - - private fun tryloadGallery() { - if (Utils.hasStoragePermission(applicationContext)) { - getDirectories() - } else { - toast(R.string.no_permissions) - } - } - - private fun getDirectories() { - GetDirectoriesAsynctask(applicationContext, false, false, ArrayList(), this).execute() - } - - override fun onItemClick(parent: AdapterView<*>, view: View, position: Int, id: Long) { - val path = mDirs!![position].path - } - - override fun gotDirectories(dirs: ArrayList) { - mDirs = dirs - - val adapter = DirectoryAdapter(this, dirs) - directories_grid.adapter = adapter - directories_grid.onItemClickListener = this - } - - companion object { - private var mDirs: MutableList? = null - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt index bbad09129..e8687dfd7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt @@ -5,8 +5,7 @@ import android.support.v4.util.Pair import android.support.v7.app.AlertDialog import android.view.LayoutInflater import android.view.WindowManager -import com.simplemobiletools.filepicker.extensions.getBasePath -import com.simplemobiletools.filepicker.extensions.getHumanReadablePath +import com.simplemobiletools.filepicker.extensions.humanizePath import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.Utils import com.simplemobiletools.gallery.asynctasks.CopyTask @@ -24,13 +23,14 @@ class CopyDialog(val activity: Activity, val files: List, val copyListener val view = LayoutInflater.from(context).inflate(R.layout.copy_item, null) val path = files[0].parent.trimEnd('/') - val basePath = path.getBasePath(context) - val humanPath = path.replaceFirst(basePath, activity.getHumanReadablePath(basePath)) - - view.source.text = humanPath + view.source.text = context.humanizePath(path) view.destination.setOnClickListener { - + PickAlbumDialog(activity, object : PickAlbumDialog.OnPickAlbumListener { + override fun onSuccess(path: String) { + view.destination.text = path + } + }) } AlertDialog.Builder(context) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickAlbumDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickAlbumDialog.kt new file mode 100644 index 000000000..b78139533 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickAlbumDialog.kt @@ -0,0 +1,55 @@ +package com.simplemobiletools.gallery.dialogs + +import android.app.Activity +import android.support.v7.app.AlertDialog +import android.view.LayoutInflater +import android.view.View +import android.widget.AdapterView +import android.widget.GridView +import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.adapters.DirectoryAdapter +import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask +import com.simplemobiletools.gallery.models.Directory +import kotlinx.android.synthetic.main.activity_main.view.* +import java.util.* + +class PickAlbumDialog(val activity: Activity, val listener: OnPickAlbumListener) : AdapterView.OnItemClickListener, GetDirectoriesAsynctask.GetDirectoriesListener { + val context = activity.applicationContext + var grid: GridView? = null + var dirs = ArrayList() + var dialog: AlertDialog? = null + + init { + val view = LayoutInflater.from(context).inflate(R.layout.dialog_album_picker, null) + grid = view.directories_grid + + dialog = AlertDialog.Builder(activity) + .setTitle(context.resources.getString(R.string.select_destination)) + .setView(view) + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .create().apply { + show() + } + + GetDirectoriesAsynctask(context, false, false, ArrayList(), this).execute() + } + + override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { + listener.onSuccess(dirs[position].path) + dialog?.dismiss() + } + + override fun gotDirectories(dirs: ArrayList) { + this.dirs = dirs + + val adapter = DirectoryAdapter(context, dirs) + + grid?.adapter = adapter + grid?.onItemClickListener = this + } + + interface OnPickAlbumListener { + fun onSuccess(path: String) + } +} diff --git a/app/src/main/res/layout/dialog_album_picker.xml b/app/src/main/res/layout/dialog_album_picker.xml new file mode 100644 index 000000000..774a991a9 --- /dev/null +++ b/app/src/main/res/layout/dialog_album_picker.xml @@ -0,0 +1,12 @@ + +