Skip to content

Commit

Permalink
Allow swipes on ImageActivity. fixes #85
Browse files Browse the repository at this point in the history
Much more subtle an intricate than it seemed on the first glance. Many unforseen issues also with respect to transitions. Some compromises have been made. I should have renamed ImageActivity etc. in a later commit but now it's too late.

Next is a ThreadManager class to centralize loading of posts / images and allow to make some functionality possible that wasn't beforehand.
  • Loading branch information
eugenkiss committed Mar 3, 2015
1 parent a7925fa commit c91f7c7
Show file tree
Hide file tree
Showing 20 changed files with 685 additions and 301 deletions.
6 changes: 3 additions & 3 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
android:configChanges="keyboardHidden|orientation|screenSize"
/>
<activity
android:name=".ui.images.ImageActivity"
android:name=".ui.media.MediaActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/ImageActivity"
android:theme="@style/MediaActivity"
/>
<activity
android:name=".ui.images.GalleryActivity"
android:name=".ui.media.GalleryActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
/>
<activity
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/anabolicandroids/chanobol/AppModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import anabolicandroids.chanobol.ui.Settings;
import anabolicandroids.chanobol.ui.boards.BoardsActivity;
import anabolicandroids.chanobol.ui.boards.FavoritesActivity;
import anabolicandroids.chanobol.ui.images.GalleryActivity;
import anabolicandroids.chanobol.ui.images.ImageActivity;
import anabolicandroids.chanobol.ui.media.GalleryActivity;
import anabolicandroids.chanobol.ui.media.MediaActivity;
import anabolicandroids.chanobol.ui.posts.PostsActivity;
import anabolicandroids.chanobol.ui.posts.PostsDialog;
import anabolicandroids.chanobol.ui.threads.ThreadsActivity;
Expand All @@ -46,7 +46,7 @@
ThreadsActivity.class,
PostsActivity.class,
PostsDialog.class,
ImageActivity.class,
MediaActivity.class,
GalleryActivity.class,
},
includes = {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/anabolicandroids/chanobol/ui/UiActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,7 @@ public void freeMemory() {
}

public void setVisibility(View view, boolean show) {
if (show) view.setVisibility(View.VISIBLE);
else view.setVisibility(View.GONE);
Util.setVisibility(view, show);
}

@SuppressWarnings("UnusedDeclaration")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package anabolicandroids.chanobol.ui.images;
package anabolicandroids.chanobol.ui.media;

import android.app.Activity;
import android.content.Intent;
Expand All @@ -9,6 +9,7 @@
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
Expand All @@ -24,7 +25,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import anabolicandroids.chanobol.R;
import anabolicandroids.chanobol.api.data.Post;
Expand All @@ -45,21 +45,21 @@ public class GalleryActivity extends SwipeRefreshActivity {
@SuppressWarnings("FieldCanBeLocal")
private static String EXTRA_THREADNUMBER = "threadNumber";

private ArrayList<ImagePointer> imagePointers;
private ArrayList<MediaPointer> mediaPointers;
private String boardName;
private String threadNumber;
private GalleryAdapter galleryAdapter;

public static void launch(
Activity activity,
String boardName, String threadNumber,
List<ImagePointer> imagePointers
List<MediaPointer> mediaPointers
) {
ActivityOptionsCompat options = makeSceneTransitionAnimation(activity);
Intent intent = new Intent(activity, GalleryActivity.class);
intent.putExtra(EXTRA_BOARDNAME, boardName);
intent.putExtra(EXTRA_THREADNUMBER, threadNumber);
intent.putExtra(EXTRA_IMAGEPOINTERS, Parcels.wrap(imagePointers));
intent.putExtra(EXTRA_IMAGEPOINTERS, Parcels.wrap(mediaPointers));
ActivityCompat.startActivity(activity, intent, options.toBundle());
}

Expand All @@ -74,7 +74,7 @@ public static void launch(
Bundle b = getIntent().getExtras();
boardName = b.getString("boardName");
threadNumber = b.getString("threadNumber");
imagePointers = Parcels.unwrap(b.getParcelable(EXTRA_IMAGEPOINTERS));
mediaPointers = Parcels.unwrap(b.getParcelable(EXTRA_IMAGEPOINTERS));

setTitle(boardName + "/gal/" + threadNumber);

Expand Down Expand Up @@ -109,12 +109,12 @@ public static void launch(
iv.getLocationOnScreen(xy);
final int cx = xy[0] + w/2;
final int cy = xy[1] + h/2;
final String uuid = UUID.randomUUID().toString();
iv.postDelayed(new Runnable() {
@Override public void run() {
ImageActivity.launch(
GalleryActivity.this, iv.image, uuid, new Point(cx, cy), r, true, true,
boardName, threadNumber, 0, Util.arrayListOf(iv.imagePointer)
MediaActivity.transitionBitmap = Util.drawableToBitmap(iv.image.getDrawable());
MediaActivity.launch(
GalleryActivity.this, iv.image, iv.index + "", new Point(cx, cy), r, true,
boardName, threadNumber, iv.index, mediaPointers
);
}
}, 200);
Expand All @@ -133,9 +133,9 @@ GalleryActivity.this, iv.image, uuid, new Point(cx, cy), r, true, true,
loaded();
return;
}
imagePointers.clear();
mediaPointers.clear();
for (Post p : result) { if (p.imageId != null) {
imagePointers.add(new ImagePointer(p.imageId, p.imageExtension, p.imageWidth, p.imageHeight));
mediaPointers.add(new MediaPointer(p, p.imageId, p.imageExtension, p.imageWidth, p.imageHeight));
}}
galleryAdapter.notifyDataSetChanged();
loaded();
Expand Down Expand Up @@ -170,19 +170,21 @@ GalleryActivity.this, iv.image, uuid, new Point(cx, cy), r, true, true,

// Adapters ////////////////////////////////////////////////////////////////////////////////////

class GalleryAdapter extends UiAdapter<ImagePointer> {
class GalleryAdapter extends UiAdapter<MediaPointer> {

public GalleryAdapter(View.OnClickListener clickListener, View.OnLongClickListener longClickListener) {
super(GalleryActivity.this, clickListener, longClickListener);
this.items = imagePointers;
this.items = mediaPointers;
}

@Override public View newView(ViewGroup container) {
return getLayoutInflater().inflate(R.layout.view_gallery_thumb, container, false);
}

@Override public void bindView(ImagePointer imagePointer, int position, View view) {
((GalleryThumbView) view).bindTo(ion, boardName, imagePointer);
@Override public void bindView(MediaPointer mediaPointer, int position, View view) {
GalleryThumbView g = (GalleryThumbView) view;
g.bindTo(ion, boardName, mediaPointer, position);
ViewCompat.setTransitionName(g.image, position+"");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package anabolicandroids.chanobol.ui.images;
package anabolicandroids.chanobol.ui.media;

import android.content.Context;
import android.util.AttributeSet;
Expand All @@ -17,22 +17,20 @@ public class GalleryThumbView extends FrameLayout {
@InjectView(R.id.image) ImageView image;
@InjectView(R.id.info) TextView info;

public ImagePointer imagePointer;
public int index;

public GalleryThumbView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public GalleryThumbView(Context context, AttributeSet attrs) { super(context, attrs); }

@Override protected void onFinishInflate() {
super.onFinishInflate();
ButterKnife.inject(this);
}

public void bindTo(Ion ion, String board, ImagePointer imagePointer) {
this.imagePointer = imagePointer;
ion.build(image).load(ApiModule.thumbUrl(board, imagePointer.id));
public void bindTo(Ion ion, String board, MediaPointer mediaPointer, int index) {
this.index = index;
ion.build(image).load(ApiModule.thumbUrl(board, mediaPointer.id));

switch (imagePointer.ext) {
switch (mediaPointer.ext) {
case ".webm": info.setText("webm"); break;
case ".gif": info.setText("gif"); break;
default: info.setText("");
Expand Down

0 comments on commit c91f7c7

Please sign in to comment.