Use item decorator in preference to inline ImageView.
This eliminates the need to include the drawable in the app_list_item layout.
This commit is contained in:
parent
6e613ad952
commit
258064d495
@ -12,9 +12,11 @@ class AppListAdapter extends RecyclerView.Adapter<AppListItemController> {
|
||||
|
||||
private Cursor cursor;
|
||||
private final Activity activity;
|
||||
private final AppListItemDivider divider;
|
||||
|
||||
AppListAdapter(Activity activity) {
|
||||
this.activity = activity;
|
||||
divider = new AppListItemDivider(activity);
|
||||
}
|
||||
|
||||
public void setAppCursor(Cursor cursor) {
|
||||
@ -37,4 +39,16 @@ class AppListAdapter extends RecyclerView.Adapter<AppListItemController> {
|
||||
public int getItemCount() {
|
||||
return cursor == null ? 0 : cursor.getCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
|
||||
super.onAttachedToRecyclerView(recyclerView);
|
||||
recyclerView.addItemDecoration(divider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
|
||||
recyclerView.removeItemDecoration(divider);
|
||||
super.onDetachedFromRecyclerView(recyclerView);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
package org.fdroid.fdroid.views.apps;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.DividerItemDecoration;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
import org.fdroid.fdroid.R;
|
||||
import org.fdroid.fdroid.Utils;
|
||||
|
||||
/**
|
||||
* Draws a faint line between items, to be used with the {@link AppListItemDivider}.
|
||||
*/
|
||||
public class AppListItemDivider extends DividerItemDecoration {
|
||||
private final int itemSpacing;
|
||||
|
||||
public AppListItemDivider(Context context) {
|
||||
super(context, DividerItemDecoration.VERTICAL);
|
||||
setDrawable(ContextCompat.getDrawable(context, R.drawable.app_list_item_divider));
|
||||
itemSpacing = Utils.dpToPx(8, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
|
||||
super.getItemOffsets(outRect, view, parent, state);
|
||||
int position = parent.getChildAdapterPosition(view);
|
||||
if (position > 0) {
|
||||
outRect.bottom = itemSpacing;
|
||||
}
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ import android.view.ViewGroup;
|
||||
import org.fdroid.fdroid.R;
|
||||
import org.fdroid.fdroid.data.App;
|
||||
import org.fdroid.fdroid.views.apps.AppListItemController;
|
||||
import org.fdroid.fdroid.views.apps.AppListItemDivider;
|
||||
|
||||
/**
|
||||
* Wraps a cursor which should have a list of "apps which can be updated". Also includes a header
|
||||
@ -18,9 +19,11 @@ public class MyAppsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
|
||||
private Cursor updatesCursor;
|
||||
private final Activity activity;
|
||||
private final AppListItemDivider divider;
|
||||
|
||||
public MyAppsAdapter(Activity activity) {
|
||||
this.activity = activity;
|
||||
divider = new AppListItemDivider(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -73,4 +76,17 @@ public class MyAppsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
updatesCursor = cursor;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
|
||||
super.onAttachedToRecyclerView(recyclerView);
|
||||
recyclerView.addItemDecoration(divider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
|
||||
recyclerView.removeItemDecoration(divider);
|
||||
super.onDetachedFromRecyclerView(recyclerView);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -64,15 +64,4 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/icon" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/app_list_item_divider"
|
||||
app:layout_constraintTop_toBottomOf="@+id/status"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_marginTop="8dp"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user