use of me.ccrama.redditslide.Fragments.SubmissionsView in project Slide by ccrama.
the class SubmissionAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder2, final int pos) {
int i = pos != 0 ? pos - 1 : pos;
if (holder2 instanceof SubmissionViewHolder) {
final SubmissionViewHolder holder = (SubmissionViewHolder) holder2;
final Submission submission = dataSet.posts.get(i);
CreateCardView.colorCard(submission.getSubredditName().toLowerCase(Locale.ENGLISH), holder.itemView, subreddit, (subreddit.equals("frontpage") || subreddit.equals("mod") || subreddit.equals("friends") || (subreddit.equals("all")) || subreddit.contains(".") || subreddit.contains("+")));
holder.itemView.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
if (Authentication.didOnline || submission.getComments() != null) {
holder.title.setAlpha(0.54f);
holder.body.setAlpha(0.54f);
if (context instanceof MainActivity) {
final MainActivity a = (MainActivity) context;
if (a.singleMode && a.commentPager && a.adapter instanceof MainActivity.OverviewPagerAdapterComment) {
if (a.openingComments != submission) {
clicked = holder2.getAdapterPosition();
a.openingComments = submission;
a.toOpenComments = a.pager.getCurrentItem() + 1;
a.currentComment = holder.getAdapterPosition() - 1;
((MainActivity.OverviewPagerAdapterComment) (a).adapter).storedFragment = (a).adapter.getCurrentFragment();
((MainActivity.OverviewPagerAdapterComment) (a).adapter).size = a.toOpenComments + 1;
try {
a.adapter.notifyDataSetChanged();
} catch (Exception ignored) {
}
}
a.pager.postDelayed(new Runnable() {
@Override
public void run() {
a.pager.setCurrentItem(a.pager.getCurrentItem() + 1, true);
}
}, 400);
} else {
Intent i2 = new Intent(context, CommentsScreen.class);
i2.putExtra(CommentsScreen.EXTRA_PAGE, holder2.getAdapterPosition() - 1);
i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, subreddit);
i2.putExtra("fullname", submission.getFullName());
context.startActivityForResult(i2, 940);
clicked = holder2.getAdapterPosition();
}
} else if (context instanceof SubredditView) {
final SubredditView a = (SubredditView) context;
if (a.singleMode && a.commentPager) {
if (a.openingComments != submission) {
clicked = holder2.getAdapterPosition();
a.openingComments = submission;
a.currentComment = holder.getAdapterPosition() - 1;
((SubredditView.OverviewPagerAdapterComment) (a).adapter).storedFragment = (a).adapter.getCurrentFragment();
((SubredditView.OverviewPagerAdapterComment) a.adapter).size = 3;
a.adapter.notifyDataSetChanged();
}
a.pager.postDelayed(new Runnable() {
@Override
public void run() {
a.pager.setCurrentItem(a.pager.getCurrentItem() + 1, true);
}
}, 400);
} else {
Intent i2 = new Intent(context, CommentsScreen.class);
i2.putExtra(CommentsScreen.EXTRA_PAGE, holder2.getAdapterPosition() - 1);
i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, subreddit);
i2.putExtra("fullname", submission.getFullName());
context.startActivityForResult(i2, 940);
clicked = holder2.getAdapterPosition();
}
}
} else {
if (!Reddit.appRestart.contains("offlinepopup")) {
new AlertDialogWrapper.Builder(context).setTitle(R.string.cache_no_comments_found).setMessage(R.string.cache_no_comments_found_message).setCancelable(false).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Reddit.appRestart.edit().putString("offlinepopup", "").apply();
}
}).show();
} else {
Snackbar s = Snackbar.make(holder.itemView, R.string.cache_no_comments_found_snackbar, Snackbar.LENGTH_SHORT);
s.setAction(R.string.misc_more_info, new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialogWrapper.Builder(context).setTitle(R.string.cache_no_comments_found).setMessage(R.string.cache_no_comments_found_message).setCancelable(false).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Reddit.appRestart.edit().putString("offlinepopup", "").apply();
}
}).show();
}
});
View view = s.getView();
TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.show();
}
}
}
});
new PopulateSubmissionViewHolder().populateSubmissionViewHolder(holder, submission, context, false, false, dataSet.posts, listView, custom, dataSet.offline, dataSet.subreddit.toLowerCase(Locale.ENGLISH), null);
}
if (holder2 instanceof SubmissionFooterViewHolder) {
Handler handler = new Handler();
final Runnable r = new Runnable() {
public void run() {
notifyItemChanged(dataSet.posts.size() + // the loading spinner to replaced by nomoreposts.xml
1);
}
};
handler.post(r);
if (holder2.itemView.findViewById(R.id.reload) != null) {
holder2.itemView.findViewById(R.id.reload).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((SubmissionsView) displayer).forceRefresh();
}
});
}
}
if (holder2 instanceof SpacerViewHolder) {
View header = (context).findViewById(R.id.header);
int height = header.getHeight();
if (height == 0) {
header.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
height = header.getMeasuredHeight();
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);
}
} else {
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 me.ccrama.redditslide.Fragments.SubmissionsView in project Slide by ccrama.
the class MainActivity method getCurrentPage.
public int getCurrentPage() {
int position = 0;
int currentOrientation = getResources().getConfiguration().orientation;
if (adapter.getCurrentFragment() == null) {
return 0;
}
if (((SubmissionsView) adapter.getCurrentFragment()).rv.getLayoutManager() instanceof LinearLayoutManager && currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
position = ((LinearLayoutManager) ((SubmissionsView) adapter.getCurrentFragment()).rv.getLayoutManager()).findFirstCompletelyVisibleItemPosition() - 1;
} else if (((SubmissionsView) adapter.getCurrentFragment()).rv.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
int[] firstVisibleItems = null;
firstVisibleItems = ((CatchStaggeredGridLayoutManager) ((SubmissionsView) adapter.getCurrentFragment()).rv.getLayoutManager()).findFirstCompletelyVisibleItemPositions(firstVisibleItems);
if (firstVisibleItems != null && firstVisibleItems.length > 0) {
position = firstVisibleItems[0] - 1;
}
} else {
position = ((PreCachingLayoutManager) ((SubmissionsView) adapter.getCurrentFragment()).rv.getLayoutManager()).findFirstCompletelyVisibleItemPosition() - 1;
}
return position;
}
use of me.ccrama.redditslide.Fragments.SubmissionsView in project Slide by ccrama.
the class MainActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == SETTINGS_RESULT) {
int current = pager.getCurrentItem();
if (commentPager && current == currentComment) {
current = current - 1;
}
if (current < 0)
current = 0;
adapter = new OverviewPagerAdapter(getSupportFragmentManager());
pager.setAdapter(adapter);
pager.setCurrentItem(current);
if (mTabLayout != null) {
mTabLayout.setupWithViewPager(pager);
scrollToTabAfterLayout(current);
}
setToolbarClick();
} else if ((requestCode == 2001 || requestCode == 2002) && resultCode == RESULT_OK) {
if (SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_DRAWER || SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_BOTH) {
drawerLayout.closeDrawers();
drawerSearch.setText("");
}
// clear the text from the toolbar search field
if (findViewById(R.id.toolbar_search) != null) {
((AutoCompleteTextView) findViewById(R.id.toolbar_search)).setText("");
}
View view = MainActivity.this.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
} else if (requestCode == 2002 && resultCode != RESULT_OK) {
// search was init from the toolbar, so return focus to the toolbar
mToolbar.performLongClick();
} else if (requestCode == 423 && resultCode == RESULT_OK) {
((OverviewPagerAdapterComment) adapter).mCurrentComments.doResult(data);
} else if (requestCode == 940) {
if (adapter != null && adapter.getCurrentFragment() != null) {
if (resultCode == RESULT_OK) {
ArrayList<Integer> posts = data.getIntegerArrayListExtra("seen");
((SubmissionsView) adapter.getCurrentFragment()).adapter.refreshView(posts);
if (data.hasExtra("lastPage") && data.getIntExtra("lastPage", 0) != 0 && ((SubmissionsView) adapter.getCurrentFragment()).rv.getLayoutManager() instanceof LinearLayoutManager) {
((LinearLayoutManager) ((SubmissionsView) adapter.getCurrentFragment()).rv.getLayoutManager()).scrollToPositionWithOffset(data.getIntExtra("lastPage", 0) + 1, mToolbar.getHeight());
}
} else {
((SubmissionsView) adapter.getCurrentFragment()).adapter.refreshView();
}
}
} else if (requestCode == RESET_ADAPTER_RESULT) {
resetAdapter();
setDrawerSubList();
} else if (requestCode == TUTORIAL_RESULT) {
UserSubscriptions.doMainActivitySubs(this);
} else if (requestCode == INBOX_RESULT) {
// update notification badge
new AsyncNotificationBadge().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else if (requestCode == 3333) {
this.data = data;
if (doImage != null) {
Handler handler = new Handler();
handler.post(doImage);
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
/* todo if(resultCode == 4 && UserSubscriptions.hasChanged){
UserSubscriptions.hasChanged = false;
sideArrayAdapter.setSideItems(UserSubscriptions.getAllSubreddits(this));
sideArrayAdapter.notifyDataSetChanged();
}*/
}
use of me.ccrama.redditslide.Fragments.SubmissionsView in project Slide by ccrama.
the class MainActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
final String subreddit = usedArray.get(Reddit.currentPosition);
switch(item.getItemId()) {
case R.id.filter:
filterContent(shouldLoad);
return true;
case R.id.sidebar:
if (!subreddit.equals("all") && !subreddit.equals("frontpage") && !subreddit.contains(".") && !subreddit.contains("+") && !subreddit.contains(".") && !subreddit.contains("/m/")) {
drawerLayout.openDrawer(GravityCompat.END);
} else {
Toast.makeText(this, R.string.sidebar_notfound, Toast.LENGTH_SHORT).show();
}
return true;
case R.id.night:
{
LayoutInflater inflater = getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.choosethemesmall, null);
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(MainActivity.this);
final TextView title = dialoglayout.findViewById(R.id.title);
title.setBackgroundColor(Palette.getDefaultColor());
builder.setView(dialoglayout);
final Dialog d = builder.show();
back = new ColorPreferences(MainActivity.this).getFontStyle().getThemeType();
if (SettingValues.isNight()) {
dialoglayout.findViewById(R.id.nightmsg).setVisibility(View.VISIBLE);
}
dialoglayout.findViewById(R.id.black).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
String name = names[names.length - 1];
final String newName = name.replace("(", "");
for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
if (theme.toString().contains(newName) && theme.getThemeType() == 2) {
back = theme.getThemeType();
new ColorPreferences(MainActivity.this).setFontStyle(theme);
d.dismiss();
restartTheme();
break;
}
}
}
});
dialoglayout.findViewById(R.id.blacklighter).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
String name = names[names.length - 1];
final String newName = name.replace("(", "");
for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
if (theme.toString().contains(newName) && theme.getThemeType() == 4) {
back = theme.getThemeType();
new ColorPreferences(MainActivity.this).setFontStyle(theme);
d.dismiss();
restartTheme();
break;
}
}
}
});
dialoglayout.findViewById(R.id.deep).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
String name = names[names.length - 1];
final String newName = name.replace("(", "");
for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
if (theme.toString().contains(newName) && theme.getThemeType() == 8) {
back = theme.getThemeType();
new ColorPreferences(MainActivity.this).setFontStyle(theme);
d.dismiss();
restartTheme();
break;
}
}
}
});
dialoglayout.findViewById(R.id.sepia).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
String name = names[names.length - 1];
final String newName = name.replace("(", "");
for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
if (theme.toString().contains(newName) && theme.getThemeType() == 5) {
back = theme.getThemeType();
new ColorPreferences(MainActivity.this).setFontStyle(theme);
d.dismiss();
restartTheme();
break;
}
}
}
});
dialoglayout.findViewById(R.id.pixel).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
String name = names[names.length - 1];
final String newName = name.replace("(", "");
for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
if (theme.toString().contains(newName) && theme.getThemeType() == 7) {
back = theme.getThemeType();
new ColorPreferences(MainActivity.this).setFontStyle(theme);
d.dismiss();
restartTheme();
break;
}
}
}
});
dialoglayout.findViewById(R.id.red).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
String name = names[names.length - 1];
final String newName = name.replace("(", "");
for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
if (theme.toString().contains(newName) && theme.getThemeType() == 6) {
back = theme.getThemeType();
new ColorPreferences(MainActivity.this).setFontStyle(theme);
d.dismiss();
restartTheme();
break;
}
}
}
});
dialoglayout.findViewById(R.id.light).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
String name = names[names.length - 1];
final String newName = name.replace("(", "");
for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
if (theme.toString().contains(newName) && theme.getThemeType() == 1) {
new ColorPreferences(MainActivity.this).setFontStyle(theme);
back = theme.getThemeType();
d.dismiss();
restartTheme();
break;
}
}
}
});
dialoglayout.findViewById(R.id.dark).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
String name = names[names.length - 1];
final String newName = name.replace("(", "");
for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
if (theme.toString().contains(newName) && theme.getThemeType() == 0) {
new ColorPreferences(MainActivity.this).setFontStyle(theme);
back = theme.getThemeType();
d.dismiss();
restartTheme();
break;
}
}
}
});
dialoglayout.findViewById(R.id.blue).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
String name = names[names.length - 1];
final String newName = name.replace("(", "");
for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
if (theme.toString().contains(newName) && theme.getThemeType() == 3) {
new ColorPreferences(MainActivity.this).setFontStyle(theme);
back = theme.getThemeType();
d.dismiss();
restartTheme();
break;
}
}
}
});
}
return true;
case R.id.action_refresh:
if (adapter != null && adapter.getCurrentFragment() != null) {
((SubmissionsView) adapter.getCurrentFragment()).forceRefresh();
}
return true;
case R.id.action_sort:
if (subreddit.equalsIgnoreCase("friends")) {
Snackbar s = Snackbar.make(findViewById(R.id.anchor), getString(R.string.friends_sort_error), Snackbar.LENGTH_SHORT);
View view = s.getView();
TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.show();
} else {
openPopup();
}
return true;
case R.id.search:
MaterialDialog.Builder builder = new MaterialDialog.Builder(this).title(R.string.search_title).alwaysCallInputCallback().input(getString(R.string.search_msg), "", new MaterialDialog.InputCallback() {
@Override
public void onInput(MaterialDialog materialDialog, CharSequence charSequence) {
term = charSequence.toString();
}
});
// Add "search current sub" if it is not frontpage/all/random
if (!subreddit.equalsIgnoreCase("frontpage") && !subreddit.equalsIgnoreCase("all") && !subreddit.contains(".") && !subreddit.contains("/m/") && !subreddit.equalsIgnoreCase("friends") && !subreddit.equalsIgnoreCase("random") && !subreddit.equalsIgnoreCase("popular") && !subreddit.equalsIgnoreCase("myrandom") && !subreddit.equalsIgnoreCase("randnsfw")) {
builder.positiveText(getString(R.string.search_subreddit, subreddit)).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
Intent i = new Intent(MainActivity.this, Search.class);
i.putExtra(Search.EXTRA_TERM, term);
i.putExtra(Search.EXTRA_SUBREDDIT, subreddit);
Log.v(LogUtil.getTag(), "INTENT SHOWS " + term + " AND " + subreddit);
startActivity(i);
}
});
builder.neutralText(R.string.search_all).onNeutral(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
Intent i = new Intent(MainActivity.this, Search.class);
i.putExtra(Search.EXTRA_TERM, term);
startActivity(i);
}
});
} else {
builder.positiveText(R.string.search_all).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
Intent i = new Intent(MainActivity.this, Search.class);
i.putExtra(Search.EXTRA_TERM, term);
startActivity(i);
}
});
}
builder.show();
return true;
case R.id.save:
saveOffline(((SubmissionsView) adapter.getCurrentFragment()).posts.posts, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
return true;
case R.id.hide_posts:
((SubmissionsView) adapter.getCurrentFragment()).clearSeenPosts(false);
return true;
case R.id.share:
Reddit.defaultShareText("Slide for Reddit", "https://play.google.com/store/apps/details?id=me.ccrama.redditslide", MainActivity.this);
return true;
case R.id.submit:
{
Intent i = new Intent(MainActivity.this, Submit.class);
i.putExtra(Submit.EXTRA_SUBREDDIT, subreddit);
startActivity(i);
}
return true;
case R.id.gallery:
if (SettingValues.tabletUI) {
List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
if (posts != null && !posts.isEmpty()) {
Intent i2 = new Intent(this, Gallery.class);
i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
i2.putExtra(Gallery.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
startActivity(i2);
}
} else {
AlertDialogWrapper.Builder b = new AlertDialogWrapper.Builder(this).setTitle(R.string.general_gallerymode_ispro).setMessage(R.string.pro_upgrade_msg).setPositiveButton(R.string.btn_yes_exclaim, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=me.ccrama.slideforreddittabletuiunlock")));
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=me.ccrama.slideforreddittabletuiunlock")));
}
}
}).setNegativeButton(R.string.btn_no_danks, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
});
if (SettingValues.previews > 0) {
b.setNeutralButton(getString(R.string.pro_previews, SettingValues.previews), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SettingValues.prefs.edit().putInt(SettingValues.PREVIEWS_LEFT, SettingValues.previews - 1).apply();
SettingValues.previews = SettingValues.prefs.getInt(SettingValues.PREVIEWS_LEFT, 10);
List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
if (posts != null && !posts.isEmpty()) {
Intent i2 = new Intent(MainActivity.this, Gallery.class);
i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
i2.putExtra(Gallery.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
startActivity(i2);
}
}
});
}
b.show();
}
return true;
case R.id.action_shadowbox:
if (SettingValues.tabletUI) {
List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
if (posts != null && !posts.isEmpty()) {
Intent i2 = new Intent(this, Shadowbox.class);
i2.putExtra(Shadowbox.EXTRA_PAGE, getCurrentPage());
i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
i2.putExtra(Shadowbox.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
startActivity(i2);
}
} else {
AlertDialogWrapper.Builder b = new AlertDialogWrapper.Builder(this).setTitle(R.string.general_shadowbox_ispro).setMessage(R.string.pro_upgrade_msg).setPositiveButton(R.string.btn_yes_exclaim, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=me.ccrama.slideforreddittabletuiunlock")));
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=me.ccrama.slideforreddittabletuiunlock")));
}
}
}).setNegativeButton(R.string.btn_no_danks, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
});
if (SettingValues.previews > 0) {
b.setNeutralButton("Preview (" + SettingValues.previews + ")", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SettingValues.prefs.edit().putInt(SettingValues.PREVIEWS_LEFT, SettingValues.previews - 1).apply();
SettingValues.previews = SettingValues.prefs.getInt(SettingValues.PREVIEWS_LEFT, 10);
List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
if (posts != null && !posts.isEmpty()) {
Intent i2 = new Intent(MainActivity.this, Shadowbox.class);
i2.putExtra(Shadowbox.EXTRA_PAGE, getCurrentPage());
i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
i2.putExtra(Shadowbox.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
startActivity(i2);
}
}
});
}
b.show();
}
return true;
default:
return false;
}
}
use of me.ccrama.redditslide.Fragments.SubmissionsView in project Slide by ccrama.
the class MainActivity method doPageSelectedComments.
public void doPageSelectedComments(int position) {
pager.setSwipeLeftOnly(false);
header.animate().translationY(0).setInterpolator(new LinearInterpolator()).setDuration(180);
Reddit.currentPosition = position;
if (position + 1 != currentComment) {
doSubSidebarNoLoad(usedArray.get(position));
}
SubmissionsView page = (SubmissionsView) adapter.getCurrentFragment();
if (page != null && page.adapter != null) {
SubredditPosts p = page.adapter.dataSet;
if (p.offline && p.cached != null) {
Toast.makeText(MainActivity.this, getString(R.string.offline_last_update, TimeUtils.getTimeAgo(p.cached.time, MainActivity.this)), Toast.LENGTH_LONG).show();
}
}
if (hea != null) {
hea.setBackgroundColor(Palette.getColor(usedArray.get(position)));
if (accountsArea != null) {
accountsArea.setBackgroundColor(Palette.getDarkerColor(usedArray.get(position)));
}
}
header.setBackgroundColor(Palette.getColor(usedArray.get(position)));
themeSystemBars(usedArray.get(position));
setRecentBar(usedArray.get(position));
if (SettingValues.single) {
getSupportActionBar().setTitle(usedArray.get(position));
} else {
if (mTabLayout != null) {
mTabLayout.setSelectedTabIndicatorColor(new ColorPreferences(MainActivity.this).getColor(usedArray.get(position)));
}
}
selectedSub = usedArray.get(position);
}
Aggregations