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();
}
}
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;
}
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);
}
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;
}
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;
}
}
Aggregations