Kotlin code refactor
parent
229393e766
commit
ffa3125438
|
@ -16,6 +16,7 @@ package code.name.monkey.retromusic.preferences
|
||||||
|
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.DialogInterface
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import androidx.core.graphics.BlendModeColorFilterCompat
|
import androidx.core.graphics.BlendModeColorFilterCompat
|
||||||
|
@ -27,9 +28,7 @@ import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.dialogs.BlacklistFolderChooserDialog
|
import code.name.monkey.retromusic.dialogs.BlacklistFolderChooserDialog
|
||||||
import code.name.monkey.retromusic.extensions.colorControlNormal
|
import code.name.monkey.retromusic.extensions.colorControlNormal
|
||||||
import code.name.monkey.retromusic.providers.BlacklistStore
|
import code.name.monkey.retromusic.providers.BlacklistStore
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.afollestad.materialdialogs.MaterialDialog
|
|
||||||
import com.afollestad.materialdialogs.list.listItems
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@ -61,59 +60,68 @@ class BlacklistPreferenceDialog : DialogFragment(), BlacklistFolderChooserDialog
|
||||||
childFragmentManager.findFragmentByTag("FOLDER_CHOOSER") as BlacklistFolderChooserDialog?
|
childFragmentManager.findFragmentByTag("FOLDER_CHOOSER") as BlacklistFolderChooserDialog?
|
||||||
chooserDialog?.setCallback(this)
|
chooserDialog?.setCallback(this)
|
||||||
refreshBlacklistData()
|
refreshBlacklistData()
|
||||||
return MaterialDialog(requireContext()).show {
|
return MaterialAlertDialogBuilder(
|
||||||
title(R.string.blacklist)
|
requireActivity(),
|
||||||
positiveButton(android.R.string.ok) {
|
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert
|
||||||
|
)
|
||||||
|
.setTitle(R.string.blacklist)
|
||||||
|
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
neutralButton(text = getString(R.string.clear_action)) {
|
.setNeutralButton(R.string.clear_action) { _, _ ->
|
||||||
MaterialDialog(requireContext()).show {
|
MaterialAlertDialogBuilder(
|
||||||
title(code.name.monkey.retromusic.R.string.clear_blacklist)
|
requireActivity(),
|
||||||
message(code.name.monkey.retromusic.R.string.do_you_want_to_clear_the_blacklist)
|
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert
|
||||||
|
)
|
||||||
positiveButton(code.name.monkey.retromusic.R.string.clear_action) {
|
.setTitle(R.string.clear_blacklist)
|
||||||
BlacklistStore.getInstance(requireContext()).clear()
|
.setMessage(R.string.do_you_want_to_clear_the_blacklist)
|
||||||
refreshBlacklistData()
|
.setPositiveButton(R.string.clear_action) { _, _ ->
|
||||||
|
BlacklistStore.getInstance(
|
||||||
|
requireContext()
|
||||||
|
).clear()
|
||||||
}
|
}
|
||||||
negativeButton(android.R.string.cancel)
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
|
.show()
|
||||||
}
|
}
|
||||||
}
|
.setNegativeButton(R.string.add_action) { _, _ ->
|
||||||
negativeButton(R.string.add_action) {
|
|
||||||
val dialog = BlacklistFolderChooserDialog.create()
|
val dialog = BlacklistFolderChooserDialog.create()
|
||||||
dialog.setCallback(this@BlacklistPreferenceDialog)
|
dialog.setCallback(this@BlacklistPreferenceDialog)
|
||||||
dialog.show(childFragmentManager, "FOLDER_CHOOSER")
|
dialog.show(requireActivity().supportFragmentManager, "FOLDER_CHOOSER")
|
||||||
}
|
}
|
||||||
listItems(items = paths, waitForPositiveButton = false) { _, _, text ->
|
.setItems(paths.toTypedArray()) { _, which ->
|
||||||
MaterialDialog(requireContext()).show {
|
MaterialAlertDialogBuilder(
|
||||||
|
requireActivity(),
|
||||||
title(code.name.monkey.retromusic.R.string.remove_from_blacklist)
|
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert
|
||||||
message(
|
)
|
||||||
text = HtmlCompat.fromHtml(
|
.setTitle(R.string.remove_from_blacklist)
|
||||||
|
.setMessage(
|
||||||
|
HtmlCompat.fromHtml(
|
||||||
|
String.format(
|
||||||
getString(
|
getString(
|
||||||
R.string.do_you_want_to_remove_from_the_blacklist,
|
R.string.do_you_want_to_remove_from_the_blacklist
|
||||||
text
|
),
|
||||||
|
paths[which]
|
||||||
),
|
),
|
||||||
HtmlCompat.FROM_HTML_MODE_LEGACY
|
HtmlCompat.FROM_HTML_MODE_LEGACY
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
positiveButton(code.name.monkey.retromusic.R.string.remove_action) {
|
.setPositiveButton(R.string.remove_action) { _, _ ->
|
||||||
BlacklistStore.getInstance(requireContext())
|
BlacklistStore.getInstance(requireContext())
|
||||||
.removePath(File(text.toString()))
|
.removePath(File(paths[which]))
|
||||||
refreshBlacklistData()
|
refreshBlacklistData()
|
||||||
}
|
}
|
||||||
negativeButton(android.R.string.cancel)
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
}
|
.show()
|
||||||
}
|
|
||||||
noAutoDismiss()
|
|
||||||
}
|
}
|
||||||
|
.create()
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var paths: ArrayList<String>
|
private lateinit var paths: ArrayList<String>
|
||||||
|
|
||||||
private fun refreshBlacklistData() {
|
private fun refreshBlacklistData() {
|
||||||
this.paths = BlacklistStore.getInstance(requireContext()).paths
|
this.paths = BlacklistStore.getInstance(requireContext()).paths
|
||||||
val dialog = dialog as MaterialDialog?
|
val dialog = dialog as MaterialAlertDialogBuilder?
|
||||||
dialog?.listItems(items = paths)
|
dialog?.setItems(paths.toTypedArray(), null)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFolderSelection(dialog: BlacklistFolderChooserDialog, folder: File) {
|
override fun onFolderSelection(dialog: BlacklistFolderChooserDialog, folder: File) {
|
||||||
|
|
|
@ -21,7 +21,6 @@ import android.os.Bundle
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AlertDialog
|
|
||||||
import androidx.core.graphics.BlendModeColorFilterCompat
|
import androidx.core.graphics.BlendModeColorFilterCompat
|
||||||
import androidx.core.graphics.BlendModeCompat.SRC_IN
|
import androidx.core.graphics.BlendModeCompat.SRC_IN
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
|
@ -65,7 +64,10 @@ class LibraryPreferenceDialog : DialogFragment() {
|
||||||
categoryAdapter.attachToRecyclerView(recyclerView)
|
categoryAdapter.attachToRecyclerView(recyclerView)
|
||||||
|
|
||||||
|
|
||||||
return MaterialAlertDialogBuilder(requireContext())
|
return MaterialAlertDialogBuilder(
|
||||||
|
requireContext(),
|
||||||
|
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert
|
||||||
|
)
|
||||||
.setTitle(R.string.library_categories)
|
.setTitle(R.string.library_categories)
|
||||||
.setNeutralButton(
|
.setNeutralButton(
|
||||||
R.string.reset_action
|
R.string.reset_action
|
||||||
|
|
Loading…
Reference in New Issue