diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/ScanMediaFolderChooserDialog.java b/app/src/main/java/code/name/monkey/retromusic/dialogs/ScanMediaFolderChooserDialog.java deleted file mode 100644 index 5b4acea7..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/ScanMediaFolderChooserDialog.java +++ /dev/null @@ -1 +0,0 @@ -/* * Copyright (c) 2019 Hemanth Savarala. * * Licensed under the GNU General Public License v3 * * This is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by * the Free Software Foundation either version 3 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. */ package code.name.monkey.retromusic.dialogs; import android.app.Activity; import android.content.Context; import android.media.MediaScannerConnection; import android.os.Bundle; import android.widget.Toast; import com.afollestad.materialdialogs.MaterialDialog; import java.io.File; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.DialogFragment; import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.misc.UpdateToastMediaScannerCompletionListener; import code.name.monkey.retromusic.util.PreferenceUtil; public class ScanMediaFolderChooserDialog extends DialogFragment /*implements MaterialDialog.ListCallback*/ { String initialPath = PreferenceUtil.getInstance().getStartDirectory().getAbsolutePath(); private File parentFolder; private File[] parentContents; private boolean canGoUp = false; public static ScanMediaFolderChooserDialog create() { return new ScanMediaFolderChooserDialog(); } private static void scanPaths(@NonNull WeakReference activityWeakReference, @NonNull Context applicationContext, @Nullable String[] toBeScanned) { Activity activity = activityWeakReference.get(); if (toBeScanned == null || toBeScanned.length < 1) { Toast.makeText(applicationContext, R.string.nothing_to_scan, Toast.LENGTH_SHORT).show(); } else { MediaScannerConnection.scanFile(applicationContext, toBeScanned, null, activity != null ? new UpdateToastMediaScannerCompletionListener(activity, toBeScanned) : null); } } 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 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) -> { final Context applicationContext = getActivity().getApplicationContext(); final WeakReference activityWeakReference = new WeakReference<>(getActivity()); dismiss(); new FoldersFragment.ListPathsAsyncTask(getActivity(), paths -> scanPaths(activityWeakReference, applicationContext, paths)).execute(new FoldersFragment.ListPathsAsyncTask.LoadingInfo(parentFolder, FoldersFragment.AUDIO_FILE_FILTER)); }) .onNegative((materialDialog, dialogAction) -> dismiss()) .positiveText(R.string.action_scan_directory) .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()); } private static class FolderSorter implements Comparator { @Override public int compare(File lhs, File rhs) { return lhs.getName().compareTo(rhs.getName()); } } } \ No newline at end of file diff --git a/app/src/main/res/menu/menu_folders.xml b/app/src/main/res/menu/menu_folders.xml index f1989ccc..79b0b5e2 100644 --- a/app/src/main/res/menu/menu_folders.xml +++ b/app/src/main/res/menu/menu_folders.xml @@ -2,12 +2,6 @@ - -