Search in sources :

Example 6 with CategoryItem

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

the class SettingsPresenter method chooseDefaultPageClicked.

public void chooseDefaultPageClicked(Context context) {
    SettingsView settingsView = getView();
    if (settingsView != null) {
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        List<CategoryItem> categoryItems = Stream.of(CategoryItem.getCategoryItems(sharedPreferences)).filter(categoryItem -> categoryItem.isChecked).toList();
        int defaultPageType = settingsManager.getDefaultPageType();
        int defaultPage = Math.min(Stream.of(categoryItems).indexed().filter(categoryItemIntPair -> categoryItemIntPair.getSecond().type == defaultPageType).map(IntPair::getFirst).findFirst().orElse(1), categoryItems.size());
        settingsView.showDefaultPageDialog(new MaterialDialog.Builder(context).title(R.string.pref_title_default_page).items(Stream.of(categoryItems).map(categoryItem -> context.getString(categoryItem.getTitleResId())).toList()).itemsCallbackSingleChoice(defaultPage, (dialog, itemView, which, text) -> {
            settingsManager.setDefaultPageType(categoryItems.get(which).type);
            return false;
        }).build());
    }
}
Also used : R(com.simplecity.amp_library.R) Context(android.content.Context) Stream(com.annimon.stream.Stream) Completable(io.reactivex.Completable) Uri(android.net.Uri) Intent(android.content.Intent) CategoryItem(com.simplecity.amp_library.model.CategoryItem) ArtworkDownloadService(com.simplecity.amp_library.services.ArtworkDownloadService) AnalyticsManager(com.simplecity.amp_library.utils.AnalyticsManager) Inject(javax.inject.Inject) BillingManager(com.simplecity.amp_library.billing.BillingManager) Aesthetic(com.afollestad.aesthetic.Aesthetic) PurchasePresenter(com.simplecity.amp_library.ui.common.PurchasePresenter) IntPair(com.annimon.stream.IntPair) Schedulers(io.reactivex.schedulers.Schedulers) PreferenceManager(android.preference.PreferenceManager) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) ContextCompat(android.support.v4.content.ContextCompat) ColorPalette(com.simplecity.amp_library.utils.ColorPalette) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) List(java.util.List) Glide(com.bumptech.glide.Glide) SharedPreferences(android.content.SharedPreferences) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ColorChooserDialog(com.afollestad.materialdialogs.color.ColorChooserDialog) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SharedPreferences(android.content.SharedPreferences) 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