use of androidx.appcompat.widget.SwitchCompat in project Slide by ccrama.
the class SettingsActivity method setSettingItems.
private void setSettingItems() {
View pro = findViewById(R.id.settings_child_pro);
if (SettingValues.isPro) {
pro.setVisibility(View.GONE);
} else {
pro.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
ProUtil.proUpgradeMsg(SettingsActivity.this, R.string.settings_support_slide).setNegativeButton(R.string.btn_no_thanks, (dialog, whichButton) -> dialog.dismiss()).show();
}
});
}
((EditText) findViewById(R.id.settings_search)).addTextChangedListener(new SimpleTextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String text = s.toString().trim();
/* No idea why, but this event can fire many times when there is no change */
if (text.equalsIgnoreCase(prev_text))
return;
BuildLayout(text);
prev_text = text;
}
});
findViewById(R.id.settings_child_general).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Intent i = new Intent(SettingsActivity.this, SettingsGeneral.class);
startActivityForResult(i, RESTART_SETTINGS_RESULT);
}
});
findViewById(R.id.settings_child_history).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Intent i = new Intent(SettingsActivity.this, SettingsHistory.class);
startActivity(i);
}
});
findViewById(R.id.settings_child_about).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Intent i = new Intent(SettingsActivity.this, SettingsAbout.class);
startActivity(i);
}
});
findViewById(R.id.settings_child_offline).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(SettingsActivity.this, ManageOfflineContent.class);
startActivity(i);
}
});
findViewById(R.id.settings_child_datasave).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Intent i = new Intent(SettingsActivity.this, SettingsData.class);
startActivity(i);
}
});
findViewById(R.id.settings_child_subtheme).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Intent i = new Intent(SettingsActivity.this, SettingsSubreddit.class);
startActivityForResult(i, RESTART_SETTINGS_RESULT);
}
});
findViewById(R.id.settings_child_filter).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Intent i = new Intent(SettingsActivity.this, SettingsFilter.class);
startActivity(i);
}
});
findViewById(R.id.settings_child_synccit).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Intent i = new Intent(SettingsActivity.this, SettingsSynccit.class);
startActivity(i);
}
});
findViewById(R.id.settings_child_reorder).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(SettingsActivity.this, ReorderSubreddits.class);
startActivity(inte);
}
});
findViewById(R.id.settings_child_maintheme).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Intent i = new Intent(SettingsActivity.this, SettingsTheme.class);
startActivityForResult(i, RESTART_SETTINGS_RESULT);
}
});
findViewById(R.id.settings_child_handling).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Intent i = new Intent(SettingsActivity.this, SettingsHandling.class);
startActivity(i);
}
});
findViewById(R.id.settings_child_layout).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Intent i = new Intent(SettingsActivity.this, EditCardsLayout.class);
startActivity(i);
}
});
findViewById(R.id.settings_child_backup).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Intent i = new Intent(SettingsActivity.this, SettingsBackup.class);
startActivity(i);
}
});
findViewById(R.id.settings_child_font).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Intent i = new Intent(SettingsActivity.this, SettingsFont.class);
startActivity(i);
}
});
findViewById(R.id.settings_child_tablet).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
/* Intent inte = new Intent(Overview.this, Overview.class);
inte.putExtra("type", UpdateSubreddits.COLLECTIONS);
Overview.this.startActivity(inte);*/
if (SettingValues.isPro) {
LayoutInflater inflater = getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.tabletui, null);
final Resources res = getResources();
dialoglayout.findViewById(R.id.title).setBackgroundColor(Palette.getDefaultColor());
// todo final Slider portrait = (Slider) dialoglayout.findViewById(R.id.portrait);
final SeekBar landscape = dialoglayout.findViewById(R.id.landscape);
// todo portrait.setBackgroundColor(Palette.getDefaultColor());
landscape.setProgress(Reddit.dpWidth - 1);
((TextView) dialoglayout.findViewById(R.id.progressnumber)).setText(res.getQuantityString(R.plurals.landscape_columns, landscape.getProgress() + 1, landscape.getProgress() + 1));
landscape.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
((TextView) dialoglayout.findViewById(R.id.progressnumber)).setText(res.getQuantityString(R.plurals.landscape_columns, landscape.getProgress() + 1, landscape.getProgress() + 1));
SettingsActivity.changed = true;
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
final AlertDialog.Builder builder = new AlertDialog.Builder(SettingsActivity.this).setView(dialoglayout);
final Dialog dialog = builder.create();
dialog.show();
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
Reddit.dpWidth = landscape.getProgress() + 1;
Reddit.colors.edit().putInt("tabletOVERRIDE", landscape.getProgress() + 1).apply();
}
});
SwitchCompat s = dialog.findViewById(R.id.dualcolumns);
s.setChecked(SettingValues.dualPortrait);
s.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingValues.dualPortrait = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_DUAL_PORTRAIT, isChecked).apply();
}
});
SwitchCompat s2 = dialog.findViewById(R.id.fullcomment);
s2.setChecked(SettingValues.fullCommentOverride);
s2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingValues.fullCommentOverride = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_FULL_COMMENT_OVERRIDE, isChecked).apply();
}
});
SwitchCompat s3 = dialog.findViewById(R.id.singlecolumnmultiwindow);
s3.setChecked(SettingValues.singleColumnMultiWindow);
s3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingValues.singleColumnMultiWindow = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_SINGLE_COLUMN_MULTI, isChecked).apply();
}
});
} else {
ProUtil.proUpgradeMsg(SettingsActivity.this, R.string.general_multicolumn_ispro).setNegativeButton(R.string.btn_no_thanks, (dialog, whichButton) -> dialog.dismiss()).show();
}
}
});
if (BuildConfig.isFDroid) {
((TextView) findViewById(R.id.settings_child_donatetext)).setText("Donate via PayPal");
}
findViewById(R.id.settings_child_support).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
if (BuildConfig.isFDroid) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=56FKCCYLX7L72"));
startActivity(browserIntent);
} else {
Intent inte = new Intent(SettingsActivity.this, DonateView.class);
startActivity(inte);
}
}
});
findViewById(R.id.settings_child_comments).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Intent inte = new Intent(SettingsActivity.this, SettingsComments.class);
startActivity(inte);
}
});
if (Authentication.isLoggedIn && NetworkUtil.isConnected(this)) {
findViewById(R.id.settings_child_reddit_settings).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Intent i = new Intent(SettingsActivity.this, SettingsReddit.class);
startActivity(i);
}
});
} else {
findViewById(R.id.settings_child_reddit_settings).setEnabled(false);
findViewById(R.id.settings_child_reddit_settings).setAlpha(0.25f);
}
if (Authentication.mod) {
findViewById(R.id.settings_child_moderation).setVisibility(View.VISIBLE);
findViewById(R.id.settings_child_moderation).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(SettingsActivity.this, SettingsModeration.class);
startActivity(i);
}
});
}
}
use of androidx.appcompat.widget.SwitchCompat in project Slide by ccrama.
the class SettingsCommentsFragment method Bind.
public void Bind() {
final SwitchCompat commentsCropImageSwitch = context.findViewById(R.id.settings_comments_cropImage);
final SwitchCompat commentsColorDepthSwitch = context.findViewById(R.id.settings_comments_colorDepth);
final SwitchCompat commentsHighlightOpColorSwitch = context.findViewById(R.id.settings_comments_highlightOpColor);
final SwitchCompat commentsWideDepthSwitch = context.findViewById(R.id.settings_comments_wideDepth);
final SwitchCompat commentsShowCreateFabSwitch = context.findViewById(R.id.settings_comments_showCreateFab);
final SwitchCompat commentsRightHandedCommentsSwitch = context.findViewById(R.id.settings_comments_rightHandedComments);
final SwitchCompat commentsUpvotePercentSwitch = context.findViewById(R.id.settings_comments_upvotePercent);
final SwitchCompat commentsColoredTimeBubbleSwitch = context.findViewById(R.id.settings_comments_coloredTimeBubble);
final SwitchCompat commentsHideAwardsSwitch = context.findViewById(R.id.settings_comments_hideAwards);
final SwitchCompat commentsParentCommentNavSwitch = context.findViewById(R.id.settings_comments_parentCommentNav);
final TextView commentsAutohideNavbarView = context.findViewById(R.id.settings_comments_autohideCommentNavbarView);
final SwitchCompat commentsAutohideNavbarSwitch = context.findViewById(R.id.settings_comments_autohideCommentNavbar);
final TextView commentsShowCollapseExpandView = context.findViewById(R.id.settings_comments_showCollapseExpandView);
final SwitchCompat commentsShowCollapseExpandSwitch = context.findViewById(R.id.settings_comments_showCollapseExpand);
final SwitchCompat commentsVolumeNavCommentsSwitch = context.findViewById(R.id.settings_comments_volumeNavComments);
final SwitchCompat commentsNavbarVoteGesturesSwitch = context.findViewById(R.id.settings_comments_navbarVoteGestures);
final SwitchCompat commentsSwapLongpressTapSwitch = context.findViewById(R.id.settings_comments_swapLongpressTap);
final SwitchCompat commentsFullCollapseSwitch = context.findViewById(R.id.settings_comments_fullCollapse);
final SwitchCompat commentsCollapseChildCommentsSwitch = context.findViewById(R.id.settings_comments_collapseChildComments);
final SwitchCompat commentsCollapseDeletedCommentsSwitch = context.findViewById(R.id.settings_comments_collapseDeletedComments);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// * Display */
commentsCropImageSwitch.setChecked(SettingValues.cropImage);
commentsCropImageSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.cropImage = isChecked;
editSharedBooleanPreference(SettingValues.PREF_CROP_IMAGE, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commentsColorDepthSwitch.setChecked(SettingValues.colorCommentDepth);
commentsColorDepthSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.colorCommentDepth = isChecked;
editSharedBooleanPreference(SettingValues.PREF_COLOR_COMMENT_DEPTH, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commentsHighlightOpColorSwitch.setChecked(SettingValues.highlightCommentOP);
commentsHighlightOpColorSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.highlightCommentOP = isChecked;
editSharedBooleanPreference(SettingValues.PREF_HIGHLIGHT_COMMENT_OP, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commentsWideDepthSwitch.setChecked(SettingValues.largeDepth);
commentsWideDepthSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.largeDepth = isChecked;
editSharedBooleanPreference(SettingValues.PREF_LARGE_DEPTH, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commentsShowCreateFabSwitch.setChecked(SettingValues.fabComments);
commentsShowCreateFabSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.fabComments = isChecked;
editSharedBooleanPreference(SettingValues.PREF_COMMENT_FAB, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commentsRightHandedCommentsSwitch.setChecked(SettingValues.rightHandedCommentMenu);
commentsRightHandedCommentsSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.rightHandedCommentMenu = isChecked;
editSharedBooleanPreference(SettingValues.PREF_RIGHT_HANDED_COMMENT_MENU, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commentsUpvotePercentSwitch.setChecked(SettingValues.upvotePercentage);
commentsUpvotePercentSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.upvotePercentage = isChecked;
editSharedBooleanPreference(SettingValues.PREF_UPVOTE_PERCENTAGE, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commentsColoredTimeBubbleSwitch.setChecked(SettingValues.highlightTime);
commentsColoredTimeBubbleSwitch.setEnabled(SettingValues.commentLastVisit);
commentsColoredTimeBubbleSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.highlightTime = isChecked;
editSharedBooleanPreference(SettingValues.PREF_HIGHLIGHT_TIME, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commentsHideAwardsSwitch.setChecked(SettingValues.hideCommentAwards);
commentsHideAwardsSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.hideCommentAwards = isChecked;
editSharedBooleanPreference(SettingValues.PREF_HIDE_COMMENT_AWARDS, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// * Navigation */
commentsParentCommentNavSwitch.setChecked(SettingValues.fastscroll);
commentsParentCommentNavSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.fastscroll = isChecked;
editSharedBooleanPreference(SettingValues.PREF_FASTSCROLL, isChecked);
// Disable autohidenav and showcollapseexpand if commentNav isn't checked
if (!isChecked) {
commentsAutohideNavbarSwitch.setEnabled(false);
commentsAutohideNavbarSwitch.setChecked(SettingValues.commentAutoHide);
commentsAutohideNavbarView.setAlpha(0.25f);
commentsShowCollapseExpandSwitch.setEnabled(false);
commentsShowCollapseExpandSwitch.setChecked(SettingValues.commentAutoHide);
commentsShowCollapseExpandView.setAlpha(0.25f);
} else {
commentsAutohideNavbarSwitch.setEnabled(true);
commentsAutohideNavbarView.setAlpha(1f);
commentsShowCollapseExpandSwitch.setEnabled(true);
commentsShowCollapseExpandView.setAlpha(1f);
}
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commentsAutohideNavbarSwitch.setChecked(SettingValues.commentAutoHide);
if (!commentsParentCommentNavSwitch.isChecked()) {
commentsAutohideNavbarSwitch.setEnabled(false);
commentsAutohideNavbarView.setAlpha(0.25f);
}
commentsAutohideNavbarSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.commentAutoHide = isChecked;
editSharedBooleanPreference(SettingValues.PREF_AUTOHIDE_COMMENTS, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commentsShowCollapseExpandSwitch.setChecked(SettingValues.showCollapseExpand);
if (!commentsParentCommentNavSwitch.isChecked()) {
commentsShowCollapseExpandSwitch.setEnabled(false);
commentsShowCollapseExpandView.setAlpha(0.25f);
}
commentsShowCollapseExpandSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.showCollapseExpand = isChecked;
editSharedBooleanPreference(SettingValues.PREF_SHOW_COLLAPSE_EXPAND, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commentsVolumeNavCommentsSwitch.setChecked(SettingValues.commentVolumeNav);
commentsVolumeNavCommentsSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.commentVolumeNav = isChecked;
editSharedBooleanPreference(SettingValues.PREF_COMMENT_NAV, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commentsNavbarVoteGesturesSwitch.setChecked(SettingValues.voteGestures);
commentsNavbarVoteGesturesSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.voteGestures = isChecked;
editSharedBooleanPreference(SettingValues.PREF_VOTE_GESTURES, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// * Collapse actions */
commentsSwapLongpressTapSwitch.setChecked(SettingValues.swap);
commentsSwapLongpressTapSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.swap = isChecked;
editSharedBooleanPreference(SettingValues.PREF_SWAP, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commentsFullCollapseSwitch.setChecked(SettingValues.collapseComments);
commentsFullCollapseSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.collapseComments = isChecked;
editSharedBooleanPreference(SettingValues.PREF_COLLAPSE_COMMENTS, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commentsCollapseChildCommentsSwitch.setChecked(SettingValues.collapseCommentsDefault);
commentsCollapseChildCommentsSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.collapseCommentsDefault = isChecked;
editSharedBooleanPreference(SettingValues.PREF_COLLAPSE_COMMENTS_DEFAULT, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commentsCollapseDeletedCommentsSwitch.setChecked(SettingValues.collapseDeletedComments);
commentsCollapseDeletedCommentsSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.collapseDeletedComments = isChecked;
editSharedBooleanPreference(SettingValues.PREF_COLLAPSE_DELETED_COMMENTS, isChecked);
});
}
use of androidx.appcompat.widget.SwitchCompat 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());
}
use of androidx.appcompat.widget.SwitchCompat in project Slide by ccrama.
the class ManageOfflineContentFragment method Bind.
public void Bind() {
if (!NetworkUtil.isConnected(context))
SettingsThemeFragment.changed = true;
context.findViewById(R.id.manage_history_clear_all).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean wifi = Reddit.cachedData.getBoolean("wifiOnly", false);
String sync = Reddit.cachedData.getString("toCache", "");
int hour = (Reddit.cachedData.getInt("hour", 0));
int minute = (Reddit.cachedData.getInt("minute", 0));
Reddit.cachedData.edit().clear().apply();
Reddit.cachedData.edit().putBoolean("wifiOnly", wifi).putString("toCache", sync).putInt("hour", hour).putInt("minute", minute).apply();
context.finish();
}
});
if (NetworkUtil.isConnectedNoOverride(context)) {
context.findViewById(R.id.manage_history_sync_now).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new CommentCacheAsync(context, Reddit.cachedData.getString("toCache", "").split(",")).execute();
}
});
} else {
context.findViewById(R.id.manage_history_sync_now).setVisibility(View.GONE);
}
{
SwitchCompat single = context.findViewById(R.id.manage_history_wifi);
single.setChecked(Reddit.cachedData.getBoolean("wifiOnly", false));
single.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Reddit.cachedData.edit().putBoolean("wifiOnly", isChecked).apply();
}
});
}
updateBackup();
updateFilters();
final List<String> commentDepths = ImmutableList.of("2", "4", "6", "8", "10");
final String[] commentDepthArray = new String[commentDepths.size()];
context.findViewById(R.id.manage_history_comments_depth).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String commentDepth = SettingValues.prefs.getString(SettingValues.COMMENT_DEPTH, "2");
new AlertDialog.Builder(context).setTitle(R.string.comments_depth).setSingleChoiceItems(commentDepths.toArray(commentDepthArray), commentDepths.indexOf(commentDepth), (dialog, which) -> SettingValues.prefs.edit().putString(SettingValues.COMMENT_DEPTH, commentDepths.get(which)).apply()).show();
}
});
final List<String> commentCounts = ImmutableList.of("20", "40", "60", "80", "100");
final String[] commentCountArray = new String[commentCounts.size()];
context.findViewById(R.id.manage_history_comments_count).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String commentCount = SettingValues.prefs.getString(SettingValues.COMMENT_COUNT, "2");
new AlertDialog.Builder(context).setTitle(R.string.comments_count).setSingleChoiceItems(commentCounts.toArray(commentCountArray), commentCounts.indexOf(commentCount), (dialog, which) -> SettingValues.prefs.edit().putString(SettingValues.COMMENT_COUNT, commentCounts.get(which)).apply()).show();
}
});
context.findViewById(R.id.manage_history_autocache).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<String> sorted = UserSubscriptions.sort(UserSubscriptions.getSubscriptions(context));
final String[] all = new String[sorted.size()];
boolean[] checked = new boolean[all.length];
int i = 0;
List<String> s2 = new ArrayList<>();
Collections.addAll(s2, Reddit.cachedData.getString("toCache", "").split(","));
for (String s : sorted) {
all[i] = s;
if (s2.contains(s)) {
checked[i] = true;
}
i++;
}
final ArrayList<String> toCheck = new ArrayList<>(s2);
new AlertDialog.Builder(context).setMultiChoiceItems(all, checked, (dialog, which, isChecked) -> {
if (!isChecked) {
toCheck.remove(all[which]);
} else {
toCheck.add(all[which]);
}
}).setTitle(R.string.multireddit_selector).setPositiveButton(context.getString(R.string.btn_add).toUpperCase(), (dialog, which) -> {
Reddit.cachedData.edit().putString("toCache", StringUtil.arrayToString(toCheck)).apply();
updateBackup();
}).show();
}
});
updateTime();
context.findViewById(R.id.manage_history_autocache_time_touch).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final TimePickerDialog d = new TimePickerDialog(context);
d.hour(Reddit.cachedData.getInt("hour", 0));
d.minute(Reddit.cachedData.getInt("minute", 0));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
d.applyStyle(new ColorPreferences(context).getFontStyle().getBaseId());
d.positiveAction("SET");
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
theme.resolveAttribute(R.attr.activity_background, typedValue, true);
int color = typedValue.data;
d.backgroundColor(color);
d.actionTextColor(context.getResources().getColor(new ColorPreferences(context).getFontStyle().getColor()));
d.positiveActionClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Reddit.cachedData.edit().putInt("hour", d.getHour()).putInt("minute", d.getMinute()).commit();
Reddit.autoCache = new AutoCacheScheduler(context);
Reddit.autoCache.start();
updateTime();
d.dismiss();
}
});
theme.resolveAttribute(R.attr.fontColor, typedValue, true);
int color2 = typedValue.data;
d.setTitle(context.getString(R.string.choose_sync_time));
d.titleColor(color2);
d.show();
}
});
}
use of androidx.appcompat.widget.SwitchCompat in project Slide by ccrama.
the class SettingsHistoryFragment method Bind.
public void Bind() {
final SwitchCompat storeHistorySwitch = context.findViewById(R.id.settings_history_storehistory);
final SwitchCompat storeNsfwHistorySwitch = context.findViewById(R.id.settings_history_storensfw);
final SwitchCompat scrollSeenSwitch = context.findViewById(R.id.settings_history_scrollseen);
final RelativeLayout clearPostsLayout = context.findViewById(R.id.settings_history_clearposts);
final RelativeLayout clearSubsLayout = context.findViewById(R.id.settings_history_clearsubs);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// * Save history */
storeHistorySwitch.setChecked(SettingValues.storeHistory);
storeHistorySwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.storeHistory = isChecked;
editSharedBooleanPreference(SettingValues.PREF_STORE_HISTORY, isChecked);
if (isChecked) {
scrollSeenSwitch.setEnabled(true);
storeNsfwHistorySwitch.setEnabled(true);
} else {
storeNsfwHistorySwitch.setChecked(false);
storeNsfwHistorySwitch.setEnabled(false);
SettingValues.storeNSFWHistory = false;
editSharedBooleanPreference(SettingValues.PREF_STORE_NSFW_HISTORY, false);
scrollSeenSwitch.setChecked(false);
scrollSeenSwitch.setEnabled(false);
SettingValues.scrollSeen = false;
editSharedBooleanPreference(SettingValues.PREF_SCROLL_SEEN, false);
}
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
storeNsfwHistorySwitch.setChecked(SettingValues.storeNSFWHistory);
storeNsfwHistorySwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.storeNSFWHistory = isChecked;
editSharedBooleanPreference(SettingValues.PREF_STORE_NSFW_HISTORY, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
scrollSeenSwitch.setChecked(SettingValues.scrollSeen);
scrollSeenSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.scrollSeen = isChecked;
editSharedBooleanPreference(SettingValues.PREF_SCROLL_SEEN, isChecked);
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// * Clear history */
clearPostsLayout.setOnClickListener(v -> {
KVStore.getInstance().clearTable();
showHistoryClearedDialog();
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clearSubsLayout.setOnClickListener(v -> {
UserSubscriptions.subscriptions.edit().remove("subhistory").apply();
showHistoryClearedDialog();
});
}
Aggregations