mirror of https://github.com/kurisufriend/Clover
parent
8e58b92592
commit
8679d0f222
@ -0,0 +1,91 @@ |
||||
/* |
||||
* Clover - 4chan browser https://github.com/Floens/Clover/
|
||||
* Copyright (C) 2014 Floens |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
package org.floens.chan.ui.cell; |
||||
|
||||
import android.content.Context; |
||||
import android.util.AttributeSet; |
||||
import android.widget.FrameLayout; |
||||
import android.widget.TextView; |
||||
|
||||
import org.floens.chan.R; |
||||
import org.floens.chan.core.model.PostImage; |
||||
import org.floens.chan.ui.view.ThumbnailView; |
||||
import org.floens.chan.utils.AndroidUtils; |
||||
|
||||
import static org.floens.chan.utils.AndroidUtils.dp; |
||||
import static org.floens.chan.utils.AndroidUtils.getDimen; |
||||
import static org.floens.chan.utils.AndroidUtils.getString; |
||||
|
||||
public class AlbumViewCell extends FrameLayout { |
||||
private PostImage postImage; |
||||
private ThumbnailView thumbnailView; |
||||
private TextView text; |
||||
|
||||
public AlbumViewCell(Context context) { |
||||
this(context, null); |
||||
} |
||||
|
||||
public AlbumViewCell(Context context, AttributeSet attrs) { |
||||
this(context, attrs, 0); |
||||
} |
||||
|
||||
public AlbumViewCell(Context context, AttributeSet attrs, int defStyleAttr) { |
||||
super(context, attrs, defStyleAttr); |
||||
} |
||||
|
||||
@Override |
||||
protected void onFinishInflate() { |
||||
super.onFinishInflate(); |
||||
thumbnailView = (ThumbnailView) findViewById(R.id.thumbnail_view); |
||||
text = (TextView) findViewById(R.id.text); |
||||
} |
||||
|
||||
public void setPostImage(PostImage postImage) { |
||||
this.postImage = postImage; |
||||
// Keep this the same as the normal thumbnails to improve performance
|
||||
int thumbnailSize = getDimen(getContext(), R.dimen.cell_post_thumbnail_size); |
||||
thumbnailView.setUrl(postImage.thumbnailUrl, thumbnailSize, thumbnailSize); |
||||
|
||||
String filename = postImage.spoiler ? getString(R.string.image_spoiler_filename) : postImage.filename + "." + postImage.extension; |
||||
String details = postImage.extension.toUpperCase() + " " + postImage.imageWidth + "x" + postImage.imageHeight + |
||||
" " + AndroidUtils.getReadableFileSize(postImage.size, false); |
||||
text.setText(details); |
||||
} |
||||
|
||||
public PostImage getPostImage() { |
||||
return postImage; |
||||
} |
||||
|
||||
public ThumbnailView getThumbnailView() { |
||||
return thumbnailView; |
||||
} |
||||
|
||||
@Override |
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
||||
int heightMode = MeasureSpec.getMode(heightMeasureSpec); |
||||
if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY && (heightMode == MeasureSpec.UNSPECIFIED || heightMode == MeasureSpec.AT_MOST)) { |
||||
int width = MeasureSpec.getSize(widthMeasureSpec); |
||||
|
||||
int height = width + dp(32); |
||||
|
||||
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); |
||||
} else { |
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,175 @@ |
||||
/* |
||||
* Clover - 4chan browser https://github.com/Floens/Clover/
|
||||
* Copyright (C) 2014 Floens |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
package org.floens.chan.ui.controller; |
||||
|
||||
import android.content.Context; |
||||
import android.support.v7.widget.GridLayoutManager; |
||||
import android.support.v7.widget.RecyclerView; |
||||
import android.view.LayoutInflater; |
||||
import android.view.View; |
||||
import android.view.ViewGroup; |
||||
|
||||
import org.floens.chan.R; |
||||
import org.floens.chan.controller.Controller; |
||||
import org.floens.chan.core.model.Loadable; |
||||
import org.floens.chan.core.model.PostImage; |
||||
import org.floens.chan.ui.cell.AlbumViewCell; |
||||
import org.floens.chan.ui.view.GridRecyclerView; |
||||
import org.floens.chan.ui.view.ThumbnailView; |
||||
|
||||
import java.util.List; |
||||
|
||||
import static org.floens.chan.utils.AndroidUtils.dp; |
||||
|
||||
public class AlbumViewController extends Controller implements ImageViewerController.ImageViewerCallback, ImageViewerController.GoPostCallback { |
||||
private GridRecyclerView recyclerView; |
||||
private GridLayoutManager gridLayoutManager; |
||||
|
||||
private List<PostImage> postImages; |
||||
private int targetIndex = -1; |
||||
|
||||
private AlbumAdapter albumAdapter; |
||||
private Loadable loadable; |
||||
|
||||
public AlbumViewController(Context context) { |
||||
super(context); |
||||
} |
||||
|
||||
@Override |
||||
public void onCreate() { |
||||
super.onCreate(); |
||||
|
||||
view = inflateRes(R.layout.controller_album_view); |
||||
|
||||
recyclerView = (GridRecyclerView) view.findViewById(R.id.recycler_view); |
||||
recyclerView.setHasFixedSize(true); |
||||
gridLayoutManager = new GridLayoutManager(context, 3); |
||||
recyclerView.setLayoutManager(gridLayoutManager); |
||||
recyclerView.setHasFixedSize(true); |
||||
recyclerView.setSpanWidth(dp(120)); |
||||
recyclerView.setItemAnimator(null); |
||||
albumAdapter = new AlbumAdapter(); |
||||
recyclerView.setAdapter(albumAdapter); |
||||
recyclerView.scrollToPosition(targetIndex); |
||||
} |
||||
|
||||
public void setImages(Loadable loadable, List<PostImage> postImages, int index, String title) { |
||||
this.loadable = loadable; |
||||
this.postImages = postImages; |
||||
navigationItem.title = title; |
||||
targetIndex = index; |
||||
} |
||||
|
||||
@Override |
||||
public ThumbnailView getPreviewImageTransitionView(ImageViewerController imageViewerController, PostImage postImage) { |
||||
ThumbnailView thumbnail = null; |
||||
for (int i = 0; i < recyclerView.getChildCount(); i++) { |
||||
View view = recyclerView.getChildAt(i); |
||||
if (view instanceof AlbumViewCell) { |
||||
AlbumViewCell cell = (AlbumViewCell) view; |
||||
if (postImage == cell.getPostImage()) { |
||||
thumbnail = cell.getThumbnailView(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
return thumbnail; |
||||
} |
||||
|
||||
@Override |
||||
public void onPreviewCreate(ImageViewerController imageViewerController) { |
||||
} |
||||
|
||||
@Override |
||||
public void onPreviewDestroy(ImageViewerController imageViewerController) { |
||||
} |
||||
|
||||
@Override |
||||
public void scrollToImage(PostImage postImage) { |
||||
int index = postImages.indexOf(postImage); |
||||
recyclerView.smoothScrollToPosition(index); |
||||
} |
||||
|
||||
@Override |
||||
public ImageViewerController.ImageViewerCallback goToPost(PostImage postImage) { |
||||
if (previousSiblingController instanceof ThreadController) { |
||||
ThreadController sibling = (ThreadController) previousSiblingController; |
||||
sibling.selectPostImage(postImage); |
||||
navigationController.popController(false); |
||||
return sibling; |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
private void openImage(AlbumItemCellHolder albumItemCellHolder, PostImage postImage) { |
||||
// Just ignore the showImages request when the image is not loaded
|
||||
if (albumItemCellHolder.thumbnailView.getBitmap() != null) { |
||||
final ImageViewerNavigationController imageViewerNavigationController = new ImageViewerNavigationController(context); |
||||
int index = postImages.indexOf(postImage); |
||||
presentController(imageViewerNavigationController, false); |
||||
imageViewerNavigationController.showImages(postImages, index, loadable, this, this); |
||||
} |
||||
} |
||||
|
||||
private class AlbumAdapter extends RecyclerView.Adapter<AlbumItemCellHolder> { |
||||
public AlbumAdapter() { |
||||
setHasStableIds(true); |
||||
} |
||||
|
||||
@Override |
||||
public AlbumItemCellHolder onCreateViewHolder(ViewGroup parent, int viewType) { |
||||
return new AlbumItemCellHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.cell_album_view, parent, false)); |
||||
} |
||||
|
||||
@Override |
||||
public void onBindViewHolder(AlbumItemCellHolder holder, int position) { |
||||
PostImage postImage = postImages.get(position); |
||||
holder.cell.setPostImage(postImage); |
||||
} |
||||
|
||||
@Override |
||||
public int getItemCount() { |
||||
return postImages.size(); |
||||
} |
||||
|
||||
@Override |
||||
public long getItemId(int position) { |
||||
return position; |
||||
} |
||||
} |
||||
|
||||
private class AlbumItemCellHolder extends RecyclerView.ViewHolder implements View.OnClickListener { |
||||
private AlbumViewCell cell; |
||||
private ThumbnailView thumbnailView; |
||||
|
||||
public AlbumItemCellHolder(View itemView) { |
||||
super(itemView); |
||||
cell = (AlbumViewCell) itemView; |
||||
thumbnailView = (ThumbnailView) itemView.findViewById(R.id.thumbnail_view); |
||||
thumbnailView.setOnClickListener(this); |
||||
} |
||||
|
||||
@Override |
||||
public void onClick(View v) { |
||||
int adapterPosition = getAdapterPosition(); |
||||
PostImage postImage = postImages.get(adapterPosition); |
||||
openImage(this, postImage); |
||||
} |
||||
} |
||||
} |
After Width: | Height: | Size: 177 B |
After Width: | Height: | Size: 132 B |
After Width: | Height: | Size: 181 B |
After Width: | Height: | Size: 256 B |
After Width: | Height: | Size: 296 B |
@ -0,0 +1,43 @@ |
||||
<?xml version="1.0" encoding="utf-8"?><!-- |
||||
Clover - 4chan browser https://github.com/Floens/Clover/ |
||||
Copyright (C) 2014 Floens |
||||
|
||||
This program is free software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
|
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
--> |
||||
<org.floens.chan.ui.cell.AlbumViewCell xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_margin="1dp"> |
||||
|
||||
<org.floens.chan.ui.view.ThumbnailView |
||||
android:id="@+id/thumbnail_view" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/text" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="32dp" |
||||
android:layout_gravity="bottom" |
||||
android:background="#8a000000" |
||||
android:gravity="center_vertical" |
||||
android:maxLines="2" |
||||
android:paddingLeft="8dp" |
||||
android:paddingRight="8dp" |
||||
android:textColor="#ffffffff" |
||||
android:textSize="10sp" |
||||
tools:ignore="SmallSp" /> |
||||
|
||||
</org.floens.chan.ui.cell.AlbumViewCell> |
@ -0,0 +1,28 @@ |
||||
<?xml version="1.0" encoding="utf-8"?><!-- |
||||
Clover - 4chan browser https://github.com/Floens/Clover/ |
||||
Copyright (C) 2014 Floens |
||||
|
||||
This program is free software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
|
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
--> |
||||
<org.floens.chan.ui.view.GridRecyclerView xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:id="@+id/recycler_view" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:background="?backcolor" |
||||
android:clipToPadding="false" |
||||
android:padding="1dp" |
||||
android:scrollbarStyle="outsideOverlay" |
||||
android:scrollbars="vertical"> |
||||
|
||||
</org.floens.chan.ui.view.GridRecyclerView> |
Loading…
Reference in new issue