diff options
Diffstat (limited to '')
16 files changed, 343 insertions, 359 deletions
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 fc16e20d..5225662c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java @@ -550,7 +550,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato return new PlaybackInfo(INDEX_UNSET, TIME_UNSET, volumeInfo); }); - return rootView; + return binding.getRoot(); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java index 1a187bff..a3c61eb9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java @@ -47,6 +47,7 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.CopyTextBottomS import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; +import ml.docilealligator.infinityforreddit.databinding.FragmentSidebarBinding; import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent; import ml.docilealligator.infinityforreddit.markdown.EvenBetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.markdown.CustomMarkwonAdapter; @@ -66,10 +67,7 @@ public class SidebarFragment extends Fragment { public static final String EXTRA_SUBREDDIT_NAME = "ESN"; public SubredditViewModel mSubredditViewModel; - @BindView(R.id.swipe_refresh_layout_sidebar_fragment) - SwipeRefreshLayout swipeRefreshLayout; - @BindView(R.id.markdown_recycler_view_sidebar_fragment) - RecyclerView recyclerView; + @Inject @Named("no_oauth") Retrofit mRetrofit; @@ -89,6 +87,7 @@ public class SidebarFragment extends Fragment { private String sidebarDescription; private EmotePlugin emotePlugin; private ImageAndGifEntry imageAndGifEntry; + private FragmentSidebarBinding binding; public SidebarFragment() { // Required empty public constructor @@ -96,24 +95,22 @@ public class SidebarFragment extends Fragment { @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_sidebar, container, false); + binding = FragmentSidebarBinding.inflate(inflater, container, false); ((Infinity) activity.getApplication()).getAppComponent().inject(this); - ButterKnife.bind(this, rootView); - EventBus.getDefault().register(this); subredditName = getArguments().getString(EXTRA_SUBREDDIT_NAME); if (subredditName == null) { Toast.makeText(activity, R.string.error_getting_subreddit_name, Toast.LENGTH_SHORT).show(); - return rootView; + return binding.getRoot(); } - swipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); - swipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); + binding.swipeRefreshLayoutSidebarFragment.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); + binding.swipeRefreshLayoutSidebarFragment.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); markdownColor = mCustomThemeWrapper.getPrimaryTextColor(); int spoilerBackgroundColor = markdownColor | 0xFF000000; @@ -195,9 +192,9 @@ public class SidebarFragment extends Fragment { return true; }); linearLayoutManager = new LinearLayoutManagerBugFixed(activity); - recyclerView.setLayoutManager(linearLayoutManager); - recyclerView.setAdapter(markwonAdapter); - recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + binding.markdownRecyclerViewSidebarFragment.setLayoutManager(linearLayoutManager); + binding.markdownRecyclerViewSidebarFragment.setAdapter(markwonAdapter); + binding.markdownRecyclerViewSidebarFragment.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { if (dy > 0) { @@ -225,9 +222,9 @@ public class SidebarFragment extends Fragment { } }); - swipeRefreshLayout.setOnRefreshListener(this::fetchSubredditData); + binding.swipeRefreshLayoutSidebarFragment.setOnRefreshListener(this::fetchSubredditData); - return rootView; + return binding.getRoot(); } @Override @@ -243,18 +240,18 @@ public class SidebarFragment extends Fragment { } public void fetchSubredditData() { - swipeRefreshLayout.setRefreshing(true); + binding.swipeRefreshLayoutSidebarFragment.setRefreshing(true); FetchSubredditData.fetchSubredditData(activity.accountName.equals(Account.ANONYMOUS_ACCOUNT) ? null : mOauthRetrofit, mRetrofit, subredditName, activity.accessToken, new FetchSubredditData.FetchSubredditDataListener() { @Override public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { - swipeRefreshLayout.setRefreshing(false); + binding.swipeRefreshLayoutSidebarFragment.setRefreshing(false); InsertSubredditData.insertSubredditData(mExecutor, new Handler(), mRedditDataRoomDatabase, - subredditData, () -> swipeRefreshLayout.setRefreshing(false)); + subredditData, () -> binding.swipeRefreshLayoutSidebarFragment.setRefreshing(false)); } @Override public void onFetchSubredditDataFail(boolean isQuarantined) { - swipeRefreshLayout.setRefreshing(false); + binding.swipeRefreshLayoutSidebarFragment.setRefreshing(false); Toast.makeText(activity, R.string.cannot_fetch_sidebar, Toast.LENGTH_SHORT).show(); } }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java index f3ade357..ad9ed554 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java @@ -46,6 +46,7 @@ import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivi import ml.docilealligator.infinityforreddit.adapters.SubredditListingRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; +import ml.docilealligator.infinityforreddit.databinding.FragmentSubredditListingBinding; import ml.docilealligator.infinityforreddit.subreddit.SubredditData; import ml.docilealligator.infinityforreddit.subreddit.SubredditListingViewModel; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; @@ -61,18 +62,6 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun public static final String EXTRA_IS_GETTING_SUBREDDIT_INFO = "EIGSI"; public static final String EXTRA_IS_MULTI_SELECTION = "EIMS"; - @BindView(R.id.coordinator_layout_subreddit_listing_fragment) - CoordinatorLayout mCoordinatorLayout; - @BindView(R.id.recycler_view_subreddit_listing_fragment) - RecyclerView mSubredditListingRecyclerView; - @BindView(R.id.swipe_refresh_layout_subreddit_listing_fragment) - SwipeRefreshLayout mSwipeRefreshLayout; - @BindView(R.id.fetch_subreddit_listing_info_linear_layout_subreddit_listing_fragment) - LinearLayout mFetchSubredditListingInfoLinearLayout; - @BindView(R.id.fetch_subreddit_listing_info_image_view_subreddit_listing_fragment) - ImageView mFetchSubredditListingInfoImageView; - @BindView(R.id.fetch_subreddit_listing_info_text_view_subreddit_listing_fragment) - TextView mFetchSubredditListingInfoTextView; SubredditListingViewModel mSubredditListingViewModel; @Inject @Named("no_oauth") @@ -99,6 +88,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun private SubredditListingRecyclerViewAdapter mAdapter; private BaseActivity mActivity; private SortType sortType; + private FragmentSubredditListingBinding binding; public SubredditListingFragment() { // Required empty public constructor @@ -109,28 +99,26 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - View rootView = inflater.inflate(R.layout.fragment_subreddit_listing, container, false); + binding = FragmentSubredditListingBinding.inflate(inflater, container, false); ((Infinity) mActivity.getApplication()).getAppComponent().inject(this); - ButterKnife.bind(this, rootView); - applyTheme(); Resources resources = getResources(); if ((mActivity != null && ((BaseActivity) mActivity).isImmersiveInterface())) { - mSubredditListingRecyclerView.setPadding(0, 0, 0, ((BaseActivity) mActivity).getNavBarHeight()); + binding.recyclerViewSubredditListingFragment.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) { - mSubredditListingRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); + binding.recyclerViewSubredditListingFragment.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); } } mLinearLayoutManager = new LinearLayoutManagerBugFixed(getActivity()); - mSubredditListingRecyclerView.setLayoutManager(mLinearLayoutManager); + binding.recyclerViewSubredditListingFragment.setLayoutManager(mLinearLayoutManager); String query = getArguments().getString(EXTRA_QUERY); boolean isGettingSubredditInfo = getArguments().getBoolean(EXTRA_IS_GETTING_SUBREDDIT_INFO); @@ -160,10 +148,10 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun } }); - mSubredditListingRecyclerView.setAdapter(mAdapter); + binding.recyclerViewSubredditListingFragment.setAdapter(mAdapter); if (mActivity instanceof RecyclerViewContentScrollingInterface) { - mSubredditListingRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + binding.recyclerViewSubredditListingFragment.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { if (dy > 0) { @@ -181,24 +169,24 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun mSubredditListingViewModel.getSubreddits().observe(getViewLifecycleOwner(), subredditData -> mAdapter.submitList(subredditData)); mSubredditListingViewModel.hasSubredditLiveData().observe(getViewLifecycleOwner(), hasSubreddit -> { - mSwipeRefreshLayout.setRefreshing(false); + binding.swipeRefreshLayoutSubredditListingFragment.setRefreshing(false); if (hasSubreddit) { - mFetchSubredditListingInfoLinearLayout.setVisibility(View.GONE); + binding.fetchSubredditListingInfoLinearLayoutSubredditListingFragment.setVisibility(View.GONE); } else { - mFetchSubredditListingInfoLinearLayout.setOnClickListener(null); + binding.fetchSubredditListingInfoLinearLayoutSubredditListingFragment.setOnClickListener(null); showErrorView(R.string.no_subreddits); } }); mSubredditListingViewModel.getInitialLoadingState().observe(getViewLifecycleOwner(), networkState -> { if (networkState.getStatus().equals(NetworkState.Status.SUCCESS)) { - mSwipeRefreshLayout.setRefreshing(false); + binding.swipeRefreshLayoutSubredditListingFragment.setRefreshing(false); } else if (networkState.getStatus().equals(NetworkState.Status.FAILED)) { - mSwipeRefreshLayout.setRefreshing(false); - mFetchSubredditListingInfoLinearLayout.setOnClickListener(view -> refresh()); + binding.swipeRefreshLayoutSubredditListingFragment.setRefreshing(false); + binding.fetchSubredditListingInfoLinearLayoutSubredditListingFragment.setOnClickListener(view -> refresh()); showErrorView(R.string.search_subreddits_error); } else { - mSwipeRefreshLayout.setRefreshing(true); + binding.swipeRefreshLayoutSubredditListingFragment.setRefreshing(true); } }); @@ -206,9 +194,9 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun mAdapter.setNetworkState(networkState); }); - mSwipeRefreshLayout.setOnRefreshListener(() -> mSubredditListingViewModel.refresh()); + binding.swipeRefreshLayoutSubredditListingFragment.setOnRefreshListener(() -> mSubredditListingViewModel.refresh()); - return rootView; + return binding.getRoot(); } @Override @@ -219,10 +207,10 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun private void showErrorView(int stringResId) { if (getActivity() != null && isAdded()) { - mSwipeRefreshLayout.setRefreshing(false); - mFetchSubredditListingInfoLinearLayout.setVisibility(View.VISIBLE); - mFetchSubredditListingInfoTextView.setText(stringResId); - Glide.with(this).load(R.drawable.error_image).into(mFetchSubredditListingInfoImageView); + binding.swipeRefreshLayoutSubredditListingFragment.setRefreshing(false); + binding.fetchSubredditListingInfoLinearLayoutSubredditListingFragment.setVisibility(View.VISIBLE); + binding.fetchSubredditListingInfoTextViewSubredditListingFragment.setText(stringResId); + Glide.with(this).load(R.drawable.error_image).into(binding.fetchSubredditListingInfoImageViewSubredditListingFragment); } } @@ -234,18 +222,18 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun @Override public void refresh() { - mFetchSubredditListingInfoLinearLayout.setVisibility(View.GONE); + binding.fetchSubredditListingInfoLinearLayoutSubredditListingFragment.setVisibility(View.GONE); mSubredditListingViewModel.refresh(); mAdapter.setNetworkState(null); } @Override public void applyTheme() { - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); - mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); - mFetchSubredditListingInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + binding.swipeRefreshLayoutSubredditListingFragment.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); + binding.swipeRefreshLayoutSubredditListingFragment.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); + binding.fetchSubredditListingInfoTextViewSubredditListingFragment.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); if (mActivity.typeface != null) { - mFetchSubredditListingInfoTextView.setTypeface(mActivity.contentTypeface); + binding.fetchSubredditListingInfoTextViewSubredditListingFragment.setTypeface(mActivity.contentTypeface); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java index a8925ddb..1e2dae33 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java @@ -41,6 +41,7 @@ import ml.docilealligator.infinityforreddit.activities.SubscribedThingListingAct import ml.docilealligator.infinityforreddit.adapters.SubscribedSubredditsRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; +import ml.docilealligator.infinityforreddit.databinding.FragmentSubscribedSubredditsListingBinding; import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditViewModel; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import retrofit2.Retrofit; @@ -55,16 +56,6 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra public static final String EXTRA_IS_SUBREDDIT_SELECTION = "EISS"; public static final String EXTRA_EXTRA_CLEAR_SELECTION = "EECS"; - @BindView(R.id.swipe_refresh_layout_subscribed_subreddits_listing_fragment) - SwipeRefreshLayout mSwipeRefreshLayout; - @BindView(R.id.recycler_view_subscribed_subreddits_listing_fragment) - RecyclerView mRecyclerView; - @BindView(R.id.no_subscriptions_linear_layout_subreddits_listing_fragment) - LinearLayout mLinearLayout; - @BindView(R.id.no_subscriptions_image_view_subreddits_listing_fragment) - ImageView mImageView; - @BindView(R.id.error_text_view_subscribed_subreddits_listing_fragment) - TextView mErrorTextView; @Inject @Named("oauth") Retrofit mOauthRetrofit; @@ -81,6 +72,7 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra private BaseActivity mActivity; private RequestManager mGlide; private LinearLayoutManagerBugFixed mLinearLayoutManager; + private FragmentSubscribedSubredditsListingBinding binding; public SubscribedSubredditsListingFragment() { // Required empty public constructor @@ -89,33 +81,31 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.fragment_subscribed_subreddits_listing, container, false); - - ButterKnife.bind(this, rootView); + binding = FragmentSubscribedSubredditsListingBinding.inflate(inflater, container, false); ((Infinity) mActivity.getApplication()).getAppComponent().inject(this); applyTheme(); - if ((mActivity instanceof BaseActivity && ((BaseActivity) mActivity).isImmersiveInterface())) { - mRecyclerView.setPadding(0, 0, 0, ((BaseActivity) mActivity).getNavBarHeight()); + if ((mActivity.isImmersiveInterface())) { + binding.recyclerViewSubscribedSubredditsListingFragment.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.recyclerViewSubscribedSubredditsListingFragment.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); } } if (mActivity.accountName.equals(Account.ANONYMOUS_ACCOUNT)) { - mSwipeRefreshLayout.setEnabled(false); + binding.swipeRefreshLayoutSubscribedSubredditsListingFragment.setEnabled(false); } mGlide = Glide.with(this); mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity); - mRecyclerView.setLayoutManager(mLinearLayoutManager); + binding.recyclerViewSubscribedSubredditsListingFragment.setLayoutManager(mLinearLayoutManager); SubscribedSubredditsRecyclerViewAdapter adapter; if (getArguments().getBoolean(EXTRA_IS_SUBREDDIT_SELECTION)) { @@ -127,22 +117,22 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra mCustomThemeWrapper, mActivity.accessToken, mActivity.accountName); } - mRecyclerView.setAdapter(adapter); - new FastScrollerBuilder(mRecyclerView).useMd2Style().build(); + binding.recyclerViewSubscribedSubredditsListingFragment.setAdapter(adapter); + new FastScrollerBuilder(binding.recyclerViewSubscribedSubredditsListingFragment).useMd2Style().build(); mSubscribedSubredditViewModel = new ViewModelProvider(this, new SubscribedSubredditViewModel.Factory(mActivity.getApplication(), mRedditDataRoomDatabase, mActivity.accountName)) .get(SubscribedSubredditViewModel.class); mSubscribedSubredditViewModel.getAllSubscribedSubreddits().observe(getViewLifecycleOwner(), subscribedSubredditData -> { - mSwipeRefreshLayout.setRefreshing(false); + binding.swipeRefreshLayoutSubscribedSubredditsListingFragment.setRefreshing(false); if (subscribedSubredditData == null || subscribedSubredditData.size() == 0) { - mRecyclerView.setVisibility(View.GONE); - mLinearLayout.setVisibility(View.VISIBLE); - mGlide.load(R.drawable.error_image).into(mImageView); + binding.recyclerViewSubscribedSubredditsListingFragment.setVisibility(View.GONE); + binding.noSubscriptionsLinearLayoutSubredditsListingFragment.setVisibility(View.VISIBLE); + mGlide.load(R.drawable.error_image).into(binding.noSubscriptionsImageViewSubredditsListingFragment); } else { - mLinearLayout.setVisibility(View.GONE); - mRecyclerView.setVisibility(View.VISIBLE); - mGlide.clear(mImageView); + binding.noSubscriptionsLinearLayoutSubredditsListingFragment.setVisibility(View.GONE); + binding.recyclerViewSubscribedSubredditsListingFragment.setVisibility(View.VISIBLE); + mGlide.clear(binding.noSubscriptionsImageViewSubredditsListingFragment); } if (!mActivity.accountName.equals(Account.ANONYMOUS_ACCOUNT)) { @@ -152,17 +142,17 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra }); mSubscribedSubredditViewModel.getAllFavoriteSubscribedSubreddits().observe(getViewLifecycleOwner(), favoriteSubscribedSubredditData -> { - mSwipeRefreshLayout.setRefreshing(false); + binding.swipeRefreshLayoutSubscribedSubredditsListingFragment.setRefreshing(false); if (favoriteSubscribedSubredditData != null && favoriteSubscribedSubredditData.size() > 0) { - mLinearLayout.setVisibility(View.GONE); - mRecyclerView.setVisibility(View.VISIBLE); - mGlide.clear(mImageView); + binding.noSubscriptionsLinearLayoutSubredditsListingFragment.setVisibility(View.GONE); + binding.recyclerViewSubscribedSubredditsListingFragment.setVisibility(View.VISIBLE); + mGlide.clear(binding.noSubscriptionsImageViewSubredditsListingFragment); } adapter.setFavoriteSubscribedSubreddits(favoriteSubscribedSubredditData); }); - return rootView; + return binding.getRoot(); } @Override @@ -173,21 +163,21 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra @Override public void stopRefreshProgressbar() { - mSwipeRefreshLayout.setRefreshing(false); + binding.swipeRefreshLayoutSubscribedSubredditsListingFragment.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.swipeRefreshLayoutSubscribedSubredditsListingFragment.setOnRefreshListener(() -> ((SubscribedThingListingActivity) mActivity).loadSubscriptions(true)); + binding.swipeRefreshLayoutSubscribedSubredditsListingFragment.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); + binding.swipeRefreshLayoutSubscribedSubredditsListingFragment.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); } else { - mSwipeRefreshLayout.setEnabled(false); + binding.swipeRefreshLayoutSubscribedSubredditsListingFragment.setEnabled(false); } - mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + binding.errorTextViewSubscribedSubredditsListingFragment.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); if (mActivity.typeface != null) { - mErrorTextView.setTypeface(mActivity.contentTypeface); + binding.errorTextViewSubscribedSubredditsListingFragment.setTypeface(mActivity.contentTypeface); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java index 69136dd1..d489674d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java @@ -46,6 +46,7 @@ import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.adapters.UserListingRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; +import ml.docilealligator.infinityforreddit.databinding.FragmentUserListingBinding; import ml.docilealligator.infinityforreddit.user.UserData; import ml.docilealligator.infinityforreddit.user.UserListingViewModel; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; @@ -61,18 +62,6 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato public static final String EXTRA_IS_GETTING_USER_INFO = "EIGUI"; public static final String EXTRA_IS_MULTI_SELECTION = "EIMS"; - @BindView(R.id.coordinator_layout_user_listing_fragment) - CoordinatorLayout mCoordinatorLayout; - @BindView(R.id.recycler_view_user_listing_fragment) - RecyclerView mUserListingRecyclerView; - @BindView(R.id.swipe_refresh_layout_user_listing_fragment) - SwipeRefreshLayout mSwipeRefreshLayout; - @BindView(R.id.fetch_user_listing_info_linear_layout_user_listing_fragment) - LinearLayout mFetchUserListingInfoLinearLayout; - @BindView(R.id.fetch_user_listing_info_image_view_user_listing_fragment) - ImageView mFetchUserListingInfoImageView; - @BindView(R.id.fetch_user_listing_info_text_view_user_listing_fragment) - TextView mFetchUserListingInfoTextView; UserListingViewModel mUserListingViewModel; @Inject @Named("no_oauth") @@ -100,6 +89,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato private UserListingRecyclerViewAdapter mAdapter; private BaseActivity mActivity; private SortType sortType; + private FragmentUserListingBinding binding; public UserListingFragment() { // Required empty public constructor @@ -107,31 +97,29 @@ public class UserListingFragment 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_user_listing, container, false); + binding = FragmentUserListingBinding.inflate(inflater, container, false); ((Infinity) mActivity.getApplication()).getAppComponent().inject(this); - ButterKnife.bind(this, rootView); - applyTheme(); Resources resources = getResources(); if (((BaseActivity) mActivity).isImmersiveInterface()) { - mUserListingRecyclerView.setPadding(0, 0, 0, ((BaseActivity) mActivity).getNavBarHeight()); + binding.recyclerViewUserListingFragment.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) { - mUserListingRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); + binding.recyclerViewUserListingFragment.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); } } mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity); - mUserListingRecyclerView.setLayoutManager(mLinearLayoutManager); + binding.recyclerViewUserListingFragment.setLayoutManager(mLinearLayoutManager); mQuery = getArguments().getString(EXTRA_QUERY); boolean isGettingUserInfo = getArguments().getBoolean(EXTRA_IS_GETTING_USER_INFO); @@ -160,10 +148,10 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato } }); - mUserListingRecyclerView.setAdapter(mAdapter); + binding.recyclerViewUserListingFragment.setAdapter(mAdapter); if (mActivity instanceof RecyclerViewContentScrollingInterface) { - mUserListingRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + binding.recyclerViewUserListingFragment.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { if (dy > 0) { @@ -181,11 +169,11 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato mUserListingViewModel.getUsers().observe(getViewLifecycleOwner(), UserData -> mAdapter.submitList(UserData)); mUserListingViewModel.hasUser().observe(getViewLifecycleOwner(), hasUser -> { - mSwipeRefreshLayout.setRefreshing(false); + binding.swipeRefreshLayoutUserListingFragment.setRefreshing(false); if (hasUser) { - mFetchUserListingInfoLinearLayout.setVisibility(View.GONE); + binding.fetchUserListingInfoLinearLayoutUserListingFragment.setVisibility(View.GONE); } else { - mFetchUserListingInfoLinearLayout.setOnClickListener(view -> { + binding.fetchUserListingInfoLinearLayoutUserListingFragment.setOnClickListener(view -> { //Do nothing }); showErrorView(R.string.no_users); @@ -194,13 +182,13 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato mUserListingViewModel.getInitialLoadingState().observe(getViewLifecycleOwner(), networkState -> { if (networkState.getStatus().equals(NetworkState.Status.SUCCESS)) { - mSwipeRefreshLayout.setRefreshing(false); + binding.swipeRefreshLayoutUserListingFragment.setRefreshing(false); } else if (networkState.getStatus().equals(NetworkState.Status.FAILED)) { - mSwipeRefreshLayout.setRefreshing(false); - mFetchUserListingInfoLinearLayout.setOnClickListener(view -> refresh()); + binding.swipeRefreshLayoutUserListingFragment.setRefreshing(false); + binding.fetchUserListingInfoLinearLayoutUserListingFragment.setOnClickListener(view -> refresh()); showErrorView(R.string.search_users_error); } else { - mSwipeRefreshLayout.setRefreshing(true); + binding.swipeRefreshLayoutUserListingFragment.setRefreshing(true); } }); @@ -208,9 +196,9 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato mAdapter.setNetworkState(networkState); }); - mSwipeRefreshLayout.setOnRefreshListener(() -> mUserListingViewModel.refresh()); + binding.swipeRefreshLayoutUserListingFragment.setOnRefreshListener(() -> mUserListingViewModel.refresh()); - return rootView; + return binding.getRoot(); } @Override @@ -221,10 +209,10 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato private void showErrorView(int stringResId) { if (getActivity() != null && isAdded()) { - mSwipeRefreshLayout.setRefreshing(false); - mFetchUserListingInfoLinearLayout.setVisibility(View.VISIBLE); - mFetchUserListingInfoTextView.setText(stringResId); - Glide.with(this).load(R.drawable.error_image).into(mFetchUserListingInfoImageView); + binding.swipeRefreshLayoutUserListingFragment.setRefreshing(false); + binding.fetchUserListingInfoLinearLayoutUserListingFragment.setVisibility(View.VISIBLE); + binding.fetchUserListingInfoTextViewUserListingFragment.setText(stringResId); + Glide.with(this).load(R.drawable.error_image).into(binding.fetchUserListingInfoImageViewUserListingFragment); } } @@ -236,18 +224,18 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato @Override public void refresh() { - mFetchUserListingInfoLinearLayout.setVisibility(View.GONE); + binding.fetchUserListingInfoLinearLayoutUserListingFragment.setVisibility(View.GONE); mUserListingViewModel.refresh(); mAdapter.setNetworkState(null); } @Override public void applyTheme() { - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); - mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); - mFetchUserListingInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + binding.swipeRefreshLayoutUserListingFragment.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); + binding.swipeRefreshLayoutUserListingFragment.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); + binding.fetchUserListingInfoTextViewUserListingFragment.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); if (mActivity.typeface != null) { - mFetchUserListingInfoTextView.setTypeface(mActivity.contentTypeface); + binding.fetchUserListingInfoTextViewUserListingFragment.setTypeface(mActivity.contentTypeface); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java index bc093ea1..4e13c051 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java @@ -16,10 +16,6 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.ProgressBar; -import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; @@ -37,16 +33,12 @@ import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.target.Target; import com.bumptech.glide.request.transition.Transition; import com.davemorrissey.labs.subscaleview.ImageSource; -import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView; -import com.google.android.material.bottomappbar.BottomAppBar; import java.io.File; import java.util.concurrent.Executor; import javax.inject.Inject; -import butterknife.BindView; -import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.BuildConfig; import ml.docilealligator.infinityforreddit.ImgurMedia; import ml.docilealligator.infinityforreddit.Infinity; @@ -55,6 +47,7 @@ import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback; import ml.docilealligator.infinityforreddit.activities.ViewImgurMediaActivity; import ml.docilealligator.infinityforreddit.asynctasks.SaveBitmapImageToFile; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SetAsWallpaperBottomSheetFragment; +import ml.docilealligator.infinityforreddit.databinding.FragmentViewImgurImageBinding; import ml.docilealligator.infinityforreddit.services.DownloadMediaService; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -65,22 +58,6 @@ public class ViewImgurImageFragment extends Fragment { public static final String EXTRA_MEDIA_COUNT = "EMC"; private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0; - @BindView(R.id.progress_bar_view_imgur_image_fragment) - ProgressBar progressBar; - @BindView(R.id.image_view_view_imgur_image_fragment) - SubsamplingScaleImageView imageView; - @BindView(R.id.load_image_error_linear_layout_view_imgur_image_fragment) - LinearLayout errorLinearLayout; - @BindView(R.id.bottom_navigation_view_imgur_image_fragment) - BottomAppBar bottomAppBar; - @BindView(R.id.title_text_view_view_imgur_image_fragment) - TextView titleTextView; - @BindView(R.id.download_image_view_view_imgur_image_fragment) - ImageView downloadImageView; - @BindView(R.id.share_image_view_view_imgur_image_fragment) - ImageView shareImageView; - @BindView(R.id.wallpaper_image_view_view_imgur_image_fragment) - ImageView wallpaperImageView; @Inject Executor mExecutor; @@ -89,27 +66,26 @@ public class ViewImgurImageFragment extends Fragment { private ImgurMedia imgurMedia; private boolean isDownloading = false; private boolean isActionBarHidden = false; + private FragmentViewImgurImageBinding binding; public ViewImgurImageFragment() { // 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_view_imgur_image, container, false); + binding = FragmentViewImgurImageBinding.inflate(inflater, container, false); ((Infinity) activity.getApplication()).getAppComponent().inject(this); - ButterKnife.bind(this, rootView); - setHasOptionsMenu(true); imgurMedia = getArguments().getParcelable(EXTRA_IMGUR_IMAGES); glide = Glide.with(activity); loadImage(); - imageView.setOnClickListener(view -> { + binding.imageViewViewImgurImageFragment.setOnClickListener(view -> { if (isActionBarHidden) { activity.getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE @@ -117,7 +93,7 @@ public class ViewImgurImageFragment extends Fragment { | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); isActionBarHidden = false; if (activity.isUseBottomAppBar()) { - bottomAppBar.setVisibility(View.VISIBLE); + binding.bottomNavigationViewImgurImageFragment.setVisibility(View.VISIBLE); } } else { activity.getWindow().getDecorView().setSystemUiVisibility( @@ -129,60 +105,60 @@ public class ViewImgurImageFragment extends Fragment { | View.SYSTEM_UI_FLAG_IMMERSIVE); isActionBarHidden = true; if (activity.isUseBottomAppBar()) { - bottomAppBar.setVisibility(View.GONE); + binding.bottomNavigationViewImgurImageFragment.setVisibility(View.GONE); } } }); - imageView.setMinimumDpi(80); - imageView.setDoubleTapZoomDpi(240); - imageView.resetScaleAndCenter(); + binding.imageViewViewImgurImageFragment.setMinimumDpi(80); + binding.imageViewViewImgurImageFragment.setDoubleTapZoomDpi(240); + binding.imageViewViewImgurImageFragment.resetScaleAndCenter(); - errorLinearLayout.setOnClickListener(view -> { - progressBar.setVisibility(View.VISIBLE); - errorLinearLayout.setVisibility(View.GONE); + binding.loadImageErrorLinearLayoutViewImgurImageFragment.setOnClickListener(view -> { + binding.progressBarViewImgurImageFragment.setVisibility(View.VISIBLE); + binding.loadImageErrorLinearLayoutViewImgurImageFragment.setVisibility(View.GONE); loadImage(); }); if (activity.isUseBottomAppBar()) { - bottomAppBar.setVisibility(View.VISIBLE); - titleTextView.setText(getString(R.string.view_imgur_media_activity_image_label, + binding.bottomNavigationViewImgurImageFragment.setVisibility(View.VISIBLE); + binding.titleTextViewViewImgurImageFragment.setText(getString(R.string.view_imgur_media_activity_image_label, getArguments().getInt(EXTRA_INDEX) + 1, getArguments().getInt(EXTRA_MEDIA_COUNT))); - downloadImageView.setOnClickListener(view -> { + binding.downloadImageViewViewImgurImageFragment.setOnClickListener(view -> { if (isDownloading) { return; } isDownloading = true; requestPermissionAndDownload(); }); - shareImageView.setOnClickListener(view -> { + binding.shareImageViewViewImgurImageFragment.setOnClickListener(view -> { shareImage(); }); - wallpaperImageView.setOnClickListener(view -> { + binding.wallpaperImageViewViewImgurImageFragment.setOnClickListener(view -> { setWallpaper(); }); } - return rootView; + return binding.getRoot(); } private void loadImage() { glide.asBitmap().load(imgurMedia.getLink()).listener(new RequestListener<Bitmap>() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) { - progressBar.setVisibility(View.GONE); - errorLinearLayout.setVisibility(View.VISIBLE); + binding.progressBarViewImgurImageFragment.setVisibility(View.GONE); + binding.loadImageErrorLinearLayoutViewImgurImageFragment.setVisibility(View.VISIBLE); return false; } @Override public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) { - progressBar.setVisibility(View.GONE); + binding.progressBarViewImgurImageFragment.setVisibility(View.GONE); return false; } }).into(new CustomTarget<Bitmap>() { @Override public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) { - imageView.setImage(ImageSource.bitmap(resource)); + binding.imageViewViewImgurImageFragment.setImage(ImageSource.bitmap(resource)); } @Override @@ -327,6 +303,6 @@ public class ViewImgurImageFragment extends Fragment { @Override public void onDestroyView() { super.onDestroyView(); - glide.clear(imageView); + glide.clear(binding.imageViewViewImgurImageFragment); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java index 0652515d..08efb5e0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java @@ -16,7 +16,6 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; -import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; @@ -31,25 +30,21 @@ import com.google.android.exoplayer2.Tracks; import com.google.android.exoplayer2.source.ProgressiveMediaSource; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import com.google.android.exoplayer2.trackselection.TrackSelector; -import com.google.android.exoplayer2.ui.PlayerView; import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DefaultHttpDataSource; import com.google.android.exoplayer2.upstream.cache.CacheDataSource; import com.google.android.exoplayer2.upstream.cache.SimpleCache; -import com.google.android.material.bottomappbar.BottomAppBar; -import com.google.android.material.button.MaterialButton; import com.google.common.collect.ImmutableList; import javax.inject.Inject; import javax.inject.Named; -import butterknife.BindView; -import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.ImgurMedia; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.ViewImgurMediaActivity; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PlaybackSpeedBottomSheetFragment; +import ml.docilealligator.infinityforreddit.databinding.FragmentViewImgurVideoBinding; import ml.docilealligator.infinityforreddit.services.DownloadMediaService; import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; @@ -64,20 +59,7 @@ public class ViewImgurVideoFragment extends Fragment { private static final String IS_MUTE_STATE = "IMS"; private static final String POSITION_STATE = "PS"; private static final String PLAYBACK_SPEED_STATE = "PSS"; - @BindView(R.id.player_view_view_imgur_video_fragment) - PlayerView videoPlayerView; - @BindView(R.id.mute_exo_playback_control_view) - MaterialButton muteButton; - @BindView(R.id.bottom_navigation_exo_playback_control_view) - BottomAppBar bottomAppBar; - @BindView(R.id.title_text_view_exo_playback_control_view) - TextView titleTextView; - @BindView(R.id.back_button_exo_playback_control_view) - MaterialButton backButton; - @BindView(R.id.download_image_view_exo_playback_control_view) - MaterialButton downloadButton; - @BindView(R.id.playback_speed_image_view_exo_playback_control_view) - MaterialButton playbackSpeedButton; + private ViewImgurMediaActivity activity; private ImgurMedia imgurMedia; private ExoPlayer player; @@ -91,6 +73,7 @@ public class ViewImgurVideoFragment extends Fragment { SharedPreferences mSharedPreferences; @Inject SimpleCache mSimpleCache; + private ViewImgurVideoFragmentBindingAdapter binding; public ViewImgurVideoFragment() { // Required empty public constructor @@ -100,16 +83,14 @@ public class ViewImgurVideoFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.fragment_view_imgur_video, container, false); + binding = new ViewImgurVideoFragmentBindingAdapter(FragmentViewImgurVideoBinding.inflate(inflater, container, false)); ((Infinity) activity.getApplication()).getAppComponent().inject(this); - ButterKnife.bind(this, rootView); - setHasOptionsMenu(true); if (activity.typeface != null) { - titleTextView.setTypeface(activity.typeface); + binding.getTitleTextView().setTypeface(activity.typeface); } activity.setVolumeControlStream(AudioManager.STREAM_MUSIC); @@ -120,19 +101,19 @@ public class ViewImgurVideoFragment extends Fragment { if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || getResources().getBoolean(R.bool.isTablet)) { //Set player controller bottom margin in order to display it above the navbar int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android"); - LinearLayout controllerLinearLayout = rootView.findViewById(R.id.linear_layout_exo_playback_control_view); + LinearLayout controllerLinearLayout = binding.getRoot().findViewById(R.id.linear_layout_exo_playback_control_view); ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) controllerLinearLayout.getLayoutParams(); params.bottomMargin = getResources().getDimensionPixelSize(resourceId); } else { //Set player controller right margin in order to display it above the navbar int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android"); - LinearLayout controllerLinearLayout = rootView.findViewById(R.id.linear_layout_exo_playback_control_view); + LinearLayout controllerLinearLayout = binding.getRoot().findViewById(R.id.linear_layout_exo_playback_control_view); ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) controllerLinearLayout.getLayoutParams(); params.rightMargin = getResources().getDimensionPixelSize(resourceId); } } - videoPlayerView.setControllerVisibilityListener(visibility -> { + binding.getRoot().setControllerVisibilityListener(visibility -> { switch (visibility) { case View.GONE: activity.getWindow().getDecorView().setSystemUiVisibility( @@ -153,7 +134,7 @@ public class ViewImgurVideoFragment extends Fragment { TrackSelector trackSelector = new DefaultTrackSelector(activity); player = new ExoPlayer.Builder(activity).setTrackSelector(trackSelector).build(); - videoPlayerView.setPlayer(player); + binding.getRoot().setPlayer(player); dataSourceFactory = new CacheDataSource.Factory().setCache(mSimpleCache) .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setAllowCrossProtocolRedirects(true).setUserAgent(APIUtils.USER_AGENT)); player.prepare(); @@ -165,17 +146,17 @@ public class ViewImgurVideoFragment extends Fragment { setPlaybackSpeed(Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_PLAYBACK_SPEED, "100"))); preparePlayer(savedInstanceState); - titleTextView.setText(getString(R.string.view_imgur_media_activity_video_label, + binding.getTitleTextView().setText(getString(R.string.view_imgur_media_activity_video_label, getArguments().getInt(EXTRA_INDEX) + 1, getArguments().getInt(EXTRA_MEDIA_COUNT))); if (activity.isUseBottomAppBar()) { - bottomAppBar.setVisibility(View.VISIBLE); + binding.getBottomAppBar().setVisibility(View.VISIBLE); - backButton.setOnClickListener(view -> { + binding.getBackButton().setOnClickListener(view -> { activity.finish(); }); - downloadButton.setOnClickListener(view -> { + binding.getDownloadButton().setOnClickListener(view -> { if (isDownloading) { return; } @@ -183,12 +164,12 @@ public class ViewImgurVideoFragment extends Fragment { requestPermissionAndDownload(); }); - playbackSpeedButton.setOnClickListener(view -> { + binding.getPlaybackSpeedButton().setOnClickListener(view -> { changePlaybackSpeed(); }); } - return rootView; + return binding.getRoot(); } private void changePlaybackSpeed() { @@ -287,17 +268,17 @@ public class ViewImgurVideoFragment extends Fragment { isMute = savedInstanceState.getBoolean(IS_MUTE_STATE); if (isMute) { player.setVolume(0f); - muteButton.setIconResource(R.drawable.ic_mute_24dp); + binding.getMuteButton().setIconResource(R.drawable.ic_mute_24dp); } else { player.setVolume(1f); - muteButton.setIconResource(R.drawable.ic_unmute_24dp); + binding.getMuteButton().setIconResource(R.drawable.ic_unmute_24dp); } } else if (muteVideo) { isMute = true; player.setVolume(0f); - muteButton.setIconResource(R.drawable.ic_mute_24dp); + binding.getMuteButton().setIconResource(R.drawable.ic_mute_24dp); } else { - muteButton.setIconResource(R.drawable.ic_unmute_24dp); + binding.getMuteButton().setIconResource(R.drawable.ic_unmute_24dp); } player.addListener(new Player.Listener() { @@ -308,23 +289,23 @@ public class ViewImgurVideoFragment extends Fragment { for (int i = 0; i < trackGroups.size(); i++) { String mimeType = trackGroups.get(i).getTrackFormat(0).sampleMimeType; if (mimeType != null && mimeType.contains("audio")) { - muteButton.setVisibility(View.VISIBLE); - muteButton.setOnClickListener(view -> { + binding.getMuteButton().setVisibility(View.VISIBLE); + binding.getMuteButton().setOnClickListener(view -> { if (isMute) { isMute = false; player.setVolume(1f); - muteButton.setIconResource(R.drawable.ic_unmute_24dp); + binding.getMuteButton().setIconResource(R.drawable.ic_unmute_24dp); } else { isMute = true; player.setVolume(0f); - muteButton.setIconResource(R.drawable.ic_mute_24dp); + binding.getMuteButton().setIconResource(R.drawable.ic_mute_24dp); } }); break; } } } else { - muteButton.setVisibility(View.GONE); + binding.getMuteButton().setVisibility(View.GONE); } } }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragmentBindingAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragmentBindingAdapter.java new file mode 100644 index 00000000..f1050db9 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragmentBindingAdapter.java @@ -0,0 +1,58 @@ +package ml.docilealligator.infinityforreddit.fragments; + +import android.widget.TextView; + +import com.google.android.exoplayer2.ui.PlayerView; +import com.google.android.material.bottomappbar.BottomAppBar; +import com.google.android.material.button.MaterialButton; + +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.databinding.FragmentViewImgurVideoBinding; + +class ViewImgurVideoFragmentBindingAdapter { + private FragmentViewImgurVideoBinding binding; + private MaterialButton muteButton; + private BottomAppBar bottomAppBar; + private TextView titleTextView; + private MaterialButton backButton; + private MaterialButton downloadButton; + private MaterialButton playbackSpeedButton; + + ViewImgurVideoFragmentBindingAdapter(FragmentViewImgurVideoBinding binding) { + this.binding = binding; + muteButton = binding.getRoot().findViewById(R.id.mute_exo_playback_control_view); + bottomAppBar = binding.getRoot().findViewById(R.id.bottom_navigation_exo_playback_control_view); + titleTextView = binding.getRoot().findViewById(R.id.title_text_view_exo_playback_control_view); + backButton = binding.getRoot().findViewById(R.id.back_button_exo_playback_control_view); + downloadButton = binding.getRoot().findViewById(R.id.download_image_view_exo_playback_control_view); + playbackSpeedButton = binding.getRoot().findViewById(R.id.playback_speed_image_view_exo_playback_control_view); + } + + PlayerView getRoot() { + return binding.getRoot(); + } + + MaterialButton getMuteButton() { + return muteButton; + } + + BottomAppBar getBottomAppBar() { + return bottomAppBar; + } + + TextView getTitleTextView() { + return titleTextView; + } + + MaterialButton getBackButton() { + return backButton; + } + + MaterialButton getDownloadButton() { + return downloadButton; + } + + MaterialButton getPlaybackSpeedButton() { + return playbackSpeedButton; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java index 39090be1..9e3f72d1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java @@ -19,10 +19,6 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.ProgressBar; -import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; @@ -44,17 +40,13 @@ import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView; import com.github.piasy.biv.BigImageViewer; import com.github.piasy.biv.loader.ImageLoader; import com.github.piasy.biv.loader.glide.GlideImageLoader; -import com.github.piasy.biv.view.BigImageView; import com.github.piasy.biv.view.GlideImageViewFactory; -import com.google.android.material.bottomappbar.BottomAppBar; import java.io.File; import java.util.concurrent.Executor; import javax.inject.Inject; -import butterknife.BindView; -import butterknife.ButterKnife; import me.saket.bettermovementmethod.BetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.BuildConfig; import ml.docilealligator.infinityforreddit.Infinity; @@ -66,6 +58,7 @@ import ml.docilealligator.infinityforreddit.asynctasks.SaveGIFToFile; import ml.docilealligator.infinityforreddit.bottomsheetfragments.CopyTextBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SetAsWallpaperBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; +import ml.docilealligator.infinityforreddit.databinding.FragmentViewRedditGalleryImageOrGifBinding; import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.services.DownloadMediaService; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -79,30 +72,6 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { public static final String EXTRA_IS_NSFW = "EIN"; private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0; - @BindView(R.id.progress_bar_view_reddit_gallery_image_or_gif_fragment) - ProgressBar progressBar; - @BindView(R.id.image_view_view_reddit_gallery_image_or_gif_fragment) - BigImageView imageView; - @BindView(R.id.load_image_error_linear_layout_view_reddit_gallery_image_or_gif_fragment) - LinearLayout errorLinearLayout; - @BindView(R.id.bottom_navigation_view_reddit_gallery_image_or_gif_fragment) - BottomAppBar bottomAppBar; - @BindView(R.id.caption_layout_view_reddit_gallery_image_or_gif_fragment) - LinearLayout captionLayout; - @BindView(R.id.caption_text_view_view_reddit_gallery_image_or_gif_fragment) - TextView captionTextView; - @BindView(R.id.caption_url_text_view_view_reddit_gallery_image_or_gif_fragment) - TextView captionUrlTextView; - @BindView(R.id.bottom_app_bar_menu_view_reddit_gallery_image_or_gif_fragment) - LinearLayout bottomAppBarMenu; - @BindView(R.id.title_text_view_view_reddit_gallery_image_or_gif_fragment) - TextView titleTextView; - @BindView(R.id.download_image_view_view_reddit_gallery_image_or_gif_fragment) - ImageView downloadImageView; - @BindView(R.id.share_image_view_view_reddit_gallery_image_or_gif_fragment) - ImageView shareImageView; - @BindView(R.id.wallpaper_image_view_view_reddit_gallery_image_or_gif_fragment) - ImageView wallpaperImageView; @Inject Executor mExecutor; @@ -114,22 +83,21 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { private boolean isDownloading = false; private boolean isUseBottomCaption = false; private boolean isFallback = false; + private FragmentViewRedditGalleryImageOrGifBinding binding; public ViewRedditGalleryImageOrGifFragment() { // Required empty public constructor } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { BigImageViewer.initialize(GlideImageLoader.with(activity.getApplicationContext())); - View rootView = inflater.inflate(R.layout.fragment_view_reddit_gallery_image_or_gif, container, false); + binding = FragmentViewRedditGalleryImageOrGifBinding.inflate(inflater, container, false); ((Infinity) activity.getApplication()).getAppComponent().inject(this); - ButterKnife.bind(this, rootView); - setHasOptionsMenu(true); media = getArguments().getParcelable(EXTRA_REDDIT_GALLERY_MEDIA); @@ -138,14 +106,14 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { glide = Glide.with(activity); if (activity.typeface != null) { - titleTextView.setTypeface(activity.typeface); - captionTextView.setTypeface(activity.typeface); - captionUrlTextView.setTypeface(activity.typeface); + binding.titleTextViewViewRedditGalleryImageOrGifFragment.setTypeface(activity.typeface); + binding.captionTextViewViewRedditGalleryImageOrGifFragment.setTypeface(activity.typeface); + binding.captionUrlTextViewViewRedditGalleryImageOrGifFragment.setTypeface(activity.typeface); } - imageView.setImageViewFactory(new GlideImageViewFactory()); + binding.imageViewViewRedditGalleryImageOrGifFragment.setImageViewFactory(new GlideImageViewFactory()); - imageView.setImageLoaderCallback(new ImageLoader.Callback() { + binding.imageViewViewRedditGalleryImageOrGifFragment.setImageLoaderCallback(new ImageLoader.Callback() { @Override public void onCacheHit(int imageType, File image) { @@ -173,9 +141,9 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { @Override public void onSuccess(File image) { - progressBar.setVisibility(View.GONE); + binding.progressBarViewRedditGalleryImageOrGifFragment.setVisibility(View.GONE); - final SubsamplingScaleImageView view = imageView.getSSIV(); + final SubsamplingScaleImageView view = binding.imageViewViewRedditGalleryImageOrGifFragment.getSSIV(); if (view != null) { view.setOnImageEventListener(new SubsamplingScaleImageView.DefaultOnImageEventListener() { @@ -195,7 +163,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { // Make sure it's not stuck in a loop if it comes to that // Fallback url should be empty if it's not an album item if (!isFallback && media.hasFallback()) { - imageView.cancel(); + binding.imageViewViewRedditGalleryImageOrGifFragment.cancel(); isFallback = true; loadImage(); } else { @@ -208,8 +176,8 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { @Override public void onFail(Exception error) { - progressBar.setVisibility(View.GONE); - errorLinearLayout.setVisibility(View.VISIBLE); + binding.progressBarViewRedditGalleryImageOrGifFragment.setVisibility(View.GONE); + binding.loadImageErrorLinearLayoutViewRedditGalleryImageOrGifFragment.setVisibility(View.VISIBLE); } }); @@ -221,53 +189,53 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { boolean captionUrlIsEmpty = TextUtils.isEmpty(captionUrl); boolean captionTextOrUrlIsNotEmpty = !captionIsEmpty || !captionUrlIsEmpty; - imageView.setOnClickListener(view -> { + binding.imageViewViewRedditGalleryImageOrGifFragment.setOnClickListener(view -> { if (activity.isActionBarHidden()) { activity.getWindow().getDecorView().setSystemUiVisibility(0); activity.setActionBarHidden(false); if (activity.isUseBottomAppBar()) { - bottomAppBarMenu.setVisibility(View.VISIBLE); + binding.bottomAppBarMenuViewRedditGalleryImageOrGifFragment.setVisibility(View.VISIBLE); } if (captionTextOrUrlIsNotEmpty) { - captionLayout.setVisibility(View.VISIBLE); + binding.captionLayoutViewRedditGalleryImageOrGifFragment.setVisibility(View.VISIBLE); } } else { hideAppBar(); } }); - captionLayout.setOnClickListener(view -> hideAppBar()); + binding.captionLayoutViewRedditGalleryImageOrGifFragment.setOnClickListener(view -> hideAppBar()); - errorLinearLayout.setOnClickListener(view -> { - progressBar.setVisibility(View.VISIBLE); - errorLinearLayout.setVisibility(View.GONE); + binding.loadImageErrorLinearLayoutViewRedditGalleryImageOrGifFragment.setOnClickListener(view -> { + binding.progressBarViewRedditGalleryImageOrGifFragment.setVisibility(View.VISIBLE); + binding.loadImageErrorLinearLayoutViewRedditGalleryImageOrGifFragment.setVisibility(View.GONE); loadImage(); }); if (activity.isUseBottomAppBar()) { - bottomAppBarMenu.setVisibility(View.VISIBLE); + binding.bottomAppBarMenuViewRedditGalleryImageOrGifFragment.setVisibility(View.VISIBLE); if (media.mediaType == Post.Gallery.TYPE_GIF) { - titleTextView.setText(getString(R.string.view_reddit_gallery_activity_gif_label, + binding.titleTextViewViewRedditGalleryImageOrGifFragment.setText(getString(R.string.view_reddit_gallery_activity_gif_label, getArguments().getInt(EXTRA_INDEX) + 1, getArguments().getInt(EXTRA_MEDIA_COUNT))); } else { - titleTextView.setText(getString(R.string.view_reddit_gallery_activity_image_label, + binding.titleTextViewViewRedditGalleryImageOrGifFragment.setText(getString(R.string.view_reddit_gallery_activity_image_label, getArguments().getInt(EXTRA_INDEX) + 1, getArguments().getInt(EXTRA_MEDIA_COUNT))); } - downloadImageView.setOnClickListener(view -> { + binding.downloadImageViewViewRedditGalleryImageOrGifFragment.setOnClickListener(view -> { if (isDownloading) { return; } isDownloading = true; requestPermissionAndDownload(); }); - shareImageView.setOnClickListener(view -> { + binding.shareImageViewViewRedditGalleryImageOrGifFragment.setOnClickListener(view -> { if (media.mediaType == Post.Gallery.TYPE_GIF) { shareGif(); } else { shareImage(); } }); - wallpaperImageView.setOnClickListener(view -> { + binding.wallpaperImageViewViewRedditGalleryImageOrGifFragment.setOnClickListener(view -> { setWallpaper(); }); } @@ -276,21 +244,21 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { isUseBottomCaption = true; if (!activity.isUseBottomAppBar()) { - bottomAppBarMenu.setVisibility(View.GONE); + binding.bottomAppBarMenuViewRedditGalleryImageOrGifFragment.setVisibility(View.GONE); } - captionLayout.setVisibility(View.VISIBLE); + binding.captionLayoutViewRedditGalleryImageOrGifFragment.setVisibility(View.VISIBLE); if (!captionIsEmpty) { - captionTextView.setVisibility(View.VISIBLE); - captionTextView.setText(caption); - captionTextView.setOnClickListener(view -> hideAppBar()); - captionTextView.setOnLongClickListener(view -> { + binding.captionTextViewViewRedditGalleryImageOrGifFragment.setVisibility(View.VISIBLE); + binding.captionTextViewViewRedditGalleryImageOrGifFragment.setText(caption); + binding.captionTextViewViewRedditGalleryImageOrGifFragment.setOnClickListener(view -> hideAppBar()); + binding.captionTextViewViewRedditGalleryImageOrGifFragment.setOnLongClickListener(view -> { if (activity != null && !activity.isDestroyed() && !activity.isFinishing() - && captionTextView.getSelectionStart() == -1 - && captionTextView.getSelectionEnd() == -1) { + && binding.captionTextViewViewRedditGalleryImageOrGifFragment.getSelectionStart() == -1 + && binding.captionTextViewViewRedditGalleryImageOrGifFragment.getSelectionEnd() == -1) { CopyTextBottomSheetFragment.show( activity.getSupportFragmentManager(), caption, null); } @@ -304,23 +272,23 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { urlWithoutScheme = captionUrl.substring(scheme.length() + 3); } - captionUrlTextView.setText(TextUtils.isEmpty(urlWithoutScheme) ? captionUrl : urlWithoutScheme); + binding.captionUrlTextViewViewRedditGalleryImageOrGifFragment.setText(TextUtils.isEmpty(urlWithoutScheme) ? captionUrl : urlWithoutScheme); - BetterLinkMovementMethod.linkify(Linkify.WEB_URLS, captionUrlTextView).setOnLinkLongClickListener((textView, url) -> { + BetterLinkMovementMethod.linkify(Linkify.WEB_URLS, binding.captionUrlTextViewViewRedditGalleryImageOrGifFragment).setOnLinkLongClickListener((textView, url) -> { if (activity != null && !activity.isDestroyed() && !activity.isFinishing()) { UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = UrlMenuBottomSheetFragment.newInstance(captionUrl); urlMenuBottomSheetFragment.show(activity.getSupportFragmentManager(), null); } return true; }); - captionUrlTextView.setVisibility(View.VISIBLE); - captionUrlTextView.setHighlightColor(Color.TRANSPARENT); + binding.captionUrlTextViewViewRedditGalleryImageOrGifFragment.setVisibility(View.VISIBLE); + binding.captionUrlTextViewViewRedditGalleryImageOrGifFragment.setHighlightColor(Color.TRANSPARENT); } } else { - captionLayout.setVisibility(View.GONE); + binding.captionLayoutViewRedditGalleryImageOrGifFragment.setVisibility(View.GONE); } - return rootView; + return binding.getRoot(); } private void hideAppBar() { @@ -333,17 +301,17 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { | View.SYSTEM_UI_FLAG_IMMERSIVE); activity.setActionBarHidden(true); if (activity.isUseBottomAppBar()) { - bottomAppBarMenu.setVisibility(View.GONE); + binding.bottomAppBarMenuViewRedditGalleryImageOrGifFragment.setVisibility(View.GONE); } - captionLayout.setVisibility(View.GONE); + binding.captionLayoutViewRedditGalleryImageOrGifFragment.setVisibility(View.GONE); } private void loadImage() { if (isFallback) { - imageView.showImage(Uri.parse(media.fallbackUrl)); + binding.imageViewViewRedditGalleryImageOrGifFragment.showImage(Uri.parse(media.fallbackUrl)); } else{ - imageView.showImage(Uri.parse(media.url)); + binding.imageViewViewRedditGalleryImageOrGifFragment.showImage(Uri.parse(media.url)); } } @@ -532,7 +500,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { @Override public void onResume() { super.onResume(); - SubsamplingScaleImageView ssiv = imageView.getSSIV(); + SubsamplingScaleImageView ssiv = binding.imageViewViewRedditGalleryImageOrGifFragment.getSSIV(); if (ssiv == null || !ssiv.hasImage()) { loadImage(); } @@ -553,9 +521,9 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { @Override public void onDestroyView() { super.onDestroyView(); - imageView.cancel(); + binding.imageViewViewRedditGalleryImageOrGifFragment.cancel(); isFallback = false; - SubsamplingScaleImageView subsamplingScaleImageView = imageView.getSSIV(); + SubsamplingScaleImageView subsamplingScaleImageView = binding.imageViewViewRedditGalleryImageOrGifFragment.getSSIV(); if (subsamplingScaleImageView != null) { subsamplingScaleImageView.recycle(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java index ba165592..8d6a00dc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java @@ -15,9 +15,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageButton; import android.widget.LinearLayout; -import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; @@ -32,20 +30,15 @@ import com.google.android.exoplayer2.Tracks; import com.google.android.exoplayer2.source.ProgressiveMediaSource; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import com.google.android.exoplayer2.trackselection.TrackSelector; -import com.google.android.exoplayer2.ui.PlayerView; import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DefaultHttpDataSource; import com.google.android.exoplayer2.upstream.cache.CacheDataSource; import com.google.android.exoplayer2.upstream.cache.SimpleCache; -import com.google.android.material.bottomappbar.BottomAppBar; -import com.google.android.material.button.MaterialButton; import com.google.common.collect.ImmutableList; import javax.inject.Inject; import javax.inject.Named; -import butterknife.BindView; -import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.ViewRedditGalleryActivity; @@ -67,20 +60,7 @@ public class ViewRedditGalleryVideoFragment extends Fragment { private static final String IS_MUTE_STATE = "IMS"; private static final String POSITION_STATE = "PS"; private static final String PLAYBACK_SPEED_STATE = "PSS"; - @BindView(R.id.player_view_view_reddit_gallery_video_fragment) - PlayerView videoPlayerView; - @BindView(R.id.mute_exo_playback_control_view) - ImageButton muteButton; - @BindView(R.id.bottom_navigation_exo_playback_control_view) - BottomAppBar bottomAppBar; - @BindView(R.id.title_text_view_exo_playback_control_view) - TextView titleTextView; - @BindView(R.id.back_button_exo_playback_control_view) - MaterialButton backButton; - @BindView(R.id.download_image_view_exo_playback_control_view) - MaterialButton downloadButton; - @BindView(R.id.playback_speed_image_view_exo_playback_control_view) - MaterialButton playbackSpeedButton; + private ViewRedditGalleryActivity activity; private Post.Gallery galleryVideo; private String subredditName; @@ -96,6 +76,7 @@ public class ViewRedditGalleryVideoFragment extends Fragment { SharedPreferences mSharedPreferences; @Inject SimpleCache mSimpleCache; + private ViewRedditGalleryVideoFragmentBindingAdapter binding; public ViewRedditGalleryVideoFragment() { // Required empty public constructor @@ -103,18 +84,16 @@ public class ViewRedditGalleryVideoFragment extends Fragment { @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_view_reddit_gallery_video, container, false); + binding = new ViewRedditGalleryVideoFragmentBindingAdapter(ml.docilealligator.infinityforreddit.databinding.FragmentViewRedditGalleryVideoBinding.inflate(inflater, container, false)); ((Infinity) activity.getApplication()).getAppComponent().inject(this); - ButterKnife.bind(this, rootView); - setHasOptionsMenu(true); if (activity.typeface != null) { - titleTextView.setTypeface(activity.typeface); + binding.getTitleTextView().setTypeface(activity.typeface); } activity.setVolumeControlStream(AudioManager.STREAM_MUSIC); @@ -127,19 +106,19 @@ public class ViewRedditGalleryVideoFragment extends Fragment { if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || getResources().getBoolean(R.bool.isTablet)) { //Set player controller bottom margin in order to display it above the navbar int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android"); - LinearLayout controllerLinearLayout = rootView.findViewById(R.id.linear_layout_exo_playback_control_view); + LinearLayout controllerLinearLayout = binding.getRoot().findViewById(R.id.linear_layout_exo_playback_control_view); ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) controllerLinearLayout.getLayoutParams(); params.bottomMargin = getResources().getDimensionPixelSize(resourceId); } else { //Set player controller right margin in order to display it above the navbar int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android"); - LinearLayout controllerLinearLayout = rootView.findViewById(R.id.linear_layout_exo_playback_control_view); + LinearLayout controllerLinearLayout = binding.getRoot().findViewById(R.id.linear_layout_exo_playback_control_view); ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) controllerLinearLayout.getLayoutParams(); params.rightMargin = getResources().getDimensionPixelSize(resourceId); } } - videoPlayerView.setControllerVisibilityListener(visibility -> { + binding.getPlayerView().setControllerVisibilityListener(visibility -> { switch (visibility) { case View.GONE: activity.getWindow().getDecorView().setSystemUiVisibility( @@ -160,7 +139,7 @@ public class ViewRedditGalleryVideoFragment extends Fragment { TrackSelector trackSelector = new DefaultTrackSelector(activity); player = new ExoPlayer.Builder(activity).setTrackSelector(trackSelector).build(); - videoPlayerView.setPlayer(player); + binding.getPlayerView().setPlayer(player); dataSourceFactory = new CacheDataSource.Factory().setCache(mSimpleCache) .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setAllowCrossProtocolRedirects(true).setUserAgent(APIUtils.USER_AGENT)); player.prepare(); @@ -172,27 +151,27 @@ public class ViewRedditGalleryVideoFragment extends Fragment { Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_PLAYBACK_SPEED, "100")); preparePlayer(savedInstanceState); - titleTextView.setText(getString(R.string.view_reddit_gallery_activity_video_label, + binding.getTitleTextView().setText(getString(R.string.view_reddit_gallery_activity_video_label, getArguments().getInt(EXTRA_INDEX) + 1, getArguments().getInt(EXTRA_MEDIA_COUNT))); if (activity.isUseBottomAppBar()) { - bottomAppBar.setVisibility(View.VISIBLE); - backButton.setOnClickListener(view -> { + binding.getBottomAppBar().setVisibility(View.VISIBLE); + binding.getBackButton().setOnClickListener(view -> { activity.finish(); }); - downloadButton.setOnClickListener(view -> { + binding.getDownloadButton().setOnClickListener(view -> { if (isDownloading) { return; } isDownloading = true; requestPermissionAndDownload(); }); - playbackSpeedButton.setOnClickListener(view -> { + binding.getPlaybackSpeedButton().setOnClickListener(view -> { changePlaybackSpeed(); }); } - return rootView; + return binding.getRoot(); } private void changePlaybackSpeed() { @@ -293,17 +272,17 @@ public class ViewRedditGalleryVideoFragment extends Fragment { isMute = savedInstanceState.getBoolean(IS_MUTE_STATE); if (isMute) { player.setVolume(0f); - muteButton.setImageResource(R.drawable.ic_mute_24dp); + binding.getMuteButton().setImageResource(R.drawable.ic_mute_24dp); } else { player.setVolume(1f); - muteButton.setImageResource(R.drawable.ic_unmute_24dp); + binding.getMuteButton().setImageResource(R.drawable.ic_unmute_24dp); } } else if (muteVideo) { isMute = true; player.setVolume(0f); - muteButton.setImageResource(R.drawable.ic_mute_24dp); + binding.getMuteButton().setImageResource(R.drawable.ic_mute_24dp); } else { - muteButton.setImageResource(R.drawable.ic_unmute_24dp); + binding.getMuteButton().setImageResource(R.drawable.ic_unmute_24dp); } player.addListener(new Player.Listener() { @@ -314,23 +293,23 @@ public class ViewRedditGalleryVideoFragment extends Fragment { for (int i = 0; i < trackGroups.size(); i++) { String mimeType = trackGroups.get(i).getTrackFormat(0).sampleMimeType; if (mimeType != null && mimeType.contains("audio")) { - muteButton.setVisibility(View.VISIBLE); - muteButton.setOnClickListener(view -> { + binding.getMuteButton().setVisibility(View.VISIBLE); + binding.getMuteButton().setOnClickListener(view -> { if (isMute) { isMute = false; player.setVolume(1f); - muteButton.setImageResource(R.drawable.ic_unmute_24dp); + binding.getMuteButton().setImageResource(R.drawable.ic_unmute_24dp); } else { isMute = true; player.setVolume(0f); - muteButton.setImageResource(R.drawable.ic_mute_24dp); + binding.getMuteButton().setImageResource(R.drawable.ic_mute_24dp); } }); break; } } } else { - muteButton.setVisibility(View.GONE); + binding.getMuteButton().setVisibility(View.GONE); } } }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragmentBindingAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragmentBindingAdapter.java new file mode 100644 index 00000000..d86a5ef2 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragmentBindingAdapter.java @@ -0,0 +1,65 @@ +package ml.docilealligator.infinityforreddit.fragments; + +import android.widget.ImageButton; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import com.google.android.exoplayer2.ui.PlayerView; +import com.google.android.material.bottomappbar.BottomAppBar; +import com.google.android.material.button.MaterialButton; + +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.databinding.FragmentViewRedditGalleryVideoBinding; + +class ViewRedditGalleryVideoFragmentBindingAdapter { + private FragmentViewRedditGalleryVideoBinding binding; + + private ImageButton muteButton; + private BottomAppBar bottomAppBar; + private TextView titleTextView; + private MaterialButton backButton; + private MaterialButton downloadButton; + private MaterialButton playbackSpeedButton; + + ViewRedditGalleryVideoFragmentBindingAdapter(FragmentViewRedditGalleryVideoBinding binding) { + this.binding = binding; + muteButton = binding.getRoot().findViewById(R.id.mute_exo_playback_control_view); + bottomAppBar = binding.getRoot().findViewById(R.id.bottom_navigation_exo_playback_control_view); + titleTextView = binding.getRoot().findViewById(R.id.title_text_view_exo_playback_control_view); + backButton = binding.getRoot().findViewById(R.id.back_button_exo_playback_control_view); + downloadButton = binding.getRoot().findViewById(R.id.download_image_view_exo_playback_control_view); + playbackSpeedButton = binding.getRoot().findViewById(R.id.playback_speed_image_view_exo_playback_control_view); + } + + RelativeLayout getRoot() { + return binding.getRoot(); + } + + PlayerView getPlayerView() { + return binding.playerViewViewRedditGalleryVideoFragment; + } + + ImageButton getMuteButton() { + return muteButton; + } + + BottomAppBar getBottomAppBar() { + return bottomAppBar; + } + + TextView getTitleTextView() { + return titleTextView; + } + + MaterialButton getBackButton() { + return backButton; + } + + MaterialButton getDownloadButton() { + return downloadButton; + } + + MaterialButton getPlaybackSpeedButton() { + return playbackSpeedButton; + } +} diff --git a/app/src/main/res/layout/fragment_subreddit_listing.xml b/app/src/main/res/layout/fragment_subreddit_listing.xml index 16122bd6..237322bf 100644 --- a/app/src/main/res/layout/fragment_subreddit_listing.xml +++ b/app/src/main/res/layout/fragment_subreddit_listing.xml @@ -1,7 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" - android:id="@+id/coordinator_layout_subreddit_listing_fragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:application=".SubredditListingFragment"> diff --git a/app/src/main/res/layout/fragment_user_listing.xml b/app/src/main/res/layout/fragment_user_listing.xml index 8e5aeb23..ec6c88b8 100644 --- a/app/src/main/res/layout/fragment_user_listing.xml +++ b/app/src/main/res/layout/fragment_user_listing.xml @@ -1,7 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" - android:id="@+id/coordinator_layout_user_listing_fragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:application=".UserListingFragment"> diff --git a/app/src/main/res/layout/fragment_view_imgur_image.xml b/app/src/main/res/layout/fragment_view_imgur_image.xml index 78bde93d..0c031d32 100644 --- a/app/src/main/res/layout/fragment_view_imgur_image.xml +++ b/app/src/main/res/layout/fragment_view_imgur_image.xml @@ -1,8 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" - xmlns:app="http://schemas.android.com/apk/res-auto" - android:id="@+id/constraintLayout" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".fragments.ViewImgurImageFragment"> diff --git a/app/src/main/res/layout/fragment_view_imgur_video.xml b/app/src/main/res/layout/fragment_view_imgur_video.xml index 824a6b02..3d5c6963 100644 --- a/app/src/main/res/layout/fragment_view_imgur_video.xml +++ b/app/src/main/res/layout/fragment_view_imgur_video.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/player_view_view_imgur_video_fragment" xmlns:app="http://schemas.android.com/apk/res-auto" app:controller_layout_id="@layout/exo_playback_control_view" tools:context=".fragments.ViewImgurVideoFragment" />
\ No newline at end of file diff --git a/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml b/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml index 66c250dd..61296cc7 100644 --- a/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml +++ b/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml @@ -2,7 +2,6 @@ <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" - android:id="@+id/constraintLayout" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".fragments.ViewImgurImageFragment"> |