From 04f16d56649d4badcd9b3cb8e56512d4fd7faaee Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 29 Jun 2020 13:15:23 +0800 Subject: Add ViewPrivateMessagesActivity. Rename getSharedPreferences to getDefaultSharedPreferences in BaseActivity. --- .../Activity/AccountPostsActivity.java | 2 +- .../Activity/AccountSavedThingActivity.java | 2 +- .../infinityforreddit/Activity/BaseActivity.java | 6 +- .../Activity/CommentActivity.java | 2 +- .../Activity/CreateMultiRedditActivity.java | 2 +- .../Activity/CustomThemeListingActivity.java | 2 +- .../Activity/CustomizeThemeActivity.java | 2 +- .../Activity/EditCommentActivity.java | 2 +- .../Activity/EditMultiRedditActivity.java | 2 +- .../Activity/EditPostActivity.java | 2 +- .../Activity/FilteredThingActivity.java | 2 +- .../infinityforreddit/Activity/InboxActivity.java | 342 +++++++++++++++++++++ .../infinityforreddit/Activity/LoginActivity.java | 2 +- .../infinityforreddit/Activity/MainActivity.java | 6 +- .../Activity/MultiRedditListingActivity.java | 2 +- .../Activity/PostImageActivity.java | 2 +- .../Activity/PostLinkActivity.java | 2 +- .../Activity/PostTextActivity.java | 2 +- .../Activity/PostVideoActivity.java | 2 +- .../infinityforreddit/Activity/ReportActivity.java | 2 +- .../infinityforreddit/Activity/RulesActivity.java | 2 +- .../infinityforreddit/Activity/SearchActivity.java | 2 +- .../Activity/SearchResultActivity.java | 2 +- .../Activity/SearchSubredditsResultActivity.java | 2 +- .../Activity/SelectedSubredditsActivity.java | 2 +- .../Activity/SettingsActivity.java | 2 +- .../Activity/SubredditMultiselectionActivity.java | 2 +- .../Activity/SubredditSelectionActivity.java | 2 +- .../Activity/SubscribedThingListingActivity.java | 2 +- .../Activity/ViewMessageActivity.java | 342 --------------------- .../Activity/ViewMultiRedditDetailActivity.java | 2 +- .../Activity/ViewPostDetailActivity.java | 2 +- .../Activity/ViewPrivateMessagesActivity.java | 165 ++++++++++ .../Activity/ViewSubredditDetailActivity.java | 4 +- .../Activity/ViewUserDetailActivity.java | 2 +- .../Adapter/MessageRecyclerViewAdapter.java | 7 +- .../infinityforreddit/AppComponent.java | 11 +- .../infinityforreddit/Fragment/InboxFragment.java | 176 +++++++++++ .../Fragment/ViewMessagesFragment.java | 176 ----------- .../docilealligator/infinityforreddit/Message.java | 67 +++- .../infinityforreddit/PullNotificationWorker.java | 22 +- 41 files changed, 809 insertions(+), 573 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Activity/InboxActivity.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPrivateMessagesActivity.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/InboxFragment.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewMessagesFragment.java (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java index 97cc5967..2c144bd4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java @@ -156,7 +156,7 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java index 42e89abc..36a61624 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java @@ -147,7 +147,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java index 883d0ce8..6f24bc3f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java @@ -58,7 +58,7 @@ public abstract class BaseActivity extends AppCompatActivity { super.onCreate(savedInstanceState); customThemeWrapper = getCustomThemeWrapper(); - SharedPreferences mSharedPreferences = getSharedPreferences(); + SharedPreferences mSharedPreferences = getDefaultSharedPreferences(); boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; int systemThemeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); immersiveInterface = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && @@ -174,7 +174,7 @@ public abstract class BaseActivity extends AppCompatActivity { } } - protected abstract SharedPreferences getSharedPreferences(); + protected abstract SharedPreferences getDefaultSharedPreferences(); protected abstract CustomThemeWrapper getCustomThemeWrapper(); @@ -229,7 +229,7 @@ public abstract class BaseActivity extends AppCompatActivity { } public int getNavBarHeight() { - if (getSharedPreferences().getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_IGNORE_NAV_BAR_KEY, false)) { + if (getDefaultSharedPreferences().getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_IGNORE_NAV_BAR_KEY, false)) { return 0; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java index 95804f88..c87fd263 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java @@ -259,7 +259,7 @@ public class CommentActivity extends BaseActivity { } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java index 86669de9..1d413026 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java @@ -210,7 +210,7 @@ public class CreateMultiRedditActivity extends BaseActivity { } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java index 4e937cf6..304a2a0a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java @@ -135,7 +135,7 @@ public class CustomThemeListingActivity extends BaseActivity implements } @Override - protected SharedPreferences getSharedPreferences() { + protected SharedPreferences getDefaultSharedPreferences() { return sharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java index 0853700b..27823944 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java @@ -229,7 +229,7 @@ public class CustomizeThemeActivity extends BaseActivity { } @Override - protected SharedPreferences getSharedPreferences() { + protected SharedPreferences getDefaultSharedPreferences() { return sharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java index 1d807d13..abe86b66 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java @@ -113,7 +113,7 @@ public class EditCommentActivity extends BaseActivity { } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditMultiRedditActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditMultiRedditActivity.java index 1eb815b6..c12683ed 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditMultiRedditActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditMultiRedditActivity.java @@ -244,7 +244,7 @@ public class EditMultiRedditActivity extends BaseActivity { } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java index d886f91f..9615c4a9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java @@ -116,7 +116,7 @@ public class EditPostActivity extends BaseActivity { } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java index 1ed02b61..b274c314 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java @@ -174,7 +174,7 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/InboxActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/InboxActivity.java new file mode 100644 index 00000000..4a94d3ab --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/InboxActivity.java @@ -0,0 +1,342 @@ +package ml.docilealligator.infinityforreddit.Activity; + +import android.content.SharedPreferences; +import android.os.Build; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; +import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowManager; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.coordinatorlayout.widget.CoordinatorLayout; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentPagerAdapter; +import androidx.viewpager.widget.ViewPager; + +import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; +import com.google.android.material.tabs.TabLayout; +import com.r0adkll.slidr.Slidr; +import com.r0adkll.slidr.model.SlidrInterface; + +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; + +import javax.inject.Inject; +import javax.inject.Named; + +import butterknife.BindView; +import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; +import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; +import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask; +import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; +import ml.docilealligator.infinityforreddit.FetchMessages; +import ml.docilealligator.infinityforreddit.Fragment.InboxFragment; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; +import retrofit2.Retrofit; + +public class InboxActivity extends BaseActivity implements ActivityToolbarInterface { + + public 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.coordinator_layout_inbox_activity) + CoordinatorLayout mCoordinatorLayout; + @BindView(R.id.collapsing_toolbar_layout_inbox_activity) + CollapsingToolbarLayout collapsingToolbarLayout; + @BindView(R.id.appbar_layout_inbox_activity) + AppBarLayout mAppBarLayout; + @BindView(R.id.toolbar_inbox_activity) + Toolbar mToolbar; + @BindView(R.id.tab_layout_inbox_activity) + TabLayout tabLayout; + @BindView(R.id.view_pager_inbox_activity) + ViewPager viewPager; + @Inject + @Named("oauth") + Retrofit mOauthRetrofit; + @Inject + RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + @Named("default") + SharedPreferences mSharedPreferences; + @Inject + CustomThemeWrapper mCustomThemeWrapper; + private SlidrInterface mSlidrInterface; + private SectionsPagerAdapter sectionsPagerAdapter; + private boolean mNullAccessToken = false; + private String mAccessToken; + private String mNewAccountName; + + @Override + protected void onCreate(Bundle savedInstanceState) { + ((Infinity) getApplication()).getAppComponent().inject(this); + + super.onCreate(savedInstanceState); + + setContentView(R.layout.activity_inbox); + + ButterKnife.bind(this); + + EventBus.getDefault().register(this); + + applyCustomTheme(); + + if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) { + mSlidrInterface = Slidr.attach(this); + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + Window window = getWindow(); + + if (isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(mAppBarLayout); + } + + if (isImmersiveInterface()) { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + adjustToolbar(mToolbar); + } + } + + mToolbar.setTitle(R.string.inbox); + setSupportActionBar(mToolbar); + setToolbarGoToTop(mToolbar); + + 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(); + } else { + bindView(); + } + } else { + mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME); + getCurrentAccountAndFetchMessage(); + } + } + + @Override + public SharedPreferences getDefaultSharedPreferences() { + return mSharedPreferences; + } + + @Override + protected CustomThemeWrapper getCustomThemeWrapper() { + return mCustomThemeWrapper; + } + + @Override + protected void applyCustomTheme() { + mCoordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); + applyAppBarLayoutAndToolbarTheme(mAppBarLayout, mToolbar); + applyTabLayoutTheme(tabLayout); + } + + private void getCurrentAccountAndFetchMessage() { + new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { + if (mNewAccountName != null) { + if (account == null || !account.getUsername().equals(mNewAccountName)) { + new SwitchAccountAsyncTask(mRedditDataRoomDatabase, mNewAccountName, newAccount -> { + EventBus.getDefault().post(new SwitchAccountEvent(getClass().getName())); + Toast.makeText(this, R.string.account_switched, Toast.LENGTH_SHORT).show(); + + mNewAccountName = null; + if (newAccount == null) { + mNullAccessToken = true; + } else { + mAccessToken = newAccount.getAccessToken(); + } + + bindView(); + }).execute(); + } else { + mAccessToken = account.getAccessToken(); + bindView(); + } + } else { + if (account == null) { + mNullAccessToken = true; + } else { + mAccessToken = account.getAccessToken(); + } + + bindView(); + } + }).execute(); + } + + private void bindView() { + sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); + viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { + @Override + public void onPageSelected(int position) { + if (position == 0) { + unlockSwipeRightToGoBack(); + } else { + lockSwipeRightToGoBack(); + } + } + }); + viewPager.setAdapter(sectionsPagerAdapter); + viewPager.setOffscreenPageLimit(2); + tabLayout.setupWithViewPager(viewPager); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.inbox_activity, menu); + applyMenuItemTheme(menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + if (item.getItemId() == R.id.action_refresh_inbox_activity) { + if (sectionsPagerAdapter != null) { + sectionsPagerAdapter.refresh(); + } + return true; + } else if (item.getItemId() == android.R.id.home) { + finish(); + return true; + } + return false; + } + + @Override + protected void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken); + outState.putString(ACCESS_TOKEN_STATE, mAccessToken); + outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + EventBus.getDefault().unregister(this); + } + + @Subscribe + public void onAccountSwitchEvent(SwitchAccountEvent event) { + if (!getClass().getName().equals(event.excludeActivityClassName)) { + finish(); + } + } + + @Override + public void onLongPress() { + if (sectionsPagerAdapter != null) { + sectionsPagerAdapter.goBackToTop(); + } + } + + private void lockSwipeRightToGoBack() { + if (mSlidrInterface != null) { + mSlidrInterface.lock(); + } + } + + private void unlockSwipeRightToGoBack() { + if (mSlidrInterface != null) { + mSlidrInterface.unlock(); + } + } + + private class SectionsPagerAdapter extends FragmentPagerAdapter { + private InboxFragment tab1; + private InboxFragment tab2; + + public SectionsPagerAdapter(@NonNull FragmentManager fm) { + super(fm, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT); + } + + @NonNull + @Override + public Fragment getItem(int position) { + if (position == 0) { + InboxFragment fragment = new InboxFragment(); + Bundle bundle = new Bundle(); + bundle.putString(InboxFragment.EXTRA_ACCESS_TOKEN, mAccessToken); + bundle.putString(InboxFragment.EXTRA_MESSAGE_WHERE, FetchMessages.WHERE_INBOX); + fragment.setArguments(bundle); + return fragment; + } else { + InboxFragment fragment = new InboxFragment(); + Bundle bundle = new Bundle(); + bundle.putString(InboxFragment.EXTRA_ACCESS_TOKEN, mAccessToken); + bundle.putString(InboxFragment.EXTRA_MESSAGE_WHERE, FetchMessages.WHERE_MESSAGES); + fragment.setArguments(bundle); + return fragment; + } + } + + @Override + public int getCount() { + return 2; + } + + @Nullable + @Override + public CharSequence getPageTitle(int position) { + if (position == 0) { + return getString(R.string.notifications); + } + + return getString(R.string.messages); + } + + @NonNull + @Override + public Object instantiateItem(@NonNull ViewGroup container, int position) { + Fragment fragment = (Fragment) super.instantiateItem(container, position); + if (position == 0) { + tab1 = (InboxFragment) fragment; + } else if (position == 1) { + tab2 = (InboxFragment) fragment; + } + + return fragment; + } + + void refresh() { + if (viewPager.getCurrentItem() == 0) { + if (tab1 != null) { + tab1.refresh(); + } + } else if (viewPager.getCurrentItem() == 1 && tab2 != null) { + tab2.refresh(); + } + } + + void goBackToTop() { + if (viewPager.getCurrentItem() == 0) { + if (tab1 != null) { + tab1.goBackToTop(); + } + } else if (viewPager.getCurrentItem() == 1) { + if (tab2 != null) { + tab2.goBackToTop(); + } + } + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java index 0fa06f4f..a15536a9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java @@ -218,7 +218,7 @@ public class LoginActivity extends BaseActivity { } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index fbc3c9f1..04c1ff41 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -292,7 +292,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } @@ -444,7 +444,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb }); messageBottomAppBar.setOnClickListener(view -> { - Intent intent = new Intent(this, ViewMessageActivity.class); + Intent intent = new Intent(this, InboxActivity.class); startActivity(intent); }); @@ -483,7 +483,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb intent = new Intent(MainActivity.this, MultiRedditListingActivity.class); break; case R.string.inbox: - intent = new Intent(MainActivity.this, ViewMessageActivity.class); + intent = new Intent(MainActivity.this, InboxActivity.class); break; case R.string.upvoted: intent = new Intent(MainActivity.this, AccountPostsActivity.class); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java index e636572d..83b34001 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java @@ -252,7 +252,7 @@ public class MultiRedditListingActivity extends BaseActivity { } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java index 07952f79..ca204bd7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java @@ -371,7 +371,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java index c041f64e..e3e7dc48 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java @@ -310,7 +310,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java index a3e3accc..f6d972da 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java @@ -314,7 +314,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java index 68068775..aeb8b70d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java @@ -376,7 +376,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ReportActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ReportActivity.java index b816b505..b05d41ab 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ReportActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ReportActivity.java @@ -202,7 +202,7 @@ public class ReportActivity extends BaseActivity { } @Override - protected SharedPreferences getSharedPreferences() { + protected SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java index f90dedf3..809fafa2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java @@ -136,7 +136,7 @@ public class RulesActivity extends BaseActivity { } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java index 8b603451..d46bfce0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java @@ -184,7 +184,7 @@ public class SearchActivity extends BaseActivity { } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java index 5ea80f8f..fa2ceaa9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java @@ -176,7 +176,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java index b7b2730d..21c80e60 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java @@ -117,7 +117,7 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java index 3d17ecbf..9145f102 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java @@ -150,7 +150,7 @@ public class SelectedSubredditsActivity extends BaseActivity implements Activity } @Override - protected SharedPreferences getSharedPreferences() { + protected SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java index 3c50caf8..4a1be2c3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java @@ -91,7 +91,7 @@ public class SettingsActivity extends BaseActivity implements } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java index 88825dc5..18aeed17 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java @@ -235,7 +235,7 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java index b6aa045d..18601f89 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java @@ -138,7 +138,7 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java index 994d19e7..cf8e5bfc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java @@ -149,7 +149,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java deleted file mode 100644 index ecc33a6c..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java +++ /dev/null @@ -1,342 +0,0 @@ -package ml.docilealligator.infinityforreddit.Activity; - -import android.content.SharedPreferences; -import android.os.Build; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; -import android.view.ViewGroup; -import android.view.Window; -import android.view.WindowManager; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.widget.Toolbar; -import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentManager; -import androidx.fragment.app.FragmentPagerAdapter; -import androidx.viewpager.widget.ViewPager; - -import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.appbar.CollapsingToolbarLayout; -import com.google.android.material.tabs.TabLayout; -import com.r0adkll.slidr.Slidr; -import com.r0adkll.slidr.model.SlidrInterface; - -import org.greenrobot.eventbus.EventBus; -import org.greenrobot.eventbus.Subscribe; - -import javax.inject.Inject; -import javax.inject.Named; - -import butterknife.BindView; -import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; -import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; -import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask; -import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; -import ml.docilealligator.infinityforreddit.FetchMessages; -import ml.docilealligator.infinityforreddit.Fragment.ViewMessagesFragment; -import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; -import retrofit2.Retrofit; - -public class ViewMessageActivity extends BaseActivity implements ActivityToolbarInterface { - - public 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.coordinator_layout_view_message_activity) - CoordinatorLayout mCoordinatorLayout; - @BindView(R.id.collapsing_toolbar_layout_view_message_activity) - CollapsingToolbarLayout collapsingToolbarLayout; - @BindView(R.id.appbar_layout_view_message_activity) - AppBarLayout mAppBarLayout; - @BindView(R.id.toolbar_view_message_activity) - Toolbar mToolbar; - @BindView(R.id.tab_layout_view_message_activity) - TabLayout tabLayout; - @BindView(R.id.view_pager_view_message_activity) - ViewPager viewPager; - @Inject - @Named("oauth") - Retrofit mOauthRetrofit; - @Inject - RedditDataRoomDatabase mRedditDataRoomDatabase; - @Inject - @Named("default") - SharedPreferences mSharedPreferences; - @Inject - CustomThemeWrapper mCustomThemeWrapper; - private SlidrInterface mSlidrInterface; - private SectionsPagerAdapter sectionsPagerAdapter; - private boolean mNullAccessToken = false; - private String mAccessToken; - private String mNewAccountName; - - @Override - protected void onCreate(Bundle savedInstanceState) { - ((Infinity) getApplication()).getAppComponent().inject(this); - - super.onCreate(savedInstanceState); - - setContentView(R.layout.activity_view_message); - - ButterKnife.bind(this); - - EventBus.getDefault().register(this); - - applyCustomTheme(); - - if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) { - mSlidrInterface = Slidr.attach(this); - } - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - Window window = getWindow(); - - if (isChangeStatusBarIconColor()) { - addOnOffsetChangedListener(mAppBarLayout); - } - - if (isImmersiveInterface()) { - window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); - adjustToolbar(mToolbar); - } - } - - mToolbar.setTitle(R.string.inbox); - setSupportActionBar(mToolbar); - setToolbarGoToTop(mToolbar); - - 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(); - } else { - bindView(); - } - } else { - mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME); - getCurrentAccountAndFetchMessage(); - } - } - - @Override - public SharedPreferences getSharedPreferences() { - return mSharedPreferences; - } - - @Override - protected CustomThemeWrapper getCustomThemeWrapper() { - return mCustomThemeWrapper; - } - - @Override - protected void applyCustomTheme() { - mCoordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(mAppBarLayout, mToolbar); - applyTabLayoutTheme(tabLayout); - } - - private void getCurrentAccountAndFetchMessage() { - new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { - if (mNewAccountName != null) { - if (account == null || !account.getUsername().equals(mNewAccountName)) { - new SwitchAccountAsyncTask(mRedditDataRoomDatabase, mNewAccountName, newAccount -> { - EventBus.getDefault().post(new SwitchAccountEvent(getClass().getName())); - Toast.makeText(this, R.string.account_switched, Toast.LENGTH_SHORT).show(); - - mNewAccountName = null; - if (newAccount == null) { - mNullAccessToken = true; - } else { - mAccessToken = newAccount.getAccessToken(); - } - - bindView(); - }).execute(); - } else { - mAccessToken = account.getAccessToken(); - bindView(); - } - } else { - if (account == null) { - mNullAccessToken = true; - } else { - mAccessToken = account.getAccessToken(); - } - - bindView(); - } - }).execute(); - } - - private void bindView() { - sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); - viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { - @Override - public void onPageSelected(int position) { - if (position == 0) { - unlockSwipeRightToGoBack(); - } else { - lockSwipeRightToGoBack(); - } - } - }); - viewPager.setAdapter(sectionsPagerAdapter); - viewPager.setOffscreenPageLimit(2); - tabLayout.setupWithViewPager(viewPager); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.view_message_activity, menu); - applyMenuItemTheme(menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(@NonNull MenuItem item) { - if (item.getItemId() == R.id.action_refresh_view_message_activity) { - if (sectionsPagerAdapter != null) { - sectionsPagerAdapter.refresh(); - } - return true; - } else if (item.getItemId() == android.R.id.home) { - finish(); - return true; - } - return false; - } - - @Override - protected void onSaveInstanceState(@NonNull Bundle outState) { - super.onSaveInstanceState(outState); - outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken); - outState.putString(ACCESS_TOKEN_STATE, mAccessToken); - outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - EventBus.getDefault().unregister(this); - } - - @Subscribe - public void onAccountSwitchEvent(SwitchAccountEvent event) { - if (!getClass().getName().equals(event.excludeActivityClassName)) { - finish(); - } - } - - @Override - public void onLongPress() { - if (sectionsPagerAdapter != null) { - sectionsPagerAdapter.goBackToTop(); - } - } - - private void lockSwipeRightToGoBack() { - if (mSlidrInterface != null) { - mSlidrInterface.lock(); - } - } - - private void unlockSwipeRightToGoBack() { - if (mSlidrInterface != null) { - mSlidrInterface.unlock(); - } - } - - private class SectionsPagerAdapter extends FragmentPagerAdapter { - private ViewMessagesFragment tab1; - private ViewMessagesFragment tab2; - - public SectionsPagerAdapter(@NonNull FragmentManager fm) { - super(fm, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT); - } - - @NonNull - @Override - public Fragment getItem(int position) { - if (position == 0) { - ViewMessagesFragment fragment = new ViewMessagesFragment(); - Bundle bundle = new Bundle(); - bundle.putString(ViewMessagesFragment.EXTRA_ACCESS_TOKEN, mAccessToken); - bundle.putString(ViewMessagesFragment.EXTRA_MESSAGE_WHERE, FetchMessages.WHERE_INBOX); - fragment.setArguments(bundle); - return fragment; - } else { - ViewMessagesFragment fragment = new ViewMessagesFragment(); - Bundle bundle = new Bundle(); - bundle.putString(ViewMessagesFragment.EXTRA_ACCESS_TOKEN, mAccessToken); - bundle.putString(ViewMessagesFragment.EXTRA_MESSAGE_WHERE, FetchMessages.WHERE_MESSAGES); - fragment.setArguments(bundle); - return fragment; - } - } - - @Override - public int getCount() { - return 2; - } - - @Nullable - @Override - public CharSequence getPageTitle(int position) { - if (position == 0) { - return getString(R.string.notifications); - } - - return getString(R.string.messages); - } - - @NonNull - @Override - public Object instantiateItem(@NonNull ViewGroup container, int position) { - Fragment fragment = (Fragment) super.instantiateItem(container, position); - if (position == 0) { - tab1 = (ViewMessagesFragment) fragment; - } else if (position == 1) { - tab2 = (ViewMessagesFragment) fragment; - } - - return fragment; - } - - void refresh() { - if (viewPager.getCurrentItem() == 0) { - if (tab1 != null) { - tab1.refresh(); - } - } else if (viewPager.getCurrentItem() == 1 && tab2 != null) { - tab2.refresh(); - } - } - - void goBackToTop() { - if (viewPager.getCurrentItem() == 0) { - if (tab1 != null) { - tab1.goBackToTop(); - } - } else if (viewPager.getCurrentItem() == 1) { - if (tab2 != null) { - tab2.goBackToTop(); - } - } - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java index 1317e133..e709b991 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java @@ -332,7 +332,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java index 81e1ba8a..6586dd08 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -377,7 +377,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPrivateMessagesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPrivateMessagesActivity.java new file mode 100644 index 00000000..0d666658 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPrivateMessagesActivity.java @@ -0,0 +1,165 @@ +package ml.docilealligator.infinityforreddit.Activity; + +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Build; +import android.os.Bundle; +import android.view.Window; +import android.view.WindowManager; + +import androidx.appcompat.widget.Toolbar; +import androidx.coordinatorlayout.widget.CoordinatorLayout; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.r0adkll.slidr.Slidr; + +import java.util.ArrayList; + +import javax.inject.Inject; +import javax.inject.Named; + +import butterknife.BindView; +import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; +import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; +import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.Message; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; +import retrofit2.Retrofit; + +public class ViewPrivateMessagesActivity extends BaseActivity implements ActivityToolbarInterface { + + public static final String EXTRA_PRIVATE_MESSAGES = "EPM"; + public static final String EXTRA_SENDER_USERNAME = "ESU"; + private static final String NULL_ACCESS_TOKEN_STATE = "NATS"; + private static final String ACCESS_TOKEN_STATE = "ATS"; + @BindView(R.id.coordinator_layout_view_private_messages_activity) + CoordinatorLayout mCoordinatorLayout; + @BindView(R.id.collapsing_toolbar_layout_view_private_messages_activity) + CollapsingToolbarLayout collapsingToolbarLayout; + @BindView(R.id.appbar_layout_view_private_messages_activity) + AppBarLayout mAppBarLayout; + @BindView(R.id.toolbar_view_private_messages_activity) + Toolbar mToolbar; + @BindView(R.id.recycler_view_view_private_messages) + RecyclerView mRecyclerView; + @BindView(R.id.fab_view_private_messages_activity) + FloatingActionButton mFab; + @Inject + @Named("oauth") + Retrofit mOauthRetrofit; + @Inject + RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + @Named("default") + SharedPreferences mSharedPreferences; + @Inject + CustomThemeWrapper mCustomThemeWrapper; + private LinearLayoutManager mLinearLayoutManager; + private ArrayList privateMessages; + private boolean mNullAccessToken = false; + private String mAccessToken; + + @Override + protected void onCreate(Bundle savedInstanceState) { + ((Infinity) getApplication()).getAppComponent().inject(this); + + super.onCreate(savedInstanceState); + + setContentView(R.layout.activity_view_private_messages); + + ButterKnife.bind(this); + + applyCustomTheme(); + + if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) { + Slidr.attach(this); + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + Window window = getWindow(); + + if (isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(mAppBarLayout); + } + + if (isImmersiveInterface()) { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + adjustToolbar(mToolbar); + + int navBarHeight = getNavBarHeight(); + if (navBarHeight > 0) { + CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mFab.getLayoutParams(); + params.bottomMargin = navBarHeight; + mFab.setLayoutParams(params); + } + } + } + + Intent intent = getIntent(); + privateMessages = intent.getParcelableArrayListExtra(EXTRA_PRIVATE_MESSAGES); + + mToolbar.setTitle(intent.getStringExtra(EXTRA_SENDER_USERNAME)); + setSupportActionBar(mToolbar); + setToolbarGoToTop(mToolbar); + + if (savedInstanceState != null) { + mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE); + mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE); + + if (!mNullAccessToken && mAccessToken == null) { + getCurrentAccountAndBindView(); + } else { + bindView(); + } + } else { + getCurrentAccountAndBindView(); + } + } + + private void getCurrentAccountAndBindView() { + new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { + if (account == null) { + mNullAccessToken = true; + } else { + mAccessToken = account.getAccessToken(); + } + bindView(); + }).execute(); + } + + private void bindView() { + + } + + @Override + protected SharedPreferences getDefaultSharedPreferences() { + return mSharedPreferences; + } + + @Override + protected CustomThemeWrapper getCustomThemeWrapper() { + return mCustomThemeWrapper; + } + + @Override + protected void applyCustomTheme() { + mCoordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); + applyAppBarLayoutAndToolbarTheme(mAppBarLayout, mToolbar); + applyFABTheme(mFab); + } + + @Override + public void onLongPress() { + if (mLinearLayoutManager != null) { + mLinearLayoutManager.scrollToPositionWithOffset(0, 0); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java index 6f122bee..2b516549 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java @@ -413,7 +413,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } @@ -542,7 +542,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp goBackToMainPageBottomAppBar.setOnClickListener(view -> EventBus.getDefault().post(new GoBackToMainPageEvent())); messageBottomAppBar.setOnClickListener(view -> { - Intent intent = new Intent(this, ViewMessageActivity.class); + Intent intent = new Intent(this, InboxActivity.class); startActivity(intent); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java index c3d4c345..cbcd54be 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java @@ -430,7 +430,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele } @Override - public SharedPreferences getSharedPreferences() { + public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } 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 0a9c9e5f..4deefed2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MessageRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MessageRecyclerViewAdapter.java @@ -12,7 +12,6 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; -import android.widget.Toast; import androidx.annotation.NonNull; import androidx.paging.PagedListAdapter; @@ -28,6 +27,7 @@ import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.simple.ext.SimpleExtPlugin; import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity; +import ml.docilealligator.infinityforreddit.Activity.ViewPrivateMessagesActivity; import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.FetchMessages; @@ -155,7 +155,10 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter mMessageViewModel.retryLoadingMore()); + mLinearLayoutManager = new LinearLayoutManager(mActivity); + mRecyclerView.setLayoutManager(mLinearLayoutManager); + mRecyclerView.setAdapter(mAdapter); + DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mActivity, mLinearLayoutManager.getOrientation()); + mRecyclerView.addItemDecoration(dividerItemDecoration); + + MessageViewModel.Factory factory = new MessageViewModel.Factory(mOauthRetrofit, + getResources().getConfiguration().locale, mAccessToken, where); + mMessageViewModel = new ViewModelProvider(this, factory).get(MessageViewModel.class); + mMessageViewModel.getMessages().observe(getViewLifecycleOwner(), messages -> mAdapter.submitList(messages)); + + mMessageViewModel.hasMessage().observe(getViewLifecycleOwner(), hasMessage -> { + mSwipeRefreshLayout.setRefreshing(false); + if (hasMessage) { + mFetchMessageInfoLinearLayout.setVisibility(View.GONE); + } else { + mFetchMessageInfoLinearLayout.setOnClickListener(null); + showErrorView(R.string.no_messages); + } + }); + + mMessageViewModel.getInitialLoadingState().observe(getViewLifecycleOwner(), networkState -> { + if (networkState.getStatus().equals(NetworkState.Status.SUCCESS)) { + mSwipeRefreshLayout.setRefreshing(false); + } else if (networkState.getStatus().equals(NetworkState.Status.FAILED)) { + mSwipeRefreshLayout.setRefreshing(false); + mFetchMessageInfoLinearLayout.setOnClickListener(view -> { + mFetchMessageInfoLinearLayout.setVisibility(View.GONE); + mMessageViewModel.refresh(); + mAdapter.setNetworkState(null); + }); + showErrorView(R.string.load_messages_failed); + } else { + mSwipeRefreshLayout.setRefreshing(true); + } + }); + + mMessageViewModel.getPaginationNetworkState().observe(getViewLifecycleOwner(), networkState -> { + mAdapter.setNetworkState(networkState); + }); + + mSwipeRefreshLayout.setOnRefreshListener(this::onRefresh); + + return rootView; + } + + private void showErrorView(int stringResId) { + mSwipeRefreshLayout.setRefreshing(false); + mFetchMessageInfoLinearLayout.setVisibility(View.VISIBLE); + mFetchMessageInfoTextView.setText(stringResId); + mGlide.load(R.drawable.error_image).into(mFetchMessageInfoImageView); + } + + @Override + public void applyTheme() { + mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); + mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); + mFetchMessageInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + } + + public void goBackToTop() { + if (mLinearLayoutManager != null) { + mLinearLayoutManager.scrollToPositionWithOffset(0, 0); + } + } + + private void onRefresh() { + mMessageViewModel.refresh(); + mAdapter.setNetworkState(null); + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + mActivity = (BaseActivity) context; + } +} \ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewMessagesFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewMessagesFragment.java deleted file mode 100644 index 8f7cdd4f..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewMessagesFragment.java +++ /dev/null @@ -1,176 +0,0 @@ -package ml.docilealligator.infinityforreddit.Fragment; - -import android.content.Context; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.fragment.app.Fragment; -import androidx.lifecycle.ViewModelProvider; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; - -import com.bumptech.glide.Glide; -import com.bumptech.glide.RequestManager; - -import javax.inject.Inject; -import javax.inject.Named; - -import butterknife.BindView; -import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.Activity.BaseActivity; -import ml.docilealligator.infinityforreddit.Adapter.MessageRecyclerViewAdapter; -import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; -import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.MessageViewModel; -import ml.docilealligator.infinityforreddit.NetworkState; -import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import retrofit2.Retrofit; - -public class ViewMessagesFragment extends Fragment implements FragmentCommunicator { - - public static final String EXTRA_ACCESS_TOKEN = "EAT"; - public static final String EXTRA_MESSAGE_WHERE = "EMT"; - @BindView(R.id.swipe_refresh_layout_view_messages_fragment) - SwipeRefreshLayout mSwipeRefreshLayout; - @BindView(R.id.recycler_view_view_messages_fragment) - RecyclerView mRecyclerView; - @BindView(R.id.fetch_messages_info_linear_layout_view_messages_fragment) - LinearLayout mFetchMessageInfoLinearLayout; - @BindView(R.id.fetch_messages_info_image_view_view_messages_fragment) - ImageView mFetchMessageInfoImageView; - @BindView(R.id.fetch_messages_info_text_view_view_messages_fragment) - TextView mFetchMessageInfoTextView; - MessageViewModel mMessageViewModel; - @Inject - @Named("oauth") - Retrofit mOauthRetrofit; - @Inject - RedditDataRoomDatabase mRedditDataRoomDatabase; - @Inject - @Named("default") - SharedPreferences mSharedPreferences; - @Inject - CustomThemeWrapper mCustomThemeWrapper; - private String mAccessToken; - private MessageRecyclerViewAdapter mAdapter; - private RequestManager mGlide; - private LinearLayoutManager mLinearLayoutManager; - private BaseActivity mActivity; - - public ViewMessagesFragment() { - // Required empty public constructor - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.fragment_view_messages, container, false); - - ((Infinity) mActivity.getApplication()).getAppComponent().inject(this); - - ButterKnife.bind(this, rootView); - - applyTheme(); - - Bundle arguments = getArguments(); - if (arguments == null) { - return rootView; - } - mAccessToken = getArguments().getString(EXTRA_ACCESS_TOKEN); - mGlide = Glide.with(this); - - if (mActivity.isImmersiveInterface()) { - mRecyclerView.setPadding(0, 0, 0, mActivity.getNavBarHeight()); - } - - String where = arguments.getString(EXTRA_MESSAGE_WHERE); - mAdapter = new MessageRecyclerViewAdapter(mActivity, mOauthRetrofit, mCustomThemeWrapper, - mAccessToken, where, () -> mMessageViewModel.retryLoadingMore()); - mLinearLayoutManager = new LinearLayoutManager(mActivity); - mRecyclerView.setLayoutManager(mLinearLayoutManager); - mRecyclerView.setAdapter(mAdapter); - DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mActivity, mLinearLayoutManager.getOrientation()); - mRecyclerView.addItemDecoration(dividerItemDecoration); - - MessageViewModel.Factory factory = new MessageViewModel.Factory(mOauthRetrofit, - getResources().getConfiguration().locale, mAccessToken, where); - mMessageViewModel = new ViewModelProvider(this, factory).get(MessageViewModel.class); - mMessageViewModel.getMessages().observe(getViewLifecycleOwner(), messages -> mAdapter.submitList(messages)); - - mMessageViewModel.hasMessage().observe(getViewLifecycleOwner(), hasMessage -> { - mSwipeRefreshLayout.setRefreshing(false); - if (hasMessage) { - mFetchMessageInfoLinearLayout.setVisibility(View.GONE); - } else { - mFetchMessageInfoLinearLayout.setOnClickListener(null); - showErrorView(R.string.no_messages); - } - }); - - mMessageViewModel.getInitialLoadingState().observe(getViewLifecycleOwner(), networkState -> { - if (networkState.getStatus().equals(NetworkState.Status.SUCCESS)) { - mSwipeRefreshLayout.setRefreshing(false); - } else if (networkState.getStatus().equals(NetworkState.Status.FAILED)) { - mSwipeRefreshLayout.setRefreshing(false); - mFetchMessageInfoLinearLayout.setOnClickListener(view -> { - mFetchMessageInfoLinearLayout.setVisibility(View.GONE); - mMessageViewModel.refresh(); - mAdapter.setNetworkState(null); - }); - showErrorView(R.string.load_messages_failed); - } else { - mSwipeRefreshLayout.setRefreshing(true); - } - }); - - mMessageViewModel.getPaginationNetworkState().observe(getViewLifecycleOwner(), networkState -> { - mAdapter.setNetworkState(networkState); - }); - - mSwipeRefreshLayout.setOnRefreshListener(this::onRefresh); - - return rootView; - } - - private void showErrorView(int stringResId) { - mSwipeRefreshLayout.setRefreshing(false); - mFetchMessageInfoLinearLayout.setVisibility(View.VISIBLE); - mFetchMessageInfoTextView.setText(stringResId); - mGlide.load(R.drawable.error_image).into(mFetchMessageInfoImageView); - } - - @Override - public void applyTheme() { - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); - mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); - mFetchMessageInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); - } - - public void goBackToTop() { - if (mLinearLayoutManager != null) { - mLinearLayoutManager.scrollToPositionWithOffset(0, 0); - } - } - - private void onRefresh() { - mMessageViewModel.refresh(); - mAdapter.setNetworkState(null); - } - - @Override - public void onAttach(@NonNull Context context) { - super.onAttach(context); - mActivity = (BaseActivity) context; - } -} \ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Message.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Message.java index d45385a1..0aa2c439 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Message.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Message.java @@ -1,8 +1,11 @@ package ml.docilealligator.infinityforreddit; +import android.os.Parcel; +import android.os.Parcelable; + import java.util.ArrayList; -public class Message { +public class Message implements Parcelable { static final String TYPE_COMMENT = "t1"; static final String TYPE_ACCOUNT = "t2"; static final String TYPE_LINK = "t3"; @@ -55,6 +58,40 @@ public class Message { } + protected Message(Parcel in) { + kind = in.readString(); + subredditName = in.readString(); + subredditNamePrefixed = in.readString(); + id = in.readString(); + fullname = in.readString(); + subject = in.readString(); + author = in.readString(); + parentFullName = in.readString(); + title = in.readString(); + body = in.readString(); + context = in.readString(); + distinguished = in.readString(); + formattedTime = in.readString(); + wasComment = in.readByte() != 0; + isNew = in.readByte() != 0; + score = in.readInt(); + nComments = in.readInt(); + timeUTC = in.readLong(); + replies = in.createTypedArrayList(Message.CREATOR); + } + + public static final Creator CREATOR = new Creator() { + @Override + public Message createFromParcel(Parcel in) { + return new Message(in); + } + + @Override + public Message[] newArray(int size) { + return new Message[size]; + } + }; + public String getKind() { return kind; } @@ -138,4 +175,32 @@ public class Message { public void setReplies(ArrayList replies) { this.replies = replies; } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(kind); + parcel.writeString(subredditName); + parcel.writeString(subredditNamePrefixed); + parcel.writeString(id); + parcel.writeString(fullname); + parcel.writeString(subject); + parcel.writeString(author); + parcel.writeString(parentFullName); + parcel.writeString(title); + parcel.writeString(body); + parcel.writeString(context); + parcel.writeString(distinguished); + parcel.writeString(formattedTime); + parcel.writeByte((byte) (wasComment ? 1 : 0)); + parcel.writeByte((byte) (isNew ? 1 : 0)); + parcel.writeInt(score); + parcel.writeInt(nComments); + parcel.writeLong(timeUTC); + parcel.writeTypedList(replies); + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java index ef831e4b..a2b37d99 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java @@ -28,8 +28,8 @@ import javax.inject.Named; import ml.docilealligator.infinityforreddit.API.RedditAPI; import ml.docilealligator.infinityforreddit.Account.Account; +import ml.docilealligator.infinityforreddit.Activity.InboxActivity; import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity; -import ml.docilealligator.infinityforreddit.Activity.ViewMessageActivity; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.Utils.APIUtils; import ml.docilealligator.infinityforreddit.Utils.JSONUtils; @@ -149,8 +149,8 @@ public class PullNotificationWorker extends Worker { 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); - intent.putExtra(ViewMessageActivity.EXTRA_NEW_ACCOUNT_NAME, accountName); + Intent intent = new Intent(context, InboxActivity.class); + intent.putExtra(InboxActivity.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)) { @@ -162,18 +162,18 @@ public class PullNotificationWorker extends Worker { 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); - intent.putExtra(ViewMessageActivity.EXTRA_NEW_ACCOUNT_NAME, accountName); + Intent intent = new Intent(context, InboxActivity.class); + intent.putExtra(InboxActivity.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); - intent.putExtra(ViewMessageActivity.EXTRA_NEW_ACCOUNT_NAME, accountName); + Intent intent = new Intent(context, InboxActivity.class); + intent.putExtra(InboxActivity.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); - intent.putExtra(ViewMessageActivity.EXTRA_NEW_ACCOUNT_NAME, accountName); + Intent intent = new Intent(context, InboxActivity.class); + intent.putExtra(InboxActivity.EXTRA_NEW_ACCOUNT_NAME, accountName); PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, accountIndex * 6 + 5, intent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(summaryPendingIntent); } @@ -186,8 +186,8 @@ public class PullNotificationWorker extends Worker { summaryBuilder.setStyle(inboxStyle); - Intent summaryIntent = new Intent(context, ViewMessageActivity.class); - summaryIntent.putExtra(ViewMessageActivity.EXTRA_NEW_ACCOUNT_NAME, accountName); + Intent summaryIntent = new Intent(context, InboxActivity.class); + summaryIntent.putExtra(InboxActivity.EXTRA_NEW_ACCOUNT_NAME, accountName); PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, accountIndex * 6 + 6, summaryIntent, PendingIntent.FLAG_UPDATE_CURRENT); summaryBuilder.setContentIntent(summaryPendingIntent); -- cgit v1.2.3