use of me.ccrama.redditslide.Fragments.MultiredditView in project Slide by ccrama.
the class MultiredditOverview method openPopupTime.
public void openPopupTime() {
PopupMenu popup = new PopupMenu(MultiredditOverview.this, findViewById(R.id.anchor), Gravity.RIGHT);
String id = ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH);
final Spannable[] base = Reddit.getSortingSpannablesTime(getBaseContext(), "multi" + id);
for (Spannable s : base) {
MenuItem m = popup.getMenu().add(s);
}
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
int i = 0;
for (Spannable s : base) {
if (s.equals(item.getTitle())) {
break;
}
i++;
}
LogUtil.v("Chosen is " + i);
if (pager.getAdapter() != null) {
switch(i) {
case 0:
Reddit.setTime("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), TimePeriod.HOUR);
reloadSubs();
break;
case 1:
Reddit.setTime("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), TimePeriod.DAY);
reloadSubs();
break;
case 2:
Reddit.setTime("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), TimePeriod.WEEK);
reloadSubs();
break;
case 3:
Reddit.setTime("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), TimePeriod.MONTH);
reloadSubs();
break;
case 4:
Reddit.setTime("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), TimePeriod.YEAR);
reloadSubs();
break;
case 5:
Reddit.setTime("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), TimePeriod.ALL);
reloadSubs();
break;
}
}
return true;
}
});
popup.show();
}
use of me.ccrama.redditslide.Fragments.MultiredditView in project Slide by ccrama.
the class MultiredditOverview method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case android.R.id.home:
try {
onBackPressed();
} catch (Exception ignored) {
}
return true;
case R.id.action_edit:
{
if (profile.isEmpty() && (UserSubscriptions.multireddits != null) && !UserSubscriptions.multireddits.isEmpty()) {
Intent i = new Intent(MultiredditOverview.this, CreateMulti.class);
i.putExtra(CreateMulti.EXTRA_MULTI, UserSubscriptions.multireddits.get(pager.getCurrentItem()).getDisplayName());
startActivity(i);
}
}
return true;
case R.id.search:
{
UserSubscriptions.MultiCallback m = new UserSubscriptions.MultiCallback() {
@Override
public void onComplete(List<MultiReddit> multireddits) {
if ((multireddits != null) && !multireddits.isEmpty()) {
searchMulti = multireddits.get(pager.getCurrentItem());
MaterialDialog.Builder builder = new MaterialDialog.Builder(MultiredditOverview.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
builder.positiveText(getString(R.string.search_subreddit, "/m/" + searchMulti.getDisplayName())).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
Intent i = new Intent(MultiredditOverview.this, Search.class);
i.putExtra(Search.EXTRA_TERM, term);
i.putExtra(Search.EXTRA_MULTIREDDIT, searchMulti.getDisplayName());
startActivity(i);
}
});
builder.show();
}
}
};
if (profile.isEmpty()) {
UserSubscriptions.getMultireddits(m);
} else {
UserSubscriptions.getPublicMultireddits(m, profile);
}
}
return true;
case R.id.create:
if (profile.isEmpty()) {
Intent i2 = new Intent(MultiredditOverview.this, CreateMulti.class);
startActivity(i2);
}
return true;
case R.id.action_sort:
openPopup();
return true;
case R.id.subs:
((DrawerLayout) findViewById(R.id.drawer_layout)).openDrawer(Gravity.RIGHT);
return true;
case R.id.gallery:
if (SettingValues.tabletUI) {
List<Submission> posts = ((MultiredditView) adapter.getCurrentFragment()).posts.posts;
if (posts != null && !posts.isEmpty()) {
Intent i2 = new Intent(this, Gallery.class);
i2.putExtra(Gallery.EXTRA_PROFILE, profile);
i2.putExtra(Gallery.EXTRA_MULTIREDDIT, ((MultiredditView) adapter.getCurrentFragment()).posts.multiReddit.getDisplayName());
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 = ((MultiredditView) adapter.getCurrentFragment()).posts.posts;
if (posts != null && !posts.isEmpty()) {
Intent i2 = new Intent(MultiredditOverview.this, Gallery.class);
i2.putExtra(Gallery.EXTRA_PROFILE, profile);
i2.putExtra(Gallery.EXTRA_MULTIREDDIT, ((MultiredditView) adapter.getCurrentFragment()).posts.multiReddit.getDisplayName());
startActivity(i2);
}
}
});
}
b.show();
}
return true;
case R.id.action_shadowbox:
if (SettingValues.tabletUI) {
List<Submission> posts = ((MultiredditView) adapter.getCurrentFragment()).posts.posts;
if (posts != null && !posts.isEmpty()) {
Intent i = new Intent(this, Shadowbox.class);
i.putExtra(Shadowbox.EXTRA_PAGE, getCurrentPage());
i.putExtra(Shadowbox.EXTRA_PROFILE, profile);
i.putExtra(Shadowbox.EXTRA_MULTIREDDIT, ((MultiredditView) adapter.getCurrentFragment()).posts.multiReddit.getDisplayName());
startActivity(i);
}
} 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 && adapter != null && ((MultiredditView) adapter.getCurrentFragment()).posts != null && ((MultiredditView) adapter.getCurrentFragment()).posts.posts != null && !((MultiredditView) adapter.getCurrentFragment()).posts.posts.isEmpty()) {
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 = ((MultiredditView) adapter.getCurrentFragment()).posts.posts;
if (posts != null && !posts.isEmpty()) {
Intent i = new Intent(MultiredditOverview.this, Shadowbox.class);
i.putExtra(Shadowbox.EXTRA_PAGE, getCurrentPage());
i.putExtra(Shadowbox.EXTRA_PROFILE, profile);
i.putExtra(Shadowbox.EXTRA_MULTIREDDIT, ((MultiredditView) adapter.getCurrentFragment()).posts.multiReddit.getDisplayName());
startActivity(i);
}
}
});
}
b.show();
}
return true;
default:
return false;
}
}
use of me.ccrama.redditslide.Fragments.MultiredditView in project Slide by ccrama.
the class MultiredditOverview method openPopup.
public void openPopup() {
PopupMenu popup = new PopupMenu(MultiredditOverview.this, findViewById(R.id.anchor), Gravity.RIGHT);
String id = ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH);
final Spannable[] base = Reddit.getSortingSpannables(getBaseContext(), "multi" + id);
for (Spannable s : base) {
MenuItem m = popup.getMenu().add(s);
}
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
int i = 0;
for (Spannable s : base) {
if (s.equals(item.getTitle())) {
break;
}
i++;
}
LogUtil.v("Chosen is " + i);
if (pager.getAdapter() != null) {
switch(i) {
case 0:
Reddit.setSorting("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), Sorting.HOT);
reloadSubs();
break;
case 1:
Reddit.setSorting("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), Sorting.NEW);
reloadSubs();
break;
case 2:
Reddit.setSorting("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), Sorting.RISING);
reloadSubs();
break;
case 3:
Reddit.setSorting("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), Sorting.TOP);
openPopupTime();
break;
case 4:
Reddit.setSorting("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), Sorting.CONTROVERSIAL);
openPopupTime();
break;
}
}
return true;
}
});
popup.show();
}
use of me.ccrama.redditslide.Fragments.MultiredditView in project Slide by ccrama.
the class MultiredditOverview method setDataSet.
private void setDataSet(List<MultiReddit> data) {
try {
usedArray = data;
if (usedArray.isEmpty()) {
buildDialog();
} else {
if (adapter == null) {
adapter = new OverviewPagerAdapter(getSupportFragmentManager());
} else {
adapter.notifyDataSetChanged();
}
pager.setAdapter(adapter);
pager.setOffscreenPageLimit(1);
tabs.setupWithViewPager(pager);
tabs.setSelectedTabIndicatorColor(new ColorPreferences(MultiredditOverview.this).getColor(usedArray.get(0).getDisplayName()));
doDrawerSubs(0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = this.getWindow();
window.setStatusBarColor(Palette.getDarkerColor(usedArray.get(0).getDisplayName()));
}
final View header = findViewById(R.id.header);
tabs.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(pager) {
@Override
public void onTabReselected(TabLayout.Tab tab) {
super.onTabReselected(tab);
int[] firstVisibleItems;
int pastVisiblesItems = 0;
firstVisibleItems = ((CatchStaggeredGridLayoutManager) (((MultiredditView) adapter.getCurrentFragment()).rv.getLayoutManager())).findFirstVisibleItemPositions(null);
if (firstVisibleItems != null && firstVisibleItems.length > 0) {
for (int firstVisibleItem : firstVisibleItems) {
pastVisiblesItems = firstVisibleItem;
}
}
if (pastVisiblesItems > 8) {
((MultiredditView) adapter.getCurrentFragment()).rv.scrollToPosition(0);
if (header != null) {
header.animate().translationY(header.getHeight()).setInterpolator(new LinearInterpolator()).setDuration(0);
}
} else {
((MultiredditView) adapter.getCurrentFragment()).rv.smoothScrollToPosition(0);
}
}
});
findViewById(R.id.header).setBackgroundColor(Palette.getColor(usedArray.get(0).getDisplayName()));
}
} catch (NullPointerException e) {
buildDialog(true);
Log.e(LogUtil.getTag(), "Cannot load multis:\n" + e);
}
}
Aggregations