diff options
author | Docile-Alligator <chineseperson5@gmail.com> | 2022-04-10 09:52:06 +0000 |
---|---|---|
committer | Docile-Alligator <chineseperson5@gmail.com> | 2022-04-10 09:52:06 +0000 |
commit | ee9249cb64ecec968511f9050b30586be13bcf4c (patch) | |
tree | 976c7ff6cbb7967d1dbadd0b4df7f02a5a7348c0 /app | |
parent | bbd212ff2c4e7e77eb1332eeab440dfe13a3d40d (diff) | |
download | infinity-for-reddit-ee9249cb64ecec968511f9050b30586be13bcf4c.tar infinity-for-reddit-ee9249cb64ecec968511f9050b30586be13bcf4c.tar.gz infinity-for-reddit-ee9249cb64ecec968511f9050b30586be13bcf4c.tar.bz2 infinity-for-reddit-ee9249cb64ecec968511f9050b30586be13bcf4c.tar.lz infinity-for-reddit-ee9249cb64ecec968511f9050b30586be13bcf4c.tar.xz infinity-for-reddit-ee9249cb64ecec968511f9050b30586be13bcf4c.tar.zst infinity-for-reddit-ee9249cb64ecec968511f9050b30586be13bcf4c.zip |
Update inbox count in MainActivity after reading all messages in InboxActivity.
Diffstat (limited to '')
4 files changed, 31 insertions, 9 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java index 7e2fd59f..c6c98e61 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java @@ -53,6 +53,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.events.ChangeInboxCountEvent; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.fragments.InboxFragment; import ml.docilealligator.infinityforreddit.message.FetchMessage; @@ -316,7 +317,7 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf if (mAccessToken != null) { Toast.makeText(this, R.string.please_wait, Toast.LENGTH_SHORT).show(); mOauthRetrofit.create(RedditAPI.class).readAllMessages(APIUtils.getOAuthHeader(mAccessToken)) - .enqueue(new Callback<String>() { + .enqueue(new Callback<>() { @Override public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { if (response.isSuccessful()) { @@ -324,6 +325,7 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf if (sectionsPagerAdapter != null) { sectionsPagerAdapter.readAllMessages(); } + EventBus.getDefault().post(new ChangeInboxCountEvent(0)); } else { if (response.code() == 429) { Toast.makeText(InboxActivity.this, R.string.read_all_messages_time_limit, Toast.LENGTH_LONG).show(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index d8ef9165..5b4e20e2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -98,6 +98,7 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTypeBottomS import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.events.ChangeDisableSwipingBetweenTabsEvent; +import ml.docilealligator.infinityforreddit.events.ChangeInboxCountEvent; import ml.docilealligator.infinityforreddit.events.ChangeLockBottomAppBarEvent; import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent; 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 public void onLongPress() { if (sectionsPagerAdapter != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java index 4f5117b6..eab46345 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java @@ -118,6 +118,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa private boolean isGif = true; private boolean isNsfw; private Typeface typeface; + private Handler handler; @Override protected void onCreate(Bundle savedInstanceState) { @@ -162,6 +163,8 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa glide = Glide.with(this); + handler = new Handler(); + Intent intent = getIntent(); mImageUrl = intent.getStringExtra(EXTRA_GIF_URL_KEY); 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) { if (getExternalCacheDir() != null) { 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, new SaveBitmapImageToFile.SaveBitmapImageToFileListener() { @Override @@ -427,7 +430,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa private void shareGif() { 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 public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<GifDrawable> target, boolean isFirstResource) { return false; @@ -436,7 +439,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa @Override public boolean onResourceReady(GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) { if (getExternalCacheDir() != null) { - SaveGIFToFile.saveGifToFile(mExecutor, new Handler(), resource, getExternalCacheDir().getPath(), mImageFileName, + SaveGIFToFile.saveGifToFile(mExecutor, handler, resource, getExternalCacheDir().getPath(), mImageFileName, new SaveGIFToFile.SaveGIFToFileAsyncTaskListener() { @Override public void saveSuccess(File imageFile) { @@ -445,7 +448,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); - shareIntent.setType("image/*"); + shareIntent.setType("image/gif"); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(Intent.createChooser(shareIntent, getString(R.string.share))); } @@ -471,7 +474,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa SetAsWallpaperBottomSheetFragment setAsWallpaperBottomSheetFragment = new SetAsWallpaperBottomSheetFragment(); setAsWallpaperBottomSheetFragment.show(getSupportFragmentManager(), setAsWallpaperBottomSheetFragment.getTag()); } else { - WallpaperSetter.set(mExecutor, new Handler(), mImageUrl, WallpaperSetter.BOTH_SCREENS, this, + WallpaperSetter.set(mExecutor, handler, mImageUrl, WallpaperSetter.BOTH_SCREENS, this, new WallpaperSetter.SetWallpaperListener() { @Override public void success() { @@ -502,7 +505,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa @Override 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() { @Override public void success() { @@ -518,7 +521,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa @Override 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() { @Override public void success() { @@ -534,7 +537,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa @Override 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() { @Override public void success() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeInboxCountEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeInboxCountEvent.java new file mode 100644 index 00000000..2c8810c4 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeInboxCountEvent.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.events; + +public class ChangeInboxCountEvent { + public int inboxCount; + + public ChangeInboxCountEvent(int inboxCount) { + this.inboxCount = inboxCount; + } +} |