really exclude the selected folder

This commit is contained in:
tibbi 2017-03-04 10:28:02 +01:00
parent 9e4ed89e35
commit cf546e3c60
1 changed files with 21 additions and 3 deletions

View File

@ -2,23 +2,39 @@ package com.simplemobiletools.gallery.dialogs
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.RadioButton
import android.widget.RadioGroup
import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.getBasePath import com.simplemobiletools.commons.extensions.getBasePath
import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.activities.SimpleActivity
import com.simplemobiletools.gallery.extensions.config
import kotlinx.android.synthetic.main.dialog_exclude_folder.view.* import kotlinx.android.synthetic.main.dialog_exclude_folder.view.*
class ExcludeFolderDialog(val activity: SimpleActivity, val selectedPaths: List<String>, val callback: () -> Unit) { class ExcludeFolderDialog(val activity: SimpleActivity, val selectedPaths: List<String>, val callback: () -> Unit) {
var dialog: AlertDialog? = null var dialog: AlertDialog? = null
val alternativePaths = getAlternativePathsList()
var radioGroup: RadioGroup? = null
init { init {
val alternativePaths = getAlternativePaths()
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_exclude_folder, null).apply { val view = LayoutInflater.from(activity).inflate(R.layout.dialog_exclude_folder, null).apply {
exclude_folder_parent.beVisibleIf(alternativePaths.size > 1) exclude_folder_parent.beVisibleIf(alternativePaths.size > 1)
radioGroup = exclude_folder_radio_group
exclude_folder_radio_group.beVisibleIf(alternativePaths.size > 1) exclude_folder_radio_group.beVisibleIf(alternativePaths.size > 1)
} }
alternativePaths.forEachIndexed { index, value ->
val radioButton = (activity.layoutInflater.inflate(R.layout.radio_button, null) as RadioButton).apply {
text = alternativePaths[index]
isChecked = index == 0
id = index
}
radioGroup!!.addView(radioButton, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
}
AlertDialog.Builder(activity) AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() }) .setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() })
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
@ -28,10 +44,12 @@ class ExcludeFolderDialog(val activity: SimpleActivity, val selectedPaths: List<
} }
private fun dialogConfirmed() { private fun dialogConfirmed() {
val path = alternativePaths[radioGroup!!.checkedRadioButtonId]
activity.config.addExcludedFolder(path)
callback.invoke()
} }
private fun getAlternativePaths(): List<String> { private fun getAlternativePathsList(): List<String> {
val pathsList = ArrayList<String>() val pathsList = ArrayList<String>()
if (selectedPaths.size > 1) if (selectedPaths.size > 1)
return pathsList return pathsList