Search in sources :

Example 1 with UserSubredditsPaginator

use of net.dean.jraw.paginators.UserSubredditsPaginator in project Slide by ccrama.

the class ReorderSubreddits method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    disableSwipeBackLayout();
    super.onCreate(savedInstanceState);
    applyColorTheme();
    setContentView(R.layout.activity_sort);
    setupAppBar(R.id.toolbar, R.string.settings_manage_subscriptions, false, true);
    mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    isSubscribed = new HashMap<>();
    if (Authentication.isLoggedIn) {
        new AsyncTask<Void, Void, Void>() {

            boolean success = true;

            @Override
            protected Void doInBackground(Void... params) {
                ArrayList<Subreddit> subs = new ArrayList<>();
                UserSubredditsPaginator p = new UserSubredditsPaginator(Authentication.reddit, "subscriber");
                try {
                    while (p.hasNext()) {
                        subs.addAll(p.next());
                    }
                } catch (Exception e) {
                    success = false;
                    return null;
                }
                for (Subreddit s : subs) {
                    isSubscribed.put(s.getDisplayName().toLowerCase(Locale.ENGLISH), true);
                }
                if (UserSubscriptions.multireddits == null) {
                    UserSubscriptions.loadMultireddits();
                }
                return null;
            }

            @Override
            protected void onPostExecute(Void aVoid) {
                if (success) {
                    d.dismiss();
                    doShowSubs();
                } else {
                    new AlertDialogWrapper.Builder(ReorderSubreddits.this).setTitle(R.string.err_title).setMessage(R.string.misc_please_try_again_soon).setCancelable(false).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            finish();
                        }
                    }).show();
                }
            }

            Dialog d;

            @Override
            protected void onPreExecute() {
                d = new MaterialDialog.Builder(ReorderSubreddits.this).progress(true, 100).content(R.string.misc_please_wait).title(R.string.reorder_loading_title).cancelable(false).show();
            }
        }.execute();
    } else {
        doShowSubs();
    }
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ColorPreferences(me.ccrama.redditslide.ColorPreferences) DialogInterface(android.content.DialogInterface) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) ArrayList(java.util.ArrayList) UserSubredditsPaginator(net.dean.jraw.paginators.UserSubredditsPaginator) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Dialog(android.app.Dialog) MultiSubreddit(net.dean.jraw.models.MultiSubreddit) Subreddit(net.dean.jraw.models.Subreddit)

Example 2 with UserSubredditsPaginator

use of net.dean.jraw.paginators.UserSubredditsPaginator in project Slide by ccrama.

the class UserSubscriptions method syncSubredditsGetObject.

public static ArrayList<Subreddit> syncSubredditsGetObject() {
    ArrayList<Subreddit> toReturn = new ArrayList<>();
    if (Authentication.isLoggedIn) {
        UserSubredditsPaginator pag = new UserSubredditsPaginator(Authentication.reddit, "subscriber");
        pag.setLimit(100);
        try {
            while (pag.hasNext()) {
                for (net.dean.jraw.models.Subreddit s : pag.next()) {
                    toReturn.add(s);
                }
            }
        } catch (Exception e) {
            // failed;
            e.printStackTrace();
        }
        addSubsToHistory(toReturn);
        return toReturn;
    }
    return toReturn;
}
Also used : ArrayList(java.util.ArrayList) UserSubredditsPaginator(net.dean.jraw.paginators.UserSubredditsPaginator) Subreddit(net.dean.jraw.models.Subreddit) MultiSubreddit(net.dean.jraw.models.MultiSubreddit) Subreddit(net.dean.jraw.models.Subreddit) ApiException(net.dean.jraw.ApiException) NetworkException(net.dean.jraw.http.NetworkException)

Example 3 with UserSubredditsPaginator

use of net.dean.jraw.paginators.UserSubredditsPaginator in project Slide by ccrama.

the class UserSubscriptions method syncSubredditsGetObjectAsync.

public static void syncSubredditsGetObjectAsync(final Login mainActivity) {
    final ArrayList<Subreddit> toReturn = new ArrayList<>();
    new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... params) {
            if (Authentication.isLoggedIn) {
                UserSubredditsPaginator pag = new UserSubredditsPaginator(Authentication.reddit, "subscriber");
                pag.setLimit(100);
                try {
                    while (pag.hasNext()) {
                        for (net.dean.jraw.models.Subreddit s : pag.next()) {
                            toReturn.add(s);
                        }
                    }
                } catch (Exception e) {
                    // failed;
                    e.printStackTrace();
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            mainActivity.doLastStuff(toReturn);
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : ArrayList(java.util.ArrayList) UserSubredditsPaginator(net.dean.jraw.paginators.UserSubredditsPaginator) MultiSubreddit(net.dean.jraw.models.MultiSubreddit) Subreddit(net.dean.jraw.models.Subreddit) ApiException(net.dean.jraw.ApiException) NetworkException(net.dean.jraw.http.NetworkException)

Example 4 with UserSubredditsPaginator

use of net.dean.jraw.paginators.UserSubredditsPaginator in project Slide by ccrama.

the class UserSubscriptions method doModOf.

private static CaseInsensitiveArrayList doModOf() {
    CaseInsensitiveArrayList finished = new CaseInsensitiveArrayList();
    UserSubredditsPaginator pag = new UserSubredditsPaginator(Authentication.reddit, "moderator");
    pag.setLimit(100);
    try {
        while (pag.hasNext()) {
            for (net.dean.jraw.models.Subreddit s : pag.next()) {
                finished.add(s.getDisplayName().toLowerCase(Locale.ENGLISH));
            }
        }
        modOf = (finished);
        cacheModOf();
    } catch (Exception e) {
        // failed;
        e.printStackTrace();
    }
    return finished;
}
Also used : UserSubredditsPaginator(net.dean.jraw.paginators.UserSubredditsPaginator) Subreddit(net.dean.jraw.models.Subreddit) ApiException(net.dean.jraw.ApiException) NetworkException(net.dean.jraw.http.NetworkException)

Example 5 with UserSubredditsPaginator

use of net.dean.jraw.paginators.UserSubredditsPaginator in project Slide by ccrama.

the class UserSubscriptions method syncSubreddits.

public static CaseInsensitiveArrayList syncSubreddits(Context c) {
    CaseInsensitiveArrayList toReturn = new CaseInsensitiveArrayList();
    if (Authentication.isLoggedIn && NetworkUtil.isConnected(c)) {
        UserSubredditsPaginator pag = new UserSubredditsPaginator(Authentication.reddit, "subscriber");
        pag.setLimit(100);
        try {
            while (pag.hasNext()) {
                for (net.dean.jraw.models.Subreddit s : pag.next()) {
                    toReturn.add(s.getDisplayName().toLowerCase(Locale.ENGLISH));
                }
            }
            if (toReturn.isEmpty() && subscriptions.getString(Authentication.name, "").isEmpty()) {
                toreturn.addAll(defaultSubs);
            }
        } catch (Exception e) {
            // failed;
            e.printStackTrace();
        }
        addSubsToHistory(toReturn, true);
        return toReturn;
    } else {
        toReturn.addAll(defaultSubs);
        return toReturn;
    }
}
Also used : UserSubredditsPaginator(net.dean.jraw.paginators.UserSubredditsPaginator) Subreddit(net.dean.jraw.models.Subreddit) ApiException(net.dean.jraw.ApiException) NetworkException(net.dean.jraw.http.NetworkException)

Aggregations

Subreddit (net.dean.jraw.models.Subreddit)5 UserSubredditsPaginator (net.dean.jraw.paginators.UserSubredditsPaginator)5 ApiException (net.dean.jraw.ApiException)4 NetworkException (net.dean.jraw.http.NetworkException)4 ArrayList (java.util.ArrayList)3 MultiSubreddit (net.dean.jraw.models.MultiSubreddit)3 Dialog (android.app.Dialog)1 DialogInterface (android.content.DialogInterface)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 CaseInsensitiveArrayList (me.ccrama.redditslide.CaseInsensitiveArrayList)1 ColorPreferences (me.ccrama.redditslide.ColorPreferences)1