From fbe8208f1b7c81afc34c6f3de6a86a957fecce5a Mon Sep 17 00:00:00 2001 From: nuclearfog <32868976+nuclearfog@users.noreply.github.com> Date: Sat, 28 Sep 2024 18:54:29 +0200 Subject: [PATCH] dialog fix, code cleanup --- .../apollo/ui/activities/AudioFxActivity.java | 3 +- .../apollo/ui/activities/ProfileActivity.java | 15 +---- .../apollo/ui/dialogs/BatteryOptDialog.java | 24 ++++--- .../apollo/ui/dialogs/CacheClearDialog.java | 32 +++++---- .../apollo/ui/dialogs/ColorSchemeDialog.java | 67 ++++++++++--------- .../ui/dialogs/DeletePlaylistDialog.java | 30 +++++---- .../apollo/ui/dialogs/DeleteTracksDialog.java | 32 ++++----- .../apollo/ui/dialogs/LicenseDialog.java | 19 ++++-- .../ui/dialogs/PhotoSelectionDialog.java | 66 +++++++++--------- .../apollo/ui/dialogs/PlaylistDialog.java | 50 ++++++++------ .../apollo/ui/dialogs/PresetDialog.java | 59 ++++++++++------ .../apollo/ui/fragments/PlaylistFragment.java | 4 +- .../preference/PreferenceFragment.java | 6 +- .../views/AlphaTouchInterceptorOverlay.java | 1 + .../apollo/ui/views/CarouselTab.java | 10 +-- .../apollo/ui/views/ProfileTabCarousel.java | 1 + .../nuclearfog/apollo/utils/ApolloUtils.java | 2 +- .../nuclearfog/apollo/utils/MusicUtils.java | 3 +- 18 files changed, 235 insertions(+), 189 deletions(-) diff --git a/app/src/main/java/org/nuclearfog/apollo/ui/activities/AudioFxActivity.java b/app/src/main/java/org/nuclearfog/apollo/ui/activities/AudioFxActivity.java index 8194acc..7df4edc 100644 --- a/app/src/main/java/org/nuclearfog/apollo/ui/activities/AudioFxActivity.java +++ b/app/src/main/java/org/nuclearfog/apollo/ui/activities/AudioFxActivity.java @@ -146,8 +146,7 @@ public boolean onCreateOptionsMenu(Menu menu) { public boolean onOptionsItemSelected(@NonNull MenuItem item) { if (item.getItemId() == R.id.menu_save_preset) { AudioPreset preset = audioEffects.getPreset(); - PresetDialog presetDialog = PresetDialog.newInstance(preset); - presetDialog.show(getSupportFragmentManager(), PresetDialog.TAG + ":" + preset.getName()); + PresetDialog.show(getSupportFragmentManager(), preset); } else if (item.getItemId() == R.id.menu_delete_preset) { Object selectedItem = presetSelector.getSelectedItem(); if (selectedItem instanceof AudioPreset) { diff --git a/app/src/main/java/org/nuclearfog/apollo/ui/activities/ProfileActivity.java b/app/src/main/java/org/nuclearfog/apollo/ui/activities/ProfileActivity.java index 788d6ef..eee6b6a 100644 --- a/app/src/main/java/org/nuclearfog/apollo/ui/activities/ProfileActivity.java +++ b/app/src/main/java/org/nuclearfog/apollo/ui/activities/ProfileActivity.java @@ -32,7 +32,6 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; -import androidx.fragment.app.DialogFragment; import androidx.lifecycle.ViewModelProvider; import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager.OnPageChangeListener; @@ -53,7 +52,6 @@ import org.nuclearfog.apollo.store.PopularStore; import org.nuclearfog.apollo.ui.adapters.viewpager.ProfileAdapter; import org.nuclearfog.apollo.ui.dialogs.PhotoSelectionDialog; -import org.nuclearfog.apollo.ui.dialogs.PhotoSelectionDialog.ProfileType; import org.nuclearfog.apollo.ui.fragments.profile.ProfileFragment; import org.nuclearfog.apollo.ui.views.ProfileTabCarousel; import org.nuclearfog.apollo.ui.views.ProfileTabCarousel.Listener; @@ -618,20 +616,13 @@ public void onTabSelected(int position) { */ @Override public void onAlbumArtSelected() { - ProfileType profileType; - String name; if (type == Type.ARTIST) { - profileType = ProfileType.ARTIST; - name = mArtistName; + PhotoSelectionDialog.show(getSupportFragmentManager(), mArtistName, PhotoSelectionDialog.ARTIST); } else if (type == Type.ALBUM) { - profileType = ProfileType.ALBUM; - name = mProfileName; + PhotoSelectionDialog.show(getSupportFragmentManager(), mProfileName, PhotoSelectionDialog.ALBUM); } else { - profileType = ProfileType.OTHER; - name = mProfileName; + PhotoSelectionDialog.show(getSupportFragmentManager(), mProfileName, PhotoSelectionDialog.OTHER); } - DialogFragment dialog = PhotoSelectionDialog.newInstance(name, profileType); - dialog.show(getSupportFragmentManager(), PhotoSelectionDialog.NAME); } /** diff --git a/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/BatteryOptDialog.java b/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/BatteryOptDialog.java index 310bfe2..57d29da 100644 --- a/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/BatteryOptDialog.java +++ b/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/BatteryOptDialog.java @@ -11,7 +11,7 @@ import androidx.annotation.Nullable; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; import org.nuclearfog.apollo.R; import org.nuclearfog.apollo.utils.ApolloUtils; @@ -29,15 +29,21 @@ public class BatteryOptDialog extends DialogFragment implements OnClickListener /** * */ - public static void show(FragmentActivity activity) { - Fragment fragment = activity.getSupportFragmentManager().findFragmentByTag(TAG); - if (fragment == null) { - BatteryOptDialog dialog = new BatteryOptDialog(); - dialog.show(activity.getSupportFragmentManager(), TAG); + public static void show(FragmentManager fm) { + BatteryOptDialog batteryDialog; + Fragment dialog = fm.findFragmentByTag(TAG); + + if (dialog instanceof BatteryOptDialog) { + batteryDialog = (BatteryOptDialog) dialog; + } else { + batteryDialog = new BatteryOptDialog(); } + batteryDialog.show(fm, TAG); } - + /** + * {@inheritDoc} + */ @NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { @@ -49,7 +55,9 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { .create(); } - + /** + * {@inheritDoc} + */ @Override public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_POSITIVE) { diff --git a/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/CacheClearDialog.java b/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/CacheClearDialog.java index e2fc223..1d34df1 100644 --- a/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/CacheClearDialog.java +++ b/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/CacheClearDialog.java @@ -9,7 +9,7 @@ import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; import org.nuclearfog.apollo.R; import org.nuclearfog.apollo.cache.ImageCache; @@ -23,6 +23,21 @@ public class CacheClearDialog extends DialogFragment { private static final String TAG = "CacheClearDialog"; + /** + * show this dialog + */ + public static void show(FragmentManager fm) { + CacheClearDialog cacheClearDialog; + Fragment dialog = fm.findFragmentByTag(TAG); + + if (dialog instanceof CacheClearDialog) { + cacheClearDialog = (CacheClearDialog) dialog; + } else { + cacheClearDialog = new CacheClearDialog(); + } + cacheClearDialog.show(fm, TAG); + } + /** * {@inheritDoc} */ @@ -31,24 +46,13 @@ public class CacheClearDialog extends DialogFragment { public Dialog onCreateDialog(Bundle savedInstanceState) { return new AlertDialog.Builder(requireContext()) .setMessage(R.string.delete_warning) + .setNegativeButton(R.string.cancel, null) .setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ImageCache mImageCache = ImageCache.getInstance(requireContext()); mImageCache.clearCaches(); } - }) - .setNegativeButton(R.string.cancel, null).create(); - } - - /** - * show this dialog - */ - public static void show(FragmentActivity fragmentActivity) { - Fragment fragment = fragmentActivity.getSupportFragmentManager().findFragmentByTag(TAG); - if (fragment == null) { - CacheClearDialog dialog = new CacheClearDialog(); - dialog.show(fragmentActivity.getSupportFragmentManager(), TAG); - } + }).create(); } } \ No newline at end of file diff --git a/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/ColorSchemeDialog.java b/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/ColorSchemeDialog.java index 8b947e5..5a9ba02 100644 --- a/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/ColorSchemeDialog.java +++ b/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/ColorSchemeDialog.java @@ -26,7 +26,7 @@ import androidx.annotation.Nullable; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; import org.nuclearfog.apollo.BuildConfig; import org.nuclearfog.apollo.R; @@ -52,7 +52,24 @@ public class ColorSchemeDialog extends DialogFragment implements ColorPickerView private PreferenceUtils mPreferences; + /** + * show this dialog + */ + public static void show(FragmentManager fm) { + ColorSchemeDialog colorDialog; + Fragment dialog = fm.findFragmentByTag(TAG); + + if (dialog instanceof ColorSchemeDialog) { + colorDialog = (ColorSchemeDialog) dialog; + } else { + colorDialog = new ColorSchemeDialog(); + } + colorDialog.show(fm, TAG); + } + /** + * {@inheritDoc} + */ @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -94,16 +111,20 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c return mRootView; } - + /** + * {@inheritDoc} + */ @Override public void onColorChanged(int color) { if (mHexValue != null) { - mHexValue.setText(padLeft(Integer.toHexString(color).toUpperCase(Locale.getDefault()))); + mHexValue.setText(Integer.toHexString(color).toUpperCase(Locale.getDefault())); } mNewColor.setBackgroundColor(color); } - + /** + * {@inheritDoc} + */ @Override public void onClick(View v) { if (v.getId() == R.id.color_scheme_dialog_preset_1) { @@ -136,7 +157,9 @@ public void onClick(View v) { onColorChanged(mColorPicker.getColor()); } - + /** + * {@inheritDoc} + */ @Override public void onTextChanged(CharSequence s, int start, int before, int count) { try { @@ -150,39 +173,17 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { } } - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - - @Override - public void afterTextChanged(Editable s) { - } - /** - * + * {@inheritDoc} */ - private String padLeft(String string) { - if (string.length() >= 8) { - return string; - } - StringBuilder result = new StringBuilder(); - for (int i = string.length(); i < 8; i++) { - result.append((char) 0); - } - result.append(string); - return result.toString(); + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { } /** - * show this dialog + * {@inheritDoc} */ - public static void show(FragmentActivity activity) { - Fragment fragment = activity.getSupportFragmentManager().findFragmentByTag(TAG); - if (fragment == null) { - ColorSchemeDialog dialog = new ColorSchemeDialog(); - dialog.show(activity.getSupportFragmentManager(), TAG); - } + @Override + public void afterTextChanged(Editable s) { } } \ No newline at end of file diff --git a/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/DeletePlaylistDialog.java b/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/DeletePlaylistDialog.java index 1eabceb..24d7a67 100644 --- a/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/DeletePlaylistDialog.java +++ b/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/DeletePlaylistDialog.java @@ -11,6 +11,8 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; import org.nuclearfog.apollo.R; import org.nuclearfog.apollo.model.Playlist; @@ -22,27 +24,29 @@ */ public class DeletePlaylistDialog extends DialogFragment implements OnClickListener { + private static final String TAG = "DeletePlaylistDialog"; + private static final String KEY_PLAYLIST = "playlist"; private Playlist playlist; /** - * - */ - public DeletePlaylistDialog() { - } - - /** - * @return A new instance of the dialog + * @param playlist playlist to delete */ - public static DeletePlaylistDialog newInstance(Playlist playlist) { - DeletePlaylistDialog dialog = new DeletePlaylistDialog(); + public static void show(FragmentManager fm, Playlist playlist) { Bundle args = new Bundle(); + DeletePlaylistDialog deleteDialog; + Fragment dialog = fm.findFragmentByTag(TAG); args.putSerializable(KEY_PLAYLIST, playlist); - dialog.setArguments(args); - return dialog; - } + if (dialog instanceof DeletePlaylistDialog) { + deleteDialog = (DeletePlaylistDialog) dialog; + } else { + deleteDialog = new DeletePlaylistDialog(); + } + deleteDialog.setArguments(args); + deleteDialog.show(fm, TAG); + } /** * {@inheritDoc} @@ -84,4 +88,4 @@ public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } } -} +} \ No newline at end of file diff --git a/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/DeleteTracksDialog.java b/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/DeleteTracksDialog.java index ef123d0..bef3105 100644 --- a/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/DeleteTracksDialog.java +++ b/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/DeleteTracksDialog.java @@ -21,6 +21,8 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; import org.nuclearfog.apollo.R; import org.nuclearfog.apollo.async.AsyncExecutor.AsyncCallback; @@ -38,43 +40,42 @@ */ public class DeleteTracksDialog extends DialogFragment implements OnClickListener, AsyncCallback { - public static final String NAME = "DeleteDialog"; + private static final String TAG = "DeleteTracksDialog"; /** * key to set the dialog title message * value type is String */ - private static final String KEY_TITLE = NAME + "_title"; + private static final String KEY_TITLE = "delete_title"; /** * key to add a long array of track IDs * value type is long[] */ - private static final String KEY_ITEMS = NAME + "_items"; + private static final String KEY_ITEMS = "delete_items"; private TrackDeleteWorker trackDeleteWorker; private long[] mItemList = {}; - private String title = ""; - - /** - * - */ - public DeleteTracksDialog() { - } /** * @param title The title of the artist, album, or song to delete * @param items The item(s) to delete - * @return A new instance of the dialog */ - public static DeleteTracksDialog newInstance(String title, long[] items) { - DeleteTracksDialog dialog = new DeleteTracksDialog(); + public static void show(FragmentManager fm, String title, long[] items) { + DeleteTracksDialog deleteDialog; Bundle args = new Bundle(); + Fragment dialog = fm.findFragmentByTag(TAG); + + if (dialog instanceof DeleteTracksDialog) { + deleteDialog = (DeleteTracksDialog) dialog; + } else { + deleteDialog = new DeleteTracksDialog(); + } args.putString(KEY_TITLE, title); args.putLongArray(KEY_ITEMS, items); - dialog.setArguments(args); - return dialog; + deleteDialog.setArguments(args); + deleteDialog.show(fm, TAG); } /** @@ -83,6 +84,7 @@ public static DeleteTracksDialog newInstance(String title, long[] items) { @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { + String title = ""; if (getArguments() != null) { title = getArguments().getString(KEY_TITLE, ""); long[] mItemList = getArguments().getLongArray(KEY_ITEMS); diff --git a/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/LicenseDialog.java b/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/LicenseDialog.java index aafb98c..3d8aa0a 100644 --- a/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/LicenseDialog.java +++ b/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/LicenseDialog.java @@ -11,7 +11,7 @@ import androidx.annotation.Nullable; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; /** * Dialog used to show a list of licenses of all used libraries @@ -22,7 +22,9 @@ public class LicenseDialog extends DialogFragment { private static final String TAG = "LicenseDialog"; - + /** + * {@inheritDoc} + */ @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -35,11 +37,14 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c /** * show this dialog */ - public static void show(FragmentActivity activity) { - Fragment fragment = activity.getSupportFragmentManager().findFragmentByTag(TAG); - if (fragment == null) { - LicenseDialog dialog = new LicenseDialog(); - dialog.show(activity.getSupportFragmentManager(), TAG); + public static void show(FragmentManager fm) { + LicenseDialog licenseDialog; + Fragment dialog = fm.findFragmentByTag(TAG); + if (dialog instanceof LicenseDialog) { + licenseDialog = (LicenseDialog) dialog; + } else { + licenseDialog = new LicenseDialog(); } + licenseDialog.show(fm, TAG); } } \ No newline at end of file diff --git a/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/PhotoSelectionDialog.java b/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/PhotoSelectionDialog.java index 2fbfbab..8364b48 100644 --- a/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/PhotoSelectionDialog.java +++ b/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/PhotoSelectionDialog.java @@ -19,8 +19,11 @@ import android.widget.ListAdapter; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; import org.nuclearfog.apollo.R; import org.nuclearfog.apollo.ui.activities.ProfileActivity; @@ -38,36 +41,39 @@ */ public class PhotoSelectionDialog extends DialogFragment implements OnClickListener { - public static final String NAME = "PhotoSelectionDialog"; + public static final String TAG = "PhotoSelectionDialog"; - private static final String KEY_TITLE = NAME + "_title"; + public static final int ARTIST = 10; + public static final int ALBUM = 11; + public static final int OTHER = 12; + + private static final String KEY_TITLE = "photo_title"; + private static final String KEY_TYPE = "photo_type"; private static final int IDX_NEW = 0; private static final int IDX_OLD = 1; private static final int IDX_SEARCH = 2; private static final int IDX_FETCH = 3; - private static ProfileType mProfileType; - private List mChoices = new ArrayList<>(5); - /** - * - */ - public PhotoSelectionDialog() { - } /** * @param title The dialog title. - * @return A new instance of the dialog. */ - public static PhotoSelectionDialog newInstance(String title, ProfileType type) { - PhotoSelectionDialog dialog = new PhotoSelectionDialog(); + public static void show(FragmentManager fm, String title, int type) { Bundle args = new Bundle(); + PhotoSelectionDialog photoSelectionDialog; + Fragment dialog = fm.findFragmentByTag(TAG); + + if (dialog instanceof PhotoSelectionDialog) { + photoSelectionDialog = (PhotoSelectionDialog) dialog; + } else { + photoSelectionDialog = new PhotoSelectionDialog(); + } + args.putInt(KEY_TYPE, type); args.putString(KEY_TITLE, title); - dialog.setArguments(args); - mProfileType = type; - return dialog; + photoSelectionDialog.setArguments(args); } /** @@ -75,8 +81,17 @@ public static PhotoSelectionDialog newInstance(String title, ProfileType type) { */ @NonNull @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - switch (mProfileType) { + public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { + int type = OTHER; + String title = ""; + if (savedInstanceState == null) { + savedInstanceState = getArguments(); + } + if (savedInstanceState != null) { + type = savedInstanceState.getInt(KEY_TYPE, OTHER); + title = savedInstanceState.getString(KEY_TITLE, ""); + } + switch (type) { case ARTIST: // Select a photo from the gallery mChoices.add(IDX_NEW, getString(R.string.new_photo)); @@ -101,6 +116,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { } break; + default: case OTHER: // Select a photo from the gallery mChoices.add(IDX_NEW, getString(R.string.new_photo)); @@ -108,16 +124,13 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { mChoices.add(IDX_OLD, getString(R.string.use_default)); break; } - // Dialog item Adapter - String title = ""; - if (getArguments() != null) { - title = getArguments().getString(KEY_TITLE, ""); - } ListAdapter adapter = new ArrayAdapter<>(requireContext(), android.R.layout.select_dialog_item, mChoices); return new AlertDialog.Builder(requireContext()).setTitle(title).setAdapter(adapter, this).create(); } - + /** + * {@inheritDoc} + */ @Override public void onClick(DialogInterface dialog, int which) { ProfileActivity activity = (ProfileActivity) requireActivity(); @@ -136,11 +149,4 @@ public void onClick(DialogInterface dialog, int which) { break; } } - - /** - * Easily detect the MIME type - */ - public enum ProfileType { - ARTIST, ALBUM, OTHER - } } \ No newline at end of file diff --git a/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/PlaylistDialog.java b/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/PlaylistDialog.java index 2e377dd..f0e3541 100644 --- a/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/PlaylistDialog.java +++ b/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/PlaylistDialog.java @@ -81,10 +81,12 @@ public class PlaylistDialog extends DialogFragment implements TextWatcher, OnCli * value type is long[] */ private static final String PLAYLIST_SONGS = "playlist_songs"; + /** * Used to make new playlist names */ private EditText playlistName; + /** * The dialog save button */ @@ -96,6 +98,32 @@ public class PlaylistDialog extends DialogFragment implements TextWatcher, OnCli private long[] songIds = {}; + /** + * shows a dialog window + * + * @param mode what action should be performed {@link #COPY,#MOVE,#CREATE} + * @param id ID of an existing playlist to modify used to copy or move + * @param songIds list of song IDs to add to the playlist + * @param name new name of the playlist + */ + public static void show(FragmentManager fm, int mode, long id, long[] songIds, String name) { + PlaylistDialog playlistDialog; + Bundle param = new Bundle(); + Fragment dialog = fm.findFragmentByTag(NAME); + param.putInt(PLAYLIST_MODE, mode); + param.putLong(PLAYLIST_ID, id); + param.putLongArray(PLAYLIST_SONGS, songIds); + param.putString(PLAYLIST_NAME, name); + + if (dialog instanceof PlaylistDialog) { + playlistDialog = (PlaylistDialog) dialog; + } else { + playlistDialog = new PlaylistDialog(); + } + playlistDialog.setArguments(param); + playlistDialog.show(fm, NAME); + } + /** * {@inheritDoc} */ @@ -210,26 +238,4 @@ public final void afterTextChanged(Editable s) { @Override public final void beforeTextChanged(CharSequence s, int start, int count, int after) { } - - /** - * shows a dialog window - * - * @param mode what action should be performed {@link #COPY,#MOVE,#CREATE} - * @param id ID of an existing playlist to modify used to copy or move - * @param songIds list of song IDs to add to the playlist - * @param name new name of the playlist - */ - public static void show(FragmentManager fm, int mode, long id, long[] songIds, String name) { - Fragment dialogFragment = fm.findFragmentByTag(NAME); - if (dialogFragment == null) { - PlaylistDialog dialog = new PlaylistDialog(); - Bundle param = new Bundle(); - param.putInt(PLAYLIST_MODE, mode); - param.putLong(PLAYLIST_ID, id); - param.putLongArray(PLAYLIST_SONGS, songIds); - param.putString(PLAYLIST_NAME, name); - dialog.setArguments(param); - dialog.show(fm, NAME); - } - } } \ No newline at end of file diff --git a/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/PresetDialog.java b/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/PresetDialog.java index b157b2e..dca5ea0 100644 --- a/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/PresetDialog.java +++ b/app/src/main/java/org/nuclearfog/apollo/ui/dialogs/PresetDialog.java @@ -15,6 +15,8 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; import org.nuclearfog.apollo.R; import org.nuclearfog.apollo.model.AudioPreset; @@ -36,7 +38,30 @@ public class PresetDialog extends DialogFragment implements OnClickListener, Tex private EditText text; private Button mSaveButton; + /** + * create an instance of this dialog + * + * @param preset preset configuration to show + */ + public static void show(FragmentManager fm, AudioPreset preset) { + PresetDialog presetDialog; + Bundle args = new Bundle(); + String tag = PresetDialog.TAG + ":" + preset.getName(); + Fragment dialog = fm.findFragmentByTag(tag); + + if (dialog instanceof PresetDialog) { + presetDialog = (PresetDialog) dialog; + } else { + presetDialog = new PresetDialog(); + } + args.putSerializable(KEY_PRESET, preset); + presetDialog.setArguments(args); + presetDialog.show(fm, tag); + } + /** + * {@inheritDoc} + */ @NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { @@ -66,13 +91,17 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { return dialog; } - + /** + * {@inheritDoc} + */ @Override public void onSaveInstanceState(@NonNull Bundle outState) { outState.putSerializable(KEY_PRESET, preset); } - + /** + * {@inheritDoc} + */ @Override public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_POSITIVE) { @@ -91,37 +120,29 @@ public void onClick(DialogInterface dialog, int which) { } } - + /** + * {@inheritDoc} + */ @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } - + /** + * {@inheritDoc} + */ @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } - + /** + * {@inheritDoc} + */ @Override public void afterTextChanged(Editable s) { mSaveButton.setEnabled(!s.toString().trim().isEmpty()); preset.setName(s.toString()); } - /** - * create an instance of this dialog - * - * @param preset preset configuration to show - * @return instance of this dialog - */ - public static PresetDialog newInstance(AudioPreset preset) { - PresetDialog dialog = new PresetDialog(); - Bundle args = new Bundle(); - args.putSerializable(KEY_PRESET, preset); - dialog.setArguments(args); - return dialog; - } - /** * callback used to send the modified preset back to activity */ diff --git a/app/src/main/java/org/nuclearfog/apollo/ui/fragments/PlaylistFragment.java b/app/src/main/java/org/nuclearfog/apollo/ui/fragments/PlaylistFragment.java index 4e5aaeb..5814d80 100644 --- a/app/src/main/java/org/nuclearfog/apollo/ui/fragments/PlaylistFragment.java +++ b/app/src/main/java/org/nuclearfog/apollo/ui/fragments/PlaylistFragment.java @@ -66,8 +66,6 @@ */ public class PlaylistFragment extends Fragment implements AsyncCallback>, OnItemClickListener, Observer { - private static final String TAG = "PlaylistFragment"; - /** * Used to keep context menu items from bleeding into other fragments */ @@ -229,7 +227,7 @@ else if (selectedPlaylist.getId() == Playlist.POPULAR_ID) { break; case ContextMenuItems.DELETE: - DeletePlaylistDialog.newInstance(selectedPlaylist).show(getParentFragmentManager(), TAG); + DeletePlaylistDialog.show(getParentFragmentManager(), selectedPlaylist); return true; } } diff --git a/app/src/main/java/org/nuclearfog/apollo/ui/fragments/preference/PreferenceFragment.java b/app/src/main/java/org/nuclearfog/apollo/ui/fragments/preference/PreferenceFragment.java index 2daa2f7..656a331 100644 --- a/app/src/main/java/org/nuclearfog/apollo/ui/fragments/preference/PreferenceFragment.java +++ b/app/src/main/java/org/nuclearfog/apollo/ui/fragments/preference/PreferenceFragment.java @@ -97,15 +97,15 @@ public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable S public boolean onPreferenceClick(@NonNull Preference preference) { switch (preference.getKey()) { case LICENSE: - LicenseDialog.show(requireActivity()); + LicenseDialog.show(getParentFragmentManager()); return true; case DEL_CACHE: - CacheClearDialog.show(requireActivity()); + CacheClearDialog.show(getParentFragmentManager()); return true; case COLOR_SEL: - ColorSchemeDialog.show(requireActivity()); + ColorSchemeDialog.show(getParentFragmentManager()); return true; case THEME_SEL: diff --git a/app/src/main/java/org/nuclearfog/apollo/ui/views/AlphaTouchInterceptorOverlay.java b/app/src/main/java/org/nuclearfog/apollo/ui/views/AlphaTouchInterceptorOverlay.java index 742a048..74a73b2 100644 --- a/app/src/main/java/org/nuclearfog/apollo/ui/views/AlphaTouchInterceptorOverlay.java +++ b/app/src/main/java/org/nuclearfog/apollo/ui/views/AlphaTouchInterceptorOverlay.java @@ -41,6 +41,7 @@ public class AlphaTouchInterceptorOverlay extends FrameLayout { private float mAlpha = 0.0f; /** + * */ public AlphaTouchInterceptorOverlay(@NonNull Context context) { this(context, null); diff --git a/app/src/main/java/org/nuclearfog/apollo/ui/views/CarouselTab.java b/app/src/main/java/org/nuclearfog/apollo/ui/views/CarouselTab.java index 177f4e2..cc2c15f 100644 --- a/app/src/main/java/org/nuclearfog/apollo/ui/views/CarouselTab.java +++ b/app/src/main/java/org/nuclearfog/apollo/ui/views/CarouselTab.java @@ -85,7 +85,7 @@ public void setSelected(boolean selected) { /** * Used to set the artist image in the artist profile. * - * @param artist The name of the artist in the profile the user is viewing. + * @param artist The name of the artist in the profile the user is viewing. */ public void setArtistPhoto(String artist) { if (!TextUtils.isEmpty(artist)) { @@ -98,7 +98,7 @@ public void setArtistPhoto(String artist) { /** * Used to set the album art in the album profile. * - * @param album The name of the album in the profile the user is viewing. + * @param album The name of the album in the profile the user is viewing. */ public void setAlbumPhoto(String album, String artist) { if (!TextUtils.isEmpty(album)) { @@ -112,7 +112,7 @@ public void setAlbumPhoto(String album, String artist) { /** * Used to set the album art in the artist profile. * - * @param artist The name of the artist in the profile the user is viewing. + * @param artist The name of the artist in the profile the user is viewing. */ public void setArtistAlbumPhoto(String artist) { final String lastAlbum = RecentStore.getInstance(getContext()).getAlbumName(artist); @@ -145,8 +145,8 @@ public void setPlaylistOrGenrePhoto(String profileName) { /** * Used to fetch for the album art via Last.fm. * - * @param album The name of the album in the profile the user is viewing. - * @param artist The name of the album artist in the profile the user is viewing + * @param album The name of the album in the profile the user is viewing. + * @param artist The name of the album artist in the profile the user is viewing */ public void fetchAlbumPhoto(String album, String artist) { if (!TextUtils.isEmpty(album)) { diff --git a/app/src/main/java/org/nuclearfog/apollo/ui/views/ProfileTabCarousel.java b/app/src/main/java/org/nuclearfog/apollo/ui/views/ProfileTabCarousel.java index 3ff65a5..28fca37 100644 --- a/app/src/main/java/org/nuclearfog/apollo/ui/views/ProfileTabCarousel.java +++ b/app/src/main/java/org/nuclearfog/apollo/ui/views/ProfileTabCarousel.java @@ -119,6 +119,7 @@ public class ProfileTabCarousel extends HorizontalScrollView implements OnClickL private Listener mListener; /** + * */ public ProfileTabCarousel(@NonNull Context context) { this(context, null); diff --git a/app/src/main/java/org/nuclearfog/apollo/utils/ApolloUtils.java b/app/src/main/java/org/nuclearfog/apollo/utils/ApolloUtils.java index 6b49f70..da043c7 100644 --- a/app/src/main/java/org/nuclearfog/apollo/utils/ApolloUtils.java +++ b/app/src/main/java/org/nuclearfog/apollo/utils/ApolloUtils.java @@ -323,7 +323,7 @@ public static void openBatteryOptimizationDialog(FragmentActivity activity) { PreferenceUtils pref = PreferenceUtils.getInstance(activity); PowerManager pm = (PowerManager) activity.getSystemService(Context.POWER_SERVICE); if (!pref.isBatteryOptimizationIgnored() && pm != null && !pm.isIgnoringBatteryOptimizations(activity.getPackageName())) { - BatteryOptDialog.show(activity); + BatteryOptDialog.show(activity.getSupportFragmentManager()); } } } diff --git a/app/src/main/java/org/nuclearfog/apollo/utils/MusicUtils.java b/app/src/main/java/org/nuclearfog/apollo/utils/MusicUtils.java index 2d5dedc..399da38 100644 --- a/app/src/main/java/org/nuclearfog/apollo/utils/MusicUtils.java +++ b/app/src/main/java/org/nuclearfog/apollo/utils/MusicUtils.java @@ -1111,8 +1111,7 @@ public static void openDeleteDialog(FragmentActivity activity, String title, lon } } } else { - DeleteTracksDialog dialog = DeleteTracksDialog.newInstance(title, ids); - dialog.show(activity.getSupportFragmentManager(), DeleteTracksDialog.NAME); + DeleteTracksDialog.show(activity.getSupportFragmentManager(), title, ids); } }