Search in sources :

Example 41 with ColorPreferences

use of me.ccrama.redditslide.ColorPreferences in project Slide by ccrama.

the class SettingsSubreddit method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    applyColorTheme();
    setContentView(R.layout.activity_settings_subreddit);
    SettingsTheme.changed = true;
    setupAppBar(R.id.toolbar, R.string.title_subreddit_settings, true, true);
    recycler = ((RecyclerView) findViewById(R.id.subslist));
    recycler.setLayoutManager(new LinearLayoutManager(this));
    reloadSubList();
    findViewById(R.id.reset).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new AlertDialogWrapper.Builder(SettingsSubreddit.this).setTitle(R.string.clear_all_sub_themes).setMessage(R.string.clear_all_sub_themes_msg).setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    for (String s : changedSubs) {
                        Palette.removeColor(s);
                        SettingValues.prefs.edit().remove(Reddit.PREF_LAYOUT + s).apply();
                        new ColorPreferences(SettingsSubreddit.this).removeFontStyle(s);
                        SettingValues.resetPicsEnabled(s);
                    }
                    reloadSubList();
                }
            }).setNegativeButton(R.string.btn_no, null).show();
        }
    });
    findViewById(R.id.post_floating_action_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            final ArrayList<String> subs = UserSubscriptions.sort(UserSubscriptions.getSubscriptions(SettingsSubreddit.this));
            final CharSequence[] subsAsChar = subs.toArray(new CharSequence[subs.size()]);
            MaterialDialog.Builder builder = new MaterialDialog.Builder(SettingsSubreddit.this);
            builder.title(R.string.dialog_choose_subreddits_to_edit).items(subsAsChar).itemsCallbackMultiChoice(null, new MaterialDialog.ListCallbackMultiChoice() {

                @Override
                public boolean onSelection(MaterialDialog dialog, Integer[] which, CharSequence[] text) {
                    ArrayList<String> selectedSubs = new ArrayList<>();
                    for (int i : which) {
                        selectedSubs.add(subsAsChar[i].toString());
                    }
                    if (mSettingsSubAdapter != null)
                        mSettingsSubAdapter.prepareAndShowSubEditor(selectedSubs);
                    return true;
                }
            }).positiveText(R.string.btn_select).negativeText(R.string.btn_cancel).show();
        }
    });
    findViewById(R.id.color).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (Authentication.isLoggedIn) {
                new AlertDialogWrapper.Builder(SettingsSubreddit.this).setTitle(R.string.dialog_color_sync_title).setMessage(R.string.dialog_color_sync_message).setPositiveButton(R.string.misc_continue, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        final MaterialDialog d = new MaterialDialog.Builder(SettingsSubreddit.this).title(R.string.general_sub_sync).content(R.string.misc_please_wait).progress(false, 100).cancelable(false).show();
                        new AsyncTask<Void, Void, Void>() {

                            @Override
                            protected Void doInBackground(Void... params) {
                                ArrayList<Subreddit> subColors = UserSubscriptions.syncSubredditsGetObject();
                                d.setMaxProgress(subColors.size());
                                int i = 0;
                                done = 0;
                                for (Subreddit s : subColors) {
                                    if (s.getDataNode().has("key_color") && !s.getDataNode().get("key_color").asText().isEmpty() && Palette.getColor(s.getDisplayName().toLowerCase(Locale.ENGLISH)) == Palette.getDefaultColor()) {
                                        Palette.setColor(s.getDisplayName().toLowerCase(Locale.ENGLISH), GetClosestColor.getClosestColor(s.getDataNode().get("key_color").asText(), SettingsSubreddit.this));
                                        done++;
                                    }
                                    d.setProgress(i);
                                    i++;
                                    if (i == d.getMaxProgress()) {
                                        d.dismiss();
                                    }
                                }
                                return null;
                            }

                            @Override
                            protected void onPostExecute(Void aVoid) {
                                reloadSubList();
                                Resources res = getResources();
                                new AlertDialogWrapper.Builder(SettingsSubreddit.this).setTitle(R.string.color_sync_complete).setMessage(res.getQuantityString(R.plurals.color_sync_colored, done, done)).setPositiveButton(getString(R.string.btn_ok), null).show();
                            }
                        }.execute();
                        d.show();
                    }
                }).setNegativeButton(R.string.btn_cancel, null).show();
            } else {
                Snackbar s = Snackbar.make(mToolbar, R.string.err_color_sync_login, Snackbar.LENGTH_SHORT);
                View view = s.getView();
                TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
                tv.setTextColor(Color.WHITE);
                s.show();
            }
        }
    });
}
Also used : DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) TextView(android.widget.TextView) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ColorPreferences(me.ccrama.redditslide.ColorPreferences) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) Resources(android.content.res.Resources) Subreddit(net.dean.jraw.models.Subreddit) Snackbar(android.support.design.widget.Snackbar)

Example 42 with ColorPreferences

use of me.ccrama.redditslide.ColorPreferences 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)

Example 43 with ColorPreferences

use of me.ccrama.redditslide.ColorPreferences in project Slide by ccrama.

the class CommentPage method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
    v = localInflater.inflate(R.layout.fragment_verticalcontenttoolbar, container, false);
    rv = (RecyclerView) v.findViewById(R.id.vertical_content);
    rv.setLayoutManager(mLayoutManager);
    rv.getLayoutManager().scrollToPosition(0);
    toolbar = (Toolbar) v.findViewById(R.id.toolbar);
    toolbar.setPopupTheme(new ColorPreferences(getActivity()).getFontStyle().getBaseId());
    if (!SettingValues.fabComments) {
        v.findViewById(R.id.comment_floating_action_button).setVisibility(View.GONE);
    } else {
        fab = (FloatingActionButton) v.findViewById(R.id.comment_floating_action_button);
        if (SettingValues.fastscroll) {
            FrameLayout.LayoutParams fabs = (FrameLayout.LayoutParams) fab.getLayoutParams();
            fabs.setMargins(fabs.leftMargin, fabs.topMargin, fabs.rightMargin, fabs.bottomMargin * 3);
            fab.setLayoutParams(fabs);
        }
        fab.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                LayoutInflater inflater = getActivity().getLayoutInflater();
                final View dialoglayout = inflater.inflate(R.layout.edit_comment, null);
                final AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(getActivity());
                final EditText e = (EditText) dialoglayout.findViewById(R.id.entry);
                // Tint the replyLine appropriately if the base theme is Light or Sepia
                if (SettingValues.currentTheme == 1 || SettingValues.currentTheme == 5) {
                    final int TINT = ContextCompat.getColor(getContext(), R.color.md_grey_600);
                    e.setHintTextColor(TINT);
                    e.getBackground().setColorFilter(TINT, PorterDuff.Mode.SRC_IN);
                }
                DoEditorActions.doActions(e, dialoglayout, getActivity().getSupportFragmentManager(), getActivity(), adapter.submission.isSelfPost() ? adapter.submission.getSelftext() : null, new String[] { adapter.submission.getAuthor() });
                builder.setCancelable(false).setView(dialoglayout);
                final Dialog d = builder.create();
                d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
                d.show();
                dialoglayout.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        d.dismiss();
                    }
                });
                dialoglayout.findViewById(R.id.submit).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        adapter.dataSet.refreshLayout.setRefreshing(true);
                        new ReplyTaskComment(adapter.submission).execute(e.getText().toString());
                        d.dismiss();
                    }
                });
            }
        });
    }
    if (fab != null)
        fab.show();
    resetScroll(false);
    fastScroll = v.findViewById(R.id.commentnav);
    if (!SettingValues.fastscroll) {
        fastScroll.setVisibility(View.GONE);
    } else {
        v.findViewById(R.id.down).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (adapter != null && adapter.keys != null && adapter.keys.size() > 0) {
                    goDown();
                }
            }
        });
        v.findViewById(R.id.up).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (adapter != null && adapter.keys != null && adapter.keys.size() > 0)
                    goUp();
            }
        });
        v.findViewById(R.id.nav).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (adapter != null && adapter.currentComments != null) {
                    int parentCount, opCount, linkCount, gildCount;
                    parentCount = 0;
                    opCount = 0;
                    linkCount = 0;
                    gildCount = 0;
                    String op = adapter.submission.getAuthor();
                    for (CommentObject o : adapter.currentComments) {
                        if (o.comment != null && !(o instanceof MoreChildItem)) {
                            if (o.comment.isTopLevel())
                                parentCount++;
                            if (o.comment.getComment().getTimesGilded() > 0)
                                gildCount++;
                            if (o.comment.getComment().getAuthor() != null && o.comment.getComment().getAuthor().equals(op)) {
                                opCount++;
                            }
                            if (o.comment.getComment().getDataNode().has("body_html") && o.comment.getComment().getDataNode().get("body_html").asText().contains("&lt;/a")) {
                                linkCount++;
                            }
                        }
                    }
                    new AlertDialogWrapper.Builder(getActivity()).setTitle(R.string.set_nav_mode).setSingleChoiceItems(Reddit.stringToArray("Parent comment (" + parentCount + ")" + "," + "Children comment (highlight child comment & navigate)" + "," + "OP (" + opCount + ")" + "," + "Time" + "," + "Link (" + linkCount + ")" + "," + ((Authentication.isLoggedIn) ? "You" + "," : "") + "Gilded (" + gildCount + ")").toArray(new String[Authentication.isLoggedIn ? 6 : 5]), getCurrentSort(), new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            switch(which) {
                                case 0:
                                    currentSort = CommentNavType.PARENTS;
                                    break;
                                case 1:
                                    currentSort = CommentNavType.CHILDREN;
                                    break;
                                case 2:
                                    currentSort = CommentNavType.OP;
                                    break;
                                case 3:
                                    currentSort = CommentNavType.TIME;
                                    LayoutInflater inflater = getActivity().getLayoutInflater();
                                    final View dialoglayout = inflater.inflate(R.layout.commenttime, null);
                                    final AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(getActivity());
                                    final Slider landscape = (Slider) dialoglayout.findViewById(R.id.landscape);
                                    final TextView since = (TextView) dialoglayout.findViewById(R.id.time_string);
                                    landscape.setValueRange(60, 18000, false);
                                    landscape.setOnPositionChangeListener(new Slider.OnPositionChangeListener() {

                                        @Override
                                        public void onPositionChanged(Slider slider, boolean b, float v, float v1, int i, int i1) {
                                            Calendar c = Calendar.getInstance();
                                            sortTime = c.getTimeInMillis() - i1 * 1000;
                                            int commentcount = 0;
                                            for (CommentObject o : adapter.currentComments) {
                                                if (o.comment != null && o.comment.getComment().getDataNode().has("created") && o.comment.getComment().getCreated().getTime() > sortTime) {
                                                    commentcount += 1;
                                                }
                                            }
                                            since.setText(TimeUtils.getTimeAgo(sortTime, getActivity()) + " (" + commentcount + " comments)");
                                        }
                                    });
                                    landscape.setValue(600, false);
                                    builder.setView(dialoglayout);
                                    builder.setPositiveButton(R.string.btn_set, null).show();
                                    break;
                                case 5:
                                    currentSort = CommentNavType.YOU;
                                    break;
                                case 4:
                                    currentSort = CommentNavType.LINK;
                                    break;
                                case 6:
                                    currentSort = CommentNavType.GILDED;
                                    break;
                            }
                        }
                    }).show();
                }
            }
        });
    }
    v.findViewById(R.id.up).setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            // Scroll to top
            rv.getLayoutManager().scrollToPosition(1);
            return true;
        }
    });
    if (SettingValues.voteGestures) {
        v.findViewById(R.id.up).setOnTouchListener(new OnFlingGestureListener() {

            @Override
            public void onRightToLeft() {
            }

            @Override
            public void onLeftToRight() {
            }

            @Override
            public void onBottomToTop() {
                adapter.submissionViewHolder.upvote.performClick();
                Context context = getContext();
                int duration = Toast.LENGTH_SHORT;
                CharSequence text;
                if (!upvoted) {
                    text = getString(R.string.profile_upvoted);
                    downvoted = false;
                } else {
                    text = getString(R.string.vote_removed);
                }
                upvoted = !upvoted;
                Toast toast = Toast.makeText(context, text, duration);
                toast.show();
            }

            @Override
            public void onTopToBottom() {
            }
        });
    }
    if (SettingValues.voteGestures) {
        v.findViewById(R.id.down).setOnTouchListener(new OnFlingGestureListener() {

            @Override
            public void onRightToLeft() {
            }

            @Override
            public void onLeftToRight() {
            }

            @Override
            public void onBottomToTop() {
                adapter.submissionViewHolder.downvote.performClick();
                Context context = getContext();
                int duration = Toast.LENGTH_SHORT;
                CharSequence text;
                if (!downvoted) {
                    text = getString(R.string.profile_downvoted);
                    upvoted = false;
                } else {
                    text = getString(R.string.vote_removed);
                }
                downvoted = !downvoted;
                Toast toast = Toast.makeText(context, text, duration);
                toast.show();
            }

            @Override
            public void onTopToBottom() {
            }
        });
    }
    toolbar.setBackgroundColor(Palette.getColor(subreddit));
    mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(subreddit, getActivity()));
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            if (comments != null) {
                comments.loadMore(adapter, subreddit, true);
            } else {
                mSwipeRefreshLayout.setRefreshing(false);
            }
        // TODO catch errors
        }
    });
    toolbar.setTitle(subreddit);
    toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });
    toolbar.inflateMenu(R.menu.menu_comment_items);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch(item.getItemId()) {
                case R.id.search:
                    {
                        if (comments.comments != null && comments.submission != null) {
                            DataShare.sharedComments = comments.comments;
                            DataShare.subAuthor = comments.submission.getAuthor();
                            Intent i = new Intent(getActivity(), CommentSearch.class);
                            if (getActivity() instanceof MainActivity) {
                                getActivity().startActivityForResult(i, 423);
                            } else {
                                startActivityForResult(i, 423);
                            }
                        }
                    }
                    return true;
                case R.id.sidebar:
                    doSidebarOpen();
                    return true;
                case R.id.related:
                    if (adapter.submission.isSelfPost()) {
                        new AlertDialogWrapper.Builder(getActivity()).setTitle("Selftext posts have no related submissions").setPositiveButton(R.string.btn_ok, null).show();
                    } else {
                        Intent i = new Intent(getActivity(), Related.class);
                        i.putExtra(Related.EXTRA_URL, adapter.submission.getUrl());
                        startActivity(i);
                    }
                    return true;
                case R.id.shadowbox:
                    if (SettingValues.tabletUI) {
                        if (comments.comments != null && comments.submission != null) {
                            ShadowboxComments.comments = new ArrayList<>();
                            for (CommentObject c : comments.comments) {
                                if (c instanceof CommentItem) {
                                    if (c.comment.getComment().getDataNode().get("body_html").asText().contains("&lt;/a")) {
                                        String body = c.comment.getComment().getDataNode().get("body_html").asText();
                                        String url;
                                        String[] split = body.split("&lt;a href=\"");
                                        if (split.length > 1) {
                                            for (String chunk : split) {
                                                url = chunk.substring(0, chunk.indexOf("\"", 1));
                                                ContentType.Type t = ContentType.getContentType(url);
                                                if (ContentType.mediaType(t)) {
                                                    ShadowboxComments.comments.add(new CommentUrlObject(c.comment, url, subreddit));
                                                }
                                            }
                                        } else {
                                            int start = body.indexOf("&lt;a href=\"");
                                            url = body.substring(start, body.indexOf("\"", start + 1));
                                            ContentType.Type t = ContentType.getContentType(url);
                                            if (ContentType.mediaType(t)) {
                                                ShadowboxComments.comments.add(new CommentUrlObject(c.comment, url, subreddit));
                                            }
                                        }
                                    }
                                }
                            }
                            if (!ShadowboxComments.comments.isEmpty()) {
                                Intent i = new Intent(getActivity(), ShadowboxComments.class);
                                startActivity(i);
                            } else {
                                Snackbar.make(mSwipeRefreshLayout, R.string.shadowbox_comments_nolinks, Snackbar.LENGTH_SHORT).show();
                            }
                        }
                    } else {
                        AlertDialogWrapper.Builder b = new AlertDialogWrapper.Builder(getContext()).setTitle(R.string.general_shadowbox_comments_ispro).setMessage(R.string.pro_upgrade_msg).setPositiveButton(R.string.btn_yes_exclaim, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int whichButton) {
                                try {
                                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=me.ccrama.slideforreddittabletuiunlock")));
                                } catch (ActivityNotFoundException e) {
                                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=me.ccrama.slideforreddittabletuiunlock")));
                                }
                            }
                        }).setNegativeButton(R.string.btn_no_danks, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int whichButton) {
                                dialog.dismiss();
                            }
                        });
                        b.show();
                    }
                    return true;
                case R.id.sort:
                    {
                        openPopup(toolbar);
                        return true;
                    }
                case R.id.content:
                    {
                        if (adapter != null && adapter.submission != null) {
                            if (!PostMatch.openExternal(adapter.submission.getUrl())) {
                                ContentType.Type type = ContentType.getContentType(adapter.submission);
                                switch(type) {
                                    case VID_ME:
                                    case STREAMABLE:
                                        if (SettingValues.video) {
                                            Intent myIntent = new Intent(getActivity(), MediaView.class);
                                            myIntent.putExtra(MediaView.SUBREDDIT, subreddit);
                                            myIntent.putExtra(MediaView.EXTRA_URL, adapter.submission.getUrl());
                                            getActivity().startActivity(myIntent);
                                        } else {
                                            LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
                                        }
                                        break;
                                    case IMGUR:
                                    case XKCD:
                                        Intent i2 = new Intent(getActivity(), MediaView.class);
                                        i2.putExtra(MediaView.SUBREDDIT, subreddit);
                                        if (adapter.submission.getDataNode().has("preview") && adapter.submission.getDataNode().get("preview").get("images").get(0).get("source").has("height") && type != ContentType.Type.XKCD) {
                                            // Load the preview image which has probably already been cached in memory instead of the direct link
                                            String previewUrl = adapter.submission.getDataNode().get("preview").get("images").get(0).get("source").get("url").asText();
                                            i2.putExtra(MediaView.EXTRA_DISPLAY_URL, previewUrl);
                                        }
                                        i2.putExtra(MediaView.EXTRA_URL, adapter.submission.getUrl());
                                        getActivity().startActivity(i2);
                                        break;
                                    case EMBEDDED:
                                        if (SettingValues.video) {
                                            String data = adapter.submission.getDataNode().get("media_embed").get("content").asText();
                                            {
                                                Intent i = new Intent(getActivity(), FullscreenVideo.class);
                                                i.putExtra(FullscreenVideo.EXTRA_HTML, data);
                                                getActivity().startActivity(i);
                                            }
                                        } else {
                                            LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
                                        }
                                        break;
                                    case REDDIT:
                                        PopulateSubmissionViewHolder.openRedditContent(adapter.submission.getUrl(), getActivity());
                                        break;
                                    case LINK:
                                        LinkUtil.openUrl(adapter.submission.getUrl(), Palette.getColor(adapter.submission.getSubredditName()), getActivity());
                                        break;
                                    case NONE:
                                    case SELF:
                                        if (adapter.submission.getSelftext().isEmpty()) {
                                            Snackbar s = Snackbar.make(rv, R.string.submission_nocontent, Snackbar.LENGTH_SHORT);
                                            View view = s.getView();
                                            TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
                                            tv.setTextColor(Color.WHITE);
                                            s.show();
                                        } else {
                                            LayoutInflater inflater = getActivity().getLayoutInflater();
                                            final View dialoglayout = inflater.inflate(R.layout.parent_comment_dialog, null);
                                            final AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(getActivity());
                                            adapter.setViews(adapter.submission.getDataNode().get("selftext_html").asText(), adapter.submission.getSubredditName(), (SpoilerRobotoTextView) dialoglayout.findViewById(R.id.firstTextView), (CommentOverflow) dialoglayout.findViewById(R.id.commentOverflow));
                                            builder.setView(dialoglayout);
                                            builder.show();
                                        }
                                        break;
                                    case ALBUM:
                                        if (SettingValues.album) {
                                            if (SettingValues.albumSwipe) {
                                                Intent i = new Intent(getActivity(), AlbumPager.class);
                                                i.putExtra(Album.EXTRA_URL, adapter.submission.getUrl());
                                                i.putExtra(AlbumPager.SUBREDDIT, subreddit);
                                                getActivity().startActivity(i);
                                                getActivity().overridePendingTransition(R.anim.slideright, R.anim.fade_out);
                                            } else {
                                                Intent i = new Intent(getActivity(), Album.class);
                                                i.putExtra(Album.EXTRA_URL, adapter.submission.getUrl());
                                                i.putExtra(Album.SUBREDDIT, subreddit);
                                                getActivity().startActivity(i);
                                                getActivity().overridePendingTransition(R.anim.slideright, R.anim.fade_out);
                                            }
                                        } else {
                                            LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
                                        }
                                        break;
                                    case TUMBLR:
                                        if (SettingValues.image) {
                                            if (SettingValues.albumSwipe) {
                                                Intent i = new Intent(getActivity(), TumblrPager.class);
                                                i.putExtra(Album.EXTRA_URL, adapter.submission.getUrl());
                                                i.putExtra(TumblrPager.SUBREDDIT, subreddit);
                                                getActivity().startActivity(i);
                                                getActivity().overridePendingTransition(R.anim.slideright, R.anim.fade_out);
                                            } else {
                                                Intent i = new Intent(getActivity(), Tumblr.class);
                                                i.putExtra(Tumblr.SUBREDDIT, subreddit);
                                                i.putExtra(Album.EXTRA_URL, adapter.submission.getUrl());
                                                getActivity().startActivity(i);
                                                getActivity().overridePendingTransition(R.anim.slideright, R.anim.fade_out);
                                            }
                                        } else {
                                            LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
                                        }
                                        break;
                                    case IMAGE:
                                        PopulateSubmissionViewHolder.openImage(type, getActivity(), adapter.submission, null, -1);
                                        break;
                                    case VREDDIT_REDIRECT:
                                    case VREDDIT_DIRECT:
                                    case GIF:
                                        PopulateSubmissionViewHolder.openGif(getActivity(), adapter.submission, -1);
                                        break;
                                    case VIDEO:
                                        if (Reddit.videoPlugin) {
                                            try {
                                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                                sharingIntent.setClassName("ccrama.me.slideyoutubeplugin", "ccrama.me.slideyoutubeplugin.YouTubeView");
                                                sharingIntent.putExtra("url", adapter.submission.getUrl());
                                                getActivity().startActivity(sharingIntent);
                                            } catch (Exception e) {
                                                LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
                                            }
                                        } else {
                                            LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
                                        }
                                }
                            } else {
                                LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
                            }
                        }
                    }
                    return true;
                case R.id.reload:
                    if (comments != null) {
                        mSwipeRefreshLayout.setRefreshing(true);
                        comments.loadMore(adapter, subreddit);
                    }
                    return true;
                case R.id.collapse:
                    {
                        if (adapter != null) {
                            adapter.collapseAll();
                        }
                    }
                    return true;
                case android.R.id.home:
                    getActivity().onBackPressed();
                    return true;
            }
            return false;
        }
    });
    toolbar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ((LinearLayoutManager) rv.getLayoutManager()).scrollToPositionWithOffset(1, headerHeight);
            resetScroll(false);
        }
    });
    addClickFunctionSubName(toolbar);
    doTopBar();
    if (Authentication.didOnline && !NetworkUtil.isConnectedNoOverride(getActivity())) {
        new AlertDialogWrapper.Builder(getActivity()).setTitle(R.string.err_title).setMessage(R.string.err_connection_failed_msg).setNegativeButton(R.string.btn_close, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (!(getActivity() instanceof MainActivity)) {
                    getActivity().finish();
                }
            }
        }).setPositiveButton(R.string.btn_offline, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Reddit.appRestart.edit().putBoolean("forceoffline", true).commit();
                Reddit.forceRestart(getActivity());
            }
        }).show();
    }
    if (!(getActivity() instanceof CommentsScreen) || ((CommentsScreen) getActivity()).currentPage == page) {
        doAdapter(true);
    } else {
        doAdapter(false);
    }
    return v;
}
Also used : ContentType(me.ccrama.redditslide.ContentType) ArrayList(java.util.ArrayList) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) Dialog(android.app.Dialog) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) Toolbar(android.support.v7.widget.Toolbar) FullscreenVideo(me.ccrama.redditslide.Activities.FullscreenVideo) EditText(android.widget.EditText) CommentsScreen(me.ccrama.redditslide.Activities.CommentsScreen) CommentObject(me.ccrama.redditslide.Adapters.CommentObject) Related(me.ccrama.redditslide.Activities.Related) CommentItem(me.ccrama.redditslide.Adapters.CommentItem) ActivityNotFoundException(android.content.ActivityNotFoundException) LayoutInflater(android.view.LayoutInflater) CommentUrlObject(me.ccrama.redditslide.Adapters.CommentUrlObject) Snackbar(android.support.design.widget.Snackbar) Slider(com.rey.material.widget.Slider) DialogInterface(android.content.DialogInterface) MainActivity(me.ccrama.redditslide.Activities.MainActivity) Toast(android.widget.Toast) MoreChildItem(me.ccrama.redditslide.Adapters.MoreChildItem) Context(android.content.Context) ColorPreferences(me.ccrama.redditslide.ColorPreferences) Calendar(java.util.Calendar) MenuItem(android.view.MenuItem) Intent(android.content.Intent) MediaView(me.ccrama.redditslide.Activities.MediaView) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) IOException(java.io.IOException) ApiException(net.dean.jraw.ApiException) ActivityNotFoundException(android.content.ActivityNotFoundException) NetworkException(net.dean.jraw.http.NetworkException) ContentType(me.ccrama.redditslide.ContentType) CommentNavType(me.ccrama.redditslide.Adapters.CommentNavType) ShadowboxComments(me.ccrama.redditslide.Activities.ShadowboxComments) FrameLayout(android.widget.FrameLayout)

Example 44 with ColorPreferences

use of me.ccrama.redditslide.ColorPreferences in project Slide by ccrama.

the class NewsView method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), new ColorPreferences(inflater.getContext()).getThemeSubreddit(id));
    final View v = ((LayoutInflater) contextThemeWrapper.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.fragment_verticalcontent, container, false);
    if (getActivity() instanceof MainActivity) {
        v.findViewById(R.id.back).setBackgroundResource(0);
    }
    rv = v.findViewById(R.id.vertical_content);
    rv.setHasFixedSize(true);
    final RecyclerView.LayoutManager mLayoutManager;
    mLayoutManager = createLayoutManager(getNumColumns(getResources().getConfiguration().orientation, getActivity()));
    if (!(getActivity() instanceof SubredditView)) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            v.findViewById(R.id.back).setBackground(null);
        } else {
            v.findViewById(R.id.back).setBackgroundDrawable(null);
        }
    }
    rv.setLayoutManager(mLayoutManager);
    rv.setItemAnimator(new SlideUpAlphaAnimator());
    rv.getLayoutManager().scrollToPosition(0);
    mSwipeRefreshLayout = v.findViewById(R.id.activity_main_swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(id, getContext()));
    /**
     * If using List view mode, we need to remove the start margin from the SwipeRefreshLayout.
     * The scrollbar style of "outsideInset" creates a 4dp padding around it. To counter this,
     * change the scrollbar style to "insideOverlay" when list view is enabled.
     * To recap: this removes the margins from the start/end so list view is full-width.
     */
    if (SettingValues.defaultCardView == CreateCardView.CardEnum.LIST) {
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            params.setMarginStart(0);
        } else {
            MarginLayoutParamsCompat.setMarginStart(params, 0);
        }
        rv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        mSwipeRefreshLayout.setLayoutParams(params);
    }
    /**
     * If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
     * So, we estimate the height of the header in dp.
     * If the view type is "single" (and therefore "commentPager"), we need a different offset
     */
    final int HEADER_OFFSET = (SettingValues.single || getActivity() instanceof SubredditView) ? Constants.SINGLE_HEADER_VIEW_OFFSET : Constants.TAB_HEADER_VIEW_OFFSET;
    mSwipeRefreshLayout.setProgressViewOffset(false, HEADER_OFFSET - Constants.PTR_OFFSET_TOP, HEADER_OFFSET + Constants.PTR_OFFSET_BOTTOM);
    if (SettingValues.fab) {
        fab = v.findViewById(R.id.post_floating_action_button);
        if (SettingValues.fabType == Constants.FAB_POST) {
            fab.setImageResource(R.drawable.add);
            fab.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Intent inte = new Intent(getActivity(), Submit.class);
                    inte.putExtra(Submit.EXTRA_SUBREDDIT, id);
                    getActivity().startActivity(inte);
                }
            });
        } else {
            fab.setImageResource(R.drawable.hide);
            fab.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (!Reddit.fabClear) {
                        new AlertDialogWrapper.Builder(getActivity()).setTitle(R.string.settings_fabclear).setMessage(R.string.settings_fabclear_msg).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Reddit.colors.edit().putBoolean(SettingValues.PREF_FAB_CLEAR, true).apply();
                                Reddit.fabClear = true;
                                clearSeenPosts(false);
                            }
                        }).show();
                    } else {
                        clearSeenPosts(false);
                    }
                }
            });
            final Handler handler = new Handler();
            fab.setOnTouchListener(new View.OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    detector.onTouchEvent(event);
                    if (event.getAction() == MotionEvent.ACTION_DOWN) {
                        origY = event.getY();
                        handler.postDelayed(mLongPressRunnable, android.view.ViewConfiguration.getLongPressTimeout());
                    }
                    if (((event.getAction() == MotionEvent.ACTION_MOVE) && Math.abs(event.getY() - origY) > fab.getHeight() / 2) || (event.getAction() == MotionEvent.ACTION_UP)) {
                        handler.removeCallbacks(mLongPressRunnable);
                    }
                    return false;
                }
            });
            mLongPressRunnable = new Runnable() {

                public void run() {
                    fab.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                    if (!Reddit.fabClear) {
                        new AlertDialogWrapper.Builder(getActivity()).setTitle(R.string.settings_fabclear).setMessage(R.string.settings_fabclear_msg).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Reddit.colors.edit().putBoolean(SettingValues.PREF_FAB_CLEAR, true).apply();
                                Reddit.fabClear = true;
                                clearSeenPosts(true);
                            }
                        }).show();
                    } else {
                        clearSeenPosts(true);
                    }
                    Snackbar s = Snackbar.make(rv, getResources().getString(R.string.posts_hidden_forever), Snackbar.LENGTH_LONG);
                    /*Todo a way to unhide
                        s.setAction(R.string.btn_undo, new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {

                            }
                        });*/
                    View view = s.getView();
                    TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
                    tv.setTextColor(Color.WHITE);
                    s.show();
                }
            };
        }
    } else {
        v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
    }
    if (fab != null)
        fab.show();
    header = getActivity().findViewById(R.id.header);
    // TODO, have it so that if the user clicks anywhere in the rv to hide and cancel GoToSubreddit?
    // final TextInputEditText GO_TO_SUB_FIELD = (TextInputEditText) getActivity().findViewById(R.id.toolbar_search);
    // final Toolbar TOOLBAR = ((Toolbar) getActivity().findViewById(R.id.toolbar));
    // final String PREV_TITLE = TOOLBAR.getTitle().toString();
    // final ImageView CLOSE_BUTTON = (ImageView) getActivity().findViewById(R.id.close);
    // 
    // rv.setOnTouchListener(new View.OnTouchListener() {
    // @Override
    // public boolean onTouch(View v, MotionEvent event) {
    // System.out.println("touched");
    // InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    // imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    // 
    // GO_TO_SUB_FIELD.setText("");
    // GO_TO_SUB_FIELD.setVisibility(View.GONE);
    // CLOSE_BUTTON.setVisibility(View.GONE);
    // TOOLBAR.setTitle(PREV_TITLE);
    // 
    // return false;
    // }
    // });
    resetScroll();
    Reddit.isLoading = false;
    if (MainActivity.shouldLoad == null || id == null || (MainActivity.shouldLoad != null && MainActivity.shouldLoad.equals(id)) || !(getActivity() instanceof MainActivity)) {
        doAdapter();
    }
    return v;
}
Also used : DialogInterface(android.content.DialogInterface) SubredditView(me.ccrama.redditslide.Activities.SubredditView) MainActivity(me.ccrama.redditslide.Activities.MainActivity) SlideUpAlphaAnimator(com.mikepenz.itemanimators.SlideUpAlphaAnimator) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) TextView(android.widget.TextView) Context(android.content.Context) ColorPreferences(me.ccrama.redditslide.ColorPreferences) Handler(android.os.Handler) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) RecyclerView(android.support.v7.widget.RecyclerView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) MotionEvent(android.view.MotionEvent) ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) LayoutInflater(android.view.LayoutInflater) RelativeLayout(android.widget.RelativeLayout) Submit(me.ccrama.redditslide.Activities.Submit) RecyclerView(android.support.v7.widget.RecyclerView) Snackbar(android.support.design.widget.Snackbar)

Example 45 with ColorPreferences

use of me.ccrama.redditslide.ColorPreferences in project Slide by ccrama.

the class SubmissionsView method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), new ColorPreferences(inflater.getContext()).getThemeSubreddit(id));
    final View v = ((LayoutInflater) contextThemeWrapper.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.fragment_verticalcontent, container, false);
    if (getActivity() instanceof MainActivity) {
        v.findViewById(R.id.back).setBackgroundResource(0);
    }
    rv = v.findViewById(R.id.vertical_content);
    rv.setHasFixedSize(true);
    final RecyclerView.LayoutManager mLayoutManager;
    mLayoutManager = createLayoutManager(getNumColumns(getResources().getConfiguration().orientation, getActivity()));
    if (!(getActivity() instanceof SubredditView)) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            v.findViewById(R.id.back).setBackground(null);
        } else {
            v.findViewById(R.id.back).setBackgroundDrawable(null);
        }
    }
    rv.setLayoutManager(mLayoutManager);
    rv.setItemAnimator(new SlideUpAlphaAnimator());
    rv.getLayoutManager().scrollToPosition(0);
    mSwipeRefreshLayout = v.findViewById(R.id.activity_main_swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(id, getContext()));
    /**
     * If using List view mode, we need to remove the start margin from the SwipeRefreshLayout.
     * The scrollbar style of "outsideInset" creates a 4dp padding around it. To counter this,
     * change the scrollbar style to "insideOverlay" when list view is enabled.
     * To recap: this removes the margins from the start/end so list view is full-width.
     */
    if (SettingValues.defaultCardView == CreateCardView.CardEnum.LIST) {
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            params.setMarginStart(0);
        } else {
            MarginLayoutParamsCompat.setMarginStart(params, 0);
        }
        rv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        mSwipeRefreshLayout.setLayoutParams(params);
    }
    /**
     * If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
     * So, we estimate the height of the header in dp.
     * If the view type is "single" (and therefore "commentPager"), we need a different offset
     */
    final int HEADER_OFFSET = (SettingValues.single || getActivity() instanceof SubredditView) ? Constants.SINGLE_HEADER_VIEW_OFFSET : Constants.TAB_HEADER_VIEW_OFFSET;
    mSwipeRefreshLayout.setProgressViewOffset(false, HEADER_OFFSET - Constants.PTR_OFFSET_TOP, HEADER_OFFSET + Constants.PTR_OFFSET_BOTTOM);
    if (SettingValues.fab) {
        fab = v.findViewById(R.id.post_floating_action_button);
        if (SettingValues.fabType == Constants.FAB_POST) {
            fab.setImageResource(R.drawable.add);
            fab.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Intent inte = new Intent(getActivity(), Submit.class);
                    inte.putExtra(Submit.EXTRA_SUBREDDIT, id);
                    getActivity().startActivity(inte);
                }
            });
        } else {
            fab.setImageResource(R.drawable.hide);
            fab.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (!Reddit.fabClear) {
                        new AlertDialogWrapper.Builder(getActivity()).setTitle(R.string.settings_fabclear).setMessage(R.string.settings_fabclear_msg).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Reddit.colors.edit().putBoolean(SettingValues.PREF_FAB_CLEAR, true).apply();
                                Reddit.fabClear = true;
                                clearSeenPosts(false);
                            }
                        }).show();
                    } else {
                        clearSeenPosts(false);
                    }
                }
            });
            final Handler handler = new Handler();
            fab.setOnTouchListener(new View.OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    detector.onTouchEvent(event);
                    if (event.getAction() == MotionEvent.ACTION_DOWN) {
                        origY = event.getY();
                        handler.postDelayed(mLongPressRunnable, android.view.ViewConfiguration.getLongPressTimeout());
                    }
                    if (((event.getAction() == MotionEvent.ACTION_MOVE) && Math.abs(event.getY() - origY) > fab.getHeight() / 2) || (event.getAction() == MotionEvent.ACTION_UP)) {
                        handler.removeCallbacks(mLongPressRunnable);
                    }
                    return false;
                }
            });
            mLongPressRunnable = new Runnable() {

                public void run() {
                    fab.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                    if (!Reddit.fabClear) {
                        new AlertDialogWrapper.Builder(getActivity()).setTitle(R.string.settings_fabclear).setMessage(R.string.settings_fabclear_msg).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Reddit.colors.edit().putBoolean(SettingValues.PREF_FAB_CLEAR, true).apply();
                                Reddit.fabClear = true;
                                clearSeenPosts(true);
                            }
                        }).show();
                    } else {
                        clearSeenPosts(true);
                    }
                    Snackbar s = Snackbar.make(rv, getResources().getString(R.string.posts_hidden_forever), Snackbar.LENGTH_LONG);
                    /*Todo a way to unhide
                        s.setAction(R.string.btn_undo, new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {

                            }
                        });*/
                    View view = s.getView();
                    TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
                    tv.setTextColor(Color.WHITE);
                    s.show();
                }
            };
        }
    } else {
        v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
    }
    if (fab != null)
        fab.show();
    header = getActivity().findViewById(R.id.header);
    // TODO, have it so that if the user clicks anywhere in the rv to hide and cancel GoToSubreddit?
    // final TextInputEditText GO_TO_SUB_FIELD = (TextInputEditText) getActivity().findViewById(R.id.toolbar_search);
    // final Toolbar TOOLBAR = ((Toolbar) getActivity().findViewById(R.id.toolbar));
    // final String PREV_TITLE = TOOLBAR.getTitle().toString();
    // final ImageView CLOSE_BUTTON = (ImageView) getActivity().findViewById(R.id.close);
    // 
    // rv.setOnTouchListener(new View.OnTouchListener() {
    // @Override
    // public boolean onTouch(View v, MotionEvent event) {
    // System.out.println("touched");
    // InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    // imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    // 
    // GO_TO_SUB_FIELD.setText("");
    // GO_TO_SUB_FIELD.setVisibility(View.GONE);
    // CLOSE_BUTTON.setVisibility(View.GONE);
    // TOOLBAR.setTitle(PREV_TITLE);
    // 
    // return false;
    // }
    // });
    resetScroll();
    Reddit.isLoading = false;
    if (MainActivity.shouldLoad == null || id == null || (MainActivity.shouldLoad != null && MainActivity.shouldLoad.equals(id)) || !(getActivity() instanceof MainActivity)) {
        doAdapter();
    }
    return v;
}
Also used : DialogInterface(android.content.DialogInterface) SubredditView(me.ccrama.redditslide.Activities.SubredditView) MainActivity(me.ccrama.redditslide.Activities.MainActivity) SlideUpAlphaAnimator(com.mikepenz.itemanimators.SlideUpAlphaAnimator) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) TextView(android.widget.TextView) Context(android.content.Context) ColorPreferences(me.ccrama.redditslide.ColorPreferences) Handler(android.os.Handler) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) RecyclerView(android.support.v7.widget.RecyclerView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) MotionEvent(android.view.MotionEvent) ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) LayoutInflater(android.view.LayoutInflater) RelativeLayout(android.widget.RelativeLayout) Submit(me.ccrama.redditslide.Activities.Submit) RecyclerView(android.support.v7.widget.RecyclerView) Snackbar(android.support.design.widget.Snackbar)

Aggregations

ColorPreferences (me.ccrama.redditslide.ColorPreferences)50 View (android.view.View)23 TextView (android.widget.TextView)22 Intent (android.content.Intent)16 DialogInterface (android.content.DialogInterface)14 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)14 ArrayList (java.util.ArrayList)14 SpoilerRobotoTextView (me.ccrama.redditslide.SpoilerRobotoTextView)13 LayoutInflater (android.view.LayoutInflater)12 RecyclerView (android.support.v7.widget.RecyclerView)10 ImageView (android.widget.ImageView)10 SubmissionsView (me.ccrama.redditslide.Fragments.SubmissionsView)10 Context (android.content.Context)9 ContextThemeWrapper (android.support.v7.view.ContextThemeWrapper)9 HorizontalScrollView (android.widget.HorizontalScrollView)9 Snackbar (android.support.design.widget.Snackbar)8 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)8 CaseInsensitiveArrayList (me.ccrama.redditslide.CaseInsensitiveArrayList)8 LinearInterpolator (android.view.animation.LinearInterpolator)7 Dialog (android.app.Dialog)6