Merge branch 'screenshots-layout' into 'master'
Improve screenshots layout See merge request !569
This commit is contained in:
commit
d65d64f6f8
@ -582,7 +582,6 @@ public class AppDetailsRecyclerViewAdapter
|
||||
snapHelper.attachToRecyclerView(null);
|
||||
}
|
||||
snapHelper = new LinearLayoutManagerSnapHelper(lm);
|
||||
snapHelper.setLinearSnapHelperListener(adapter);
|
||||
snapHelper.attachToRecyclerView(recyclerView);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
package org.fdroid.fdroid.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -17,22 +15,13 @@ import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
||||
import org.fdroid.fdroid.R;
|
||||
import org.fdroid.fdroid.data.App;
|
||||
|
||||
public class ScreenShotsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
implements LinearLayoutManagerSnapHelper.LinearSnapHelperListener {
|
||||
class ScreenShotsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
private final String[] screenshots;
|
||||
private final DisplayImageOptions displayImageOptions;
|
||||
private View selectedView;
|
||||
private int selectedPosition;
|
||||
private final int selectedItemElevation;
|
||||
private final int unselectedItemMargin;
|
||||
|
||||
public ScreenShotsRecyclerViewAdapter(Context context, App app) {
|
||||
ScreenShotsRecyclerViewAdapter(Context context, App app) {
|
||||
super();
|
||||
screenshots = app.getAllScreenshots(context);
|
||||
selectedPosition = 0;
|
||||
Resources r = context.getResources();
|
||||
selectedItemElevation = r.getDimensionPixelSize(R.dimen.details_screenshot_selected_elevation);
|
||||
unselectedItemMargin = r.getDimensionPixelSize(R.dimen.details_screenshot_margin);
|
||||
displayImageOptions = new DisplayImageOptions.Builder()
|
||||
.cacheInMemory(true)
|
||||
.cacheOnDisk(true)
|
||||
@ -46,10 +35,6 @@ public class ScreenShotsRecyclerViewAdapter extends RecyclerView.Adapter<Recycle
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
ScreenShotViewHolder vh = (ScreenShotViewHolder) holder;
|
||||
setViewSelected(vh.itemView, position == selectedPosition);
|
||||
if (position == selectedPosition) {
|
||||
this.selectedView = vh.itemView;
|
||||
}
|
||||
ImageLoader.getInstance().displayImage(screenshots[position],
|
||||
vh.image, displayImageOptions);
|
||||
}
|
||||
@ -66,30 +51,6 @@ public class ScreenShotsRecyclerViewAdapter extends RecyclerView.Adapter<Recycle
|
||||
return screenshots.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSnappedToView(View view, int snappedPosition) {
|
||||
// Deselect the previous selected view first
|
||||
setViewSelected(selectedView, false);
|
||||
|
||||
// Change the selected view to the newly snapped-to view.
|
||||
selectedView = view;
|
||||
selectedPosition = snappedPosition;
|
||||
setViewSelected(selectedView, true);
|
||||
}
|
||||
|
||||
private void setViewSelected(View view, boolean selected) {
|
||||
if (view != null) {
|
||||
RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) view.getLayoutParams();
|
||||
if (selected) {
|
||||
lp.setMargins(0, selectedItemElevation, 0, selectedItemElevation);
|
||||
} else {
|
||||
lp.setMargins(0, unselectedItemMargin, 0, unselectedItemMargin);
|
||||
}
|
||||
ViewCompat.setElevation(view, selected ? selectedItemElevation : selectedItemElevation / 2);
|
||||
view.setLayoutParams(lp);
|
||||
}
|
||||
}
|
||||
|
||||
private class ScreenShotViewHolder extends RecyclerView.ViewHolder {
|
||||
final ImageView image;
|
||||
|
||||
|
@ -1,18 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
app:cardElevation="3dp"
|
||||
app:cardBackgroundColor="#ffffff"
|
||||
android:layout_margin="@dimen/details_screenshot_margin"
|
||||
android:padding="10dp"
|
||||
>
|
||||
app:cardBackgroundColor="#ffffff"
|
||||
app:cardElevation="3dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:adjustViewBounds="true"
|
||||
android:minWidth="@dimen/details_screenshot_width"
|
||||
android:scaleType="fitCenter"
|
||||
/>
|
||||
android:scaleType="fitCenter" />
|
||||
|
||||
</android.support.v7.widget.CardView>
|
@ -1,7 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v7.widget.RecyclerView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/screenshots"
|
||||
<FrameLayout 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:layout_width="match_parent"
|
||||
android:layout_height="@dimen/details_screenshot_height">
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/screenshots"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:orientation="horizontal"
|
||||
app:layoutManager="LinearLayoutManager"
|
||||
tools:listitem="@layout/app_details2_screenshot_item" />
|
||||
|
||||
</FrameLayout>
|
@ -11,12 +11,9 @@
|
||||
applied. The collapsable lists have a little extra on the sides. -->
|
||||
<dimen name="details_activity__collapsable_lists__padding__horizontal">4dp</dimen>
|
||||
|
||||
<dimen name="details_screenshot_height">200dp</dimen>
|
||||
<dimen name="details_screenshot_width">200dp</dimen>
|
||||
<!-- "Not selected" items are inset by this value, while the selected one is not -->
|
||||
<dimen name="details_screenshot_margin">8dp</dimen>
|
||||
<!-- The selected item stands out from the background by this elevation -->
|
||||
<dimen name="details_screenshot_selected_elevation">3dp</dimen>
|
||||
<dimen name="details_screenshot_height">240dp</dimen>
|
||||
<dimen name="details_screenshot_width">240dp</dimen>
|
||||
<dimen name="details_screenshot_margin">4dp</dimen>
|
||||
|
||||
<dimen name="fab_margin">16dp</dimen>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user