diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-06-27 06:00:24 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-06-27 06:00:24 +0000 |
commit | 3c482c63ec9057ca0a74e5ed66be5d7720139727 (patch) | |
tree | 2ad93ab812835aa1d3e35c4f94637e80a648adaf | |
parent | f9884167694f94e906860757b51d6600ee5143d4 (diff) | |
download | infinity-for-reddit-3c482c63ec9057ca0a74e5ed66be5d7720139727.tar infinity-for-reddit-3c482c63ec9057ca0a74e5ed66be5d7720139727.tar.gz infinity-for-reddit-3c482c63ec9057ca0a74e5ed66be5d7720139727.tar.bz2 infinity-for-reddit-3c482c63ec9057ca0a74e5ed66be5d7720139727.tar.lz infinity-for-reddit-3c482c63ec9057ca0a74e5ed66be5d7720139727.tar.xz infinity-for-reddit-3c482c63ec9057ca0a74e5ed66be5d7720139727.tar.zst infinity-for-reddit-3c482c63ec9057ca0a74e5ed66be5d7720139727.zip |
Add another tab for PM in ViewMessageActivity.
Diffstat (limited to '')
7 files changed, 190 insertions, 158 deletions
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 d1e9af09..fbc3c9f1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -1054,9 +1054,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb if (mAccessToken == null) { switch (position) { case 0: - return "Popular"; + return getString(R.string.popular); case 1: - return "All"; + return getString(R.string.all); } } else { switch (position) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java index 5e7446bc..8f049922 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java @@ -5,27 +5,23 @@ import android.os.Build; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; -import android.view.View; +import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; -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 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 org.greenrobot.eventbus.EventBus; @@ -37,15 +33,13 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; -import ml.docilealligator.infinityforreddit.Adapter.MessageRecyclerViewAdapter; 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.MessageViewModel; -import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; @@ -67,17 +61,10 @@ public class ViewMessageActivity extends BaseActivity implements ActivityToolbar AppBarLayout mAppBarLayout; @BindView(R.id.toolbar_view_message_activity) Toolbar mToolbar; - @BindView(R.id.swipe_refresh_layout_view_message_activity) - SwipeRefreshLayout mSwipeRefreshLayout; - @BindView(R.id.recycler_view_view_message_activity) - RecyclerView mRecyclerView; - @BindView(R.id.fetch_messages_info_linear_layout_view_message_activity) - LinearLayout mFetchMessageInfoLinearLayout; - @BindView(R.id.fetch_messages_info_image_view_view_message_activity) - ImageView mFetchMessageInfoImageView; - @BindView(R.id.fetch_messages_info_text_view_view_message_activity) - TextView mFetchMessageInfoTextView; - MessageViewModel mMessageViewModel; + @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; @@ -88,12 +75,10 @@ public class ViewMessageActivity extends BaseActivity implements ActivityToolbar SharedPreferences mSharedPreferences; @Inject CustomThemeWrapper mCustomThemeWrapper; + private SectionsPagerAdapter sectionsPagerAdapter; private boolean mNullAccessToken = false; private String mAccessToken; private String mNewAccountName; - private MessageRecyclerViewAdapter mAdapter; - private RequestManager mGlide; - private LinearLayoutManager mLinearLayoutManager; @Override protected void onCreate(Bundle savedInstanceState) { @@ -113,8 +98,6 @@ public class ViewMessageActivity extends BaseActivity implements ActivityToolbar Slidr.attach(this); } - mGlide = Glide.with(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Window window = getWindow(); @@ -125,11 +108,6 @@ public class ViewMessageActivity extends BaseActivity implements ActivityToolbar if (isImmersiveInterface()) { window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); adjustToolbar(mToolbar); - - int navBarHeight = getNavBarHeight(); - if (navBarHeight > 0) { - mRecyclerView.setPadding(0, 0, 0, navBarHeight); - } } } @@ -167,9 +145,7 @@ public class ViewMessageActivity extends BaseActivity implements ActivityToolbar protected void applyCustomTheme() { mCoordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); applyAppBarLayoutAndToolbarTheme(mAppBarLayout, mToolbar); - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); - mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); - mFetchMessageInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + applyTabLayoutTheme(tabLayout); } private void getCurrentAccountAndFetchMessage() { @@ -206,59 +182,10 @@ public class ViewMessageActivity extends BaseActivity implements ActivityToolbar } private void bindView() { - mAdapter = new MessageRecyclerViewAdapter(this, mOauthRetrofit, mCustomThemeWrapper, - mAccessToken, () -> mMessageViewModel.retryLoadingMore()); - mLinearLayoutManager = new LinearLayoutManager(this); - mRecyclerView.setLayoutManager(mLinearLayoutManager); - mRecyclerView.setAdapter(mAdapter); - DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, mLinearLayoutManager.getOrientation()); - mRecyclerView.addItemDecoration(dividerItemDecoration); - - MessageViewModel.Factory factory = new MessageViewModel.Factory(mOauthRetrofit, - getResources().getConfiguration().locale, mAccessToken, FetchMessages.WHERE_INBOX); - mMessageViewModel = new ViewModelProvider(this, factory).get(MessageViewModel.class); - mMessageViewModel.getMessages().observe(this, messages -> mAdapter.submitList(messages)); - - mMessageViewModel.hasMessage().observe(this, hasMessage -> { - mSwipeRefreshLayout.setRefreshing(false); - if (hasMessage) { - mFetchMessageInfoLinearLayout.setVisibility(View.GONE); - } else { - mFetchMessageInfoLinearLayout.setOnClickListener(view -> { - //Do nothing - }); - showErrorView(R.string.no_messages); - } - }); - - mMessageViewModel.getInitialLoadingState().observe(this, 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(this, networkState -> { - mAdapter.setNetworkState(networkState); - }); - - mSwipeRefreshLayout.setOnRefreshListener(this::onRefresh); - } - - private void showErrorView(int stringResId) { - mSwipeRefreshLayout.setRefreshing(false); - mFetchMessageInfoLinearLayout.setVisibility(View.VISIBLE); - mFetchMessageInfoTextView.setText(stringResId); - mGlide.load(R.drawable.error_image).into(mFetchMessageInfoImageView); + sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); + viewPager.setAdapter(sectionsPagerAdapter); + viewPager.setOffscreenPageLimit(2); + tabLayout.setupWithViewPager(viewPager); } @Override @@ -271,8 +198,9 @@ public class ViewMessageActivity extends BaseActivity implements ActivityToolbar @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { if (item.getItemId() == R.id.action_refresh_view_message_activity) { - mMessageViewModel.refresh(); - mAdapter.setNetworkState(null); + if (sectionsPagerAdapter != null) { + sectionsPagerAdapter.refresh(); + } return true; } else if (item.getItemId() == android.R.id.home) { finish(); @@ -302,14 +230,89 @@ public class ViewMessageActivity extends BaseActivity implements ActivityToolbar } } - private void onRefresh() { - mMessageViewModel.refresh(); - } - @Override public void onLongPress() { - if (mLinearLayoutManager != null) { - mLinearLayoutManager.scrollToPositionWithOffset(0, 0); + if (sectionsPagerAdapter != null) { + sectionsPagerAdapter.goBackToTop(); + } + } + + 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/Adapter/MessageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MessageRecyclerViewAdapter.java index 17f9ff2f..0a9c9e5f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MessageRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MessageRecyclerViewAdapter.java @@ -12,6 +12,7 @@ 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; @@ -29,6 +30,7 @@ import io.noties.markwon.simple.ext.SimpleExtPlugin; import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity; import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.FetchMessages; import ml.docilealligator.infinityforreddit.Message; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; @@ -54,6 +56,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl private Retrofit mOauthRetrofit; private Markwon mMarkwon; private String mAccessToken; + private int mMessageType; private NetworkState networkState; private RetryLoadingMoreCallback mRetryLoadingMoreCallback; private int mColorAccent; @@ -67,7 +70,8 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl public MessageRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, CustomThemeWrapper customThemeWrapper, - String accessToken, RetryLoadingMoreCallback retryLoadingMoreCallback) { + String accessToken, String where, + RetryLoadingMoreCallback retryLoadingMoreCallback) { super(DIFF_CALLBACK); mContext = context; mOauthRetrofit = oauthRetrofit; @@ -98,6 +102,8 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl ) .build(); mAccessToken = accessToken; + mMessageType = where.equals(FetchMessages.WHERE_MESSAGES) ? + FetchMessages.MESSAGE_TYPE_PRIVATE_MESSAGE : FetchMessages.MESSAGE_TYPE_NOTIFICATION; mColorAccent = customThemeWrapper.getColorAccent(); mMessageBackgroundColor = customThemeWrapper.getCardViewBackgroundColor(); @@ -132,7 +138,6 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl } if (message.wasComment()) { - ((DataViewHolder) holder).authorTextView.setTextColor(mUsernameColor); ((DataViewHolder) holder).titleTextView.setText(message.getTitle()); } else { ((DataViewHolder) holder).titleTextView.setVisibility(View.GONE); @@ -149,6 +154,8 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl Intent intent = new Intent(mContext, LinkResolverActivity.class); intent.setData(uri); mContext.startActivity(intent); + } else if (mMessageType == FetchMessages.MESSAGE_TYPE_PRIVATE_MESSAGE) { + Toast.makeText(mContext, "To be implemented", Toast.LENGTH_SHORT).show(); } if (message.isNew()) { @@ -171,11 +178,9 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl }); ((DataViewHolder) holder).authorTextView.setOnClickListener(view -> { - if (message.wasComment()) { - Intent intent = new Intent(mContext, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, message.getAuthor()); - mContext.startActivity(intent); - } + Intent intent = new Intent(mContext, ViewUserDetailActivity.class); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, message.getAuthor()); + mContext.startActivity(intent); }); ((DataViewHolder) holder).contentCustomMarkwonView.setOnClickListener(view -> ((DataViewHolder) holder).itemView.performClick()); @@ -211,7 +216,6 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl if (holder instanceof DataViewHolder) { ((DataViewHolder) holder).itemView.setBackgroundColor(mMessageBackgroundColor); ((DataViewHolder) holder).titleTextView.setVisibility(View.VISIBLE); - ((DataViewHolder) holder).authorTextView.setTextColor(mPrimaryTextColor); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 9e763433..847afb43 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -50,6 +50,7 @@ import ml.docilealligator.infinityforreddit.Fragment.SubredditListingFragment; import ml.docilealligator.infinityforreddit.Fragment.SubscribedSubredditsListingFragment; import ml.docilealligator.infinityforreddit.Fragment.UserListingFragment; import ml.docilealligator.infinityforreddit.Fragment.ViewImgurVideoFragment; +import ml.docilealligator.infinityforreddit.Fragment.ViewMessagesFragment; import ml.docilealligator.infinityforreddit.Service.DownloadRedditVideoService; import ml.docilealligator.infinityforreddit.Service.SubmitPostService; import ml.docilealligator.infinityforreddit.Settings.AdvancedPreferenceFragment; @@ -173,4 +174,6 @@ public interface AppComponent { void inject(DownloadRedditVideoService downloadRedditVideoService); void inject(MultiRedditListingFragment multiRedditListingFragment); + + void inject(ViewMessagesFragment viewMessagesFragment); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewMessagesFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewMessagesFragment.java index 6d2d7061..8f7cdd4f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewMessagesFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewMessagesFragment.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit.Fragment; +import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.view.LayoutInflater; @@ -9,22 +10,27 @@ 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.FetchMessages; 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; @@ -33,6 +39,8 @@ 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) @@ -58,6 +66,7 @@ public class ViewMessagesFragment extends Fragment implements FragmentCommunicat private MessageRecyclerViewAdapter mAdapter; private RequestManager mGlide; private LinearLayoutManager mLinearLayoutManager; + private BaseActivity mActivity; public ViewMessagesFragment() { // Required empty public constructor @@ -68,8 +77,34 @@ public class ViewMessagesFragment extends Fragment implements FragmentCommunicat 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, FetchMessages.WHERE_INBOX); + getResources().getConfiguration().locale, mAccessToken, where); mMessageViewModel = new ViewModelProvider(this, factory).get(MessageViewModel.class); mMessageViewModel.getMessages().observe(getViewLifecycleOwner(), messages -> mAdapter.submitList(messages)); @@ -78,9 +113,7 @@ public class ViewMessagesFragment extends Fragment implements FragmentCommunicat if (hasMessage) { mFetchMessageInfoLinearLayout.setVisibility(View.GONE); } else { - mFetchMessageInfoLinearLayout.setOnClickListener(view -> { - //Do nothing - }); + mFetchMessageInfoLinearLayout.setOnClickListener(null); showErrorView(R.string.no_messages); } }); @@ -119,10 +152,25 @@ public class ViewMessagesFragment extends Fragment implements FragmentCommunicat @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/res/layout/activity_view_message.xml b/app/src/main/res/layout/activity_view_message.xml index 1ce1e9db..8d357f52 100644 --- a/app/src/main/res/layout/activity_view_message.xml +++ b/app/src/main/res/layout/activity_view_message.xml @@ -31,52 +31,24 @@ </com.google.android.material.appbar.CollapsingToolbarLayout> - </com.google.android.material.appbar.AppBarLayout> - - <RelativeLayout - android:layout_width="match_parent" - android:layout_height="match_parent" - app:layout_behavior="@string/appbar_scrolling_view_behavior" > - - <androidx.swiperefreshlayout.widget.SwipeRefreshLayout - android:id="@+id/swipe_refresh_layout_view_message_activity" - android:layout_width="match_parent" - android:layout_height="match_parent" - app:layout_behavior="@string/appbar_scrolling_view_behavior"> - - <androidx.recyclerview.widget.RecyclerView - android:id="@+id/recycler_view_view_message_activity" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:clipToPadding="false"/> - - </androidx.swiperefreshlayout.widget.SwipeRefreshLayout> - - <LinearLayout - android:id="@+id/fetch_messages_info_linear_layout_view_message_activity" + <com.google.android.material.tabs.TabLayout + android:id="@+id/tab_layout_view_message_activity" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_centerInParent="true" - android:gravity="center" - android:orientation="vertical" - android:visibility="gone"> - - <ImageView - android:id="@+id/fetch_messages_info_image_view_view_message_activity" - android:layout_width="150dp" - android:layout_height="wrap_content" /> - - <TextView - android:id="@+id/fetch_messages_info_text_view_view_message_activity" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginTop="16dp" - android:gravity="center" - android:textSize="?attr/font_default" - android:fontFamily="?attr/font_family" /> + android:layout_gravity="bottom" + app:layout_scrollFlags="scroll|enterAlways" + app:tabGravity="fill" + app:tabIndicatorHeight="3dp" + app:tabMode="fixed" + app:tabRippleColor="?attr/colorControlHighlight" + app:tabUnboundedRipple="false" /> - </LinearLayout> + </com.google.android.material.appbar.AppBarLayout> - </RelativeLayout> + <androidx.viewpager.widget.ViewPager + android:id="@+id/view_pager_view_message_activity" + android:layout_width="match_parent" + android:layout_height="match_parent" + app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1eecbe16..18faf6b8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -760,6 +760,8 @@ <string name="home">Home</string> <string name="popular">Popular</string> + <string name="notifications">Notifications</string> + <string name="messages">Messages</string> <string name="fetch_gfycat_video_failed">Fetch Gfycat video failed</string> <string name="fetch_redgifs_video_failed">Fetch Redgifs video failed</string> |