Skip to content

Commit

Permalink
dialog fix, code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearfog committed Sep 28, 2024
1 parent 7d197a8 commit fbe8208
Show file tree
Hide file tree
Showing 18 changed files with 235 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}
*/
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}
Expand Down Expand Up @@ -84,4 +88,4 @@ public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}
}
}
Loading

0 comments on commit fbe8208

Please sign in to comment.