use of me.ccrama.redditslide.Fragments.DrawerItemsDialog in project Slide by ccrama.
the class SettingsGeneralFragment method Bind.
/* Allow SettingsGeneral and Settings Activity classes to use the same XML functionality */
public void Bind() {
final RelativeLayout notifLayout = context.findViewById(R.id.settings_general_notifications);
final TextView notifCurrentView = context.findViewById(R.id.settings_general_notifications_current);
final RelativeLayout subNotifLayout = context.findViewById(R.id.settings_general_sub_notifications);
final TextView defaultSortingCurrentView = context.findViewById(R.id.settings_general_sorting_current);
context.findViewById(R.id.settings_general_drawer_items).setOnClickListener(v -> new DrawerItemsDialog(new MaterialDialog.Builder(context)).show());
{
SwitchCompat immersiveModeSwitch = context.findViewById(R.id.settings_general_immersivemode);
if (immersiveModeSwitch != null) {
immersiveModeSwitch.setChecked(SettingValues.immersiveMode);
immersiveModeSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingsThemeFragment.changed = true;
SettingValues.immersiveMode = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_IMMERSIVE_MODE, isChecked).apply();
});
}
}
{
SwitchCompat highClrSpaceSwitch = context.findViewById(R.id.settings_general_high_colorspace);
if (highClrSpaceSwitch != null) {
highClrSpaceSwitch.setChecked(SettingValues.highColorspaceImages);
highClrSpaceSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingsThemeFragment.changed = true;
SettingValues.highColorspaceImages = isChecked;
Reddit application = (Reddit) context.getApplication();
ImageLoaderUtils.initImageLoader(application.getApplicationContext());
application.defaultImageLoader = ImageLoaderUtils.imageLoader;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_HIGH_COLORSPACE_IMAGES, isChecked).apply();
});
}
}
{
SwitchCompat forceLangSwitch = context.findViewById(R.id.settings_general_forcelanguage);
if (forceLangSwitch != null) {
forceLangSwitch.setChecked(SettingValues.overrideLanguage);
forceLangSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingsThemeFragment.changed = true;
SettingValues.overrideLanguage = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_OVERRIDE_LANGUAGE, isChecked).apply();
}
});
}
}
// hide fab while scrolling
{
SwitchCompat alwaysShowFabSwitch = context.findViewById(R.id.settings_general_always_show_fab);
if (alwaysShowFabSwitch != null) {
alwaysShowFabSwitch.setChecked(SettingValues.alwaysShowFAB);
alwaysShowFabSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingsThemeFragment.changed = true;
SettingValues.alwaysShowFAB = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_ALWAYS_SHOW_FAB, isChecked).apply();
}
});
}
}
// Show image download button
{
SwitchCompat showDownloadBtnSwitch = context.findViewById(R.id.settings_general_show_download_button);
if (showDownloadBtnSwitch != null) {
showDownloadBtnSwitch.setChecked(SettingValues.imageDownloadButton);
showDownloadBtnSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingValues.imageDownloadButton = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_IMAGE_DOWNLOAD_BUTTON, isChecked).apply();
}
});
}
}
{
SwitchCompat subfolderSwitch = context.findViewById(R.id.settings_general_subfolder);
if (subfolderSwitch != null) {
subfolderSwitch.setChecked(SettingValues.imageSubfolders);
subfolderSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingValues.imageSubfolders = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_IMAGE_SUBFOLDERS, isChecked).apply();
}
});
}
}
final RelativeLayout setSaveLocationLayout = context.findViewById(R.id.settings_general_set_save_location);
if (setSaveLocationLayout != null) {
setSaveLocationLayout.setOnClickListener(v -> DialogUtil.showFolderChooserDialog(context));
}
TextView setSaveLocationView = context.findViewById(R.id.settings_general_set_save_location_view);
if (setSaveLocationView != null) {
String loc = Reddit.appRestart.getString("imagelocation", context.getString(R.string.settings_image_location_unset));
setSaveLocationView.setText(loc);
}
final SwitchCompat expandedMenuSwitch = context.findViewById(R.id.settings_general_expandedmenu);
if (expandedMenuSwitch != null) {
expandedMenuSwitch.setChecked(SettingValues.expandedToolbar);
expandedMenuSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingValues.expandedToolbar = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_EXPANDED_TOOLBAR, isChecked).apply();
});
}
final RelativeLayout viewTypeLayout = context.findViewById(R.id.settings_general_viewtype);
if (viewTypeLayout != null) {
viewTypeLayout.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Intent i = new Intent(context, SettingsViewType.class);
context.startActivity(i);
}
});
}
// FAB multi choice//
final RelativeLayout fabLayout = context.findViewById(R.id.settings_general_fab);
final TextView currentFabView = context.findViewById(R.id.settings_general_fab_current);
if (currentFabView != null && fabLayout != null) {
currentFabView.setText(SettingValues.fab ? SettingValues.fabType == FAB_DISMISS ? context.getString(R.string.fab_hide) : context.getString(R.string.fab_create) : context.getString(R.string.fab_disabled));
fabLayout.setOnClickListener(v -> {
PopupMenu popup = new PopupMenu(context, v);
popup.getMenuInflater().inflate(R.menu.fab_settings, popup.getMenu());
popup.setOnMenuItemClickListener(item -> {
switch(item.getItemId()) {
case R.id.disabled:
SettingValues.fab = false;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_FAB, false).apply();
break;
case R.id.hide:
SettingValues.fab = true;
SettingValues.fabType = FAB_DISMISS;
SettingValues.prefs.edit().putInt(SettingValues.PREF_FAB_TYPE, FAB_DISMISS).apply();
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_FAB, true).apply();
break;
case R.id.create:
SettingValues.fab = true;
SettingValues.fabType = FAB_POST;
SettingValues.prefs.edit().putInt(SettingValues.PREF_FAB_TYPE, FAB_POST).apply();
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_FAB, true).apply();
break;
case R.id.search:
SettingValues.fab = true;
SettingValues.fabType = FAB_SEARCH;
SettingValues.prefs.edit().putInt(SettingValues.PREF_FAB_TYPE, FAB_SEARCH).apply();
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_FAB, true).apply();
break;
}
if (SettingValues.fab) {
if (SettingValues.fabType == FAB_DISMISS) {
currentFabView.setText(R.string.fab_hide);
} else if (SettingValues.fabType == FAB_POST) {
currentFabView.setText(R.string.fab_create);
} else {
currentFabView.setText(R.string.fab_search);
}
} else {
currentFabView.setText(R.string.fab_disabled);
}
return true;
});
popup.show();
});
}
// SettingValues.subredditSearchMethod == 1 for drawer, 2 for toolbar, 3 for both
final TextView currentMethodTitle = context.findViewById(R.id.settings_general_subreddit_search_method_current);
if (currentMethodTitle != null) {
switch(SettingValues.subredditSearchMethod) {
case SUBREDDIT_SEARCH_METHOD_DRAWER:
currentMethodTitle.setText(context.getString(R.string.subreddit_search_method_drawer));
break;
case SUBREDDIT_SEARCH_METHOD_TOOLBAR:
currentMethodTitle.setText(context.getString(R.string.subreddit_search_method_toolbar));
break;
case SUBREDDIT_SEARCH_METHOD_BOTH:
currentMethodTitle.setText(context.getString(R.string.subreddit_search_method_both));
break;
}
}
final RelativeLayout currentMethodLayout = context.findViewById(R.id.settings_general_subreddit_search_method);
if (currentMethodLayout != null) {
currentMethodLayout.setOnClickListener(v -> {
final PopupMenu popup = new PopupMenu(SettingsGeneralFragment.this.context, v);
popup.getMenuInflater().inflate(R.menu.subreddit_search_settings, popup.getMenu());
popup.setOnMenuItemClickListener(item -> {
switch(item.getItemId()) {
case R.id.subreddit_search_drawer:
SettingValues.subredditSearchMethod = SUBREDDIT_SEARCH_METHOD_DRAWER;
SettingValues.prefs.edit().putInt(SettingValues.PREF_SUBREDDIT_SEARCH_METHOD, SUBREDDIT_SEARCH_METHOD_DRAWER).apply();
searchChanged = true;
break;
case R.id.subreddit_search_toolbar:
SettingValues.subredditSearchMethod = SUBREDDIT_SEARCH_METHOD_TOOLBAR;
SettingValues.prefs.edit().putInt(SettingValues.PREF_SUBREDDIT_SEARCH_METHOD, SUBREDDIT_SEARCH_METHOD_TOOLBAR).apply();
searchChanged = true;
break;
case R.id.subreddit_search_both:
SettingValues.subredditSearchMethod = SUBREDDIT_SEARCH_METHOD_BOTH;
SettingValues.prefs.edit().putInt(SettingValues.PREF_SUBREDDIT_SEARCH_METHOD, SUBREDDIT_SEARCH_METHOD_BOTH).apply();
searchChanged = true;
break;
}
switch(SettingValues.subredditSearchMethod) {
case SUBREDDIT_SEARCH_METHOD_DRAWER:
currentMethodTitle.setText(context.getString(R.string.subreddit_search_method_drawer));
break;
case SUBREDDIT_SEARCH_METHOD_TOOLBAR:
currentMethodTitle.setText(context.getString(R.string.subreddit_search_method_toolbar));
break;
case SUBREDDIT_SEARCH_METHOD_BOTH:
currentMethodTitle.setText(context.getString(R.string.subreddit_search_method_both));
break;
}
return true;
});
popup.show();
});
}
final TextView currentBackButtonTitle = context.findViewById(R.id.settings_general_back_button_behavior_current);
if (SettingValues.backButtonBehavior == BackButtonBehaviorOptions.ConfirmExit.getValue()) {
currentBackButtonTitle.setText(context.getString(R.string.back_button_behavior_confirm_exit));
} else if (SettingValues.backButtonBehavior == BackButtonBehaviorOptions.OpenDrawer.getValue()) {
currentBackButtonTitle.setText(context.getString(R.string.back_button_behavior_drawer));
} else if (SettingValues.backButtonBehavior == BackButtonBehaviorOptions.GotoFirst.getValue()) {
currentBackButtonTitle.setText(context.getString(R.string.back_button_behavior_goto_first));
} else {
currentBackButtonTitle.setText(context.getString(R.string.back_button_behavior_default));
}
final RelativeLayout currentBackButtonLayout = context.findViewById(R.id.settings_general_back_button_behavior);
currentBackButtonLayout.setOnClickListener(v -> {
final PopupMenu popup = new PopupMenu(context, v);
popup.getMenuInflater().inflate(R.menu.back_button_behavior_settings, popup.getMenu());
popup.setOnMenuItemClickListener(item -> {
switch(item.getItemId()) {
case R.id.back_button_behavior_default:
SettingValues.backButtonBehavior = BackButtonBehaviorOptions.Default.getValue();
SettingValues.prefs.edit().putInt(SettingValues.PREF_BACK_BUTTON_BEHAVIOR, BackButtonBehaviorOptions.Default.getValue()).apply();
break;
case R.id.back_button_behavior_confirm_exit:
SettingValues.backButtonBehavior = BackButtonBehaviorOptions.ConfirmExit.getValue();
SettingValues.prefs.edit().putInt(SettingValues.PREF_BACK_BUTTON_BEHAVIOR, BackButtonBehaviorOptions.ConfirmExit.getValue()).apply();
break;
case R.id.back_button_behavior_open_drawer:
SettingValues.backButtonBehavior = BackButtonBehaviorOptions.OpenDrawer.getValue();
SettingValues.prefs.edit().putInt(SettingValues.PREF_BACK_BUTTON_BEHAVIOR, BackButtonBehaviorOptions.OpenDrawer.getValue()).apply();
break;
case R.id.back_button_behavior_goto_first:
SettingValues.backButtonBehavior = BackButtonBehaviorOptions.GotoFirst.getValue();
SettingValues.prefs.edit().putInt(SettingValues.PREF_BACK_BUTTON_BEHAVIOR, BackButtonBehaviorOptions.GotoFirst.getValue()).apply();
break;
}
if (SettingValues.backButtonBehavior == BackButtonBehaviorOptions.ConfirmExit.getValue()) {
currentBackButtonTitle.setText(context.getString(R.string.back_button_behavior_confirm_exit));
} else if (SettingValues.backButtonBehavior == BackButtonBehaviorOptions.OpenDrawer.getValue()) {
currentBackButtonTitle.setText(context.getString(R.string.back_button_behavior_drawer));
} else if (SettingValues.backButtonBehavior == BackButtonBehaviorOptions.GotoFirst.getValue()) {
currentBackButtonTitle.setText(context.getString(R.string.back_button_behavior_goto_first));
} else {
currentBackButtonTitle.setText(context.getString(R.string.back_button_behavior_default));
}
return true;
});
popup.show();
});
if (notifCurrentView != null && context.findViewById(R.id.settings_general_sub_notifs_current) != null) {
if (Reddit.notificationTime > 0) {
notifCurrentView.setText(context.getString(R.string.settings_notification_short, TimeUtils.getTimeInHoursAndMins(Reddit.notificationTime, context.getBaseContext())));
setSubText();
} else {
notifCurrentView.setText(R.string.settings_notifdisabled);
((TextView) context.findViewById(R.id.settings_general_sub_notifs_current)).setText(R.string.settings_enable_notifs);
}
}
if (Authentication.isLoggedIn) {
if (notifLayout != null) {
notifLayout.setOnClickListener(v -> {
final LayoutInflater inflater = context.getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.inboxfrequency, null);
setupNotificationSettings(dialoglayout, SettingsGeneralFragment.this.context);
});
}
if (subNotifLayout != null) {
subNotifLayout.setOnClickListener(v -> showSelectDialog());
}
} else {
if (notifLayout != null) {
notifLayout.setEnabled(false);
notifLayout.setAlpha(0.25f);
}
if (subNotifLayout != null) {
subNotifLayout.setEnabled(false);
subNotifLayout.setAlpha(0.25f);
}
}
if (defaultSortingCurrentView != null) {
defaultSortingCurrentView.setText(SortingUtil.getSortingStrings()[SortingUtil.getSortingId("")]);
}
{
if (context.findViewById(R.id.settings_general_sorting) != null) {
context.findViewById(R.id.settings_general_sorting).setOnClickListener(v -> {
final DialogInterface.OnClickListener l2 = (dialogInterface, i) -> {
switch(i) {
case 0:
SortingUtil.defaultSorting = Sorting.HOT;
break;
case 1:
SortingUtil.defaultSorting = Sorting.NEW;
break;
case 2:
SortingUtil.defaultSorting = Sorting.RISING;
break;
case 3:
SortingUtil.defaultSorting = Sorting.TOP;
askTimePeriod();
return;
case 4:
SortingUtil.defaultSorting = Sorting.CONTROVERSIAL;
askTimePeriod();
return;
}
SettingValues.prefs.edit().putString("defaultSorting", SortingUtil.defaultSorting.name()).apply();
SettingValues.defaultSorting = SortingUtil.defaultSorting;
if (defaultSortingCurrentView != null) {
defaultSortingCurrentView.setText(SortingUtil.getSortingStrings()[SortingUtil.getSortingId("")]);
}
};
// Remove the "Best" sorting option from settings because it is only supported on the frontpage.
int skip = -1;
List<String> sortingStrings = new ArrayList<>(Arrays.asList(SortingUtil.getSortingStrings()));
for (int i = 0; i < sortingStrings.size(); i++) {
if (sortingStrings.get(i).equals(context.getString(R.string.sorting_best))) {
skip = i;
break;
}
}
if (skip != -1) {
sortingStrings.remove(skip);
}
new AlertDialog.Builder(SettingsGeneralFragment.this.context).setTitle(R.string.sorting_choose).setSingleChoiceItems(sortingStrings.toArray(new String[0]), SortingUtil.getSortingId(""), l2).show();
});
}
}
doNotifText(context);
{
final int i2 = SettingValues.defaultCommentSorting == CommentSort.CONFIDENCE ? 0 : SettingValues.defaultCommentSorting == CommentSort.TOP ? 1 : SettingValues.defaultCommentSorting == CommentSort.NEW ? 2 : SettingValues.defaultCommentSorting == CommentSort.CONTROVERSIAL ? 3 : SettingValues.defaultCommentSorting == CommentSort.OLD ? 4 : SettingValues.defaultCommentSorting == CommentSort.QA ? 5 : 0;
final TextView sortingCurrentCommentView = context.findViewById(R.id.settings_general_sorting_current_comment);
if (sortingCurrentCommentView != null) {
sortingCurrentCommentView.setText(SortingUtil.getSortingCommentsStrings()[i2]);
}
if (context.findViewById(R.id.settings_general_sorting_comment) != null) {
context.findViewById(R.id.settings_general_sorting_comment).setOnClickListener(v -> {
final DialogInterface.OnClickListener l2 = (dialogInterface, i) -> {
CommentSort commentSorting = SettingValues.defaultCommentSorting;
switch(i) {
case 0:
commentSorting = CommentSort.CONFIDENCE;
break;
case 1:
commentSorting = CommentSort.TOP;
break;
case 2:
commentSorting = CommentSort.NEW;
break;
case 3:
commentSorting = CommentSort.CONTROVERSIAL;
break;
case 4:
commentSorting = CommentSort.OLD;
break;
case 5:
commentSorting = CommentSort.QA;
break;
}
SettingValues.prefs.edit().putString("defaultCommentSortingNew", commentSorting.name()).apply();
SettingValues.defaultCommentSorting = commentSorting;
if (sortingCurrentCommentView != null) {
sortingCurrentCommentView.setText(SortingUtil.getSortingCommentsStrings()[i]);
}
};
Resources res = context.getBaseContext().getResources();
new AlertDialog.Builder(SettingsGeneralFragment.this.context).setTitle(R.string.sorting_choose).setSingleChoiceItems(new String[] { res.getString(R.string.sorting_best), res.getString(R.string.sorting_top), res.getString(R.string.sorting_new), res.getString(R.string.sorting_controversial), res.getString(R.string.sorting_old), res.getString(R.string.sorting_ama) }, i2, l2).show();
});
}
}
}
Aggregations