Improves media swiping
This commit is contained in:
parent
8435c1dced
commit
c7f7f01bf6
|
@ -29,7 +29,6 @@ import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
@ -68,6 +67,7 @@ import fr.gouv.etalab.mastodon.helper.Helper;
|
||||||
import mastodon.etalab.gouv.fr.mastodon.R;
|
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||||
|
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.EXTERNAL_STORAGE_REQUEST_CODE;
|
import static fr.gouv.etalab.mastodon.helper.Helper.EXTERNAL_STORAGE_REQUEST_CODE;
|
||||||
|
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,7 +82,7 @@ public class MediaActivity extends AppCompatActivity {
|
||||||
private ArrayList<Attachment> attachments;
|
private ArrayList<Attachment> attachments;
|
||||||
private PhotoView imageView;
|
private PhotoView imageView;
|
||||||
private VideoView videoView;
|
private VideoView videoView;
|
||||||
private float downX, downY;
|
private float downX;
|
||||||
private int mediaPosition;
|
private int mediaPosition;
|
||||||
MediaActivity.actionSwipe currentAction;
|
MediaActivity.actionSwipe currentAction;
|
||||||
private ImageLoader imageLoader;
|
private ImageLoader imageLoader;
|
||||||
|
@ -124,8 +124,12 @@ public class MediaActivity extends AppCompatActivity {
|
||||||
RelativeLayout main_container_media = (RelativeLayout) findViewById(R.id.main_container_media);
|
RelativeLayout main_container_media = (RelativeLayout) findViewById(R.id.main_container_media);
|
||||||
if( theme == Helper.THEME_LIGHT){
|
if( theme == Helper.THEME_LIGHT){
|
||||||
main_container_media.setBackgroundResource(R.color.background_image);
|
main_container_media.setBackgroundResource(R.color.background_image);
|
||||||
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_next_pic,R.color.colorAccent);
|
||||||
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_prev_pic,R.color.colorAccent);
|
||||||
}else {
|
}else {
|
||||||
main_container_media.setBackgroundResource(R.color.colorPrimaryD);
|
main_container_media.setBackgroundResource(R.color.colorPrimaryD);
|
||||||
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_next_pic,R.color.colorAccentD);
|
||||||
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_prev_pic,R.color.colorAccentD);
|
||||||
}
|
}
|
||||||
canSwipe = true;
|
canSwipe = true;
|
||||||
loader = (RelativeLayout) findViewById(R.id.loader);
|
loader = (RelativeLayout) findViewById(R.id.loader);
|
||||||
|
@ -209,7 +213,6 @@ public class MediaActivity extends AppCompatActivity {
|
||||||
switch(event.getAction()){
|
switch(event.getAction()){
|
||||||
case MotionEvent.ACTION_DOWN: {
|
case MotionEvent.ACTION_DOWN: {
|
||||||
downX = event.getX();
|
downX = event.getX();
|
||||||
downY = event.getY();
|
|
||||||
//Displays navigation left/right buttons
|
//Displays navigation left/right buttons
|
||||||
if( attachments != null && attachments.size() > 1 && !isHiding){
|
if( attachments != null && attachments.size() > 1 && !isHiding){
|
||||||
prev.setVisibility(View.VISIBLE);
|
prev.setVisibility(View.VISIBLE);
|
||||||
|
@ -227,12 +230,10 @@ public class MediaActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
case MotionEvent.ACTION_UP: {
|
case MotionEvent.ACTION_UP: {
|
||||||
float upX = event.getX();
|
float upX = event.getX();
|
||||||
float upY = event.getY();
|
|
||||||
float deltaX = downX - upX;
|
float deltaX = downX - upX;
|
||||||
float deltaY = downY - upY;
|
|
||||||
// swipe horizontal
|
// swipe horizontal
|
||||||
|
|
||||||
if( downX > MIN_DISTANCE & (Math.abs(deltaX) > MIN_DISTANCE && Math.abs(deltaY) < MIN_DISTANCE)){
|
if( downX > MIN_DISTANCE & (Math.abs(deltaX) > MIN_DISTANCE ) ){
|
||||||
if(deltaX < 0) { switchOnSwipe(MediaActivity.actionSwipe.LEFT_TO_RIGHT); return true; }
|
if(deltaX < 0) { switchOnSwipe(MediaActivity.actionSwipe.LEFT_TO_RIGHT); return true; }
|
||||||
if(deltaX > 0) { switchOnSwipe(MediaActivity.actionSwipe.RIGHT_TO_LEFT); return true; }
|
if(deltaX > 0) { switchOnSwipe(MediaActivity.actionSwipe.RIGHT_TO_LEFT); return true; }
|
||||||
}else{
|
}else{
|
||||||
|
@ -358,6 +359,9 @@ public class MediaActivity extends AppCompatActivity {
|
||||||
String filename = URLUtil.guessFileName(url, null, null);
|
String filename = URLUtil.guessFileName(url, null, null);
|
||||||
if( filename == null)
|
if( filename == null)
|
||||||
filename = url;
|
filename = url;
|
||||||
|
if( attachments.size() > 1 )
|
||||||
|
filename = String.format("%s (%s/%s)",filename, mediaPosition, attachments.size());
|
||||||
|
|
||||||
LayoutInflater mInflater = LayoutInflater.from(MediaActivity.this);
|
LayoutInflater mInflater = LayoutInflater.from(MediaActivity.this);
|
||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
if( actionBar != null){
|
if( actionBar != null){
|
||||||
|
|
|
@ -21,30 +21,6 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/main_container_media"
|
android:id="@+id/main_container_media"
|
||||||
>
|
>
|
||||||
<ImageView
|
|
||||||
android:visibility="gone"
|
|
||||||
android:layout_marginLeft="5dp"
|
|
||||||
android:layout_marginStart="5dp"
|
|
||||||
android:src="@drawable/ic_prev_pic"
|
|
||||||
android:id="@+id/media_prev"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:layout_alignParentStart="true"
|
|
||||||
android:layout_alignParentLeft="true"
|
|
||||||
android:layout_width="20dp"
|
|
||||||
android:layout_height="20dp"
|
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
<ImageView
|
|
||||||
android:visibility="gone"
|
|
||||||
android:layout_marginRight="5dp"
|
|
||||||
android:layout_marginEnd="5dp"
|
|
||||||
android:id="@+id/media_next"
|
|
||||||
android:src="@drawable/ic_next_pic"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:layout_alignParentEnd="true"
|
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
android:layout_width="20dp"
|
|
||||||
android:layout_height="20dp"
|
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
<com.github.chrisbanes.photoview.PhotoView
|
<com.github.chrisbanes.photoview.PhotoView
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
android:layout_centerInParent="true"
|
android:layout_centerInParent="true"
|
||||||
|
@ -58,6 +34,29 @@
|
||||||
android:id="@+id/media_video"
|
android:id="@+id/media_video"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_margin="5dp"
|
||||||
|
android:src="@drawable/ic_prev_pic"
|
||||||
|
android:id="@+id/media_prev"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_width="20dp"
|
||||||
|
android:layout_height="20dp"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
|
<ImageView
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_margin="5dp"
|
||||||
|
android:id="@+id/media_next"
|
||||||
|
android:src="@drawable/ic_next_pic"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_width="20dp"
|
||||||
|
android:layout_height="20dp"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
<!-- Main Loader -->
|
<!-- Main Loader -->
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/loader"
|
android:id="@+id/loader"
|
||||||
|
|
Loading…
Reference in New Issue