use of com.afollestad.materialdialogs.DialogAction in project Slide by ccrama.
the class MainActivity method doDrawer.
public void doDrawer() {
drawerSubList = (ListView) findViewById(R.id.drawerlistview);
drawerSubList.setDividerHeight(0);
drawerSubList.setDescendantFocusability(ListView.FOCUS_BEFORE_DESCENDANTS);
final LayoutInflater inflater = getLayoutInflater();
final View header;
if (Authentication.isLoggedIn && Authentication.didOnline) {
header = inflater.inflate(R.layout.drawer_loggedin, drawerSubList, false);
headerMain = header;
hea = header.findViewById(R.id.back);
drawerSubList.addHeaderView(header, null, false);
((TextView) header.findViewById(R.id.name)).setText(Authentication.name);
header.findViewById(R.id.multi).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
if (runAfterLoad == null) {
Intent inte = new Intent(MainActivity.this, MultiredditOverview.class);
MainActivity.this.startActivity(inte);
}
}
});
header.findViewById(R.id.multi).setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
new MaterialDialog.Builder(MainActivity.this).inputRange(3, 20).alwaysCallInputCallback().input(getString(R.string.user_enter), null, new MaterialDialog.InputCallback() {
@Override
public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
final EditText editText = dialog.getInputEditText();
EditTextValidator.validateUsername(editText);
if (input.length() >= 3 && input.length() <= 20) {
dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
}
}
}).positiveText(R.string.user_btn_gotomultis).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
if (runAfterLoad == null) {
Intent inte = new Intent(MainActivity.this, MultiredditOverview.class);
inte.putExtra(Profile.EXTRA_PROFILE, dialog.getInputEditText().getText().toString());
MainActivity.this.startActivity(inte);
}
}
}).negativeText(R.string.btn_cancel).show();
return true;
}
});
header.findViewById(R.id.discover).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Discover.class);
MainActivity.this.startActivity(inte);
}
});
header.findViewById(R.id.prof_click).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Profile.class);
inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
MainActivity.this.startActivity(inte);
}
});
header.findViewById(R.id.saved).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Profile.class);
inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
inte.putExtra(Profile.EXTRA_SAVED, true);
MainActivity.this.startActivity(inte);
}
});
header.findViewById(R.id.later).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, PostReadLater.class);
MainActivity.this.startActivity(inte);
}
});
header.findViewById(R.id.history).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Profile.class);
inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
inte.putExtra(Profile.EXTRA_HISTORY, true);
MainActivity.this.startActivity(inte);
}
});
header.findViewById(R.id.commented).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Profile.class);
inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
inte.putExtra(Profile.EXTRA_COMMENT, true);
MainActivity.this.startActivity(inte);
}
});
header.findViewById(R.id.submitted).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Profile.class);
inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
inte.putExtra(Profile.EXTRA_SUBMIT, true);
MainActivity.this.startActivity(inte);
}
});
header.findViewById(R.id.upvoted).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Profile.class);
inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
inte.putExtra(Profile.EXTRA_UPVOTE, true);
MainActivity.this.startActivity(inte);
}
});
/**
* If the user is a known mod, show the "Moderation" drawer item quickly to
* stop the UI from jumping
*/
if (modOf != null && !modOf.isEmpty() && Authentication.mod) {
header.findViewById(R.id.mod).setVisibility(View.VISIBLE);
}
// update notification badge
final LinearLayout profStuff = header.findViewById(R.id.accountsarea);
profStuff.setVisibility(View.GONE);
findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (profStuff.getVisibility() == View.GONE) {
expand(profStuff);
header.setContentDescription(getResources().getString(R.string.btn_collapse));
AnimatorUtil.flipAnimator(false, header.findViewById(R.id.headerflip)).start();
} else {
collapse(profStuff);
header.setContentDescription(getResources().getString(R.string.btn_expand));
AnimatorUtil.flipAnimator(true, header.findViewById(R.id.headerflip)).start();
}
}
});
for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
if (s.contains(":")) {
accounts.put(s.split(":")[0], s.split(":")[1]);
} else {
accounts.put(s, "");
}
}
final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
final LinearLayout accountList = header.findViewById(R.id.accountsarea);
for (final String accName : keys) {
LogUtil.v(accName);
final View t = getLayoutInflater().inflate(R.layout.account_textview_white, accountList, false);
((TextView) t.findViewById(R.id.name)).setText(accName);
LogUtil.v("Adding click to " + ((TextView) t.findViewById(R.id.name)).getText());
t.findViewById(R.id.remove).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(MainActivity.this).setTitle(R.string.profile_remove).setMessage(R.string.profile_remove_account).setNegativeButton(R.string.btn_delete, (dialog2, which2) -> {
Set<String> accounts2 = Authentication.authentication.getStringSet("accounts", new HashSet<>());
Set<String> done = new HashSet<>();
for (String s : accounts2) {
if (!s.contains(accName)) {
done.add(s);
}
}
Authentication.authentication.edit().putStringSet("accounts", done).commit();
dialog2.dismiss();
accountList.removeView(t);
if (accName.equalsIgnoreCase(Authentication.name)) {
boolean d = false;
for (String s : keys) {
if (!s.equalsIgnoreCase(accName)) {
d = true;
LogUtil.v("Switching to " + s);
for (Map.Entry<String, String> e : accounts.entrySet()) {
LogUtil.v(e.getKey() + ":" + e.getValue());
}
if (accounts.containsKey(s) && !accounts.get(s).isEmpty()) {
Authentication.authentication.edit().putString("lasttoken", accounts.get(s)).remove("backedCreds").commit();
} else {
ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<>()));
int index = keys.indexOf(s);
if (keys.indexOf(s) > tokens.size()) {
index -= 1;
}
Authentication.authentication.edit().putString("lasttoken", tokens.get(index)).remove("backedCreds").commit();
}
Authentication.name = s;
UserSubscriptions.switchAccounts();
Reddit.forceRestart(MainActivity.this, true);
break;
}
}
if (!d) {
Authentication.name = "LOGGEDOUT";
Authentication.isLoggedIn = false;
Authentication.authentication.edit().remove("lasttoken").remove("backedCreds").commit();
UserSubscriptions.switchAccounts();
Reddit.forceRestart(MainActivity.this, true);
}
} else {
accounts.remove(accName);
keys.remove(accName);
}
}).setPositiveButton(R.string.btn_cancel, null).show();
}
});
t.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String accName = ((TextView) t.findViewById(R.id.name)).getText().toString();
LogUtil.v("Found name is " + accName);
if (!accName.equalsIgnoreCase(Authentication.name)) {
LogUtil.v("Switching to " + accName);
if (!accounts.get(accName).isEmpty()) {
LogUtil.v("Using token " + accounts.get(accName));
Authentication.authentication.edit().putString("lasttoken", accounts.get(accName)).remove("backedCreds").apply();
} else {
ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<String>()));
Authentication.authentication.edit().putString("lasttoken", tokens.get(keys.indexOf(accName))).remove("backedCreds").apply();
}
Authentication.name = accName;
UserSubscriptions.switchAccounts();
Reddit.forceRestart(MainActivity.this, true);
}
}
});
accountList.addView(t);
}
header.findViewById(R.id.godown).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LinearLayout body = header.findViewById(R.id.expand_profile);
if (body.getVisibility() == View.GONE) {
expand(body);
AnimatorUtil.flipAnimator(false, view).start();
view.findViewById(R.id.godown).setContentDescription(getResources().getString(R.string.btn_collapse));
} else {
collapse(body);
AnimatorUtil.flipAnimator(true, view).start();
view.findViewById(R.id.godown).setContentDescription(getResources().getString(R.string.btn_expand));
}
}
});
header.findViewById(R.id.guest_mode).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Authentication.name = "LOGGEDOUT";
Authentication.isLoggedIn = false;
Authentication.authentication.edit().remove("lasttoken").remove("backedCreds").apply();
UserSubscriptions.switchAccounts();
Reddit.forceRestart(MainActivity.this, true);
}
});
header.findViewById(R.id.add).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Login.class);
MainActivity.this.startActivity(inte);
}
});
header.findViewById(R.id.offline).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Reddit.appRestart.edit().putBoolean("forceoffline", true).commit();
Reddit.forceRestart(MainActivity.this, false);
}
});
header.findViewById(R.id.inbox).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Inbox.class);
MainActivity.this.startActivityForResult(inte, INBOX_RESULT);
}
});
headerMain = header;
if (runAfterLoad == null) {
new AsyncNotificationBadge().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
} else if (Authentication.didOnline) {
header = inflater.inflate(R.layout.drawer_loggedout, drawerSubList, false);
drawerSubList.addHeaderView(header, null, false);
headerMain = header;
hea = header.findViewById(R.id.back);
final LinearLayout profStuff = header.findViewById(R.id.accountsarea);
profStuff.setVisibility(View.GONE);
findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (profStuff.getVisibility() == View.GONE) {
expand(profStuff);
AnimatorUtil.flipAnimator(false, header.findViewById(R.id.headerflip)).start();
header.findViewById(R.id.headerflip).setContentDescription(getResources().getString(R.string.btn_collapse));
} else {
collapse(profStuff);
AnimatorUtil.flipAnimator(true, header.findViewById(R.id.headerflip)).start();
header.findViewById(R.id.headerflip).setContentDescription(getResources().getString(R.string.btn_expand));
}
}
});
final HashMap<String, String> accounts = new HashMap<>();
for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
if (s.contains(":")) {
accounts.put(s.split(":")[0], s.split(":")[1]);
} else {
accounts.put(s, "");
}
}
final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
final LinearLayout accountList = header.findViewById(R.id.accountsarea);
for (final String accName : keys) {
LogUtil.v(accName);
final View t = getLayoutInflater().inflate(R.layout.account_textview_white, accountList, false);
((TextView) t.findViewById(R.id.name)).setText(accName);
t.findViewById(R.id.remove).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(MainActivity.this).setTitle(R.string.profile_remove).setMessage(R.string.profile_remove_account).setNegativeButton(R.string.btn_delete, (dialog2, which2) -> {
Set<String> accounts2 = Authentication.authentication.getStringSet("accounts", new HashSet<>());
Set<String> done = new HashSet<>();
for (String s : accounts2) {
if (!s.contains(accName)) {
done.add(s);
}
}
Authentication.authentication.edit().putStringSet("accounts", done).commit();
dialog2.dismiss();
accountList.removeView(t);
if (accName.equalsIgnoreCase(Authentication.name)) {
boolean d = false;
for (String s : keys) {
if (!s.equalsIgnoreCase(accName)) {
d = true;
LogUtil.v("Switching to " + s);
if (!accounts.get(s).isEmpty()) {
Authentication.authentication.edit().putString("lasttoken", accounts.get(s)).remove("backedCreds").commit();
} else {
ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<>()));
Authentication.authentication.edit().putString("lasttoken", tokens.get(keys.indexOf(s))).remove("backedCreds").commit();
}
Authentication.name = s;
UserSubscriptions.switchAccounts();
Reddit.forceRestart(MainActivity.this, true);
}
}
if (!d) {
Authentication.name = "LOGGEDOUT";
Authentication.isLoggedIn = false;
Authentication.authentication.edit().remove("lasttoken").remove("backedCreds").commit();
UserSubscriptions.switchAccounts();
Reddit.forceRestart(MainActivity.this, true);
}
} else {
accounts.remove(accName);
keys.remove(accName);
}
}).setPositiveButton(R.string.btn_cancel, null).show();
}
});
t.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
if (!accName.equalsIgnoreCase(Authentication.name)) {
if (!accounts.get(accName).isEmpty()) {
Authentication.authentication.edit().putString("lasttoken", accounts.get(accName)).remove("backedCreds").commit();
} else {
ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<String>()));
Authentication.authentication.edit().putString("lasttoken", tokens.get(keys.indexOf(accName))).remove("backedCreds").commit();
}
Authentication.isLoggedIn = true;
Authentication.name = accName;
UserSubscriptions.switchAccounts();
Reddit.forceRestart(MainActivity.this, true);
}
}
});
accountList.addView(t);
}
header.findViewById(R.id.add).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Login.class);
MainActivity.this.startActivity(inte);
}
});
header.findViewById(R.id.offline).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Reddit.appRestart.edit().putBoolean("forceoffline", true).commit();
Reddit.forceRestart(MainActivity.this, false);
}
});
headerMain = header;
header.findViewById(R.id.multi).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new MaterialDialog.Builder(MainActivity.this).inputRange(3, 20).alwaysCallInputCallback().input(getString(R.string.user_enter), null, new MaterialDialog.InputCallback() {
@Override
public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
final EditText editText = dialog.getInputEditText();
EditTextValidator.validateUsername(editText);
if (input.length() >= 3 && input.length() <= 20) {
dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
}
}
}).positiveText(R.string.user_btn_gotomultis).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
if (runAfterLoad == null) {
Intent inte = new Intent(MainActivity.this, MultiredditOverview.class);
inte.putExtra(Profile.EXTRA_PROFILE, dialog.getInputEditText().getText().toString());
MainActivity.this.startActivity(inte);
}
}
}).negativeText(R.string.btn_cancel).show();
}
});
} else {
header = inflater.inflate(R.layout.drawer_offline, drawerSubList, false);
headerMain = header;
drawerSubList.addHeaderView(header, null, false);
hea = header.findViewById(R.id.back);
header.findViewById(R.id.online).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Reddit.appRestart.edit().remove("forceoffline").commit();
Reddit.forceRestart(MainActivity.this, false);
}
});
}
final LinearLayout expandSettings = header.findViewById(R.id.expand_settings);
header.findViewById(R.id.godown_settings).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (expandSettings.getVisibility() == View.GONE) {
expand(expandSettings);
header.findViewById(R.id.godown_settings).setContentDescription(getResources().getString(R.string.btn_collapse));
AnimatorUtil.flipAnimator(false, v).start();
} else {
collapse(expandSettings);
header.findViewById(R.id.godown_settings).setContentDescription(getResources().getString(R.string.btn_expand));
AnimatorUtil.flipAnimator(true, v).start();
}
}
});
{
// Set up quick setting toggles
final SwitchCompat toggleNightMode = expandSettings.findViewById(R.id.toggle_night_mode);
if (SettingValues.isPro) {
toggleNightMode.setVisibility(View.VISIBLE);
toggleNightMode.setChecked(inNightMode);
toggleNightMode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingValues.forcedNightModeState = isChecked ? SettingValues.ForcedState.FORCED_ON : SettingValues.ForcedState.FORCED_OFF;
restartTheme();
}
});
}
final SwitchCompat toggleImmersiveMode = expandSettings.findViewById(R.id.toggle_immersive_mode);
toggleImmersiveMode.setChecked(SettingValues.immersiveMode);
toggleImmersiveMode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingValues.immersiveMode = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_IMMERSIVE_MODE, isChecked).apply();
if (isChecked) {
hideDecor();
} else {
showDecor();
}
}
});
final SwitchCompat toggleNSFW = expandSettings.findViewById(R.id.toggle_nsfw);
toggleNSFW.setChecked(SettingValues.showNSFWContent);
toggleNSFW.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingValues.showNSFWContent = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_SHOW_NSFW_CONTENT, isChecked).apply();
reloadSubs();
}
});
final SwitchCompat toggleRightThumbnails = expandSettings.findViewById(R.id.toggle_right_thumbnails);
toggleRightThumbnails.setChecked(SettingValues.switchThumb);
toggleRightThumbnails.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingValues.switchThumb = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_SWITCH_THUMB, isChecked).apply();
reloadSubs();
}
});
final SwitchCompat toggleReaderMode = expandSettings.findViewById(R.id.toggle_reader_mode);
toggleReaderMode.setChecked(SettingValues.readerMode);
toggleReaderMode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingValues.readerMode = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_READER_MODE, isChecked).apply();
}
});
}
header.findViewById(R.id.manage).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent i = new Intent(MainActivity.this, ManageOfflineContent.class);
startActivity(i);
}
});
if (Authentication.didOnline) {
View support = header.findViewById(R.id.support);
if (SettingValues.isPro) {
support.setVisibility(View.GONE);
} else {
support.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
ProUtil.proUpgradeMsg(MainActivity.this, R.string.settings_support_slide).setNegativeButton(R.string.btn_no_thanks, (dialog, whichButton) -> dialog.dismiss()).show();
}
});
}
header.findViewById(R.id.prof).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new MaterialDialog.Builder(MainActivity.this).inputRange(3, 20).alwaysCallInputCallback().input(getString(R.string.user_enter), null, new MaterialDialog.InputCallback() {
@Override
public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
final EditText editText = dialog.getInputEditText();
EditTextValidator.validateUsername(editText);
if (input.length() >= 3 && input.length() <= 20) {
dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
}
}
}).positiveText(R.string.user_btn_goto).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
Intent inte = new Intent(MainActivity.this, Profile.class);
// noinspection ConstantConditions
inte.putExtra(Profile.EXTRA_PROFILE, dialog.getInputEditText().getText().toString());
MainActivity.this.startActivity(inte);
}
}).negativeText(R.string.btn_cancel).show();
}
});
}
header.findViewById(R.id.settings).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Intent i = new Intent(MainActivity.this, SettingsActivity.class);
startActivity(i);
// Cancel sub loading because exiting the settings will reload it anyway
if (mAsyncGetSubreddit != null)
mAsyncGetSubreddit.cancel(true);
drawerLayout.closeDrawers();
}
});
/* footer.findViewById(R.id.settings).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent inte = new Intent(Overview.this, Setting.class);
Overview.this.startActivityForResult(inte, 3);
}
});*/
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
final ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(MainActivity.this, drawerLayout, toolbar, R.string.btn_open, R.string.btn_close) {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
// this disables the animation
super.onDrawerSlide(drawerView, 0);
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
if (drawerLayout.isDrawerOpen(GravityCompat.END)) {
int current = pager.getCurrentItem();
if (current == toOpenComments && toOpenComments != 0) {
current -= 1;
}
String compare = usedArray.get(current);
if (compare.equals("random") || compare.equals("myrandom") || compare.equals("randnsfw")) {
if (adapter != null && adapter.getCurrentFragment() != null && ((SubmissionsView) adapter.getCurrentFragment()).adapter.dataSet.subredditRandom != null) {
String sub = ((SubmissionsView) adapter.getCurrentFragment()).adapter.dataSet.subredditRandom;
doSubSidebarNoLoad(sub);
doSubSidebar(sub);
}
} else {
doSubSidebar(usedArray.get(current));
}
}
}
@Override
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
KeyboardUtil.hideKeyboard(MainActivity.this, drawerLayout.getWindowToken(), 0);
}
};
drawerLayout.addDrawerListener(actionBarDrawerToggle);
actionBarDrawerToggle.syncState();
header.findViewById(R.id.back).setBackgroundColor(Palette.getColor("alsdkfjasld"));
accountsArea = header.findViewById(R.id.accountsarea);
if (accountsArea != null) {
accountsArea.setBackgroundColor(Palette.getDarkerColor("alsdkfjasld"));
}
setDrawerSubList();
hideDrawerItems();
}
use of com.afollestad.materialdialogs.DialogAction in project Slide by ccrama.
the class MainActivity method doSubSidebar.
public void doSubSidebar(final String subreddit) {
if (mAsyncGetSubreddit != null) {
mAsyncGetSubreddit.cancel(true);
}
findViewById(R.id.loader).setVisibility(View.VISIBLE);
invalidateOptionsMenu();
if (!subreddit.equalsIgnoreCase("all") && !subreddit.equalsIgnoreCase("frontpage") && !subreddit.equalsIgnoreCase("friends") && !subreddit.equalsIgnoreCase("mod") && !subreddit.contains("+") && !subreddit.contains(".") && !subreddit.contains("/m/")) {
if (drawerLayout != null) {
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, GravityCompat.END);
}
mAsyncGetSubreddit = new AsyncGetSubreddit();
mAsyncGetSubreddit.execute(subreddit);
final View dialoglayout = findViewById(R.id.sidebarsub);
{
View submit = (dialoglayout.findViewById(R.id.submit));
if (!Authentication.isLoggedIn || !Authentication.didOnline) {
submit.setVisibility(View.GONE);
}
if (SettingValues.fab && SettingValues.fabType == Constants.FAB_POST) {
submit.setVisibility(View.GONE);
}
submit.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Submit.class);
if (!subreddit.contains("/m/") && canSubmit) {
inte.putExtra(Submit.EXTRA_SUBREDDIT, subreddit);
}
MainActivity.this.startActivity(inte);
}
});
}
dialoglayout.findViewById(R.id.wiki).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, Wiki.class);
i.putExtra(Wiki.EXTRA_SUBREDDIT, subreddit);
startActivity(i);
}
});
dialoglayout.findViewById(R.id.syncflair).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ImageFlairs.syncFlairs(MainActivity.this, subreddit);
}
});
dialoglayout.findViewById(R.id.submit).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, Submit.class);
if ((!subreddit.contains("/m/") || !subreddit.contains(".")) && canSubmit) {
i.putExtra(Submit.EXTRA_SUBREDDIT, subreddit);
}
startActivity(i);
}
});
final TextView sort = dialoglayout.findViewById(R.id.sort);
Sorting sortingis = Sorting.HOT;
if (SettingValues.hasSort(subreddit)) {
sortingis = SettingValues.getBaseSubmissionSort(subreddit);
sort.setText(sortingis.name() + ((sortingis == Sorting.CONTROVERSIAL || sortingis == Sorting.TOP) ? " of " + SettingValues.getBaseTimePeriod(subreddit).name() : ""));
} else {
sort.setText("Set default sorting");
}
final int sortid = SortingUtil.getSortingId(sortingis);
dialoglayout.findViewById(R.id.sorting).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final DialogInterface.OnClickListener l2 = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
switch(i) {
case 0:
sorts = Sorting.HOT;
break;
case 1:
sorts = Sorting.NEW;
break;
case 2:
sorts = Sorting.RISING;
break;
case 3:
sorts = Sorting.TOP;
askTimePeriod(sorts, subreddit, dialoglayout);
return;
case 4:
sorts = Sorting.CONTROVERSIAL;
askTimePeriod(sorts, subreddit, dialoglayout);
return;
}
SettingValues.setSubSorting(sorts, time, subreddit);
Sorting sortingis = SettingValues.getBaseSubmissionSort(subreddit);
sort.setText(sortingis.name() + ((sortingis == Sorting.CONTROVERSIAL || sortingis == Sorting.TOP) ? " of " + SettingValues.getBaseTimePeriod(subreddit).name() : ""));
reloadSubs();
}
};
new AlertDialog.Builder(MainActivity.this).setTitle(R.string.sorting_choose).setSingleChoiceItems(SortingUtil.getSortingStrings(), sortid, l2).setNegativeButton("Reset default sorting", (dialog, which) -> {
SettingValues.prefs.edit().remove("defaultSort" + subreddit.toLowerCase(Locale.ENGLISH)).apply();
SettingValues.prefs.edit().remove("defaultTime" + subreddit.toLowerCase(Locale.ENGLISH)).apply();
final TextView sort1 = dialoglayout.findViewById(R.id.sort);
if (SettingValues.hasSort(subreddit)) {
Sorting sortingis1 = SettingValues.getBaseSubmissionSort(subreddit);
sort1.setText(sortingis1.name() + ((sortingis1 == Sorting.CONTROVERSIAL || sortingis1 == Sorting.TOP) ? " of " + SettingValues.getBaseTimePeriod(subreddit).name() : ""));
} else {
sort1.setText("Set default sorting");
}
reloadSubs();
}).show();
}
});
dialoglayout.findViewById(R.id.theme).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int style = new ColorPreferences(MainActivity.this).getThemeSubreddit(subreddit);
final Context contextThemeWrapper = new ContextThemeWrapper(MainActivity.this, style);
LayoutInflater localInflater = getLayoutInflater().cloneInContext(contextThemeWrapper);
final View dialoglayout = localInflater.inflate(R.layout.colorsub, null);
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add(subreddit);
SettingsSubAdapter.showSubThemeEditor(arrayList, MainActivity.this, dialoglayout);
}
});
dialoglayout.findViewById(R.id.mods).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Dialog d = new MaterialDialog.Builder(MainActivity.this).title(R.string.sidebar_findingmods).cancelable(true).content(R.string.misc_please_wait).progress(true, 100).show();
new AsyncTask<Void, Void, Void>() {
ArrayList<UserRecord> mods;
@Override
protected Void doInBackground(Void... params) {
mods = new ArrayList<>();
UserRecordPaginator paginator = new UserRecordPaginator(Authentication.reddit, subreddit, "moderators");
paginator.setSorting(Sorting.HOT);
paginator.setTimePeriod(TimePeriod.ALL);
while (paginator.hasNext()) {
mods.addAll(paginator.next());
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
final ArrayList<String> names = new ArrayList<>();
for (UserRecord rec : mods) {
names.add(rec.getFullName());
}
d.dismiss();
new MaterialDialog.Builder(MainActivity.this).title(getString(R.string.sidebar_submods, subreddit)).items(names).itemsCallback(new MaterialDialog.ListCallback() {
@Override
public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
Intent i = new Intent(MainActivity.this, Profile.class);
i.putExtra(Profile.EXTRA_PROFILE, names.get(which));
startActivity(i);
}
}).positiveText(R.string.btn_message).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
Intent i = new Intent(MainActivity.this, SendMessage.class);
i.putExtra(SendMessage.EXTRA_NAME, "/r/" + subreddit);
startActivity(i);
}
}).show();
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
dialoglayout.findViewById(R.id.flair).setVisibility(View.GONE);
if (Authentication.didOnline && Authentication.isLoggedIn) {
if (currentFlair != null)
currentFlair.cancel(true);
currentFlair = new AsyncTask<View, Void, View>() {
List<FlairTemplate> flairs;
ArrayList<String> flairText;
String current;
AccountManager m;
@Override
protected View doInBackground(View... params) {
try {
m = new AccountManager(Authentication.reddit);
JsonNode node = m.getFlairChoicesRootNode(subreddit, null);
flairs = m.getFlairChoices(subreddit, node);
FlairTemplate currentF = m.getCurrentFlair(subreddit, node);
if (currentF != null) {
if (currentF.getText().isEmpty()) {
current = ("[" + currentF.getCssClass() + "]");
} else {
current = (currentF.getText());
}
}
flairText = new ArrayList<>();
for (FlairTemplate temp : flairs) {
if (temp.getText().isEmpty()) {
flairText.add("[" + temp.getCssClass() + "]");
} else {
flairText.add(temp.getText());
}
}
} catch (Exception e1) {
e1.printStackTrace();
}
return params[0];
}
@Override
protected void onPostExecute(View flair) {
if (flairs != null && !flairs.isEmpty() && flairText != null && !flairText.isEmpty()) {
flair.setVisibility(View.VISIBLE);
if (current != null) {
((TextView) dialoglayout.findViewById(R.id.flair_text)).setText(getString(R.string.sidebar_flair, current));
}
flair.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new MaterialDialog.Builder(MainActivity.this).items(flairText).title(R.string.sidebar_select_flair).itemsCallback(new MaterialDialog.ListCallback() {
@Override
public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
final FlairTemplate t = flairs.get(which);
if (t.isTextEditable()) {
new MaterialDialog.Builder(MainActivity.this).title(R.string.sidebar_select_flair_text).input(getString(R.string.mod_flair_hint), t.getText(), true, (dialog1, input) -> {
}).positiveText(R.string.btn_set).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(MaterialDialog dialog, DialogAction which) {
final String flair = dialog.getInputEditText().getText().toString();
new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... params) {
try {
new ModerationManager(Authentication.reddit).setFlair(subreddit, t, flair, Authentication.name);
FlairTemplate currentF = m.getCurrentFlair(subreddit);
if (currentF.getText().isEmpty()) {
current = ("[" + currentF.getCssClass() + "]");
} else {
current = (currentF.getText());
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
@Override
protected void onPostExecute(Boolean done) {
Snackbar s;
if (done) {
if (current != null) {
((TextView) dialoglayout.findViewById(R.id.flair_text)).setText(getString(R.string.sidebar_flair, current));
}
s = Snackbar.make(mToolbar, R.string.snackbar_flair_success, Snackbar.LENGTH_SHORT);
} else {
s = Snackbar.make(mToolbar, R.string.snackbar_flair_error, Snackbar.LENGTH_SHORT);
}
if (s != null) {
LayoutUtils.showSnackbar(s);
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}).negativeText(R.string.btn_cancel).show();
} else {
new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... params) {
try {
new ModerationManager(Authentication.reddit).setFlair(subreddit, t, null, Authentication.name);
FlairTemplate currentF = m.getCurrentFlair(subreddit);
if (currentF.getText().isEmpty()) {
current = ("[" + currentF.getCssClass() + "]");
} else {
current = (currentF.getText());
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
@Override
protected void onPostExecute(Boolean done) {
Snackbar s;
if (done) {
if (current != null) {
((TextView) dialoglayout.findViewById(R.id.flair_text)).setText(getString(R.string.sidebar_flair, current));
}
s = Snackbar.make(mToolbar, R.string.snackbar_flair_success, Snackbar.LENGTH_SHORT);
} else {
s = Snackbar.make(mToolbar, R.string.snackbar_flair_error, Snackbar.LENGTH_SHORT);
}
if (s != null) {
LayoutUtils.showSnackbar(s);
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
}).show();
}
});
}
}
};
currentFlair.execute((View) dialoglayout.findViewById(R.id.flair));
}
} else {
if (drawerLayout != null) {
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, GravityCompat.END);
}
}
}
use of com.afollestad.materialdialogs.DialogAction in project Slide by ccrama.
the class Profile method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case (android.R.id.home):
onBackPressed();
break;
case (R.id.category):
new AsyncTask<Void, Void, List<String>>() {
Dialog d;
@Override
public void onPreExecute() {
d = new MaterialDialog.Builder(Profile.this).progress(true, 100).content(R.string.misc_please_wait).title(R.string.profile_category_loading).show();
}
@Override
protected List<String> doInBackground(Void... params) {
try {
List<String> categories = new ArrayList<>(new AccountManager(Authentication.reddit).getSavedCategories());
categories.add(0, "No category");
return categories;
} catch (Exception e) {
e.printStackTrace();
// probably has no categories?
return new ArrayList<String>() {
{
add(0, "No category");
}
};
}
}
@Override
public void onPostExecute(final List<String> data) {
try {
new MaterialDialog.Builder(Profile.this).items(data).title(R.string.profile_category_select).itemsCallback(new MaterialDialog.ListCallback() {
@Override
public void onSelection(MaterialDialog dialog, final View itemView, int which, CharSequence text) {
final String t = data.get(which);
if (which == 0)
category = null;
else
category = t;
int current = pager.getCurrentItem();
ProfilePagerAdapter adapter = new ProfilePagerAdapter(getSupportFragmentManager());
pager.setAdapter(adapter);
pager.setOffscreenPageLimit(1);
tabs.setupWithViewPager(pager);
pager.setCurrentItem(current);
}
}).show();
if (d != null) {
d.dismiss();
}
} catch (Exception ignored) {
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
break;
case (R.id.info):
if (account != null && trophyCase != null) {
LayoutInflater inflater = getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.colorprofile, null);
final TextView title = dialoglayout.findViewById(R.id.title);
title.setText(name);
if (account.getDataNode().has("is_employee") && account.getDataNode().get("is_employee").asBoolean()) {
SpannableStringBuilder admin = new SpannableStringBuilder("[A]");
admin.setSpan(new RelativeSizeSpan(.67f), 0, admin.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
title.append(" ");
title.append(admin);
}
dialoglayout.findViewById(R.id.share).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Reddit.defaultShareText(getString(R.string.profile_share, name), "https://www.reddit.com/u/" + name, Profile.this);
}
});
final int currentColor = Palette.getColorUser(name);
title.setBackgroundColor(currentColor);
String info = getString(R.string.profile_age, TimeUtils.getTimeSince(account.getCreated().getTime(), Profile.this));
/*todo better if (account.hasGold() &&account.getDataNode().has("gold_expiration") ) {
Calendar c = Calendar.getInstance();
c.setTimeInMillis(account.getDataNode().get("gold_expiration").asLong());
info.append("Gold expires on " + new SimpleDateFormat("dd/MM/yy").format(c.getTime()));
}*/
((TextView) dialoglayout.findViewById(R.id.moreinfo)).setText(info);
String tag = UserTags.getUserTag(name);
if (tag.isEmpty()) {
tag = getString(R.string.profile_tag_user);
} else {
tag = getString(R.string.profile_tag_user_existing, tag);
}
((TextView) dialoglayout.findViewById(R.id.tagged)).setText(tag);
LinearLayout l = dialoglayout.findViewById(R.id.trophies_inner);
dialoglayout.findViewById(R.id.tag).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MaterialDialog.Builder b = new MaterialDialog.Builder(Profile.this).title(getString(R.string.profile_tag_set, name)).input(getString(R.string.profile_tag), UserTags.getUserTag(name), false, (dialog, input) -> {
}).positiveText(R.string.profile_btn_tag).neutralText(R.string.btn_cancel);
if (UserTags.isUserTagged(name)) {
b.negativeText(R.string.profile_btn_untag);
}
b.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(MaterialDialog dialog, DialogAction which) {
UserTags.setUserTag(name, dialog.getInputEditText().getText().toString());
String tag = UserTags.getUserTag(name);
if (tag.isEmpty()) {
tag = getString(R.string.profile_tag_user);
} else {
tag = getString(R.string.profile_tag_user_existing, tag);
}
((TextView) dialoglayout.findViewById(R.id.tagged)).setText(tag);
}
}).onNeutral(null).onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(MaterialDialog dialog, DialogAction which) {
UserTags.removeUserTag(name);
String tag = UserTags.getUserTag(name);
if (tag.isEmpty()) {
tag = getString(R.string.profile_tag_user);
} else {
tag = getString(R.string.profile_tag_user_existing, tag);
}
((TextView) dialoglayout.findViewById(R.id.tagged)).setText(tag);
}
}).show();
}
});
if (trophyCase.isEmpty()) {
dialoglayout.findViewById(R.id.trophies).setVisibility(View.GONE);
} else {
for (final Trophy t : trophyCase) {
View view = getLayoutInflater().inflate(R.layout.trophy, null);
((Reddit) getApplicationContext()).getImageLoader().displayImage(t.getIcon(), ((ImageView) view.findViewById(R.id.image)));
((TextView) view.findViewById(R.id.trophyTitle)).setText(t.getFullName());
if (t.getAboutUrl() != null && !t.getAboutUrl().equalsIgnoreCase("null")) {
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LinkUtil.openUrl(LinkUtil.formatURL(t.getAboutUrl()).toString(), Palette.getColorUser(account.getFullName()), Profile.this);
}
});
}
l.addView(view);
}
}
if (Authentication.isLoggedIn) {
dialoglayout.findViewById(R.id.pm).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Profile.this, SendMessage.class);
i.putExtra(SendMessage.EXTRA_NAME, name);
startActivity(i);
}
});
friend = account.isFriend();
if (friend) {
((TextView) dialoglayout.findViewById(R.id.friend)).setText(R.string.profile_remove_friend);
} else {
((TextView) dialoglayout.findViewById(R.id.friend)).setText(R.string.profile_add_friend);
}
dialoglayout.findViewById(R.id.friend_body).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
if (friend) {
try {
new AccountManager(Authentication.reddit).deleteFriend(name);
} catch (Exception ignored) {
// Will throw java.lang.IllegalStateException: No Content-Type header was found, but it still works.
}
friend = false;
} else {
new AccountManager(Authentication.reddit).updateFriend(name);
friend = true;
}
return null;
}
@Override
public void onPostExecute(Void voids) {
if (friend) {
((TextView) dialoglayout.findViewById(R.id.friend)).setText(R.string.profile_remove_friend);
} else {
((TextView) dialoglayout.findViewById(R.id.friend)).setText(R.string.profile_add_friend);
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
dialoglayout.findViewById(R.id.block_body).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... params) {
Map<String, String> map = new HashMap();
map.put("account_id", "t2_" + account.getId());
try {
Authentication.reddit.execute(Authentication.reddit.request().post(map).path("/api/block_user").build());
} catch (Exception ex) {
return false;
}
return true;
}
@Override
public void onPostExecute(Boolean blocked) {
if (!blocked) {
Toast.makeText(getBaseContext(), getString(R.string.err_block_user), Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getBaseContext(), getString(R.string.success_block_user), Toast.LENGTH_LONG).show();
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
} else {
dialoglayout.findViewById(R.id.pm).setVisibility(View.GONE);
}
dialoglayout.findViewById(R.id.multi_body).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent inte = new Intent(Profile.this, MultiredditOverview.class);
inte.putExtra(EXTRA_PROFILE, name);
Profile.this.startActivity(inte);
}
});
final View body = dialoglayout.findViewById(R.id.body2);
body.setVisibility(View.INVISIBLE);
final View center = dialoglayout.findViewById(R.id.colorExpandFrom);
dialoglayout.findViewById(R.id.color).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int cx = center.getWidth() / 2;
int cy = center.getHeight() / 2;
int finalRadius = Math.max(body.getWidth(), body.getHeight());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Animator anim = ViewAnimationUtils.createCircularReveal(body, cx, cy, 0, finalRadius);
body.setVisibility(View.VISIBLE);
anim.start();
} else {
body.setVisibility(View.VISIBLE);
}
}
});
LineColorPicker colorPicker = dialoglayout.findViewById(R.id.picker);
final LineColorPicker colorPicker2 = dialoglayout.findViewById(R.id.picker2);
colorPicker.setColors(ColorPreferences.getBaseColors(Profile.this));
colorPicker.setOnColorChangedListener(new OnColorChangedListener() {
@Override
public void onColorChanged(int c) {
colorPicker2.setColors(ColorPreferences.getColors(getBaseContext(), c));
colorPicker2.setSelectedColor(c);
}
});
for (int i : colorPicker.getColors()) {
for (int i2 : ColorPreferences.getColors(getBaseContext(), i)) {
if (i2 == currentColor) {
colorPicker.setSelectedColor(i);
colorPicker2.setColors(ColorPreferences.getColors(getBaseContext(), i));
colorPicker2.setSelectedColor(i2);
break;
}
}
}
colorPicker2.setOnColorChangedListener(new OnColorChangedListener() {
@Override
public void onColorChanged(int i) {
findViewById(R.id.header).setBackgroundColor(colorPicker2.getColor());
if (mToolbar != null)
mToolbar.setBackgroundColor(colorPicker2.getColor());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.setStatusBarColor(Palette.getDarkerColor(colorPicker2.getColor()));
}
title.setBackgroundColor(colorPicker2.getColor());
}
});
{
TextView dialogButton = dialoglayout.findViewById(R.id.ok);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Palette.setColorUser(name, colorPicker2.getColor());
int cx = center.getWidth() / 2;
int cy = center.getHeight() / 2;
int initialRadius = body.getWidth();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Animator anim = ViewAnimationUtils.createCircularReveal(body, cx, cy, initialRadius, 0);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
body.setVisibility(View.GONE);
}
});
anim.start();
} else {
body.setVisibility(View.GONE);
}
}
});
}
{
final TextView dialogButton = dialoglayout.findViewById(R.id.reset);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Palette.removeUserColor(name);
Snackbar.make(dialogButton, "User color removed", Snackbar.LENGTH_SHORT).show();
int cx = center.getWidth() / 2;
int cy = center.getHeight() / 2;
int initialRadius = body.getWidth();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Animator anim = ViewAnimationUtils.createCircularReveal(body, cx, cy, initialRadius, 0);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
body.setVisibility(View.GONE);
}
});
anim.start();
} else {
body.setVisibility(View.GONE);
}
}
});
}
((TextView) dialoglayout.findViewById(R.id.commentkarma)).setText(String.format(Locale.getDefault(), "%d", account.getCommentKarma()));
((TextView) dialoglayout.findViewById(R.id.linkkarma)).setText(String.format(Locale.getDefault(), "%d", account.getLinkKarma()));
((TextView) dialoglayout.findViewById(R.id.totalKarma)).setText(String.format(Locale.getDefault(), "%d", account.getCommentKarma() + account.getLinkKarma()));
new AlertDialog.Builder(Profile.this).setOnDismissListener(dialogInterface -> {
findViewById(R.id.header).setBackgroundColor(currentColor);
if (mToolbar != null)
mToolbar.setBackgroundColor(currentColor);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.setStatusBarColor(Palette.getDarkerColor(currentColor));
}
}).setView(dialoglayout).show();
}
return true;
case (R.id.sort):
openPopup();
return true;
}
return false;
}
use of com.afollestad.materialdialogs.DialogAction in project Slide by ccrama.
the class SubredditView method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
case R.id.filter:
filterContent(subreddit);
return true;
case R.id.submit:
Intent i = new Intent(this, Submit.class);
if (canSubmit)
i.putExtra(Submit.EXTRA_SUBREDDIT, subreddit);
startActivity(i);
return true;
case R.id.action_refresh:
if (adapter != null && adapter.getCurrentFragment() != null) {
((SubmissionsView) adapter.getCurrentFragment()).forceRefresh();
}
return true;
case R.id.action_sort:
if (subreddit.equalsIgnoreCase("friends")) {
Snackbar s = Snackbar.make(findViewById(R.id.anchor), getString(R.string.friends_sort_error), Snackbar.LENGTH_SHORT);
LayoutUtils.showSnackbar(s);
} else {
openPopup();
}
return true;
case R.id.gallery:
if (SettingValues.isPro) {
List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
if (posts != null && !posts.isEmpty()) {
Intent i2 = new Intent(this, Gallery.class);
i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
i2.putExtra(Gallery.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
startActivity(i2);
}
} else {
ProUtil.proUpgradeMsg(this, R.string.general_gallerymode_ispro).setNegativeButton(R.string.btn_no_thanks, (dialog, whichButton) -> dialog.dismiss()).show();
}
return true;
case R.id.search:
MaterialDialog.Builder builder = new MaterialDialog.Builder(this).title(R.string.search_title).alwaysCallInputCallback().input(getString(R.string.search_msg), "", new MaterialDialog.InputCallback() {
@Override
public void onInput(MaterialDialog materialDialog, CharSequence charSequence) {
term = charSequence.toString();
}
}).neutralText(R.string.search_all).onNeutral(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
Intent i = new Intent(SubredditView.this, Search.class);
i.putExtra(Search.EXTRA_TERM, term);
startActivity(i);
}
});
// Add "search current sub" if it is not frontpage/all/random
if (!subreddit.equalsIgnoreCase("frontpage") && !subreddit.equalsIgnoreCase("all") && !subreddit.equalsIgnoreCase("random") && !subreddit.equalsIgnoreCase("popular") && !subreddit.equals("myrandom") && !subreddit.equals("randnsfw") && !subreddit.equalsIgnoreCase("friends") && !subreddit.equalsIgnoreCase("mod")) {
builder.positiveText(getString(R.string.search_subreddit, subreddit)).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
Intent i = new Intent(SubredditView.this, Search.class);
i.putExtra(Search.EXTRA_TERM, term);
i.putExtra(Search.EXTRA_SUBREDDIT, subreddit);
Log.v(LogUtil.getTag(), "INTENT SHOWS " + term + " AND " + subreddit);
startActivity(i);
}
});
}
builder.show();
return true;
case R.id.sidebar:
drawerLayout.openDrawer(Gravity.RIGHT);
return true;
case R.id.hide_posts:
((SubmissionsView) adapter.getCurrentFragment()).clearSeenPosts(false);
return true;
case R.id.action_shadowbox:
if (SettingValues.isPro) {
List<Submission> posts = ((SubmissionsView) ((SubredditPagerAdapter) pager.getAdapter()).getCurrentFragment()).posts.posts;
if (posts != null && !posts.isEmpty()) {
Intent i2 = new Intent(this, Shadowbox.class);
i2.putExtra(Shadowbox.EXTRA_PAGE, getCurrentPage());
i2.putExtra(Shadowbox.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
startActivity(i2);
}
} else {
ProUtil.proUpgradeMsg(this, R.string.general_shadowbox_ispro).setNegativeButton(R.string.btn_no_thanks, (dialog, whichButton) -> dialog.dismiss()).show();
}
return true;
default:
return false;
}
}
use of com.afollestad.materialdialogs.DialogAction in project Slide by ccrama.
the class MultiredditOverview method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case android.R.id.home:
try {
onBackPressed();
} catch (Exception ignored) {
}
return true;
case R.id.action_edit:
{
if (profile.isEmpty() && (UserSubscriptions.multireddits != null) && !UserSubscriptions.multireddits.isEmpty()) {
Intent i = new Intent(MultiredditOverview.this, CreateMulti.class);
i.putExtra(CreateMulti.EXTRA_MULTI, UserSubscriptions.multireddits.get(pager.getCurrentItem()).getDisplayName());
startActivity(i);
}
}
return true;
case R.id.search:
{
UserSubscriptions.MultiCallback m = new UserSubscriptions.MultiCallback() {
@Override
public void onComplete(List<MultiReddit> multireddits) {
if ((multireddits != null) && !multireddits.isEmpty()) {
searchMulti = multireddits.get(pager.getCurrentItem());
MaterialDialog.Builder builder = new MaterialDialog.Builder(MultiredditOverview.this).title(R.string.search_title).alwaysCallInputCallback().input(getString(R.string.search_msg), "", new MaterialDialog.InputCallback() {
@Override
public void onInput(MaterialDialog materialDialog, CharSequence charSequence) {
term = charSequence.toString();
}
});
// Add "search current sub" if it is not frontpage/all/random
builder.positiveText(getString(R.string.search_subreddit, "/m/" + searchMulti.getDisplayName())).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
Intent i = new Intent(MultiredditOverview.this, Search.class);
i.putExtra(Search.EXTRA_TERM, term);
i.putExtra(Search.EXTRA_MULTIREDDIT, searchMulti.getDisplayName());
startActivity(i);
}
});
builder.show();
}
}
};
if (profile.isEmpty()) {
UserSubscriptions.getMultireddits(m);
} else {
UserSubscriptions.getPublicMultireddits(m, profile);
}
}
return true;
case R.id.create:
if (profile.isEmpty()) {
Intent i2 = new Intent(MultiredditOverview.this, CreateMulti.class);
startActivity(i2);
}
return true;
case R.id.action_sort:
openPopup();
return true;
case R.id.subs:
((DrawerLayout) findViewById(R.id.drawer_layout)).openDrawer(Gravity.RIGHT);
return true;
case R.id.gallery:
if (SettingValues.isPro) {
List<Submission> posts = ((MultiredditView) adapter.getCurrentFragment()).posts.posts;
if (posts != null && !posts.isEmpty()) {
Intent i2 = new Intent(this, Gallery.class);
i2.putExtra(Gallery.EXTRA_PROFILE, profile);
i2.putExtra(Gallery.EXTRA_MULTIREDDIT, ((MultiredditView) adapter.getCurrentFragment()).posts.multiReddit.getDisplayName());
startActivity(i2);
}
} else {
final AlertDialog.Builder b = ProUtil.proUpgradeMsg(this, R.string.general_gallerymode_ispro).setNegativeButton(R.string.btn_no_thanks, (dialog, whichButton) -> dialog.dismiss());
if (SettingValues.previews > 0) {
b.setNeutralButton(getString(R.string.pro_previews, SettingValues.previews), (dialog, which) -> {
SettingValues.prefs.edit().putInt(SettingValues.PREVIEWS_LEFT, SettingValues.previews - 1).apply();
SettingValues.previews = SettingValues.prefs.getInt(SettingValues.PREVIEWS_LEFT, 10);
List<Submission> posts = ((MultiredditView) adapter.getCurrentFragment()).posts.posts;
if (posts != null && !posts.isEmpty()) {
Intent i2 = new Intent(MultiredditOverview.this, Gallery.class);
i2.putExtra(Gallery.EXTRA_PROFILE, profile);
i2.putExtra(Gallery.EXTRA_MULTIREDDIT, ((MultiredditView) adapter.getCurrentFragment()).posts.multiReddit.getDisplayName());
startActivity(i2);
}
});
}
b.show();
}
return true;
case R.id.action_shadowbox:
if (SettingValues.isPro) {
List<Submission> posts = ((MultiredditView) adapter.getCurrentFragment()).posts.posts;
if (posts != null && !posts.isEmpty()) {
Intent i = new Intent(this, Shadowbox.class);
i.putExtra(Shadowbox.EXTRA_PAGE, getCurrentPage());
i.putExtra(Shadowbox.EXTRA_PROFILE, profile);
i.putExtra(Shadowbox.EXTRA_MULTIREDDIT, ((MultiredditView) adapter.getCurrentFragment()).posts.multiReddit.getDisplayName());
startActivity(i);
}
} else {
final AlertDialog.Builder b = ProUtil.proUpgradeMsg(this, R.string.general_shadowbox_ispro).setNegativeButton(R.string.btn_no_thanks, (dialog, whichButton) -> dialog.dismiss());
if (SettingValues.previews > 0 && adapter != null && ((MultiredditView) adapter.getCurrentFragment()).posts != null && ((MultiredditView) adapter.getCurrentFragment()).posts.posts != null && !((MultiredditView) adapter.getCurrentFragment()).posts.posts.isEmpty()) {
b.setNeutralButton(getString(R.string.pro_previews, SettingValues.previews), (dialog, which) -> {
SettingValues.prefs.edit().putInt(SettingValues.PREVIEWS_LEFT, SettingValues.previews - 1).apply();
SettingValues.previews = SettingValues.prefs.getInt(SettingValues.PREVIEWS_LEFT, 10);
List<Submission> posts = ((MultiredditView) adapter.getCurrentFragment()).posts.posts;
if (posts != null && !posts.isEmpty()) {
Intent i = new Intent(MultiredditOverview.this, Shadowbox.class);
i.putExtra(Shadowbox.EXTRA_PAGE, getCurrentPage());
i.putExtra(Shadowbox.EXTRA_PROFILE, profile);
i.putExtra(Shadowbox.EXTRA_MULTIREDDIT, ((MultiredditView) adapter.getCurrentFragment()).posts.multiReddit.getDisplayName());
startActivity(i);
}
});
}
b.show();
}
return true;
default:
return false;
}
}
Aggregations