many fixes
This commit is contained in:
@@ -59,7 +59,7 @@ public class MusicCacheImpl {
|
||||
}
|
||||
|
||||
public static boolean hasPlaylist() {
|
||||
return PlaylistCacheDbDelegate.getPlaylistsCount(AndroidUtils.getGlobalContext()) != 0; // has playlists or not
|
||||
return !PlaylistCacheDbDelegate.isPlaylistsDbEmpty(AndroidUtils.getGlobalContext()); // has playlists or not
|
||||
}
|
||||
|
||||
public static long getTracksCount() {
|
||||
@@ -89,7 +89,7 @@ public class MusicCacheImpl {
|
||||
}
|
||||
|
||||
public static boolean isEmpty() {
|
||||
return !LibVKXClient.isIntegrationEnabled() && getTracksCount() == 0L && PlaylistCacheDbDelegate.isPlaylistsDbEmpty(AndroidUtils.getGlobalContext());
|
||||
return !LibVKXClient.isIntegrationEnabled() && MusicCacheDbDelegate.isEmpty(AndroidUtils.getGlobalContext());
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
|
||||
@@ -184,6 +184,26 @@ public class PlaylistCacheDb extends SQLiteOpenHelper implements AutoCloseable {
|
||||
return count;
|
||||
}
|
||||
|
||||
public List<String> getAllPlaylistIds() {
|
||||
SQLiteDatabase db = getReadableDatabase();
|
||||
List<String> playlistIds = new ArrayList<>();
|
||||
Cursor cursor = db.query(
|
||||
Constants.TABLE_NAME,
|
||||
new String[]{Constants.COLUMN_ID, Constants.COLUMN_OWNER_ID},
|
||||
null, null, null, null, null
|
||||
);
|
||||
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
String playlistId = cursor.getString(cursor.getColumnIndexOrThrow(Constants.COLUMN_OWNER_ID)) + "_" + cursor.getString(cursor.getColumnIndexOrThrow(Constants.COLUMN_ID));
|
||||
playlistIds.add(playlistId);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
return playlistIds;
|
||||
}
|
||||
|
||||
public boolean isPlaylistsDbEmpty() {
|
||||
SQLiteDatabase db = getReadableDatabase();
|
||||
Cursor cursor = db.rawQuery("SELECT EXISTS(SELECT 1 FROM " + Constants.TABLE_NAME + " LIMIT 1)", null);
|
||||
|
||||
+13
@@ -74,6 +74,19 @@ public class PlaylistCacheDbDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeAllPlaylists(Context context) {
|
||||
List<String> playlistIds = getAllPlaylistIds(context);
|
||||
for (String playlistId : playlistIds) {
|
||||
deletePlaylist(context, playlistId);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getAllPlaylistIds(Context context) {
|
||||
try (var db = connectToDb(context)) {
|
||||
return db.getAllPlaylistIds();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isCachedPlaylist(Context context, String id) {
|
||||
try (var db = connectToDb(context)) {
|
||||
String[] parts = id.split("_");
|
||||
|
||||
@@ -112,8 +112,8 @@ public class PlaylistHelper {
|
||||
arr.put(AccountManagerUtils.getUserId() + "_-1");
|
||||
}
|
||||
|
||||
for (var playlist : MusicCacheImpl.getPlaylists()) {
|
||||
arr.put(playlist.v1());
|
||||
for (String playlist : PlaylistCacheDbDelegate.getAllPlaylistIds(AndroidUtils.getGlobalContext())) {
|
||||
arr.put(playlist);
|
||||
}
|
||||
|
||||
return arr;
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ public class TracklistHelper {
|
||||
|
||||
boolean doNotinvertOrder = Preferences.getBoolValue("invertCachedTracks", false);
|
||||
|
||||
if (!doNotinvertOrder) {
|
||||
if (doNotinvertOrder) {
|
||||
Collections.reverse(tracks);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import ru.vtosters.lite.music.LastFMScrobbler;
|
||||
import ru.vtosters.lite.music.cache.MusicCacheImpl;
|
||||
import ru.vtosters.lite.music.cache.delegate.PlaylistCacheDbDelegate;
|
||||
import ru.vtosters.lite.ui.PreferenceFragmentUtils;
|
||||
import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.LifecycleUtils;
|
||||
|
||||
@@ -55,7 +56,7 @@ public class MusicFragment extends TrackedMaterialPreferenceToolbarFragment {
|
||||
if (MusicCacheImpl.isEmpty()) {
|
||||
AndroidUtils.sendToast(requireContext().getString(com.vtosters.lite.R.string.no_cache_error));
|
||||
} else {
|
||||
delcache(requireContext());
|
||||
delcache(requireContext(), false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -73,6 +74,18 @@ public class MusicFragment extends TrackedMaterialPreferenceToolbarFragment {
|
||||
return true;
|
||||
}
|
||||
);
|
||||
|
||||
PreferenceFragmentUtils.addPreference(
|
||||
getPreferenceScreen(),
|
||||
"cached_playlists",
|
||||
"Удалить все скачанные плейлисты",
|
||||
null,
|
||||
null,
|
||||
preference -> {
|
||||
delcache(requireContext(), true);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
PreferenceFragmentUtils.addPreference(
|
||||
@@ -443,12 +456,18 @@ public class MusicFragment extends TrackedMaterialPreferenceToolbarFragment {
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private void delcache(Context ctx) {
|
||||
private void delcache(Context ctx, boolean isPlaylists) {
|
||||
new VkAlertDialog.Builder(ctx)
|
||||
.setTitle(com.vtosters.lite.R.string.warning)
|
||||
.setMessage(com.vtosters.lite.R.string.cached_tracks_remove_confirm)
|
||||
.setPositiveButton(com.vtosters.lite.R.string.yes, (dialog, which) -> {
|
||||
executor.submit(MusicCacheImpl::clear);
|
||||
executor.submit(() -> {
|
||||
if (isPlaylists) {
|
||||
PlaylistCacheDbDelegate.removeAllPlaylists(ctx);
|
||||
} else {
|
||||
PlaylistCacheDbDelegate.deletePlaylist(ctx, AccountManagerUtils.getUserId() + "_-1");
|
||||
}
|
||||
});
|
||||
findPreference("cached_tracks").setSummary(String.format(requireContext().getString(com.vtosters.lite.R.string.cached_tracks_counter), MusicCacheImpl.getTracksCount()));
|
||||
})
|
||||
.setNeutralButton(com.vtosters.lite.R.string.no, (dialog, which) -> dialog.cancel())
|
||||
|
||||
Reference in New Issue
Block a user