aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-07-02 05:12:36 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-07-02 05:12:36 +0000
commit3a72c5a1f8f37010459794a4c6e80e0141030907 (patch)
tree981c5247fccd7e2b9275b7654a03668277211db8 /app/src/main
parent1958ad77e3c7c4c523caef15f90b0b32da1d0cb2 (diff)
downloadinfinity-for-reddit-3a72c5a1f8f37010459794a4c6e80e0141030907.tar
infinity-for-reddit-3a72c5a1f8f37010459794a4c6e80e0141030907.tar.gz
infinity-for-reddit-3a72c5a1f8f37010459794a4c6e80e0141030907.tar.bz2
infinity-for-reddit-3a72c5a1f8f37010459794a4c6e80e0141030907.tar.lz
infinity-for-reddit-3a72c5a1f8f37010459794a4c6e80e0141030907.tar.xz
infinity-for-reddit-3a72c5a1f8f37010459794a4c6e80e0141030907.tar.zst
infinity-for-reddit-3a72c5a1f8f37010459794a4c6e80e0141030907.zip
Open message tab in InboxActivity when opening a message notification.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/InboxActivity.java20
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MessageRecyclerViewAdapter.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FetchMessages.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/InboxFragment.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MessageDataSource.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParseMessage.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java3
7 files changed, 21 insertions, 18 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/InboxActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/InboxActivity.java
index 4a94d3ab..66072a2b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/InboxActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/InboxActivity.java
@@ -49,6 +49,7 @@ import retrofit2.Retrofit;
public class InboxActivity extends BaseActivity implements ActivityToolbarInterface {
public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN";
+ public static final String EXTRA_VIEW_MESSAGE = "EVM";
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
private static final String ACCESS_TOKEN_STATE = "ATS";
@@ -123,13 +124,13 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
if (!mNullAccessToken && mAccessToken == null) {
- getCurrentAccountAndFetchMessage();
+ getCurrentAccountAndFetchMessage(savedInstanceState);
} else {
- bindView();
+ bindView(savedInstanceState);
}
} else {
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
- getCurrentAccountAndFetchMessage();
+ getCurrentAccountAndFetchMessage(savedInstanceState);
}
}
@@ -150,7 +151,7 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
applyTabLayoutTheme(tabLayout);
}
- private void getCurrentAccountAndFetchMessage() {
+ private void getCurrentAccountAndFetchMessage(Bundle savedInstanceState) {
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
if (mNewAccountName != null) {
if (account == null || !account.getUsername().equals(mNewAccountName)) {
@@ -165,11 +166,11 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
mAccessToken = newAccount.getAccessToken();
}
- bindView();
+ bindView(savedInstanceState);
}).execute();
} else {
mAccessToken = account.getAccessToken();
- bindView();
+ bindView(savedInstanceState);
}
} else {
if (account == null) {
@@ -178,12 +179,12 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
mAccessToken = account.getAccessToken();
}
- bindView();
+ bindView(savedInstanceState);
}
}).execute();
}
- private void bindView() {
+ private void bindView(Bundle savedInstanceState) {
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
@@ -198,6 +199,9 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
viewPager.setAdapter(sectionsPagerAdapter);
viewPager.setOffscreenPageLimit(2);
tabLayout.setupWithViewPager(viewPager);
+ if (savedInstanceState == null && getIntent().getBooleanExtra(EXTRA_VIEW_MESSAGE, false)) {
+ viewPager.setCurrentItem(1);
+ }
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MessageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MessageRecyclerViewAdapter.java
index bd9e5ed1..f450700b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MessageRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MessageRecyclerViewAdapter.java
@@ -106,10 +106,8 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl
mAccessToken = accessToken;
if (where.equals(FetchMessages.WHERE_MESSAGES)) {
mMessageType = FetchMessages.MESSAGE_TYPE_PRIVATE_MESSAGE;
- } else if (where.equals(FetchMessages.WHERE_MESSAGES_DETAIL)) {
- mMessageType = FetchMessages.MESSAGE_TYPE_PRIVATE_MESSAGE_DETAIL;
} else {
- mMessageType = FetchMessages.MESSAGE_TYPE_NOTIFICATION;
+ mMessageType = FetchMessages.MESSAGE_TYPE_INBOX;
}
mColorAccent = customThemeWrapper.getColorAccent();
@@ -163,7 +161,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl
mMarkwon.setMarkdown(((DataViewHolder) holder).contentCustomMarkwonView, displayedMessage.getBody());
((DataViewHolder) holder).itemView.setOnClickListener(view -> {
- if (mMessageType == FetchMessages.MESSAGE_TYPE_NOTIFICATION
+ if (mMessageType == FetchMessages.MESSAGE_TYPE_INBOX
&& message.getContext() != null && !message.getContext().equals("")) {
Uri uri = LinkResolverActivity.getRedditUriByPath(message.getContext());
Intent intent = new Intent(mContext, LinkResolverActivity.class);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchMessages.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchMessages.java
index 8d929a15..a1a6552c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchMessages.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchMessages.java
@@ -21,9 +21,9 @@ public class FetchMessages {
public static final String WHERE_COMMENTS = "comments";
public static final String WHERE_MESSAGES = "messages";
public static final String WHERE_MESSAGES_DETAIL = "messages_detail";
- public static final int MESSAGE_TYPE_NOTIFICATION = 0;
+ public static final int MESSAGE_TYPE_INBOX = 0;
public static final int MESSAGE_TYPE_PRIVATE_MESSAGE = 1;
- public static final int MESSAGE_TYPE_PRIVATE_MESSAGE_DETAIL = 2;
+ public static final int MESSAGE_TYPE_NOTIFICATION = 2;
static void fetchInbox(Retrofit oauthRetrofit, Locale locale, String accessToken, String where,
String after, int messageType, FetchMessagesListener fetchMessagesListener) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/InboxFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/InboxFragment.java
index 1b7a12c9..9129bec2 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/InboxFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/InboxFragment.java
@@ -102,7 +102,7 @@ public class InboxFragment extends Fragment implements FragmentCommunicator {
mRecyclerView.setPadding(0, 0, 0, mActivity.getNavBarHeight());
}
- mWhere = arguments.getString(EXTRA_MESSAGE_WHERE);
+ mWhere = arguments.getString(EXTRA_MESSAGE_WHERE, FetchMessages.WHERE_INBOX);
mAdapter = new MessageRecyclerViewAdapter(mActivity, mOauthRetrofit, mCustomThemeWrapper,
mAccessToken, mWhere, () -> mMessageViewModel.retryLoadingMore());
mLinearLayoutManager = new LinearLayoutManager(mActivity);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MessageDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MessageDataSource.java
index 66fd7647..f81d1894 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MessageDataSource.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MessageDataSource.java
@@ -32,7 +32,7 @@ class MessageDataSource extends PageKeyedDataSource<String, Message> {
if (where.equals(FetchMessages.WHERE_MESSAGES)) {
messageType = FetchMessages.MESSAGE_TYPE_PRIVATE_MESSAGE;
} else {
- messageType = FetchMessages.MESSAGE_TYPE_NOTIFICATION;
+ messageType = FetchMessages.MESSAGE_TYPE_INBOX;
}
paginationNetworkStateLiveData = new MutableLiveData<>();
initialLoadStateLiveData = new MutableLiveData<>();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseMessage.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseMessage.java
index 5f704567..c605a5f3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseMessage.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseMessage.java
@@ -44,7 +44,7 @@ public class ParseMessage {
@Nullable
private static Message parseSingleMessage(JSONObject messageJSON, Locale locale, int messageType) throws JSONException {
String kind = messageJSON.getString(JSONUtils.KIND_KEY);
- if ((messageType == FetchMessages.MESSAGE_TYPE_NOTIFICATION && kind.equals("t4")) ||
+ if ((messageType == FetchMessages.MESSAGE_TYPE_INBOX && kind.equals("t4")) ||
(messageType == FetchMessages.MESSAGE_TYPE_PRIVATE_MESSAGE && !kind.equals("t4"))) {
return null;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java
index 67d7490e..52886ecb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java
@@ -98,7 +98,7 @@ public class PullNotificationWorker extends Worker {
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
- int messageSize = Math.min(messages.size(), 5);
+ int messageSize = Math.min(messages.size(), 20);
long lastNotificationTime = mSharedPreferences.getLong(SharedPreferencesUtils.PULL_NOTIFICATION_TIME, -1L);
boolean hasValidMessage = false;
@@ -164,6 +164,7 @@ public class PullNotificationWorker extends Worker {
} else if (kind.equals(Message.TYPE_MESSAGE)) {
Intent intent = new Intent(context, InboxActivity.class);
intent.putExtra(InboxActivity.EXTRA_NEW_ACCOUNT_NAME, accountName);
+ intent.putExtra(InboxActivity.EXTRA_VIEW_MESSAGE, true);
PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, accountIndex * 6 + 3, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(summaryPendingIntent);
} else if (kind.equals(Message.TYPE_SUBREDDIT)) {