use of net.dean.jraw.models.Subreddit 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.models.Subreddit 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.models.Subreddit in project Slide by ccrama.
the class SubredditAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder2, final int pos) {
int i = pos != 0 ? pos - 1 : pos;
if (holder2 instanceof SubredditViewHolder) {
final SubredditViewHolder holder = (SubredditViewHolder) holder2;
final Subreddit sub = dataSet.posts.get(i);
holder.name.setText(sub.getDisplayName());
holder.color.setBackgroundResource(R.drawable.circle);
holder.color.getBackground().setColorFilter(Palette.getColor(sub.getDisplayName().toLowerCase(Locale.ENGLISH)), PorterDuff.Mode.MULTIPLY);
holder.itemView.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(context, SubredditView.class);
inte.putExtra(SubredditView.EXTRA_SUBREDDIT, sub.getDisplayName());
context.startActivityForResult(inte, 4);
}
});
holder.overflow.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(context, SubredditView.class);
inte.putExtra(SubredditView.EXTRA_SUBREDDIT, sub.getDisplayName());
context.startActivityForResult(inte, 4);
}
});
holder.body.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(context, SubredditView.class);
inte.putExtra(SubredditView.EXTRA_SUBREDDIT, sub.getDisplayName());
context.startActivityForResult(inte, 4);
}
});
if (sub.getDataNode().get("public_description_html").asText().equals("null")) {
holder.body.setVisibility(View.GONE);
holder.overflow.setVisibility(View.GONE);
} else {
holder.body.setVisibility(View.VISIBLE);
holder.overflow.setVisibility(View.VISIBLE);
setViews(sub.getDataNode().get("public_description_html").asText().trim(), sub.getDisplayName().toLowerCase(Locale.ENGLISH), holder.body, holder.overflow);
}
try {
int state = sub.isUserSubscriber() ? View.VISIBLE : View.INVISIBLE;
holder.subbed.setVisibility(state);
} catch (Exception e) {
holder.subbed.setVisibility(View.INVISIBLE);
}
} else if (holder2 instanceof SubmissionFooterViewHolder) {
Handler handler = new Handler();
final Runnable r = new Runnable() {
public void run() {
// the loading spinner to replaced by nomoreposts.xml
notifyItemChanged(dataSet.posts.size() + 1);
}
};
handler.post(r);
if (holder2.itemView.findViewById(R.id.reload) != null) {
holder2.itemView.setVisibility(View.INVISIBLE);
}
}
if (holder2 instanceof SpacerViewHolder) {
final int height = (context).findViewById(R.id.header).getHeight();
holder2.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(holder2.itemView.getWidth(), height));
if (listView.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
CatchStaggeredGridLayoutManager.LayoutParams layoutParams = new CatchStaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height);
layoutParams.setFullSpan(true);
holder2.itemView.setLayoutParams(layoutParams);
}
}
}
use of net.dean.jraw.models.Subreddit in project Slide by ccrama.
the class Login method doSubStrings.
private void doSubStrings(ArrayList<Subreddit> subs) {
subNames = new CaseInsensitiveArrayList();
for (Subreddit s : subs) {
subNames.add(s.getDisplayName().toLowerCase(Locale.ENGLISH));
}
subNames = UserSubscriptions.sort(subNames);
if (!subNames.contains("slideforreddit")) {
new AlertDialogWrapper.Builder(Login.this).setTitle(R.string.login_subscribe_rslideforreddit).setMessage(R.string.login_subscribe_rslideforreddit_desc).setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
subNames.add(2, "slideforreddit");
UserSubscriptions.setSubscriptions(subNames);
Reddit.forceRestart(Login.this, true);
}
}).setNegativeButton(R.string.btn_no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
UserSubscriptions.setSubscriptions(subNames);
Reddit.forceRestart(Login.this, true);
}
}).setCancelable(false).show();
} else {
UserSubscriptions.setSubscriptions(subNames);
Reddit.forceRestart(Login.this, true);
}
}
Aggregations