Search in sources :

Example 31 with AsyncTask

use of android.os.AsyncTask in project Slide by ccrama.

the class MainActivity method doSubSidebar.

public void doSubSidebar(final String subreddit) {
    if (mAsyncGetSubreddit != null) {
        mAsyncGetSubreddit.cancel(true);
    }
    findViewById(R.id.loader).setVisibility(View.VISIBLE);
    invalidateOptionsMenu();
    if (!subreddit.equalsIgnoreCase("all") && !subreddit.equalsIgnoreCase("frontpage") && !subreddit.equalsIgnoreCase("friends") && !subreddit.equalsIgnoreCase("mod") && !subreddit.contains("+") && !subreddit.contains(".") && !subreddit.contains("/m/")) {
        if (drawerLayout != null) {
            drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, GravityCompat.END);
        }
        mAsyncGetSubreddit = new AsyncGetSubreddit();
        mAsyncGetSubreddit.execute(subreddit);
        final View dialoglayout = findViewById(R.id.sidebarsub);
        {
            View submit = (dialoglayout.findViewById(R.id.submit));
            if (!Authentication.isLoggedIn || !Authentication.didOnline) {
                submit.setVisibility(View.GONE);
            }
            if (SettingValues.fab && SettingValues.fabType == Constants.FAB_POST) {
                submit.setVisibility(View.GONE);
            }
            submit.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View view) {
                    Intent inte = new Intent(MainActivity.this, Submit.class);
                    if (!subreddit.contains("/m/") && canSubmit) {
                        inte.putExtra(Submit.EXTRA_SUBREDDIT, subreddit);
                    }
                    MainActivity.this.startActivity(inte);
                }
            });
        }
        dialoglayout.findViewById(R.id.wiki).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent i = new Intent(MainActivity.this, Wiki.class);
                i.putExtra(Wiki.EXTRA_SUBREDDIT, subreddit);
                startActivity(i);
            }
        });
        dialoglayout.findViewById(R.id.syncflair).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                ImageFlairs.syncFlairs(MainActivity.this, subreddit);
            }
        });
        dialoglayout.findViewById(R.id.submit).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent i = new Intent(MainActivity.this, Submit.class);
                if ((!subreddit.contains("/m/") || !subreddit.contains(".")) && canSubmit) {
                    i.putExtra(Submit.EXTRA_SUBREDDIT, subreddit);
                }
                startActivity(i);
            }
        });
        final TextView sort = dialoglayout.findViewById(R.id.sort);
        Sorting sortingis = Sorting.HOT;
        if (SettingValues.hasSort(subreddit)) {
            sortingis = SettingValues.getBaseSubmissionSort(subreddit);
            sort.setText(sortingis.name() + ((sortingis == Sorting.CONTROVERSIAL || sortingis == Sorting.TOP) ? " of " + SettingValues.getBaseTimePeriod(subreddit).name() : ""));
        } else {
            sort.setText("Set default sorting");
        }
        final int sortid = Reddit.getSortingId(sortingis);
        dialoglayout.findViewById(R.id.sorting).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                final DialogInterface.OnClickListener l2 = new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        switch(i) {
                            case 0:
                                sorts = Sorting.HOT;
                                break;
                            case 1:
                                sorts = Sorting.NEW;
                                break;
                            case 2:
                                sorts = Sorting.RISING;
                                break;
                            case 3:
                                sorts = Sorting.TOP;
                                askTimePeriod(sorts, subreddit, dialoglayout);
                                return;
                            case 4:
                                sorts = Sorting.CONTROVERSIAL;
                                askTimePeriod(sorts, subreddit, dialoglayout);
                                return;
                        }
                        SettingValues.setSubSorting(sorts, time, subreddit);
                        Sorting sortingis = SettingValues.getBaseSubmissionSort(subreddit);
                        sort.setText(sortingis.name() + ((sortingis == Sorting.CONTROVERSIAL || sortingis == Sorting.TOP) ? " of " + SettingValues.getBaseTimePeriod(subreddit).name() : ""));
                        reloadSubs();
                    }
                };
                AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(MainActivity.this);
                builder.setTitle(R.string.sorting_choose);
                builder.setSingleChoiceItems(Reddit.getSortingStrings(getBaseContext()), sortid, l2);
                builder.setNegativeButton("Reset default sorting", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        SettingValues.prefs.edit().remove("defaultSort" + subreddit.toLowerCase(Locale.ENGLISH)).apply();
                        SettingValues.prefs.edit().remove("defaultTime" + subreddit.toLowerCase(Locale.ENGLISH)).apply();
                        final TextView sort = dialoglayout.findViewById(R.id.sort);
                        if (SettingValues.hasSort(subreddit)) {
                            Sorting sortingis = SettingValues.getBaseSubmissionSort(subreddit);
                            sort.setText(sortingis.name() + ((sortingis == Sorting.CONTROVERSIAL || sortingis == Sorting.TOP) ? " of " + SettingValues.getBaseTimePeriod(subreddit).name() : ""));
                        } else {
                            sort.setText("Set default sorting");
                        }
                        reloadSubs();
                    }
                });
                builder.show();
            }
        });
        dialoglayout.findViewById(R.id.theme).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                int style = new ColorPreferences(MainActivity.this).getThemeSubreddit(subreddit);
                final Context contextThemeWrapper = new ContextThemeWrapper(MainActivity.this, style);
                LayoutInflater localInflater = getLayoutInflater().cloneInContext(contextThemeWrapper);
                final View dialoglayout = localInflater.inflate(R.layout.colorsub, null);
                ArrayList<String> arrayList = new ArrayList<>();
                arrayList.add(subreddit);
                SettingsSubAdapter.showSubThemeEditor(arrayList, MainActivity.this, dialoglayout);
            }
        });
        dialoglayout.findViewById(R.id.mods).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                final Dialog d = new MaterialDialog.Builder(MainActivity.this).title(R.string.sidebar_findingmods).cancelable(true).content(R.string.misc_please_wait).progress(true, 100).show();
                new AsyncTask<Void, Void, Void>() {

                    ArrayList<UserRecord> mods;

                    @Override
                    protected Void doInBackground(Void... params) {
                        mods = new ArrayList<>();
                        UserRecordPaginator paginator = new UserRecordPaginator(Authentication.reddit, subreddit, "moderators");
                        paginator.setSorting(Sorting.HOT);
                        paginator.setTimePeriod(TimePeriod.ALL);
                        while (paginator.hasNext()) {
                            mods.addAll(paginator.next());
                        }
                        return null;
                    }

                    @Override
                    protected void onPostExecute(Void aVoid) {
                        final ArrayList<String> names = new ArrayList<>();
                        for (UserRecord rec : mods) {
                            names.add(rec.getFullName());
                        }
                        d.dismiss();
                        new MaterialDialog.Builder(MainActivity.this).title(getString(R.string.sidebar_submods, subreddit)).items(names).itemsCallback(new MaterialDialog.ListCallback() {

                            @Override
                            public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
                                Intent i = new Intent(MainActivity.this, Profile.class);
                                i.putExtra(Profile.EXTRA_PROFILE, names.get(which));
                                startActivity(i);
                            }
                        }).positiveText(R.string.btn_message).onPositive(new MaterialDialog.SingleButtonCallback() {

                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                Intent i = new Intent(MainActivity.this, SendMessage.class);
                                i.putExtra(SendMessage.EXTRA_NAME, "/r/" + subreddit);
                                startActivity(i);
                            }
                        }).show();
                    }
                }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
        });
        dialoglayout.findViewById(R.id.flair).setVisibility(View.GONE);
        if (Authentication.didOnline && Authentication.isLoggedIn) {
            if (currentFlair != null)
                currentFlair.cancel(true);
            currentFlair = new AsyncTask<View, Void, View>() {

                List<FlairTemplate> flairs;

                ArrayList<String> flairText;

                String current;

                AccountManager m;

                @Override
                protected View doInBackground(View... params) {
                    try {
                        m = new AccountManager(Authentication.reddit);
                        JsonNode node = m.getFlairChoicesRootNode(subreddit, null);
                        flairs = m.getFlairChoices(subreddit, node);
                        FlairTemplate currentF = m.getCurrentFlair(subreddit, node);
                        if (currentF != null) {
                            if (currentF.getText().isEmpty()) {
                                current = ("[" + currentF.getCssClass() + "]");
                            } else {
                                current = (currentF.getText());
                            }
                        }
                        flairText = new ArrayList<>();
                        for (FlairTemplate temp : flairs) {
                            if (temp.getText().isEmpty()) {
                                flairText.add("[" + temp.getCssClass() + "]");
                            } else {
                                flairText.add(temp.getText());
                            }
                        }
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                    return params[0];
                }

                @Override
                protected void onPostExecute(View flair) {
                    if (flairs != null && !flairs.isEmpty() && flairText != null && !flairText.isEmpty()) {
                        flair.setVisibility(View.VISIBLE);
                        if (current != null) {
                            ((TextView) dialoglayout.findViewById(R.id.flair_text)).setText(getString(R.string.sidebar_flair, current));
                        }
                        flair.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                new MaterialDialog.Builder(MainActivity.this).items(flairText).title(R.string.sidebar_select_flair).itemsCallback(new MaterialDialog.ListCallback() {

                                    @Override
                                    public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
                                        final FlairTemplate t = flairs.get(which);
                                        if (t.isTextEditable()) {
                                            new MaterialDialog.Builder(MainActivity.this).title(R.string.sidebar_select_flair_text).input(getString(R.string.mod_flair_hint), t.getText(), true, new MaterialDialog.InputCallback() {

                                                @Override
                                                public void onInput(MaterialDialog dialog, CharSequence input) {
                                                }
                                            }).positiveText(R.string.btn_set).onPositive(new MaterialDialog.SingleButtonCallback() {

                                                @Override
                                                public void onClick(MaterialDialog dialog, DialogAction which) {
                                                    final String flair = dialog.getInputEditText().getText().toString();
                                                    new AsyncTask<Void, Void, Boolean>() {

                                                        @Override
                                                        protected Boolean doInBackground(Void... params) {
                                                            try {
                                                                new ModerationManager(Authentication.reddit).setFlair(subreddit, t, flair, Authentication.name);
                                                                FlairTemplate currentF = m.getCurrentFlair(subreddit);
                                                                if (currentF.getText().isEmpty()) {
                                                                    current = ("[" + currentF.getCssClass() + "]");
                                                                } else {
                                                                    current = (currentF.getText());
                                                                }
                                                                return true;
                                                            } catch (Exception e) {
                                                                e.printStackTrace();
                                                                return false;
                                                            }
                                                        }

                                                        @Override
                                                        protected void onPostExecute(Boolean done) {
                                                            Snackbar s;
                                                            if (done) {
                                                                if (current != null) {
                                                                    ((TextView) dialoglayout.findViewById(R.id.flair_text)).setText(getString(R.string.sidebar_flair, current));
                                                                }
                                                                s = Snackbar.make(mToolbar, R.string.snackbar_flair_success, Snackbar.LENGTH_SHORT);
                                                            } else {
                                                                s = Snackbar.make(mToolbar, R.string.snackbar_flair_error, Snackbar.LENGTH_SHORT);
                                                            }
                                                            if (s != null) {
                                                                View view = s.getView();
                                                                TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
                                                                tv.setTextColor(Color.WHITE);
                                                                s.show();
                                                            }
                                                        }
                                                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                                                }
                                            }).negativeText(R.string.btn_cancel).show();
                                        } else {
                                            new AsyncTask<Void, Void, Boolean>() {

                                                @Override
                                                protected Boolean doInBackground(Void... params) {
                                                    try {
                                                        new ModerationManager(Authentication.reddit).setFlair(subreddit, t, null, Authentication.name);
                                                        FlairTemplate currentF = m.getCurrentFlair(subreddit);
                                                        if (currentF.getText().isEmpty()) {
                                                            current = ("[" + currentF.getCssClass() + "]");
                                                        } else {
                                                            current = (currentF.getText());
                                                        }
                                                        return true;
                                                    } catch (Exception e) {
                                                        e.printStackTrace();
                                                        return false;
                                                    }
                                                }

                                                @Override
                                                protected void onPostExecute(Boolean done) {
                                                    Snackbar s;
                                                    if (done) {
                                                        if (current != null) {
                                                            ((TextView) dialoglayout.findViewById(R.id.flair_text)).setText(getString(R.string.sidebar_flair, current));
                                                        }
                                                        s = Snackbar.make(mToolbar, R.string.snackbar_flair_success, Snackbar.LENGTH_SHORT);
                                                    } else {
                                                        s = Snackbar.make(mToolbar, R.string.snackbar_flair_error, Snackbar.LENGTH_SHORT);
                                                    }
                                                    if (s != null) {
                                                        View view = s.getView();
                                                        TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
                                                        tv.setTextColor(Color.WHITE);
                                                        s.show();
                                                    }
                                                }
                                            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                                        }
                                    }
                                }).show();
                            }
                        });
                    }
                }
            };
            currentFlair.execute(dialoglayout.findViewById(R.id.flair));
        }
    } else {
        if (drawerLayout != null) {
            drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, GravityCompat.END);
        }
    }
}
Also used : UserRecordPaginator(net.dean.jraw.paginators.UserRecordPaginator) DialogInterface(android.content.DialogInterface) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) ArrayList(java.util.ArrayList) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) Dialog(android.app.Dialog) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) NonNull(android.support.annotation.NonNull) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) Context(android.content.Context) ModerationManager(net.dean.jraw.managers.ModerationManager) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ColorPreferences(me.ccrama.redditslide.ColorPreferences) FlairTemplate(net.dean.jraw.models.FlairTemplate) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) ListView(android.widget.ListView) Point(android.graphics.Point) ApiException(net.dean.jraw.ApiException) ActivityNotFoundException(android.content.ActivityNotFoundException) NetworkException(net.dean.jraw.http.NetworkException) Sorting(net.dean.jraw.paginators.Sorting) ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) UserRecord(net.dean.jraw.models.UserRecord) DialogAction(com.afollestad.materialdialogs.DialogAction) LayoutInflater(android.view.LayoutInflater) AccountManager(net.dean.jraw.managers.AccountManager) Snackbar(android.support.design.widget.Snackbar)

Example 32 with AsyncTask

use of android.os.AsyncTask in project Slide by ccrama.

the class CreateMulti method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.delete:
            new AlertDialogWrapper.Builder(CreateMulti.this).setTitle(getString(R.string.delete_multireddit_title, title.getText().toString())).setMessage(R.string.cannot_be_undone).setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {

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

                        @Override
                        protected Void doInBackground(Void... params) {
                            try {
                                new MultiRedditManager(Authentication.reddit).delete(old);
                                runOnUiThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        new UserSubscriptions.SyncMultireddits(CreateMulti.this).execute();
                                    }
                                });
                            } catch (final Exception e) {
                                runOnUiThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        new AlertDialogWrapper.Builder(CreateMulti.this).setTitle(R.string.err_title).setMessage(e instanceof ApiException ? getString(R.string.misc_err) + ": " + ((ApiException) e).getExplanation() + "\n" + getString(R.string.misc_retry) : getString(R.string.misc_err)).setNeutralButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

                                            @Override
                                            public void onClick(DialogInterface dialogInterface, int i) {
                                                finish();
                                            }
                                        }).create().show();
                                    }
                                });
                                e.printStackTrace();
                            }
                            return null;
                        }
                    }.execute();
                }
            }).setNegativeButton(R.string.btn_cancel, null).show();
            return true;
        case R.id.save:
            if (title.getText().toString().isEmpty()) {
                new AlertDialogWrapper.Builder(CreateMulti.this).setTitle(R.string.multireddit_title_empty).setMessage(R.string.multireddit_title_empty_msg).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        title.requestFocus();
                    }
                }).show();
            } else if (subs.isEmpty()) {
                new AlertDialogWrapper.Builder(CreateMulti.this).setTitle(R.string.multireddit_no_subs).setMessage(R.string.multireddit_no_subs_msg).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).show();
            } else {
                new SaveMulti().execute();
            }
            return true;
        case android.R.id.home:
            onBackPressed();
            return true;
        default:
            return false;
    }
}
Also used : DialogInterface(android.content.DialogInterface) AsyncTask(android.os.AsyncTask) ApiException(net.dean.jraw.ApiException) NetworkException(net.dean.jraw.http.NetworkException) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) MultiRedditManager(net.dean.jraw.managers.MultiRedditManager) ApiException(net.dean.jraw.ApiException)

Example 33 with AsyncTask

use of android.os.AsyncTask in project Slide by ccrama.

the class Crosspost method onCreate.

public void onCreate(Bundle savedInstanceState) {
    disableSwipeBackLayout();
    super.onCreate(savedInstanceState);
    applyColorTheme();
    setContentView(R.layout.activity_crosspost);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = this.getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    }
    setupAppBar(R.id.toolbar, R.string.title_crosspost, true, true);
    inboxReplies = (SwitchCompat) findViewById(R.id.replies);
    final AutoCompleteTextView subredditText = ((AutoCompleteTextView) findViewById(R.id.subreddittext));
    ((EditText) findViewById(R.id.crossposttext)).setText(toCrosspost.getTitle() + getString(R.string.submission_properties_seperator) + "/u/" + toCrosspost.getAuthor());
    findViewById(R.id.crossposttext).setEnabled(false);
    ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, UserSubscriptions.getAllSubreddits(this));
    subredditText.setAdapter(adapter);
    subredditText.setThreshold(2);
    subredditText.addTextChangedListener(new 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(Crosspost.this).setTitle(R.string.err_submit_restricted).setMessage(R.string.err_submit_restricted_text).setPositiveButton(R.string.btn_ok, null).show();
                            }
                        } else {
                            findViewById(R.id.submittext).setVisibility(View.GONE);
                        }
                    }
                };
                tchange.execute();
            }
        }
    });
    ((EditText) findViewById(R.id.titletext)).setText(toCrosspost.getTitle());
    findViewById(R.id.suggest).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ((EditText) findViewById(R.id.titletext)).setText(toCrosspost.getTitle());
        }
    });
    findViewById(R.id.send).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            ((FloatingActionButton) findViewById(R.id.send)).hide();
            new AsyncDo().execute();
        }
    });
}
Also used : Window(android.view.Window) EditText(android.widget.EditText) AsyncTask(android.os.AsyncTask) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) ApiException(net.dean.jraw.ApiException) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) Subreddit(net.dean.jraw.models.Subreddit) ArrayAdapter(android.widget.ArrayAdapter) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 34 with AsyncTask

use of android.os.AsyncTask in project Slide by ccrama.

the class Profile method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case (android.R.id.home):
            onBackPressed();
            break;
        case (R.id.category):
            new AsyncTask<Void, Void, List<String>>() {

                Dialog d;

                @Override
                public void onPreExecute() {
                    d = new MaterialDialog.Builder(Profile.this).progress(true, 100).content(R.string.misc_please_wait).title(R.string.profile_category_loading).show();
                }

                @Override
                protected List<String> doInBackground(Void... params) {
                    try {
                        List<String> categories = new ArrayList<>(new AccountManager(Authentication.reddit).getSavedCategories());
                        categories.add(0, "No category");
                        return categories;
                    } catch (Exception e) {
                        e.printStackTrace();
                        // probably has no categories?
                        return new ArrayList<String>() {

                            {
                                add(0, "No category");
                            }
                        };
                    }
                }

                @Override
                public void onPostExecute(final List<String> data) {
                    try {
                        new MaterialDialog.Builder(Profile.this).items(data).title(R.string.profile_category_select).itemsCallback(new MaterialDialog.ListCallback() {

                            @Override
                            public void onSelection(MaterialDialog dialog, final View itemView, int which, CharSequence text) {
                                final String t = data.get(which);
                                if (which == 0)
                                    category = null;
                                else
                                    category = t;
                                int current = pager.getCurrentItem();
                                ProfilePagerAdapter adapter = new ProfilePagerAdapter(getSupportFragmentManager());
                                pager.setAdapter(adapter);
                                pager.setOffscreenPageLimit(1);
                                tabs.setupWithViewPager(pager);
                                pager.setCurrentItem(current);
                            }
                        }).show();
                        if (d != null) {
                            d.dismiss();
                        }
                    } catch (Exception ignored) {
                    }
                }
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            break;
        case (R.id.info):
            if (account != null && trophyCase != null) {
                LayoutInflater inflater = getLayoutInflater();
                final View dialoglayout = inflater.inflate(R.layout.colorprofile, null);
                AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(Profile.this);
                final TextView title = (TextView) dialoglayout.findViewById(R.id.title);
                title.setText(name);
                dialoglayout.findViewById(R.id.share).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Reddit.defaultShareText(getString(R.string.profile_share, name), "https://www.reddit.com/u/" + name, Profile.this);
                    }
                });
                final int currentColor = Palette.getColorUser(name);
                title.setBackgroundColor(currentColor);
                String info = getString(R.string.profile_age, TimeUtils.getTimeSince(account.getCreated().getTime(), Profile.this));
                /*todo better if (account.hasGold() &&account.getDataNode().has("gold_expiration") ) {
                    Calendar c = Calendar.getInstance();
                    c.setTimeInMillis(account.getDataNode().get("gold_expiration").asLong());
                    info.append("Gold expires on " + new SimpleDateFormat("dd/MM/yy").format(c.getTime()));
                }*/
                ((TextView) dialoglayout.findViewById(R.id.moreinfo)).setText(info);
                String tag = UserTags.getUserTag(name);
                if (tag.isEmpty()) {
                    tag = getString(R.string.profile_tag_user);
                } else {
                    tag = getString(R.string.profile_tag_user_existing, tag);
                }
                ((TextView) dialoglayout.findViewById(R.id.tagged)).setText(tag);
                LinearLayout l = (LinearLayout) dialoglayout.findViewById(R.id.trophies_inner);
                dialoglayout.findViewById(R.id.tag).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        MaterialDialog.Builder b = new MaterialDialog.Builder(Profile.this).title(getString(R.string.profile_tag_set, name)).input(getString(R.string.profile_tag), UserTags.getUserTag(name), false, new MaterialDialog.InputCallback() {

                            @Override
                            public void onInput(MaterialDialog dialog, CharSequence input) {
                            }
                        }).positiveText(R.string.profile_btn_tag).neutralText(R.string.btn_cancel);
                        if (UserTags.isUserTagged(name)) {
                            b.negativeText(R.string.profile_btn_untag);
                        }
                        b.onPositive(new MaterialDialog.SingleButtonCallback() {

                            @Override
                            public void onClick(MaterialDialog dialog, DialogAction which) {
                                UserTags.setUserTag(name, dialog.getInputEditText().getText().toString());
                                String tag = UserTags.getUserTag(name);
                                if (tag.isEmpty()) {
                                    tag = getString(R.string.profile_tag_user);
                                } else {
                                    tag = getString(R.string.profile_tag_user_existing, tag);
                                }
                                ((TextView) dialoglayout.findViewById(R.id.tagged)).setText(tag);
                            }
                        }).onNeutral(null).onNegative(new MaterialDialog.SingleButtonCallback() {

                            @Override
                            public void onClick(MaterialDialog dialog, DialogAction which) {
                                UserTags.removeUserTag(name);
                                String tag = UserTags.getUserTag(name);
                                if (tag.isEmpty()) {
                                    tag = getString(R.string.profile_tag_user);
                                } else {
                                    tag = getString(R.string.profile_tag_user_existing, tag);
                                }
                                ((TextView) dialoglayout.findViewById(R.id.tagged)).setText(tag);
                            }
                        }).show();
                    }
                });
                if (trophyCase.isEmpty()) {
                    dialoglayout.findViewById(R.id.trophies).setVisibility(View.GONE);
                } else {
                    for (final Trophy t : trophyCase) {
                        View view = getLayoutInflater().inflate(R.layout.trophy, null);
                        ((Reddit) getApplicationContext()).getImageLoader().displayImage(t.getIcon(), ((ImageView) view.findViewById(R.id.image)));
                        ((TextView) view.findViewById(R.id.trophyTitle)).setText(t.getFullName());
                        if (t.getAboutUrl() != null && !t.getAboutUrl().equalsIgnoreCase("null")) {
                            view.setOnClickListener(new View.OnClickListener() {

                                @Override
                                public void onClick(View v) {
                                    LinkUtil.openUrl("https://reddit.com" + t.getAboutUrl(), Palette.getColorUser(account.getFullName()), Profile.this);
                                }
                            });
                        }
                        l.addView(view);
                    }
                }
                if (Authentication.isLoggedIn) {
                    dialoglayout.findViewById(R.id.pm).setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            Intent i = new Intent(Profile.this, SendMessage.class);
                            i.putExtra(SendMessage.EXTRA_NAME, name);
                            startActivity(i);
                        }
                    });
                    friend = account.isFriend();
                    if (friend) {
                        ((TextView) dialoglayout.findViewById(R.id.friend)).setText(R.string.profile_remove_friend);
                    } else {
                        ((TextView) dialoglayout.findViewById(R.id.friend)).setText(R.string.profile_add_friend);
                    }
                    dialoglayout.findViewById(R.id.friend_body).setOnClickListener(new View.OnClickListener() {

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

                                @Override
                                protected Void doInBackground(Void... params) {
                                    if (friend) {
                                        try {
                                            new AccountManager(Authentication.reddit).deleteFriend(name);
                                        } catch (Exception ignored) {
                                        // Will throw java.lang.IllegalStateException: No Content-Type header was found, but it still works.
                                        }
                                        friend = false;
                                    } else {
                                        new AccountManager(Authentication.reddit).updateFriend(name);
                                        friend = true;
                                    }
                                    return null;
                                }

                                @Override
                                public void onPostExecute(Void voids) {
                                    if (friend) {
                                        ((TextView) dialoglayout.findViewById(R.id.friend)).setText(R.string.profile_remove_friend);
                                    } else {
                                        ((TextView) dialoglayout.findViewById(R.id.friend)).setText(R.string.profile_add_friend);
                                    }
                                }
                            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                        }
                    });
                    dialoglayout.findViewById(R.id.block_body).setOnClickListener(new View.OnClickListener() {

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

                                @Override
                                protected Boolean doInBackground(Void... params) {
                                    Map<String, String> map = new HashMap();
                                    map.put("account_id", "t2_" + account.getId());
                                    try {
                                        Authentication.reddit.execute(Authentication.reddit.request().post(map).path(String.format("/api/block_user")).build());
                                    } catch (Exception ex) {
                                        return false;
                                    }
                                    return true;
                                }

                                @Override
                                public void onPostExecute(Boolean blocked) {
                                    if (!blocked) {
                                        Toast.makeText(getBaseContext(), getString(R.string.err_block_user), Toast.LENGTH_LONG).show();
                                    } else {
                                        Toast.makeText(getBaseContext(), getString(R.string.success_block_user), Toast.LENGTH_LONG).show();
                                    }
                                }
                            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                        }
                    });
                } else {
                    dialoglayout.findViewById(R.id.pm).setVisibility(View.GONE);
                }
                dialoglayout.findViewById(R.id.multi_body).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent inte = new Intent(Profile.this, MultiredditOverview.class);
                        inte.putExtra(EXTRA_PROFILE, name);
                        Profile.this.startActivity(inte);
                    }
                });
                final View body = dialoglayout.findViewById(R.id.body2);
                body.setVisibility(View.INVISIBLE);
                final View center = dialoglayout.findViewById(R.id.colorExpandFrom);
                dialoglayout.findViewById(R.id.color).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        int cx = center.getWidth() / 2;
                        int cy = center.getHeight() / 2;
                        int finalRadius = Math.max(body.getWidth(), body.getHeight());
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                            Animator anim = ViewAnimationUtils.createCircularReveal(body, cx, cy, 0, finalRadius);
                            body.setVisibility(View.VISIBLE);
                            anim.start();
                        } else {
                            body.setVisibility(View.VISIBLE);
                        }
                    }
                });
                LineColorPicker colorPicker = (LineColorPicker) dialoglayout.findViewById(R.id.picker);
                final LineColorPicker colorPicker2 = (LineColorPicker) dialoglayout.findViewById(R.id.picker2);
                colorPicker.setColors(ColorPreferences.getBaseColors(Profile.this));
                colorPicker.setOnColorChangedListener(new OnColorChangedListener() {

                    @Override
                    public void onColorChanged(int c) {
                        colorPicker2.setColors(ColorPreferences.getColors(getBaseContext(), c));
                        colorPicker2.setSelectedColor(c);
                    }
                });
                for (int i : colorPicker.getColors()) {
                    for (int i2 : ColorPreferences.getColors(getBaseContext(), i)) {
                        if (i2 == currentColor) {
                            colorPicker.setSelectedColor(i);
                            colorPicker2.setColors(ColorPreferences.getColors(getBaseContext(), i));
                            colorPicker2.setSelectedColor(i2);
                            break;
                        }
                    }
                }
                colorPicker2.setOnColorChangedListener(new OnColorChangedListener() {

                    @Override
                    public void onColorChanged(int i) {
                        findViewById(R.id.header).setBackgroundColor(colorPicker2.getColor());
                        if (mToolbar != null)
                            mToolbar.setBackgroundColor(colorPicker2.getColor());
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                            Window window = getWindow();
                            window.setStatusBarColor(Palette.getDarkerColor(colorPicker2.getColor()));
                        }
                        title.setBackgroundColor(colorPicker2.getColor());
                    }
                });
                {
                    TextView dialogButton = (TextView) dialoglayout.findViewById(R.id.ok);
                    // if button is clicked, close the custom dialog
                    dialogButton.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            Palette.setColorUser(name, colorPicker2.getColor());
                            int cx = center.getWidth() / 2;
                            int cy = center.getHeight() / 2;
                            int initialRadius = body.getWidth();
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                Animator anim = ViewAnimationUtils.createCircularReveal(body, cx, cy, initialRadius, 0);
                                anim.addListener(new AnimatorListenerAdapter() {

                                    @Override
                                    public void onAnimationEnd(Animator animation) {
                                        super.onAnimationEnd(animation);
                                        body.setVisibility(View.GONE);
                                    }
                                });
                                anim.start();
                            } else {
                                body.setVisibility(View.GONE);
                            }
                        }
                    });
                }
                {
                    final TextView dialogButton = (TextView) dialoglayout.findViewById(R.id.reset);
                    // if button is clicked, close the custom dialog
                    dialogButton.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            Palette.removeUserColor(name);
                            Snackbar.make(dialogButton, "User color removed", Snackbar.LENGTH_SHORT).show();
                            int cx = center.getWidth() / 2;
                            int cy = center.getHeight() / 2;
                            int initialRadius = body.getWidth();
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                Animator anim = ViewAnimationUtils.createCircularReveal(body, cx, cy, initialRadius, 0);
                                anim.addListener(new AnimatorListenerAdapter() {

                                    @Override
                                    public void onAnimationEnd(Animator animation) {
                                        super.onAnimationEnd(animation);
                                        body.setVisibility(View.GONE);
                                    }
                                });
                                anim.start();
                            } else {
                                body.setVisibility(View.GONE);
                            }
                        }
                    });
                }
                ((TextView) dialoglayout.findViewById(R.id.commentkarma)).setText(String.format(Locale.getDefault(), "%d", account.getCommentKarma()));
                ((TextView) dialoglayout.findViewById(R.id.linkkarma)).setText(String.format(Locale.getDefault(), "%d", account.getLinkKarma()));
                builder.setOnDismissListener(new DialogInterface.OnDismissListener() {

                    @Override
                    public void onDismiss(DialogInterface dialogInterface) {
                        findViewById(R.id.header).setBackgroundColor(currentColor);
                        if (mToolbar != null)
                            mToolbar.setBackgroundColor(currentColor);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                            Window window = getWindow();
                            window.setStatusBarColor(Palette.getDarkerColor(currentColor));
                        }
                    }
                });
                builder.setView(dialoglayout);
                builder.show();
            }
            return true;
        case (R.id.sort):
            openPopup();
            return true;
    }
    return false;
}
Also used : Trophy(net.dean.jraw.models.Trophy) HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Dialog(android.app.Dialog) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) List(java.util.List) ArrayList(java.util.ArrayList) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Window(android.view.Window) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ContributionsView(me.ccrama.redditslide.Fragments.ContributionsView) HistoryView(me.ccrama.redditslide.Fragments.HistoryView) LineColorPicker(uz.shift.colorpicker.LineColorPicker) Animator(android.animation.Animator) DialogAction(com.afollestad.materialdialogs.DialogAction) OnColorChangedListener(uz.shift.colorpicker.OnColorChangedListener) LayoutInflater(android.view.LayoutInflater) AccountManager(net.dean.jraw.managers.AccountManager) LinearLayout(android.widget.LinearLayout)

Example 35 with AsyncTask

use of android.os.AsyncTask 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)

Aggregations

AsyncTask (android.os.AsyncTask)395 IOException (java.io.IOException)188 InputStream (java.io.InputStream)159 URL (java.net.URL)159 HttpURLConnection (java.net.HttpURLConnection)158 ExecutionException (java.util.concurrent.ExecutionException)158 Gson (com.google.gson.Gson)155 Message (com.remswork.project.alice.model.support.Message)153 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)102 ArrayList (java.util.ArrayList)93 View (android.view.View)54 Intent (android.content.Intent)52 TextView (android.widget.TextView)52 JSONException (org.json.JSONException)51 JSONArray (org.json.JSONArray)50 DialogInterface (android.content.DialogInterface)40 OutputStream (java.io.OutputStream)37 BufferedWriter (java.io.BufferedWriter)35 OutputStreamWriter (java.io.OutputStreamWriter)35 ImageView (android.widget.ImageView)33