use of me.ccrama.redditslide.util.OnSingleClickListener 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);
flipAnimator(false, header.findViewById(R.id.headerflip)).start();
} else {
collapse(profStuff);
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 String guest = getString(R.string.guest);
keys.add(guest);
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());
if (!accName.equals(guest)) {
t.findViewById(R.id.remove).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialogWrapper.Builder(MainActivity.this).setTitle(R.string.profile_remove).setMessage(R.string.profile_remove_account).setNegativeButton(R.string.btn_delete, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog2, int which2) {
Set<String> accounts2 = Authentication.authentication.getStringSet("accounts", new HashSet<String>());
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<String>()));
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();
}
});
} else {
t.findViewById(R.id.remove).setVisibility(View.GONE);
}
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 (!accName.equals(guest)) {
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;
} else {
Authentication.name = "LOGGEDOUT";
Authentication.isLoggedIn = false;
Authentication.authentication.edit().remove("lasttoken").remove("backedCreds").apply();
}
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);
flipAnimator(false, view).start();
} else {
collapse(body);
flipAnimator(true, view).start();
}
}
});
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);
}
});
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);
flipAnimator(false, header.findViewById(R.id.headerflip)).start();
} else {
collapse(profStuff);
flipAnimator(true, header.findViewById(R.id.headerflip)).start();
}
}
});
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 String guest = getString(R.string.guest);
keys.add(guest);
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);
if (!accName.equals(guest)) {
t.findViewById(R.id.remove).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialogWrapper.Builder(MainActivity.this).setTitle(R.string.profile_remove).setMessage(R.string.profile_remove_account).setNegativeButton(R.string.btn_delete, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog2, int which2) {
Set<String> accounts2 = Authentication.authentication.getStringSet("accounts", new HashSet<String>());
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<String>()));
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();
}
});
} else {
t.findViewById(R.id.remove).setVisibility(View.GONE);
}
t.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
if (!accName.equalsIgnoreCase(Authentication.name) && !accName.equals(guest)) {
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);
}
});
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);
}
});
}
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.tabletUI) {
support.setVisibility(View.GONE);
} else {
header.findViewById(R.id.support).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
new AlertDialogWrapper.Builder(MainActivity.this).setTitle(R.string.settings_support_slide).setMessage(R.string.pro_upgrade_msg).setPositiveButton(R.string.btn_yes_exclaim, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=me.ccrama.slideforreddittabletuiunlock")));
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=me.ccrama.slideforreddittabletuiunlock")));
}
}
}).setNegativeButton(R.string.btn_no_danks, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int 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, Settings.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);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(drawerLayout.getWindowToken(), 0);
}
};
drawerLayout.setDrawerListener(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();
}
use of me.ccrama.redditslide.util.OnSingleClickListener 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 = Reddit.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();
}
};
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(MainActivity.this);
builder.setTitle(R.string.sorting_choose);
builder.setSingleChoiceItems(Reddit.getSortingStrings(getBaseContext()), sortid, l2);
builder.setNegativeButton("Reset default sorting", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SettingValues.prefs.edit().remove("defaultSort" + subreddit.toLowerCase(Locale.ENGLISH)).apply();
SettingValues.prefs.edit().remove("defaultTime" + subreddit.toLowerCase(Locale.ENGLISH)).apply();
final TextView sort = dialoglayout.findViewById(R.id.sort);
if (SettingValues.hasSort(subreddit)) {
Sorting 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");
}
reloadSubs();
}
});
builder.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, new MaterialDialog.InputCallback() {
@Override
public void onInput(MaterialDialog dialog, CharSequence 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) {
View view = s.getView();
TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.show();
}
}
}.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) {
View view = s.getView();
TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.show();
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
}).show();
}
});
}
}
};
currentFlair.execute(dialoglayout.findViewById(R.id.flair));
}
} else {
if (drawerLayout != null) {
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, GravityCompat.END);
}
}
}
use of me.ccrama.redditslide.util.OnSingleClickListener in project Slide by ccrama.
the class CommentAdapter method setCommentStateHighlighted.
public void setCommentStateHighlighted(final CommentViewHolder holder, final Comment n, final CommentNode baseNode, boolean isReplying, boolean animate) {
if (currentlySelected != null && currentlySelected != holder) {
setCommentStateUnhighlighted(currentlySelected, currentBaseNode, true);
}
if (mContext instanceof BaseActivity) {
((BaseActivity) mContext).setShareUrl("https://reddit.com" + submission.getPermalink() + n.getFullName() + "?context=3");
}
// and expand to show all children comments
if (SettingValues.swap && holder.firstTextView.getVisibility() == View.GONE && !isReplying) {
hiddenPersons.remove(n.getFullName());
unhideAll(baseNode, holder.getAdapterPosition() + 1);
if (toCollapse.contains(n.getFullName()) && SettingValues.collapseComments) {
setViews(n.getDataNode().get("body_html").asText(), submission.getSubredditName(), holder);
}
CommentAdapterHelper.hideChildrenObject(holder.childrenNumber);
holder.commentOverflow.setVisibility(View.VISIBLE);
toCollapse.remove(n.getFullName());
} else {
currentlySelected = holder;
currentBaseNode = baseNode;
int color = Palette.getColor(n.getSubredditName());
currentSelectedItem = n.getFullName();
currentNode = baseNode;
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
resetMenu(holder.menuArea, false);
final View baseView = (SettingValues.rightHandedCommentMenu) ? inflater.inflate(R.layout.comment_menu_right_handed, holder.menuArea) : inflater.inflate(R.layout.comment_menu, holder.menuArea);
if (!isReplying) {
baseView.setVisibility(View.GONE);
if (animate) {
expand(baseView);
} else {
baseView.setVisibility(View.VISIBLE);
final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
baseView.measure(widthSpec, heightSpec);
View l2 = baseView.findViewById(R.id.replyArea) == null ? baseView.findViewById(R.id.innerSend) : baseView.findViewById(R.id.replyArea);
final int widthSpec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int heightSpec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
l2.measure(widthSpec2, heightSpec2);
ViewGroup.LayoutParams layoutParams = baseView.getLayoutParams();
layoutParams.height = baseView.getMeasuredHeight() - l2.getMeasuredHeight();
baseView.setLayoutParams(layoutParams);
}
}
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
params.setMargins(0, 0, 0, 0);
holder.itemView.setLayoutParams(params);
View reply = baseView.findViewById(R.id.reply);
View send = baseView.findViewById(R.id.send);
final View menu = baseView.findViewById(R.id.menu);
final View replyArea = baseView.findViewById(R.id.replyArea);
final View more = baseView.findViewById(R.id.more);
final ImageView upvote = (ImageView) baseView.findViewById(R.id.upvote);
final ImageView downvote = (ImageView) baseView.findViewById(R.id.downvote);
View discard = baseView.findViewById(R.id.discard);
final EditText replyLine = (EditText) baseView.findViewById(R.id.replyLine);
final Comment comment = baseNode.getComment();
if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
upvote.setColorFilter(holder.textColorUp, PorterDuff.Mode.MULTIPLY);
} else if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
downvote.setColorFilter(holder.textColorDown, PorterDuff.Mode.MULTIPLY);
} else {
downvote.clearColorFilter();
upvote.clearColorFilter();
}
{
final ImageView mod = (ImageView) baseView.findViewById(R.id.mod);
try {
if (UserSubscriptions.modOf.contains(submission.getSubredditName())) {
// todo
mod.setVisibility(View.GONE);
} else {
mod.setVisibility(View.GONE);
}
} catch (Exception e) {
Log.d(LogUtil.getTag(), "Error loading mod " + e.toString());
}
}
if (UserSubscriptions.modOf != null && UserSubscriptions.modOf.contains(submission.getSubredditName().toLowerCase(Locale.ENGLISH))) {
baseView.findViewById(R.id.mod).setVisibility(View.VISIBLE);
final Map<String, Integer> reports = comment.getUserReports();
final Map<String, String> reports2 = comment.getModeratorReports();
if (reports.size() + reports2.size() > 0) {
((ImageView) baseView.findViewById(R.id.mod)).setColorFilter(ContextCompat.getColor(mContext, R.color.md_red_300), PorterDuff.Mode.SRC_ATOP);
} else {
((ImageView) baseView.findViewById(R.id.mod)).setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
}
baseView.findViewById(R.id.mod).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
CommentAdapterHelper.showModBottomSheet(CommentAdapter.this, mContext, baseNode, comment, holder, reports, reports2);
}
});
} else {
baseView.findViewById(R.id.mod).setVisibility(View.GONE);
}
final ImageView edit = (ImageView) baseView.findViewById(R.id.edit);
if (Authentication.name != null && Authentication.name.toLowerCase(Locale.ENGLISH).equals(comment.getAuthor().toLowerCase(Locale.ENGLISH)) && Authentication.didOnline) {
edit.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
CommentAdapterHelper.doCommentEdit(CommentAdapter.this, mContext, fm, baseNode, baseNode.isTopLevel() ? submission.getSelftext() : baseNode.getParent().getComment().getBody(), holder);
}
});
} else {
edit.setVisibility(View.GONE);
}
final ImageView delete = (ImageView) baseView.findViewById(R.id.delete);
if (Authentication.name != null && Authentication.name.toLowerCase(Locale.ENGLISH).equals(comment.getAuthor().toLowerCase(Locale.ENGLISH)) && Authentication.didOnline) {
delete.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
CommentAdapterHelper.deleteComment(CommentAdapter.this, mContext, baseNode, holder);
}
});
} else {
delete.setVisibility(View.GONE);
}
if (Authentication.isLoggedIn && !submission.isArchived() && !submission.isLocked() && !deleted.contains(n.getFullName()) && !comment.getAuthor().equals("[deleted]") && Authentication.didOnline) {
if (isReplying) {
baseView.setVisibility(View.VISIBLE);
final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
baseView.measure(widthSpec, heightSpec);
View l2 = baseView.findViewById(R.id.replyArea) == null ? baseView.findViewById(R.id.innerSend) : baseView.findViewById(R.id.replyArea);
final int widthSpec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int heightSpec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
l2.measure(widthSpec2, heightSpec2);
RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) baseView.getLayoutParams();
params2.height = RelativeLayout.LayoutParams.WRAP_CONTENT;
params2.addRule(RelativeLayout.BELOW, R.id.commentOverflow);
baseView.setLayoutParams(params2);
replyArea.setVisibility(View.VISIBLE);
menu.setVisibility(View.GONE);
currentlyEditing = replyLine;
currentlyEditing.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
mPage.fastScroll.setVisibility(View.GONE);
if (mPage.fab != null) {
mPage.fab.setVisibility(View.GONE);
}
mPage.overrideFab = true;
} else if (SettingValues.fastscroll) {
mPage.fastScroll.setVisibility(View.VISIBLE);
if (mPage.fab != null) {
mPage.fab.setVisibility(View.VISIBLE);
}
mPage.overrideFab = false;
}
}
});
final TextView profile = (TextView) baseView.findViewById(R.id.profile);
changedProfile = Authentication.name;
profile.setText("/u/" + changedProfile);
profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
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 int i = keys.indexOf(changedProfile);
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
builder.setTitle(R.string.sorting_choose);
builder.setSingleChoiceItems(keys.toArray(new String[keys.size()]), i, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
changedProfile = keys.get(which);
profile.setText("/u/" + changedProfile);
}
});
builder.alwaysCallSingleChoiceCallback();
builder.setNegativeButton(R.string.btn_cancel, null);
builder.show();
}
});
replyLine.requestFocus();
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
currentlyEditingId = n.getFullName();
replyLine.setText(backedText);
replyLine.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
backedText = s.toString();
}
@Override
public void afterTextChanged(Editable s) {
}
});
editingPosition = holder.getAdapterPosition();
}
reply.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
expandAndSetParams(baseView);
// If the base theme is Light or Sepia, tint the Editor actions to be white
if (SettingValues.currentTheme == 1 || SettingValues.currentTheme == 5) {
((ImageView) replyArea.findViewById(R.id.savedraft)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.draft)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.imagerep)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.link)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.bold)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.italics)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.bulletlist)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.numlist)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.draw)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.quote)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.size)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.strike)).setColorFilter(Color.WHITE);
((TextView) replyArea.findViewById(R.id.author)).setTextColor(Color.WHITE);
replyLine.getBackground().setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);
}
replyArea.setVisibility(View.VISIBLE);
menu.setVisibility(View.GONE);
currentlyEditing = replyLine;
DoEditorActions.doActions(currentlyEditing, replyArea, fm, (Activity) mContext, comment.getBody(), getParents(baseNode));
currentlyEditing.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
mPage.fastScroll.setVisibility(View.GONE);
if (mPage.fab != null)
mPage.fab.setVisibility(View.GONE);
mPage.overrideFab = true;
} else if (SettingValues.fastscroll) {
mPage.fastScroll.setVisibility(View.VISIBLE);
if (mPage.fab != null)
mPage.fab.setVisibility(View.VISIBLE);
mPage.overrideFab = false;
}
}
});
final TextView profile = (TextView) baseView.findViewById(R.id.profile);
changedProfile = Authentication.name;
profile.setText("/u/" + changedProfile);
profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
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 int i = keys.indexOf(changedProfile);
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
builder.setTitle(R.string.sorting_choose);
builder.setSingleChoiceItems(keys.toArray(new String[keys.size()]), i, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
changedProfile = keys.get(which);
profile.setText("/u/" + changedProfile);
}
});
builder.alwaysCallSingleChoiceCallback();
builder.setNegativeButton(R.string.btn_cancel, null);
builder.show();
}
});
replyLine.requestFocus();
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
currentlyEditingId = n.getFullName();
replyLine.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
backedText = s.toString();
}
@Override
public void afterTextChanged(Editable s) {
}
});
editingPosition = holder.getAdapterPosition();
}
});
send.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
currentlyEditingId = "";
backedText = "";
doShowMenu(baseView);
if (SettingValues.fastscroll) {
mPage.fastScroll.setVisibility(View.VISIBLE);
if (mPage.fab != null)
mPage.fab.setVisibility(View.VISIBLE);
mPage.overrideFab = false;
}
dataSet.refreshLayout.setRefreshing(true);
if (currentlyEditing != null) {
String text = currentlyEditing.getText().toString();
new ReplyTaskComment(n, baseNode, holder, changedProfile).execute(text);
currentlyEditing = null;
editingPosition = -1;
}
// Hide soft keyboard
View view = ((Activity) mContext).getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
});
discard.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
currentlyEditing = null;
editingPosition = -1;
currentlyEditingId = "";
backedText = "";
mPage.overrideFab = false;
View view = ((Activity) mContext).getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
doShowMenu(baseView);
}
});
} else {
if (reply.getVisibility() == View.VISIBLE) {
reply.setVisibility(View.GONE);
}
if ((submission.isArchived() || deleted.contains(n.getFullName()) || comment.getAuthor().equals("[deleted]")) && Authentication.isLoggedIn && Authentication.didOnline && upvote.getVisibility() == View.VISIBLE) {
upvote.setVisibility(View.GONE);
}
if ((submission.isArchived() || deleted.contains(n.getFullName()) || comment.getAuthor().equals("[deleted]")) && Authentication.isLoggedIn && Authentication.didOnline && downvote.getVisibility() == View.VISIBLE) {
downvote.setVisibility(View.GONE);
}
}
more.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
CommentAdapterHelper.showOverflowBottomSheet(CommentAdapter.this, mContext, holder, baseNode);
}
});
upvote.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
setCommentStateUnhighlighted(holder, comment, baseNode, true);
if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
new Vote(v, mContext).execute(n);
ActionStates.setVoteDirection(comment, VoteDirection.NO_VOTE);
doScoreText(holder, n, CommentAdapter.this);
upvote.clearColorFilter();
} else {
new Vote(true, v, mContext).execute(n);
ActionStates.setVoteDirection(comment, VoteDirection.UPVOTE);
// reset colour
downvote.clearColorFilter();
doScoreText(holder, n, CommentAdapter.this);
upvote.setColorFilter(holder.textColorUp, PorterDuff.Mode.MULTIPLY);
}
}
});
downvote.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
setCommentStateUnhighlighted(holder, comment, baseNode, true);
if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
new Vote(v, mContext).execute(n);
ActionStates.setVoteDirection(comment, VoteDirection.NO_VOTE);
doScoreText(holder, n, CommentAdapter.this);
downvote.clearColorFilter();
} else {
new Vote(false, v, mContext).execute(n);
ActionStates.setVoteDirection(comment, VoteDirection.DOWNVOTE);
// reset colour
upvote.clearColorFilter();
doScoreText(holder, n, CommentAdapter.this);
downvote.setColorFilter(holder.textColorDown, PorterDuff.Mode.MULTIPLY);
}
}
});
menu.setBackgroundColor(color);
replyArea.setBackgroundColor(color);
if (!isReplying) {
menu.setVisibility(View.VISIBLE);
replyArea.setVisibility(View.GONE);
}
holder.itemView.findViewById(R.id.background).setBackgroundColor(Color.argb(50, Color.red(color), Color.green(color), Color.blue(color)));
}
}
use of me.ccrama.redditslide.util.OnSingleClickListener in project Slide by ccrama.
the class CommentAdapter method doReplySubmission.
private void doReplySubmission(RecyclerView.ViewHolder submissionViewHolder) {
final View replyArea = submissionViewHolder.itemView.findViewById(R.id.innerSend);
if (replyArea.getVisibility() == View.GONE) {
expandSubmissionReply(replyArea);
EditText replyLine = ((EditText) submissionViewHolder.itemView.findViewById(R.id.replyLine));
DoEditorActions.doActions(replyLine, submissionViewHolder.itemView, fm, (Activity) mContext, submission.isSelfPost() ? submission.getSelftext() : null, new String[] { submission.getAuthor() });
currentlyEditing = ((EditText) submissionViewHolder.itemView.findViewById(R.id.replyLine));
final TextView profile = (TextView) submissionViewHolder.itemView.findViewById(R.id.profile);
changedProfile = Authentication.name;
profile.setText("/u/" + changedProfile);
profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
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 int i = keys.indexOf(changedProfile);
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
builder.setTitle("Switch to another account");
builder.setSingleChoiceItems(keys.toArray(new String[keys.size()]), i, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
changedProfile = keys.get(which);
profile.setText("/u/" + changedProfile);
}
});
builder.alwaysCallSingleChoiceCallback();
builder.setNegativeButton(R.string.btn_cancel, null);
builder.show();
}
});
currentlyEditing.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
mPage.fastScroll.setVisibility(View.GONE);
if (mPage.fab != null)
mPage.fab.setVisibility(View.GONE);
mPage.overrideFab = true;
} else if (SettingValues.fastscroll) {
mPage.fastScroll.setVisibility(View.VISIBLE);
if (mPage.fab != null)
mPage.fab.setVisibility(View.VISIBLE);
mPage.overrideFab = false;
}
}
});
replyLine.requestFocus();
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
editingPosition = submissionViewHolder.getAdapterPosition();
submissionViewHolder.itemView.findViewById(R.id.send).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
dataSet.refreshLayout.setRefreshing(true);
if (SettingValues.fastscroll) {
mPage.fastScroll.setVisibility(View.VISIBLE);
}
if (mPage.fab != null)
mPage.fab.setVisibility(View.VISIBLE);
mPage.overrideFab = false;
if (currentlyEditing != null) {
String text = currentlyEditing.getText().toString();
new ReplyTaskComment(submission, changedProfile).execute(text);
replyArea.setVisibility(View.GONE);
currentlyEditing.setText("");
currentlyEditing = null;
editingPosition = -1;
// Hide soft keyboard
View view = ((Activity) mContext).getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
}
});
} else {
collapseAndHide(replyArea);
}
}
use of me.ccrama.redditslide.util.OnSingleClickListener in project Slide by ccrama.
the class ModeratorAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder firstHold, final int pos) {
int i = pos != 0 ? pos - 1 : pos;
if (firstHold instanceof SubmissionViewHolder) {
SubmissionViewHolder holder = (SubmissionViewHolder) firstHold;
final Submission submission = (Submission) dataSet.posts.get(i);
CreateCardView.resetColorCard(holder.itemView);
CreateCardView.colorCard(submission.getSubredditName().toLowerCase(Locale.ENGLISH), holder.itemView, "no_subreddit", false);
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
LayoutInflater inflater = mContext.getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.postmenu, null);
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
final TextView title = (TextView) dialoglayout.findViewById(R.id.title);
title.setText(Html.fromHtml(submission.getTitle()));
((TextView) dialoglayout.findViewById(R.id.userpopup)).setText("/u/" + submission.getAuthor());
((TextView) dialoglayout.findViewById(R.id.subpopup)).setText("/r/" + submission.getSubredditName());
dialoglayout.findViewById(R.id.sidebar).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(mContext, Profile.class);
i.putExtra(Profile.EXTRA_PROFILE, submission.getAuthor());
mContext.startActivity(i);
}
});
dialoglayout.findViewById(R.id.wiki).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(mContext, SubredditView.class);
i.putExtra(SubredditView.EXTRA_SUBREDDIT, submission.getSubredditName());
mContext.startActivity(i);
}
});
dialoglayout.findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (submission.isSaved()) {
((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_save);
} else {
((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_post_saved);
}
new AsyncSave(firstHold.itemView).execute(submission);
}
});
dialoglayout.findViewById(R.id.copy).setVisibility(View.GONE);
if (submission.isSaved()) {
((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_post_saved);
}
dialoglayout.findViewById(R.id.gild).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String urlString = "https://reddit.com" + submission.getPermalink();
Intent i = new Intent(mContext, Website.class);
i.putExtra(Website.EXTRA_URL, urlString);
mContext.startActivity(i);
}
});
dialoglayout.findViewById(R.id.share).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (submission.isSelfPost()) {
if (SettingValues.shareLongLink) {
Reddit.defaultShareText("", "htts://reddit.com" + submission.getPermalink(), mContext);
} else {
Reddit.defaultShareText("", "https://redd.it/" + submission.getId(), mContext);
}
} else {
new BottomSheet.Builder(mContext).title(R.string.submission_share_title).grid().sheet(R.menu.share_menu).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which) {
case R.id.reddit_url:
if (SettingValues.shareLongLink) {
Reddit.defaultShareText(submission.getTitle(), "htts://reddit.com" + submission.getPermalink(), mContext);
} else {
Reddit.defaultShareText(submission.getTitle(), "https://redd.it/" + submission.getId(), mContext);
}
break;
case R.id.link_url:
Reddit.defaultShareText(submission.getTitle(), submission.getUrl(), mContext);
break;
}
}
}).show();
}
}
});
if (!Authentication.isLoggedIn || !Authentication.didOnline) {
dialoglayout.findViewById(R.id.save).setVisibility(View.GONE);
dialoglayout.findViewById(R.id.gild).setVisibility(View.GONE);
}
title.setBackgroundColor(Palette.getColor(submission.getSubredditName()));
builder.setView(dialoglayout);
final Dialog d = builder.show();
dialoglayout.findViewById(R.id.hide).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final int pos = dataSet.posts.indexOf(submission);
final Contribution old = dataSet.posts.get(pos);
dataSet.posts.remove(submission);
notifyItemRemoved(pos + 1);
d.dismiss();
Hidden.setHidden(old);
Snackbar s = Snackbar.make(listView, R.string.submission_info_hidden, Snackbar.LENGTH_LONG).setAction(R.string.btn_undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
dataSet.posts.add(pos, (PublicContribution) old);
notifyItemInserted(pos + 1);
Hidden.undoHidden(old);
}
});
View view = s.getView();
TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.show();
}
});
return true;
}
});
new PopulateSubmissionViewHolder().populateSubmissionViewHolder(holder, submission, mContext, false, false, dataSet.posts, listView, false, false, null, null);
final ImageView hideButton = (ImageView) holder.itemView.findViewById(R.id.hide);
if (hideButton != null) {
hideButton.setVisibility(View.GONE);
}
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = "www.reddit.com" + submission.getPermalink();
url = url.replace("?ref=search_posts", "");
new OpenRedditLink(mContext, url);
}
});
} else if (firstHold instanceof ProfileCommentViewHolder) {
// IS COMMENT
final ProfileCommentViewHolder holder = (ProfileCommentViewHolder) firstHold;
final Comment comment = (Comment) dataSet.posts.get(i);
holder.score.setText(comment.getScore() + " " + mContext.getResources().getQuantityString(R.plurals.points, comment.getScore()));
if (Authentication.isLoggedIn) {
if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
holder.score.setTextColor(mContext.getResources().getColor(R.color.md_orange_500));
} else if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
holder.score.setTextColor(mContext.getResources().getColor(R.color.md_blue_500));
} else {
holder.score.setTextColor(holder.time.getCurrentTextColor());
}
}
String spacer = mContext.getString(R.string.submission_properties_seperator);
SpannableStringBuilder titleString = new SpannableStringBuilder();
String timeAgo = TimeUtils.getTimeAgo(comment.getCreated().getTime(), mContext);
// some users were crashing here
String time = ((timeAgo == null || timeAgo.isEmpty()) ? "just now" : timeAgo);
time = time + (((comment.getEditDate() != null) ? " (edit " + TimeUtils.getTimeAgo(comment.getEditDate().getTime(), mContext) + ")" : ""));
titleString.append(time);
titleString.append(spacer);
{
final ImageView mod = (ImageView) holder.itemView.findViewById(R.id.mod);
try {
if (UserSubscriptions.modOf.contains(comment.getSubredditName())) {
// todo
mod.setVisibility(View.GONE);
} else {
mod.setVisibility(View.GONE);
}
} catch (Exception e) {
Log.d(LogUtil.getTag(), "Error loading mod " + e.toString());
}
}
if ((UserSubscriptions.modOf != null) && UserSubscriptions.modOf.contains(comment.getSubredditName().toLowerCase(Locale.ENGLISH))) {
holder.itemView.findViewById(R.id.mod).setVisibility(View.VISIBLE);
final Map<String, Integer> reports = comment.getUserReports();
final Map<String, String> reports2 = comment.getModeratorReports();
if (reports.size() + reports2.size() > 0) {
((ImageView) holder.itemView.findViewById(R.id.mod)).setColorFilter(ContextCompat.getColor(mContext, R.color.md_red_300), PorterDuff.Mode.SRC_ATOP);
} else {
int[] attrs = new int[] { R.attr.tintColor };
TypedArray ta = mContext.obtainStyledAttributes(attrs);
int color = ta.getColor(0, Color.WHITE);
((ImageView) holder.itemView.findViewById(R.id.mod)).setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
ta.recycle();
}
holder.itemView.findViewById(R.id.mod).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
showModBottomSheet(mContext, comment, holder, reports, reports2);
}
});
} else {
holder.itemView.findViewById(R.id.mod).setVisibility(View.GONE);
}
if (comment.getSubredditName() != null) {
String subname = comment.getSubredditName();
SpannableStringBuilder subreddit = new SpannableStringBuilder("/r/" + subname);
if ((SettingValues.colorSubName && Palette.getColor(subname) != Palette.getDefaultColor())) {
subreddit.setSpan(new ForegroundColorSpan(Palette.getColor(subname)), 0, subreddit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
subreddit.setSpan(new StyleSpan(Typeface.BOLD), 0, subreddit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
titleString.append(subreddit);
}
holder.time.setText(titleString);
setViews(comment.getDataNode().get("body_html").asText(), comment.getSubredditName(), holder);
if (comment.getTimesGilded() > 0) {
holder.gild.setVisibility(View.VISIBLE);
((TextView) holder.gild).setText(Integer.toString(comment.getTimesGilded()));
} else if (holder.gild.getVisibility() == View.VISIBLE)
holder.gild.setVisibility(View.GONE);
if (comment.getSubmissionTitle() != null)
holder.title.setText(Html.fromHtml(comment.getSubmissionTitle()));
else
holder.title.setText(Html.fromHtml(comment.getAuthor()));
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new OpenRedditLink(mContext, comment.getSubmissionId(), comment.getSubredditName(), comment.getId());
}
});
holder.content.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new OpenRedditLink(mContext, comment.getSubmissionId(), comment.getSubredditName(), comment.getId());
}
});
}
if (firstHold instanceof SpacerViewHolder) {
firstHold.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(firstHold.itemView.getWidth(), mContext.findViewById(R.id.header).getHeight()));
}
}
Aggregations