Search in sources :

Example 1 with TedBottomPicker

use of gun0912.tedbottompicker.TedBottomPicker 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);
    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);
    }
    ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, UserSubscriptions.getAllSubreddits(this));
    subredditText.setAdapter(adapter);
    subredditText.setThreshold(2);
    subredditText.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) {
            if (tchange != null) {
                tchange.cancel(true);
            }
            findViewById(R.id.submittext).setVisibility(View.GONE);
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    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 AlertDialogWrapper.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.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 AlertDialogWrapper.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(new TedBottomPicker.OnImageSelectedListener() {

                @Override
                public void onImageSelected(List<Uri> uri) {
                    handleImageIntent(uri);
                }
            }).setLayoutResource(R.layout.image_sheet_dialog).setTitle("Choose a photo").create();
            tedBottomPicker.show(getSupportFragmentManager());
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(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()) {
        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"), data.length()));
        } 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 : ArrayList(java.util.ArrayList) InputMethodManager(android.view.inputmethod.InputMethodManager) Uri(android.net.Uri) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Dialog(android.app.Dialog) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) Window(android.view.Window) 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) AutoCompleteTextView(android.widget.AutoCompleteTextView) ApiException(net.dean.jraw.ApiException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Subreddit(net.dean.jraw.models.Subreddit) TedBottomPicker(gun0912.tedbottompicker.TedBottomPicker) ArrayAdapter(android.widget.ArrayAdapter) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 2 with TedBottomPicker

use of gun0912.tedbottompicker.TedBottomPicker in project Slide by ccrama.

the class DoEditorActions method doDraw.

public static void doDraw(final Activity a, final EditText editText, final FragmentManager fm) {
    final Intent intent = new Intent(a, Draw.class);
    InputMethodManager imm = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
    e = editText.getText();
    TedBottomPicker tedBottomPicker = new TedBottomPicker.Builder(editText.getContext()).setOnImageSelectedListener(new TedBottomPicker.OnImageSelectedListener() {

        @Override
        public void onImageSelected(List<Uri> uri) {
            Draw.uri = uri.get(0);
            Fragment auxiliary = new AuxiliaryFragment();
            sStart = editText.getSelectionStart();
            sEnd = editText.getSelectionEnd();
            fm.beginTransaction().add(auxiliary, "IMAGE_UPLOAD").commit();
            fm.executePendingTransactions();
            auxiliary.startActivityForResult(intent, 3333);
        }
    }).setLayoutResource(R.layout.image_sheet_dialog).setTitle("Choose a photo").create();
    tedBottomPicker.show(fm);
}
Also used : Intent(android.content.Intent) InputMethodManager(android.view.inputmethod.InputMethodManager) List(java.util.List) ArrayList(java.util.ArrayList) TedBottomPicker(gun0912.tedbottompicker.TedBottomPicker) Fragment(android.support.v4.app.Fragment)

Example 3 with TedBottomPicker

use of gun0912.tedbottompicker.TedBottomPicker in project Slide by ccrama.

the class DoEditorActions method doActions.

public static void doActions(final EditText editText, final View baseView, final FragmentManager fm, final Activity a, final String oldComment, @Nullable final String[] authors) {
    baseView.findViewById(R.id.bold).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (editText.hasSelection()) {
                wrapString("**", // If the user has text selected, wrap that text in the symbols
                editText);
            } else {
                // If the user doesn't have text selected, put the symbols around the cursor's position
                int pos = editText.getSelectionStart();
                editText.getText().insert(pos, "**");
                editText.getText().insert(pos + 1, "**");
                // put the cursor between the symbols
                editText.setSelection(pos + 2);
            }
        }
    });
    if (baseView.findViewById(R.id.author) != null) {
        if (authors != null && authors.length > 0) {
            baseView.findViewById(R.id.author).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (authors.length == 1) {
                        int pos = editText.getSelectionStart();
                        String author = "/u/" + authors[0];
                        editText.setText(editText.getText().toString() + author);
                        // put the cursor between the symbols
                        editText.setSelection(pos + author.length());
                    } else {
                        new AlertDialogWrapper.Builder(a).setTitle(R.string.authors_above).setItems(authors, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                int pos = editText.getSelectionStart();
                                String author = "/u/" + authors[which];
                                editText.setText(editText.getText().toString() + author);
                                // put the cursor between the symbols
                                editText.setSelection(pos + author.length());
                            }
                        }).setNeutralButton(R.string.btn_cancel, null).show();
                    }
                }
            });
        } else {
            baseView.findViewById(R.id.author).setVisibility(View.GONE);
        }
    }
    baseView.findViewById(R.id.italics).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (editText.hasSelection()) {
                wrapString("*", // If the user has text selected, wrap that text in the symbols
                editText);
            } else {
                // If the user doesn't have text selected, put the symbols around the cursor's position
                int pos = editText.getSelectionStart();
                editText.getText().insert(pos, "*");
                editText.getText().insert(pos + 1, "*");
                // put the cursor between the symbols
                editText.setSelection(pos + 1);
            }
        }
    });
    baseView.findViewById(R.id.strike).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (editText.hasSelection()) {
                wrapString("~~", // If the user has text selected, wrap that text in the symbols
                editText);
            } else {
                // If the user doesn't have text selected, put the symbols around the cursor's position
                int pos = editText.getSelectionStart();
                editText.getText().insert(pos, "~~");
                editText.getText().insert(pos + 1, "~~");
                // put the cursor between the symbols
                editText.setSelection(pos + 2);
            }
        }
    });
    baseView.findViewById(R.id.savedraft).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Drafts.addDraft(editText.getText().toString());
            Snackbar s = Snackbar.make(baseView.findViewById(R.id.savedraft), "Draft saved", Snackbar.LENGTH_SHORT);
            View view = s.getView();
            TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
            tv.setTextColor(Color.WHITE);
            s.setAction(R.string.btn_discard, new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    Drafts.deleteDraft(Drafts.getDrafts().size() - 1);
                }
            });
            s.show();
        }
    });
    baseView.findViewById(R.id.draft).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final ArrayList<String> drafts = Drafts.getDrafts();
            Collections.reverse(drafts);
            final String[] draftText = new String[drafts.size()];
            for (int i = 0; i < drafts.size(); i++) {
                draftText[i] = drafts.get(i);
            }
            if (drafts.isEmpty()) {
                new AlertDialogWrapper.Builder(a).setTitle(R.string.dialog_no_drafts).setMessage(R.string.dialog_no_drafts_msg).setPositiveButton(R.string.btn_ok, null).show();
            } else {
                new AlertDialogWrapper.Builder(a).setTitle(R.string.choose_draft).setItems(draftText, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        editText.setText(editText.getText().toString() + draftText[which]);
                    }
                }).setNeutralButton(R.string.btn_cancel, null).setPositiveButton(R.string.manage_drafts, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        final boolean[] selected = new boolean[drafts.size()];
                        new AlertDialogWrapper.Builder(a).setTitle(R.string.choose_draft).setNeutralButton(R.string.btn_cancel, null).alwaysCallMultiChoiceCallback().setNegativeButton(R.string.btn_delete, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                new AlertDialogWrapper.Builder(a).setTitle(R.string.really_delete_drafts).setCancelable(false).setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        ArrayList<String> draf = new ArrayList<>();
                                        for (int i = 0; i < draftText.length; i++) {
                                            if (!selected[i]) {
                                                draf.add(draftText[i]);
                                            }
                                        }
                                        Drafts.save(draf);
                                    }
                                }).setNegativeButton(R.string.btn_no, null).show();
                            }
                        }).setMultiChoiceItems(draftText, selected, new DialogInterface.OnMultiChoiceClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                                selected[which] = isChecked;
                            }
                        }).show();
                    }
                }).show();
            }
        }
    });
    /*todo baseView.findViewById(R.id.strikethrough).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                wrapString("~~", editText);
            }
        });*/
    baseView.findViewById(R.id.imagerep).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            e = editText.getText();
            sStart = editText.getSelectionStart();
            sEnd = editText.getSelectionEnd();
            TedBottomPicker tedBottomPicker = new TedBottomPicker.Builder(editText.getContext()).setOnImageSelectedListener(new TedBottomPicker.OnImageSelectedListener() {

                @Override
                public void onImageSelected(List<Uri> uri) {
                    handleImageIntent(uri, editText, a);
                }
            }).setLayoutResource(R.layout.image_sheet_dialog).setTitle("Choose a photo").create();
            tedBottomPicker.show(fm);
            InputMethodManager imm = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
        }
    });
    baseView.findViewById(R.id.draw).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (SettingValues.tabletUI) {
                doDraw(a, editText, fm);
            } else {
                AlertDialogWrapper.Builder b = new AlertDialogWrapper.Builder(a).setTitle(R.string.general_cropdraw_ispro).setMessage(R.string.pro_upgrade_msg).setPositiveButton(R.string.btn_yes_exclaim, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        try {
                            a.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=me.ccrama.slideforreddittabletuiunlock")));
                        } catch (ActivityNotFoundException e) {
                            a.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();
                    }
                });
                if (SettingValues.previews > 0) {
                    b.setNeutralButton(a.getString(R.string.pro_previews, SettingValues.previews), new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            SettingValues.prefs.edit().putInt(SettingValues.PREVIEWS_LEFT, SettingValues.previews - 1).apply();
                            SettingValues.previews = SettingValues.prefs.getInt(SettingValues.PREVIEWS_LEFT, 10);
                            doDraw(a, editText, fm);
                        }
                    });
                }
                b.show();
            }
        }
    });
    /*todo baseView.findViewById(R.id.superscript).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                insertBefore("^", editText);
            }
        });*/
    baseView.findViewById(R.id.size).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            insertBefore("#", editText);
        }
    });
    baseView.findViewById(R.id.quote).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (oldComment != null) {
                final TextView showText = new TextView(a);
                showText.setText(oldComment);
                showText.setTextIsSelectable(true);
                int sixteen = Reddit.dpToPxVertical(24);
                showText.setPadding(sixteen, 0, sixteen, 0);
                AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(a);
                builder.setView(showText).setTitle(R.string.editor_actions_quote_comment).setCancelable(true).setPositiveButton(a.getString(R.string.btn_select), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        String selected = showText.getText().toString().substring(showText.getSelectionStart(), showText.getSelectionEnd());
                        if (selected.equals("")) {
                            insertBefore("> " + oldComment, editText);
                        } else {
                            insertBefore("> " + selected + "\n\n", editText);
                        }
                    }
                }).setNegativeButton(a.getString(R.string.btn_cancel), null).show();
            } else {
                insertBefore("> ", editText);
            }
        }
    });
    baseView.findViewById(R.id.bulletlist).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            insertBefore("* ", editText);
        }
    });
    baseView.findViewById(R.id.numlist).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            insertBefore("1. ", editText);
        }
    });
    baseView.findViewById(R.id.preview).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            List<Extension> extensions = Arrays.asList(TablesExtension.create(), StrikethroughExtension.create());
            Parser parser = Parser.builder().extensions(extensions).build();
            HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).build();
            Node document = parser.parse(editText.getText().toString());
            String html = renderer.render(document);
            LayoutInflater inflater = a.getLayoutInflater();
            final View dialoglayout = inflater.inflate(R.layout.parent_comment_dialog, null);
            final AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(a);
            setViews(html, "NO sub", (SpoilerRobotoTextView) dialoglayout.findViewById(R.id.firstTextView), (CommentOverflow) dialoglayout.findViewById(R.id.commentOverflow));
            builder.setView(dialoglayout);
            builder.show();
        }
    });
    baseView.findViewById(R.id.link).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final LayoutInflater inflater = LayoutInflater.from(a);
            final LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.insert_link, null);
            int[] attrs = { R.attr.fontColor };
            TypedArray ta = baseView.getContext().obtainStyledAttributes(new ColorPreferences(baseView.getContext()).getFontStyle().getBaseId(), attrs);
            ta.recycle();
            String selectedText = "";
            // if the user highlighted text before inputting a URL, use that text for the descriptionBox
            if (editText.hasSelection()) {
                final int startSelection = editText.getSelectionStart();
                final int endSelection = editText.getSelectionEnd();
                selectedText = editText.getText().toString().substring(startSelection, endSelection);
            }
            final boolean selectedTextNotEmpty = !selectedText.isEmpty();
            final MaterialDialog dialog = new MaterialDialog.Builder(editText.getContext()).title(R.string.editor_title_link).customView(layout, false).positiveColorAttr(R.attr.tintColor).positiveText(R.string.editor_action_link).onPositive(new MaterialDialog.SingleButtonCallback() {

                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    final EditText urlBox = (EditText) dialog.findViewById(R.id.url_box);
                    final EditText textBox = (EditText) dialog.findViewById(R.id.text_box);
                    dialog.dismiss();
                    final String s = "[".concat(textBox.getText().toString()).concat("](").concat(urlBox.getText().toString()).concat(")");
                    int start = Math.max(editText.getSelectionStart(), 0);
                    int end = Math.max(editText.getSelectionEnd(), 0);
                    editText.getText().insert(Math.max(start, end), s);
                    // delete the selected text to avoid duplication
                    if (selectedTextNotEmpty) {
                        editText.getText().delete(start, end);
                    }
                }
            }).build();
            // Tint the hint text if the base theme is Sepia
            if (SettingValues.currentTheme == 5) {
                ((EditText) dialog.findViewById(R.id.url_box)).setHintTextColor(ContextCompat.getColor(dialog.getContext(), R.color.md_grey_600));
                ((EditText) dialog.findViewById(R.id.text_box)).setHintTextColor(ContextCompat.getColor(dialog.getContext(), R.color.md_grey_600));
            }
            // use the selected text as the text for the link
            if (!selectedText.isEmpty()) {
                ((EditText) dialog.findViewById(R.id.text_box)).setText(selectedText);
            }
            dialog.show();
        }
    });
    try {
        ((ImageInsertEditText) editText).setImageSelectedCallback(new ImageInsertEditText.ImageSelectedCallback() {

            @Override
            public void onImageSelected(final Uri content, String mimeType) {
                e = editText.getText();
                sStart = editText.getSelectionStart();
                sEnd = editText.getSelectionEnd();
                handleImageIntent(new ArrayList<Uri>() {

                    {
                        add(content);
                    }
                }, editText, a);
            }
        });
    } catch (Exception e) {
    // if thrown, there is likely an issue implementing this on the user's version of Android. There shouldn't be an issue, but just in case
    }
}
Also used : DialogInterface(android.content.DialogInterface) Node(org.commonmark.node.Node) ArrayList(java.util.ArrayList) InputMethodManager(android.view.inputmethod.InputMethodManager) Uri(android.net.Uri) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) TypedArray(android.content.res.TypedArray) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) List(java.util.List) ArrayList(java.util.ArrayList) EditText(android.widget.EditText) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ColorPreferences(me.ccrama.redditslide.ColorPreferences) Intent(android.content.Intent) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) TextView(android.widget.TextView) FileNotFoundException(java.io.FileNotFoundException) ActivityNotFoundException(android.content.ActivityNotFoundException) IOException(java.io.IOException) Parser(org.commonmark.parser.Parser) SubmissionParser(me.ccrama.redditslide.util.SubmissionParser) ActivityNotFoundException(android.content.ActivityNotFoundException) DialogAction(com.afollestad.materialdialogs.DialogAction) LayoutInflater(android.view.LayoutInflater) HtmlRenderer(org.commonmark.html.HtmlRenderer) TedBottomPicker(gun0912.tedbottompicker.TedBottomPicker) LinearLayout(android.widget.LinearLayout) Snackbar(android.support.design.widget.Snackbar)

Aggregations

Intent (android.content.Intent)3 InputMethodManager (android.view.inputmethod.InputMethodManager)3 TedBottomPicker (gun0912.tedbottompicker.TedBottomPicker)3 ArrayList (java.util.ArrayList)3 Uri (android.net.Uri)2 View (android.view.View)2 EditText (android.widget.EditText)2 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)2 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 List (java.util.List)2 SpoilerRobotoTextView (me.ccrama.redditslide.SpoilerRobotoTextView)2 Dialog (android.app.Dialog)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 DialogInterface (android.content.DialogInterface)1 TypedArray (android.content.res.TypedArray)1 AsyncTask (android.os.AsyncTask)1 Snackbar (android.support.design.widget.Snackbar)1 Fragment (android.support.v4.app.Fragment)1