use of me.ccrama.redditslide.util.stubs.SimpleTextWatcher in project Slide by ccrama.
the class Submit method onCreate.
public void onCreate(Bundle savedInstanceState) {
disableSwipeBackLayout();
super.onCreate(savedInstanceState);
applyColorTheme();
setContentView(R.layout.activity_submit);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = this.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
}
setupAppBar(R.id.toolbar, R.string.title_submit_post, true, true);
inboxReplies = (SwitchCompat) findViewById(R.id.replies);
Intent intent = getIntent();
final String subreddit = intent.getStringExtra(EXTRA_SUBREDDIT);
final String initialBody = intent.getStringExtra(EXTRA_BODY);
self = findViewById(R.id.selftext);
final AutoCompleteTextView subredditText = ((AutoCompleteTextView) findViewById(R.id.subreddittext));
image = findViewById(R.id.image);
link = findViewById(R.id.url);
image.setVisibility(View.GONE);
link.setVisibility(View.GONE);
if (subreddit != null && !subreddit.equals("frontpage") && !subreddit.equals("all") && !subreddit.equals("friends") && !subreddit.equals("mod") && !subreddit.contains("/m/") && !subreddit.contains("+")) {
subredditText.setText(subreddit);
}
if (initialBody != null) {
((ImageInsertEditText) self.findViewById(R.id.bodytext)).setText(initialBody);
}
ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, UserSubscriptions.getAllSubreddits(this));
subredditText.setAdapter(adapter);
subredditText.setThreshold(2);
subredditText.addTextChangedListener(new SimpleTextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (tchange != null) {
tchange.cancel(true);
}
findViewById(R.id.submittext).setVisibility(View.GONE);
}
});
subredditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
findViewById(R.id.submittext).setVisibility(View.GONE);
if (!hasFocus) {
tchange = new AsyncTask<Void, Void, Subreddit>() {
@Override
protected Subreddit doInBackground(Void... params) {
try {
return Authentication.reddit.getSubreddit(subredditText.getText().toString());
} catch (Exception ignored) {
}
return null;
}
@Override
protected void onPostExecute(Subreddit s) {
if (s != null) {
String text = s.getDataNode().get("submit_text_html").asText();
if (text != null && !text.isEmpty() && !text.equals("null")) {
findViewById(R.id.submittext).setVisibility(View.VISIBLE);
setViews(text, subredditText.getText().toString(), (SpoilerRobotoTextView) findViewById(R.id.submittext), (CommentOverflow) findViewById(R.id.commentOverflow));
}
if (s.getSubredditType().equals("RESTRICTED")) {
subredditText.setText("");
new AlertDialog.Builder(Submit.this).setTitle(R.string.err_submit_restricted).setMessage(R.string.err_submit_restricted_text).setPositiveButton(R.string.btn_ok, null).show();
}
} else {
findViewById(R.id.submittext).setVisibility(View.GONE);
}
}
};
tchange.execute();
}
}
});
findViewById(R.id.selftextradio).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
self.setVisibility(View.VISIBLE);
image.setVisibility(View.GONE);
link.setVisibility(View.GONE);
}
});
findViewById(R.id.imageradio).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
self.setVisibility(View.GONE);
image.setVisibility(View.VISIBLE);
link.setVisibility(View.GONE);
}
});
findViewById(R.id.linkradio).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
self.setVisibility(View.GONE);
image.setVisibility(View.GONE);
link.setVisibility(View.VISIBLE);
}
});
findViewById(R.id.flair).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showFlairChooser();
}
});
findViewById(R.id.suggest).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AsyncTask<String, Void, String>() {
Dialog d;
@Override
protected String doInBackground(String... params) {
try {
return TitleExtractor.getPageTitle(params[0]);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPreExecute() {
d = new MaterialDialog.Builder(Submit.this).progress(true, 100).title(R.string.editor_finding_title).content(R.string.misc_please_wait).show();
}
@Override
protected void onPostExecute(String s) {
if (s != null) {
((EditText) findViewById(R.id.titletext)).setText(s);
d.dismiss();
} else {
d.dismiss();
new AlertDialog.Builder(Submit.this).setTitle(R.string.title_not_found).setPositiveButton(R.string.btn_ok, null).show();
}
}
}.execute(((EditText) findViewById(R.id.urltext)).getText().toString());
}
});
findViewById(R.id.selImage).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
TedBottomPicker tedBottomPicker = new TedBottomPicker.Builder(Submit.this).setOnImageSelectedListener(Submit.this::handleImageIntent).setLayoutResource(R.layout.image_sheet_dialog).setTitle("Choose a photo").create();
tedBottomPicker.show(getSupportFragmentManager());
KeyboardUtil.hideKeyboard(Submit.this, findViewById(R.id.bodytext).getWindowToken(), 0);
}
});
DoEditorActions.doActions(((EditText) findViewById(R.id.bodytext)), findViewById(R.id.selftext), getSupportFragmentManager(), Submit.this, null, null);
if (intent.hasExtra(Intent.EXTRA_TEXT) && !intent.getExtras().getString(Intent.EXTRA_TEXT, "").isEmpty() && !intent.getBooleanExtra(EXTRA_IS_SELF, false)) {
String data = intent.getStringExtra(Intent.EXTRA_TEXT);
if (data.contains("\n")) {
((EditText) findViewById(R.id.titletext)).setText(data.substring(0, data.indexOf("\n")));
((EditText) findViewById(R.id.urltext)).setText(data.substring(data.indexOf("\n")));
} else {
((EditText) findViewById(R.id.urltext)).setText(data);
}
self.setVisibility(View.GONE);
image.setVisibility(View.GONE);
link.setVisibility(View.VISIBLE);
((RadioButton) findViewById(R.id.linkradio)).setChecked(true);
} else if (intent.hasExtra(Intent.EXTRA_STREAM)) {
final Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (imageUri != null) {
handleImageIntent(new ArrayList<Uri>() {
{
add(imageUri);
}
});
self.setVisibility(View.GONE);
image.setVisibility(View.VISIBLE);
link.setVisibility(View.GONE);
((RadioButton) findViewById(R.id.imageradio)).setChecked(true);
}
}
if (intent.hasExtra(Intent.EXTRA_SUBJECT) && !intent.getExtras().getString(Intent.EXTRA_SUBJECT, "").isEmpty()) {
String data = intent.getStringExtra(Intent.EXTRA_SUBJECT);
((EditText) findViewById(R.id.titletext)).setText(data);
}
findViewById(R.id.send).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((FloatingActionButton) findViewById(R.id.send)).hide();
new AsyncDo().execute();
}
});
}
use of me.ccrama.redditslide.util.stubs.SimpleTextWatcher in project Slide by ccrama.
the class MainActivity method setDrawerSubList.
public void setDrawerSubList() {
ArrayList<String> copy;
if (NetworkUtil.isConnected(this)) {
copy = new ArrayList<>(usedArray);
} else {
copy = UserSubscriptions.getAllUserSubreddits(this);
}
copy.removeAll(Arrays.asList("", null));
sideArrayAdapter = new SideArrayAdapter(this, copy, UserSubscriptions.getAllSubreddits(this), drawerSubList);
drawerSubList.setAdapter(sideArrayAdapter);
if ((SettingValues.subredditSearchMethod != Constants.SUBREDDIT_SEARCH_METHOD_TOOLBAR)) {
drawerSearch = headerMain.findViewById(R.id.sort);
drawerSearch.setVisibility(View.VISIBLE);
drawerSubList.setFocusable(false);
headerMain.findViewById(R.id.close_search_drawer).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
drawerSearch.setText("");
}
});
drawerSearch.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
drawerSubList.smoothScrollToPositionFromTop(1, drawerSearch.getHeight(), 100);
} else {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
}
}
});
drawerSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {
if (arg1 == EditorInfo.IME_ACTION_SEARCH) {
// If it the input text doesn't match a subreddit from the list exactly, openInSubView is true
if (sideArrayAdapter.fitems == null || sideArrayAdapter.openInSubView || !usedArray.contains(drawerSearch.getText().toString().toLowerCase(Locale.ENGLISH))) {
Intent inte = new Intent(MainActivity.this, SubredditView.class);
inte.putExtra(SubredditView.EXTRA_SUBREDDIT, drawerSearch.getText().toString());
MainActivity.this.startActivityForResult(inte, 2001);
} else {
if (commentPager && adapter instanceof MainPagerAdapterComment) {
openingComments = null;
toOpenComments = -1;
((MainPagerAdapterComment) adapter).size = (usedArray.size() + 1);
adapter.notifyDataSetChanged();
if (usedArray.contains(drawerSearch.getText().toString().toLowerCase(Locale.ENGLISH))) {
doPageSelectedComments(usedArray.indexOf(drawerSearch.getText().toString().toLowerCase(Locale.ENGLISH)));
} else {
doPageSelectedComments(usedArray.indexOf(sideArrayAdapter.fitems.get(0)));
}
}
if (usedArray.contains(drawerSearch.getText().toString().toLowerCase(Locale.ENGLISH))) {
pager.setCurrentItem(usedArray.indexOf(drawerSearch.getText().toString().toLowerCase(Locale.ENGLISH)));
} else {
pager.setCurrentItem(usedArray.indexOf(sideArrayAdapter.fitems.get(0)));
}
drawerLayout.closeDrawers();
drawerSearch.setText("");
View view = MainActivity.this.getCurrentFocus();
if (view != null) {
KeyboardUtil.hideKeyboard(MainActivity.this, view.getWindowToken(), 0);
}
}
}
return false;
}
});
final View close = findViewById(R.id.close_search_drawer);
close.setVisibility(View.GONE);
drawerSearch.addTextChangedListener(new SimpleTextWatcher() {
@Override
public void afterTextChanged(Editable editable) {
final String result = editable.toString();
if (result.isEmpty()) {
close.setVisibility(View.GONE);
} else {
close.setVisibility(View.VISIBLE);
}
sideArrayAdapter.getFilter().filter(result);
}
});
} else {
if (drawerSearch != null) {
drawerSearch.setOnClickListener(// remove the touch listener on the drawer search field
null);
drawerSearch.setVisibility(View.GONE);
}
}
}
use of me.ccrama.redditslide.util.stubs.SimpleTextWatcher 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.getBindingAdapterPosition() + 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 = inflater.inflate(SettingValues.rightHandedCommentMenu ? R.layout.comment_menu_right_handed : 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 = baseView.findViewById(R.id.upvote);
final ImageView downvote = baseView.findViewById(R.id.downvote);
View discard = baseView.findViewById(R.id.discard);
final EditText replyLine = baseView.findViewById(R.id.replyLine);
final ImageView mod = baseView.findViewById(R.id.mod);
final Comment comment = baseNode.getComment();
if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
BlendModeUtil.tintImageViewAsModulate(upvote, holder.textColorUp);
upvote.setContentDescription(mContext.getResources().getString(R.string.btn_upvoted));
} else if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
BlendModeUtil.tintImageViewAsModulate(downvote, holder.textColorDown);
downvote.setContentDescription(mContext.getResources().getString(R.string.btn_downvoted));
} else {
downvote.clearColorFilter();
downvote.setContentDescription(mContext.getResources().getString(R.string.btn_downvote));
upvote.clearColorFilter();
upvote.setContentDescription(mContext.getResources().getString(R.string.btn_upvote));
}
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))) {
mod.setVisibility(View.VISIBLE);
final Map<String, Integer> reports = comment.getUserReports();
final Map<String, String> reports2 = comment.getModeratorReports();
if (reports.size() + reports2.size() > 0) {
BlendModeUtil.tintImageViewAsSrcAtop(mod, ContextCompat.getColor(mContext, R.color.md_red_300));
} else {
BlendModeUtil.tintImageViewAsSrcAtop(mod, Color.WHITE);
}
mod.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
CommentAdapterHelper.showModBottomSheet(CommentAdapter.this, mContext, baseNode, comment, holder, reports, reports2);
}
});
} else {
mod.setVisibility(View.GONE);
}
final ImageView edit = 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 = 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() && !(comment.getDataNode().has("locked") && comment.getDataNode().get("locked").asBoolean()) && !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 = 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);
new AlertDialog.Builder(mContext).setTitle(R.string.sorting_choose).setSingleChoiceItems(keys.toArray(new String[0]), i, (dialog, which) -> {
changedProfile = keys.get(which);
profile.setText("/u/" + changedProfile);
}).setNegativeButton(R.string.btn_cancel, null).show();
}
});
replyLine.requestFocus();
KeyboardUtil.toggleKeyboard(mContext, InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
currentlyEditingId = n.getFullName();
replyLine.setText(backedText);
replyLine.addTextChangedListener(new SimpleTextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
backedText = s.toString();
}
});
editingPosition = holder.getBindingAdapterPosition();
}
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) {
final ImageView saveDraft = (ImageView) replyArea.findViewById(R.id.savedraft);
final ImageView draft = (ImageView) replyArea.findViewById(R.id.draft);
final ImageView imagerep = (ImageView) replyArea.findViewById(R.id.imagerep);
final ImageView link = (ImageView) replyArea.findViewById(R.id.link);
final ImageView bold = (ImageView) replyArea.findViewById(R.id.bold);
final ImageView italics = (ImageView) replyArea.findViewById(R.id.italics);
final ImageView bulletlist = (ImageView) replyArea.findViewById(R.id.bulletlist);
final ImageView numlist = (ImageView) replyArea.findViewById(R.id.numlist);
final ImageView draw = (ImageView) replyArea.findViewById(R.id.draw);
final ImageView quote = (ImageView) replyArea.findViewById(R.id.quote);
final ImageView size = (ImageView) replyArea.findViewById(R.id.size);
final ImageView strike = (ImageView) replyArea.findViewById(R.id.strike);
final ImageView author = (ImageView) replyArea.findViewById(R.id.author);
final ImageView spoiler = (ImageView) replyArea.findViewById(R.id.spoiler);
final List<ImageView> imageViewSet = Arrays.asList(saveDraft, draft, imagerep, link, bold, italics, bulletlist, numlist, draw, quote, size, strike, author, spoiler);
BlendModeUtil.tintImageViewsAsSrcAtop(imageViewSet, Color.WHITE);
BlendModeUtil.tintDrawableAsSrcIn(replyLine.getBackground(), Color.WHITE);
}
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 = 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);
new AlertDialog.Builder(mContext).setTitle(R.string.sorting_choose).setSingleChoiceItems(keys.toArray(new String[0]), i, (dialog, which) -> {
changedProfile = keys.get(which);
profile.setText("/u/" + changedProfile);
}).setNegativeButton(R.string.btn_cancel, null).show();
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
replyLine.setOnFocusChangeListener((view, b) -> {
if (b) {
view.postDelayed(() -> {
if (!view.hasFocus())
view.requestFocus();
}, 100);
}
});
}
// TODO: Not working when called a second time
replyLine.requestFocus();
KeyboardUtil.toggleKeyboard(mContext, InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
currentlyEditingId = n.getFullName();
replyLine.addTextChangedListener(new SimpleTextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
backedText = s.toString();
}
});
editingPosition = holder.getBindingAdapterPosition();
}
});
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).findViewById(android.R.id.content);
if (view != null) {
KeyboardUtil.hideKeyboard(mContext, 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).findViewById(android.R.id.content);
if (view != null) {
KeyboardUtil.hideKeyboard(mContext, 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);
BlendModeUtil.tintImageViewAsModulate(upvote, holder.textColorUp);
}
}
});
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);
BlendModeUtil.tintImageViewAsModulate(downvote, holder.textColorDown);
}
}
});
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.stubs.SimpleTextWatcher in project Slide by ccrama.
the class SetupWidget method doShortcut.
public void doShortcut() {
setContentView(R.layout.activity_setup_widget);
setupAppBar(R.id.toolbar, R.string.widget_creation_title, true, true);
header = getLayoutInflater().inflate(R.layout.widget_header, null);
ListView list = (ListView) findViewById(R.id.subs);
final ArrayList<String> sorted = UserSubscriptions.getSubscriptionsForShortcut(SetupWidget.this);
final SubChooseAdapter adapter = new SubChooseAdapter(this, sorted, UserSubscriptions.getAllSubreddits(this));
list.addHeaderView(header);
list.setAdapter(adapter);
(header.findViewById(R.id.sort)).clearFocus();
((EditText) header.findViewById(R.id.sort)).addTextChangedListener(new SimpleTextWatcher() {
@Override
public void afterTextChanged(Editable editable) {
final String result = editable.toString();
adapter.getFilter().filter(result);
}
});
}
use of me.ccrama.redditslide.util.stubs.SimpleTextWatcher in project Slide by ccrama.
the class Crosspost method onCreate.
public void onCreate(Bundle savedInstanceState) {
disableSwipeBackLayout();
super.onCreate(savedInstanceState);
applyColorTheme();
setContentView(R.layout.activity_crosspost);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = this.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
}
setupAppBar(R.id.toolbar, R.string.title_crosspost, true, true);
inboxReplies = (SwitchCompat) findViewById(R.id.replies);
final AutoCompleteTextView subredditText = ((AutoCompleteTextView) findViewById(R.id.subreddittext));
((EditText) findViewById(R.id.crossposttext)).setText(toCrosspost.getTitle() + getString(R.string.submission_properties_seperator) + "/u/" + toCrosspost.getAuthor());
findViewById(R.id.crossposttext).setEnabled(false);
ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, UserSubscriptions.getAllSubreddits(this));
subredditText.setAdapter(adapter);
subredditText.setThreshold(2);
subredditText.addTextChangedListener(new SimpleTextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (tchange != null) {
tchange.cancel(true);
}
findViewById(R.id.submittext).setVisibility(View.GONE);
}
});
subredditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
findViewById(R.id.submittext).setVisibility(View.GONE);
if (!hasFocus) {
tchange = new AsyncTask<Void, Void, Subreddit>() {
@Override
protected Subreddit doInBackground(Void... params) {
try {
return Authentication.reddit.getSubreddit(subredditText.getText().toString());
} catch (Exception ignored) {
}
return null;
}
@Override
protected void onPostExecute(Subreddit s) {
if (s != null) {
String text = s.getDataNode().get("submit_text_html").asText();
if (text != null && !text.isEmpty() && !text.equals("null")) {
findViewById(R.id.submittext).setVisibility(View.VISIBLE);
setViews(text, subredditText.getText().toString(), (SpoilerRobotoTextView) findViewById(R.id.submittext), (CommentOverflow) findViewById(R.id.commentOverflow));
}
if (s.getSubredditType().equals("RESTRICTED")) {
subredditText.setText("");
new AlertDialog.Builder(Crosspost.this).setTitle(R.string.err_submit_restricted).setMessage(R.string.err_submit_restricted_text).setPositiveButton(R.string.btn_ok, null).show();
}
} else {
findViewById(R.id.submittext).setVisibility(View.GONE);
}
}
};
tchange.execute();
}
}
});
((EditText) findViewById(R.id.titletext)).setText(toCrosspost.getTitle());
findViewById(R.id.suggest).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((EditText) findViewById(R.id.titletext)).setText(toCrosspost.getTitle());
}
});
findViewById(R.id.send).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((FloatingActionButton) findViewById(R.id.send)).hide();
new AsyncDo().execute();
}
});
}
Aggregations