diff options
Diffstat (limited to '')
7 files changed, 241 insertions, 324 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java index ba6d55f0..929ff3f7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java @@ -53,6 +53,7 @@ import ml.docilealligator.infinityforreddit.adapters.CommentsListingRecyclerView import ml.docilealligator.infinityforreddit.comment.CommentViewModel; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; +import ml.docilealligator.infinityforreddit.databinding.FragmentCommentsListingBinding; import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -67,18 +68,6 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni public static final String EXTRA_USERNAME = "EN"; public static final String EXTRA_ARE_SAVED_COMMENTS = "EISC"; - @BindView(R.id.coordinator_layout_comments_listing_fragment) - CoordinatorLayout mCoordinatorLayout; - @BindView(R.id.swipe_refresh_layout_view_comments_listing_fragment) - SwipeRefreshLayout mSwipeRefreshLayout; - @BindView(R.id.recycler_view_comments_listing_fragment) - RecyclerView mCommentRecyclerView; - @BindView(R.id.fetch_comments_info_linear_layout_comments_listing_fragment) - LinearLayout mFetchCommentInfoLinearLayout; - @BindView(R.id.fetch_comments_info_image_view_comments_listing_fragment) - ImageView mFetchCommentInfoImageView; - @BindView(R.id.fetch_comments_info_text_view_comments_listing_fragment) - TextView mFetchCommentInfoTextView; CommentViewModel mCommentViewModel; @Inject @Named("no_oauth") @@ -117,6 +106,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni private int swipeRightAction; private float swipeActionThreshold; private ItemTouchHelper touchHelper; + private FragmentCommentsListingBinding binding; public CommentsListingFragment() { // Required empty public constructor @@ -126,12 +116,10 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.fragment_comments_listing, container, false); + binding = FragmentCommentsListingBinding.inflate(inflater, container, false); ((Infinity) mActivity.getApplication()).getAppComponent().inject(this); - ButterKnife.bind(this, rootView); - EventBus.getDefault().register(this); applyTheme(); @@ -141,12 +129,12 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni Resources resources = getResources(); if ((mActivity instanceof BaseActivity && ((BaseActivity) mActivity).isImmersiveInterface())) { - mCommentRecyclerView.setPadding(0, 0, 0, ((BaseActivity) mActivity).getNavBarHeight()); + binding.recyclerViewCommentsListingFragment.setPadding(0, 0, 0, ((BaseActivity) mActivity).getNavBarHeight()); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); if (navBarResourceId > 0) { - mCommentRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); + binding.recyclerViewCommentsListingFragment.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); } } @@ -183,7 +171,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni if (touchHelper != null) { exceedThreshold = false; touchHelper.attachToRecyclerView(null); - touchHelper.attachToRecyclerView(mCommentRecyclerView); + touchHelper.attachToRecyclerView(binding.recyclerViewCommentsListingFragment); } } @@ -251,18 +239,18 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni }); if (enableSwipeAction) { - touchHelper.attachToRecyclerView(mCommentRecyclerView); + touchHelper.attachToRecyclerView(binding.recyclerViewCommentsListingFragment); } new Handler().postDelayed(() -> bindView(resources), 0); - return rootView; + return binding.getRoot(); } private void bindView(Resources resources) { if (mActivity != null && !mActivity.isFinishing() && !mActivity.isDestroyed()) { mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity); - mCommentRecyclerView.setLayoutManager(mLinearLayoutManager); + binding.recyclerViewCommentsListingFragment.setLayoutManager(mLinearLayoutManager); String username = getArguments().getString(EXTRA_USERNAME); String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, SortType.Type.NEW.name()); @@ -278,10 +266,10 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni mActivity.accessToken, mActivity.accountName, username, () -> mCommentViewModel.retryLoadingMore()); - mCommentRecyclerView.setAdapter(mAdapter); + binding.recyclerViewCommentsListingFragment.setAdapter(mAdapter); if (mActivity instanceof RecyclerViewContentScrollingInterface) { - mCommentRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + binding.recyclerViewCommentsListingFragment.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { if (dy > 0) { @@ -308,30 +296,30 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni mCommentViewModel.getComments().observe(getViewLifecycleOwner(), comments -> mAdapter.submitList(comments)); mCommentViewModel.hasComment().observe(getViewLifecycleOwner(), hasComment -> { - mSwipeRefreshLayout.setRefreshing(false); + binding.swipeRefreshLayoutViewCommentsListingFragment.setRefreshing(false); if (hasComment) { - mFetchCommentInfoLinearLayout.setVisibility(View.GONE); + binding.fetchCommentsInfoLinearLayoutCommentsListingFragment.setVisibility(View.GONE); } else { - mFetchCommentInfoLinearLayout.setOnClickListener(null); + binding.fetchCommentsInfoLinearLayoutCommentsListingFragment.setOnClickListener(null); showErrorView(R.string.no_comments); } }); mCommentViewModel.getInitialLoadingState().observe(getViewLifecycleOwner(), networkState -> { if (networkState.getStatus().equals(NetworkState.Status.SUCCESS)) { - mSwipeRefreshLayout.setRefreshing(false); + binding.swipeRefreshLayoutViewCommentsListingFragment.setRefreshing(false); } else if (networkState.getStatus().equals(NetworkState.Status.FAILED)) { - mSwipeRefreshLayout.setRefreshing(false); - mFetchCommentInfoLinearLayout.setOnClickListener(view -> refresh()); + binding.swipeRefreshLayoutViewCommentsListingFragment.setRefreshing(false); + binding.fetchCommentsInfoLinearLayoutCommentsListingFragment.setOnClickListener(view -> refresh()); showErrorView(R.string.load_comments_failed); } else { - mSwipeRefreshLayout.setRefreshing(true); + binding.swipeRefreshLayoutViewCommentsListingFragment.setRefreshing(true); } }); mCommentViewModel.getPaginationNetworkState().observe(getViewLifecycleOwner(), networkState -> mAdapter.setNetworkState(networkState)); - mSwipeRefreshLayout.setOnRefreshListener(() -> mCommentViewModel.refresh()); + binding.swipeRefreshLayoutViewCommentsListingFragment.setOnRefreshListener(() -> mCommentViewModel.refresh()); } } @@ -380,27 +368,27 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni @Override public void refresh() { - mFetchCommentInfoLinearLayout.setVisibility(View.GONE); + binding.fetchCommentsInfoLinearLayoutCommentsListingFragment.setVisibility(View.GONE); mCommentViewModel.refresh(); mAdapter.setNetworkState(null); } @Override public void applyTheme() { - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(customThemeWrapper.getCircularProgressBarBackground()); - mSwipeRefreshLayout.setColorSchemeColors(customThemeWrapper.getColorAccent()); - mFetchCommentInfoTextView.setTextColor(customThemeWrapper.getSecondaryTextColor()); + binding.swipeRefreshLayoutViewCommentsListingFragment.setProgressBackgroundColorSchemeColor(customThemeWrapper.getCircularProgressBarBackground()); + binding.swipeRefreshLayoutViewCommentsListingFragment.setColorSchemeColors(customThemeWrapper.getColorAccent()); + binding.fetchCommentsInfoTextViewCommentsListingFragment.setTextColor(customThemeWrapper.getSecondaryTextColor()); if (mActivity.typeface != null) { - mFetchCommentInfoTextView.setTypeface(mActivity.typeface); + binding.fetchCommentsInfoTextViewCommentsListingFragment.setTypeface(mActivity.typeface); } } private void showErrorView(int stringResId) { if (mActivity != null && isAdded()) { - mSwipeRefreshLayout.setRefreshing(false); - mFetchCommentInfoLinearLayout.setVisibility(View.VISIBLE); - mFetchCommentInfoTextView.setText(stringResId); - mGlide.load(R.drawable.error_image).into(mFetchCommentInfoImageView); + binding.swipeRefreshLayoutViewCommentsListingFragment.setRefreshing(false); + binding.fetchCommentsInfoLinearLayoutCommentsListingFragment.setVisibility(View.VISIBLE); + binding.fetchCommentsInfoTextViewCommentsListingFragment.setText(stringResId); + mGlide.load(R.drawable.error_image).into(binding.fetchCommentsInfoImageViewCommentsListingFragment); } } @@ -426,7 +414,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni String dataSavingMode = mSharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF); if (dataSavingMode.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) { mAdapter.setDataSavingMode(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_CELLULAR); - refreshAdapter(mCommentRecyclerView, mAdapter); + refreshAdapter(binding.recyclerViewCommentsListingFragment, mAdapter); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java index c6aecc88..24281520 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java @@ -40,6 +40,7 @@ import ml.docilealligator.infinityforreddit.activities.SubscribedThingListingAct import ml.docilealligator.infinityforreddit.adapters.FollowedUsersRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; +import ml.docilealligator.infinityforreddit.databinding.FragmentFollowedUsersListingBinding; import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserViewModel; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import retrofit2.Retrofit; @@ -50,16 +51,6 @@ import retrofit2.Retrofit; */ public class FollowedUsersListingFragment extends Fragment implements FragmentCommunicator { - @BindView(R.id.swipe_refresh_layout_followed_users_listing_fragment) - SwipeRefreshLayout mSwipeRefreshLayout; - @BindView(R.id.recycler_view_followed_users_listing_fragment) - RecyclerView mRecyclerView; - @BindView(R.id.no_subscriptions_linear_layout_followed_users_listing_fragment) - LinearLayout mLinearLayout; - @BindView(R.id.no_subscriptions_image_view_followed_users_listing_fragment) - ImageView mImageView; - @BindView(R.id.error_text_view_followed_users_listing_fragment) - TextView mErrorTextView; @Inject @Named("oauth") Retrofit mOauthRetrofit; @@ -76,17 +67,16 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo private BaseActivity mActivity; private RequestManager mGlide; private LinearLayoutManagerBugFixed mLinearLayoutManager; + private FragmentFollowedUsersListingBinding binding; public FollowedUsersListingFragment() { // Required empty public constructor } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.fragment_followed_users_listing, container, false); - - ButterKnife.bind(this, rootView); + binding = FragmentFollowedUsersListingBinding.inflate(inflater, container, false); ((Infinity) mActivity.getApplication()).getAppComponent().inject(this); @@ -95,56 +85,56 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo Resources resources = getResources(); if ((mActivity instanceof BaseActivity && ((BaseActivity) mActivity).isImmersiveInterface())) { - mRecyclerView.setPadding(0, 0, 0, ((BaseActivity) mActivity).getNavBarHeight()); + binding.recyclerViewFollowedUsersListingFragment.setPadding(0, 0, 0, ((BaseActivity) mActivity).getNavBarHeight()); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); if (navBarResourceId > 0) { - mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); + binding.recyclerViewFollowedUsersListingFragment.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); } } mGlide = Glide.with(this); if (mActivity.accountName.equals(Account.ANONYMOUS_ACCOUNT)) { - mSwipeRefreshLayout.setEnabled(false); + binding.swipeRefreshLayoutFollowedUsersListingFragment.setEnabled(false); } mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity); - mRecyclerView.setLayoutManager(mLinearLayoutManager); + binding.recyclerViewFollowedUsersListingFragment.setLayoutManager(mLinearLayoutManager); FollowedUsersRecyclerViewAdapter adapter = new FollowedUsersRecyclerViewAdapter(mActivity, mExecutor, mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, mActivity.accessToken, mActivity.accountName); - mRecyclerView.setAdapter(adapter); - new FastScrollerBuilder(mRecyclerView).useMd2Style().build(); + binding.recyclerViewFollowedUsersListingFragment.setAdapter(adapter); + new FastScrollerBuilder(binding.recyclerViewFollowedUsersListingFragment).useMd2Style().build(); mSubscribedUserViewModel = new ViewModelProvider(this, new SubscribedUserViewModel.Factory(mActivity.getApplication(), mRedditDataRoomDatabase, mActivity.accountName)) .get(SubscribedUserViewModel.class); mSubscribedUserViewModel.getAllSubscribedUsers().observe(getViewLifecycleOwner(), subscribedUserData -> { - mSwipeRefreshLayout.setRefreshing(false); + binding.swipeRefreshLayoutFollowedUsersListingFragment.setRefreshing(false); if (subscribedUserData == null || subscribedUserData.size() == 0) { - mRecyclerView.setVisibility(View.GONE); - mLinearLayout.setVisibility(View.VISIBLE); - mGlide.load(R.drawable.error_image).into(mImageView); + binding.recyclerViewFollowedUsersListingFragment.setVisibility(View.GONE); + binding.noSubscriptionsLinearLayoutFollowedUsersListingFragment.setVisibility(View.VISIBLE); + mGlide.load(R.drawable.error_image).into(binding.noSubscriptionsImageViewFollowedUsersListingFragment); } else { - mLinearLayout.setVisibility(View.GONE); - mRecyclerView.setVisibility(View.VISIBLE); - mGlide.clear(mImageView); + binding.noSubscriptionsLinearLayoutFollowedUsersListingFragment.setVisibility(View.GONE); + binding.recyclerViewFollowedUsersListingFragment.setVisibility(View.VISIBLE); + mGlide.clear(binding.noSubscriptionsImageViewFollowedUsersListingFragment); } adapter.setSubscribedUsers(subscribedUserData); }); mSubscribedUserViewModel.getAllFavoriteSubscribedUsers().observe(getViewLifecycleOwner(), favoriteSubscribedUserData -> { - mSwipeRefreshLayout.setRefreshing(false); + binding.swipeRefreshLayoutFollowedUsersListingFragment.setRefreshing(false); if (favoriteSubscribedUserData != null && favoriteSubscribedUserData.size() > 0) { - mLinearLayout.setVisibility(View.GONE); - mRecyclerView.setVisibility(View.VISIBLE); - mGlide.clear(mImageView); + binding.noSubscriptionsLinearLayoutFollowedUsersListingFragment.setVisibility(View.GONE); + binding.recyclerViewFollowedUsersListingFragment.setVisibility(View.VISIBLE); + mGlide.clear(binding.noSubscriptionsImageViewFollowedUsersListingFragment); } adapter.setFavoriteSubscribedUsers(favoriteSubscribedUserData); }); - return rootView; + return binding.getRoot(); } @Override @@ -155,21 +145,21 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo @Override public void stopRefreshProgressbar() { - mSwipeRefreshLayout.setRefreshing(false); + binding.swipeRefreshLayoutFollowedUsersListingFragment.setRefreshing(false); } @Override public void applyTheme() { if (mActivity instanceof SubscribedThingListingActivity) { - mSwipeRefreshLayout.setOnRefreshListener(() -> ((SubscribedThingListingActivity) mActivity).loadSubscriptions(true)); - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); - mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); + binding.swipeRefreshLayoutFollowedUsersListingFragment.setOnRefreshListener(() -> ((SubscribedThingListingActivity) mActivity).loadSubscriptions(true)); + binding.swipeRefreshLayoutFollowedUsersListingFragment.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); + binding.swipeRefreshLayoutFollowedUsersListingFragment.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); } else { - mSwipeRefreshLayout.setEnabled(false); + binding.swipeRefreshLayoutFollowedUsersListingFragment.setEnabled(false); } - mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + binding.errorTextViewFollowedUsersListingFragment.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); if (mActivity.typeface != null) { - mErrorTextView.setTypeface(mActivity.typeface); + binding.errorTextViewFollowedUsersListingFragment.setTypeface(mActivity.typeface); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java index e88e549f..fc16e20d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java @@ -61,9 +61,6 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Provider; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; import ml.docilealligator.infinityforreddit.FetchPostFilterReadPostsAndConcatenatedSubredditNames; import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; @@ -78,8 +75,9 @@ import ml.docilealligator.infinityforreddit.apis.StreamableAPI; import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon; import ml.docilealligator.infinityforreddit.asynctasks.LoadUserData; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.customviews.CustomToroContainer; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; +import ml.docilealligator.infinityforreddit.databinding.FragmentHistoryPostBinding; +import ml.docilealligator.infinityforreddit.databinding.FragmentPostBinding; import ml.docilealligator.infinityforreddit.events.ChangeAutoplayNsfwVideosEvent; import ml.docilealligator.infinityforreddit.events.ChangeCompactLayoutToolbarHiddenByDefaultEvent; import ml.docilealligator.infinityforreddit.events.ChangeDataSavingModeEvent; @@ -144,16 +142,6 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato private static final String POST_FILTER_STATE = "PFS"; private static final String POST_FRAGMENT_ID_STATE = "PFIS"; - @BindView(R.id.swipe_refresh_layout_history_post_fragment) - SwipeRefreshLayout mSwipeRefreshLayout; - @BindView(R.id.recycler_view_history_post_fragment) - CustomToroContainer mPostRecyclerView; - @BindView(R.id.fetch_post_info_linear_layout_history_post_fragment) - LinearLayout mFetchPostInfoLinearLayout; - @BindView(R.id.fetch_post_info_image_view_history_post_fragment) - ImageView mFetchPostInfoImageView; - @BindView(R.id.fetch_post_info_text_view_history_post_fragment) - TextView mFetchPostInfoTextView; HistoryPostViewModel mHistoryPostViewModel; @Inject @Named("no_oauth") @@ -225,9 +213,9 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato private float swipeActionThreshold; private ItemTouchHelper touchHelper; private ArrayList<String> readPosts; - private Unbinder unbinder; private final Map<String, String> subredditOrUserIcons = new HashMap<>(); private int historyType; + private FragmentHistoryPostBinding binding; public HistoryPostFragment() { // Required empty public constructor @@ -241,22 +229,20 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - View rootView = inflater.inflate(R.layout.fragment_history_post, container, false); + binding = FragmentHistoryPostBinding.inflate(inflater, container, false); ((Infinity) activity.getApplication()).getAppComponent().inject(this); - unbinder = ButterKnife.bind(this, rootView); - setHasOptionsMenu(true); EventBus.getDefault().register(this); applyTheme(); - mPostRecyclerView.addOnWindowFocusChangedListener(this::onWindowFocusChanged); + binding.recyclerViewHistoryPostFragment.addOnWindowFocusChangedListener(this::onWindowFocusChanged); lazyModeHandler = new Handler(); @@ -274,12 +260,12 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato Resources resources = getResources(); if ((activity != null && activity.isImmersiveInterface())) { - mPostRecyclerView.setPadding(0, 0, 0, ((BaseActivity) activity).getNavBarHeight()); + binding.recyclerViewHistoryPostFragment.setPadding(0, 0, 0, ((BaseActivity) activity).getNavBarHeight()); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); if (navBarResourceId > 0) { - mPostRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); + binding.recyclerViewHistoryPostFragment.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); } } @@ -326,8 +312,8 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato } }; - mSwipeRefreshLayout.setEnabled(mSharedPreferences.getBoolean(SharedPreferencesUtils.PULL_TO_REFRESH, true)); - mSwipeRefreshLayout.setOnRefreshListener(this::refresh); + binding.swipeRefreshLayoutHistoryPostFragment.setEnabled(mSharedPreferences.getBoolean(SharedPreferencesUtils.PULL_TO_REFRESH, true)); + binding.swipeRefreshLayoutHistoryPostFragment.setOnRefreshListener(this::refresh); int recyclerViewPosition = 0; if (savedInstanceState != null) { @@ -342,7 +328,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato historyPostFragmentId = System.currentTimeMillis() + new Random().nextInt(1000); } - mPostRecyclerView.setOnTouchListener((view, motionEvent) -> { + binding.recyclerViewHistoryPostFragment.setOnTouchListener((view, motionEvent) -> { if (isInLazyMode) { pauseLazyMode(true); } @@ -350,7 +336,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato }); if (activity instanceof RecyclerViewContentScrollingInterface) { - mPostRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + binding.recyclerViewHistoryPostFragment.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { if (dy > 0) { @@ -414,7 +400,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato @Override public void delayTransition() { - TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition()); + TransitionManager.beginDelayedTransition(binding.recyclerViewHistoryPostFragment, new AutoTransition()); } }); } @@ -422,17 +408,17 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato int nColumns = getNColumns(resources); if (nColumns == 1) { mLinearLayoutManager = new LinearLayoutManagerBugFixed(activity); - mPostRecyclerView.setLayoutManager(mLinearLayoutManager); + binding.recyclerViewHistoryPostFragment.setLayoutManager(mLinearLayoutManager); } else { mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(nColumns, StaggeredGridLayoutManager.VERTICAL); - mPostRecyclerView.setLayoutManager(mStaggeredGridLayoutManager); + binding.recyclerViewHistoryPostFragment.setLayoutManager(mStaggeredGridLayoutManager); StaggeredGridLayoutManagerItemOffsetDecoration itemDecoration = new StaggeredGridLayoutManagerItemOffsetDecoration(activity, R.dimen.staggeredLayoutManagerItemOffset, nColumns); - mPostRecyclerView.addItemDecoration(itemDecoration); + binding.recyclerViewHistoryPostFragment.addItemDecoration(itemDecoration); } if (recyclerViewPosition > 0) { - mPostRecyclerView.scrollToPosition(recyclerViewPosition); + binding.recyclerViewHistoryPostFragment.scrollToPosition(recyclerViewPosition); } if (postFilter == null) { @@ -486,7 +472,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato if (touchHelper != null) { exceedThreshold = false; touchHelper.attachToRecyclerView(null); - touchHelper.attachToRecyclerView(mPostRecyclerView); + touchHelper.attachToRecyclerView(binding.recyclerViewHistoryPostFragment); } } @@ -555,11 +541,11 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato if (nColumns == 1 && mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SWIPE_ACTION, false)) { swipeActionEnabled = true; - touchHelper.attachToRecyclerView(mPostRecyclerView); + touchHelper.attachToRecyclerView(binding.recyclerViewHistoryPostFragment); } - mPostRecyclerView.setAdapter(mAdapter); - mPostRecyclerView.setCacheManager(mAdapter); - mPostRecyclerView.setPlayerInitializer(order -> { + binding.recyclerViewHistoryPostFragment.setAdapter(mAdapter); + binding.recyclerViewHistoryPostFragment.setCacheManager(mAdapter); + binding.recyclerViewHistoryPostFragment.setPlayerInitializer(order -> { VolumeInfo volumeInfo = new VolumeInfo(true, 0f); return new PlaybackInfo(INDEX_UNSET, TIME_UNSET, volumeInfo); }); @@ -576,8 +562,8 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato if (isInLazyMode) { resumeLazyMode(false); } - if (mAdapter != null && mPostRecyclerView != null) { - mPostRecyclerView.onWindowVisibilityChanged(View.VISIBLE); + if (mAdapter != null && binding.recyclerViewHistoryPostFragment != null) { + binding.recyclerViewHistoryPostFragment.onWindowVisibilityChanged(View.VISIBLE); } } @@ -664,7 +650,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato LoadState refreshLoadState = combinedLoadStates.getRefresh(); LoadState appendLoadState = combinedLoadStates.getAppend(); - mSwipeRefreshLayout.setRefreshing(refreshLoadState instanceof LoadState.Loading); + binding.swipeRefreshLayoutHistoryPostFragment.setRefreshing(refreshLoadState instanceof LoadState.Loading); if (refreshLoadState instanceof LoadState.NotLoading) { if (refreshLoadState.getEndOfPaginationReached() && mAdapter.getItemCount() < 1) { noPostFound(); @@ -672,7 +658,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato hasPost = true; } } else if (refreshLoadState instanceof LoadState.Error) { - mFetchPostInfoLinearLayout.setOnClickListener(view -> refresh()); + binding.fetchPostInfoLinearLayoutHistoryPostFragment.setOnClickListener(view -> refresh()); showErrorView(R.string.load_posts_error); } if (!(refreshLoadState instanceof LoadState.Loading) && appendLoadState instanceof LoadState.NotLoading) { @@ -683,7 +669,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato return null; }); - mPostRecyclerView.setAdapter(mAdapter.withLoadStateFooter(new Paging3LoadingStateAdapter(activity, mCustomThemeWrapper, R.string.load_more_posts_error, + binding.recyclerViewHistoryPostFragment.setAdapter(mAdapter.withLoadStateFooter(new Paging3LoadingStateAdapter(activity, mCustomThemeWrapper, R.string.load_more_posts_error, view -> mAdapter.retry()))); } @@ -693,7 +679,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato stopLazyMode(); } - mFetchPostInfoLinearLayout.setOnClickListener(null); + binding.fetchPostInfoLinearLayoutHistoryPostFragment.setOnClickListener(null); showErrorView(R.string.no_posts); } @@ -743,7 +729,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato @Override public void refresh() { - mFetchPostInfoLinearLayout.setVisibility(View.GONE); + binding.fetchPostInfoLinearLayoutHistoryPostFragment.setVisibility(View.GONE); hasPost = false; if (isInLazyMode) { stopLazyMode(); @@ -754,10 +740,10 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato private void showErrorView(int stringResId) { if (activity != null && isAdded()) { - mSwipeRefreshLayout.setRefreshing(false); - mFetchPostInfoLinearLayout.setVisibility(View.VISIBLE); - mFetchPostInfoTextView.setText(stringResId); - mGlide.load(R.drawable.error_image).into(mFetchPostInfoImageView); + binding.swipeRefreshLayoutHistoryPostFragment.setRefreshing(false); + binding.fetchPostInfoLinearLayoutHistoryPostFragment.setVisibility(View.VISIBLE); + binding.fetchPostInfoTextViewHistoryPostFragment.setText(stringResId); + mGlide.load(R.drawable.error_image).into(binding.fetchPostInfoImageViewHistoryPostFragment); } } @@ -869,25 +855,25 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato int nColumns = getNColumns(getResources()); if (nColumns == 1) { mLinearLayoutManager = new LinearLayoutManagerBugFixed(activity); - if (mPostRecyclerView.getItemDecorationCount() > 0) { - mPostRecyclerView.removeItemDecorationAt(0); + if (binding.recyclerViewHistoryPostFragment.getItemDecorationCount() > 0) { + binding.recyclerViewHistoryPostFragment.removeItemDecorationAt(0); } - mPostRecyclerView.setLayoutManager(mLinearLayoutManager); + binding.recyclerViewHistoryPostFragment.setLayoutManager(mLinearLayoutManager); mStaggeredGridLayoutManager = null; } else { mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(nColumns, StaggeredGridLayoutManager.VERTICAL); - if (mPostRecyclerView.getItemDecorationCount() > 0) { - mPostRecyclerView.removeItemDecorationAt(0); + if (binding.recyclerViewHistoryPostFragment.getItemDecorationCount() > 0) { + binding.recyclerViewHistoryPostFragment.removeItemDecorationAt(0); } - mPostRecyclerView.setLayoutManager(mStaggeredGridLayoutManager); + binding.recyclerViewHistoryPostFragment.setLayoutManager(mStaggeredGridLayoutManager); StaggeredGridLayoutManagerItemOffsetDecoration itemDecoration = new StaggeredGridLayoutManagerItemOffsetDecoration(activity, R.dimen.staggeredLayoutManagerItemOffset, nColumns); - mPostRecyclerView.addItemDecoration(itemDecoration); + binding.recyclerViewHistoryPostFragment.addItemDecoration(itemDecoration); mLinearLayoutManager = null; } if (previousPosition > 0) { - mPostRecyclerView.scrollToPosition(previousPosition); + binding.recyclerViewHistoryPostFragment.scrollToPosition(previousPosition); } if (mAdapter != null) { @@ -898,11 +884,11 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato @Override public void applyTheme() { - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); - mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); - mFetchPostInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + binding.swipeRefreshLayoutHistoryPostFragment.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); + binding.swipeRefreshLayoutHistoryPostFragment.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); + binding.fetchPostInfoTextViewHistoryPostFragment.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); if (activity.typeface != null) { - mFetchPostInfoTextView.setTypeface(activity.typeface); + binding.fetchPostInfoTextViewHistoryPostFragment.setTypeface(activity.typeface); } } @@ -947,13 +933,13 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato previousPosition = mStaggeredGridLayoutManager.findFirstVisibleItemPositions(into)[0]; } - RecyclerView.LayoutManager layoutManager = mPostRecyclerView.getLayoutManager(); - mPostRecyclerView.setAdapter(null); - mPostRecyclerView.setLayoutManager(null); - mPostRecyclerView.setAdapter(mAdapter); - mPostRecyclerView.setLayoutManager(layoutManager); + RecyclerView.LayoutManager layoutManager = binding.recyclerViewHistoryPostFragment.getLayoutManager(); + binding.recyclerViewHistoryPostFragment.setAdapter(null); + binding.recyclerViewHistoryPostFragment.setLayoutManager(null); + binding.recyclerViewHistoryPostFragment.setAdapter(mAdapter); + binding.recyclerViewHistoryPostFragment.setLayoutManager(layoutManager); if (previousPosition > 0) { - mPostRecyclerView.scrollToPosition(previousPosition); + binding.recyclerViewHistoryPostFragment.scrollToPosition(previousPosition); } } @@ -977,23 +963,15 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato if (isInLazyMode) { pauseLazyMode(false); } - if (mAdapter != null && mPostRecyclerView != null) { - mPostRecyclerView.onWindowVisibilityChanged(View.GONE); + if (mAdapter != null) { + binding.recyclerViewHistoryPostFragment.onWindowVisibilityChanged(View.GONE); } } @Override - public void onDestroyView() { - super.onDestroyView(); - unbinder.unbind(); - } - - @Override public void onDestroy() { EventBus.getDefault().unregister(this); - if (mPostRecyclerView != null) { - mPostRecyclerView.addOnWindowFocusChangedListener(null); - } + binding.recyclerViewHistoryPostFragment.addOnWindowFocusChangedListener(null); super.onDestroy(); } @@ -1206,7 +1184,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato if (getNColumns(getResources()) == 1 && touchHelper != null) { swipeActionEnabled = changeEnableSwipeActionSwitchEvent.enableSwipeAction; if (changeEnableSwipeActionSwitchEvent.enableSwipeAction) { - touchHelper.attachToRecyclerView(mPostRecyclerView); + touchHelper.attachToRecyclerView(binding.recyclerViewHistoryPostFragment); } else { touchHelper.attachToRecyclerView(null); } @@ -1215,7 +1193,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato @Subscribe public void onChangePullToRefreshEvent(ChangePullToRefreshEvent changePullToRefreshEvent) { - mSwipeRefreshLayout.setEnabled(changePullToRefreshEvent.pullToRefresh); + binding.swipeRefreshLayoutHistoryPostFragment.setEnabled(changePullToRefreshEvent.pullToRefresh); } @Subscribe diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/InboxFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/InboxFragment.java index 25e4263e..45309aec 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/InboxFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/InboxFragment.java @@ -39,6 +39,7 @@ import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.adapters.MessageRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; +import ml.docilealligator.infinityforreddit.databinding.FragmentInboxBinding; import ml.docilealligator.infinityforreddit.events.RepliedToPrivateMessageEvent; import ml.docilealligator.infinityforreddit.message.FetchMessage; import ml.docilealligator.infinityforreddit.message.Message; @@ -48,16 +49,7 @@ import retrofit2.Retrofit; public class InboxFragment extends Fragment implements FragmentCommunicator { public static final String EXTRA_MESSAGE_WHERE = "EMT"; - @BindView(R.id.swipe_refresh_layout_inbox_fragment) - SwipeRefreshLayout mSwipeRefreshLayout; - @BindView(R.id.recycler_view_inbox_fragment) - RecyclerView mRecyclerView; - @BindView(R.id.fetch_messages_info_linear_layout_inbox_fragment) - LinearLayout mFetchMessageInfoLinearLayout; - @BindView(R.id.fetch_messages_info_image_view_inbox_fragment) - ImageView mFetchMessageInfoImageView; - @BindView(R.id.fetch_messages_info_text_view_inbox_fragment) - TextView mFetchMessageInfoTextView; + MessageViewModel mMessageViewModel; @Inject @Named("oauth") @@ -74,45 +66,44 @@ public class InboxFragment extends Fragment implements FragmentCommunicator { private RequestManager mGlide; private LinearLayoutManagerBugFixed mLinearLayoutManager; private BaseActivity mActivity; + private FragmentInboxBinding binding; public InboxFragment() { // Required empty public constructor } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.fragment_inbox, container, false); + binding = FragmentInboxBinding.inflate(inflater, container, false); ((Infinity) mActivity.getApplication()).getAppComponent().inject(this); - ButterKnife.bind(this, rootView); - EventBus.getDefault().register(this); applyTheme(); Bundle arguments = getArguments(); if (arguments == null) { - return rootView; + return binding.getRoot(); } mGlide = Glide.with(this); if (mActivity.isImmersiveInterface()) { - mRecyclerView.setPadding(0, 0, 0, mActivity.getNavBarHeight()); + binding.recyclerViewInboxFragment.setPadding(0, 0, 0, mActivity.getNavBarHeight()); } mWhere = arguments.getString(EXTRA_MESSAGE_WHERE, FetchMessage.WHERE_INBOX); mAdapter = new MessageRecyclerViewAdapter(mActivity, mOauthRetrofit, mCustomThemeWrapper, mActivity.accessToken, mWhere, () -> mMessageViewModel.retryLoadingMore()); mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity); - mRecyclerView.setLayoutManager(mLinearLayoutManager); - mRecyclerView.setAdapter(mAdapter); + binding.recyclerViewInboxFragment.setLayoutManager(mLinearLayoutManager); + binding.recyclerViewInboxFragment.setAdapter(mAdapter); DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mActivity, mLinearLayoutManager.getOrientation()); - mRecyclerView.addItemDecoration(dividerItemDecoration); + binding.recyclerViewInboxFragment.addItemDecoration(dividerItemDecoration); if (mActivity instanceof RecyclerViewContentScrollingInterface) { - mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + binding.recyclerViewInboxFragment.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { if (dy > 0) { @@ -130,28 +121,28 @@ public class InboxFragment extends Fragment implements FragmentCommunicator { mMessageViewModel.getMessages().observe(getViewLifecycleOwner(), messages -> mAdapter.submitList(messages)); mMessageViewModel.hasMessage().observe(getViewLifecycleOwner(), hasMessage -> { - mSwipeRefreshLayout.setRefreshing(false); + binding.swipeRefreshLayoutInboxFragment.setRefreshing(false); if (hasMessage) { - mFetchMessageInfoLinearLayout.setVisibility(View.GONE); + binding.fetchMessagesInfoLinearLayoutInboxFragment.setVisibility(View.GONE); } else { - mFetchMessageInfoLinearLayout.setOnClickListener(null); + binding.fetchMessagesInfoLinearLayoutInboxFragment.setOnClickListener(null); showErrorView(R.string.no_messages); } }); mMessageViewModel.getInitialLoadingState().observe(getViewLifecycleOwner(), networkState -> { if (networkState.getStatus().equals(NetworkState.Status.SUCCESS)) { - mSwipeRefreshLayout.setRefreshing(false); + binding.swipeRefreshLayoutInboxFragment.setRefreshing(false); } else if (networkState.getStatus().equals(NetworkState.Status.FAILED)) { - mSwipeRefreshLayout.setRefreshing(false); - mFetchMessageInfoLinearLayout.setOnClickListener(view -> { - mFetchMessageInfoLinearLayout.setVisibility(View.GONE); + binding.swipeRefreshLayoutInboxFragment.setRefreshing(false); + binding.fetchMessagesInfoLinearLayoutInboxFragment.setOnClickListener(view -> { + binding.fetchMessagesInfoLinearLayoutInboxFragment.setVisibility(View.GONE); mMessageViewModel.refresh(); mAdapter.setNetworkState(null); }); showErrorView(R.string.load_messages_failed); } else { - mSwipeRefreshLayout.setRefreshing(true); + binding.swipeRefreshLayoutInboxFragment.setRefreshing(true); } }); @@ -159,25 +150,25 @@ public class InboxFragment extends Fragment implements FragmentCommunicator { mAdapter.setNetworkState(networkState); }); - mSwipeRefreshLayout.setOnRefreshListener(this::onRefresh); + binding.swipeRefreshLayoutInboxFragment.setOnRefreshListener(this::onRefresh); - return rootView; + return binding.getRoot(); } private void showErrorView(int stringResId) { - mSwipeRefreshLayout.setRefreshing(false); - mFetchMessageInfoLinearLayout.setVisibility(View.VISIBLE); - mFetchMessageInfoTextView.setText(stringResId); - mGlide.load(R.drawable.error_image).into(mFetchMessageInfoImageView); + binding.swipeRefreshLayoutInboxFragment.setRefreshing(false); + binding.fetchMessagesInfoLinearLayoutInboxFragment.setVisibility(View.VISIBLE); + binding.fetchMessagesInfoTextViewInboxFragment.setText(stringResId); + mGlide.load(R.drawable.error_image).into(binding.fetchMessagesInfoImageViewInboxFragment); } @Override public void applyTheme() { - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); - mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); - mFetchMessageInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + binding.swipeRefreshLayoutInboxFragment.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); + binding.swipeRefreshLayoutInboxFragment.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); + binding.fetchMessagesInfoTextViewInboxFragment.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); if (mActivity.typeface != null) { - mFetchMessageInfoTextView.setTypeface(mActivity.typeface); + binding.fetchMessagesInfoTextViewInboxFragment.setTypeface(mActivity.typeface); } } @@ -196,14 +187,14 @@ public class InboxFragment extends Fragment implements FragmentCommunicator { previousPosition = mLinearLayoutManager.findFirstVisibleItemPosition(); } - RecyclerView.LayoutManager layoutManager = mRecyclerView.getLayoutManager(); - mRecyclerView.setAdapter(null); - mRecyclerView.setLayoutManager(null); - mRecyclerView.setAdapter(mAdapter); - mRecyclerView.setLayoutManager(layoutManager); + RecyclerView.LayoutManager layoutManager = binding.recyclerViewInboxFragment.getLayoutManager(); + binding.recyclerViewInboxFragment.setAdapter(null); + binding.recyclerViewInboxFragment.setLayoutManager(null); + binding.recyclerViewInboxFragment.setAdapter(mAdapter); + binding.recyclerViewInboxFragment.setLayoutManager(layoutManager); if (previousPosition > 0) { - mRecyclerView.scrollToPosition(previousPosition); + binding.recyclerViewInboxFragment.scrollToPosition(previousPosition); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java index c58f1c50..36a2969b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java @@ -43,6 +43,7 @@ import ml.docilealligator.infinityforreddit.adapters.MultiRedditListingRecyclerV import ml.docilealligator.infinityforreddit.bottomsheetfragments.MultiRedditOptionsBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; +import ml.docilealligator.infinityforreddit.databinding.FragmentMultiRedditListingBinding; import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; import ml.docilealligator.infinityforreddit.multireddit.MultiRedditViewModel; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; @@ -52,16 +53,6 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm public static final String EXTRA_IS_GETTING_MULTIREDDIT_INFO = "EIGMI"; - @BindView(R.id.swipe_refresh_layout_multi_reddit_listing_fragment) - SwipeRefreshLayout mSwipeRefreshLayout; - @BindView(R.id.recycler_view_multi_reddit_listing_fragment) - RecyclerView mRecyclerView; - @BindView(R.id.fetch_multi_reddit_listing_info_linear_layout_multi_reddit_listing_fragment) - LinearLayout mErrorLinearLayout; - @BindView(R.id.fetch_multi_reddit_listing_info_image_view_multi_reddit_listing_fragment) - ImageView mErrorImageView; - @BindView(R.id.fetch_multi_reddit_listing_info_text_view_multi_reddit_listing_fragment) - TextView mErrorTextView; @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject @@ -79,43 +70,42 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm private BaseActivity mActivity; private RequestManager mGlide; private LinearLayoutManagerBugFixed mLinearLayoutManager; + private FragmentMultiRedditListingBinding binding; public MultiRedditListingFragment() { // Required empty public constructor } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.fragment_multi_reddit_listing, container, false); + binding = FragmentMultiRedditListingBinding.inflate(inflater, container, false); ((Infinity) mActivity.getApplication()).getAppComponent().inject(this); - ButterKnife.bind(this, rootView); - applyTheme(); if ((mActivity != null && ((BaseActivity) mActivity).isImmersiveInterface())) { - mRecyclerView.setPadding(0, 0, 0, ((BaseActivity) mActivity).getNavBarHeight()); + binding.recyclerViewMultiRedditListingFragment.setPadding(0, 0, 0, ((BaseActivity) mActivity).getNavBarHeight()); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { Resources resources = getResources(); int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); if (navBarResourceId > 0) { - mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); + binding.recyclerViewMultiRedditListingFragment.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); } } boolean isGettingMultiredditInfo = getArguments().getBoolean(EXTRA_IS_GETTING_MULTIREDDIT_INFO, false); if (mActivity.accountName.equals(Account.ANONYMOUS_ACCOUNT)) { - mSwipeRefreshLayout.setEnabled(false); + binding.swipeRefreshLayoutMultiRedditListingFragment.setEnabled(false); } mGlide = Glide.with(this); mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity); - mRecyclerView.setLayoutManager(mLinearLayoutManager); + binding.recyclerViewMultiRedditListingFragment.setLayoutManager(mLinearLayoutManager); MultiRedditListingRecyclerViewAdapter adapter = new MultiRedditListingRecyclerViewAdapter(mActivity, mExecutor, mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, mActivity.accessToken, mActivity.accountName, new MultiRedditListingRecyclerViewAdapter.OnItemClickListener() { @@ -137,9 +127,9 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm } } }); - mRecyclerView.setAdapter(adapter); + binding.recyclerViewMultiRedditListingFragment.setAdapter(adapter); if (mActivity instanceof SubscribedThingListingActivity) { - mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + binding.recyclerViewMultiRedditListingFragment.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); @@ -151,7 +141,7 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm } }); } - new FastScrollerBuilder(mRecyclerView).useMd2Style().build(); + new FastScrollerBuilder(binding.recyclerViewMultiRedditListingFragment).useMd2Style().build(); mMultiRedditViewModel = new ViewModelProvider(this, new MultiRedditViewModel.Factory(mActivity.getApplication(), mRedditDataRoomDatabase, mActivity.accountName)) @@ -159,27 +149,27 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm mMultiRedditViewModel.getAllMultiReddits().observe(getViewLifecycleOwner(), subscribedUserData -> { if (subscribedUserData == null || subscribedUserData.size() == 0) { - mRecyclerView.setVisibility(View.GONE); - mErrorLinearLayout.setVisibility(View.VISIBLE); - mGlide.load(R.drawable.error_image).into(mErrorImageView); + binding.recyclerViewMultiRedditListingFragment.setVisibility(View.GONE); + binding.fetchMultiRedditListingInfoLinearLayoutMultiRedditListingFragment.setVisibility(View.VISIBLE); + mGlide.load(R.drawable.error_image).into(binding.fetchMultiRedditListingInfoImageViewMultiRedditListingFragment); } else { - mErrorLinearLayout.setVisibility(View.GONE); - mRecyclerView.setVisibility(View.VISIBLE); - mGlide.clear(mErrorImageView); + binding.fetchMultiRedditListingInfoLinearLayoutMultiRedditListingFragment.setVisibility(View.GONE); + binding.recyclerViewMultiRedditListingFragment.setVisibility(View.VISIBLE); + mGlide.clear(binding.fetchMultiRedditListingInfoImageViewMultiRedditListingFragment); } adapter.setMultiReddits(subscribedUserData); }); mMultiRedditViewModel.getAllFavoriteMultiReddits().observe(getViewLifecycleOwner(), favoriteSubscribedUserData -> { if (favoriteSubscribedUserData != null && favoriteSubscribedUserData.size() > 0) { - mErrorLinearLayout.setVisibility(View.GONE); - mRecyclerView.setVisibility(View.VISIBLE); - mGlide.clear(mErrorImageView); + binding.fetchMultiRedditListingInfoLinearLayoutMultiRedditListingFragment.setVisibility(View.GONE); + binding.recyclerViewMultiRedditListingFragment.setVisibility(View.VISIBLE); + mGlide.clear(binding.fetchMultiRedditListingInfoImageViewMultiRedditListingFragment); } adapter.setFavoriteMultiReddits(favoriteSubscribedUserData); }); - return rootView; + return binding.getRoot(); } private void showOptionsBottomSheetFragment(MultiReddit multiReddit) { @@ -209,21 +199,21 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm @Override public void applyTheme() { if (mActivity instanceof SubscribedThingListingActivity) { - mSwipeRefreshLayout.setOnRefreshListener(() -> ((SubscribedThingListingActivity) mActivity).loadSubscriptions(true)); - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); - mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); + binding.swipeRefreshLayoutMultiRedditListingFragment.setOnRefreshListener(() -> ((SubscribedThingListingActivity) mActivity).loadSubscriptions(true)); + binding.swipeRefreshLayoutMultiRedditListingFragment.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); + binding.swipeRefreshLayoutMultiRedditListingFragment.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); } else { - mSwipeRefreshLayout.setEnabled(false); + binding.swipeRefreshLayoutMultiRedditListingFragment.setEnabled(false); } - mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + binding.fetchMultiRedditListingInfoTextViewMultiRedditListingFragment.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); if (mActivity.typeface != null) { - mErrorTextView.setTypeface(mActivity.typeface); + binding.fetchMultiRedditListingInfoTextViewMultiRedditListingFragment.setTypeface(mActivity.typeface); } } @Override public void stopRefreshProgressbar() { - mSwipeRefreshLayout.setRefreshing(false); + binding.swipeRefreshLayoutMultiRedditListingFragment.setRefreshing(false); } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java index f73e3db8..b7dcea20 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -91,6 +91,7 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.FABMoreOptionsB import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.CustomToroContainer; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; +import ml.docilealligator.infinityforreddit.databinding.FragmentPostBinding; import ml.docilealligator.infinityforreddit.events.ChangeAutoplayNsfwVideosEvent; import ml.docilealligator.infinityforreddit.events.ChangeCompactLayoutToolbarHiddenByDefaultEvent; import ml.docilealligator.infinityforreddit.events.ChangeDataSavingModeEvent; @@ -166,16 +167,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator { private static final String CONCATENATED_SUBREDDIT_NAMES_STATE = "CSNS"; private static final String POST_FRAGMENT_ID_STATE = "PFIS"; - @BindView(R.id.swipe_refresh_layout_post_fragment) - SwipeRefreshLayout mSwipeRefreshLayout; - @BindView(R.id.recycler_view_post_fragment) - CustomToroContainer mPostRecyclerView; - @BindView(R.id.fetch_post_info_linear_layout_post_fragment) - LinearLayout mFetchPostInfoLinearLayout; - @BindView(R.id.fetch_post_info_image_view_post_fragment) - ImageView mFetchPostInfoImageView; - @BindView(R.id.fetch_post_info_text_view_post_fragment) - TextView mFetchPostInfoTextView; PostViewModel mPostViewModel; @Inject @Named("no_oauth") @@ -259,8 +250,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator { private float swipeActionThreshold; private ItemTouchHelper touchHelper; private ArrayList<String> readPosts; - private Unbinder unbinder; private final Map<String, String> subredditOrUserIcons = new HashMap<>(); + private FragmentPostBinding binding; public PostFragment() { // Required empty public constructor @@ -275,8 +266,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator { if (isInLazyMode) { resumeLazyMode(false); } - if (mAdapter != null && mPostRecyclerView != null) { - mPostRecyclerView.onWindowVisibilityChanged(View.VISIBLE); + if (mAdapter != null && binding.recyclerViewPostFragment != null) { + binding.recyclerViewPostFragment.onWindowVisibilityChanged(View.VISIBLE); } } @@ -309,19 +300,17 @@ public class PostFragment extends Fragment implements FragmentCommunicator { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - View rootView = inflater.inflate(R.layout.fragment_post, container, false); + binding = FragmentPostBinding.inflate(inflater, container, false); ((Infinity) activity.getApplication()).getAppComponent().inject(this); - unbinder = ButterKnife.bind(this, rootView); - setHasOptionsMenu(true); EventBus.getDefault().register(this); applyTheme(); - mPostRecyclerView.addOnWindowFocusChangedListener(this::onWindowFocusChanged); + binding.recyclerViewPostFragment.addOnWindowFocusChangedListener(this::onWindowFocusChanged); lazyModeHandler = new Handler(); @@ -339,12 +328,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator { Resources resources = getResources(); if ((activity != null && activity.isImmersiveInterface())) { - mPostRecyclerView.setPadding(0, 0, 0, ((BaseActivity) activity).getNavBarHeight()); + binding.recyclerViewPostFragment.setPadding(0, 0, 0, ((BaseActivity) activity).getNavBarHeight()); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); if (navBarResourceId > 0) { - mPostRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); + binding.recyclerViewPostFragment.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); } } @@ -391,8 +380,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } }; - mSwipeRefreshLayout.setEnabled(mSharedPreferences.getBoolean(SharedPreferencesUtils.PULL_TO_REFRESH, true)); - mSwipeRefreshLayout.setOnRefreshListener(this::refresh); + binding.swipeRefreshLayoutPostFragment.setEnabled(mSharedPreferences.getBoolean(SharedPreferencesUtils.PULL_TO_REFRESH, true)); + binding.swipeRefreshLayoutPostFragment.setOnRefreshListener(this::refresh); int recyclerViewPosition = 0; if (savedInstanceState != null) { @@ -408,7 +397,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { postFragmentId = System.currentTimeMillis() + new Random().nextInt(1000); } - mPostRecyclerView.setOnTouchListener((view, motionEvent) -> { + binding.recyclerViewPostFragment.setOnTouchListener((view, motionEvent) -> { if (isInLazyMode) { pauseLazyMode(true); } @@ -416,7 +405,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { }); if (activity instanceof RecyclerViewContentScrollingInterface) { - mPostRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + binding.recyclerViewPostFragment.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { if (dy > 0) { @@ -501,7 +490,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public void delayTransition() { - TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition()); + TransitionManager.beginDelayedTransition(binding.recyclerViewPostFragment, new AutoTransition()); } }); } else if (postType == PostPagingSource.TYPE_SUBREDDIT) { @@ -572,7 +561,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public void delayTransition() { - TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition()); + TransitionManager.beginDelayedTransition(binding.recyclerViewPostFragment, new AutoTransition()); } }); } else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) { @@ -643,7 +632,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public void delayTransition() { - TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition()); + TransitionManager.beginDelayedTransition(binding.recyclerViewPostFragment, new AutoTransition()); } }); } else if (postType == PostPagingSource.TYPE_USER) { @@ -711,7 +700,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public void delayTransition() { - TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition()); + TransitionManager.beginDelayedTransition(binding.recyclerViewPostFragment, new AutoTransition()); } }); } else if (postType == PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE) { @@ -766,7 +755,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public void delayTransition() { - TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition()); + TransitionManager.beginDelayedTransition(binding.recyclerViewPostFragment, new AutoTransition()); } }); } else if (postType == PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT) { @@ -829,7 +818,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public void delayTransition() { - TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition()); + TransitionManager.beginDelayedTransition(binding.recyclerViewPostFragment, new AutoTransition()); } }); } else { @@ -883,7 +872,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public void delayTransition() { - TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition()); + TransitionManager.beginDelayedTransition(binding.recyclerViewPostFragment, new AutoTransition()); } }); } @@ -891,17 +880,17 @@ public class PostFragment extends Fragment implements FragmentCommunicator { int nColumns = getNColumns(resources); if (nColumns == 1) { mLinearLayoutManager = new LinearLayoutManagerBugFixed(activity); - mPostRecyclerView.setLayoutManager(mLinearLayoutManager); + binding.recyclerViewPostFragment.setLayoutManager(mLinearLayoutManager); } else { mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(nColumns, StaggeredGridLayoutManager.VERTICAL); - mPostRecyclerView.setLayoutManager(mStaggeredGridLayoutManager); + binding.recyclerViewPostFragment.setLayoutManager(mStaggeredGridLayoutManager); StaggeredGridLayoutManagerItemOffsetDecoration itemDecoration = new StaggeredGridLayoutManagerItemOffsetDecoration(activity, R.dimen.staggeredLayoutManagerItemOffset, nColumns); - mPostRecyclerView.addItemDecoration(itemDecoration); + binding.recyclerViewPostFragment.addItemDecoration(itemDecoration); } if (recyclerViewPosition > 0) { - mPostRecyclerView.scrollToPosition(recyclerViewPosition); + binding.recyclerViewPostFragment.scrollToPosition(recyclerViewPosition); } if (activity instanceof ActivityToolbarInterface) { @@ -1077,7 +1066,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { if (touchHelper != null) { exceedThreshold = false; touchHelper.attachToRecyclerView(null); - touchHelper.attachToRecyclerView(mPostRecyclerView); + touchHelper.attachToRecyclerView(binding.recyclerViewPostFragment); } } @@ -1146,16 +1135,16 @@ public class PostFragment extends Fragment implements FragmentCommunicator { if (nColumns == 1 && mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SWIPE_ACTION, false)) { swipeActionEnabled = true; - touchHelper.attachToRecyclerView(mPostRecyclerView); + touchHelper.attachToRecyclerView(binding.recyclerViewPostFragment); } - mPostRecyclerView.setAdapter(mAdapter); - mPostRecyclerView.setCacheManager(mAdapter); - mPostRecyclerView.setPlayerInitializer(order -> { + binding.recyclerViewPostFragment.setAdapter(mAdapter); + binding.recyclerViewPostFragment.setCacheManager(mAdapter); + binding.recyclerViewPostFragment.setPlayerInitializer(order -> { VolumeInfo volumeInfo = new VolumeInfo(true, 0f); return new PlaybackInfo(INDEX_UNSET, TIME_UNSET, volumeInfo); }); - return rootView; + return binding.getRoot(); } private int getNColumns(Resources resources) { @@ -1260,7 +1249,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { LoadState refreshLoadState = combinedLoadStates.getRefresh(); LoadState appendLoadState = combinedLoadStates.getAppend(); - mSwipeRefreshLayout.setRefreshing(refreshLoadState instanceof LoadState.Loading); + binding.swipeRefreshLayoutPostFragment.setRefreshing(refreshLoadState instanceof LoadState.Loading); if (refreshLoadState instanceof LoadState.NotLoading) { if (refreshLoadState.getEndOfPaginationReached() && mAdapter.getItemCount() < 1) { noPostFound(); @@ -1268,7 +1257,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { hasPost = true; } } else if (refreshLoadState instanceof LoadState.Error) { - mFetchPostInfoLinearLayout.setOnClickListener(view -> refresh()); + binding.fetchPostInfoLinearLayoutPostFragment.setOnClickListener(view -> refresh()); showErrorView(R.string.load_posts_error); } if (!(refreshLoadState instanceof LoadState.Loading) && appendLoadState instanceof LoadState.NotLoading) { @@ -1279,7 +1268,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { return null; }); - mPostRecyclerView.setAdapter(mAdapter.withLoadStateFooter(new Paging3LoadingStateAdapter(activity, mCustomThemeWrapper, R.string.load_more_posts_error, + binding.recyclerViewPostFragment.setAdapter(mAdapter.withLoadStateFooter(new Paging3LoadingStateAdapter(activity, mCustomThemeWrapper, R.string.load_more_posts_error, view -> mAdapter.retry()))); } @@ -1336,7 +1325,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { stopLazyMode(); } - mFetchPostInfoLinearLayout.setOnClickListener(null); + binding.fetchPostInfoLinearLayoutPostFragment.setOnClickListener(null); showErrorView(R.string.no_posts); } @@ -1385,9 +1374,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator { break; } } - if (mFetchPostInfoLinearLayout.getVisibility() != View.GONE) { - mFetchPostInfoLinearLayout.setVisibility(View.GONE); - mGlide.clear(mFetchPostInfoImageView); + if (binding.fetchPostInfoLinearLayoutPostFragment.getVisibility() != View.GONE) { + binding.fetchPostInfoLinearLayoutPostFragment.setVisibility(View.GONE); + mGlide.clear(binding.fetchPostInfoImageViewPostFragment); } hasPost = false; if (isInLazyMode) { @@ -1464,7 +1453,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public void refresh() { - mFetchPostInfoLinearLayout.setVisibility(View.GONE); + binding.fetchPostInfoLinearLayoutPostFragment.setVisibility(View.GONE); hasPost = false; if (isInLazyMode) { stopLazyMode(); @@ -1476,10 +1465,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator { private void showErrorView(int stringResId) { if (activity != null && isAdded()) { - mSwipeRefreshLayout.setRefreshing(false); - mFetchPostInfoLinearLayout.setVisibility(View.VISIBLE); - mFetchPostInfoTextView.setText(stringResId); - mGlide.load(R.drawable.error_image).into(mFetchPostInfoImageView); + binding.swipeRefreshLayoutPostFragment.setRefreshing(false); + binding.fetchPostInfoLinearLayoutPostFragment.setVisibility(View.VISIBLE); + binding.fetchPostInfoTextViewPostFragment.setText(stringResId); + mGlide.load(R.drawable.error_image).into(binding.fetchPostInfoImageViewPostFragment); } } @@ -1614,25 +1603,25 @@ public class PostFragment extends Fragment implements FragmentCommunicator { int nColumns = getNColumns(getResources()); if (nColumns == 1) { mLinearLayoutManager = new LinearLayoutManagerBugFixed(activity); - if (mPostRecyclerView.getItemDecorationCount() > 0) { - mPostRecyclerView.removeItemDecorationAt(0); + if (binding.recyclerViewPostFragment.getItemDecorationCount() > 0) { + binding.recyclerViewPostFragment.removeItemDecorationAt(0); } - mPostRecyclerView.setLayoutManager(mLinearLayoutManager); + binding.recyclerViewPostFragment.setLayoutManager(mLinearLayoutManager); mStaggeredGridLayoutManager = null; } else { mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(nColumns, StaggeredGridLayoutManager.VERTICAL); - if (mPostRecyclerView.getItemDecorationCount() > 0) { - mPostRecyclerView.removeItemDecorationAt(0); + if (binding.recyclerViewPostFragment.getItemDecorationCount() > 0) { + binding.recyclerViewPostFragment.removeItemDecorationAt(0); } - mPostRecyclerView.setLayoutManager(mStaggeredGridLayoutManager); + binding.recyclerViewPostFragment.setLayoutManager(mStaggeredGridLayoutManager); StaggeredGridLayoutManagerItemOffsetDecoration itemDecoration = new StaggeredGridLayoutManagerItemOffsetDecoration(activity, R.dimen.staggeredLayoutManagerItemOffset, nColumns); - mPostRecyclerView.addItemDecoration(itemDecoration); + binding.recyclerViewPostFragment.addItemDecoration(itemDecoration); mLinearLayoutManager = null; } if (previousPosition > 0) { - mPostRecyclerView.scrollToPosition(previousPosition); + binding.recyclerViewPostFragment.scrollToPosition(previousPosition); } if (mAdapter != null) { @@ -1643,11 +1632,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public void applyTheme() { - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); - mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); - mFetchPostInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + binding.swipeRefreshLayoutPostFragment.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); + binding.swipeRefreshLayoutPostFragment.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); + binding.fetchPostInfoTextViewPostFragment.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); if (activity.typeface != null) { - mFetchPostInfoTextView.setTypeface(activity.typeface); + binding.fetchPostInfoTextViewPostFragment.setTypeface(activity.typeface); } } @@ -1972,7 +1961,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { if (getNColumns(getResources()) == 1 && touchHelper != null) { swipeActionEnabled = changeEnableSwipeActionSwitchEvent.enableSwipeAction; if (changeEnableSwipeActionSwitchEvent.enableSwipeAction) { - touchHelper.attachToRecyclerView(mPostRecyclerView); + touchHelper.attachToRecyclerView(binding.recyclerViewPostFragment); } else { touchHelper.attachToRecyclerView(null); } @@ -1981,7 +1970,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Subscribe public void onChangePullToRefreshEvent(ChangePullToRefreshEvent changePullToRefreshEvent) { - mSwipeRefreshLayout.setEnabled(changePullToRefreshEvent.pullToRefresh); + binding.swipeRefreshLayoutPostFragment.setEnabled(changePullToRefreshEvent.pullToRefresh); } @Subscribe @@ -2140,13 +2129,13 @@ public class PostFragment extends Fragment implements FragmentCommunicator { previousPosition = mStaggeredGridLayoutManager.findFirstVisibleItemPositions(into)[0]; } - RecyclerView.LayoutManager layoutManager = mPostRecyclerView.getLayoutManager(); - mPostRecyclerView.setAdapter(null); - mPostRecyclerView.setLayoutManager(null); - mPostRecyclerView.setAdapter(mAdapter); - mPostRecyclerView.setLayoutManager(layoutManager); + RecyclerView.LayoutManager layoutManager = binding.recyclerViewPostFragment.getLayoutManager(); + binding.recyclerViewPostFragment.setAdapter(null); + binding.recyclerViewPostFragment.setLayoutManager(null); + binding.recyclerViewPostFragment.setAdapter(mAdapter); + binding.recyclerViewPostFragment.setLayoutManager(layoutManager); if (previousPosition > 0) { - mPostRecyclerView.scrollToPosition(previousPosition); + binding.recyclerViewPostFragment.scrollToPosition(previousPosition); } } @@ -2178,23 +2167,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator { if (isInLazyMode) { pauseLazyMode(false); } - if (mAdapter != null && mPostRecyclerView != null) { - mPostRecyclerView.onWindowVisibilityChanged(View.GONE); + if (mAdapter != null) { + binding.recyclerViewPostFragment.onWindowVisibilityChanged(View.GONE); } } @Override - public void onDestroyView() { - super.onDestroyView(); - unbinder.unbind(); - } - - @Override public void onDestroy() { EventBus.getDefault().unregister(this); - if (mPostRecyclerView != null) { - mPostRecyclerView.addOnWindowFocusChangedListener(null); - } + binding.recyclerViewPostFragment.addOnWindowFocusChangedListener(null); super.onDestroy(); } diff --git a/app/src/main/res/layout/fragment_comments_listing.xml b/app/src/main/res/layout/fragment_comments_listing.xml index 59c8a2d2..ff558526 100644 --- a/app/src/main/res/layout/fragment_comments_listing.xml +++ b/app/src/main/res/layout/fragment_comments_listing.xml @@ -3,7 +3,6 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:id="@+id/coordinator_layout_comments_listing_fragment" tools:application="ml.docilealligator.infinityforreddit.fragments.CommentsListingFragment"> <androidx.swiperefreshlayout.widget.SwipeRefreshLayout |