Skip to content

Commit

Permalink
Fix "only show unread" option in inbox
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumBadger committed Jun 26, 2016
1 parent 29ed64e commit 59042de
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,14 @@ public final class InboxListingActivity extends BaseActivity {
private static final int OPTIONS_MENU_SHOW_UNREAD_ONLY = 1;

private GroupedRecyclerViewAdapter adapter;
private SharedPreferences.Editor editor;

private LoadingView loadingView;
private LinearLayout notifications;

private CacheRequest request;

private boolean isModmail = false;
private boolean onlyUnread;
private boolean mOnlyShowUnread;

private RRThemeAttributes mTheme;
private RedditChangeDataManagerVolatile mChangeDataManager;
Expand Down Expand Up @@ -145,15 +144,14 @@ public void onCreate(Bundle savedInstanceState) {
RedditAccountManager.getInstance(this).getDefaultAccount());

final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
editor = sharedPreferences.edit();

getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

final String title;

isModmail = getIntent() != null && getIntent().getBooleanExtra("modmail", false);
onlyUnread = sharedPreferences.getBoolean("onlyUnread", false);
mOnlyShowUnread = sharedPreferences.getBoolean("onlyUnread", false);

if(!isModmail) {
title = getString(R.string.mainmenu_inbox);
Expand Down Expand Up @@ -204,7 +202,7 @@ private void makeFirstRequest(final Context context) {
final URI url;

if(!isModmail) {
if(onlyUnread) {
if(mOnlyShowUnread) {
url = Constants.Reddit.getUri("/message/unread.json?mark=true&limit=100");
}else{
url = Constants.Reddit.getUri("/message/inbox.json?mark=true&limit=100");
Expand Down Expand Up @@ -343,7 +341,7 @@ public boolean onCreateOptionsMenu(final Menu menu) {
menu.add(0, OPTIONS_MENU_MARK_ALL_AS_READ, 0, R.string.mark_all_as_read);
menu.add(0, OPTIONS_MENU_SHOW_UNREAD_ONLY, 1, "Unread Messages Only");
menu.getItem(1).setCheckable(true);
if(onlyUnread){
if(mOnlyShowUnread){
menu.getItem(1).setChecked(true);
}
return super.onCreateOptionsMenu(menu);
Expand Down Expand Up @@ -394,19 +392,24 @@ public void run() {
this);

return true;
case OPTIONS_MENU_SHOW_UNREAD_ONLY:
if (!item.isChecked()) {
item.setChecked(true);
editor.putBoolean("onlyUnread", true);
onlyUnread = true;
} else {
item.setChecked(false);
editor.putBoolean("onlyUnread", false);
onlyUnread = false;
}
editor.apply();
makeFirstRequest(this);

case OPTIONS_MENU_SHOW_UNREAD_ONLY: {

final boolean enabled = !item.isChecked();

item.setChecked(enabled);
mOnlyShowUnread = enabled;

PreferenceManager
.getDefaultSharedPreferences(this)
.edit()
.putBoolean("onlyUnread", enabled)
.apply();

General.recreateActivityNoAnimation(this);
return true;
}

case android.R.id.home:
finish();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

package org.quantumbadger.redreader.activities;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import org.quantumbadger.redreader.R;
import org.quantumbadger.redreader.common.General;
import org.quantumbadger.redreader.common.PrefsUtility;

import java.util.EnumSet;
Expand Down Expand Up @@ -82,14 +82,7 @@ protected void onResume() {
protected void doRefreshNow(RefreshableFragment which, boolean force) {

if(which == RefreshableFragment.RESTART) {

// http://stackoverflow.com/a/3419987/1526861
final Intent intent = getIntent();
overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
overridePendingTransition(0, 0);
startActivity(intent);
General.recreateActivityNoAnimation(this);

} else {
doRefresh(which, force, null);
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/org/quantumbadger/redreader/common/General.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Typeface;
Expand All @@ -36,7 +37,6 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import org.quantumbadger.redreader.R;
import org.quantumbadger.redreader.activities.BugReportActivity;
import org.quantumbadger.redreader.cache.CacheRequest;
Expand Down Expand Up @@ -501,4 +501,15 @@ public static void setAllMarginsDp(final Context context, final View view, final
layoutParams.topMargin = marginPx;
layoutParams.bottomMargin = marginPx;
}

public static void recreateActivityNoAnimation(final AppCompatActivity activity) {

// http://stackoverflow.com/a/3419987/1526861
final Intent intent = activity.getIntent();
activity.overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
activity.finish();
activity.overridePendingTransition(0, 0);
activity.startActivity(intent);
}
}

0 comments on commit 59042de

Please sign in to comment.