Search in sources :

Example 6 with SpoilerRobotoTextView

use of me.ccrama.redditslide.SpoilerRobotoTextView 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 7 with SpoilerRobotoTextView

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

the class SubredditView method doSubOnlyStuff.

private void doSubOnlyStuff(final Subreddit subreddit) {
    if (!isFinishing()) {
        findViewById(R.id.loader).setVisibility(View.GONE);
        if (subreddit.getDataNode().has("subreddit_type") && !subreddit.getDataNode().get("subreddit_type").isNull()) {
            canSubmit = !subreddit.getDataNode().get("subreddit_type").asText().toUpperCase().equals("RESTRICTED");
        }
        if (subreddit.getSidebar() != null && !subreddit.getSidebar().isEmpty()) {
            findViewById(R.id.sidebar_text).setVisibility(View.VISIBLE);
            final String text = subreddit.getDataNode().get("description_html").asText().trim();
            final SpoilerRobotoTextView body = (SpoilerRobotoTextView) findViewById(R.id.sidebar_text);
            CommentOverflow overflow = (CommentOverflow) findViewById(R.id.commentOverflow);
            setViews(text, subreddit.getDisplayName(), body, overflow);
            // get all subs that have Notifications enabled
            ArrayList<String> rawSubs = Reddit.stringToArray(Reddit.appRestart.getString(CheckForMail.SUBS_TO_GET, ""));
            HashMap<String, Integer> subThresholds = new HashMap<>();
            for (String s : rawSubs) {
                try {
                    String[] split = s.split(":");
                    subThresholds.put(split[0].toLowerCase(Locale.ENGLISH), Integer.valueOf(split[1]));
                } catch (Exception ignored) {
                // do nothing
                }
            }
            // whether or not this subreddit was in the keySet
            boolean isNotified = subThresholds.keySet().contains(subreddit.getDisplayName().toLowerCase(Locale.ENGLISH));
            ((AppCompatCheckBox) findViewById(R.id.notify_posts_state)).setChecked(isNotified);
        } else {
            findViewById(R.id.sidebar_text).setVisibility(View.GONE);
        }
        View collection = findViewById(R.id.collection);
        if (Authentication.isLoggedIn) {
            collection.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    new AsyncTask<Void, Void, Void>() {

                        HashMap<String, MultiReddit> multis = new HashMap<String, MultiReddit>();

                        @Override
                        protected Void doInBackground(Void... params) {
                            if (UserSubscriptions.multireddits == null) {
                                UserSubscriptions.syncMultiReddits(SubredditView.this);
                            }
                            for (MultiReddit r : UserSubscriptions.multireddits) {
                                multis.put(r.getDisplayName(), r);
                            }
                            return null;
                        }

                        @Override
                        protected void onPostExecute(Void aVoid) {
                            new MaterialDialog.Builder(SubredditView.this).title("Add /r/" + subreddit.getDisplayName() + " to").items(multis.keySet()).itemsCallback(new MaterialDialog.ListCallback() {

                                @Override
                                public void onSelection(MaterialDialog dialog, View itemView, final int which, CharSequence text) {
                                    new AsyncTask<Void, Void, Void>() {

                                        @Override
                                        protected Void doInBackground(Void... params) {
                                            try {
                                                final String multiName = multis.keySet().toArray(new String[multis.size()])[which];
                                                List<String> subs = new ArrayList<String>();
                                                for (MultiSubreddit sub : multis.get(multiName).getSubreddits()) {
                                                    subs.add(sub.getDisplayName());
                                                }
                                                subs.add(subreddit.getDisplayName());
                                                new MultiRedditManager(Authentication.reddit).createOrUpdate(new MultiRedditUpdateRequest.Builder(Authentication.name, multiName).subreddits(subs).build());
                                                UserSubscriptions.syncMultiReddits(SubredditView.this);
                                                runOnUiThread(new Runnable() {

                                                    @Override
                                                    public void run() {
                                                        drawerLayout.closeDrawers();
                                                        Snackbar s = Snackbar.make(mToolbar, getString(R.string.multi_subreddit_added, multiName), Snackbar.LENGTH_LONG);
                                                        View view = s.getView();
                                                        TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
                                                        tv.setTextColor(Color.WHITE);
                                                        s.show();
                                                    }
                                                });
                                            } catch (final NetworkException | ApiException e) {
                                                runOnUiThread(new Runnable() {

                                                    @Override
                                                    public void run() {
                                                        runOnUiThread(new Runnable() {

                                                            @Override
                                                            public void run() {
                                                                Snackbar.make(mToolbar, getString(R.string.multi_error), Snackbar.LENGTH_LONG).setAction(R.string.btn_ok, new View.OnClickListener() {

                                                                    @Override
                                                                    public void onClick(View v) {
                                                                    }
                                                                }).show();
                                                            }
                                                        });
                                                    }
                                                });
                                                e.printStackTrace();
                                            }
                                            return null;
                                        }
                                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                                }
                            }).show();
                        }
                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                }
            });
        } else {
            collection.setVisibility(View.GONE);
        }
        {
            final TextView subscribe = (TextView) findViewById(R.id.subscribe);
            currentlySubbed = (!Authentication.isLoggedIn && UserSubscriptions.getSubscriptions(this).contains(subreddit.getDisplayName().toLowerCase(Locale.ENGLISH))) || (Authentication.isLoggedIn && subreddit.isUserSubscriber());
            doSubscribeButtonText(currentlySubbed, subscribe);
            assert subscribe != null;
            subscribe.setOnClickListener(new View.OnClickListener() {

                private void doSubscribe() {
                    if (Authentication.isLoggedIn) {
                        new AlertDialogWrapper.Builder(SubredditView.this).setTitle(getString(R.string.subscribe_to, subreddit.getDisplayName())).setPositiveButton(R.string.reorder_add_subscribe, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                new AsyncTask<Void, Void, Boolean>() {

                                    @Override
                                    public void onPostExecute(Boolean success) {
                                        if (!success) {
                                            // If subreddit was removed from account or not
                                            new AlertDialogWrapper.Builder(SubredditView.this).setTitle(R.string.force_change_subscription).setMessage(R.string.force_change_subscription_desc).setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {

                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    changeSubscription(subreddit, // Force add the subscription
                                                    true);
                                                    Snackbar s = Snackbar.make(mToolbar, getString(R.string.misc_subscribed), 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();
                                                }
                                            }).setNegativeButton(R.string.btn_no, new DialogInterface.OnClickListener() {

                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                }
                                            }).setCancelable(false).show();
                                        } else {
                                            changeSubscription(subreddit, true);
                                        }
                                    }

                                    @Override
                                    protected Boolean doInBackground(Void... params) {
                                        try {
                                            new AccountManager(Authentication.reddit).subscribe(subreddit);
                                        } catch (NetworkException e) {
                                            // Either network crashed or trying to unsubscribe to a subreddit that the account isn't subscribed to
                                            return false;
                                        }
                                        return true;
                                    }
                                }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                            }
                        }).setNegativeButton(R.string.btn_cancel, null).setNeutralButton(R.string.btn_add_to_sublist, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                changeSubscription(subreddit, // Force add the subscription
                                true);
                                Snackbar s = Snackbar.make(mToolbar, R.string.sub_added, 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();
                            }
                        }).show();
                    } else {
                        changeSubscription(subreddit, true);
                    }
                }

                @Override
                public void onClick(View v) {
                    if (!currentlySubbed) {
                        doSubscribe();
                        doSubscribeButtonText(currentlySubbed, subscribe);
                    } else {
                        doUnsubscribe();
                        doSubscribeButtonText(currentlySubbed, subscribe);
                    }
                }

                private void doUnsubscribe() {
                    if (Authentication.didOnline) {
                        new AlertDialogWrapper.Builder(SubredditView.this).setTitle(getString(R.string.unsubscribe_from, subreddit.getDisplayName())).setPositiveButton(R.string.reorder_remove_unsubsribe, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                new AsyncTask<Void, Void, Boolean>() {

                                    @Override
                                    public void onPostExecute(Boolean success) {
                                        if (!success) {
                                            // If subreddit was removed from account or not
                                            new AlertDialogWrapper.Builder(SubredditView.this).setTitle(R.string.force_change_subscription).setMessage(R.string.force_change_subscription_desc).setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {

                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    changeSubscription(subreddit, // Force add the subscription
                                                    false);
                                                    Snackbar s = Snackbar.make(mToolbar, getString(R.string.misc_unsubscribed), 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();
                                                }
                                            }).setNegativeButton(R.string.btn_no, new DialogInterface.OnClickListener() {

                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                }
                                            }).setCancelable(false).show();
                                        } else {
                                            changeSubscription(subreddit, false);
                                        }
                                    }

                                    @Override
                                    protected Boolean doInBackground(Void... params) {
                                        try {
                                            new AccountManager(Authentication.reddit).unsubscribe(subreddit);
                                        } catch (NetworkException e) {
                                            // Either network crashed or trying to unsubscribe to a subreddit that the account isn't subscribed to
                                            return false;
                                        }
                                        return true;
                                    }
                                }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                            }
                        }).setNeutralButton(R.string.just_unsub, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                changeSubscription(subreddit, // Force add the subscription
                                false);
                                Snackbar s = Snackbar.make(mToolbar, R.string.misc_unsubscribed, 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();
                            }
                        }).setNegativeButton(R.string.btn_cancel, null).show();
                    } else {
                        changeSubscription(subreddit, false);
                    }
                }
            });
        }
        {
            final AppCompatCheckBox notifyStateCheckBox = (AppCompatCheckBox) findViewById(R.id.notify_posts_state);
            assert notifyStateCheckBox != null;
            notifyStateCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        final String sub = subreddit.getDisplayName();
                        if (!sub.equalsIgnoreCase("all") && !sub.equalsIgnoreCase("frontpage") && !sub.equalsIgnoreCase("friends") && !sub.equalsIgnoreCase("mod") && !sub.contains("+") && !sub.contains(".") && !sub.contains("/m/")) {
                            new AlertDialogWrapper.Builder(SubredditView.this).setTitle(getString(R.string.sub_post_notifs_title, sub)).setMessage(R.string.sub_post_notifs_msg).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    new MaterialDialog.Builder(SubredditView.this).title(R.string.sub_post_notifs_threshold).items(new String[] { "1", "5", "10", "20", "40", "50" }).alwaysCallSingleChoiceCallback().itemsCallbackSingleChoice(0, new MaterialDialog.ListCallbackSingleChoice() {

                                        @Override
                                        public boolean onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
                                            ArrayList<String> subs = Reddit.stringToArray(Reddit.appRestart.getString(CheckForMail.SUBS_TO_GET, ""));
                                            subs.add(sub + ":" + text);
                                            Reddit.appRestart.edit().putString(CheckForMail.SUBS_TO_GET, Reddit.arrayToString(subs)).commit();
                                            return true;
                                        }
                                    }).cancelable(false).show();
                                }
                            }).setNegativeButton(R.string.btn_cancel, null).setNegativeButton(R.string.btn_cancel, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    notifyStateCheckBox.setChecked(false);
                                }
                            }).setOnCancelListener(new DialogInterface.OnCancelListener() {

                                @Override
                                public void onCancel(DialogInterface dialog) {
                                    notifyStateCheckBox.setChecked(false);
                                }
                            }).show();
                        } else {
                            notifyStateCheckBox.setChecked(false);
                            Toast.makeText(SubredditView.this, R.string.sub_post_notifs_err, Toast.LENGTH_SHORT).show();
                        }
                    } else {
                        Intent cancelIntent = new Intent(SubredditView.this, CancelSubNotifs.class);
                        cancelIntent.putExtra(CancelSubNotifs.EXTRA_SUB, subreddit.getDisplayName());
                        startActivity(cancelIntent);
                    }
                }
            });
        }
        if (!subreddit.getPublicDescription().isEmpty()) {
            findViewById(R.id.sub_title).setVisibility(View.VISIBLE);
            setViews(subreddit.getDataNode().get("public_description_html").asText(), subreddit.getDisplayName().toLowerCase(Locale.ENGLISH), ((SpoilerRobotoTextView) findViewById(R.id.sub_title)), (CommentOverflow) findViewById(R.id.sub_title_overflow));
        } else {
            findViewById(R.id.sub_title).setVisibility(View.GONE);
        }
        if (subreddit.getDataNode().has("icon_img") && !subreddit.getDataNode().get("icon_img").asText().isEmpty()) {
            ((Reddit) getApplication()).getImageLoader().displayImage(subreddit.getDataNode().get("icon_img").asText(), (ImageView) findViewById(R.id.subimage));
        } else {
            findViewById(R.id.subimage).setVisibility(View.GONE);
        }
        ((TextView) findViewById(R.id.subscribers)).setText(getString(R.string.subreddit_subscribers_string, subreddit.getLocalizedSubscriberCount()));
        findViewById(R.id.subscribers).setVisibility(View.VISIBLE);
        ((TextView) findViewById(R.id.active_users)).setText(getString(R.string.subreddit_active_users_string_new, subreddit.getLocalizedAccountsActive()));
        findViewById(R.id.active_users).setVisibility(View.VISIBLE);
    }
}
Also used : HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) MultiSubreddit(net.dean.jraw.models.MultiSubreddit) MultiReddit(net.dean.jraw.models.MultiReddit) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) CommentOverflow(me.ccrama.redditslide.Views.CommentOverflow) List(java.util.List) ArrayList(java.util.ArrayList) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) NetworkException(net.dean.jraw.http.NetworkException) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) ImageView(android.widget.ImageView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) View(android.view.View) TextView(android.widget.TextView) ApiException(net.dean.jraw.ApiException) ActivityNotFoundException(android.content.ActivityNotFoundException) NetworkException(net.dean.jraw.http.NetworkException) AppCompatCheckBox(android.support.v7.widget.AppCompatCheckBox) MultiRedditManager(net.dean.jraw.managers.MultiRedditManager) AccountManager(net.dean.jraw.managers.AccountManager) CompoundButton(android.widget.CompoundButton) Snackbar(android.support.design.widget.Snackbar)

Example 8 with SpoilerRobotoTextView

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

the class SubredditView method setViews.

private void setViews(String rawHTML, String subreddit, SpoilerRobotoTextView firstTextView, CommentOverflow commentOverflow) {
    if (rawHTML.isEmpty()) {
        return;
    }
    List<String> blocks = SubmissionParser.getBlocks(rawHTML);
    int startIndex = 0;
    // the <div class="md"> case is when the body contains a table or code block first
    if (!blocks.get(0).equals("<div class=\"md\">")) {
        firstTextView.setVisibility(View.VISIBLE);
        firstTextView.setTextHtml(blocks.get(0), subreddit);
        startIndex = 1;
    } else {
        firstTextView.setText("");
        firstTextView.setVisibility(View.GONE);
    }
    if (blocks.size() > 1) {
        if (startIndex == 0) {
            commentOverflow.setViews(blocks, subreddit);
        } else {
            commentOverflow.setViews(blocks.subList(startIndex, blocks.size()), subreddit);
        }
        SidebarLayout sidebar = (SidebarLayout) findViewById(R.id.drawer_layout);
        for (int i = 0; i < commentOverflow.getChildCount(); i++) {
            View maybeScrollable = commentOverflow.getChildAt(i);
            if (maybeScrollable instanceof HorizontalScrollView) {
                sidebar.addScrollable(maybeScrollable);
            }
        }
    } else {
        commentOverflow.removeAllViews();
    }
}
Also used : SidebarLayout(me.ccrama.redditslide.Views.SidebarLayout) ImageView(android.widget.ImageView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) View(android.view.View) TextView(android.widget.TextView) HorizontalScrollView(android.widget.HorizontalScrollView)

Example 9 with SpoilerRobotoTextView

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

the class CommentAdapterHelper method viewCommentParent.

private static void viewCommentParent(CommentAdapter adapter, CommentViewHolder holder, Context mContext, CommentNode baseNode) {
    int old = holder.getAdapterPosition();
    int pos = (old < 2) ? 0 : old - 1;
    for (int i = pos - 1; i >= 0; i--) {
        CommentObject o = adapter.currentComments.get(adapter.getRealPosition(i));
        if (o instanceof CommentItem && pos - 1 != i && o.comment.getDepth() < baseNode.getDepth()) {
            LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
            final View dialoglayout = inflater.inflate(R.layout.parent_comment_dialog, null);
            final AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
            Comment parent = o.comment.getComment();
            adapter.setViews(parent.getDataNode().get("body_html").asText(), adapter.submission.getSubredditName(), (SpoilerRobotoTextView) dialoglayout.findViewById(R.id.firstTextView), (CommentOverflow) dialoglayout.findViewById(R.id.commentOverflow));
            builder.setView(dialoglayout);
            builder.show();
            break;
        }
    }
}
Also used : Comment(net.dean.jraw.models.Comment) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) LayoutInflater(android.view.LayoutInflater) SpannableStringBuilder(android.text.SpannableStringBuilder) Activity(android.app.Activity) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) TextView(android.widget.TextView)

Example 10 with SpoilerRobotoTextView

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

the class SelftextFull method setViews.

private void setViews(String rawHTML, String subredditName, View base) {
    if (rawHTML.isEmpty()) {
        return;
    }
    List<String> blocks = SubmissionParser.getBlocks(rawHTML);
    int startIndex = 0;
    if (!blocks.get(0).startsWith("<table>") && !blocks.get(0).startsWith("<pre>")) {
        ((SpoilerRobotoTextView) base.findViewById(R.id.firstTextView)).setTextHtml(blocks.get(0), subredditName);
        startIndex = 1;
    }
    CommentOverflow overflow = (CommentOverflow) base.findViewById(R.id.commentOverflow);
    if (blocks.size() > 1) {
        if (startIndex == 0) {
            overflow.setViews(blocks, subredditName);
        } else {
            overflow.setViews(blocks.subList(startIndex, blocks.size()), subredditName);
        }
    }
}
Also used : SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) CommentOverflow(me.ccrama.redditslide.Views.CommentOverflow)

Aggregations

SpoilerRobotoTextView (me.ccrama.redditslide.SpoilerRobotoTextView)20 View (android.view.View)18 TextView (android.widget.TextView)12 HorizontalScrollView (android.widget.HorizontalScrollView)11 ImageView (android.widget.ImageView)11 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)7 ApiException (net.dean.jraw.ApiException)7 Intent (android.content.Intent)6 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)6 ArrayList (java.util.ArrayList)6 ActivityNotFoundException (android.content.ActivityNotFoundException)5 AsyncTask (android.os.AsyncTask)5 Snackbar (android.support.design.widget.Snackbar)5 DialogInterface (android.content.DialogInterface)4 RecyclerView (android.support.v7.widget.RecyclerView)4 AutoCompleteTextView (android.widget.AutoCompleteTextView)4 EditText (android.widget.EditText)4 ColorPreferences (me.ccrama.redditslide.ColorPreferences)4 SubmissionsView (me.ccrama.redditslide.Fragments.SubmissionsView)4 SidebarLayout (me.ccrama.redditslide.Views.SidebarLayout)4