Search in sources :

Example 6 with AdaptableItem

use of com.simplecity.amp_library.model.AdaptableItem in project Shuttle by timusus.

the class DialogUtils method showColorPickerDialog.

public static void showColorPickerDialog(SettingsFragment fragment, int selectedColor, int[] mainColors, int[][] subColors, ColorSelectionListener listener) {
    View customView = LayoutInflater.from(fragment.getActivity()).inflate(R.layout.dialog_color_picker, null);
    RecyclerView recyclerView = (RecyclerView) customView.findViewById(R.id.recyclerView);
    GridLayoutManager gridLayoutManager = new GridLayoutManager(fragment.getActivity(), 5);
    recyclerView.setLayoutManager(gridLayoutManager);
    ThemeUtils.themeRecyclerView(recyclerView);
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            ThemeUtils.themeRecyclerView(recyclerView);
            super.onScrollStateChanged(recyclerView, newState);
        }
    });
    ColorAdapter colorAdapter = new ColorAdapter();
    List<AdaptableItem> colorViews = new ArrayList<>();
    for (int i = 0, length = mainColors.length; i < length; i++) {
        ColorView colorView = new ColorView(mainColors[i]);
        boolean selected = false;
        //If the sub colors array contains our selected color, then we set this colorView to selected.
        for (int j = 0, jLength = subColors[i].length; j < jLength; j++) {
            if (subColors[i][j] == selectedColor) {
                selected = true;
            }
        }
        colorView.selected = selected;
        colorViews.add(colorView);
    }
    colorAdapter.setItems(colorViews);
    recyclerView.setAdapter(colorAdapter);
    colorAdapter.setColorListener((position, color, isSubColor) -> {
        if (isSubColor) {
            colorAdapter.setSelectedPosition(position);
        } else {
            List<AdaptableItem> subColorViews = new ArrayList<>();
            for (int i = 0, length = subColors[position].length; i < length; i++) {
                ColorView colorView = new ColorView(subColors[position][i]);
                colorView.selected = colorView.color == selectedColor;
                subColorViews.add(colorView);
                colorAdapter.isSubColor = true;
            }
            colorAdapter.setItems(subColorViews);
        }
    });
    int neutralTextResId;
    TextView textView = (TextView) customView.findViewById(R.id.text1);
    if (ShuttleUtils.isUpgraded()) {
        textView.setVisibility(View.GONE);
        neutralTextResId = R.string.dialog_custom;
    } else {
        textView.setVisibility(View.VISIBLE);
        if (ShuttleUtils.isAmazonBuild()) {
            neutralTextResId = R.string.get_pro_button_amazon;
        } else {
            neutralTextResId = R.string.btn_upgrade;
        }
    }
    getBuilder(fragment.getActivity()).title(fragment.getActivity().getString(R.string.color_pick)).negativeText(R.string.cancel).onNegative((dialog, which) -> dialog.dismiss()).positiveText(R.string.button_done).onPositive((dialog, which) -> {
        int color = selectedColor;
        for (AdaptableItem item : colorAdapter.items) {
            if (((ColorView) item).selected) {
                color = ((ColorView) item).color;
                break;
            }
        }
        listener.colorSelected(color);
        dialog.dismiss();
    }).neutralText(neutralTextResId).autoDismiss(false).onNeutral((dialog, which) -> {
        if (ShuttleUtils.isUpgraded()) {
            showCustomColorPickerDialog(fragment.getActivity(), selectedColor, listener);
            dialog.dismiss();
        } else {
            showUpgradeDialog(fragment.getActivity(), (upgradeDialog, which1) -> {
                if (ShuttleUtils.isAmazonBuild()) {
                    ShuttleUtils.openShuttleLink(fragment.getActivity(), "com.simplecity.amp_pro");
                } else {
                    AnalyticsManager.logUpgrade(AnalyticsManager.UpgradeType.COLORS);
                    ((SettingsActivity) fragment.getActivity()).purchasePremiumUpgrade();
                }
            });
        }
    }).customView(customView, false).show();
}
Also used : ContentProviderOperation(android.content.ContentProviderOperation) R(com.simplecity.amp_library.R) GridLayoutManager(android.support.v7.widget.GridLayoutManager) ProgressBar(android.widget.ProgressBar) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) PlayCountTable(com.simplecity.amp_library.sql.providers.PlayCountTable) Drawable(android.graphics.drawable.Drawable) FileProvider(android.support.v4.content.FileProvider) Song(com.simplecity.amp_library.model.Song) FileObject(com.simplecity.amp_library.model.FileObject) Schedulers(rx.schedulers.Schedulers) View(android.view.View) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) BlacklistAdapter(com.simplecity.amp_library.ui.adapters.BlacklistAdapter) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) WhitelistAdapter(com.simplecity.amp_library.ui.adapters.WhitelistAdapter) R.id.album(com.simplecity.amp_library.R.id.album) MainActivity(com.simplecity.amp_library.ui.activities.MainActivity) ColorView(com.simplecity.amp_library.ui.modelviews.ColorView) R.id.artist(com.simplecity.amp_library.R.id.artist) WhitelistHelper(com.simplecity.amp_library.sql.databases.WhitelistHelper) FileNotFoundException(java.io.FileNotFoundException) CustomColorPicker(com.simplecity.amp_library.ui.views.CustomColorPicker) List(java.util.List) TextView(android.widget.TextView) ColorAdapter(com.simplecity.amp_library.ui.adapters.ColorAdapter) Html(android.text.Html) LastFmArtist(com.simplecity.amp_library.lastfm.LastFmArtist) ListView(android.widget.ListView) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) Snackbar(android.support.design.widget.Snackbar) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Call(retrofit2.Call) Subscription(rx.Subscription) NumberPicker(android.widget.NumberPicker) SettingsActivity(com.simplecity.amp_library.ui.activities.SettingsActivity) Context(android.content.Context) LastFmAlbum(com.simplecity.amp_library.lastfm.LastFmAlbum) Stream(com.annimon.stream.Stream) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) HttpClient(com.simplecity.amp_library.http.HttpClient) Dialog(android.app.Dialog) Intent(android.content.Intent) RemoteException(android.os.RemoteException) StringRes(android.support.annotation.StringRes) Response(retrofit2.Response) SettingsFragment(com.simplecity.amp_library.ui.fragments.SettingsFragment) ArrayList(java.util.ArrayList) Observable(rx.Observable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) WhitelistView(com.simplecity.amp_library.ui.modelviews.WhitelistView) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) BlacklistedSong(com.simplecity.amp_library.model.BlacklistedSong) SqlBriteUtils(com.simplecity.amp_library.sql.sqlbrite.SqlBriteUtils) Collectors(com.annimon.stream.Collectors) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) IntentCompat(android.support.v4.content.IntentCompat) FileOutputStream(java.io.FileOutputStream) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) IOException(java.io.IOException) File(java.io.File) OperationApplicationException(android.content.OperationApplicationException) Color(android.graphics.Color) RecyclerView(android.support.v7.widget.RecyclerView) ArrayAdapter(android.widget.ArrayAdapter) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) BlacklistHelper(com.simplecity.amp_library.sql.databases.BlacklistHelper) Glide(com.bumptech.glide.Glide) Callback(retrofit2.Callback) ScrollView(android.widget.ScrollView) Bitmap(android.graphics.Bitmap) Activity(android.app.Activity) ArrayList(java.util.ArrayList) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) View(android.view.View) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) ColorView(com.simplecity.amp_library.ui.modelviews.ColorView) TextView(android.widget.TextView) ListView(android.widget.ListView) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) WhitelistView(com.simplecity.amp_library.ui.modelviews.WhitelistView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) ColorView(com.simplecity.amp_library.ui.modelviews.ColorView) GridLayoutManager(android.support.v7.widget.GridLayoutManager) ColorAdapter(com.simplecity.amp_library.ui.adapters.ColorAdapter) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) SettingsActivity(com.simplecity.amp_library.ui.activities.SettingsActivity)

Example 7 with AdaptableItem

use of com.simplecity.amp_library.model.AdaptableItem in project Shuttle by timusus.

the class ArtworkDialog method showDialog.

public static void showDialog(Context context, ArtworkProvider artworkProvider) {
    View customView = LayoutInflater.from(context).inflate(R.layout.dialog_artwork, null);
    ArtworkAdapter artworkAdapter = new ArtworkAdapter();
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
    RecyclerView recyclerView = (RecyclerView) customView.findViewById(R.id.recyclerView);
    recyclerView.addItemDecoration(new SpacesItemDecoration(16));
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setHasFixedSize(true);
    recyclerView.setItemViewCacheSize(0);
    recyclerView.setRecyclerListener(holder -> {
        if (holder.getAdapterPosition() != -1) {
            artworkAdapter.items.get(holder.getAdapterPosition()).recycle(holder);
        }
    });
    artworkAdapter.items.add(0, new LoadingView());
    artworkAdapter.notifyDataSetChanged();
    recyclerView.setAdapter(artworkAdapter);
    ArtworkView.GlideListener glideListener = artworkView -> {
        int index = artworkAdapter.items.indexOf(artworkView);
        if (index != -1) {
            artworkAdapter.removeItem(index);
        }
    };
    List<AdaptableItem> adaptableItems = new ArrayList<>();
    UserSelectedArtwork userSelectedArtwork = ShuttleApplication.getInstance().userSelectedArtwork.get(artworkProvider.getArtworkKey());
    if (userSelectedArtwork != null) {
        File file = null;
        if (userSelectedArtwork.path != null) {
            file = new File(userSelectedArtwork.path);
        }
        ArtworkView artworkView = new ArtworkView(userSelectedArtwork.type, artworkProvider, glideListener, file, true);
        artworkView.setSelected(true);
        adaptableItems.add(artworkView);
    }
    if (userSelectedArtwork == null || userSelectedArtwork.type != ArtworkProvider.Type.MEDIA_STORE) {
        adaptableItems.add(new ArtworkView(ArtworkProvider.Type.MEDIA_STORE, artworkProvider, glideListener));
    }
    if (userSelectedArtwork == null || userSelectedArtwork.type != ArtworkProvider.Type.TAG) {
        adaptableItems.add(new ArtworkView(ArtworkProvider.Type.TAG, artworkProvider, glideListener));
    }
    if (userSelectedArtwork == null || userSelectedArtwork.type != ArtworkProvider.Type.LAST_FM) {
        adaptableItems.add(new ArtworkView(ArtworkProvider.Type.LAST_FM, artworkProvider, glideListener));
    }
    if (userSelectedArtwork == null || userSelectedArtwork.type != ArtworkProvider.Type.ITUNES) {
        adaptableItems.add(new ArtworkView(ArtworkProvider.Type.ITUNES, artworkProvider, glideListener));
    }
    //Dummy Folder ArtworkView - will be replaced or removed depending on availability of folder images
    ArtworkView folderView = new ArtworkView(ArtworkProvider.Type.FOLDER, null, null);
    adaptableItems.add(folderView);
    artworkAdapter.setItems(adaptableItems);
    Observable.fromCallable(artworkProvider::getFolderArtworkFiles).subscribeOn(Schedulers.io()).subscribeOn(AndroidSchedulers.mainThread()).subscribe(files -> {
        artworkAdapter.removeItem(artworkAdapter.items.indexOf(folderView));
        if (files != null) {
            Stream.of(files).filter(file -> userSelectedArtwork == null || !file.getPath().equals(userSelectedArtwork.path)).forEach(file -> {
                artworkAdapter.addItem(new ArtworkView(ArtworkProvider.Type.FOLDER, artworkProvider, glideListener, file, false));
            });
        }
    }, error -> {
        Log.e(TAG, "Error getting folder artwork files.. " + error.toString());
    });
    DialogUtils.getBuilder(context).title(context.getString(R.string.artwork_edit)).customView(customView, false).autoDismiss(false).positiveText(context.getString(R.string.save)).onPositive((dialog, which) -> {
        if (artworkAdapter.checkedItem != null) {
            ContentValues values = new ContentValues();
            values.put(CustomArtworkTable.COLUMN_KEY, artworkProvider.getArtworkKey());
            values.put(CustomArtworkTable.COLUMN_TYPE, artworkAdapter.checkedItem.type);
            values.put(CustomArtworkTable.COLUMN_PATH, artworkAdapter.checkedItem.file == null ? null : artworkAdapter.checkedItem.file.getPath());
            context.getContentResolver().insert(CustomArtworkTable.URI, values);
            ShuttleApplication.getInstance().userSelectedArtwork.put(artworkProvider.getArtworkKey(), new UserSelectedArtwork(artworkAdapter.checkedItem.type, artworkAdapter.checkedItem.file == null ? null : artworkAdapter.checkedItem.file.getPath()));
        } else {
            context.getContentResolver().delete(CustomArtworkTable.URI, CustomArtworkTable.COLUMN_KEY + "='" + artworkProvider.getArtworkKey().replaceAll("'", "\''") + "'", null);
            ShuttleApplication.getInstance().userSelectedArtwork.remove(artworkProvider.getArtworkKey());
        }
        dialog.dismiss();
    }).negativeText(context.getString(R.string.close)).onNegative((dialog, which) -> dialog.dismiss()).neutralText(context.getString(R.string.artwork_gallery)).onNeutral((dialog, which) -> RxImagePicker.with(context).requestImage(Sources.GALLERY).flatMap(uri -> {
        File dir = new File(ShuttleApplication.getInstance().getFilesDir() + "/shuttle/custom_artwork/" + artworkProvider.getArtworkKey().hashCode() + "/");
        if (!dir.exists()) {
            dir.mkdirs();
        } else {
            if (dir.isDirectory()) {
                String[] children = dir.list();
                for (String child : children) {
                    new File(dir, child).delete();
                }
            }
        }
        File file = new File(dir.getPath() + System.currentTimeMillis() + ".artwork");
        try {
            file.createNewFile();
            if (file.exists()) {
                return RxImageConverters.uriToFile(context, uri, file);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }).filter(file -> file != null && file.exists()).subscribe(file -> {
        if (artworkAdapter.getItemCount() != 0) {
            File aFile = ((ArtworkView) artworkAdapter.items.get(0)).file;
            if (aFile != null && aFile.getPath().contains(artworkProvider.getArtworkKey())) {
                artworkAdapter.removeItem(0);
            }
        }
        ArtworkView artworkView = new ArtworkView(ArtworkProvider.Type.FOLDER, artworkProvider, glideListener, file, true);
        artworkAdapter.addItem(0, artworkView);
        artworkAdapter.selectItem(0);
        recyclerView.scrollToPosition(0);
    })).cancelable(false).show();
}
Also used : R(com.simplecity.amp_library.R) Context(android.content.Context) SpacesItemDecoration(com.simplecity.amp_library.ui.recyclerview.SpacesItemDecoration) Stream(com.annimon.stream.Stream) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) ItemAdapter(com.simplecity.amp_library.ui.adapters.ItemAdapter) ArrayList(java.util.ArrayList) Observable(rx.Observable) UserSelectedArtwork(com.simplecity.amp_library.model.UserSelectedArtwork) LoadingView(com.simplecity.amp_library.ui.modelviews.LoadingView) Schedulers(rx.schedulers.Schedulers) View(android.view.View) RxImageConverters(com.mlsdev.rximagepicker.RxImageConverters) Log(android.util.Log) RxImagePicker(com.mlsdev.rximagepicker.RxImagePicker) ArtworkModel(com.simplecity.amp_library.model.ArtworkModel) ArtworkView(com.simplecity.amp_library.ui.modelviews.ArtworkView) LayoutInflater(android.view.LayoutInflater) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) IOException(java.io.IOException) ArtworkProvider(com.simplecity.amp_library.model.ArtworkProvider) CustomArtworkTable(com.simplecity.amp_library.sql.databases.CustomArtworkTable) File(java.io.File) RecyclerView(android.support.v7.widget.RecyclerView) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) List(java.util.List) ContentValues(android.content.ContentValues) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) Sources(com.mlsdev.rximagepicker.Sources) ContentValues(android.content.ContentValues) ArtworkView(com.simplecity.amp_library.ui.modelviews.ArtworkView) ArrayList(java.util.ArrayList) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) IOException(java.io.IOException) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) LoadingView(com.simplecity.amp_library.ui.modelviews.LoadingView) View(android.view.View) ArtworkView(com.simplecity.amp_library.ui.modelviews.ArtworkView) RecyclerView(android.support.v7.widget.RecyclerView) UserSelectedArtwork(com.simplecity.amp_library.model.UserSelectedArtwork) LoadingView(com.simplecity.amp_library.ui.modelviews.LoadingView) RecyclerView(android.support.v7.widget.RecyclerView) SpacesItemDecoration(com.simplecity.amp_library.ui.recyclerview.SpacesItemDecoration) File(java.io.File)

Example 8 with AdaptableItem

use of com.simplecity.amp_library.model.AdaptableItem in project Shuttle by timusus.

the class DetailFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_detail, container, false);
    recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    recyclerView.setAdapter(adapter);
    if (canEdit()) {
        itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback((from, to) -> {
            long songViewCount = Stream.of(adapter.items).filter(adaptableItem -> adaptableItem instanceof SongView).count();
            int offset = (int) (adapter.getItemCount() - songViewCount);
            if (to >= offset) {
                adapter.moveItem(from, to);
            }
        }, (from, to) -> {
            // The 'offset' here is the number of items in the list which are not
            // SongViews. We need this to determine the actual playlist positions of the items.
            long songViewCount = Stream.of(adapter.items).filter(adaptableItem -> adaptableItem instanceof SongView).count();
            int offset = (int) (adapter.getItemCount() - songViewCount);
            from -= offset;
            to -= offset;
            try {
                MediaStore.Audio.Playlists.Members.moveItem(getActivity().getContentResolver(), playlist.id, from, to);
            } catch (IllegalArgumentException e) {
                CrashlyticsCore.getInstance().log(String.format("Failed to move playlist item from %s to %s. Adapter count: %s. Error:%s", from, to, adapter.getItemCount(), e.getMessage()));
            }
        }, null));
        itemTouchHelper.attachToRecyclerView(recyclerView);
    }
    fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
    fab.setOnClickListener(this);
    lineOne = (TextView) rootView.findViewById(R.id.line_one);
    lineTwo = (TextView) rootView.findViewById(R.id.line_two);
    overflowButton = (NonScrollImageButton) rootView.findViewById(R.id.btn_overflow);
    overflowButton.setOnClickListener(this);
    if (albumArtist != null) {
        lineOne.setText(albumArtist.name);
        overflowButton.setContentDescription(getString(R.string.btn_options, albumArtist.name));
    } else if (album != null) {
        lineOne.setText(album.name);
        overflowButton.setContentDescription(getString(R.string.btn_options, album.name));
    } else if (genre != null) {
        lineOne.setText(genre.name);
        overflowButton.setVisibility(View.GONE);
    } else if (playlist != null) {
        lineOne.setText(playlist.name);
        overflowButton.setContentDescription(getString(R.string.btn_options, playlist.name));
    }
    textProtectionScrim = rootView.findViewById(R.id.textProtectionScrim);
    headerImageView = (ImageView) rootView.findViewById(R.id.background);
    String transitionName = getArguments().getString(ARG_TRANSITION_NAME);
    ViewCompat.setTransitionName(headerImageView, transitionName);
    if (transitionName != null) {
        textProtectionScrim.setVisibility(View.GONE);
        fab.setVisibility(View.GONE);
    }
    int width = ResourceUtils.getScreenSize().width + ResourceUtils.toPixels(60);
    int height = getResources().getDimensionPixelSize(R.dimen.header_view_height);
    if (albumArtist != null || album != null) {
        requestManager.load(albumArtist == null ? album : albumArtist).override(width, height).diskCacheStrategy(DiskCacheStrategy.SOURCE).priority(Priority.HIGH).placeholder(GlideUtils.getPlaceHolderDrawable(albumArtist == null ? album.name : albumArtist.name, false)).centerCrop().animate(new AlwaysCrossFade(false)).into(headerImageView);
    }
    actionMode = null;
    //Set the RecyclerView HeaderView height equal to the headerItem height
    headerView = rootView.findViewById(R.id.headerView);
    headerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            headerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            DetailFragment.this.headerItem.height = headerView.getHeight();
        }
    });
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            headerTranslation = headerView.getTranslationY() - dy;
            headerImageTranslation = headerImageView.getTranslationY() + dy / 2;
            //the header translation.
            if (headerTranslation == 0) {
                headerImageTranslation = 0;
            }
            float ratio = Math.min(1, -headerTranslation / headerView.getHeight());
            headerView.setTranslationY(headerTranslation);
            headerImageView.setTranslationY(headerImageTranslation);
            //when recreating this fragment.
            if (getActivity() != null) {
                if (((MainActivity) getActivity()).canSetAlpha()) {
                    ((MainActivity) getActivity()).setActionBarAlpha(ratio, true);
                }
            }
        }
    });
    themeUIComponents();
    headerView.setTranslationY(headerTranslation);
    headerImageView.setTranslationY(headerImageTranslation);
    return rootView;
}
Also used : ModalMultiSelectorCallback(com.bignerdranch.android.multiselector.ModalMultiSelectorCallback) R(com.simplecity.amp_library.R) Genre(com.simplecity.amp_library.model.Genre) Bundle(android.os.Bundle) SongView(com.simplecity.amp_library.ui.modelviews.SongView) CrashlyticsCore(com.crashlytics.android.core.CrashlyticsCore) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Random(java.util.Random) ItemAdapter(com.simplecity.amp_library.ui.adapters.ItemAdapter) ColorStateList(android.content.res.ColorStateList) Song(com.simplecity.amp_library.model.Song) Priority(com.bumptech.glide.Priority) RequestManager(com.bumptech.glide.RequestManager) HorizontalAlbumView(com.simplecity.amp_library.ui.modelviews.HorizontalAlbumView) MediaStore(android.provider.MediaStore) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) Schedulers(rx.schedulers.Schedulers) View(android.view.View) DetailAdapter(com.simplecity.amp_library.ui.adapters.DetailAdapter) ResourceUtils(com.simplecity.amp_library.utils.ResourceUtils) ViewCompat(android.support.v4.view.ViewCompat) Transition(android.transition.Transition) PreferenceManager(android.preference.PreferenceManager) ItemTouchHelperCallback(com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback) FloatingActionButton(android.support.design.widget.FloatingActionButton) SortManager(com.simplecity.amp_library.utils.SortManager) ActionMode(android.support.v7.view.ActionMode) Playlist(com.simplecity.amp_library.model.Playlist) MainActivity(com.simplecity.amp_library.ui.activities.MainActivity) ObjectAnimator(android.animation.ObjectAnimator) IntentFilter(android.content.IntentFilter) PopupMenu(android.support.v7.widget.PopupMenu) SubMenu(android.view.SubMenu) BroadcastReceiver(android.content.BroadcastReceiver) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) BaseAdaptableItem(com.simplecity.amp_library.ui.modelviews.BaseAdaptableItem) NonScrollImageButton(com.simplecity.amp_library.ui.views.NonScrollImageButton) Serializable(java.io.Serializable) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) List(java.util.List) TextView(android.widget.TextView) PermissionUtils(com.simplecity.amp_library.utils.PermissionUtils) GlideUtils(com.simplecity.amp_library.glide.utils.GlideUtils) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) Subscription(rx.Subscription) Context(android.content.Context) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) DrawableUtils(com.simplecity.amp_library.utils.DrawableUtils) Intent(android.content.Intent) StringUtils(com.simplecity.amp_library.utils.StringUtils) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Observable(rx.Observable) ThemeUtils(com.simplecity.amp_library.utils.ThemeUtils) ColorUtils(com.simplecity.amp_library.utils.ColorUtils) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) Menu(android.view.Menu) AnimatorSet(android.animation.AnimatorSet) WeakReference(java.lang.ref.WeakReference) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) SharedElementCallback(android.support.v4.app.SharedElementCallback) AlwaysCrossFade(com.simplecity.amp_library.glide.utils.AlwaysCrossFade) ViewType(com.simplecity.amp_library.ui.modelviews.ViewType) Collectors(com.annimon.stream.Collectors) LayoutInflater(android.view.LayoutInflater) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DiscNumberView(com.simplecity.amp_library.ui.modelviews.DiscNumberView) DialogUtils(com.simplecity.amp_library.utils.DialogUtils) TimeUnit(java.util.concurrent.TimeUnit) CompositeSubscription(rx.subscriptions.CompositeSubscription) RecyclerView(android.support.v7.widget.RecyclerView) BlacklistHelper(com.simplecity.amp_library.sql.databases.BlacklistHelper) Glide(com.bumptech.glide.Glide) SharedPreferences(android.content.SharedPreferences) HorizontalRecyclerView(com.simplecity.amp_library.ui.modelviews.HorizontalRecyclerView) OvershootInterpolator(android.view.animation.OvershootInterpolator) MultiSelector(com.bignerdranch.android.multiselector.MultiSelector) ComparisonUtils(com.simplecity.amp_library.utils.ComparisonUtils) ViewTreeObserver(android.view.ViewTreeObserver) DataManager(com.simplecity.amp_library.utils.DataManager) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) Operators(com.simplecity.amp_library.utils.Operators) Collections(java.util.Collections) ContentUris(android.content.ContentUris) SongView(com.simplecity.amp_library.ui.modelviews.SongView) AlwaysCrossFade(com.simplecity.amp_library.glide.utils.AlwaysCrossFade) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ItemTouchHelperCallback(com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) RecyclerView(android.support.v7.widget.RecyclerView) HorizontalRecyclerView(com.simplecity.amp_library.ui.modelviews.HorizontalRecyclerView) ViewTreeObserver(android.view.ViewTreeObserver)

Example 9 with AdaptableItem

use of com.simplecity.amp_library.model.AdaptableItem in project Shuttle by timusus.

the class SuggestedFragment method refreshAdapterItems.

void refreshAdapterItems() {
    PermissionUtils.RequestStoragePermissions(() -> {
        if (getActivity() != null && isAdded()) {
            subscription = new CompositeSubscription();
            Observable<Playlist> mostPlayedPlaylistObservable = Observable.fromCallable(Playlist::mostPlayedPlaylist).subscribeOn(Schedulers.io()).cache();
            Observable<List<Song>> mostPlayedSongsObservable = mostPlayedPlaylistObservable.filter(playlist -> playlist != null).flatMap(playlist -> playlist.getSongsObservable(getContext())).cache();
            Observable<List<AdaptableItem>> mostPlayedItemsObservable = mostPlayedPlaylistObservable.flatMap(playlist -> {
                SuggestedHeader mostPlayedHeader = new SuggestedHeader(getString(R.string.mostplayed), getString(R.string.suggested_most_played_songs_subtitle), playlist);
                SuggestedHeaderView mostPlayedHeaderView = new SuggestedHeaderView(mostPlayedHeader);
                return mostPlayedSongsObservable.map(songs -> {
                    List<AdaptableItem> items = new ArrayList<>();
                    if (!songs.isEmpty()) {
                        items.add(mostPlayedHeaderView);
                        items.add(mostPlayedRecyclerView);
                    }
                    return items;
                });
            }).switchIfEmpty(Observable.just(Collections.emptyList()));
            Observable<List<AdaptableItem>> recentlyPlayedAlbums = Observable.fromCallable(Playlist::recentlyPlayedPlaylist).subscribeOn(Schedulers.io()).filter(playlist -> playlist != null).flatMap(playlist -> {
                SuggestedHeader recentlyPlayedHeader = new SuggestedHeader(getString(R.string.suggested_recent_title), getString(R.string.suggested_recent_subtitle), playlist);
                SuggestedHeaderView recentlyPlayedHeaderView = new SuggestedHeaderView(recentlyPlayedHeader);
                return playlist.getSongsObservable(getContext()).flatMap(songs -> Observable.just(Operators.songsToAlbums(songs))).flatMap(Observable::from).sorted((a, b) -> ComparisonUtils.compareLong(b.lastPlayed, a.lastPlayed)).limit(6).flatMap(album -> album.getSongsObservable().map(songs -> {
                    album.numSongs = songs.size();
                    return album;
                })).sorted((a, b) -> ComparisonUtils.compareLong(b.lastPlayed, a.lastPlayed)).filter(album -> album.numSongs > 0).map(album -> (AdaptableItem) new AlbumView(album, ViewType.ALBUM_LIST_SMALL, requestManager)).toList().map(adaptableItems -> {
                    if (!adaptableItems.isEmpty()) {
                        adaptableItems.add(0, recentlyPlayedHeaderView);
                    }
                    return adaptableItems;
                });
            }).switchIfEmpty(Observable.just(Collections.emptyList()));
            Observable<Playlist> favouritesPlaylistObservable = Observable.fromCallable(Playlist::favoritesPlaylist).subscribeOn(Schedulers.io()).cache();
            Observable<List<Song>> favouritesSongsObservable = favouritesPlaylistObservable.filter(playlist -> playlist != null).flatMap(playlist -> playlist.getSongsObservable(getContext())).cache();
            Observable<List<AdaptableItem>> favoriteSongsItemsObservable = favouritesPlaylistObservable.flatMap(playlist -> {
                SuggestedHeader favoriteHeader = new SuggestedHeader(getString(R.string.fav_title), getString(R.string.suggested_favorite_subtitle), playlist);
                SuggestedHeaderView favoriteHeaderView = new SuggestedHeaderView(favoriteHeader);
                return favouritesSongsObservable.map(songs -> {
                    List<AdaptableItem> items = new ArrayList<>();
                    if (!songs.isEmpty()) {
                        items.add(favoriteHeaderView);
                        items.add(favoriteRecyclerView);
                    }
                    return items;
                });
            }).switchIfEmpty(Observable.just(Collections.emptyList()));
            Observable<List<AdaptableItem>> recentlyAddedAlbums = Observable.fromCallable(Playlist::recentlyAddedPlaylist).subscribeOn(Schedulers.io()).filter(playlist -> playlist != null).flatMap(playlist -> {
                SuggestedHeader recentlyAddedHeader = new SuggestedHeader(getString(R.string.recentlyadded), getString(R.string.suggested_recently_added_subtitle), playlist);
                SuggestedHeaderView recentlyAddedHeaderView = new SuggestedHeaderView(recentlyAddedHeader);
                return playlist.getSongsObservable(getContext()).flatMap(songs -> Observable.just(Operators.songsToAlbums(songs))).flatMap(Observable::from).sorted((a, b) -> ComparisonUtils.compareLong(b.dateAdded, a.dateAdded)).limit(4).flatMap(album -> album.getSongsObservable().map(songs -> {
                    album.numSongs = songs.size();
                    return album;
                })).sorted((a, b) -> ComparisonUtils.compareLong(b.dateAdded, a.dateAdded)).filter(album -> album.numSongs > 0).map(album -> (AdaptableItem) new AlbumView(album, ViewType.ALBUM_LIST_SMALL, requestManager)).toList().map(adaptableItems -> {
                    if (!adaptableItems.isEmpty()) {
                        adaptableItems.add(0, recentlyAddedHeaderView);
                    }
                    return adaptableItems;
                });
            }).switchIfEmpty(Observable.just(Collections.emptyList()));
            Observable.merge(mostPlayedItemsObservable, recentlyPlayedAlbums, favoriteSongsItemsObservable, recentlyAddedAlbums);
            subscription.add(Observable.combineLatest(mostPlayedItemsObservable, recentlyPlayedAlbums, favoriteSongsItemsObservable, recentlyAddedAlbums, (mostPlayedSongs1, recentlyPlayedAlbums1, favoriteSongs1, recentlyAddedAlbums1) -> {
                List<AdaptableItem> items = new ArrayList<>();
                items.addAll(mostPlayedSongs1);
                items.addAll(recentlyPlayedAlbums1);
                items.addAll(favoriteSongs1);
                items.addAll(recentlyAddedAlbums1);
                return items;
            }).debounce(250, TimeUnit.MILLISECONDS).switchIfEmpty(Observable.just(new ArrayList<>())).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
                if (adaptableItems.isEmpty()) {
                    suggestedAdapter.setEmpty(new EmptyView(R.string.empty_suggested));
                } else {
                    suggestedAdapter.setItems(adaptableItems);
                }
            }));
            subscription.add(mostPlayedSongsObservable.map(songs -> {
                Collections.sort(songs, (a, b) -> ComparisonUtils.compareInt(b.playCount, a.playCount));
                return Stream.of(songs).map(song -> (AdaptableItem) new SuggestedSongView(song, requestManager)).limit(20).collect(Collectors.toList());
            }).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
                mostPlayedRecyclerView.itemAdapter.setItems(adaptableItems);
            }));
            subscription.add(favouritesSongsObservable.map(songs -> Stream.of(songs).map(song -> (AdaptableItem) new SuggestedSongView(song, requestManager)).limit(20).collect(Collectors.toList())).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
                favoriteRecyclerView.itemAdapter.setItems(adaptableItems);
            }));
        }
    });
}
Also used : R(com.simplecity.amp_library.R) GridLayoutManager(android.support.v7.widget.GridLayoutManager) Bundle(android.os.Bundle) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) SuggestedDividerDecoration(com.simplecity.amp_library.ui.views.SuggestedDividerDecoration) ItemAdapter(com.simplecity.amp_library.ui.adapters.ItemAdapter) Song(com.simplecity.amp_library.model.Song) RequestManager(com.bumptech.glide.RequestManager) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) Schedulers(rx.schedulers.Schedulers) View(android.view.View) PreferenceManager(android.preference.PreferenceManager) Playlist(com.simplecity.amp_library.model.Playlist) IntentFilter(android.content.IntentFilter) PopupMenu(android.support.v7.widget.PopupMenu) BroadcastReceiver(android.content.BroadcastReceiver) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) SuggestedHeaderView(com.simplecity.amp_library.ui.modelviews.SuggestedHeaderView) Serializable(java.io.Serializable) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) List(java.util.List) PermissionUtils(com.simplecity.amp_library.utils.PermissionUtils) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) Context(android.content.Context) SuggestedSongView(com.simplecity.amp_library.ui.modelviews.SuggestedSongView) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) Intent(android.content.Intent) ArrayList(java.util.ArrayList) Observable(rx.Observable) SuggestedHeader(com.simplecity.amp_library.model.SuggestedHeader) ThemeUtils(com.simplecity.amp_library.utils.ThemeUtils) SuggestedAdapter(com.simplecity.amp_library.ui.adapters.SuggestedAdapter) Toast(android.widget.Toast) ViewType(com.simplecity.amp_library.ui.modelviews.ViewType) Collectors(com.annimon.stream.Collectors) LayoutInflater(android.view.LayoutInflater) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) TimeUnit(java.util.concurrent.TimeUnit) CompositeSubscription(rx.subscriptions.CompositeSubscription) RecyclerView(android.support.v7.widget.RecyclerView) BlacklistHelper(com.simplecity.amp_library.sql.databases.BlacklistHelper) Glide(com.bumptech.glide.Glide) SharedPreferences(android.content.SharedPreferences) HorizontalRecyclerView(com.simplecity.amp_library.ui.modelviews.HorizontalRecyclerView) ComparisonUtils(com.simplecity.amp_library.utils.ComparisonUtils) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) Operators(com.simplecity.amp_library.utils.Operators) Collections(java.util.Collections) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) SuggestedSongView(com.simplecity.amp_library.ui.modelviews.SuggestedSongView) Playlist(com.simplecity.amp_library.model.Playlist) SuggestedHeaderView(com.simplecity.amp_library.ui.modelviews.SuggestedHeaderView) CompositeSubscription(rx.subscriptions.CompositeSubscription) List(java.util.List) ArrayList(java.util.ArrayList) SuggestedHeader(com.simplecity.amp_library.model.SuggestedHeader) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView)

Example 10 with AdaptableItem

use of com.simplecity.amp_library.model.AdaptableItem in project Shuttle by timusus.

the class AlbumFragment method refreshAdapterItems.

void refreshAdapterItems() {
    PermissionUtils.RequestStoragePermissions(() -> {
        if (getActivity() != null && isAdded()) {
            int albumDisplayType = SettingsManager.getInstance().getAlbumDisplayType();
            boolean ascending = SortManager.getInstance().getAlbumsAscending();
            subscription = DataManager.getInstance().getAlbumsRelay().flatMap(albums -> {
                SortManager.getInstance().sortAlbums(albums);
                if (!ascending) {
                    Collections.reverse(albums);
                }
                return Observable.from(albums).map(album -> (AdaptableItem) new AlbumView(album, albumDisplayType, requestManager, multiSelector)).toList();
            }).observeOn(AndroidSchedulers.mainThread()).subscribe(items -> {
                if (items.isEmpty()) {
                    albumAdapter.setEmpty(new EmptyView(R.string.empty_albums));
                } else {
                    albumAdapter.setItems(items);
                }
                if (sortOrderChanged) {
                    recyclerView.scrollToPosition(0);
                }
                sortOrderChanged = false;
            });
        }
    });
}
Also used : ModalMultiSelectorCallback(com.bignerdranch.android.multiselector.ModalMultiSelectorCallback) R(com.simplecity.amp_library.R) GridLayoutManager(android.support.v7.widget.GridLayoutManager) Bundle(android.os.Bundle) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Song(com.simplecity.amp_library.model.Song) RequestManager(com.bumptech.glide.RequestManager) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) View(android.view.View) PreferenceManager(android.preference.PreferenceManager) SortManager(com.simplecity.amp_library.utils.SortManager) ActionMode(android.support.v7.view.ActionMode) Playlist(com.simplecity.amp_library.model.Playlist) IntentFilter(android.content.IntentFilter) PopupMenu(android.support.v7.widget.PopupMenu) SubMenu(android.view.SubMenu) BroadcastReceiver(android.content.BroadcastReceiver) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) List(java.util.List) PermissionUtils(com.simplecity.amp_library.utils.PermissionUtils) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) Subscription(rx.Subscription) Context(android.content.Context) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) Intent(android.content.Intent) MenuItem(android.view.MenuItem) Observable(rx.Observable) SuppressLint(android.annotation.SuppressLint) ThemeUtils(com.simplecity.amp_library.utils.ThemeUtils) ColorUtils(com.simplecity.amp_library.utils.ColorUtils) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) ViewType(com.simplecity.amp_library.ui.modelviews.ViewType) Collectors(com.annimon.stream.Collectors) LayoutInflater(android.view.LayoutInflater) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) DialogUtils(com.simplecity.amp_library.utils.DialogUtils) RecyclerView(android.support.v7.widget.RecyclerView) Glide(com.bumptech.glide.Glide) SharedPreferences(android.content.SharedPreferences) GridDividerDecoration(com.simplecity.amp_library.ui.recyclerview.GridDividerDecoration) MultiSelector(com.bignerdranch.android.multiselector.MultiSelector) DataManager(com.simplecity.amp_library.utils.DataManager) Collections(java.util.Collections) AlbumAdapter(com.simplecity.amp_library.ui.adapters.AlbumAdapter) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) SuppressLint(android.annotation.SuppressLint)

Aggregations

AdaptableItem (com.simplecity.amp_library.model.AdaptableItem)13 RecyclerView (android.support.v7.widget.RecyclerView)11 Context (android.content.Context)10 View (android.view.View)10 Stream (com.annimon.stream.Stream)10 R (com.simplecity.amp_library.R)10 List (java.util.List)10 AndroidSchedulers (rx.android.schedulers.AndroidSchedulers)10 LayoutInflater (android.view.LayoutInflater)9 Collectors (com.annimon.stream.Collectors)9 Song (com.simplecity.amp_library.model.Song)9 ArrayList (java.util.ArrayList)9 Schedulers (rx.schedulers.Schedulers)9 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)8 Toast (android.widget.Toast)8 Observable (rx.Observable)8 Intent (android.content.Intent)7 Bundle (android.os.Bundle)7 PopupMenu (android.support.v7.widget.PopupMenu)7 Glide (com.bumptech.glide.Glide)7