use of me.ccrama.redditslide.OfflineSubreddit in project Slide by ccrama.
the class Shadowbox method onCreate.
@Override
public void onCreate(Bundle savedInstance) {
overrideSwipeFromAnywhere();
subreddit = getIntent().getExtras().getString(EXTRA_SUBREDDIT);
firstPage = getIntent().getExtras().getInt(EXTRA_PAGE, 0);
subreddit = getIntent().getExtras().getString(EXTRA_SUBREDDIT);
String multireddit = getIntent().getExtras().getString(EXTRA_MULTIREDDIT);
String profile = getIntent().getExtras().getString(EXTRA_PROFILE, "");
if (multireddit != null) {
subredditPosts = new MultiredditPosts(multireddit, profile);
} else {
subredditPosts = new SubredditPosts(subreddit, Shadowbox.this);
}
subreddit = multireddit == null ? subreddit : ("multi" + multireddit);
if (multireddit == null) {
setShareUrl("https://reddit.com/r/" + subreddit);
}
applyDarkColorTheme(subreddit);
super.onCreate(savedInstance);
setContentView(R.layout.activity_slide);
long offline = getIntent().getLongExtra("offline", 0L);
OfflineSubreddit submissions = OfflineSubreddit.getSubreddit(subreddit, offline, !Authentication.didOnline, this);
subredditPosts.getPosts().addAll(submissions.submissions);
pager = (ViewPager) findViewById(R.id.content_view);
submissionsPager = new OverviewPagerAdapter(getSupportFragmentManager());
pager.setAdapter(submissionsPager);
pager.setCurrentItem(firstPage);
pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
if (SettingValues.storeHistory) {
if (subredditPosts.getPosts().get(position).isNsfw() && !SettingValues.storeNSFWHistory) {
} else
HasSeen.addSeen(subredditPosts.getPosts().get(position).getFullName());
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
}
use of me.ccrama.redditslide.OfflineSubreddit in project Slide by ccrama.
the class SubredditPosts method doMainActivityOffline.
public void doMainActivityOffline(final Context c, final SubmissionDisplay displayer) {
LogUtil.v(subreddit);
if (all == null) {
all = OfflineSubreddit.getAll(subreddit);
}
// Move 0, or "submission only", to the end
Collections.rotate(all, -1);
offline = true;
final String[] titles = new String[all.size()];
final String[] base = new String[all.size()];
int i = 0;
for (String s : all) {
String[] split = s.split(",");
titles[i] = (Long.valueOf(split[1]) == 0 ? c.getString(R.string.settings_backup_submission_only) : TimeUtils.getTimeAgo(Long.valueOf(split[1]), c) + c.getString(R.string.settings_backup_comments));
base[i] = s;
i++;
}
((MainActivity) c).getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
((MainActivity) c).getSupportActionBar().setListNavigationCallbacks(new OfflineSubAdapter(c, android.R.layout.simple_list_item_1, titles), new ActionBar.OnNavigationListener() {
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
final String[] s2 = base[itemPosition].split(",");
OfflineSubreddit.currentid = Long.valueOf(s2[1]);
currentid = OfflineSubreddit.currentid;
new AsyncTask<Void, Void, Void>() {
OfflineSubreddit cached;
@Override
protected Void doInBackground(Void... params) {
cached = OfflineSubreddit.getSubreddit(subreddit, Long.valueOf(s2[1]), true, c);
List<Submission> finalSubs = new ArrayList<>();
for (Submission s : cached.submissions) {
if (!PostMatch.doesMatch(s, subreddit, force18)) {
finalSubs.add(s);
}
}
posts = finalSubs;
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
if (cached.submissions.isEmpty()) {
displayer.updateOfflineError();
}
// update offline
displayer.updateOffline(posts, Long.valueOf(s2[1]));
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
return true;
}
});
}
use of me.ccrama.redditslide.OfflineSubreddit in project Slide by ccrama.
the class MultiredditView method clearSeenPosts.
private List<Submission> clearSeenPosts(boolean forever) {
if (posts.posts != null) {
List<Submission> originalDataSetPosts = posts.posts;
OfflineSubreddit o = OfflineSubreddit.getSubreddit("multi" + posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), false, getActivity());
for (int i = posts.posts.size(); i > -1; i--) {
try {
if (HasSeen.getSeen(posts.posts.get(i))) {
if (forever) {
Hidden.setHidden(posts.posts.get(i));
}
o.clearPost(posts.posts.get(i));
posts.posts.remove(i);
if (posts.posts.isEmpty()) {
adapter.notifyDataSetChanged();
} else {
rv.setItemAnimator(new AlphaInAnimator());
adapter.notifyItemRemoved(i + 1);
}
}
} catch (IndexOutOfBoundsException e) {
// Let the loop reset itself
}
}
o.writeToMemoryNoStorage();
rv.setItemAnimator(new SlideUpAlphaAnimator());
return originalDataSetPosts;
}
return null;
}
use of me.ccrama.redditslide.OfflineSubreddit in project Slide by ccrama.
the class PopulateNewsViewHolder method hideSubmission.
public <T extends Contribution> void hideSubmission(final Submission submission, final List<T> posts, final String baseSub, final RecyclerView recyclerview, Context c) {
final int pos = posts.indexOf(submission);
if (pos != -1) {
if (submission.isHidden()) {
posts.remove(pos);
Hidden.undoHidden(submission);
recyclerview.getAdapter().notifyItemRemoved(pos + 1);
Snackbar snack = Snackbar.make(recyclerview, R.string.submission_info_unhidden, Snackbar.LENGTH_LONG);
View view = snack.getView();
TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
snack.show();
} else {
final T t = posts.get(pos);
posts.remove(pos);
Hidden.setHidden(t);
final OfflineSubreddit s;
boolean success = false;
if (baseSub != null) {
s = OfflineSubreddit.getSubreddit(baseSub, false, c);
try {
s.hide(pos);
success = true;
} catch (Exception e) {
}
} else {
success = false;
s = null;
}
recyclerview.getAdapter().notifyItemRemoved(pos + 1);
final boolean finalSuccess = success;
Snackbar snack = Snackbar.make(recyclerview, R.string.submission_info_hidden, Snackbar.LENGTH_LONG).setAction(R.string.btn_undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
if (baseSub != null && s != null && finalSuccess) {
s.unhideLast();
}
posts.add(pos, t);
recyclerview.getAdapter().notifyItemInserted(pos + 1);
Hidden.undoHidden(t);
}
});
View view = snack.getView();
TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
snack.show();
}
}
}
use of me.ccrama.redditslide.OfflineSubreddit in project Slide by ccrama.
the class PopulateSubmissionViewHolder method hideSubmission.
public <T extends Contribution> void hideSubmission(final Submission submission, final List<T> posts, final String baseSub, final RecyclerView recyclerview, Context c) {
final int pos = posts.indexOf(submission);
if (pos != -1) {
if (submission.isHidden()) {
posts.remove(pos);
Hidden.undoHidden(submission);
recyclerview.getAdapter().notifyItemRemoved(pos + 1);
Snackbar snack = Snackbar.make(recyclerview, R.string.submission_info_unhidden, Snackbar.LENGTH_LONG);
View view = snack.getView();
TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
snack.show();
} else {
final T t = posts.get(pos);
posts.remove(pos);
Hidden.setHidden(t);
final OfflineSubreddit s;
boolean success = false;
if (baseSub != null) {
s = OfflineSubreddit.getSubreddit(baseSub, false, c);
try {
s.hide(pos);
success = true;
} catch (Exception e) {
}
} else {
success = false;
s = null;
}
recyclerview.getAdapter().notifyItemRemoved(pos + 1);
final boolean finalSuccess = success;
Snackbar snack = Snackbar.make(recyclerview, R.string.submission_info_hidden, Snackbar.LENGTH_LONG).setAction(R.string.btn_undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
if (baseSub != null && s != null && finalSuccess) {
s.unhideLast();
}
posts.add(pos, t);
recyclerview.getAdapter().notifyItemInserted(pos + 1);
Hidden.undoHidden(t);
}
});
View view = snack.getView();
TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
snack.show();
}
}
}
Aggregations