Search in sources :

Example 1 with IntPair

use of com.annimon.stream.IntPair 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

Context (android.content.Context)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Uri (android.net.Uri)1 PreferenceManager (android.preference.PreferenceManager)1 ContextCompat (android.support.v4.content.ContextCompat)1 Aesthetic (com.afollestad.aesthetic.Aesthetic)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 ColorChooserDialog (com.afollestad.materialdialogs.color.ColorChooserDialog)1 IntPair (com.annimon.stream.IntPair)1 Stream (com.annimon.stream.Stream)1 Glide (com.bumptech.glide.Glide)1 R (com.simplecity.amp_library.R)1 ShuttleApplication (com.simplecity.amp_library.ShuttleApplication)1 BillingManager (com.simplecity.amp_library.billing.BillingManager)1 CategoryItem (com.simplecity.amp_library.model.CategoryItem)1 ArtworkDownloadService (com.simplecity.amp_library.services.ArtworkDownloadService)1 PurchasePresenter (com.simplecity.amp_library.ui.common.PurchasePresenter)1 AnalyticsManager (com.simplecity.amp_library.utils.AnalyticsManager)1 ColorPalette (com.simplecity.amp_library.utils.ColorPalette)1