aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/LinkResolverActivity.java16
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java24
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java46
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java30
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java21
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java21
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java21
7 files changed, 135 insertions, 44 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/LinkResolverActivity.java
index b095d3c0..c0561963 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/LinkResolverActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/LinkResolverActivity.java
@@ -17,8 +17,7 @@ import static androidx.browser.customtabs.CustomTabsService.ACTION_CUSTOM_TABS_C
public class LinkResolverActivity extends AppCompatActivity {
- static final String EXTRA_NOTIFICATION_FULLNAME = "ENF";
- static final String EXTRA_SWITCH_ACCOUNT = "ESA";
+ static final String EXTRA_MESSAGE_FULLNAME = "ENF";
static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN";
private static final String POST_PATTERN = "/r/\\w+/comments/\\w+/{0,1}\\w+/{0,1}";
@@ -36,8 +35,7 @@ public class LinkResolverActivity extends AppCompatActivity {
path = path.substring(0, path.length() - 1);
}
- String notificationFullname = getIntent().getStringExtra(EXTRA_NOTIFICATION_FULLNAME);
- boolean switchAccount = getIntent().getBooleanExtra(EXTRA_SWITCH_ACCOUNT, false);
+ String messageFullname = getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME);
String newAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
if(path.matches(POST_PATTERN)) {
@@ -46,7 +44,7 @@ public class LinkResolverActivity extends AppCompatActivity {
if(commentsIndex >=0 && commentsIndex < segments.size() - 1) {
Intent intent = new Intent(this, ViewPostDetailActivity.class);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1));
- intent.putExtra(ViewPostDetailActivity.EXTRA_NOTIFICATION_FULLNAME, notificationFullname);
+ intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
startActivity(intent);
} else {
@@ -59,7 +57,7 @@ public class LinkResolverActivity extends AppCompatActivity {
Intent intent = new Intent(this, ViewPostDetailActivity.class);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1));
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, segments.get(segments.size() - 1));
- intent.putExtra(ViewPostDetailActivity.EXTRA_NOTIFICATION_FULLNAME, notificationFullname);
+ intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
startActivity(intent);
} else {
@@ -70,20 +68,20 @@ public class LinkResolverActivity extends AppCompatActivity {
if(subredditName.equals("popular") || subredditName.equals("all")) {
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra(MainActivity.EXTRA_POST_TYPE, subredditName);
- intent.putExtra(MainActivity.EXTRA_NOTIFICATION_FULLNAME, notificationFullname);
+ intent.putExtra(MainActivity.EXTRA_MESSSAGE_FULLNAME, messageFullname);
intent.putExtra(MainActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
startActivity(intent);
} else {
Intent intent = new Intent(this, ViewSubredditDetailActivity.class);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, path.substring(3));
- intent.putExtra(ViewSubredditDetailActivity.EXTRA_NOTIFICATION_FULLNAME, notificationFullname);
+ intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
startActivity(intent);
}
} else if(path.matches(USER_PATTERN)) {
Intent intent = new Intent(this, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, path.substring(6));
- intent.putExtra(ViewUserDetailActivity.EXTRA_NOTIFICATION_FULLNAME, notificationFullname);
+ intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
startActivity(intent);
} else {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
index eb665671..66899f0e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
@@ -61,7 +61,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
PostTypeBottomSheetFragment.PostTypeSelectionCallback {
static final String EXTRA_POST_TYPE = "EPT";
- static final String EXTRA_NOTIFICATION_FULLNAME = "ENF";
+ static final String EXTRA_MESSSAGE_FULLNAME = "ENF";
static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN";
private static final String FETCH_USER_INFO_STATE = "FUIS";
@@ -73,6 +73,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
private static final String ACCOUNT_PROFILE_IMAGE_URL_STATE = "APIUS";
private static final String ACCOUNT_BANNER_IMAGE_URL_STATE = "ABIUS";
private static final String ACCOUNT_KARMA_STATE = "AKS";
+ private static final String MESSAGE_FULLNAME_STATE = "MFS";
private static final String NEW_ACCOUNT_NAME_STATE = "NANS";
private static final int LOGIN_ACTIVITY_REQUEST_CODE = 0;
@@ -120,6 +121,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
private int mKarma;
private boolean mFetchUserInfoSuccess = false;
private boolean mDrawerOnAccountSwitch = false;
+ private String mMessageFullname;
private String mNewAccountName;
private Menu mMenu;
@@ -221,6 +223,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
mProfileImageUrl = savedInstanceState.getString(ACCOUNT_PROFILE_IMAGE_URL_STATE);
mBannerImageUrl = savedInstanceState.getString(ACCOUNT_BANNER_IMAGE_URL_STATE);
mKarma = savedInstanceState.getInt(ACCOUNT_KARMA_STATE);
+ mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE);
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
if(!mNullAccessToken && mAccessToken == null) {
@@ -229,6 +232,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
bindView();
}
} else {
+ mMessageFullname = getIntent().getStringExtra(EXTRA_MESSSAGE_FULLNAME);
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
getCurrentAccountAndBindView();
}
@@ -260,7 +264,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
.build();
WorkManager.getInstance(this).enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
- ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest);
+ ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
}
bindView();
}).execute();
@@ -286,7 +290,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
.build();
WorkManager.getInstance(this).enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
- ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
+ ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest);
}
bindView();
}).execute();
@@ -416,6 +420,19 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
if(mAccessToken != null) {
mKarmaTextView.setText(getString(R.string.karma_info, mKarma));
mAccountNameTextView.setText(mAccountName);
+ if(mMessageFullname != null) {
+ ReadMessage.readMessage(mOauthRetrofit, mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() {
+ @Override
+ public void readSuccess() {
+ mMessageFullname = null;
+ }
+
+ @Override
+ public void readFailed() {
+
+ }
+ });
+ }
} else {
mKarmaTextView.setText(R.string.press_here_to_login);
mAccountNameTextView.setText(R.string.anonymous_account);
@@ -645,6 +662,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
outState.putString(ACCOUNT_PROFILE_IMAGE_URL_STATE, mProfileImageUrl);
outState.putString(ACCOUNT_BANNER_IMAGE_URL_STATE, mBannerImageUrl);
outState.putInt(ACCOUNT_KARMA_STATE, mKarma);
+ outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname);
outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java
index 13bf43b5..5e306572 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java
@@ -60,7 +60,9 @@ public class PullNotificationWorker extends Worker {
List<Account> accounts = redditDataRoomDatabase.accountDao().getAllAccounts();
for(int accountIndex = 0; accountIndex < accounts.size(); accountIndex++) {
Account account = accounts.get(accountIndex);
- Log.i("workmanager", account.getUsername() + " " + account.getAccessToken());
+ String accountName = account.getUsername();
+
+ Log.i("workmanager", accountName + " " + account.getAccessToken());
Response<String> response = fetchMessages(account);
@@ -73,10 +75,10 @@ public class PullNotificationWorker extends Worker {
NotificationManagerCompat notificationManager = NotificationUtils.getNotificationManager(context);
NotificationCompat.Builder summaryBuilder = NotificationUtils.buildSummaryNotification(context,
- notificationManager, account.getUsername(),
+ notificationManager, accountName,
context.getString(R.string.notification_new_messages, messages.size()),
NotificationUtils.CHANNEL_ID_NEW_COMMENTS, NotificationUtils.CHANNEL_NEW_COMMENTS,
- NotificationUtils.getAccountGroupName(account.getUsername()));
+ NotificationUtils.getAccountGroupName(accountName));
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
@@ -88,7 +90,6 @@ public class PullNotificationWorker extends Worker {
inboxStyle.addLine(message.getAuthor() + " " + message.getBody());
String kind = message.getKind();
- Log.i("workmanager", kind);
String title;
String summary;
if(kind.equals(Message.TYPE_COMMENT) || kind.equals(Message.TYPE_LINK)) {
@@ -111,55 +112,54 @@ public class PullNotificationWorker extends Worker {
context, title, message.getBody(), summary,
NotificationUtils.CHANNEL_ID_NEW_COMMENTS,
NotificationUtils.CHANNEL_NEW_COMMENTS,
- NotificationUtils.getAccountGroupName(account.getUsername()));
+ NotificationUtils.getAccountGroupName(accountName));
if(kind.equals(Message.TYPE_COMMENT)) {
Intent intent = new Intent(context, LinkResolverActivity.class);
Uri uri = LinkResolverActivity.getRedditUriByPath(message.getContext());
intent.setData(uri);
- if(!account.getUsername().equals(currentAccountName)) {
- intent.putExtra(LinkResolverActivity.EXTRA_SWITCH_ACCOUNT, true);
- intent.putExtra(LinkResolverActivity.EXTRA_NEW_ACCOUNT_NAME, account.getUsername());
- }
- PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
+ intent.putExtra(LinkResolverActivity.EXTRA_NEW_ACCOUNT_NAME, accountName);
+ PendingIntent pendingIntent = PendingIntent.getActivity(context, accountIndex * 6, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
} else if(kind.equals(Message.TYPE_ACCOUNT)) {
Intent intent = new Intent(context, ViewMessageActivity.class);
- PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
+ intent.putExtra(ViewMessageActivity.EXTRA_NEW_ACCOUNT_NAME, accountName);
+ PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, accountIndex * 6 + 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(summaryPendingIntent);
} else if(kind.equals(Message.TYPE_LINK)) {
Intent intent = new Intent(context, LinkResolverActivity.class);
Uri uri = LinkResolverActivity.getRedditUriByPath(message.getContext());
intent.setData(uri);
- if(!account.getUsername().equals(currentAccountName)) {
- intent.putExtra(LinkResolverActivity.EXTRA_SWITCH_ACCOUNT, true);
- intent.putExtra(LinkResolverActivity.EXTRA_NEW_ACCOUNT_NAME, account.getUsername());
- }
- PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
+ intent.putExtra(LinkResolverActivity.EXTRA_NEW_ACCOUNT_NAME, accountName);
+ PendingIntent pendingIntent = PendingIntent.getActivity(context, accountIndex * 6 + 2, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
} else if(kind.equals(Message.TYPE_MESSAGE)) {
Intent intent = new Intent(context, ViewMessageActivity.class);
- PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
+ intent.putExtra(ViewMessageActivity.EXTRA_NEW_ACCOUNT_NAME, accountName);
+ PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, accountIndex * 6 + 3, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(summaryPendingIntent);
} else if(kind.equals(Message.TYPE_SUBREDDIT)) {
Intent intent = new Intent(context, ViewMessageActivity.class);
- PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
+ intent.putExtra(ViewMessageActivity.EXTRA_NEW_ACCOUNT_NAME, accountName);
+ PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, accountIndex * 6 + 4, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(summaryPendingIntent);
} else {
Intent intent = new Intent(context, ViewMessageActivity.class);
- PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
+ intent.putExtra(ViewMessageActivity.EXTRA_NEW_ACCOUNT_NAME, accountName);
+ PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, accountIndex * 6 + 5, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(summaryPendingIntent);
}
notificationManager.notify(NotificationUtils.getNotificationIdUnreadMessage(accountIndex, messageIndex), builder.build());
}
inboxStyle.setBigContentTitle(context.getString(R.string.notification_new_messages, messages.size()))
- .setSummaryText(account.getUsername());
+ .setSummaryText(accountName);
summaryBuilder.setStyle(inboxStyle);
Intent summaryIntent = new Intent(context, ViewMessageActivity.class);
- PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, 0, summaryIntent, 0);
+ summaryIntent.putExtra(ViewMessageActivity.EXTRA_NEW_ACCOUNT_NAME, accountName);
+ PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, accountIndex * 6 + 6, summaryIntent, PendingIntent.FLAG_UPDATE_CURRENT);
summaryBuilder.setContentIntent(summaryPendingIntent);
notificationManager.notify(NotificationUtils.getSummaryIdUnreadMessage(accountIndex), summaryBuilder.build());
@@ -170,7 +170,9 @@ public class PullNotificationWorker extends Worker {
return Result.retry();
}
} else {
- Log.i("workmanager", "retry2 " + response.code());
+ if(response != null) {
+ Log.i("workmanager", "retry2 " + response.code());
+ }
return Result.retry();
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java
index 3f6d5960..2ea81af6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java
@@ -31,15 +31,17 @@ import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
import javax.inject.Inject;
import javax.inject.Named;
-import Account.Account;
import butterknife.BindView;
import butterknife.ButterKnife;
import retrofit2.Retrofit;
public class ViewMessageActivity extends AppCompatActivity {
+ static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN";
+
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
private static final String ACCESS_TOKEN_STATE = "ATS";
+ private static final String NEW_ACCOUNT_NAME_STATE = "NANS";
@BindView(R.id.collapsing_toolbar_layout_view_message_activity) CollapsingToolbarLayout collapsingToolbarLayout;
@BindView(R.id.appbar_layout_view_message_activity) AppBarLayout appBarLayout;
@@ -52,6 +54,7 @@ public class ViewMessageActivity extends AppCompatActivity {
private boolean mNullAccessToken = false;
private String mAccessToken;
+ private String mNewAccountName;
private MessageRecyclerViewAdapter mAdapter;
@@ -129,6 +132,7 @@ public class ViewMessageActivity extends AppCompatActivity {
if(savedInstanceState != null) {
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
+ mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
if(!mNullAccessToken && mAccessToken == null) {
getCurrentAccountAndFetchMessage();
@@ -136,14 +140,27 @@ public class ViewMessageActivity extends AppCompatActivity {
bindView();
}
} else {
+ mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
getCurrentAccountAndFetchMessage();
}
}
private void getCurrentAccountAndFetchMessage() {
- new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), new GetCurrentAccountAsyncTask.GetCurrentAccountAsyncTaskListener() {
- @Override
- public void success(Account account) {
+ if(mNewAccountName != null) {
+ new SwitchAccountAsyncTask(mRedditDataRoomDatabase, mNewAccountName, () -> {
+ mNewAccountName = null;
+ new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
+ if(account == null) {
+ mNullAccessToken = true;
+ } else {
+ mAccessToken = account.getAccessToken();
+
+ bindView();
+ }
+ }).execute();
+ }).execute();
+ } else {
+ new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
if(account == null) {
mNullAccessToken = true;
} else {
@@ -151,8 +168,8 @@ public class ViewMessageActivity extends AppCompatActivity {
bindView();
}
- }
- }).execute();
+ }).execute();
+ }
}
private void bindView() {
@@ -226,5 +243,6 @@ public class ViewMessageActivity extends AppCompatActivity {
super.onSaveInstanceState(outState);
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
+ outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName);
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
index c48f2697..ba5ef9a8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
@@ -60,7 +60,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
static final String EXTRA_POST_LIST_POSITION = "EPLI";
static final String EXTRA_POST_ID = "EPI";
static final String EXTRA_SINGLE_COMMENT_ID = "ESCI";
- static final String EXTRA_NOTIFICATION_FULLNAME = "ENI";
+ static final String EXTRA_MESSAGE_FULLNAME = "ENI";
static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN";
private static final int EDIT_POST_REQUEST_CODE = 2;
@@ -99,6 +99,8 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
@State
boolean hasMoreChildren;
@State
+ String mMessageFullname;
+ @State
String mNewAccountName;
private boolean showToast = false;
@@ -198,6 +200,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
if(mSingleCommentId != null) {
isSingleCommentThreadMode = true;
}
+ mMessageFullname = getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME);
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
}
@@ -210,7 +213,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
}
if(getIntent().hasExtra(EXTRA_POST_LIST_POSITION)) {
- postListPosition = getIntent().getExtras().getInt(EXTRA_POST_LIST_POSITION);
+ postListPosition = getIntent().getIntExtra(EXTRA_POST_LIST_POSITION, -1);
}
}
@@ -244,6 +247,20 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
}
private void bindView() {
+ if(mAccessToken != null && mMessageFullname != null) {
+ ReadMessage.readMessage(mOauthRetrofit, mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() {
+ @Override
+ public void readSuccess() {
+ mMessageFullname = null;
+ }
+
+ @Override
+ public void readFailed() {
+
+ }
+ });
+ }
+
if(mPost == null) {
mPost = getIntent().getExtras().getParcelable(EXTRA_POST_DATA);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
index 6cba00f7..57169f00 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
@@ -47,7 +47,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
PostTypeBottomSheetFragment.PostTypeSelectionCallback {
static final String EXTRA_SUBREDDIT_NAME_KEY = "ESN";
- static final String EXTRA_NOTIFICATION_FULLNAME = "ENF";
+ static final String EXTRA_MESSAGE_FULLNAME = "ENF";
static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN";
private static final String FETCH_SUBREDDIT_INFO_STATE = "FSIS";
@@ -56,6 +56,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
private static final String ACCESS_TOKEN_STATE = "ATS";
private static final String ACCOUNT_NAME_STATE = "ANS";
+ private static final String MESSAGE_FULLNAME_STATE = "MFS";
private static final String NEW_ACCOUNT_NAME_STATE = "NANS";
@BindView(R.id.coordinator_layout_view_subreddit_detail_activity) CoordinatorLayout coordinatorLayout;
@@ -79,6 +80,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
private boolean subscriptionReady = false;
private boolean isInLazyMode = false;
private boolean showToast = false;
+ private String mMessageFullname;
private String mNewAccountName;
private RequestManager glide;
@@ -153,6 +155,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME_KEY);
if(savedInstanceState == null) {
+ mMessageFullname = getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME);
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
getCurrentAccountAndBindView();
} else {
@@ -161,6 +164,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
+ mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE);
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
if(!mNullAccessToken && mAccessToken == null) {
@@ -310,6 +314,20 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
}
private void bindView(boolean initializeFragment) {
+ if(mAccessToken != null && mMessageFullname != null) {
+ ReadMessage.readMessage(mOauthRetrofit, mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() {
+ @Override
+ public void readSuccess() {
+ mMessageFullname = null;
+ }
+
+ @Override
+ public void readFailed() {
+
+ }
+ });
+ }
+
subscribeSubredditChip.setOnClickListener(view -> {
if(subscriptionReady) {
subscriptionReady = false;
@@ -451,6 +469,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
+ outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname);
outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName);
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE_KEY, mFragment);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java
index 8875ea63..50f3fdf2 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java
@@ -51,7 +51,7 @@ import retrofit2.Retrofit;
public class ViewUserDetailActivity extends AppCompatActivity implements UserThingSortTypeBottomSheetFragment.UserThingSortTypeSelectionCallback {
static final String EXTRA_USER_NAME_KEY = "EUNK";
- static final String EXTRA_NOTIFICATION_FULLNAME = "ENF";
+ static final String EXTRA_MESSAGE_FULLNAME = "ENF";
static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN";
private static final String FETCH_USER_INFO_STATE = "FSIS";
@@ -59,6 +59,7 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi
private static final String ACCESS_TOKEN_STATE = "ATS";
private static final String ACCOUNT_NAME_STATE = "ANS";
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
+ private static final String MESSAGE_FULLNAME_STATE = "MFS";
private static final String NEW_ACCOUNT_NAME_STATE = "NANS";
@BindView(R.id.coordinator_layout_view_user_detail_activity) CoordinatorLayout coordinatorLayout;
@@ -96,6 +97,7 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi
private int collapsedTabBackgroundColor;
private int collapsedTabIndicatorColor;
private boolean showToast = false;
+ private String mMessageFullname;
private String mNewAccountName;
@Inject
@@ -121,6 +123,7 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi
username = getIntent().getStringExtra(EXTRA_USER_NAME_KEY);
if (savedInstanceState == null) {
+ mMessageFullname = getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME);
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
getCurrentAccountAndInitializeViewPager();
} else {
@@ -129,6 +132,7 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
+ mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE);
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
if (!mNullAccessToken && mAccessToken == null) {
@@ -397,6 +401,20 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi
}
});
+
+ if(mAccessToken != null && mMessageFullname != null) {
+ ReadMessage.readMessage(mOauthRetrofit, mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() {
+ @Override
+ public void readSuccess() {
+ mMessageFullname = null;
+ }
+
+ @Override
+ public void readFailed() {
+
+ }
+ });
+ }
}
private void fetchUserInfo() {
@@ -505,6 +523,7 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
+ outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname);
outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName);
}