adding a backup way of retrieving OTG path

This commit is contained in:
tibbi 2019-03-27 17:29:00 +01:00
parent 052821d27f
commit 4d1e73f987
1 changed files with 11 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuItemCompat import androidx.core.view.MenuItemCompat
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.helpers.*
@ -209,10 +210,19 @@ class MainActivity : SimpleActivity() {
private fun checkOTGPath() { private fun checkOTGPath() {
Thread { Thread {
if (!config.wasOTGHandled && hasPermission(PERMISSION_WRITE_STORAGE) && hasOTGConnected() && config.OTGPath.isEmpty()) { if (!config.wasOTGHandled && hasPermission(PERMISSION_WRITE_STORAGE) && hasOTGConnected() && config.OTGPath.isEmpty()) {
config.wasOTGHandled = true
getStorageDirectories().firstOrNull { it.trimEnd('/') != internalStoragePath && it.trimEnd('/') != sdCardPath }?.apply { getStorageDirectories().firstOrNull { it.trimEnd('/') != internalStoragePath && it.trimEnd('/') != sdCardPath }?.apply {
config.wasOTGHandled = true
config.OTGPath = trimEnd('/') config.OTGPath = trimEnd('/')
} }
if (config.OTGPath.isEmpty()) {
runOnUiThread {
ConfirmationDialog(this, getString(R.string.usb_detected), positive = R.string.ok, negative = 0) {
config.wasOTGHandled = true
showOTGPermissionDialog()
}
}
}
} }
}.start() }.start()
} }