Dialog corner and Filter song duration
This commit is contained in:
parent
a5a27e62aa
commit
fc868e1c2e
75 changed files with 1409 additions and 1294 deletions
|
@ -1,157 +0,0 @@
|
|||
package code.name.monkey.retromusic.dialogs;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Dialog;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.view.View;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import code.name.monkey.retromusic.R;
|
||||
|
||||
/**
|
||||
* @author Aidan Follestad (afollestad), modified by Karim Abou Zeid
|
||||
*/
|
||||
public class BlacklistFolderChooserDialog extends DialogFragment /*implements MaterialDialog.ListCallback */{
|
||||
|
||||
private String initialPath = Environment.getExternalStorageDirectory().getAbsolutePath();
|
||||
private File parentFolder;
|
||||
private File[] parentContents;
|
||||
private boolean canGoUp = false;
|
||||
private FolderCallback callback;
|
||||
|
||||
public static BlacklistFolderChooserDialog create() {
|
||||
return new BlacklistFolderChooserDialog();
|
||||
}
|
||||
|
||||
private String[] getContentsArray() {
|
||||
if (parentContents == null) {
|
||||
if (canGoUp) {
|
||||
return new String[]{".."};
|
||||
}
|
||||
return new String[]{};
|
||||
}
|
||||
String[] results = new String[parentContents.length + (canGoUp ? 1 : 0)];
|
||||
if (canGoUp) {
|
||||
results[0] = "..";
|
||||
}
|
||||
for (int i = 0; i < parentContents.length; i++) {
|
||||
results[canGoUp ? i + 1 : i] = parentContents[i].getName();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private File[] listFiles() {
|
||||
File[] contents = parentFolder.listFiles();
|
||||
List<File> results = new ArrayList<>();
|
||||
if (contents != null) {
|
||||
for (File fi : contents) {
|
||||
if (fi.isDirectory()) {
|
||||
results.add(fi);
|
||||
}
|
||||
}
|
||||
Collections.sort(results, new FolderSorter());
|
||||
return results.toArray(new File[results.size()]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
return new MaterialDialog.Builder(getActivity())
|
||||
.title(R.string.md_error_label)
|
||||
.content(R.string.md_storage_perm_error)
|
||||
.positiveText(android.R.string.ok)
|
||||
.build();
|
||||
}
|
||||
if (savedInstanceState == null) {
|
||||
savedInstanceState = new Bundle();
|
||||
}
|
||||
if (!savedInstanceState.containsKey("current_path")) {
|
||||
savedInstanceState.putString("current_path", initialPath);
|
||||
}
|
||||
parentFolder = new File(savedInstanceState.getString("current_path", File.pathSeparator));
|
||||
checkIfCanGoUp();
|
||||
parentContents = listFiles();
|
||||
MaterialDialog.Builder builder =
|
||||
new MaterialDialog.Builder(getActivity())
|
||||
.title(parentFolder.getAbsolutePath())
|
||||
.items((CharSequence[]) getContentsArray())
|
||||
.itemsCallback(this)
|
||||
.autoDismiss(false)
|
||||
.onPositive((dialog, which) -> {
|
||||
dismiss();
|
||||
callback.onFolderSelection(BlacklistFolderChooserDialog.this, parentFolder);
|
||||
})
|
||||
.onNegative((materialDialog, dialogAction) -> dismiss())
|
||||
.positiveText(R.string.add_action)
|
||||
.negativeText(android.R.string.cancel);
|
||||
return builder.build();
|
||||
}*/
|
||||
|
||||
/*@Override
|
||||
public void onSelection(MaterialDialog materialDialog, View view, int i, CharSequence s) {
|
||||
if (canGoUp && i == 0) {
|
||||
parentFolder = parentFolder.getParentFile();
|
||||
if (parentFolder.getAbsolutePath().equals("/storage/emulated")) {
|
||||
parentFolder = parentFolder.getParentFile();
|
||||
}
|
||||
checkIfCanGoUp();
|
||||
} else {
|
||||
parentFolder = parentContents[canGoUp ? i - 1 : i];
|
||||
canGoUp = true;
|
||||
if (parentFolder.getAbsolutePath().equals("/storage/emulated")) {
|
||||
parentFolder = Environment.getExternalStorageDirectory();
|
||||
}
|
||||
}
|
||||
reload();
|
||||
}*/
|
||||
|
||||
private void checkIfCanGoUp() {
|
||||
canGoUp = parentFolder.getParent() != null;
|
||||
}
|
||||
|
||||
private void reload() {
|
||||
parentContents = listFiles();
|
||||
MaterialDialog dialog = (MaterialDialog) getDialog();
|
||||
dialog.setTitle(parentFolder.getAbsolutePath());
|
||||
//dialog.setItems((CharSequence[]) getContentsArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString("current_path", parentFolder.getAbsolutePath());
|
||||
}
|
||||
|
||||
public void setCallback(FolderCallback callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public interface FolderCallback {
|
||||
void onFolderSelection(@NonNull BlacklistFolderChooserDialog dialog, @NonNull File folder);
|
||||
}
|
||||
|
||||
private static class FolderSorter implements Comparator<File> {
|
||||
|
||||
@Override
|
||||
public int compare(File lhs, File rhs) {
|
||||
return lhs.getName().compareTo(rhs.getName());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,162 @@
|
|||
package code.name.monkey.retromusic.dialogs
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Dialog
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import code.name.monkey.retromusic.R
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.list.listItems
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
/**
|
||||
* @author Aidan Follestad (afollestad), modified by Karim Abou Zeid
|
||||
*/
|
||||
class BlacklistFolderChooserDialog : DialogFragment() {
|
||||
|
||||
private val initialPath = Environment.getExternalStorageDirectory().absolutePath
|
||||
private var parentFolder: File? = null
|
||||
private var parentContents: Array<File>? = null
|
||||
private var canGoUp = false
|
||||
private var callback: FolderCallback? = null
|
||||
|
||||
|
||||
private fun contentsArray(): List<String> {
|
||||
if (parentContents == null) {
|
||||
return if (canGoUp) {
|
||||
return listOf("..")
|
||||
} else listOf()
|
||||
}
|
||||
|
||||
val results = arrayOfNulls<String>(parentContents!!.size + if (canGoUp) 1 else 0)
|
||||
if (canGoUp) {
|
||||
results[0] = ".."
|
||||
}
|
||||
for (i in parentContents!!.indices) {
|
||||
results[if (canGoUp) i + 1 else i] = parentContents!![i].name!!
|
||||
}
|
||||
|
||||
val data = ArrayList<String>()
|
||||
for (i in results) {
|
||||
data.add(i!!)
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
private fun listFiles(): Array<File>? {
|
||||
val contents = parentFolder!!.listFiles()
|
||||
val results = ArrayList<File>()
|
||||
if (contents != null) {
|
||||
for (fi in contents) {
|
||||
if (fi.isDirectory) {
|
||||
results.add(fi)
|
||||
}
|
||||
}
|
||||
Collections.sort(results, FolderSorter())
|
||||
return results.toTypedArray()
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
var savedInstanceStateFinal = savedInstanceState
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
|
||||
ActivityCompat.checkSelfPermission(activity!!, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
return MaterialDialog(activity!!).show {
|
||||
title(R.string.md_error_label)
|
||||
message(R.string.md_storage_perm_error)
|
||||
positiveButton(android.R.string.ok)
|
||||
}
|
||||
}
|
||||
if (savedInstanceStateFinal == null) {
|
||||
savedInstanceStateFinal = Bundle()
|
||||
}
|
||||
if (!savedInstanceStateFinal.containsKey("current_path")) {
|
||||
savedInstanceStateFinal.putString("current_path", initialPath)
|
||||
}
|
||||
parentFolder = File(savedInstanceStateFinal.getString("current_path", File.pathSeparator))
|
||||
checkIfCanGoUp()
|
||||
parentContents = listFiles()
|
||||
|
||||
return MaterialDialog(activity!!).show {
|
||||
title(text = parentFolder!!.absolutePath)
|
||||
listItems(items = contentsArray(), waitForPositiveButton = false) { dialog, index, text ->
|
||||
onSelection(dialog, index, text)
|
||||
}
|
||||
noAutoDismiss()
|
||||
positiveButton(R.string.add_action) {
|
||||
dismiss()
|
||||
callback!!.onFolderSelection(this@BlacklistFolderChooserDialog, parentFolder!!)
|
||||
}
|
||||
negativeButton(android.R.string.cancel) {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun onSelection(materialDialog: MaterialDialog, i: Int, s: String) {
|
||||
if (canGoUp && i == 0) {
|
||||
parentFolder = parentFolder!!.parentFile
|
||||
if (parentFolder!!.absolutePath == "/storage/emulated") {
|
||||
parentFolder = parentFolder!!.parentFile
|
||||
}
|
||||
checkIfCanGoUp()
|
||||
} else {
|
||||
parentFolder = parentContents!![if (canGoUp) i - 1 else i]
|
||||
canGoUp = true
|
||||
if (parentFolder!!.absolutePath == "/storage/emulated") {
|
||||
parentFolder = Environment.getExternalStorageDirectory()
|
||||
}
|
||||
}
|
||||
reload()
|
||||
}
|
||||
|
||||
private fun checkIfCanGoUp() {
|
||||
canGoUp = parentFolder!!.parent != null
|
||||
}
|
||||
|
||||
private fun reload() {
|
||||
parentContents = listFiles()
|
||||
val dialog = dialog as MaterialDialog?
|
||||
|
||||
dialog?.apply {
|
||||
setTitle(parentFolder!!.absolutePath)
|
||||
listItems(items = contentsArray()) { dialog, index, text ->
|
||||
onSelection(dialog, index, text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putString("current_path", parentFolder!!.absolutePath)
|
||||
}
|
||||
|
||||
fun setCallback(callback: FolderCallback) {
|
||||
this.callback = callback
|
||||
}
|
||||
|
||||
interface FolderCallback {
|
||||
fun onFolderSelection(dialog: BlacklistFolderChooserDialog, folder: File)
|
||||
}
|
||||
|
||||
private class FolderSorter : Comparator<File> {
|
||||
|
||||
override fun compare(lhs: File, rhs: File): Int {
|
||||
return lhs.name.compareTo(rhs.name)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun create(): BlacklistFolderChooserDialog {
|
||||
return BlacklistFolderChooserDialog()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,18 +18,17 @@ class ClearSmartPlaylistDialog : DialogFragment() {
|
|||
|
||||
val content = Html.fromHtml(getString(R.string.clear_playlist_x, playlist!!.name))
|
||||
|
||||
return MaterialDialog.Builder(activity!!)
|
||||
.title(title)
|
||||
.content(content)
|
||||
.positiveText(R.string.clear_action)
|
||||
.negativeText(android.R.string.cancel)
|
||||
.onPositive { _, _ ->
|
||||
if (activity == null) {
|
||||
return@onPositive
|
||||
}
|
||||
playlist.clear(activity)
|
||||
return MaterialDialog(activity!!).show {
|
||||
title(title)
|
||||
message(text = content)
|
||||
positiveButton(R.string.clear_action) {
|
||||
if (activity == null) {
|
||||
return@positiveButton
|
||||
}
|
||||
.build()
|
||||
playlist.clear(activity)
|
||||
}
|
||||
negativeButton { (android.R.string.cancel) }
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue