Search in sources :

Example 1 with ItemTouchHelperCallback

use of com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback in project Shuttle by timusus.

the class SettingsFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActivity().supportInvalidateOptionsMenu();
    mTintManager = new SystemBarTintManager(getActivity());
    if (getArguments() != null) {
        mPrefResId = getArguments().getInt(PREF_RES_ID);
    } else {
        mPrefResId = R.xml.settings_headers;
    }
    // Load the preferences from an XML resource
    addPreferencesFromResource(mPrefResId);
    mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    final Preference chooseTabsPreference = findPreference("pref_tab_chooser");
    if (chooseTabsPreference != null) {
        chooseTabsPreference.setOnPreferenceClickListener(preference -> {
            RecyclerView recyclerView = (RecyclerView) LayoutInflater.from(getContext()).inflate(R.layout.dialog_tab_chooser, null);
            recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
            TabsAdapter tabsAdapter = new TabsAdapter(getContext());
            ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback(tabsAdapter::moveItem, (fromPosition, toPosition) -> tabsAdapter.updatePreferences(), () -> {
            }));
            itemTouchHelper.attachToRecyclerView(recyclerView);
            tabsAdapter.setListener(new TabsAdapter.TabListener() {

                @Override
                public void onItemClick(View v, int position, CategoryItem categoryItem) {
                    categoryItem.setChecked(!categoryItem.isChecked());
                    com.simplecity.amp_library.utils.AnalyticsManager.logTabVisibilityChanged(categoryItem.isChecked(), categoryItem.title);
                    tabsAdapter.notifyItemChanged(position);
                    tabsAdapter.updatePreferences();
                }

                @Override
                public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
                    itemTouchHelper.startDrag(viewHolder);
                }
            });
            recyclerView.setAdapter(tabsAdapter);
            DialogUtils.getBuilder(getContext()).title(R.string.pref_title_choose_tabs).customView(recyclerView, false).positiveText(R.string.button_done).onPositive((materialDialog, dialogAction) -> {
                DialogUtils.createRestartDialog(getActivity());
                materialDialog.dismiss();
            }).show();
            return true;
        });
    }
    final Preference colorPickerPreference = findPreference("pref_theme_highlight_color");
    if (colorPickerPreference != null) {
        colorPickerPreference.setOnPreferenceClickListener(preference -> {
            int selectedColor = mPrefs.getInt("pref_theme_highlight_color", -1);
            DialogUtils.showColorPickerDialog(this, selectedColor, color -> mPrefs.edit().putInt("pref_theme_highlight_color", color).apply());
            return true;
        });
    }
    final Preference accentPickerPreference = findPreference("pref_theme_accent_color");
    if (accentPickerPreference != null) {
        accentPickerPreference.setOnPreferenceClickListener(preference -> {
            int selectedColor = mPrefs.getInt("pref_theme_accent_color", -1);
            DialogUtils.showColorPickerDialog(this, selectedColor, ColorPalette.getAccentColors(), ColorPalette.getAccentColorsSub(), color -> mPrefs.edit().putInt("pref_theme_accent_color", color).apply());
            return true;
        });
    }
    mListener = (sharedPreferences, key) -> {
        if (key.equals("pref_theme_highlight_color") || key.equals("pref_theme_accent_color") || key.equals("pref_theme_white_accent")) {
            ThemeUtils.setTheme(getActivity());
            ThemeUtils.themeActionBar((SettingsActivity) getActivity());
            ThemeUtils.themeStatusBar(getActivity(), mTintManager);
            getListView().invalidate();
            themeUIElements();
            for (int i = 0, size = getListView().getChildCount(); i < size; i++) {
                View view = getListView().getChildAt(i);
                ThemeUtils.updateThemableViews(view);
            }
        }
        if (key.equals("pref_theme_base") || key.equals("pref_default_page")) {
            DialogUtils.createRestartDialog(getActivity());
        }
    };
    final Preference restartPreference = findPreference("pref_restart");
    if (restartPreference != null) {
        restartPreference.setOnPreferenceClickListener(preference -> {
            Intent intent = new Intent(getActivity(), MainActivity.class);
            ComponentName componentNAme = intent.getComponent();
            Intent mainIntent = IntentCompat.makeRestartActivityTask(componentNAme);
            startActivity(mainIntent);
            return true;
        });
    }
    final CheckBoxPreference showLockscreenArtworkPreference = (CheckBoxPreference) findPreference(SettingsManager.KEY_SHOW_LOCKSCREEN_ARTWORK);
    if (showLockscreenArtworkPreference != null) {
        showLockscreenArtworkPreference.setOnPreferenceClickListener(preference -> {
            MusicUtils.toggleLockscreenArtwork();
            return false;
        });
    }
    final Preference downloadArtworkPreference = findPreference("pref_download_artwork");
    if (downloadArtworkPreference != null) {
        downloadArtworkPreference.setOnPreferenceClickListener(preference -> {
            DialogUtils.showDownloadWarningDialog(getActivity(), (materialDialog, dialogAction) -> {
                Intent intent = new Intent(getContext(), ArtworkDownloadService.class);
                ShuttleApplication.getInstance().startService(intent);
            });
            return true;
        });
    }
    final Preference deleteArtworkPreference = findPreference("pref_delete_artwork");
    if (deleteArtworkPreference != null) {
        deleteArtworkPreference.setOnPreferenceClickListener(preference -> {
            DialogUtils.getBuilder(getActivity()).title(getString(R.string.pref_title_delete_artwork)).icon(DrawableUtils.themeLightOrDark(getActivity(), getResources().getDrawable(R.drawable.ic_dialog_alert))).content(getString(R.string.delete_artwork_confirmation_dialog)).positiveText(getString(R.string.button_ok)).onPositive((materialDialog, dialogAction) -> {
                Glide.get(getContext()).clearMemory();
                ShuttleUtils.execute(new AsyncTask<Void, Void, Void>() {

                    @Override
                    protected Void doInBackground(Void... params) {
                        Glide.get(getContext()).clearDiskCache();
                        return null;
                    }
                });
            }).negativeText(getString(R.string.cancel)).show();
            return true;
        });
    }
    final Preference downloadSimpleLastFmScrobbler = findPreference("pref_download_simple_lastfm_scrobbler");
    if (downloadSimpleLastFmScrobbler != null) {
        if (ShuttleUtils.isAmazonBuild()) {
            PreferenceGroup preferenceGroup = (PreferenceGroup) findPreference("pref_key_simple_lastfm_scrobble_settings");
            if (preferenceGroup != null) {
                preferenceGroup.removePreference(downloadSimpleLastFmScrobbler);
            }
        } else {
            downloadSimpleLastFmScrobbler.setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.adam.aslfms")));
        }
    }
    final Preference about = findPreference("pref_about");
    if (about != null) {
        about.setOnPreferenceClickListener(preference -> {
            View customView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_changelog, null);
            WebView webView = (WebView) customView.findViewById(R.id.webView);
            int themeType = ThemeUtils.getThemeType(getActivity());
            webView.setBackgroundColor(getResources().getColor(android.R.color.transparent));
            if (themeType == ThemeUtils.ThemeType.TYPE_LIGHT || themeType == ThemeUtils.ThemeType.TYPE_SOLID_LIGHT) {
                webView.loadUrl("file:///android_asset/web/info.html");
            } else {
                webView.loadUrl("file:///android_asset/web/info_dark.html");
            }
            DialogUtils.getBuilder(getActivity()).title(R.string.pref_title_about).customView(customView, false).negativeText(R.string.close).show();
            AnalyticsManager.logChangelogViewed();
            return true;
        });
    }
    final Preference upgrade = findPreference("pref_upgrade");
    if (upgrade != null) {
        if (ShuttleUtils.isUpgraded()) {
            SettingsFragment.this.getPreferenceScreen().removePreference(upgrade);
        }
        upgrade.setOnPreferenceClickListener(preference -> {
            DialogUtils.showUpgradeDialog(getActivity(), (materialDialog, dialogAction) -> {
                if (ShuttleUtils.isAmazonBuild()) {
                    ShuttleUtils.openShuttleLink(getActivity(), "com.simplecity.amp_pro");
                } else {
                    AnalyticsManager.logUpgrade(AnalyticsManager.UpgradeType.UPGRADE);
                    ((SettingsActivity) getActivity()).purchasePremiumUpgrade();
                }
            });
            return true;
        });
    }
    final Preference viewBlacklist = findPreference("pref_blacklist_view");
    if (viewBlacklist != null) {
        viewBlacklist.setOnPreferenceClickListener(preference -> {
            DialogUtils.showBlacklistDialog(getActivity());
            return true;
        });
    }
    final Preference viewWhitelist = findPreference("pref_whitelist_view");
    if (viewWhitelist != null) {
        viewWhitelist.setOnPreferenceClickListener(preference -> {
            DialogUtils.showWhitelistDialog(getActivity());
            return true;
        });
    }
    final Preference clearBlacklist = findPreference("pref_blacklist_clear");
    if (clearBlacklist != null) {
        clearBlacklist.setOnPreferenceClickListener(preference -> {
            BlacklistHelper.deleteAllSongs();
            Toast.makeText(getActivity(), R.string.blacklist_deleted, Toast.LENGTH_SHORT).show();
            return true;
        });
    }
    final Preference clearWhitelist = findPreference("pref_whitelist_clear");
    if (clearWhitelist != null) {
        clearWhitelist.setOnPreferenceClickListener(preference -> {
            WhitelistHelper.deleteAllFolders();
            Toast.makeText(getActivity(), R.string.whitelist_deleted, Toast.LENGTH_SHORT).show();
            return true;
        });
    }
    final CheckBoxPreference ignoreEmbeddedArtwork = (CheckBoxPreference) findPreference(SettingsManager.KEY_IGNORE_EMBEDDED_ARTWORK);
    if (ignoreEmbeddedArtwork != null) {
        ignoreEmbeddedArtwork.setOnPreferenceChangeListener((preference, newValue) -> {
            showArtworkPreferenceDialog();
            return true;
        });
    }
    final CheckBoxPreference ignoreFolderArtwork = (CheckBoxPreference) findPreference(SettingsManager.KEY_IGNORE_FOLDER_ARTWORK);
    if (ignoreFolderArtwork != null) {
        ignoreFolderArtwork.setOnPreferenceChangeListener((preference, newValue) -> {
            showArtworkPreferenceDialog();
            return true;
        });
    }
    final CheckBoxPreference preferEmbeddedArtwork = (CheckBoxPreference) findPreference(SettingsManager.KEY_PREFER_EMBEDDED_ARTWORK);
    if (preferEmbeddedArtwork != null) {
        preferEmbeddedArtwork.setOnPreferenceChangeListener((preference, newValue) -> {
            showArtworkPreferenceDialog();
            return true;
        });
    }
    final CheckBoxPreference ignoreMediaStoreArtwork = (CheckBoxPreference) findPreference(SettingsManager.KEY_IGNORE_MEDIASTORE_ART);
    if (ignoreMediaStoreArtwork != null) {
        ignoreMediaStoreArtwork.setOnPreferenceChangeListener((preference, newValue) -> {
            showArtworkPreferenceDialog();
            return true;
        });
    }
    final CheckBoxPreference preferLastFmArtwork = (CheckBoxPreference) findPreference(SettingsManager.KEY_PREFER_LAST_FM);
    if (preferLastFmArtwork != null) {
        preferLastFmArtwork.setOnPreferenceChangeListener((preference, newValue) -> {
            showArtworkPreferenceDialog();
            return true;
        });
    }
    final Preference restorePurchases = findPreference("pref_restore_purchases");
    if (ShuttleUtils.isAmazonBuild() || ShuttleUtils.isUpgraded()) {
        PreferenceGroup preferenceGroup = (PreferenceGroup) findPreference("support_group");
        if (preferenceGroup != null) {
            preferenceGroup.removePreference(restorePurchases);
        }
    } else if (restorePurchases != null) {
        restorePurchases.setOnPreferenceClickListener(preference -> {
            ((SettingsActivity) getActivity()).restorePurchases();
            return true;
        });
    }
    final Preference versionPreference = findPreference("pref_version");
    if (versionPreference != null) {
        versionPreference.setSummary("Shuttle Music Player " + BuildConfig.VERSION_NAME + (ShuttleUtils.isUpgraded() ? " (Upgraded)" : " (Free)"));
    }
    final Preference faqPreference = findPreference("pref_faq");
    if (faqPreference != null) {
        faqPreference.setOnPreferenceClickListener(preference -> {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("http://www.shuttlemusicplayer.com/#faq"));
            startActivity(intent);
            return true;
        });
    }
    final Preference gplusPreference = findPreference("pref_gplus");
    if (gplusPreference != null) {
        gplusPreference.setOnPreferenceClickListener(preference -> {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/communities/112365043563095486408"));
            startActivity(intent);
            return true;
        });
    }
    final Preference ratePreference = findPreference("pref_rate");
    if (ratePreference != null) {
        ratePreference.setOnPreferenceClickListener(preference -> {
            final String appPackageName = getActivity().getPackageName();
            ShuttleUtils.openShuttleLink(getActivity(), appPackageName);
            SettingsManager.getInstance().setHasRated();
            return true;
        });
    }
    final CheckBoxPreference openOnClickPreference = (CheckBoxPreference) findPreference("pref_open_now_playing_on_click");
    if (openOnClickPreference != null) {
        if (!ShuttleUtils.isTablet()) {
            PreferenceGroup preferenceGroup = (PreferenceGroup) findPreference("display_group");
            if (preferenceGroup != null) {
                preferenceGroup.removePreference(openOnClickPreference);
            }
        }
    }
    if (!ShuttleUtils.hasLollipop()) {
        PreferenceScreen preferenceScreen = getPreferenceScreen();
        if (preferenceScreen != null) {
            Preference notificationPreference = preferenceScreen.findPreference("pref_category_notifications");
            if (notificationPreference != null) {
                preferenceScreen.removePreference(notificationPreference);
            }
        }
    }
}
Also used : R(com.simplecity.amp_library.R) Bundle(android.os.Bundle) Uri(android.net.Uri) DrawableUtils(com.simplecity.amp_library.utils.DrawableUtils) Dialog(android.app.Dialog) Intent(android.content.Intent) CheckBoxPreference(android.preference.CheckBoxPreference) CategoryItem(com.simplecity.amp_library.model.CategoryItem) ArtworkDownloadService(com.simplecity.amp_library.services.ArtworkDownloadService) PreferenceScreen(android.preference.PreferenceScreen) Drawable(android.graphics.drawable.Drawable) AnalyticsManager(com.simplecity.amp_library.utils.AnalyticsManager) PreferenceFragment(android.support.v4.preference.PreferenceFragment) ThemeUtils(com.simplecity.amp_library.utils.ThemeUtils) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) Toast(android.widget.Toast) View(android.view.View) ResourceUtils(com.simplecity.amp_library.utils.ResourceUtils) SystemBarTintManager(com.readystatesoftware.systembartint.SystemBarTintManager) Build(android.os.Build) PreferenceManager(android.preference.PreferenceManager) WebView(android.webkit.WebView) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) TargetApi(android.annotation.TargetApi) TabsAdapter(com.simplecity.amp_library.ui.adapters.TabsAdapter) ItemTouchHelperCallback(com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback) InsetDrawable(android.graphics.drawable.InsetDrawable) AsyncTask(android.os.AsyncTask) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) MainActivity(com.simplecity.amp_library.ui.activities.MainActivity) IntentCompat(android.support.v4.content.IntentCompat) ColorPalette(com.simplecity.amp_library.utils.ColorPalette) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BuildConfig(com.simplecity.amp_library.BuildConfig) ViewGroup(android.view.ViewGroup) WhitelistHelper(com.simplecity.amp_library.sql.databases.WhitelistHelper) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) DialogUtils(com.simplecity.amp_library.utils.DialogUtils) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) RecyclerView(android.support.v7.widget.RecyclerView) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) BlacklistHelper(com.simplecity.amp_library.sql.databases.BlacklistHelper) PreferenceGroup(android.preference.PreferenceGroup) Glide(com.bumptech.glide.Glide) SharedPreferences(android.content.SharedPreferences) Preference(android.preference.Preference) SettingsActivity(com.simplecity.amp_library.ui.activities.SettingsActivity) PreferenceScreen(android.preference.PreferenceScreen) CheckBoxPreference(android.preference.CheckBoxPreference) Intent(android.content.Intent) SystemBarTintManager(com.readystatesoftware.systembartint.SystemBarTintManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) TabsAdapter(com.simplecity.amp_library.ui.adapters.TabsAdapter) View(android.view.View) WebView(android.webkit.WebView) RecyclerView(android.support.v7.widget.RecyclerView) ItemTouchHelperCallback(com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) RecyclerView(android.support.v7.widget.RecyclerView) ComponentName(android.content.ComponentName) PreferenceGroup(android.preference.PreferenceGroup) WebView(android.webkit.WebView) SettingsActivity(com.simplecity.amp_library.ui.activities.SettingsActivity) CategoryItem(com.simplecity.amp_library.model.CategoryItem)

Example 2 with ItemTouchHelperCallback

use of com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback 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 3 with ItemTouchHelperCallback

use of com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback in project Shuttle by timusus.

the class QueueFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_queue, container, false);
    header = rootView.findViewById(R.id.header);
    if (ShuttleUtils.isLandscape() || ShuttleUtils.isTablet()) {
        header.setVisibility(View.GONE);
    } else {
        header.setVisibility(View.VISIBLE);
    }
    lineTwo = (TextView) rootView.findViewById(R.id.line2);
    recyclerView = (ScrollBlockingRecyclerView) rootView.findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    recyclerView.setRecyclerListener(this);
    recyclerView.setAdapter(songAdapter);
    recyclerView.setStateChangeListener(new OnFastScrollStateChangeListener() {

        @Override
        public void onFastScrollStart() {
            recyclerView.setBlockScroll(false);
        }

        @Override
        public void onFastScrollStop() {
            recyclerView.setBlockScroll(true);
        }
    });
    itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback((fromPosition, toPosition) -> {
        songAdapter.moveItem(fromPosition, toPosition);
    }, (fromPosition, toPosition) -> {
        MusicUtils.moveQueueItem(fromPosition, toPosition);
        recyclerView.setBlockScroll(true);
    }, () -> {
        //We've finished our drag event. Allow the sliding up panel to intercept touch events
        recyclerView.setBlockScroll(true);
    }));
    itemTouchHelper.attachToRecyclerView(recyclerView);
    themeUIComponents();
    updateTrackInfo();
    return rootView;
}
Also used : ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) OnFastScrollStateChangeListener(com.simplecityapps.recyclerview_fastscroll.interfaces.OnFastScrollStateChangeListener) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ItemTouchHelperCallback(com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)3 ItemTouchHelperCallback (com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback)3 Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 PreferenceManager (android.preference.PreferenceManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 Toast (android.widget.Toast)2 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 TargetApi (android.annotation.TargetApi)1 Dialog (android.app.Dialog)1 BroadcastReceiver (android.content.BroadcastReceiver)1 ComponentName (android.content.ComponentName)1 ContentUris (android.content.ContentUris)1