Skip to content

Commit

Permalink
Update MusicFragment.java
Browse files Browse the repository at this point in the history
  • Loading branch information
gdlbo committed Mar 26, 2024
1 parent 2b87ace commit daca8ef
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions app/src/main/java/ru/vtosters/lite/ui/fragments/MusicFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
Expand All @@ -19,7 +18,6 @@
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.ui.adapters.ImagineArrayAdapter;
import ru.vtosters.lite.utils.AndroidUtils;
import ru.vtosters.lite.utils.LifecycleUtils;

Expand Down Expand Up @@ -104,21 +102,24 @@ public void onCreate(Bundle bundle) {
getAutocacheSumm(),
null,
preference -> {
List<ImagineArrayAdapter.ImagineArrayAdapterItem> items = Arrays.asList(
new ImagineArrayAdapter.ImagineArrayAdapterItem(null, "Не кешировать"),
new ImagineArrayAdapter.ImagineArrayAdapterItem(null, "Только свои"),
new ImagineArrayAdapter.ImagineArrayAdapterItem(null, "Все")
);
List<String> items = Arrays.asList("Не кешировать", "Только свои", "Все");

ImagineArrayAdapter adapter = new ImagineArrayAdapter(requireContext(), items);
adapter.setSelected(Preferences.getPreferences().getInt("autocaching", 0));
ArrayAdapter<String> adapter = new ArrayAdapter<>(requireContext(), android.R.layout.simple_list_item_1, items);

int selectedItem = Preferences.getPreferences().getInt("autocaching", 0);
if (selectedItem >= 0 && selectedItem < items.size()) {
adapter.getItem(selectedItem);
}

new VkAlertDialog.Builder(getActivity())
.setAdapter(adapter, (dialog, which) -> {
adapter.getItem(which);
Preferences.getPreferences().edit().putInt("autocaching", which).apply();
findPreference("autocache_params").setSummary(getAutocacheSumm());
dialog.cancel();
})
.show();

return true;
}
);
Expand Down Expand Up @@ -183,6 +184,7 @@ public void onCreate(Bundle bundle) {
return;
}
Preferences.setMetadataSeparator(separator.getText().toString());
findPreference("metadataSeparator").setSummary(separator.getText().toString());
})
.setNegativeButton("Отмена", (dialog, which) -> dialog.cancel())
.show();
Expand Down Expand Up @@ -381,7 +383,8 @@ private void logout(Context ctx) {
.show();
}

private static void cachedPlaylistsDialog(Context ctx) {
@SuppressLint("DefaultLocale")
private void cachedPlaylistsDialog(Context ctx) {
List<Playlist> playlists = PlaylistCacheDbDelegate.getAllPlaylists(ctx);
String[] playlistNames = new String[playlists.size()];

Expand All @@ -396,6 +399,7 @@ private static void cachedPlaylistsDialog(Context ctx) {
String playlistId = selectedPlaylist.v1();
PlaylistCacheDbDelegate.deletePlaylist(ctx, playlistId);
AndroidUtils.sendToast("Плейлист удален");
findPreference("cached_playlists").setSummary(String.format("Скачано плейлистов: %d", MusicCacheImpl.getPlaylists().size()));
});

builder.show();
Expand All @@ -405,10 +409,11 @@ private void delcache(Context ctx) {
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))
.setNeutralButton(com.vtosters.lite.R.string.no,
(dialog, which) -> dialog.cancel())
.setPositiveButton(com.vtosters.lite.R.string.yes, (dialog, which) -> {
executor.submit(MusicCacheImpl::clear);
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())
.show();
}

Expand Down

0 comments on commit daca8ef

Please sign in to comment.