Search in sources :

Example 1 with CategoryItem

use of com.simplecity.amp_library.model.CategoryItem 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 CategoryItem

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

the class TabChooserDialog method getDialog.

public static MaterialDialog getDialog(Activity activity) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(activity);
    ViewModelAdapter adapter = new ViewModelAdapter();
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback(adapter::moveItem, (fromPosition, toPosition) -> {
    }, () -> {
    }));
    TabViewModel.Listener listener = new TabViewModel.Listener() {

        @Override
        public void onStartDrag(TabViewModel.ViewHolder holder) {
            itemTouchHelper.startDrag(holder);
        }

        @Override
        public void onFolderChecked(TabViewModel tabViewModel, TabViewModel.ViewHolder viewHolder) {
            if (!ShuttleUtils.isUpgraded()) {
                viewHolder.checkBox.setChecked(false);
                tabViewModel.categoryItem.isChecked = false;
                UpgradeDialog.getUpgradeDialog(activity).show();
            }
        }
    };
    List<ViewModel> items = Stream.of(CategoryItem.getCategoryItems(sharedPreferences)).map(categoryItem -> {
        TabViewModel tabViewModel = new TabViewModel(categoryItem);
        tabViewModel.setListener(listener);
        return tabViewModel;
    }).collect(Collectors.toList());
    adapter.setItems(items);
    RecyclerView recyclerView = new RecyclerView(activity);
    recyclerView.setLayoutManager(new LinearLayoutManager(activity));
    recyclerView.setAdapter(adapter);
    itemTouchHelper.attachToRecyclerView(recyclerView);
    return new MaterialDialog.Builder(activity).title(R.string.pref_title_choose_tabs).customView(recyclerView, false).positiveText(R.string.button_done).onPositive((dialog, which) -> {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        Stream.of(adapter.items).indexed().forEach(viewModelIntPair -> {
            ((TabViewModel) viewModelIntPair.getSecond()).categoryItem.sortOrder = viewModelIntPair.getFirst();
            ((TabViewModel) viewModelIntPair.getSecond()).categoryItem.savePrefs(editor);
        });
        LocalBroadcastManager.getInstance(activity).sendBroadcast(new Intent(LibraryController.EVENT_TABS_CHANGED));
    }).negativeText(R.string.close).build();
}
Also used : R(com.simplecity.amp_library.R) ItemTouchHelperCallback(com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback) Collectors(com.annimon.stream.Collectors) Stream(com.annimon.stream.Stream) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) CategoryItem(com.simplecity.amp_library.model.CategoryItem) TabViewModel(com.simplecity.amp_library.ui.modelviews.TabViewModel) RecyclerView(android.support.v7.widget.RecyclerView) List(java.util.List) SharedPreferences(android.content.SharedPreferences) LibraryController(com.simplecity.amp_library.ui.fragments.LibraryController) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) PreferenceManager(android.preference.PreferenceManager) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Activity(android.app.Activity) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) TabViewModel(com.simplecity.amp_library.ui.modelviews.TabViewModel) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ItemTouchHelperCallback(com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) TabViewModel(com.simplecity.amp_library.ui.modelviews.TabViewModel) RecyclerView(android.support.v7.widget.RecyclerView) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter)

Example 3 with CategoryItem

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

the class LibraryController method setupViewPager.

private void setupViewPager() {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
    CategoryItem.getCategoryItems(sharedPreferences);
    if (pagerAdapter != null && refreshPagerAdapter) {
        pagerAdapter.removeAllChildFragments();
        refreshPagerAdapter = false;
        pager.setAdapter(null);
    }
    int defaultPage = 1;
    pagerAdapter = new PagerAdapter(getChildFragmentManager());
    List<CategoryItem> categoryItems = Stream.of(CategoryItem.getCategoryItems(sharedPreferences)).filter(categoryItem -> categoryItem.isChecked).toList();
    int defaultPageType = settingsManager.getDefaultPageType();
    for (int i = 0; i < categoryItems.size(); i++) {
        CategoryItem categoryItem = categoryItems.get(i);
        pagerAdapter.addFragment(categoryItem.getFragment(getContext()));
        if (categoryItem.type == defaultPageType) {
            defaultPage = i;
        }
    }
    int currentPage = Math.min(defaultPage, pagerAdapter.getCount());
    pager.setAdapter(pagerAdapter);
    pager.setOffscreenPageLimit(pagerAdapter.getCount() - 1);
    pager.setCurrentItem(currentPage);
    slidingTabLayout.setupWithViewPager(pager);
    pager.postDelayed(() -> {
        if (pager != null) {
            new RatingSnackbar(settingsManager, analyticsManager).show(pager, () -> {
                ShuttleUtils.openShuttleLink(getActivity(), getActivity().getPackageName(), getActivity().getPackageManager());
                return Unit.INSTANCE;
            });
        }
    }, 1000);
}
Also used : R(com.simplecity.amp_library.R) Genre(com.simplecity.amp_library.model.Genre) NavigationEventRelay(com.simplecity.amp_library.ui.screens.drawer.NavigationEventRelay) Bundle(android.os.Bundle) PlaylistDetailFragment(com.simplecity.amp_library.ui.screens.playlist.detail.PlaylistDetailFragment) AlbumDetailFragment(com.simplecity.amp_library.ui.screens.album.detail.AlbumDetailFragment) Rx.onErrorLogAndRethrow(com.afollestad.aesthetic.Rx.onErrorLogAndRethrow) CategoryItem(com.simplecity.amp_library.model.CategoryItem) AnalyticsManager(com.simplecity.amp_library.utils.AnalyticsManager) PagerAdapter(com.simplecity.amp_library.ui.adapters.PagerAdapter) BindView(butterknife.BindView) Aesthetic(com.afollestad.aesthetic.Aesthetic) View(android.view.View) ViewCompat(android.support.v4.view.ViewCompat) Transition(android.transition.Transition) PreferenceManager(android.preference.PreferenceManager) Unbinder(butterknife.Unbinder) Playlist(com.simplecity.amp_library.model.Playlist) IntentFilter(android.content.IntentFilter) Fragment(android.support.v4.app.Fragment) FragmentInfo(test.com.androidnavigation.fragment.FragmentInfo) CastManager(com.simplecity.amp_library.cast.CastManager) AlbumListFragment(com.simplecity.amp_library.ui.screens.album.list.AlbumListFragment) RxBroadcast(com.cantrowitz.rxbroadcast.RxBroadcast) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) BaseFragment(com.simplecity.amp_library.ui.common.BaseFragment) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) Unit(kotlin.Unit) SearchFragment(com.simplecity.amp_library.ui.screens.search.SearchFragment) ContextualToolbarHost(com.simplecity.amp_library.ui.views.ContextualToolbarHost) Nullable(android.support.annotation.Nullable) AppBarLayout(android.support.design.widget.AppBarLayout) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) ButterKnife(butterknife.ButterKnife) ContextualToolbar(com.simplecity.amp_library.ui.views.ContextualToolbar) ViewPager(android.support.v4.view.ViewPager) NonNull(android.support.annotation.NonNull) ArtistDetailFragment(com.simplecity.amp_library.ui.screens.artist.detail.ArtistDetailFragment) RatingSnackbar(com.simplecity.amp_library.ui.views.RatingSnackbar) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) TabLayout(android.support.design.widget.TabLayout) Inject(javax.inject.Inject) MultiSheetEventRelay(com.simplecity.amp_library.ui.views.multisheet.MultiSheetEventRelay) GenreDetailFragment(com.simplecity.amp_library.ui.screens.genre.detail.GenreDetailFragment) GenreListFragment(com.simplecity.amp_library.ui.screens.genre.list.GenreListFragment) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) ViewBackgroundAction(com.afollestad.aesthetic.ViewBackgroundAction) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) Rx.distinctToMainThread(com.afollestad.aesthetic.Rx.distinctToMainThread) CastButtonFactory(com.google.android.gms.cast.framework.CastButtonFactory) PlaylistListFragment(com.simplecity.amp_library.ui.screens.playlist.list.PlaylistListFragment) MultiSheetView(com.simplecity.multisheetview.ui.view.MultiSheetView) LayoutInflater(android.view.LayoutInflater) AndroidSupportInjection(dagger.android.support.AndroidSupportInjection) ToolbarListener(com.simplecity.amp_library.ui.common.ToolbarListener) SuggestedFragment(com.simplecity.amp_library.ui.screens.suggested.SuggestedFragment) SharedPreferences(android.content.SharedPreferences) Toolbar(android.support.v7.widget.Toolbar) Pair(android.support.v4.util.Pair) TransitionInflater(android.transition.TransitionInflater) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) AlbumArtistListFragment(com.simplecity.amp_library.ui.screens.artist.list.AlbumArtistListFragment) SharedPreferences(android.content.SharedPreferences) PagerAdapter(com.simplecity.amp_library.ui.adapters.PagerAdapter) CategoryItem(com.simplecity.amp_library.model.CategoryItem) RatingSnackbar(com.simplecity.amp_library.ui.views.RatingSnackbar)

Example 4 with CategoryItem

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

the class TabsAdapter method updatePreferences.

public void updatePreferences() {
    String genresTitle = mContext.getString(R.string.genres_title);
    String suggestedTitle = mContext.getString(R.string.suggested_title);
    String artistsTitle = mContext.getString(R.string.artists_title);
    String albumsTitle = mContext.getString(R.string.albums_title);
    String songsTitle = mContext.getString(R.string.tracks_title);
    String foldersTitle = mContext.getString(R.string.folders_title);
    String playlistsTitle = mContext.getString(R.string.playlists_title);
    SharedPreferences.Editor editor = mPrefs.edit();
    for (int i = 0, length = getItemCount(); i < length; i++) {
        CategoryItem item = ((TabView) items.get(i)).categoryItem;
        if (item.title.equals(genresTitle)) {
            editor.putInt(GENRES_ORDER, i);
            editor.putBoolean(SHOW_GENRES, item.checked);
        } else if (item.title.equals(suggestedTitle)) {
            editor.putInt(SUGGESTED_ORDER, i);
            editor.putBoolean(SHOW_SUGGESTED, item.checked);
        } else if (item.title.equals(artistsTitle)) {
            editor.putInt(ARTISTS_ORDER, i);
            editor.putBoolean(SHOW_ARTISTS, item.checked);
        } else if (item.title.equals(albumsTitle)) {
            editor.putInt(ALBUMS_ORDER, i);
            editor.putBoolean(SHOW_ALBUMS, item.checked);
        } else if (item.title.equals(songsTitle)) {
            editor.putInt(SONGS_ORDER, i);
            editor.putBoolean(SHOW_SONGS, item.checked);
        } else if (item.title.equals(foldersTitle)) {
            editor.putInt(FOLDERS_ORDER, i);
            editor.putBoolean(SHOW_FOLDERS, item.checked);
        } else if (item.title.equals(playlistsTitle)) {
            editor.putInt(PLAYLISTS_ORDER, i);
            editor.putBoolean(SHOW_PLAYLISTS, item.checked);
        }
        editor.apply();
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) TabView(com.simplecity.amp_library.ui.modelviews.TabView) CategoryItem(com.simplecity.amp_library.model.CategoryItem)

Example 5 with CategoryItem

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

the class LibraryController method setupViewPager.

private void setupViewPager() {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
    CategoryItem.getCategoryItems(sharedPreferences);
    if (pagerAdapter != null && refreshPagerAdapter) {
        pagerAdapter.removeAllChildFragments();
        refreshPagerAdapter = false;
        pager.setAdapter(null);
    }
    int defaultPage = 1;
    pagerAdapter = new PagerAdapter(getChildFragmentManager());
    List<CategoryItem> categoryItems = Stream.of(CategoryItem.getCategoryItems(sharedPreferences)).filter(categoryItem -> categoryItem.isChecked).toList();
    int defaultPageType = SettingsManager.getInstance().getDefaultPageType();
    for (int i = 0; i < categoryItems.size(); i++) {
        CategoryItem categoryItem = categoryItems.get(i);
        pagerAdapter.addFragment(categoryItem.getFragment(getContext()));
        if (categoryItem.type == defaultPageType) {
            defaultPage = i;
        }
    }
    int currentPage = Math.min(defaultPage, pagerAdapter.getCount());
    pager.setAdapter(pagerAdapter);
    pager.setOffscreenPageLimit(pagerAdapter.getCount() - 1);
    pager.setCurrentItem(currentPage);
    slidingTabLayout.setupWithViewPager(pager);
    pager.postDelayed(() -> {
        if (pager != null) {
            DialogUtils.showRateSnackbar(getActivity(), pager);
        }
    }, 1000);
}
Also used : R(com.simplecity.amp_library.R) Genre(com.simplecity.amp_library.model.Genre) BaseDetailFragment(com.simplecity.amp_library.ui.detail.BaseDetailFragment) Bundle(android.os.Bundle) Rx.onErrorLogAndRethrow(com.afollestad.aesthetic.Rx.onErrorLogAndRethrow) CategoryItem(com.simplecity.amp_library.model.CategoryItem) PagerAdapter(com.simplecity.amp_library.ui.adapters.PagerAdapter) BindView(butterknife.BindView) Aesthetic(com.afollestad.aesthetic.Aesthetic) ToolbarListener(com.simplecity.amp_library.ui.activities.ToolbarListener) View(android.view.View) ViewCompat(android.support.v4.view.ViewCompat) Transition(android.transition.Transition) PreferenceManager(android.preference.PreferenceManager) Unbinder(butterknife.Unbinder) Playlist(com.simplecity.amp_library.model.Playlist) IntentFilter(android.content.IntentFilter) FragmentInfo(test.com.androidnavigation.fragment.FragmentInfo) RxBroadcast(com.cantrowitz.rxbroadcast.RxBroadcast) GenreDetailFragment(com.simplecity.amp_library.ui.detail.GenreDetailFragment) 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) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) ContextualToolbarHost(com.simplecity.amp_library.ui.views.ContextualToolbarHost) Nullable(android.support.annotation.Nullable) ArtistDetailFragment(com.simplecity.amp_library.ui.detail.ArtistDetailFragment) AppBarLayout(android.support.design.widget.AppBarLayout) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) ContextualToolbar(com.simplecity.amp_library.ui.views.ContextualToolbar) ButterKnife(butterknife.ButterKnife) AlbumDetailFragment(com.simplecity.amp_library.ui.detail.AlbumDetailFragment) ViewPager(android.support.v4.view.ViewPager) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) TabLayout(android.support.design.widget.TabLayout) Inject(javax.inject.Inject) MultiSheetEventRelay(com.simplecity.amp_library.ui.views.multisheet.MultiSheetEventRelay) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) ViewBackgroundAction(com.afollestad.aesthetic.ViewBackgroundAction) Rx.distinctToMainThread(com.afollestad.aesthetic.Rx.distinctToMainThread) MultiSheetView(com.simplecity.multisheetview.ui.view.MultiSheetView) LayoutInflater(android.view.LayoutInflater) NavigationEventRelay(com.simplecity.amp_library.ui.drawer.NavigationEventRelay) DialogUtils(com.simplecity.amp_library.utils.DialogUtils) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) SearchFragment(com.simplecity.amp_library.search.SearchFragment) SharedPreferences(android.content.SharedPreferences) Toolbar(android.support.v7.widget.Toolbar) Pair(android.support.v4.util.Pair) TransitionInflater(android.transition.TransitionInflater) PlaylistDetailFragment(com.simplecity.amp_library.ui.detail.PlaylistDetailFragment) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) SharedPreferences(android.content.SharedPreferences) PagerAdapter(com.simplecity.amp_library.ui.adapters.PagerAdapter) CategoryItem(com.simplecity.amp_library.model.CategoryItem)

Aggregations

SharedPreferences (android.content.SharedPreferences)6 CategoryItem (com.simplecity.amp_library.model.CategoryItem)6 PreferenceManager (android.preference.PreferenceManager)5 R (com.simplecity.amp_library.R)5 Stream (com.annimon.stream.Stream)4 SettingsManager (com.simplecity.amp_library.utils.SettingsManager)4 List (java.util.List)4 Intent (android.content.Intent)3 Bundle (android.os.Bundle)3 LayoutInflater (android.view.LayoutInflater)3 View (android.view.View)3 ViewGroup (android.view.ViewGroup)3 ShuttleUtils (com.simplecity.amp_library.utils.ShuttleUtils)3 IntentFilter (android.content.IntentFilter)2 Uri (android.net.Uri)2 Nullable (android.support.annotation.Nullable)2 AppBarLayout (android.support.design.widget.AppBarLayout)2 TabLayout (android.support.design.widget.TabLayout)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2