add a dialog for picking the copy destination

This commit is contained in:
tibbi 2016-11-09 21:10:08 +01:00
parent 3804f3d8f4
commit 2c7d62c863
6 changed files with 75 additions and 66 deletions

View file

@ -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'

View file

@ -47,10 +47,6 @@
android:name=".activities.MediaActivity"
android:parentActivityName=".activities.MainActivity"/>
<activity
android:name=".activities.PickAlbumActivity"
android:parentActivityName=".activities.MainActivity"/>
<activity
android:name=".activities.ViewPagerActivity"
android:configChanges="orientation|keyboardHidden|screenSize"

View file

@ -1,54 +0,0 @@
package com.simplemobiletools.gallery.activities
import android.os.Bundle
import android.view.View
import android.widget.AdapterView
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.Utils
import com.simplemobiletools.gallery.adapters.DirectoryAdapter
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
import com.simplemobiletools.gallery.extensions.toast
import com.simplemobiletools.gallery.models.Directory
import kotlinx.android.synthetic.main.activity_main.*
import java.util.*
class PickAlbumActivity : SimpleActivity(), AdapterView.OnItemClickListener, GetDirectoriesAsynctask.GetDirectoriesListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mDirs = ArrayList<Directory>()
}
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<String>(), this).execute()
}
override fun onItemClick(parent: AdapterView<*>, view: View, position: Int, id: Long) {
val path = mDirs!![position].path
}
override fun gotDirectories(dirs: ArrayList<Directory>) {
mDirs = dirs
val adapter = DirectoryAdapter(this, dirs)
directories_grid.adapter = adapter
directories_grid.onItemClickListener = this
}
companion object {
private var mDirs: MutableList<Directory>? = null
}
}

View file

@ -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<File>, 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)

View file

@ -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<Directory>()
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<String>(), 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<Directory>) {
this.dirs = dirs
val adapter = DirectoryAdapter(context, dirs)
grid?.adapter = adapter
grid?.onItemClickListener = this
}
interface OnPickAlbumListener {
fun onSuccess(path: String)
}
}

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/directories_grid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="@dimen/dir_tmb_size"
android:horizontalSpacing="1dp"
android:numColumns="auto_fit"
android:paddingTop="@dimen/activity_margin"
android:stretchMode="columnWidth"
android:verticalSpacing="1dp"/>