Change DMG file picker to StorageChooser

Previous picker worked badly on Android P
This commit is contained in:
Davide Depau 2018-08-30 17:18:40 +02:00
parent 95c2f28a4a
commit 367c39c34d
Signed by: depau
GPG key ID: C7D999B6A55EFE86
4 changed files with 22 additions and 42 deletions

View file

@ -33,7 +33,7 @@ dependencies {
implementation 'com.android.support:gridlayout-v7:28.0.0-rc01' implementation 'com.android.support:gridlayout-v7:28.0.0-rc01'
api 'com.google.guava:guava:26.0-android' api 'com.google.guava:guava:26.0-android'
implementation 'com.github.isabsent:filepicker:1.1.01' implementation 'com.github.codekidX:storage-chooser:2.0.4.2'
// implementation 'com.github.mjdev:libaums:0.5.5' // implementation 'com.github.mjdev:libaums:0.5.5'
implementation project(':libaums') implementation project(':libaums')
implementation project(':dmg2img') implementation project(':dmg2img')

View file

@ -1,25 +1,12 @@
package eu.depau.etchdroid.activities package eu.depau.etchdroid.activities
import android.content.Intent import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.view.View import android.view.View
import com.github.isabsent.filepicker.SimpleFilePickerDialog
import eu.depau.etchdroid.StateKeeper import eu.depau.etchdroid.StateKeeper
import eu.depau.etchdroid.fragments.WizardFragment import eu.depau.etchdroid.fragments.WizardFragment
abstract class WizardActivity : AppCompatActivity(), SimpleFilePickerDialog.InteractionListenerString { abstract class WizardActivity : AppCompatActivity() {
override fun onResult(dialogTag: String, which: Int, extras: Bundle): Boolean {
if (StateKeeper.currentFragment is SimpleFilePickerDialog.InteractionListenerString)
return (StateKeeper.currentFragment as SimpleFilePickerDialog.InteractionListenerString).onResult(dialogTag, which, extras)
throw RuntimeException("Wrong fragment fsType")
}
override fun showListItemDialog(title: String?, folderPath: String?, mode: SimpleFilePickerDialog.CompositeMode?, dialogTag: String?) {
if (StateKeeper.currentFragment is SimpleFilePickerDialog.InteractionListenerString)
return (StateKeeper.currentFragment as SimpleFilePickerDialog.InteractionListenerString).showListItemDialog(title, folderPath, mode, dialogTag)
}
abstract fun goToNewFragment(fragment: WizardFragment) abstract fun goToNewFragment(fragment: WizardFragment)
open fun onCheckBoxClicked(view: View) { open fun onCheckBoxClicked(view: View) {

View file

@ -14,17 +14,17 @@ import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import com.github.isabsent.filepicker.SimpleFilePickerDialog import com.codekidlabs.storagechooser.StorageChooser
import eu.depau.etchdroid.R import eu.depau.etchdroid.R
import eu.depau.etchdroid.StateKeeper import eu.depau.etchdroid.StateKeeper
import eu.depau.etchdroid.activities.WizardActivity import eu.depau.etchdroid.activities.WizardActivity
import eu.depau.etchdroid.adapters.PartitionTableRecyclerViewAdapter import eu.depau.etchdroid.adapters.PartitionTableRecyclerViewAdapter
import eu.depau.etchdroid.kotlin_exts.getFileName
import eu.depau.etchdroid.kotlin_exts.snackbar
import eu.depau.etchdroid.enums.FlashMethod import eu.depau.etchdroid.enums.FlashMethod
import eu.depau.etchdroid.enums.ImageLocation import eu.depau.etchdroid.enums.ImageLocation
import eu.depau.etchdroid.enums.WizardStep import eu.depau.etchdroid.enums.WizardStep
import eu.depau.etchdroid.img_types.DMGImage import eu.depau.etchdroid.img_types.DMGImage
import eu.depau.etchdroid.kotlin_exts.getFileName
import eu.depau.etchdroid.kotlin_exts.snackbar
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.fragment_select_location.* import kotlinx.android.synthetic.main.fragment_select_location.*
import java.io.File import java.io.File
@ -33,8 +33,7 @@ import java.io.File
/** /**
* A placeholder fragment containing a simple view. * A placeholder fragment containing a simple view.
*/ */
class ImageLocationFragment : WizardFragment(), SimpleFilePickerDialog.InteractionListenerString { class ImageLocationFragment : WizardFragment() {
val READ_REQUEST_CODE = 42 val READ_REQUEST_CODE = 42
val MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 29 val MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 29
val TAG = "ImageLocationFragment" val TAG = "ImageLocationFragment"
@ -100,7 +99,21 @@ class ImageLocationFragment : WizardFragment(), SimpleFilePickerDialog.Interacti
FlashMethod.FLASH_DMG_API -> { FlashMethod.FLASH_DMG_API -> {
if (checkAndRequestStorageReadPerm()) { if (checkAndRequestStorageReadPerm()) {
val sdcard = Environment.getExternalStorageDirectory().absolutePath val sdcard = Environment.getExternalStorageDirectory().absolutePath
showListItemDialog("Select a DMG file", sdcard, SimpleFilePickerDialog.CompositeMode.FILE_ONLY_DIRECT_CHOICE_IMMEDIATE, PICKER_DIALOG_TAG)
val chooser = StorageChooser.Builder()
.withActivity(activity)
.withFragmentManager(activity!!.fragmentManager)
.withMemoryBar(true)
.allowCustomPath(true)
.setType(StorageChooser.FILE_PICKER)
.customFilter(arrayListOf("dmg"))
.build()
chooser.show()
chooser.setOnSelectListener {
StateKeeper.imageFile = Uri.fromFile(File(it))
loadImageChanges(activity as WizardActivity)
}
} }
} }
FlashMethod.FLASH_UNETBOOTIN -> { FlashMethod.FLASH_UNETBOOTIN -> {
@ -259,25 +272,4 @@ class ImageLocationFragment : WizardFragment(), SimpleFilePickerDialog.Interacti
} }
} }
} }
override fun onResult(dialogTag: String, which: Int, extras: Bundle): Boolean {
when (dialogTag) {
PICKER_DIALOG_TAG -> {
if (extras.containsKey(SimpleFilePickerDialog.SELECTED_SINGLE_PATH)) {
val path = extras.getString(SimpleFilePickerDialog.SELECTED_SINGLE_PATH)
StateKeeper.imageFile = Uri.fromFile(File(path))
loadImageChanges(activity as WizardActivity)
}
}
}
return false
}
override fun showListItemDialog(title: String?, folderPath: String?, mode: SimpleFilePickerDialog.CompositeMode?, dialogTag: String?) {
SimpleFilePickerDialog.build(folderPath, mode)
.title(title)
.show(this, dialogTag)
}
} }

View file

@ -25,6 +25,7 @@ allprojects {
repositories { repositories {
google() google()
jcenter() jcenter()
maven { url "https://jitpack.io" }
} }
} }