Search in sources :

Example 1 with SimpleTextWatcher

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();
        }
    });
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) ArrayList(java.util.ArrayList) Uri(android.net.Uri) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) AlertDialog(androidx.appcompat.app.AlertDialog) Dialog(android.app.Dialog) Window(android.view.Window) ImageInsertEditText(me.ccrama.redditslide.Views.ImageInsertEditText) EditText(android.widget.EditText) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) RadioButton(android.widget.RadioButton) ImageView(android.widget.ImageView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) ApiException(net.dean.jraw.ApiException) SimpleTextWatcher(me.ccrama.redditslide.util.stubs.SimpleTextWatcher) ImageInsertEditText(me.ccrama.redditslide.Views.ImageInsertEditText) Subreddit(net.dean.jraw.models.Subreddit) TedBottomPicker(gun0912.tedbottompicker.TedBottomPicker) ArrayAdapter(android.widget.ArrayAdapter) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 2 with SimpleTextWatcher

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);
        }
    }
}
Also used : Intent(android.content.Intent) SideArrayAdapter(me.ccrama.redditslide.Adapters.SideArrayAdapter) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) CardView(androidx.cardview.widget.CardView) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) Point(android.graphics.Point) KeyEvent(android.view.KeyEvent) SimpleTextWatcher(me.ccrama.redditslide.util.stubs.SimpleTextWatcher) Editable(android.text.Editable) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView)

Example 3 with SimpleTextWatcher

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)));
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) LinearLayout(android.widget.LinearLayout) Arrays(java.util.Arrays) R(me.ccrama.redditslide.R) RobotoTypefaces(com.devspark.robototextview.RobotoTypefaces) AnimatorUtil(me.ccrama.redditslide.util.AnimatorUtil) Uri(android.net.Uri) ImageView(android.widget.ImageView) Animator(android.animation.Animator) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) Locale(java.util.Locale) Handler(android.os.Handler) Looper(android.os.Looper) Map(java.util.Map) View(android.view.View) Drafts(me.ccrama.redditslide.Drafts) PreCachingLayoutManagerComments(me.ccrama.redditslide.Views.PreCachingLayoutManagerComments) RecyclerView(androidx.recyclerview.widget.RecyclerView) DiskCacheUtils(com.nostra13.universalimageloader.utils.DiskCacheUtils) ContextCompat(androidx.core.content.ContextCompat) Log(android.util.Log) PrintWriter(java.io.PrintWriter) AsyncTask(android.os.AsyncTask) KeyboardUtil(me.ccrama.redditslide.util.KeyboardUtil) Authentication(me.ccrama.redditslide.Authentication) CommentPage(me.ccrama.redditslide.Fragments.CommentPage) ApiException(net.dean.jraw.ApiException) DisplayUtil(me.ccrama.redditslide.util.DisplayUtil) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) Palette(me.ccrama.redditslide.Visuals.Palette) BlendModeUtil(me.ccrama.redditslide.util.BlendModeUtil) SimpleTextWatcher(me.ccrama.redditslide.util.stubs.SimpleTextWatcher) ViewGroup(android.view.ViewGroup) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) List(java.util.List) TextView(android.widget.TextView) Contribution(net.dean.jraw.models.Contribution) Writer(java.io.Writer) RelativeLayout(android.widget.RelativeLayout) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) CommentOverflow(me.ccrama.redditslide.Views.CommentOverflow) BuildConfig(me.ccrama.redditslide.BuildConfig) SubmissionParser(me.ccrama.redditslide.util.SubmissionParser) Typeface(android.graphics.Typeface) DoEditorActions(me.ccrama.redditslide.Views.DoEditorActions) Context(android.content.Context) BaseActivity(me.ccrama.redditslide.Activities.BaseActivity) SettingValues(me.ccrama.redditslide.SettingValues) AlertDialog(androidx.appcompat.app.AlertDialog) HasSeen(me.ccrama.redditslide.HasSeen) FontPreferences(me.ccrama.redditslide.Visuals.FontPreferences) Submission(net.dean.jraw.models.Submission) Vote(me.ccrama.redditslide.Vote) BitmapFactory(android.graphics.BitmapFactory) HashMap(java.util.HashMap) Constants(me.ccrama.redditslide.Constants) LogUtil(me.ccrama.redditslide.util.LogUtil) InputMethodManager(android.view.inputmethod.InputMethodManager) AccountManager(net.dean.jraw.managers.AccountManager) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UserSubscriptions(me.ccrama.redditslide.UserSubscriptions) SlideRightAlphaAnimator(com.mikepenz.itemanimators.SlideRightAlphaAnimator) Build(android.os.Build) OpenRedditLink(me.ccrama.redditslide.OpenRedditLink) AlphaInAnimator(com.mikepenz.itemanimators.AlphaInAnimator) FragmentManager(androidx.fragment.app.FragmentManager) RedditClient(net.dean.jraw.RedditClient) UserAgent(net.dean.jraw.http.UserAgent) LayoutInflater(android.view.LayoutInflater) StringWriter(java.io.StringWriter) ImageFlairs(me.ccrama.redditslide.ImageFlairs) Reddit(me.ccrama.redditslide.Reddit) VoteDirection(net.dean.jraw.models.VoteDirection) KVStore(com.lusfold.androidkeyvaluestore.KVStore) File(java.io.File) Color(android.graphics.Color) TypedValue(android.util.TypedValue) TreeMap(java.util.TreeMap) Bitmap(android.graphics.Bitmap) ActionStates(me.ccrama.redditslide.ActionStates) CommentNode(net.dean.jraw.models.CommentNode) LastComments(me.ccrama.redditslide.LastComments) Activity(android.app.Activity) Collections(java.util.Collections) EditText(android.widget.EditText) Comment(net.dean.jraw.models.Comment) ValueAnimator(android.animation.ValueAnimator) Resources(android.content.res.Resources) HashMap(java.util.HashMap) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) ArrayList(java.util.ArrayList) BaseActivity(me.ccrama.redditslide.Activities.BaseActivity) Activity(android.app.Activity) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) List(java.util.List) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) HashSet(java.util.HashSet) EditText(android.widget.EditText) Comment(net.dean.jraw.models.Comment) Vote(me.ccrama.redditslide.Vote) ViewGroup(android.view.ViewGroup) ImageView(android.widget.ImageView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) ApiException(net.dean.jraw.ApiException) SimpleTextWatcher(me.ccrama.redditslide.util.stubs.SimpleTextWatcher) LayoutInflater(android.view.LayoutInflater) BaseActivity(me.ccrama.redditslide.Activities.BaseActivity) RelativeLayout(android.widget.RelativeLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 4 with SimpleTextWatcher

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);
        }
    });
}
Also used : EditText(android.widget.EditText) SubChooseAdapter(me.ccrama.redditslide.Adapters.SubChooseAdapter) ListView(android.widget.ListView) SimpleTextWatcher(me.ccrama.redditslide.util.stubs.SimpleTextWatcher) Editable(android.text.Editable)

Example 5 with SimpleTextWatcher

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();
        }
    });
}
Also used : Window(android.view.Window) EditText(android.widget.EditText) AsyncTask(android.os.AsyncTask) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) ApiException(net.dean.jraw.ApiException) SimpleTextWatcher(me.ccrama.redditslide.util.stubs.SimpleTextWatcher) Subreddit(net.dean.jraw.models.Subreddit) ArrayAdapter(android.widget.ArrayAdapter) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Aggregations

SimpleTextWatcher (me.ccrama.redditslide.util.stubs.SimpleTextWatcher)9 EditText (android.widget.EditText)7 View (android.view.View)6 Editable (android.text.Editable)5 TextView (android.widget.TextView)5 SpoilerRobotoTextView (me.ccrama.redditslide.SpoilerRobotoTextView)5 Intent (android.content.Intent)4 AutoCompleteTextView (android.widget.AutoCompleteTextView)4 ImageView (android.widget.ImageView)4 ListView (android.widget.ListView)4 ArrayList (java.util.ArrayList)4 AsyncTask (android.os.AsyncTask)3 AlertDialog (androidx.appcompat.app.AlertDialog)3 ApiException (net.dean.jraw.ApiException)3 Dialog (android.app.Dialog)2 Resources (android.content.res.Resources)2 Uri (android.net.Uri)2 KeyEvent (android.view.KeyEvent)2 LayoutInflater (android.view.LayoutInflater)2 Window (android.view.Window)2