Search in sources :

Example 11 with Color

use of android.graphics.Color in project Shuttle by timusus.

the class QueueFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_queue, container, false);
    unbinder = ButterKnife.bind(this, rootView);
    toolbar.setNavigationOnClickListener(v -> getActivity().onBackPressed());
    toolbar.inflateMenu(R.menu.menu_queue);
    SubMenu sub = toolbar.getMenu().addSubMenu(0, MusicUtils.Defs.ADD_TO_PLAYLIST, 1, R.string.save_as_playlist);
    disposables.add(PlaylistUtils.createUpdatingPlaylistMenu(sub).subscribe());
    toolbar.setOnMenuItemClickListener(toolbarListener);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    recyclerView.setRecyclerListener(new RecyclerListener());
    recyclerView.setAdapter(adapter);
    itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback((fromPosition, toPosition) -> adapter.moveItem(fromPosition, toPosition), MusicUtils::moveQueueItem, () -> {
    // Nothing to do
    }));
    itemTouchHelper.attachToRecyclerView(recyclerView);
    disposables.add(Aesthetic.get(getContext()).colorPrimary().subscribe(color -> {
        boolean isLight = Util.isColorLight(color);
        lineOne.setTextColor(isLight ? Color.BLACK : Color.WHITE);
        lineTwo.setTextColor(isLight ? Color.BLACK : Color.WHITE);
    }));
    // In landscape, we need to adjust the status bar's translation depending on the slide offset of the sheet
    if (ShuttleUtils.isLandscape()) {
        statusBarView.setTranslationY(ResourceUtils.toPixels(16));
        disposables.add(multiSheetSlideEventRelay.getEvents().filter(multiSheetEvent -> multiSheetEvent.sheet == MultiSheetView.Sheet.SECOND).filter(multiSheetEvent -> multiSheetEvent.slideOffset >= 0).subscribe(multiSheetEvent -> {
            statusBarView.setTranslationY((1 - multiSheetEvent.slideOffset) * ResourceUtils.toPixels(16));
        }));
    }
    setupContextualToolbar();
    queuePresenter = new QueuePresenter(requestManager, cabHelper);
    return rootView;
}
Also used : ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) R(com.simplecity.amp_library.R) CompletionListUpdateCallbackAdapter(com.simplecityapps.recycler_adapter.adapter.CompletionListUpdateCallbackAdapter) Bundle(android.os.Bundle) SongView(com.simplecity.amp_library.ui.modelviews.SongView) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) BindView(butterknife.BindView) Song(com.simplecity.amp_library.model.Song) Aesthetic(com.afollestad.aesthetic.Aesthetic) RequestManager(com.bumptech.glide.RequestManager) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) View(android.view.View) ResourceUtils(com.simplecity.amp_library.utils.ResourceUtils) Unbinder(butterknife.Unbinder) ItemTouchHelperCallback(com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback) ContextualToolbarHelper(com.simplecity.amp_library.utils.ContextualToolbarHelper) QueueView(com.simplecity.amp_library.ui.views.QueueView) SubMenu(android.view.SubMenu) ViewGroup(android.view.ViewGroup) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) TextView(android.widget.TextView) FragmentModule(com.simplecity.amp_library.dagger.module.FragmentModule) PermissionUtils(com.simplecity.amp_library.utils.PermissionUtils) Util(com.afollestad.aesthetic.Util) PlayerViewAdapter(com.simplecity.amp_library.ui.views.PlayerViewAdapter) Nullable(android.support.annotation.Nullable) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ContextualToolbar(com.simplecity.amp_library.ui.views.ContextualToolbar) RecyclerListener(com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener) ButterKnife(butterknife.ButterKnife) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter) SelectableViewModel(com.simplecity.amp_library.ui.modelviews.SelectableViewModel) Single(io.reactivex.Single) MenuItem(android.view.MenuItem) Inject(javax.inject.Inject) Toast(android.widget.Toast) UpgradeDialog(com.simplecity.amp_library.ui.dialog.UpgradeDialog) DeleteDialog(com.simplecity.amp_library.ui.dialog.DeleteDialog) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) TaggerDialog(com.simplecity.amp_library.tagger.TaggerDialog) MultiSheetView(com.simplecity.multisheetview.ui.view.MultiSheetView) LayoutInflater(android.view.LayoutInflater) ThemedStatusBarView(com.simplecity.amp_library.ui.views.ThemedStatusBarView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Color(android.graphics.Color) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) MultiSheetSlideEventRelay(com.simplecity.amp_library.ui.views.multisheet.MultiSheetSlideEventRelay) Toolbar(android.support.v7.widget.Toolbar) PlayerPresenter(com.simplecity.amp_library.ui.presenters.PlayerPresenter) QueuePresenter(com.simplecity.amp_library.ui.presenters.QueuePresenter) Callback(com.simplecity.amp_library.utils.ContextualToolbarHelper.Callback) QueuePresenter(com.simplecity.amp_library.ui.presenters.QueuePresenter) RecyclerListener(com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener) SubMenu(android.view.SubMenu) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SongView(com.simplecity.amp_library.ui.modelviews.SongView) BindView(butterknife.BindView) View(android.view.View) QueueView(com.simplecity.amp_library.ui.views.QueueView) TextView(android.widget.TextView) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) MultiSheetView(com.simplecity.multisheetview.ui.view.MultiSheetView) ThemedStatusBarView(com.simplecity.amp_library.ui.views.ThemedStatusBarView) ItemTouchHelperCallback(com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback)

Example 12 with Color

use of android.graphics.Color in project Tusky by tuskyapp.

the class AccountActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_account);
    avatar = findViewById(R.id.account_avatar);
    header = findViewById(R.id.account_header);
    floatingBtn = findViewById(R.id.floating_btn);
    followBtn = findViewById(R.id.follow_btn);
    followsYouView = findViewById(R.id.account_follows_you);
    tabLayout = findViewById(R.id.tab_layout);
    accountLockedView = findViewById(R.id.account_locked);
    container = findViewById(R.id.activity_account);
    followersTextView = findViewById(R.id.followers_tv);
    followingTextView = findViewById(R.id.following_tv);
    statusesTextView = findViewById(R.id.statuses_btn);
    if (savedInstanceState != null) {
        accountId = savedInstanceState.getString("accountId");
        followState = (FollowState) savedInstanceState.getSerializable("followState");
        blocking = savedInstanceState.getBoolean("blocking");
        muting = savedInstanceState.getBoolean("muting");
    } else {
        Intent intent = getIntent();
        accountId = intent.getStringExtra("id");
        followState = FollowState.NOT_FOLLOWING;
        blocking = false;
        muting = false;
    }
    loadedAccount = null;
    // Setup the toolbar.
    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(null);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
    }
    hideFab = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("fabHide", false);
    // Add a listener to change the toolbar icon color when it enters/exits its collapsed state.
    AppBarLayout appBarLayout = findViewById(R.id.account_app_bar_layout);
    final CollapsingToolbarLayout collapsingToolbar = findViewById(R.id.collapsing_toolbar);
    appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {

        @AttrRes
        int priorAttribute = R.attr.account_toolbar_icon_tint_uncollapsed;

        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            @AttrRes int attribute;
            if (collapsingToolbar.getHeight() + verticalOffset < 2 * ViewCompat.getMinimumHeight(collapsingToolbar)) {
                toolbar.setTitleTextColor(ThemeUtils.getColor(AccountActivity.this, android.R.attr.textColorPrimary));
                toolbar.setSubtitleTextColor(ThemeUtils.getColor(AccountActivity.this, android.R.attr.textColorSecondary));
                attribute = R.attr.account_toolbar_icon_tint_collapsed;
            } else {
                toolbar.setTitleTextColor(Color.TRANSPARENT);
                toolbar.setSubtitleTextColor(Color.TRANSPARENT);
                attribute = R.attr.account_toolbar_icon_tint_uncollapsed;
            }
            if (attribute != priorAttribute) {
                priorAttribute = attribute;
                Context context = toolbar.getContext();
                ThemeUtils.setDrawableTint(context, toolbar.getNavigationIcon(), attribute);
                ThemeUtils.setDrawableTint(context, toolbar.getOverflowIcon(), attribute);
            }
            if (floatingBtn != null && hideFab && !isSelf && !blocking) {
                if (verticalOffset > oldOffset) {
                    floatingBtn.show();
                }
                if (verticalOffset < oldOffset) {
                    floatingBtn.hide();
                }
            }
            oldOffset = verticalOffset;
        }
    });
    // Initialise the default UI states.
    floatingBtn.hide();
    followBtn.setVisibility(View.GONE);
    followsYouView.setVisibility(View.GONE);
    // Obtain information to fill out the profile.
    obtainAccount();
    AccountEntity activeAccount = TuskyApplication.getInstance(this).getServiceLocator().get(AccountManager.class).getActiveAccount();
    if (accountId.equals(activeAccount.getAccountId())) {
        isSelf = true;
    } else {
        isSelf = false;
        obtainRelationships();
    }
    // Setup the tabs and timeline pager.
    AccountPagerAdapter adapter = new AccountPagerAdapter(getSupportFragmentManager(), accountId);
    String[] pageTitles = { getString(R.string.title_statuses), getString(R.string.title_media) };
    adapter.setPageTitles(pageTitles);
    final ViewPager viewPager = findViewById(R.id.pager);
    int pageMargin = getResources().getDimensionPixelSize(R.dimen.tab_page_margin);
    viewPager.setPageMargin(pageMargin);
    Drawable pageMarginDrawable = ThemeUtils.getDrawable(this, R.attr.tab_page_margin_drawable, R.drawable.tab_page_margin_dark);
    viewPager.setPageMarginDrawable(pageMarginDrawable);
    viewPager.setAdapter(adapter);
    viewPager.setOffscreenPageLimit(0);
    tabLayout.setupWithViewPager(viewPager);
    View.OnClickListener accountListClickListener = v -> {
        AccountListActivity.Type type;
        switch(v.getId()) {
            case R.id.followers_tv:
                type = AccountListActivity.Type.FOLLOWERS;
                break;
            case R.id.following_tv:
                type = AccountListActivity.Type.FOLLOWING;
                break;
            default:
                throw new AssertionError();
        }
        Intent intent = AccountListActivity.newIntent(AccountActivity.this, type, accountId);
        startActivity(intent);
    };
    followersTextView.setOnClickListener(accountListClickListener);
    followingTextView.setOnClickListener(accountListClickListener);
    statusesTextView.setOnClickListener(v -> {
        // Make nice ripple effect on tab
        // noinspection ConstantConditions
        tabLayout.getTabAt(0).select();
        final View poorTabView = ((ViewGroup) tabLayout.getChildAt(0)).getChildAt(0);
        poorTabView.setPressed(true);
        tabLayout.postDelayed(() -> poorTabView.setPressed(false), 300);
    });
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) ImageView(android.widget.ImageView) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) Drawable(android.graphics.drawable.Drawable) Picasso(com.squareup.picasso.Picasso) Assert(com.keylesspalace.tusky.util.Assert) ActionButtonActivity(com.keylesspalace.tusky.interfaces.ActionButtonActivity) View(android.view.View) Button(android.widget.Button) AttrRes(android.support.annotation.AttrRes) ViewCompat(android.support.v4.view.ViewCompat) Account(com.keylesspalace.tusky.entity.Account) PreferenceManager(android.preference.PreferenceManager) DispatchingAndroidInjector(dagger.android.DispatchingAndroidInjector) Log(android.util.Log) FloatingActionButton(android.support.design.widget.FloatingActionButton) AndroidInjector(dagger.android.AndroidInjector) Fragment(android.support.v4.app.Fragment) AccountPagerAdapter(com.keylesspalace.tusky.pager.AccountPagerAdapter) Relationship(com.keylesspalace.tusky.entity.Relationship) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) List(java.util.List) TextView(android.widget.TextView) Nullable(android.support.annotation.Nullable) Snackbar(android.support.design.widget.Snackbar) HasSupportFragmentInjector(dagger.android.support.HasSupportFragmentInjector) Call(retrofit2.Call) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) Context(android.content.Context) AppBarLayout(android.support.design.widget.AppBarLayout) ViewPager(android.support.v4.view.ViewPager) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) Response(retrofit2.Response) NumberFormat(java.text.NumberFormat) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) TabLayout(android.support.design.widget.TabLayout) Inject(javax.inject.Inject) Menu(android.view.Menu) ActionBar(android.support.v7.app.ActionBar) ThemeUtils(com.keylesspalace.tusky.util.ThemeUtils) DialogInterface(android.content.DialogInterface) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) TimelineReceiver(com.keylesspalace.tusky.receiver.TimelineReceiver) LinkHelper(com.keylesspalace.tusky.util.LinkHelper) LinkListener(com.keylesspalace.tusky.interfaces.LinkListener) Color(android.graphics.Color) Callback(retrofit2.Callback) Toolbar(android.support.v7.widget.Toolbar) CircularImageView(com.pkmmte.view.CircularImageView) MastodonApi(com.keylesspalace.tusky.network.MastodonApi) AccountManager(com.keylesspalace.tusky.db.AccountManager) Collections(java.util.Collections) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) AccountPagerAdapter(com.keylesspalace.tusky.pager.AccountPagerAdapter) ViewPager(android.support.v4.view.ViewPager) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) CircularImageView(com.pkmmte.view.CircularImageView) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) AttrRes(android.support.annotation.AttrRes) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) AccountManager(com.keylesspalace.tusky.db.AccountManager) AppBarLayout(android.support.design.widget.AppBarLayout) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 13 with Color

use of android.graphics.Color in project Slide by ccrama.

the class PopulateSubmissionViewHolder method showBottomSheet.

public <T extends Contribution> void showBottomSheet(final Activity mContext, final Submission submission, final SubmissionViewHolder holder, final List<T> posts, final String baseSub, final RecyclerView recyclerview, final boolean full) {
    int[] attrs = new int[] { R.attr.tintColor };
    TypedArray ta = mContext.obtainStyledAttributes(attrs);
    int color = ta.getColor(0, Color.WHITE);
    Drawable profile = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_account_circle, null);
    final Drawable sub = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_bookmark_border, null);
    Drawable saved = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_star, null);
    Drawable hide = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_visibility_off, null);
    final Drawable report = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_report, null);
    Drawable copy = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_content_copy, null);
    final Drawable readLater = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_download, null);
    Drawable open = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_open_in_browser, null);
    Drawable link = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_link, null);
    Drawable reddit = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_forum, null);
    Drawable filter = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_filter_list, null);
    Drawable crosspost = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_forward, null);
    final List<Drawable> drawableSet = Arrays.asList(profile, sub, saved, hide, report, copy, open, link, reddit, readLater, filter, crosspost);
    BlendModeUtil.tintDrawablesAsSrcAtop(drawableSet, color);
    ta.recycle();
    final BottomSheet.Builder b = new BottomSheet.Builder(mContext).title(CompatUtil.fromHtml(submission.getTitle()));
    final boolean isReadLater = mContext instanceof PostReadLater;
    final boolean isAddedToReadLaterList = ReadLater.isToBeReadLater(submission);
    if (Authentication.didOnline) {
        b.sheet(1, profile, "/u/" + submission.getAuthor()).sheet(2, sub, "/r/" + submission.getSubredditName());
        String save = mContext.getString(R.string.btn_save);
        if (ActionStates.isSaved(submission)) {
            save = mContext.getString(R.string.comment_unsave);
        }
        if (Authentication.isLoggedIn) {
            b.sheet(3, saved, save);
        }
    }
    if (isAddedToReadLaterList) {
        b.sheet(28, readLater, "Mark As Read");
    } else {
        b.sheet(28, readLater, "Read later");
    }
    if (Authentication.didOnline) {
        if (Authentication.isLoggedIn) {
            b.sheet(12, report, mContext.getString(R.string.btn_report));
            b.sheet(13, crosspost, mContext.getString(R.string.btn_crosspost));
        }
    }
    if (submission.getSelftext() != null && !submission.getSelftext().isEmpty() && full) {
        b.sheet(25, copy, mContext.getString(R.string.submission_copy_text));
    }
    boolean hidden = submission.isHidden();
    if (!full && Authentication.didOnline) {
        if (!hidden) {
            b.sheet(5, hide, mContext.getString(R.string.submission_hide));
        } else {
            b.sheet(5, hide, mContext.getString(R.string.submission_unhide));
        }
    }
    b.sheet(7, open, mContext.getString(R.string.open_externally));
    b.sheet(4, link, mContext.getString(R.string.submission_share_permalink)).sheet(8, reddit, mContext.getString(R.string.submission_share_reddit_url));
    if ((mContext instanceof MainActivity) || (mContext instanceof SubredditView)) {
        b.sheet(10, filter, mContext.getString(R.string.filter_content));
    }
    b.listener(new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            switch(which) {
                case 1:
                    {
                        Intent i = new Intent(mContext, Profile.class);
                        i.putExtra(Profile.EXTRA_PROFILE, submission.getAuthor());
                        mContext.startActivity(i);
                    }
                    break;
                case 2:
                    {
                        Intent i = new Intent(mContext, SubredditView.class);
                        i.putExtra(SubredditView.EXTRA_SUBREDDIT, submission.getSubredditName());
                        mContext.startActivityForResult(i, 14);
                    }
                    break;
                case 10:
                    String[] choices;
                    final String flair = submission.getSubmissionFlair().getText() != null ? submission.getSubmissionFlair().getText() : "";
                    if (flair.isEmpty()) {
                        choices = new String[] { mContext.getString(R.string.filter_posts_sub, submission.getSubredditName()), mContext.getString(R.string.filter_posts_user, submission.getAuthor()), mContext.getString(R.string.filter_posts_urls, submission.getDomain()), mContext.getString(R.string.filter_open_externally, submission.getDomain()) };
                        chosen = new boolean[] { SettingValues.subredditFilters.contains(submission.getSubredditName().toLowerCase(Locale.ENGLISH)), SettingValues.userFilters.contains(submission.getAuthor().toLowerCase(Locale.ENGLISH)), SettingValues.domainFilters.contains(submission.getDomain().toLowerCase(Locale.ENGLISH)), SettingValues.alwaysExternal.contains(submission.getDomain().toLowerCase(Locale.ENGLISH)) };
                        oldChosen = chosen.clone();
                    } else {
                        choices = new String[] { mContext.getString(R.string.filter_posts_sub, submission.getSubredditName()), mContext.getString(R.string.filter_posts_user, submission.getAuthor()), mContext.getString(R.string.filter_posts_urls, submission.getDomain()), mContext.getString(R.string.filter_open_externally, submission.getDomain()), mContext.getString(R.string.filter_posts_flair, flair, baseSub) };
                    }
                    chosen = new boolean[] { SettingValues.subredditFilters.contains(submission.getSubredditName().toLowerCase(Locale.ENGLISH)), SettingValues.userFilters.contains(submission.getAuthor().toLowerCase(Locale.ENGLISH)), SettingValues.domainFilters.contains(submission.getDomain().toLowerCase(Locale.ENGLISH)), SettingValues.alwaysExternal.contains(submission.getDomain().toLowerCase(Locale.ENGLISH)), SettingValues.flairFilters.contains(baseSub + ":" + flair.toLowerCase(Locale.ENGLISH).trim()) };
                    oldChosen = chosen.clone();
                    new AlertDialog.Builder(mContext).setTitle(R.string.filter_title).setMultiChoiceItems(choices, chosen, (dialog1, which1, isChecked) -> chosen[which1] = isChecked).setPositiveButton(R.string.filter_btn, (dialog12, which12) -> {
                        boolean filtered = false;
                        SharedPreferences.Editor e = SettingValues.prefs.edit();
                        if (chosen[0] && chosen[0] != oldChosen[0]) {
                            SettingValues.subredditFilters.add(submission.getSubredditName().toLowerCase(Locale.ENGLISH).trim());
                            filtered = true;
                            e.putStringSet(SettingValues.PREF_SUBREDDIT_FILTERS, SettingValues.subredditFilters);
                        } else if (!chosen[0] && chosen[0] != oldChosen[0]) {
                            SettingValues.subredditFilters.remove(submission.getSubredditName().toLowerCase(Locale.ENGLISH).trim());
                            filtered = false;
                            e.putStringSet(SettingValues.PREF_SUBREDDIT_FILTERS, SettingValues.subredditFilters);
                            e.apply();
                        }
                        if (chosen[1] && chosen[1] != oldChosen[1]) {
                            SettingValues.userFilters.add(submission.getAuthor().toLowerCase(Locale.ENGLISH).trim());
                            filtered = true;
                            e.putStringSet(SettingValues.PREF_USER_FILTERS, SettingValues.userFilters);
                        } else if (!chosen[1] && chosen[1] != oldChosen[1]) {
                            SettingValues.userFilters.remove(submission.getAuthor().toLowerCase(Locale.ENGLISH).trim());
                            filtered = false;
                            e.putStringSet(SettingValues.PREF_USER_FILTERS, SettingValues.userFilters);
                            e.apply();
                        }
                        if (chosen[2] && chosen[2] != oldChosen[2]) {
                            SettingValues.domainFilters.add(submission.getDomain().toLowerCase(Locale.ENGLISH).trim());
                            filtered = true;
                            e.putStringSet(SettingValues.PREF_DOMAIN_FILTERS, SettingValues.domainFilters);
                        } else if (!chosen[2] && chosen[2] != oldChosen[2]) {
                            SettingValues.domainFilters.remove(submission.getDomain().toLowerCase(Locale.ENGLISH).trim());
                            filtered = false;
                            e.putStringSet(SettingValues.PREF_DOMAIN_FILTERS, SettingValues.domainFilters);
                            e.apply();
                        }
                        if (chosen[3] && chosen[3] != oldChosen[3]) {
                            SettingValues.alwaysExternal.add(submission.getDomain().toLowerCase(Locale.ENGLISH).trim());
                            e.putStringSet(SettingValues.PREF_ALWAYS_EXTERNAL, SettingValues.alwaysExternal);
                            e.apply();
                        } else if (!chosen[3] && chosen[3] != oldChosen[3]) {
                            SettingValues.alwaysExternal.remove(submission.getDomain().toLowerCase(Locale.ENGLISH).trim());
                            e.putStringSet(SettingValues.PREF_ALWAYS_EXTERNAL, SettingValues.alwaysExternal);
                            e.apply();
                        }
                        if (chosen.length > 4) {
                            String s = (baseSub + ":" + flair).toLowerCase(Locale.ENGLISH).trim();
                            if (chosen[4] && chosen[4] != oldChosen[4]) {
                                SettingValues.flairFilters.add(s);
                                e.putStringSet(SettingValues.PREF_FLAIR_FILTERS, SettingValues.flairFilters);
                                e.apply();
                                filtered = true;
                            } else if (!chosen[4] && chosen[4] != oldChosen[4]) {
                                SettingValues.flairFilters.remove(s);
                                e.putStringSet(SettingValues.PREF_FLAIR_FILTERS, SettingValues.flairFilters);
                                e.apply();
                            }
                        }
                        if (filtered) {
                            e.apply();
                            ArrayList<Contribution> toRemove = new ArrayList<>();
                            for (Contribution s : posts) {
                                if (s instanceof Submission && PostMatch.doesMatch((Submission) s)) {
                                    toRemove.add(s);
                                }
                            }
                            OfflineSubreddit s = OfflineSubreddit.getSubreddit(baseSub, false, mContext);
                            for (Contribution remove : toRemove) {
                                final int pos = posts.indexOf(remove);
                                posts.remove(pos);
                                if (baseSub != null) {
                                    s.hideMulti(pos);
                                }
                            }
                            s.writeToMemoryNoStorage();
                            recyclerview.getAdapter().notifyDataSetChanged();
                        }
                    }).setNegativeButton(R.string.btn_cancel, null).show();
                    break;
                case 3:
                    saveSubmission(submission, mContext, holder, full);
                    break;
                case 5:
                    {
                        hideSubmission(submission, posts, baseSub, recyclerview, mContext);
                    }
                    break;
                case 7:
                    LinkUtil.openExternally(submission.getUrl());
                    if (submission.isNsfw() && !SettingValues.storeNSFWHistory) {
                    // Do nothing if the post is NSFW and storeNSFWHistory is not enabled
                    } else if (SettingValues.storeHistory) {
                        HasSeen.addSeen(submission.getFullName());
                    }
                    break;
                case 13:
                    LinkUtil.crosspost(submission, mContext);
                    break;
                case 28:
                    if (!isAddedToReadLaterList) {
                        ReadLater.setReadLater(submission, true);
                        Snackbar s = Snackbar.make(holder.itemView, "Added to read later!", Snackbar.LENGTH_SHORT);
                        View view = s.getView();
                        TextView tv = view.findViewById(com.google.android.material.R.id.snackbar_text);
                        tv.setTextColor(Color.WHITE);
                        s.setAction(R.string.btn_undo, new View.OnClickListener() {

                            @Override
                            public void onClick(View view) {
                                ReadLater.setReadLater(submission, false);
                                Snackbar s2 = Snackbar.make(holder.itemView, "Removed from read later", Snackbar.LENGTH_SHORT);
                                LayoutUtils.showSnackbar(s2);
                            }
                        });
                        if (NetworkUtil.isConnected(mContext)) {
                            new CommentCacheAsync(Collections.singletonList(submission), mContext, CommentCacheAsync.SAVED_SUBMISSIONS, new boolean[] { true, true }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                        }
                        s.show();
                    } else {
                        ReadLater.setReadLater(submission, false);
                        if (isReadLater || !Authentication.didOnline) {
                            final int pos = posts.indexOf(submission);
                            posts.remove(submission);
                            recyclerview.getAdapter().notifyItemRemoved(holder.getBindingAdapterPosition());
                            Snackbar s2 = Snackbar.make(holder.itemView, "Removed from read later", Snackbar.LENGTH_SHORT);
                            View view2 = s2.getView();
                            TextView tv2 = view2.findViewById(com.google.android.material.R.id.snackbar_text);
                            tv2.setTextColor(Color.WHITE);
                            s2.setAction(R.string.btn_undo, new View.OnClickListener() {

                                @Override
                                public void onClick(View view) {
                                    posts.add(pos, (T) submission);
                                    recyclerview.getAdapter().notifyDataSetChanged();
                                }
                            });
                        } else {
                            Snackbar s2 = Snackbar.make(holder.itemView, "Removed from read later", Snackbar.LENGTH_SHORT);
                            View view2 = s2.getView();
                            TextView tv2 = view2.findViewById(com.google.android.material.R.id.snackbar_text);
                            s2.show();
                        }
                        OfflineSubreddit.newSubreddit(CommentCacheAsync.SAVED_SUBMISSIONS).deleteFromMemory(submission.getFullName());
                    }
                    break;
                case 4:
                    Reddit.defaultShareText(CompatUtil.fromHtml(submission.getTitle()).toString(), StringEscapeUtils.escapeHtml4(submission.getUrl()), mContext);
                    break;
                case 12:
                    final MaterialDialog reportDialog = new MaterialDialog.Builder(mContext).customView(R.layout.report_dialog, true).title(R.string.report_post).positiveText(R.string.btn_report).negativeText(R.string.btn_cancel).onPositive(new MaterialDialog.SingleButtonCallback() {

                        @Override
                        public void onClick(MaterialDialog dialog, DialogAction which) {
                            RadioGroup reasonGroup = dialog.getCustomView().findViewById(R.id.report_reasons);
                            String reportReason;
                            if (reasonGroup.getCheckedRadioButtonId() == R.id.report_other) {
                                reportReason = ((EditText) dialog.getCustomView().findViewById(R.id.input_report_reason)).getText().toString();
                            } else {
                                reportReason = ((RadioButton) reasonGroup.findViewById(reasonGroup.getCheckedRadioButtonId())).getText().toString();
                            }
                            new AsyncReportTask(submission, holder.itemView).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, reportReason);
                        }
                    }).build();
                    final RadioGroup reasonGroup = reportDialog.getCustomView().findViewById(R.id.report_reasons);
                    reasonGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(RadioGroup group, int checkedId) {
                            if (checkedId == R.id.report_other)
                                reportDialog.getCustomView().findViewById(R.id.input_report_reason).setVisibility(View.VISIBLE);
                            else
                                reportDialog.getCustomView().findViewById(R.id.input_report_reason).setVisibility(View.GONE);
                        }
                    });
                    // Load sub's report reasons and show the appropriate ones
                    new AsyncTask<Void, Void, Ruleset>() {

                        @Override
                        protected Ruleset doInBackground(Void... voids) {
                            return Authentication.reddit.getRules(submission.getSubredditName());
                        }

                        @Override
                        protected void onPostExecute(Ruleset rules) {
                            reportDialog.getCustomView().findViewById(R.id.report_loading).setVisibility(View.GONE);
                            if (rules.getSubredditRules().size() > 0) {
                                TextView subHeader = new TextView(mContext);
                                subHeader.setText(mContext.getString(R.string.report_sub_rules, submission.getSubredditName()));
                                reasonGroup.addView(subHeader, reasonGroup.getChildCount() - 2);
                            }
                            for (SubredditRule rule : rules.getSubredditRules()) {
                                if (rule.getKind() == SubredditRule.RuleKind.LINK || rule.getKind() == SubredditRule.RuleKind.ALL) {
                                    RadioButton btn = new RadioButton(mContext);
                                    btn.setText(rule.getViolationReason());
                                    reasonGroup.addView(btn, reasonGroup.getChildCount() - 2);
                                    btn.getLayoutParams().width = WindowManager.LayoutParams.MATCH_PARENT;
                                }
                            }
                            if (rules.getSiteRules().size() > 0) {
                                TextView siteHeader = new TextView(mContext);
                                siteHeader.setText(R.string.report_site_rules);
                                reasonGroup.addView(siteHeader, reasonGroup.getChildCount() - 2);
                            }
                            for (String rule : rules.getSiteRules()) {
                                RadioButton btn = new RadioButton(mContext);
                                btn.setText(rule);
                                reasonGroup.addView(btn, reasonGroup.getChildCount() - 2);
                                btn.getLayoutParams().width = WindowManager.LayoutParams.MATCH_PARENT;
                            }
                        }
                    }.execute();
                    reportDialog.show();
                    break;
                case 8:
                    if (SettingValues.shareLongLink) {
                        Reddit.defaultShareText(submission.getTitle(), "https://reddit.com" + submission.getPermalink(), mContext);
                    } else {
                        Reddit.defaultShareText(submission.getTitle(), "https://redd.it/" + submission.getId(), mContext);
                    }
                    break;
                case 6:
                    {
                        ClipboardUtil.copyToClipboard(mContext, "Link", submission.getUrl());
                        Toast.makeText(mContext, R.string.submission_link_copied, Toast.LENGTH_SHORT).show();
                    }
                    break;
                case 25:
                    final TextView showText = new TextView(mContext);
                    showText.setText(StringEscapeUtils.unescapeHtml4(submission.getTitle() + "\n\n" + submission.getSelftext()));
                    showText.setTextIsSelectable(true);
                    int sixteen = DisplayUtil.dpToPxVertical(24);
                    showText.setPadding(sixteen, 0, sixteen, 0);
                    new AlertDialog.Builder(mContext).setView(showText).setTitle("Select text to copy").setCancelable(true).setPositiveButton("COPY SELECTED", (dialog13, which13) -> {
                        String selected = showText.getText().toString().substring(showText.getSelectionStart(), showText.getSelectionEnd());
                        if (!selected.isEmpty()) {
                            ClipboardUtil.copyToClipboard(mContext, "Selftext", selected);
                        } else {
                            ClipboardUtil.copyToClipboard(mContext, "Selftext", CompatUtil.fromHtml(submission.getTitle() + "\n\n" + submission.getSelftext()));
                        }
                        Toast.makeText(mContext, R.string.submission_comment_copied, Toast.LENGTH_SHORT).show();
                    }).setNegativeButton(R.string.btn_cancel, null).setNeutralButton("COPY ALL", (dialog14, which14) -> {
                        ClipboardUtil.copyToClipboard(mContext, "Selftext", StringEscapeUtils.unescapeHtml4(submission.getTitle() + "\n\n" + submission.getSelftext()));
                        Toast.makeText(mContext, R.string.submission_text_copied, Toast.LENGTH_SHORT).show();
                    }).show();
                    break;
            }
        }
    });
    b.show();
}
Also used : Arrays(java.util.Arrays) Bundle(android.os.Bundle) R(me.ccrama.redditslide.R) RobotoTypefaces(com.devspark.robototextview.RobotoTypefaces) Thing(net.dean.jraw.models.Thing) MainActivity(me.ccrama.redditslide.Activities.MainActivity) MediaView(me.ccrama.redditslide.Activities.MediaView) AnimatorUtil(me.ccrama.redditslide.util.AnimatorUtil) JsonUtil(me.ccrama.redditslide.util.JsonUtil) ImageView(android.widget.ImageView) RadioButton(android.widget.RadioButton) DistinguishedStatus(net.dean.jraw.models.DistinguishedStatus) PostMatch(me.ccrama.redditslide.PostMatch) ContentType(me.ccrama.redditslide.ContentType) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan) DataShare(me.ccrama.redditslide.DataShare) Drawable(android.graphics.drawable.Drawable) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) MultiredditOverview(me.ccrama.redditslide.Activities.MultiredditOverview) ContextCompat(androidx.core.content.ContextCompat) Ruleset(net.dean.jraw.models.Ruleset) DisplayUtil(me.ccrama.redditslide.util.DisplayUtil) GalleryImage(me.ccrama.redditslide.Activities.GalleryImage) Palette(me.ccrama.redditslide.Visuals.Palette) BlendModeUtil(me.ccrama.redditslide.util.BlendModeUtil) Profile(me.ccrama.redditslide.Activities.Profile) PeekViewActivity(me.ccrama.redditslide.ForceTouch.PeekViewActivity) Nullable(androidx.annotation.Nullable) Contribution(net.dean.jraw.models.Contribution) Reauthenticate(me.ccrama.redditslide.Activities.Reauthenticate) SubmissionParser(me.ccrama.redditslide.util.SubmissionParser) DoEditorActions(me.ccrama.redditslide.Views.DoEditorActions) HasSeen(me.ccrama.redditslide.HasSeen) Vote(me.ccrama.redditslide.Vote) Dialog(android.app.Dialog) SubmissionViewHolder(me.ccrama.redditslide.Adapters.SubmissionViewHolder) RadioGroup(android.widget.RadioGroup) AccountManager(net.dean.jraw.managers.AccountManager) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) TumblrPager(me.ccrama.redditslide.Activities.TumblrPager) Toast(android.widget.Toast) UserSubscriptions(me.ccrama.redditslide.UserSubscriptions) OpenRedditLink(me.ccrama.redditslide.OpenRedditLink) InvalidScopeException(net.dean.jraw.http.oauth.InvalidScopeException) FluentRedditClient(net.dean.jraw.fluent.FluentRedditClient) FlairTemplate(net.dean.jraw.models.FlairTemplate) Reddit(me.ccrama.redditslide.Reddit) VoteDirection(net.dean.jraw.models.VoteDirection) ModQueue(me.ccrama.redditslide.Activities.ModQueue) SharedPreferences(android.content.SharedPreferences) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) GifUtils(me.ccrama.redditslide.util.GifUtils) ActionStates(me.ccrama.redditslide.ActionStates) EditText(android.widget.EditText) LinkUtil(me.ccrama.redditslide.util.LinkUtil) EXTRA_SUBMISSION_TITLE(me.ccrama.redditslide.Notifications.ImageDownloadNotificationService.EXTRA_SUBMISSION_TITLE) LinearLayout(android.widget.LinearLayout) CommentCacheAsync(me.ccrama.redditslide.CommentCacheAsync) WindowManager(android.view.WindowManager) Tumblr(me.ccrama.redditslide.Activities.Tumblr) Locale(java.util.Locale) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SubredditRule(net.dean.jraw.models.SubredditRule) ToolboxUI(me.ccrama.redditslide.Toolbox.ToolboxUI) AsyncTask(android.os.AsyncTask) FullscreenVideo(me.ccrama.redditslide.Activities.FullscreenVideo) Album(me.ccrama.redditslide.Activities.Album) Authentication(me.ccrama.redditslide.Authentication) InputType(android.text.InputType) ApiException(net.dean.jraw.ApiException) SubmissionCache(me.ccrama.redditslide.SubmissionCache) AlbumPager(me.ccrama.redditslide.Activities.AlbumPager) OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) List(java.util.List) NetworkUtil(me.ccrama.redditslide.util.NetworkUtil) TextView(android.widget.TextView) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Snackbar(com.google.android.material.snackbar.Snackbar) BottomSheet(com.cocosw.bottomsheet.BottomSheet) RedditGalleryPager(me.ccrama.redditslide.Activities.RedditGalleryPager) Typeface(android.graphics.Typeface) LayoutUtils(me.ccrama.redditslide.util.LayoutUtils) Context(android.content.Context) SettingValues(me.ccrama.redditslide.SettingValues) AlertDialog(androidx.appcompat.app.AlertDialog) ResourcesCompat(androidx.core.content.res.ResourcesCompat) ModerationManager(net.dean.jraw.managers.ModerationManager) FontPreferences(me.ccrama.redditslide.Visuals.FontPreferences) Submission(net.dean.jraw.models.Submission) Intent(android.content.Intent) Hidden(me.ccrama.redditslide.Hidden) TypedArray(android.content.res.TypedArray) Search(me.ccrama.redditslide.Activities.Search) SubredditView(me.ccrama.redditslide.Activities.SubredditView) DialogInterface(android.content.DialogInterface) ClipboardUtil(me.ccrama.redditslide.util.ClipboardUtil) LayoutInflater(android.view.LayoutInflater) DialogAction(com.afollestad.materialdialogs.DialogAction) StringEscapeUtils(org.apache.commons.text.StringEscapeUtils) CompatUtil(me.ccrama.redditslide.util.CompatUtil) Color(android.graphics.Color) FlairReference(net.dean.jraw.fluent.FlairReference) RedditGallery(me.ccrama.redditslide.Activities.RedditGallery) PostReadLater(me.ccrama.redditslide.Activities.PostReadLater) CommentAdapter(me.ccrama.redditslide.Adapters.CommentAdapter) LastComments(me.ccrama.redditslide.LastComments) Activity(android.app.Activity) NetworkException(net.dean.jraw.http.NetworkException) Collections(java.util.Collections) Resources(android.content.res.Resources) Ruleset(net.dean.jraw.models.Ruleset) RadioGroup(android.widget.RadioGroup) DialogInterface(android.content.DialogInterface) SpannableStringBuilder(android.text.SpannableStringBuilder) ArrayList(java.util.ArrayList) PostReadLater(me.ccrama.redditslide.Activities.PostReadLater) SubredditView(me.ccrama.redditslide.Activities.SubredditView) MainActivity(me.ccrama.redditslide.Activities.MainActivity) TypedArray(android.content.res.TypedArray) TextView(android.widget.TextView) SubredditRule(net.dean.jraw.models.SubredditRule) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Submission(net.dean.jraw.models.Submission) CommentCacheAsync(me.ccrama.redditslide.CommentCacheAsync) Drawable(android.graphics.drawable.Drawable) OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) RadioButton(android.widget.RadioButton) MediaView(me.ccrama.redditslide.Activities.MediaView) ImageView(android.widget.ImageView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) DialogAction(com.afollestad.materialdialogs.DialogAction) BottomSheet(com.cocosw.bottomsheet.BottomSheet) Contribution(net.dean.jraw.models.Contribution) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 14 with Color

use of android.graphics.Color in project Slide by ccrama.

the class PopulateNewsViewHolder method showBottomSheet.

public <T extends Contribution> void showBottomSheet(final Activity mContext, final Submission submission, final NewsViewHolder holder, final List<T> posts, final String baseSub, final RecyclerView recyclerview, final boolean full) {
    int[] attrs = new int[] { R.attr.tintColor };
    TypedArray ta = mContext.obtainStyledAttributes(attrs);
    int color = ta.getColor(0, Color.WHITE);
    Drawable profile = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_account_circle, null);
    final Drawable sub = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_bookmark_border, null);
    Drawable saved = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_star, null);
    Drawable hide = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_visibility_off, null);
    final Drawable report = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_report, null);
    Drawable copy = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_content_copy, null);
    final Drawable readLater = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_download, null);
    Drawable open = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_open_in_browser, null);
    Drawable link = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_link, null);
    Drawable reddit = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_forum, null);
    Drawable filter = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_filter_list, null);
    final List<Drawable> drawableSet = Arrays.asList(profile, sub, saved, hide, report, copy, open, link, reddit, readLater, filter);
    BlendModeUtil.tintDrawablesAsSrcAtop(drawableSet, color);
    ta.recycle();
    final BottomSheet.Builder b = new BottomSheet.Builder(mContext).title(CompatUtil.fromHtml(submission.getTitle()));
    final boolean isReadLater = mContext instanceof PostReadLater;
    final boolean isAddedToReadLaterList = ReadLater.isToBeReadLater(submission);
    if (Authentication.didOnline) {
        b.sheet(1, profile, "/u/" + submission.getAuthor()).sheet(2, sub, "/r/" + submission.getSubredditName());
        String save = mContext.getString(R.string.btn_save);
        if (ActionStates.isSaved(submission)) {
            save = mContext.getString(R.string.comment_unsave);
        }
        if (Authentication.isLoggedIn) {
            b.sheet(3, saved, save);
        }
    }
    if (isAddedToReadLaterList) {
        b.sheet(28, readLater, "Mark As Read");
    } else {
        b.sheet(28, readLater, "Read later");
    }
    if (Authentication.didOnline) {
        if (Authentication.isLoggedIn) {
            b.sheet(12, report, mContext.getString(R.string.btn_report));
        }
    }
    if (submission.getSelftext() != null && !submission.getSelftext().isEmpty() && full) {
        b.sheet(25, copy, mContext.getString(R.string.submission_copy_text));
    }
    boolean hidden = submission.isHidden();
    if (!full && Authentication.didOnline) {
        if (!hidden) {
            b.sheet(5, hide, mContext.getString(R.string.submission_hide));
        } else {
            b.sheet(5, hide, mContext.getString(R.string.submission_unhide));
        }
    }
    b.sheet(7, open, mContext.getString(R.string.open_externally));
    b.sheet(4, link, mContext.getString(R.string.submission_share_permalink)).sheet(8, reddit, mContext.getString(R.string.submission_share_reddit_url));
    if ((mContext instanceof MainActivity) || (mContext instanceof SubredditView)) {
        b.sheet(10, filter, mContext.getString(R.string.filter_content));
    }
    b.listener(new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            switch(which) {
                case 1:
                    {
                        Intent i = new Intent(mContext, Profile.class);
                        i.putExtra(Profile.EXTRA_PROFILE, submission.getAuthor());
                        mContext.startActivity(i);
                    }
                    break;
                case 2:
                    {
                        Intent i = new Intent(mContext, SubredditView.class);
                        i.putExtra(SubredditView.EXTRA_SUBREDDIT, submission.getSubredditName());
                        mContext.startActivityForResult(i, 14);
                    }
                    break;
                case 10:
                    String[] choices;
                    final String flair = submission.getSubmissionFlair().getText() != null ? submission.getSubmissionFlair().getText() : "";
                    if (flair.isEmpty()) {
                        choices = new String[] { mContext.getString(R.string.filter_posts_sub, submission.getSubredditName()), mContext.getString(R.string.filter_posts_user, submission.getAuthor()), mContext.getString(R.string.filter_posts_urls, submission.getDomain()), mContext.getString(R.string.filter_open_externally, submission.getDomain()) };
                        chosen = new boolean[] { SettingValues.subredditFilters.contains(submission.getSubredditName().toLowerCase(Locale.ENGLISH)), SettingValues.userFilters.contains(submission.getAuthor().toLowerCase(Locale.ENGLISH)), SettingValues.domainFilters.contains(submission.getDomain().toLowerCase(Locale.ENGLISH)), SettingValues.alwaysExternal.contains(submission.getDomain().toLowerCase(Locale.ENGLISH)) };
                        oldChosen = chosen.clone();
                    } else {
                        choices = new String[] { mContext.getString(R.string.filter_posts_sub, submission.getSubredditName()), mContext.getString(R.string.filter_posts_user, submission.getAuthor()), mContext.getString(R.string.filter_posts_urls, submission.getDomain()), mContext.getString(R.string.filter_open_externally, submission.getDomain()), mContext.getString(R.string.filter_posts_flair, flair, baseSub) };
                    }
                    chosen = new boolean[] { SettingValues.subredditFilters.contains(submission.getSubredditName().toLowerCase(Locale.ENGLISH)), SettingValues.userFilters.contains(submission.getAuthor().toLowerCase(Locale.ENGLISH)), SettingValues.domainFilters.contains(submission.getDomain().toLowerCase(Locale.ENGLISH)), SettingValues.alwaysExternal.contains(submission.getDomain().toLowerCase(Locale.ENGLISH)), SettingValues.flairFilters.contains(baseSub + ":" + flair.toLowerCase(Locale.ENGLISH).trim()) };
                    oldChosen = chosen.clone();
                    new AlertDialog.Builder(mContext).setTitle(R.string.filter_title).setMultiChoiceItems(choices, chosen, (dialog1, which1, isChecked) -> chosen[which1] = isChecked).setPositiveButton(R.string.filter_btn, (dialog12, which12) -> {
                        boolean filtered = false;
                        SharedPreferences.Editor e = SettingValues.prefs.edit();
                        if (chosen[0] && chosen[0] != oldChosen[0]) {
                            SettingValues.subredditFilters.add(submission.getSubredditName().toLowerCase(Locale.ENGLISH).trim());
                            filtered = true;
                            e.putStringSet(SettingValues.PREF_SUBREDDIT_FILTERS, SettingValues.subredditFilters);
                        } else if (!chosen[0] && chosen[0] != oldChosen[0]) {
                            SettingValues.subredditFilters.remove(submission.getSubredditName().toLowerCase(Locale.ENGLISH).trim());
                            filtered = false;
                            e.putStringSet(SettingValues.PREF_SUBREDDIT_FILTERS, SettingValues.subredditFilters);
                            e.apply();
                        }
                        if (chosen[1] && chosen[1] != oldChosen[1]) {
                            SettingValues.userFilters.add(submission.getAuthor().toLowerCase(Locale.ENGLISH).trim());
                            filtered = true;
                            e.putStringSet(SettingValues.PREF_USER_FILTERS, SettingValues.userFilters);
                        } else if (!chosen[1] && chosen[1] != oldChosen[1]) {
                            SettingValues.userFilters.remove(submission.getAuthor().toLowerCase(Locale.ENGLISH).trim());
                            filtered = false;
                            e.putStringSet(SettingValues.PREF_USER_FILTERS, SettingValues.userFilters);
                            e.apply();
                        }
                        if (chosen[2] && chosen[2] != oldChosen[2]) {
                            SettingValues.domainFilters.add(submission.getDomain().toLowerCase(Locale.ENGLISH).trim());
                            filtered = true;
                            e.putStringSet(SettingValues.PREF_DOMAIN_FILTERS, SettingValues.domainFilters);
                        } else if (!chosen[2] && chosen[2] != oldChosen[2]) {
                            SettingValues.domainFilters.remove(submission.getDomain().toLowerCase(Locale.ENGLISH).trim());
                            filtered = false;
                            e.putStringSet(SettingValues.PREF_DOMAIN_FILTERS, SettingValues.domainFilters);
                            e.apply();
                        }
                        if (chosen[3] && chosen[3] != oldChosen[3]) {
                            SettingValues.alwaysExternal.add(submission.getDomain().toLowerCase(Locale.ENGLISH).trim());
                            e.putStringSet(SettingValues.PREF_ALWAYS_EXTERNAL, SettingValues.alwaysExternal);
                            e.apply();
                        } else if (!chosen[3] && chosen[3] != oldChosen[3]) {
                            SettingValues.alwaysExternal.remove(submission.getDomain().toLowerCase(Locale.ENGLISH).trim());
                            e.putStringSet(SettingValues.PREF_ALWAYS_EXTERNAL, SettingValues.alwaysExternal);
                            e.apply();
                        }
                        if (chosen.length > 4) {
                            String s = (baseSub + ":" + flair).toLowerCase(Locale.ENGLISH).trim();
                            if (chosen[4] && chosen[4] != oldChosen[4]) {
                                SettingValues.flairFilters.add(s);
                                e.putStringSet(SettingValues.PREF_FLAIR_FILTERS, SettingValues.flairFilters);
                                e.apply();
                                filtered = true;
                            } else if (!chosen[4] && chosen[4] != oldChosen[4]) {
                                SettingValues.flairFilters.remove(s);
                                e.putStringSet(SettingValues.PREF_FLAIR_FILTERS, SettingValues.flairFilters);
                                e.apply();
                            }
                        }
                        if (filtered) {
                            e.apply();
                            ArrayList<Contribution> toRemove = new ArrayList<>();
                            for (Contribution s : posts) {
                                if (s instanceof Submission && PostMatch.doesMatch((Submission) s)) {
                                    toRemove.add(s);
                                }
                            }
                            OfflineSubreddit s = OfflineSubreddit.getSubreddit(baseSub, false, mContext);
                            for (Contribution remove : toRemove) {
                                final int pos = posts.indexOf(remove);
                                posts.remove(pos);
                                if (baseSub != null) {
                                    s.hideMulti(pos);
                                }
                            }
                            s.writeToMemoryNoStorage();
                            recyclerview.getAdapter().notifyDataSetChanged();
                        }
                    }).setNegativeButton(R.string.btn_cancel, null).show();
                    break;
                case 5:
                    hideSubmission(submission, posts, baseSub, recyclerview, mContext);
                    break;
                case 7:
                    LinkUtil.openExternally(submission.getUrl());
                    if (submission.isNsfw() && !SettingValues.storeNSFWHistory) {
                    // Do nothing if the post is NSFW and storeNSFWHistory is not enabled
                    } else if (SettingValues.storeHistory) {
                        HasSeen.addSeen(submission.getFullName());
                    }
                    break;
                case 28:
                    if (!isAddedToReadLaterList) {
                        ReadLater.setReadLater(submission, true);
                        Snackbar s = Snackbar.make(holder.itemView, "Added to read later!", Snackbar.LENGTH_SHORT);
                        View view = s.getView();
                        TextView tv = view.findViewById(com.google.android.material.R.id.snackbar_text);
                        tv.setTextColor(Color.WHITE);
                        s.setAction(R.string.btn_undo, new View.OnClickListener() {

                            @Override
                            public void onClick(View view) {
                                ReadLater.setReadLater(submission, false);
                                Snackbar s2 = Snackbar.make(holder.itemView, "Removed from read later", Snackbar.LENGTH_SHORT);
                                LayoutUtils.showSnackbar(s2);
                            }
                        });
                        if (NetworkUtil.isConnected(mContext)) {
                            new CommentCacheAsync(Collections.singletonList(submission), mContext, CommentCacheAsync.SAVED_SUBMISSIONS, new boolean[] { true, true }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                        }
                        s.show();
                    } else {
                        ReadLater.setReadLater(submission, false);
                        if (isReadLater || !Authentication.didOnline) {
                            final int pos = posts.indexOf(submission);
                            posts.remove(submission);
                            recyclerview.getAdapter().notifyItemRemoved(holder.getBindingAdapterPosition());
                            Snackbar s2 = Snackbar.make(holder.itemView, "Removed from read later", Snackbar.LENGTH_SHORT);
                            View view2 = s2.getView();
                            TextView tv2 = view2.findViewById(com.google.android.material.R.id.snackbar_text);
                            tv2.setTextColor(Color.WHITE);
                            s2.setAction(R.string.btn_undo, new View.OnClickListener() {

                                @Override
                                public void onClick(View view) {
                                    posts.add(pos, (T) submission);
                                    recyclerview.getAdapter().notifyDataSetChanged();
                                }
                            });
                        } else {
                            Snackbar s2 = Snackbar.make(holder.itemView, "Removed from read later", Snackbar.LENGTH_SHORT);
                            View view2 = s2.getView();
                            TextView tv2 = view2.findViewById(com.google.android.material.R.id.snackbar_text);
                            s2.show();
                        }
                        OfflineSubreddit.newSubreddit(CommentCacheAsync.SAVED_SUBMISSIONS).deleteFromMemory(submission.getFullName());
                    }
                    break;
                case 4:
                    Reddit.defaultShareText(CompatUtil.fromHtml(submission.getTitle()).toString(), StringEscapeUtils.escapeHtml4(submission.getUrl()), mContext);
                    break;
                case 12:
                    final MaterialDialog reportDialog = new MaterialDialog.Builder(mContext).customView(R.layout.report_dialog, true).title(R.string.report_post).positiveText(R.string.btn_report).negativeText(R.string.btn_cancel).onPositive(new MaterialDialog.SingleButtonCallback() {

                        @Override
                        public void onClick(MaterialDialog dialog, DialogAction which) {
                            RadioGroup reasonGroup = dialog.getCustomView().findViewById(R.id.report_reasons);
                            String reportReason;
                            if (reasonGroup.getCheckedRadioButtonId() == R.id.report_other) {
                                reportReason = ((EditText) dialog.getCustomView().findViewById(R.id.input_report_reason)).getText().toString();
                            } else {
                                reportReason = ((RadioButton) reasonGroup.findViewById(reasonGroup.getCheckedRadioButtonId())).getText().toString();
                            }
                            new PopulateBase.AsyncReportTask(submission, holder.itemView).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, reportReason);
                        }
                    }).build();
                    final RadioGroup reasonGroup = reportDialog.getCustomView().findViewById(R.id.report_reasons);
                    reasonGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(RadioGroup group, int checkedId) {
                            if (checkedId == R.id.report_other)
                                reportDialog.getCustomView().findViewById(R.id.input_report_reason).setVisibility(View.VISIBLE);
                            else
                                reportDialog.getCustomView().findViewById(R.id.input_report_reason).setVisibility(View.GONE);
                        }
                    });
                    // Load sub's report reasons and show the appropriate ones
                    new AsyncTask<Void, Void, Ruleset>() {

                        @Override
                        protected Ruleset doInBackground(Void... voids) {
                            return Authentication.reddit.getRules(submission.getSubredditName());
                        }

                        @Override
                        protected void onPostExecute(Ruleset rules) {
                            reportDialog.getCustomView().findViewById(R.id.report_loading).setVisibility(View.GONE);
                            if (rules.getSubredditRules().size() > 0) {
                                TextView subHeader = new TextView(mContext);
                                subHeader.setText(mContext.getString(R.string.report_sub_rules, submission.getSubredditName()));
                                reasonGroup.addView(subHeader, reasonGroup.getChildCount() - 2);
                            }
                            for (SubredditRule rule : rules.getSubredditRules()) {
                                if (rule.getKind() == SubredditRule.RuleKind.LINK || rule.getKind() == SubredditRule.RuleKind.ALL) {
                                    RadioButton btn = new RadioButton(mContext);
                                    btn.setText(rule.getViolationReason());
                                    reasonGroup.addView(btn, reasonGroup.getChildCount() - 2);
                                    btn.getLayoutParams().width = WindowManager.LayoutParams.MATCH_PARENT;
                                }
                            }
                            if (rules.getSiteRules().size() > 0) {
                                TextView siteHeader = new TextView(mContext);
                                siteHeader.setText(R.string.report_site_rules);
                                reasonGroup.addView(siteHeader, reasonGroup.getChildCount() - 2);
                            }
                            for (String rule : rules.getSiteRules()) {
                                RadioButton btn = new RadioButton(mContext);
                                btn.setText(rule);
                                reasonGroup.addView(btn, reasonGroup.getChildCount() - 2);
                                btn.getLayoutParams().width = WindowManager.LayoutParams.MATCH_PARENT;
                            }
                        }
                    }.execute();
                    reportDialog.show();
                    break;
                case 8:
                    Reddit.defaultShareText(CompatUtil.fromHtml(submission.getTitle()).toString(), "https://reddit.com" + submission.getPermalink(), mContext);
                    break;
                case 6:
                    {
                        ClipboardUtil.copyToClipboard(mContext, "Link", submission.getUrl());
                        Toast.makeText(mContext, R.string.submission_link_copied, Toast.LENGTH_SHORT).show();
                    }
                    break;
                case 25:
                    final TextView showText = new TextView(mContext);
                    showText.setText(StringEscapeUtils.unescapeHtml4(submission.getTitle() + "\n\n" + submission.getSelftext()));
                    showText.setTextIsSelectable(true);
                    int sixteen = DisplayUtil.dpToPxVertical(24);
                    showText.setPadding(sixteen, 0, sixteen, 0);
                    new AlertDialog.Builder(mContext).setView(showText).setTitle("Select text to copy").setCancelable(true).setPositiveButton("COPY SELECTED", (dialog13, which13) -> {
                        String selected = showText.getText().toString().substring(showText.getSelectionStart(), showText.getSelectionEnd());
                        if (!selected.isEmpty()) {
                            ClipboardUtil.copyToClipboard(mContext, "Selftext", selected);
                        } else {
                            ClipboardUtil.copyToClipboard(mContext, "Selftext", CompatUtil.fromHtml(submission.getTitle() + "\n\n" + submission.getSelftext()));
                        }
                        Toast.makeText(mContext, R.string.submission_comment_copied, Toast.LENGTH_SHORT).show();
                    }).setNegativeButton(R.string.btn_cancel, null).setNeutralButton("COPY ALL", (dialog14, which14) -> {
                        ClipboardUtil.copyToClipboard(mContext, "Selftext", StringEscapeUtils.unescapeHtml4(submission.getTitle() + "\n\n" + submission.getSelftext()));
                        Toast.makeText(mContext, R.string.submission_text_copied, Toast.LENGTH_SHORT).show();
                    }).show();
                    break;
            }
        }
    });
    b.show();
}
Also used : Arrays(java.util.Arrays) CommentCacheAsync(me.ccrama.redditslide.CommentCacheAsync) R(me.ccrama.redditslide.R) MainActivity(me.ccrama.redditslide.Activities.MainActivity) MediaView(me.ccrama.redditslide.Activities.MediaView) WindowManager(android.view.WindowManager) ImageView(android.widget.ImageView) RadioButton(android.widget.RadioButton) PostMatch(me.ccrama.redditslide.PostMatch) ContentType(me.ccrama.redditslide.ContentType) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan) DataShare(me.ccrama.redditslide.DataShare) Drawable(android.graphics.drawable.Drawable) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) Tumblr(me.ccrama.redditslide.Activities.Tumblr) Locale(java.util.Locale) View(android.view.View) MultiredditOverview(me.ccrama.redditslide.Activities.MultiredditOverview) RecyclerView(androidx.recyclerview.widget.RecyclerView) ContextCompat(androidx.core.content.ContextCompat) SubredditRule(net.dean.jraw.models.SubredditRule) NewsViewHolder(me.ccrama.redditslide.Adapters.NewsViewHolder) AsyncTask(android.os.AsyncTask) FullscreenVideo(me.ccrama.redditslide.Activities.FullscreenVideo) Album(me.ccrama.redditslide.Activities.Album) Ruleset(net.dean.jraw.models.Ruleset) Authentication(me.ccrama.redditslide.Authentication) DisplayUtil(me.ccrama.redditslide.util.DisplayUtil) Palette(me.ccrama.redditslide.Visuals.Palette) BlendModeUtil(me.ccrama.redditslide.util.BlendModeUtil) Profile(me.ccrama.redditslide.Activities.Profile) SubmissionCache(me.ccrama.redditslide.SubmissionCache) PeekViewActivity(me.ccrama.redditslide.ForceTouch.PeekViewActivity) AlbumPager(me.ccrama.redditslide.Activities.AlbumPager) OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) List(java.util.List) NetworkUtil(me.ccrama.redditslide.util.NetworkUtil) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Contribution(net.dean.jraw.models.Contribution) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Snackbar(com.google.android.material.snackbar.Snackbar) BottomSheet(com.cocosw.bottomsheet.BottomSheet) LayoutUtils(me.ccrama.redditslide.util.LayoutUtils) Context(android.content.Context) SettingValues(me.ccrama.redditslide.SettingValues) AlertDialog(androidx.appcompat.app.AlertDialog) ResourcesCompat(androidx.core.content.res.ResourcesCompat) HasSeen(me.ccrama.redditslide.HasSeen) Submission(net.dean.jraw.models.Submission) Intent(android.content.Intent) Hidden(me.ccrama.redditslide.Hidden) RadioGroup(android.widget.RadioGroup) TypedArray(android.content.res.TypedArray) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) TumblrPager(me.ccrama.redditslide.Activities.TumblrPager) Toast(android.widget.Toast) Search(me.ccrama.redditslide.Activities.Search) SubredditView(me.ccrama.redditslide.Activities.SubredditView) OpenRedditLink(me.ccrama.redditslide.OpenRedditLink) DialogInterface(android.content.DialogInterface) ClipboardUtil(me.ccrama.redditslide.util.ClipboardUtil) Reddit(me.ccrama.redditslide.Reddit) DialogAction(com.afollestad.materialdialogs.DialogAction) StringEscapeUtils(org.apache.commons.text.StringEscapeUtils) CompatUtil(me.ccrama.redditslide.util.CompatUtil) Color(android.graphics.Color) SharedPreferences(android.content.SharedPreferences) PostReadLater(me.ccrama.redditslide.Activities.PostReadLater) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) GifUtils(me.ccrama.redditslide.util.GifUtils) ActionStates(me.ccrama.redditslide.ActionStates) CommentAdapter(me.ccrama.redditslide.Adapters.CommentAdapter) LastComments(me.ccrama.redditslide.LastComments) Activity(android.app.Activity) Collections(java.util.Collections) EditText(android.widget.EditText) LinkUtil(me.ccrama.redditslide.util.LinkUtil) EXTRA_SUBMISSION_TITLE(me.ccrama.redditslide.Notifications.ImageDownloadNotificationService.EXTRA_SUBMISSION_TITLE) Ruleset(net.dean.jraw.models.Ruleset) RadioGroup(android.widget.RadioGroup) DialogInterface(android.content.DialogInterface) SpannableStringBuilder(android.text.SpannableStringBuilder) ArrayList(java.util.ArrayList) PostReadLater(me.ccrama.redditslide.Activities.PostReadLater) SubredditView(me.ccrama.redditslide.Activities.SubredditView) MainActivity(me.ccrama.redditslide.Activities.MainActivity) TypedArray(android.content.res.TypedArray) TextView(android.widget.TextView) SubredditRule(net.dean.jraw.models.SubredditRule) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Submission(net.dean.jraw.models.Submission) CommentCacheAsync(me.ccrama.redditslide.CommentCacheAsync) Drawable(android.graphics.drawable.Drawable) OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) RadioButton(android.widget.RadioButton) MediaView(me.ccrama.redditslide.Activities.MediaView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) DialogAction(com.afollestad.materialdialogs.DialogAction) BottomSheet(com.cocosw.bottomsheet.BottomSheet) Contribution(net.dean.jraw.models.Contribution) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 15 with Color

use of android.graphics.Color in project Slide by ccrama.

the class ToolboxUI method showUsernotes.

/**
 * Shows a user's usernotes in a dialog
 *
 * @param context     context
 * @param author      user to show usernotes for
 * @param subreddit   subreddit to get usernotes from
 * @param currentLink Link, in Toolbox format, for the current item - used for adding usernotes
 */
public static void showUsernotes(final Context context, String author, String subreddit, String currentLink) {
    final UsernoteListAdapter adapter = new UsernoteListAdapter(context, subreddit, author);
    new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.mod_usernotes_title, author)).setAdapter(adapter, null).setNeutralButton(R.string.mod_usernotes_add, (dialog, which) -> {
        // set up layout for add note dialog
        final LinearLayout layout = new LinearLayout(context);
        final Spinner spinner = new Spinner(context);
        final EditText noteText = new EditText(context);
        layout.addView(spinner);
        layout.addView(noteText);
        noteText.setHint(R.string.toolbox_note_text_placeholder);
        layout.setOrientation(LinearLayout.VERTICAL);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        spinner.setLayoutParams(params);
        noteText.setLayoutParams(params);
        // create list of types, add default "no type" type
        List<CharSequence> types = new ArrayList<>();
        SpannableStringBuilder defaultType = new SpannableStringBuilder(" " + context.getString(R.string.toolbox_note_default) + " ");
        defaultType.setSpan(new BackgroundColorSpan(Color.parseColor("#808080")), 0, defaultType.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        defaultType.setSpan(new ForegroundColorSpan(Color.WHITE), 0, defaultType.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        types.add(defaultType);
        // add additional types
        ToolboxConfig config = Toolbox.getConfig(subreddit);
        final Map<String, Map<String, String>> typeMap;
        if (config != null && config.getUsernoteTypes() != null && config.getUsernoteTypes().size() > 0) {
            typeMap = Toolbox.getConfig(subreddit).getUsernoteTypes();
        } else {
            typeMap = Toolbox.DEFAULT_USERNOTE_TYPES;
        }
        for (Map<String, String> stringStringMap : typeMap.values()) {
            SpannableStringBuilder typeString = new SpannableStringBuilder(" [" + stringStringMap.get("text") + "] ");
            typeString.setSpan(new BackgroundColorSpan(Color.parseColor(stringStringMap.get("color"))), 0, typeString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            typeString.setSpan(new ForegroundColorSpan(Color.WHITE), 0, typeString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            types.add(typeString);
        }
        spinner.setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_spinner_dropdown_item, types));
        // show add note dialog
        new MaterialDialog.Builder(context).customView(layout, true).autoDismiss(false).positiveText(R.string.btn_add).onPositive(new MaterialDialog.SingleButtonCallback() {

            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                if (noteText.getText().length() == 0) {
                    noteText.setError(context.getString(R.string.toolbox_note_text_required));
                    return;
                }
                int selected = spinner.getSelectedItemPosition();
                new AsyncAddUsernoteTask(context).execute(subreddit, author, noteText.getText().toString(), currentLink, selected - 1 >= 0 ? typeMap.keySet().toArray()[selected - 1].toString() : null);
                dialog.dismiss();
            }
        }).negativeText(R.string.btn_cancel).onNegative((dialog1, which1) -> dialog1.dismiss()).show();
    }).setPositiveButton(R.string.btn_close, null).show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) LinearLayout(android.widget.LinearLayout) R(me.ccrama.redditslide.R) NonNull(androidx.annotation.NonNull) URL(java.net.URL) Date(java.util.Date) Spannable(android.text.Spannable) RadioButton(android.widget.RadioButton) DistinguishedStatus(net.dean.jraw.models.DistinguishedStatus) RoundedBackgroundSpan(me.ccrama.redditslide.Views.RoundedBackgroundSpan) CheckBox(android.widget.CheckBox) Map(java.util.Map) View(android.view.View) ForegroundColorSpan(android.text.style.ForegroundColorSpan) AsyncTask(android.os.AsyncTask) Authentication(me.ccrama.redditslide.Authentication) ApiException(net.dean.jraw.ApiException) ViewGroup(android.view.ViewGroup) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Reauthenticate(me.ccrama.redditslide.Activities.Reauthenticate) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Context(android.content.Context) SettingValues(me.ccrama.redditslide.SettingValues) Spanned(android.text.Spanned) AlertDialog(androidx.appcompat.app.AlertDialog) ModerationManager(net.dean.jraw.managers.ModerationManager) PublicContribution(net.dean.jraw.models.PublicContribution) Submission(net.dean.jraw.models.Submission) SimpleDateFormat(java.text.SimpleDateFormat) Intent(android.content.Intent) RadioGroup(android.widget.RadioGroup) AccountManager(net.dean.jraw.managers.AccountManager) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) InboxManager(net.dean.jraw.managers.InboxManager) WeakReference(java.lang.ref.WeakReference) OpenRedditLink(me.ccrama.redditslide.OpenRedditLink) InvalidScopeException(net.dean.jraw.http.oauth.InvalidScopeException) MalformedURLException(java.net.MalformedURLException) LayoutInflater(android.view.LayoutInflater) TextUtils(android.text.TextUtils) BackgroundColorSpan(android.text.style.BackgroundColorSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan) DialogAction(com.afollestad.materialdialogs.DialogAction) Spinner(android.widget.Spinner) Color(android.graphics.Color) ArrayAdapter(android.widget.ArrayAdapter) TypedValue(android.util.TypedValue) NetworkException(net.dean.jraw.http.NetworkException) EditText(android.widget.EditText) Comment(net.dean.jraw.models.Comment) Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) NonNull(androidx.annotation.NonNull) EditText(android.widget.EditText) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ForegroundColorSpan(android.text.style.ForegroundColorSpan) DialogAction(com.afollestad.materialdialogs.DialogAction) Map(java.util.Map) LinearLayout(android.widget.LinearLayout) SpannableStringBuilder(android.text.SpannableStringBuilder) BackgroundColorSpan(android.text.style.BackgroundColorSpan)

Aggregations

Color (android.graphics.Color)17 View (android.view.View)16 TextView (android.widget.TextView)14 List (java.util.List)12 Context (android.content.Context)11 Bundle (android.os.Bundle)11 LayoutInflater (android.view.LayoutInflater)11 ArrayList (java.util.ArrayList)10 Toast (android.widget.Toast)9 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)9 Intent (android.content.Intent)8 ViewGroup (android.view.ViewGroup)8 Drawable (android.graphics.drawable.Drawable)7 ImageView (android.widget.ImageView)7 Activity (android.app.Activity)6 Log (android.util.Log)6 SharedPreferences (android.content.SharedPreferences)5 AsyncTask (android.os.AsyncTask)5 MenuItem (android.view.MenuItem)5 Resources (android.content.res.Resources)4