Set span size 2 for wide thumb
This commit is contained in:
1 parent
e84a060194
commit
a4f9580171
8 files changed
+94
-8
No files matched your search
@@ -90,6 +90,9 @@ public class GalleryInfo implements Parcelable {
|
||||
@Nullable
|
||||
public String[] simpleTags;
|
||||
|
||||
public int thumbWidth;
|
||||
public int thumbHeight;
|
||||
|
||||
/**
|
||||
* language from title
|
||||
*/
|
||||
|
||||
@@ -79,8 +79,8 @@ public class GalleryListParser {
|
||||
|
||||
gi.category = EhUtils.getCategory(ParserUtils.trim(m.group(1)));
|
||||
gi.posted = ParserUtils.trim(m.group(2));
|
||||
//gi.thumbHeight = ParserUtils.parseInt(m.group(3));
|
||||
//gi.thumbWidth = ParserUtils.parseInt(m.group(4));
|
||||
gi.thumbHeight = ParserUtils.parseInt(m.group(3));
|
||||
gi.thumbWidth = ParserUtils.parseInt(m.group(4));
|
||||
|
||||
if (m.group(5) == null) {
|
||||
gi.thumb = ParserUtils.trim("http://" + m.group(7).replace('~', '/'));
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.os.Build;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -59,6 +60,8 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> implem
|
||||
private final RecyclerView mRecyclerView;
|
||||
private final GridAutoSpanLayoutManager mLayoutManager;
|
||||
private RecyclerView.ItemDecoration mGirdDecoration;
|
||||
private final GridLayoutManager.SpanSizeLookup mDefaultSpanSizeLookup;
|
||||
private GridLayoutManager.SpanSizeLookup mThumbSpanSizeLookup;
|
||||
private int mType = TYPE_INVALID;
|
||||
|
||||
public GalleryAdapter(@NonNull LayoutInflater inflater, @NonNull Resources resources,
|
||||
@@ -67,6 +70,7 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> implem
|
||||
mResources = resources;
|
||||
mRecyclerView = recyclerView;
|
||||
mLayoutManager = layoutManager;
|
||||
mDefaultSpanSizeLookup = mLayoutManager.getSpanSizeLookup();
|
||||
|
||||
int paddingH = mResources.getDimensionPixelOffset(R.dimen.list_content_margin_h);
|
||||
int paddingV = mResources.getDimensionPixelOffset(R.dimen.list_content_margin_v);
|
||||
@@ -90,6 +94,7 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> implem
|
||||
int columnWidth = mResources.getDimensionPixelOffset(R.dimen.gallery_list_column_width);
|
||||
mLayoutManager.setColumnSize(columnWidth);
|
||||
mLayoutManager.setStrategy(GridAutoSpanLayoutManager.STRATEGY_MIN_SIZE);
|
||||
mLayoutManager.setSpanSizeLookup(mDefaultSpanSizeLookup);
|
||||
if (null != mGirdDecoration) {
|
||||
mRecyclerView.removeItemDecoration(mGirdDecoration);
|
||||
}
|
||||
@@ -100,9 +105,13 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> implem
|
||||
int columnWidth = mResources.getDimensionPixelOffset(R.dimen.gallery_grid_column_width);
|
||||
mLayoutManager.setColumnSize(columnWidth);
|
||||
mLayoutManager.setStrategy(GridAutoSpanLayoutManager.STRATEGY_SUITABLE_SIZE);
|
||||
if (null == mThumbSpanSizeLookup) {
|
||||
mThumbSpanSizeLookup = new ThumbSpanSizeLookup();
|
||||
}
|
||||
mLayoutManager.setSpanSizeLookup(mThumbSpanSizeLookup);
|
||||
if (null == mGirdDecoration) {
|
||||
mGirdDecoration = new MarginItemDecoration(
|
||||
mResources.getDimensionPixelOffset(R.dimen.list_content_interval));
|
||||
mResources.getDimensionPixelOffset(R.dimen.gallery_grid_margin) / 2);
|
||||
}
|
||||
mRecyclerView.addItemDecoration(mGirdDecoration);
|
||||
notifyDataSetChanged();
|
||||
@@ -195,4 +204,17 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> implem
|
||||
setType(Settings.getListMode());
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private class ThumbSpanSizeLookup extends GridLayoutManager.SpanSizeLookup {
|
||||
|
||||
@Override
|
||||
public int getSpanSize(int position) {
|
||||
GalleryInfo info = getDataAt(position);
|
||||
if (info == null || info.thumbWidth <= info.thumbHeight) {
|
||||
return 1;
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,7 @@ import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import de.greenrobot.dao.query.LazyList;
|
||||
|
||||
// TODO No grid for history
|
||||
public class HistoryScene extends ToolbarScene
|
||||
implements EasyRecyclerView.OnItemClickListener,
|
||||
EasyRecyclerView.OnItemLongClickListener{
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.widget.LoadImageView;
|
||||
|
||||
public class TileThumb extends LoadImageView {
|
||||
|
||||
private int mMargin;
|
||||
|
||||
public TileThumb(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public TileThumb(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public TileThumb(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
mMargin = context.getResources().getDimensionPixelOffset(R.dimen.gallery_grid_margin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int width = MeasureSpec.getSize(widthMeasureSpec);
|
||||
int spanSize = ((GridLayoutManager.LayoutParams) ((ViewGroup) getParent()).getLayoutParams()).getSpanSize();
|
||||
int height = (int) ((width - (mMargin * (spanSize - 1))) / spanSize / 0.67f);
|
||||
setMeasuredDimension(width, height);
|
||||
}
|
||||
}
|
||||
@@ -50,8 +50,6 @@ import java.util.List;
|
||||
|
||||
public class ContentLayout extends FrameLayout {
|
||||
|
||||
private static final String TAG = ContentLayout.class.getSimpleName();
|
||||
|
||||
private ProgressView mProgressView;
|
||||
private TextView mTipView;
|
||||
private ViewGroup mContentView;
|
||||
@@ -208,7 +206,7 @@ public class ContentLayout extends FrameLayout {
|
||||
/**
|
||||
* Generate task id
|
||||
*/
|
||||
private IntIdGenerator mIdGenerator = new IntIdGenerator();
|
||||
private final IntIdGenerator mIdGenerator = new IntIdGenerator();
|
||||
|
||||
/**
|
||||
* Store the page divider index
|
||||
@@ -359,6 +357,10 @@ public class ContentLayout extends FrameLayout {
|
||||
mEmptyString = str;
|
||||
}
|
||||
|
||||
public List<E> getDat() {
|
||||
return mData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IndexOutOfBoundsException
|
||||
* if {@code location < 0 || location >= size()}
|
||||
|
||||
Reference in new issue
Block a user