remove blacklist feature
This commit is contained in:
parent
9923a4c1e0
commit
6afd14c647
39 changed files with 0 additions and 689 deletions
|
|
@ -1,160 +0,0 @@
|
|||
package com.kabouzeid.gramophone.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.annotation.NonNull;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import android.view.View;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Aidan Follestad (afollestad), modified by Karim Abou Zeid
|
||||
*/
|
||||
public class BlacklistFolderChooserDialog extends DialogFragment implements MaterialDialog.ListCallback {
|
||||
|
||||
private File parentFolder;
|
||||
private File[] parentContents;
|
||||
private boolean canGoUp = false;
|
||||
|
||||
private FolderCallback callback;
|
||||
|
||||
String initialPath = Environment.getExternalStorageDirectory().getAbsolutePath();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static BlacklistFolderChooserDialog create() {
|
||||
return new BlacklistFolderChooserDialog();
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,6 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.provider.BlacklistStore;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -110,13 +109,6 @@ public class SongLoader {
|
|||
selection = BASE_SELECTION;
|
||||
}
|
||||
|
||||
// Blacklist
|
||||
List<String> paths = BlacklistStore.getInstance(context).getPaths();
|
||||
if (!paths.isEmpty()) {
|
||||
selection = generateBlacklistSelection(selection, paths.size());
|
||||
selectionValues = addBlacklistSelectionValues(selectionValues, paths);
|
||||
}
|
||||
|
||||
try {
|
||||
return context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
|
||||
BASE_PROJECTION, selection, selectionValues, sortOrder);
|
||||
|
|
@ -124,23 +116,4 @@ public class SongLoader {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String generateBlacklistSelection(String selection, int pathCount) {
|
||||
String newSelection = selection != null && !selection.trim().equals("") ? selection + " AND " : "";
|
||||
newSelection += AudioColumns.DATA + " NOT LIKE ?";
|
||||
for (int i = 0; i < pathCount - 1; i++) {
|
||||
newSelection += " AND " + AudioColumns.DATA + " NOT LIKE ?";
|
||||
}
|
||||
return newSelection;
|
||||
}
|
||||
|
||||
private static String[] addBlacklistSelectionValues(String[] selectionValues, List<String> paths) {
|
||||
if (selectionValues == null) selectionValues = new String[0];
|
||||
String[] newSelectionValues = new String[selectionValues.length + paths.size()];
|
||||
System.arraycopy(selectionValues, 0, newSelectionValues, 0, selectionValues.length);
|
||||
for (int i = selectionValues.length; i < newSelectionValues.length; i++) {
|
||||
newSelectionValues[i] = paths.get(i - selectionValues.length) + "%";
|
||||
}
|
||||
return newSelectionValues;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
package com.kabouzeid.gramophone.preferences;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEDialogPreference;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class BlacklistPreference extends ATEDialogPreference {
|
||||
public BlacklistPreference(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public BlacklistPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public BlacklistPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public BlacklistPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,90 +0,0 @@
|
|||
package com.kabouzeid.gramophone.preferences;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import android.text.Html;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.dialogs.BlacklistFolderChooserDialog;
|
||||
import com.kabouzeid.gramophone.provider.BlacklistStore;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class BlacklistPreferenceDialog extends DialogFragment implements BlacklistFolderChooserDialog.FolderCallback {
|
||||
|
||||
private List<String> paths;
|
||||
|
||||
public static BlacklistPreferenceDialog newInstance() {
|
||||
return new BlacklistPreferenceDialog();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
BlacklistFolderChooserDialog blacklistFolderChooserDialog = (BlacklistFolderChooserDialog) getChildFragmentManager().findFragmentByTag("FOLDER_CHOOSER");
|
||||
if (blacklistFolderChooserDialog != null) {
|
||||
blacklistFolderChooserDialog.setCallback(this);
|
||||
}
|
||||
|
||||
refreshBlacklistData();
|
||||
return new MaterialDialog.Builder(getContext())
|
||||
.title(R.string.blacklist)
|
||||
.positiveText(android.R.string.ok)
|
||||
.neutralText(R.string.clear_action)
|
||||
.negativeText(R.string.add_action)
|
||||
.items(paths)
|
||||
.autoDismiss(false)
|
||||
.itemsCallback((materialDialog, view, i, charSequence) -> new MaterialDialog.Builder(getContext())
|
||||
.title(R.string.remove_from_blacklist)
|
||||
.content(Html.fromHtml(getString(R.string.do_you_want_to_remove_from_the_blacklist, charSequence)))
|
||||
.positiveText(R.string.remove_action)
|
||||
.negativeText(android.R.string.cancel)
|
||||
.onPositive((materialDialog12, dialogAction) -> {
|
||||
BlacklistStore.getInstance(getContext()).removePath(new File(charSequence.toString()));
|
||||
refreshBlacklistData();
|
||||
}).show())
|
||||
// clear
|
||||
.onNeutral((materialDialog, dialogAction) -> new MaterialDialog.Builder(getContext())
|
||||
.title(R.string.clear_blacklist)
|
||||
.content(R.string.do_you_want_to_clear_the_blacklist)
|
||||
.positiveText(R.string.clear_action)
|
||||
.negativeText(android.R.string.cancel)
|
||||
.onPositive((materialDialog1, dialogAction1) -> {
|
||||
BlacklistStore.getInstance(getContext()).clear();
|
||||
refreshBlacklistData();
|
||||
}).show())
|
||||
// add
|
||||
.onNegative((materialDialog, dialogAction) -> {
|
||||
BlacklistFolderChooserDialog dialog = BlacklistFolderChooserDialog.create();
|
||||
dialog.setCallback(BlacklistPreferenceDialog.this);
|
||||
dialog.show(getChildFragmentManager(), "FOLDER_CHOOSER");
|
||||
})
|
||||
.onPositive((materialDialog, dialogAction) -> dismiss())
|
||||
.build();
|
||||
}
|
||||
|
||||
private void refreshBlacklistData() {
|
||||
paths = BlacklistStore.getInstance(getContext()).getPaths();
|
||||
|
||||
MaterialDialog dialog = (MaterialDialog) getDialog();
|
||||
if (dialog != null) {
|
||||
String[] pathArray = new String[paths.size()];
|
||||
pathArray = paths.toArray(pathArray);
|
||||
dialog.setItems((CharSequence[]) pathArray);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFolderSelection(@NonNull BlacklistFolderChooserDialog folderChooserDialog, @NonNull File file) {
|
||||
BlacklistStore.getInstance(getContext()).addPath(file);
|
||||
refreshBlacklistData();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,156 +0,0 @@
|
|||
package com.kabouzeid.gramophone.provider;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.os.Environment;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.kabouzeid.gramophone.service.MusicService;
|
||||
import com.kabouzeid.gramophone.util.FileUtil;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BlacklistStore extends SQLiteOpenHelper {
|
||||
private static BlacklistStore sInstance = null;
|
||||
public static final String DATABASE_NAME = "blacklist.db";
|
||||
private static final int VERSION = 1;
|
||||
private Context context;
|
||||
|
||||
public BlacklistStore(final Context context) {
|
||||
super(context, DATABASE_NAME, null, VERSION);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@NonNull final SQLiteDatabase db) {
|
||||
db.execSQL("CREATE TABLE IF NOT EXISTS " + BlacklistStoreColumns.NAME + " ("
|
||||
+ BlacklistStoreColumns.PATH + " STRING NOT NULL);");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(@NonNull final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
||||
db.execSQL("DROP TABLE IF EXISTS " + BlacklistStoreColumns.NAME);
|
||||
onCreate(db);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDowngrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
db.execSQL("DROP TABLE IF EXISTS " + BlacklistStoreColumns.NAME);
|
||||
onCreate(db);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static synchronized BlacklistStore getInstance(@NonNull final Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new BlacklistStore(context.getApplicationContext());
|
||||
if (!PreferenceUtil.getInstance(context).initializedBlacklist()) {
|
||||
// blacklisted by default
|
||||
sInstance.addPathImpl(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_ALARMS));
|
||||
sInstance.addPathImpl(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_NOTIFICATIONS));
|
||||
sInstance.addPathImpl(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES));
|
||||
|
||||
PreferenceUtil.getInstance(context).setInitializedBlacklist();
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public void addPath(File file) {
|
||||
addPathImpl(file);
|
||||
notifyMediaStoreChanged();
|
||||
}
|
||||
|
||||
private void addPathImpl(File file) {
|
||||
if (file == null || contains(file)) {
|
||||
return;
|
||||
}
|
||||
String path = FileUtil.safeGetCanonicalPath(file);
|
||||
|
||||
final SQLiteDatabase database = getWritableDatabase();
|
||||
database.beginTransaction();
|
||||
|
||||
try {
|
||||
// add the entry
|
||||
final ContentValues values = new ContentValues(1);
|
||||
values.put(BlacklistStoreColumns.PATH, path);
|
||||
database.insert(BlacklistStoreColumns.NAME, null, values);
|
||||
|
||||
database.setTransactionSuccessful();
|
||||
} finally {
|
||||
database.endTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(File file) {
|
||||
if (file == null) {
|
||||
return false;
|
||||
}
|
||||
String path = FileUtil.safeGetCanonicalPath(file);
|
||||
|
||||
final SQLiteDatabase database = getReadableDatabase();
|
||||
Cursor cursor = database.query(BlacklistStoreColumns.NAME,
|
||||
new String[]{BlacklistStoreColumns.PATH},
|
||||
BlacklistStoreColumns.PATH + "=?",
|
||||
new String[]{path},
|
||||
null, null, null, null);
|
||||
|
||||
boolean containsPath = cursor != null && cursor.moveToFirst();
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
return containsPath;
|
||||
}
|
||||
|
||||
public void removePath(File file) {
|
||||
final SQLiteDatabase database = getWritableDatabase();
|
||||
String path = FileUtil.safeGetCanonicalPath(file);
|
||||
|
||||
database.delete(BlacklistStoreColumns.NAME,
|
||||
BlacklistStoreColumns.PATH + "=?",
|
||||
new String[]{path});
|
||||
|
||||
notifyMediaStoreChanged();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
final SQLiteDatabase database = getWritableDatabase();
|
||||
database.delete(BlacklistStoreColumns.NAME, null, null);
|
||||
|
||||
notifyMediaStoreChanged();
|
||||
}
|
||||
|
||||
private void notifyMediaStoreChanged() {
|
||||
context.sendBroadcast(new Intent(MusicService.MEDIA_STORE_CHANGED));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<String> getPaths() {
|
||||
Cursor cursor = getReadableDatabase().query(BlacklistStoreColumns.NAME,
|
||||
new String[]{BlacklistStoreColumns.PATH},
|
||||
null, null, null, null, null);
|
||||
|
||||
List<String> paths = new ArrayList<>();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
paths.add(cursor.getString(0));
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
return paths;
|
||||
}
|
||||
|
||||
public interface BlacklistStoreColumns {
|
||||
String NAME = "blacklist";
|
||||
|
||||
String PATH = "path";
|
||||
}
|
||||
}
|
||||
|
|
@ -2,9 +2,6 @@ package com.kabouzeid.gramophone.ui.activities;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.media.audiofx.AudioEffect;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.ColorInt;
|
||||
|
|
@ -29,14 +26,11 @@ import com.kabouzeid.gramophone.App;
|
|||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.appshortcuts.DynamicShortcutManager;
|
||||
import com.kabouzeid.gramophone.misc.NonProAllowedColors;
|
||||
import com.kabouzeid.gramophone.preferences.BlacklistPreference;
|
||||
import com.kabouzeid.gramophone.preferences.BlacklistPreferenceDialog;
|
||||
import com.kabouzeid.gramophone.preferences.LibraryPreference;
|
||||
import com.kabouzeid.gramophone.preferences.LibraryPreferenceDialog;
|
||||
import com.kabouzeid.gramophone.preferences.NowPlayingScreenPreference;
|
||||
import com.kabouzeid.gramophone.preferences.NowPlayingScreenPreferenceDialog;
|
||||
import com.kabouzeid.gramophone.ui.activities.base.AbsBaseActivity;
|
||||
import com.kabouzeid.gramophone.util.NavigationUtil;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
|
@ -158,7 +152,6 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
|||
addPreferencesFromResource(R.xml.pref_lockscreen);
|
||||
addPreferencesFromResource(R.xml.pref_audio);
|
||||
addPreferencesFromResource(R.xml.pref_playlists);
|
||||
addPreferencesFromResource(R.xml.pref_blacklist);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
@ -166,8 +159,6 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
|||
public DialogFragment onCreatePreferenceDialog(Preference preference) {
|
||||
if (preference instanceof NowPlayingScreenPreference) {
|
||||
return NowPlayingScreenPreferenceDialog.newInstance();
|
||||
} else if (preference instanceof BlacklistPreference) {
|
||||
return BlacklistPreferenceDialog.newInstance();
|
||||
} else if (preference instanceof LibraryPreference) {
|
||||
return LibraryPreferenceDialog.newInstance();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue