finish view binding migration and remove butterknife
This commit is contained in:
parent
8a58a53db7
commit
f8cfdc4706
3 changed files with 25 additions and 55 deletions
|
|
@ -77,9 +77,6 @@ dependencies {
|
||||||
implementation 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.11.0'
|
implementation 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.11.0'
|
||||||
implementation 'com.android.support:multidex:1.0.3'
|
implementation 'com.android.support:multidex:1.0.3'
|
||||||
|
|
||||||
implementation 'com.jakewharton:butterknife:10.2.0'
|
|
||||||
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0'
|
|
||||||
|
|
||||||
implementation 'com.squareup.retrofit2:retrofit:2.6.2'
|
implementation 'com.squareup.retrofit2:retrofit:2.6.2'
|
||||||
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
|
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,49 +10,46 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import com.dkanada.gramophone.R;
|
import com.dkanada.gramophone.R;
|
||||||
|
|
||||||
import butterknife.BindView;
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
|
|
||||||
public class MediaEntryViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
public class MediaEntryViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||||
@Nullable
|
@Nullable
|
||||||
@BindView(R.id.image)
|
|
||||||
public ImageView image;
|
public ImageView image;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@BindView(R.id.image_text)
|
|
||||||
public TextView imageText;
|
public TextView imageText;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@BindView(R.id.title)
|
|
||||||
public TextView title;
|
public TextView title;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@BindView(R.id.text)
|
|
||||||
public TextView text;
|
public TextView text;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@BindView(R.id.menu)
|
|
||||||
public View menu;
|
public View menu;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@BindView(R.id.separator)
|
|
||||||
public View separator;
|
public View separator;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@BindView(R.id.short_separator)
|
|
||||||
public View shortSeparator;
|
public View shortSeparator;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@BindView(R.id.drag_view)
|
|
||||||
public View dragView;
|
public View dragView;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@BindView(R.id.palette_color_container)
|
|
||||||
public View paletteColorContainer;
|
public View paletteColorContainer;
|
||||||
|
|
||||||
public MediaEntryViewHolder(View itemView) {
|
public MediaEntryViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
ButterKnife.bind(this, itemView);
|
|
||||||
|
image = itemView.findViewById(R.id.image);
|
||||||
|
imageText = itemView.findViewById(R.id.image_text);
|
||||||
|
title = itemView.findViewById(R.id.title);
|
||||||
|
text = itemView.findViewById(R.id.text);
|
||||||
|
menu = itemView.findViewById(R.id.menu);
|
||||||
|
separator = itemView.findViewById(R.id.separator);
|
||||||
|
shortSeparator = itemView.findViewById(R.id.short_separator);
|
||||||
|
dragView = itemView.findViewById(R.id.drag_view);
|
||||||
|
paletteColorContainer = itemView.findViewById(R.id.palette_color_container);
|
||||||
|
|
||||||
itemView.setOnClickListener(this);
|
itemView.setOnClickListener(this);
|
||||||
itemView.setOnLongClickListener(this);
|
itemView.setOnLongClickListener(this);
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
package com.dkanada.gramophone.ui.fragments.mainactivity.library.pager;
|
package com.dkanada.gramophone.ui.fragments.mainactivity.library.pager;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.annotation.LayoutRes;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
|
|
||||||
import com.dkanada.gramophone.App;
|
import com.dkanada.gramophone.App;
|
||||||
|
import com.dkanada.gramophone.databinding.FragmentMainActivityRecyclerViewBinding;
|
||||||
import com.dkanada.gramophone.util.PreferenceUtil;
|
import com.dkanada.gramophone.util.PreferenceUtil;
|
||||||
import com.google.android.material.appbar.AppBarLayout;
|
import com.google.android.material.appbar.AppBarLayout;
|
||||||
import com.google.android.material.appbar.AppBarLayout.OnOffsetChangedListener;
|
import com.google.android.material.appbar.AppBarLayout.OnOffsetChangedListener;
|
||||||
|
|
@ -16,27 +16,13 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.kabouzeid.appthemehelper.ThemeStore;
|
import com.kabouzeid.appthemehelper.ThemeStore;
|
||||||
import com.dkanada.gramophone.R;
|
import com.dkanada.gramophone.R;
|
||||||
import com.dkanada.gramophone.util.ViewUtil;
|
import com.dkanada.gramophone.util.ViewUtil;
|
||||||
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView;
|
|
||||||
|
|
||||||
import butterknife.BindView;
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import butterknife.Unbinder;
|
|
||||||
|
|
||||||
public abstract class AbsLibraryPagerRecyclerViewFragment<A extends RecyclerView.Adapter, L extends RecyclerView.LayoutManager, Q> extends AbsLibraryPagerFragment implements OnOffsetChangedListener {
|
public abstract class AbsLibraryPagerRecyclerViewFragment<A extends RecyclerView.Adapter, L extends RecyclerView.LayoutManager, Q> extends AbsLibraryPagerFragment implements OnOffsetChangedListener {
|
||||||
|
private FragmentMainActivityRecyclerViewBinding binding;
|
||||||
private Unbinder unbinder;
|
|
||||||
|
|
||||||
@BindView(R.id.container)
|
|
||||||
View container;
|
|
||||||
@BindView(R.id.recycler_view)
|
|
||||||
RecyclerView recyclerView;
|
|
||||||
@BindView(android.R.id.empty)
|
|
||||||
TextView empty;
|
|
||||||
|
|
||||||
private A adapter;
|
private A adapter;
|
||||||
private L layoutManager;
|
private L layoutManager;
|
||||||
|
|
@ -47,13 +33,13 @@ public abstract class AbsLibraryPagerRecyclerViewFragment<A extends RecyclerView
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(getLayoutRes(), container, false);
|
binding = FragmentMainActivityRecyclerViewBinding.inflate(getLayoutInflater(), container, false);
|
||||||
unbinder = ButterKnife.bind(this, view);
|
|
||||||
return view;
|
return binding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
getLibraryFragment().addOnAppBarOffsetChangedListener(this);
|
getLibraryFragment().addOnAppBarOffsetChangedListener(this);
|
||||||
|
|
@ -86,29 +72,27 @@ public abstract class AbsLibraryPagerRecyclerViewFragment<A extends RecyclerView
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initRecyclerView() {
|
private void initRecyclerView() {
|
||||||
if (recyclerView instanceof FastScrollRecyclerView) {
|
ViewUtil.setUpFastScrollRecyclerViewColor(getActivity(), binding.recyclerView, ThemeStore.accentColor(getActivity()));
|
||||||
ViewUtil.setUpFastScrollRecyclerViewColor(getActivity(), ((FastScrollRecyclerView) recyclerView), ThemeStore.accentColor(getActivity()));
|
|
||||||
}
|
|
||||||
|
|
||||||
recyclerView.setLayoutManager(layoutManager);
|
binding.recyclerView.setLayoutManager(layoutManager);
|
||||||
recyclerView.setAdapter(adapter);
|
binding.recyclerView.setAdapter(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void invalidateAdapter() {
|
protected void invalidateAdapter() {
|
||||||
initAdapter();
|
initAdapter();
|
||||||
initQuery();
|
initQuery();
|
||||||
|
|
||||||
recyclerView.setAdapter(adapter);
|
binding.recyclerView.setAdapter(adapter);
|
||||||
loadItems(0);
|
loadItems(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void invalidateLayoutManager() {
|
protected void invalidateLayoutManager() {
|
||||||
initLayoutManager();
|
initLayoutManager();
|
||||||
recyclerView.setLayoutManager(layoutManager);
|
binding.recyclerView.setLayoutManager(layoutManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RecyclerView getRecyclerView() {
|
protected RecyclerView getRecyclerView() {
|
||||||
return recyclerView;
|
return binding.recyclerView;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected A getAdapter() {
|
protected A getAdapter() {
|
||||||
|
|
@ -128,11 +112,6 @@ public abstract class AbsLibraryPagerRecyclerViewFragment<A extends RecyclerView
|
||||||
return R.string.empty;
|
return R.string.empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@LayoutRes
|
|
||||||
protected int getLayoutRes() {
|
|
||||||
return R.layout.fragment_main_activity_recycler_view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
protected abstract A createAdapter();
|
protected abstract A createAdapter();
|
||||||
|
|
||||||
|
|
@ -146,7 +125,7 @@ public abstract class AbsLibraryPagerRecyclerViewFragment<A extends RecyclerView
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onOffsetChanged(AppBarLayout appBarLayout, int i) {
|
public void onOffsetChanged(AppBarLayout appBarLayout, int i) {
|
||||||
container.setPadding(container.getPaddingLeft(), container.getPaddingTop(), container.getPaddingRight(), getLibraryFragment().getTotalAppBarScrollingRange() + i);
|
binding.container.setPadding(binding.container.getPaddingLeft(), binding.container.getPaddingTop(), binding.container.getPaddingRight(), getLibraryFragment().getTotalAppBarScrollingRange() + i);
|
||||||
|
|
||||||
int last = 0;
|
int last = 0;
|
||||||
if (!loading && getLayoutManager() instanceof GridLayoutManager) {
|
if (!loading && getLayoutManager() instanceof GridLayoutManager) {
|
||||||
|
|
@ -172,13 +151,10 @@ public abstract class AbsLibraryPagerRecyclerViewFragment<A extends RecyclerView
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
|
|
||||||
getLibraryFragment().removeOnAppBarOffsetChangedListener(this);
|
getLibraryFragment().removeOnAppBarOffsetChangedListener(this);
|
||||||
unbinder.unbind();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkIsEmpty() {
|
private void checkIsEmpty() {
|
||||||
if (empty != null) {
|
binding.empty.setText(getEmptyMessage());
|
||||||
empty.setText(getEmptyMessage());
|
binding.empty.setVisibility(adapter == null || adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||||
empty.setVisibility(adapter == null || adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue