Search in sources :

Example 1 with Toolbox

use of me.ccrama.redditslide.Toolbox.Toolbox in project Slide by ccrama.

the class SettingsModerationFragment method Bind.

public void Bind() {
    final RelativeLayout removalReasonsLayout = context.findViewById(R.id.settings_moderation_removal_reasons);
    final TextView removalReasonsCurrentView = context.findViewById(R.id.settings_moderation_removal_reasons_current);
    final SwitchCompat enableToolboxSwitch = context.findViewById(R.id.settings_moderation_toolbox_enabled);
    final RelativeLayout removalMessageLayout = context.findViewById(R.id.settings_moderation_toolbox_message);
    final TextView removalMessageCurrentView = context.findViewById(R.id.settings_moderation_toolbox_message_current);
    final SwitchCompat sendMsgAsSubredditSwitch = context.findViewById(R.id.settings_moderation_toolbox_sendMsgAsSubreddit);
    final SwitchCompat stickyMessageSwitch = context.findViewById(R.id.settings_moderation_toolbox_sticky);
    final SwitchCompat lockAfterRemovalSwitch = context.findViewById(R.id.settings_moderation_toolbox_lock);
    final RelativeLayout refreshLayout = context.findViewById(R.id.settings_moderation_toolbox_refresh);
    // Set up removal reason setting
    if (SettingValues.removalReasonType == RemovalReasonType.SLIDE.ordinal()) {
        removalReasonsCurrentView.setText(context.getString(R.string.settings_mod_removal_slide));
    } else if (SettingValues.removalReasonType == RemovalReasonType.TOOLBOX.ordinal()) {
        removalReasonsCurrentView.setText(context.getString(R.string.settings_mod_removal_toolbox));
    } else {
        removalReasonsCurrentView.setText(context.getString(R.string.settings_mod_removal_reddit));
    }
    removalReasonsLayout.setOnClickListener(v -> {
        PopupMenu popupMenu = new PopupMenu(context, v);
        popupMenu.getMenuInflater().inflate(R.menu.removal_reason_setings, popupMenu.getMenu());
        popupMenu.getMenu().findItem(R.id.toolbox).setEnabled(SettingValues.toolboxEnabled);
        popupMenu.setOnMenuItemClickListener(item -> {
            switch(item.getItemId()) {
                case R.id.slide:
                    setModRemovalReasonType(removalReasonsCurrentView, RemovalReasonType.SLIDE.ordinal(), R.string.settings_mod_removal_slide);
                    break;
                case R.id.toolbox:
                    setModRemovalReasonType(removalReasonsCurrentView, RemovalReasonType.TOOLBOX.ordinal(), R.string.settings_mod_removal_toolbox);
                    break;
            }
            return true;
        });
        popupMenu.show();
    });
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // * Toolbox */
    // Set up toolbox enabled switch
    enableToolboxSwitch.setChecked(SettingValues.toolboxEnabled);
    enableToolboxSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
        SettingValues.toolboxEnabled = isChecked;
        editSharedBooleanPreference(SettingValues.PREF_MOD_TOOLBOX_ENABLED, isChecked);
        removalMessageLayout.setEnabled(isChecked);
        sendMsgAsSubredditSwitch.setEnabled(isChecked);
        stickyMessageSwitch.setEnabled(isChecked);
        lockAfterRemovalSwitch.setEnabled(isChecked);
        refreshLayout.setEnabled(isChecked);
        if (!isChecked) {
            setModRemovalReasonType(removalReasonsCurrentView, RemovalReasonType.SLIDE.ordinal(), R.string.settings_mod_removal_slide);
        }
        // download and cache toolbox stuff in the background unless it's already loaded
        for (String sub : UserSubscriptions.modOf) {
            Toolbox.ensureConfigCachedLoaded(sub, false);
            Toolbox.ensureUsernotesCachedLoaded(sub, false);
        }
    });
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Set up toolbox default removal type
    removalMessageLayout.setEnabled(SettingValues.toolboxEnabled);
    if (SettingValues.toolboxMessageType == ToolboxRemovalMessageType.COMMENT.ordinal()) {
        removalMessageCurrentView.setText(context.getString(R.string.toolbox_removal_comment));
    } else if (SettingValues.toolboxMessageType == ToolboxRemovalMessageType.PM.ordinal()) {
        removalMessageCurrentView.setText(context.getString(R.string.toolbox_removal_pm));
    } else if (SettingValues.toolboxMessageType == ToolboxRemovalMessageType.BOTH.ordinal()) {
        removalMessageCurrentView.setText(context.getString(R.string.toolbox_removal_both));
    } else {
        removalMessageCurrentView.setText(context.getString(R.string.toolbox_removal_none));
    }
    removalMessageLayout.setOnClickListener(v -> {
        PopupMenu popupMenu = new PopupMenu(context, v);
        popupMenu.getMenuInflater().inflate(R.menu.settings_toolbox_message, popupMenu.getMenu());
        popupMenu.setOnMenuItemClickListener(item -> {
            switch(item.getItemId()) {
                case R.id.comment:
                    setToolboxRemovalMessageType(removalMessageCurrentView, ToolboxRemovalMessageType.COMMENT.ordinal(), R.string.toolbox_removal_comment);
                    break;
                case R.id.pm:
                    setToolboxRemovalMessageType(removalMessageCurrentView, ToolboxRemovalMessageType.PM.ordinal(), R.string.toolbox_removal_pm);
                    break;
                case R.id.both:
                    setToolboxRemovalMessageType(removalMessageCurrentView, ToolboxRemovalMessageType.BOTH.ordinal(), R.string.toolbox_removal_both);
                    break;
                case R.id.none:
                    setToolboxRemovalMessageType(removalMessageCurrentView, ToolboxRemovalMessageType.NONE.ordinal(), R.string.toolbox_removal_none);
                    break;
            }
            return true;
        });
        popupMenu.show();
    });
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Set up modmail switch
    sendMsgAsSubredditSwitch.setEnabled(SettingValues.toolboxEnabled);
    sendMsgAsSubredditSwitch.setChecked(SettingValues.toolboxModmail);
    sendMsgAsSubredditSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
        SettingValues.toolboxModmail = isChecked;
        editSharedBooleanPreference(SettingValues.PREF_MOD_TOOLBOX_MODMAIL, isChecked);
    });
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Set up sticky switch
    stickyMessageSwitch.setEnabled(SettingValues.toolboxEnabled);
    stickyMessageSwitch.setChecked(SettingValues.toolboxSticky);
    stickyMessageSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
        SettingValues.toolboxSticky = isChecked;
        editSharedBooleanPreference(SettingValues.PREF_MOD_TOOLBOX_STICKY, isChecked);
    });
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Set up lock switch
    lockAfterRemovalSwitch.setEnabled(SettingValues.toolboxEnabled);
    lockAfterRemovalSwitch.setChecked(SettingValues.toolboxLock);
    lockAfterRemovalSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
        SettingValues.toolboxLock = isChecked;
        editSharedBooleanPreference(SettingValues.PREF_MOD_TOOLBOX_LOCK, isChecked);
    });
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Set up force refresh button
    refreshLayout.setEnabled(SettingValues.toolboxEnabled);
    refreshLayout.setOnClickListener(v -> new MaterialDialog.Builder(context).content(R.string.settings_mod_toolbox_refreshing).progress(false, UserSubscriptions.modOf.size() * 2).showListener(dialog -> new AsyncRefreshToolboxTask(dialog).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)).cancelable(false).show());
}
Also used : SettingValues(me.ccrama.redditslide.SettingValues) R(me.ccrama.redditslide.R) SwitchCompat(androidx.appcompat.widget.SwitchCompat) AsyncTask(android.os.AsyncTask) Toolbox(me.ccrama.redditslide.Toolbox.Toolbox) RemovalReasonType(me.ccrama.redditslide.SettingValues.RemovalReasonType) TextView(android.widget.TextView) PopupMenu(android.widget.PopupMenu) RelativeLayout(android.widget.RelativeLayout) UserSubscriptions(me.ccrama.redditslide.UserSubscriptions) ToolboxRemovalMessageType(me.ccrama.redditslide.SettingValues.ToolboxRemovalMessageType) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Activity(android.app.Activity) NetworkException(net.dean.jraw.http.NetworkException) DialogInterface(android.content.DialogInterface) RelativeLayout(android.widget.RelativeLayout) TextView(android.widget.TextView) SwitchCompat(androidx.appcompat.widget.SwitchCompat) PopupMenu(android.widget.PopupMenu)

Aggregations

Activity (android.app.Activity)1 DialogInterface (android.content.DialogInterface)1 AsyncTask (android.os.AsyncTask)1 PopupMenu (android.widget.PopupMenu)1 RelativeLayout (android.widget.RelativeLayout)1 TextView (android.widget.TextView)1 SwitchCompat (androidx.appcompat.widget.SwitchCompat)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 R (me.ccrama.redditslide.R)1 SettingValues (me.ccrama.redditslide.SettingValues)1 RemovalReasonType (me.ccrama.redditslide.SettingValues.RemovalReasonType)1 ToolboxRemovalMessageType (me.ccrama.redditslide.SettingValues.ToolboxRemovalMessageType)1 Toolbox (me.ccrama.redditslide.Toolbox.Toolbox)1 UserSubscriptions (me.ccrama.redditslide.UserSubscriptions)1 NetworkException (net.dean.jraw.http.NetworkException)1