Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c9b5fded authored by 2bllw8's avatar 2bllw8 Committed by Joey
Browse files

Eleven: allow to reset to default photo

Change-Id: I1ea62a3da433d81997b400ac46e3c5336129df53
parent 10366aa1
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -92,9 +92,7 @@
    <string name="cannot_be_undone">This cannot be undone</string>
    <string name="delete_warning">This will permanently delete the cached image entries</string>
    <string name="new_photo">Choose photo from Gallery</string>
    <string name="google_search">Google search</string>
    <string name="use_default">Use default photo</string>
    <string name="old_photo">Use old photo</string>

    <!-- Context menu items -->
    <string name="context_menu_play_selection">Play</string>
+13 −64
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 Andrew Neal
 * Copyright (C) 2014 The CyanogenMod Project
 * Copyright (C) 2020-021 The LineageOS Project
 * Copyright (C) 2020-2021 The LineageOS Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -29,15 +29,12 @@ import androidx.fragment.app.DialogFragment;
import org.lineageos.eleven.Config;
import org.lineageos.eleven.R;
import org.lineageos.eleven.ui.activities.HomeActivity;
import org.lineageos.eleven.utils.Lists;
import org.lineageos.eleven.utils.MusicUtils;

import java.util.ArrayList;

/**
 * Used when the user requests to modify Album art or Artist image
 * It provides an easy interface for them to choose a new image, use the old
 * image, or search Google for one.
 * It provides an easy interface for them to choose a new image or use the old
 * image.
 *
 * @author Andrew Neal (andrewdneal@gmail.com)
 */
@@ -45,11 +42,7 @@ public class PhotoSelectionDialog extends DialogFragment {

    private static final int NEW_PHOTO = 0;

    private static final int OLD_PHOTO = 1;

    private final ArrayList<String> mChoices = Lists.newArrayList();

    private static ProfileType mProfileType;
    private static final int DEFAULT_PHOTO = 1;

    private String mKey;

@@ -61,17 +54,14 @@ public class PhotoSelectionDialog extends DialogFragment {

    /**
     * @param title The dialog title.
     * @param type  Either Artist or Album
     * @param key   key to query ImageFetcher
     * @return A new instance of the dialog.
     */
    public static PhotoSelectionDialog newInstance(final String title, final ProfileType type,
                                                   String key) {
    public static PhotoSelectionDialog newInstance(final String title, String key) {
        final PhotoSelectionDialog frag = new PhotoSelectionDialog();
        final Bundle args = new Bundle();
        args.putString(Config.NAME, title);
        frag.setArguments(args);
        mProfileType = type;
        frag.mKey = key;
        return frag;
    }
@@ -81,23 +71,16 @@ public class PhotoSelectionDialog extends DialogFragment {
    public Dialog onCreateDialog(final Bundle savedInstanceState) {
        final Bundle args = getArguments();
        final String title = args == null ? "" : args.getString(Config.NAME);
        switch (mProfileType) {
            case ARTIST:
                setArtistChoices();
                break;
            case ALBUM:
                setAlbumChoices();
                break;
            case OTHER:
                setOtherChoices();
                break;
            default:
                break;
        }
        final String[] choices = new String[2];
        // Select a photo from the gallery
        choices[NEW_PHOTO] = getString(R.string.new_photo);
        // Default photo
        choices[DEFAULT_PHOTO] = getString(R.string.use_default);

        // Dialog item Adapter
        final HomeActivity activity = (HomeActivity) getActivity();
        final ListAdapter adapter = new ArrayAdapter<>(activity,
                android.R.layout.select_dialog_item, mChoices);
                android.R.layout.select_dialog_item, choices);
        return new AlertDialog.Builder(activity).setTitle(title)
                .setAdapter(adapter, (dialog, which) -> {
                    switch (which) {
@@ -106,7 +89,7 @@ public class PhotoSelectionDialog extends DialogFragment {
                                activity.selectNewPhoto(mKey);
                            }
                            break;
                        case OLD_PHOTO:
                        case DEFAULT_PHOTO:
                            MusicUtils.selectOldPhoto(activity, mKey);
                            break;
                        default:
@@ -115,38 +98,4 @@ public class PhotoSelectionDialog extends DialogFragment {
                })
                .create();
    }

    /**
     * Adds the choices for the artist profile image.
     */
    private void setArtistChoices() {
        // Select a photo from the gallery
        mChoices.add(NEW_PHOTO, getString(R.string.new_photo));
    }

    /**
     * Adds the choices for the album profile image.
     */
    private void setAlbumChoices() {
        // Select a photo from the gallery
        mChoices.add(NEW_PHOTO, getString(R.string.new_photo));
    }

    /**
     * Adds the choices for the genre and playlist images.
     */
    private void setOtherChoices() {
        // Select a photo from the gallery
        mChoices.add(NEW_PHOTO, getString(R.string.new_photo));
    }

    /**
     * Easily detect the MIME type
     */
    public enum ProfileType {
        ARTIST,
        ALBUM,
        PROFILE_TYPE,
        OTHER
    }
}
+1 −2
Original line number Diff line number Diff line
@@ -87,8 +87,7 @@ public abstract class AlbumPopupMenuHelper extends PopupMenuHelper {
            if (item.getItemId() == FragmentMenuItems.CHANGE_IMAGE) {
                String key = ImageFetcher.generateAlbumCacheKey(mAlbum.mAlbumName,
                        getArtistName());
                PhotoSelectionDialog.newInstance(mAlbum.mAlbumName,
                        PhotoSelectionDialog.ProfileType.ALBUM, key)
                PhotoSelectionDialog.newInstance(mAlbum.mAlbumName, key)
                        .show(mFragmentManager, "PhotoSelectionDialog");
                return true;
            }
+1 −2
Original line number Diff line number Diff line
@@ -75,8 +75,7 @@ public abstract class ArtistPopupMenuHelper extends PopupMenuHelper {
        boolean handled = super.onMenuItemClick(item);
        if (!handled && item.getGroupId() == getGroupId()) {
            if (item.getItemId() == FragmentMenuItems.CHANGE_IMAGE) {
                PhotoSelectionDialog.newInstance(getArtistName(),
                        PhotoSelectionDialog.ProfileType.ARTIST, getArtistName())
                PhotoSelectionDialog.newInstance(getArtistName(), getArtistName())
                        .show(mFragmentManager, "PhotoSelectionDialog");
                return true;
            }