Update inbox count in MainActivity after reading all messages in InboxActivity.

This commit is contained in:
Docile-Alligator 2022-04-10 17:52:06 +08:00
parent bbd212ff2c
commit ee9249cb64
4 changed files with 31 additions and 9 deletions

View File

@ -53,6 +53,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.apis.RedditAPI;
import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount; import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.events.ChangeInboxCountEvent;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.fragments.InboxFragment; import ml.docilealligator.infinityforreddit.fragments.InboxFragment;
import ml.docilealligator.infinityforreddit.message.FetchMessage; import ml.docilealligator.infinityforreddit.message.FetchMessage;
@ -316,7 +317,7 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
if (mAccessToken != null) { if (mAccessToken != null) {
Toast.makeText(this, R.string.please_wait, Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.please_wait, Toast.LENGTH_SHORT).show();
mOauthRetrofit.create(RedditAPI.class).readAllMessages(APIUtils.getOAuthHeader(mAccessToken)) mOauthRetrofit.create(RedditAPI.class).readAllMessages(APIUtils.getOAuthHeader(mAccessToken))
.enqueue(new Callback<String>() { .enqueue(new Callback<>() {
@Override @Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if (response.isSuccessful()) { if (response.isSuccessful()) {
@ -324,6 +325,7 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
if (sectionsPagerAdapter != null) { if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.readAllMessages(); sectionsPagerAdapter.readAllMessages();
} }
EventBus.getDefault().post(new ChangeInboxCountEvent(0));
} else { } else {
if (response.code() == 429) { if (response.code() == 429) {
Toast.makeText(InboxActivity.this, R.string.read_all_messages_time_limit, Toast.LENGTH_LONG).show(); Toast.makeText(InboxActivity.this, R.string.read_all_messages_time_limit, Toast.LENGTH_LONG).show();

View File

@ -98,6 +98,7 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTypeBottomS
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.events.ChangeDisableSwipingBetweenTabsEvent; import ml.docilealligator.infinityforreddit.events.ChangeDisableSwipingBetweenTabsEvent;
import ml.docilealligator.infinityforreddit.events.ChangeInboxCountEvent;
import ml.docilealligator.infinityforreddit.events.ChangeLockBottomAppBarEvent; import ml.docilealligator.infinityforreddit.events.ChangeLockBottomAppBarEvent;
import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent;
import ml.docilealligator.infinityforreddit.events.ChangeRequireAuthToAccountSectionEvent; import ml.docilealligator.infinityforreddit.events.ChangeRequireAuthToAccountSectionEvent;
@ -1252,6 +1253,13 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
} }
} }
@Subscribe
public void onChangeInboxCountEvent(ChangeInboxCountEvent event) {
if (adapter != null) {
adapter.setInboxCount(event.inboxCount);
}
}
@Override @Override
public void onLongPress() { public void onLongPress() {
if (sectionsPagerAdapter != null) { if (sectionsPagerAdapter != null) {

View File

@ -118,6 +118,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
private boolean isGif = true; private boolean isGif = true;
private boolean isNsfw; private boolean isNsfw;
private Typeface typeface; private Typeface typeface;
private Handler handler;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -162,6 +163,8 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
glide = Glide.with(this); glide = Glide.with(this);
handler = new Handler();
Intent intent = getIntent(); Intent intent = getIntent();
mImageUrl = intent.getStringExtra(EXTRA_GIF_URL_KEY); mImageUrl = intent.getStringExtra(EXTRA_GIF_URL_KEY);
if (mImageUrl == null) { if (mImageUrl == null) {
@ -391,7 +394,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) { public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
if (getExternalCacheDir() != null) { if (getExternalCacheDir() != null) {
Toast.makeText(ViewImageOrGifActivity.this, R.string.save_image_first, Toast.LENGTH_SHORT).show(); Toast.makeText(ViewImageOrGifActivity.this, R.string.save_image_first, Toast.LENGTH_SHORT).show();
SaveBitmapImageToFile.SaveBitmapImageToFile(mExecutor, new Handler(), resource, SaveBitmapImageToFile.SaveBitmapImageToFile(mExecutor, handler, resource,
getExternalCacheDir().getPath(), mImageFileName, getExternalCacheDir().getPath(), mImageFileName,
new SaveBitmapImageToFile.SaveBitmapImageToFileListener() { new SaveBitmapImageToFile.SaveBitmapImageToFileListener() {
@Override @Override
@ -427,7 +430,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
private void shareGif() { private void shareGif() {
Toast.makeText(ViewImageOrGifActivity.this, R.string.save_gif_first, Toast.LENGTH_SHORT).show(); Toast.makeText(ViewImageOrGifActivity.this, R.string.save_gif_first, Toast.LENGTH_SHORT).show();
glide.asGif().load(mImageUrl).listener(new RequestListener<GifDrawable>() { glide.asGif().load(mImageUrl).listener(new RequestListener<>() {
@Override @Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<GifDrawable> target, boolean isFirstResource) { public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<GifDrawable> target, boolean isFirstResource) {
return false; return false;
@ -436,7 +439,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
@Override @Override
public boolean onResourceReady(GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) { public boolean onResourceReady(GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) {
if (getExternalCacheDir() != null) { if (getExternalCacheDir() != null) {
SaveGIFToFile.saveGifToFile(mExecutor, new Handler(), resource, getExternalCacheDir().getPath(), mImageFileName, SaveGIFToFile.saveGifToFile(mExecutor, handler, resource, getExternalCacheDir().getPath(), mImageFileName,
new SaveGIFToFile.SaveGIFToFileAsyncTaskListener() { new SaveGIFToFile.SaveGIFToFileAsyncTaskListener() {
@Override @Override
public void saveSuccess(File imageFile) { public void saveSuccess(File imageFile) {
@ -445,7 +448,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
Intent shareIntent = new Intent(); Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.setType("image/*"); shareIntent.setType("image/gif");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, getString(R.string.share))); startActivity(Intent.createChooser(shareIntent, getString(R.string.share)));
} }
@ -471,7 +474,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
SetAsWallpaperBottomSheetFragment setAsWallpaperBottomSheetFragment = new SetAsWallpaperBottomSheetFragment(); SetAsWallpaperBottomSheetFragment setAsWallpaperBottomSheetFragment = new SetAsWallpaperBottomSheetFragment();
setAsWallpaperBottomSheetFragment.show(getSupportFragmentManager(), setAsWallpaperBottomSheetFragment.getTag()); setAsWallpaperBottomSheetFragment.show(getSupportFragmentManager(), setAsWallpaperBottomSheetFragment.getTag());
} else { } else {
WallpaperSetter.set(mExecutor, new Handler(), mImageUrl, WallpaperSetter.BOTH_SCREENS, this, WallpaperSetter.set(mExecutor, handler, mImageUrl, WallpaperSetter.BOTH_SCREENS, this,
new WallpaperSetter.SetWallpaperListener() { new WallpaperSetter.SetWallpaperListener() {
@Override @Override
public void success() { public void success() {
@ -502,7 +505,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
@Override @Override
public void setToHomeScreen(int viewPagerPosition) { public void setToHomeScreen(int viewPagerPosition) {
WallpaperSetter.set(mExecutor, new Handler(), mImageUrl, WallpaperSetter.HOME_SCREEN, this, WallpaperSetter.set(mExecutor, handler, mImageUrl, WallpaperSetter.HOME_SCREEN, this,
new WallpaperSetter.SetWallpaperListener() { new WallpaperSetter.SetWallpaperListener() {
@Override @Override
public void success() { public void success() {
@ -518,7 +521,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
@Override @Override
public void setToLockScreen(int viewPagerPosition) { public void setToLockScreen(int viewPagerPosition) {
WallpaperSetter.set(mExecutor, new Handler(), mImageUrl, WallpaperSetter.LOCK_SCREEN, this, WallpaperSetter.set(mExecutor, handler, mImageUrl, WallpaperSetter.LOCK_SCREEN, this,
new WallpaperSetter.SetWallpaperListener() { new WallpaperSetter.SetWallpaperListener() {
@Override @Override
public void success() { public void success() {
@ -534,7 +537,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
@Override @Override
public void setToBoth(int viewPagerPosition) { public void setToBoth(int viewPagerPosition) {
WallpaperSetter.set(mExecutor, new Handler(), mImageUrl, WallpaperSetter.BOTH_SCREENS, this, WallpaperSetter.set(mExecutor, handler, mImageUrl, WallpaperSetter.BOTH_SCREENS, this,
new WallpaperSetter.SetWallpaperListener() { new WallpaperSetter.SetWallpaperListener() {
@Override @Override
public void success() { public void success() {

View File

@ -0,0 +1,9 @@
package ml.docilealligator.infinityforreddit.events;
public class ChangeInboxCountEvent {
public int inboxCount;
public ChangeInboxCountEvent(int inboxCount) {
this.inboxCount = inboxCount;
}
}