aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java209
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java233
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImgurMediaActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java185
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java22
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurImageFragment.java1
6 files changed, 39 insertions, 617 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java
index 3173c143..8bdc82fe 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java
@@ -1,15 +1,11 @@
package ml.docilealligator.infinityforreddit.Activity;
import android.Manifest;
-import android.animation.Animator;
-import android.animation.ArgbEvaluator;
-import android.animation.ValueAnimator;
import android.app.DownloadManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
-import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
@@ -19,11 +15,9 @@ import android.os.Environment;
import android.text.Html;
import android.view.Menu;
import android.view.MenuItem;
-import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
-import android.widget.RelativeLayout;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -42,8 +36,7 @@ import com.bumptech.glide.load.resource.gif.GifDrawable;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
-import com.github.pwittchen.swipe.library.rx2.SimpleSwipeListener;
-import com.github.pwittchen.swipe.library.rx2.Swipe;
+import com.thefuntasty.hauler.HaulerView;
import java.io.File;
@@ -68,8 +61,8 @@ public class ViewGIFActivity extends AppCompatActivity {
public static final String FILE_NAME_KEY = "FNK";
public static final String POST_TITLE_KEY = "PTK";
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
- @BindView(R.id.parent_relative_layout_view_gif_activity)
- RelativeLayout mRelativeLayout;
+ @BindView(R.id.hauler_view_view_gif_activity)
+ HaulerView mHaulerView;
@BindView(R.id.progress_bar_view_gif_activity)
ProgressBar mProgressBar;
@BindView(R.id.image_view_view_gif_activity)
@@ -81,14 +74,9 @@ public class ViewGIFActivity extends AppCompatActivity {
SharedPreferences mSharedPreferences;
private boolean isActionBarHidden = false;
private boolean isDownloading = false;
- private Menu mMenu;
- private Swipe swipe;
private RequestManager glide;
private String mImageUrl;
private String mImageFileName;
- private float totalLengthY = 0.0f;
- private float touchY = -1.0f;
- private float zoom = 1.0f;
private boolean isSwiping = false;
private String postTitle;
@@ -117,6 +105,8 @@ public class ViewGIFActivity extends AppCompatActivity {
actionBar.setHomeAsUpIndicator(upArrow);
actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor)));
+ mHaulerView.setOnDragDismissedListener(dragDirection -> finish());
+
glide = Glide.with(this);
Intent intent = getIntent();
@@ -138,182 +128,8 @@ public class ViewGIFActivity extends AppCompatActivity {
}
});
- float pxHeight = getResources().getDisplayMetrics().heightPixels;
-
- int activityColorFrom = getResources().getColor(android.R.color.black);
- int actionBarColorFrom = getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor);
- int actionBarElementColorFrom = getResources().getColor(android.R.color.white);
- int colorTo = getResources().getColor(android.R.color.transparent);
-
- final ValueAnimator activityColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), activityColorFrom, colorTo);
- final ValueAnimator actionBarColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), actionBarColorFrom, colorTo);
- final ValueAnimator actionBarElementColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), actionBarElementColorFrom, colorTo);
-
- activityColorAnimation.setDuration(300); // milliseconds
- actionBarColorAnimation.setDuration(300);
- actionBarElementColorAnimation.setDuration(300);
-
- activityColorAnimation.addUpdateListener(valueAnimator -> mRelativeLayout.setBackgroundColor((int) valueAnimator.getAnimatedValue()));
-
- actionBarColorAnimation.addUpdateListener(valueAnimator -> actionBar.setBackgroundDrawable(new ColorDrawable((int) valueAnimator.getAnimatedValue())));
-
- actionBarElementColorAnimation.addUpdateListener(valueAnimator -> {
- upArrow.setColorFilter((int) valueAnimator.getAnimatedValue(), PorterDuff.Mode.SRC_IN);
- if (mMenu != null) {
- Drawable drawable = mMenu.getItem(0).getIcon();
- //drawable.mutate();
- drawable.setColorFilter((int) valueAnimator.getAnimatedValue(), PorterDuff.Mode.SRC_IN);
- }
- });
-
loadImage();
- swipe = new Swipe();
- swipe.setListener(new SimpleSwipeListener() {
- @Override
- public void onSwipingUp(final MotionEvent event) {
- isSwiping = true;
- float nowY = event.getY();
- float offset;
- if (touchY == -1.0f) {
- offset = 0.0f;
- } else {
- offset = nowY - touchY;
- }
- totalLengthY += offset;
- touchY = nowY;
- mImageView.animate()
- .y(totalLengthY)
- .setDuration(0)
- .start();
- mLoadErrorLinearLayout.animate()
- .y(totalLengthY)
- .setDuration(0)
- .start();
- }
-
- @Override
- public boolean onSwipedUp(final MotionEvent event) {
- if (totalLengthY < -pxHeight / 8) {
- mImageView.animate()
- .y(-pxHeight)
- .setDuration(300)
- .setListener(new Animator.AnimatorListener() {
- @Override
- public void onAnimationStart(Animator animator) {
- activityColorAnimation.start();
- actionBarColorAnimation.start();
- actionBarElementColorAnimation.start();
- }
-
- @Override
- public void onAnimationEnd(Animator animator) {
- finish();
- }
-
- @Override
- public void onAnimationCancel(Animator animator) {
- }
-
- @Override
- public void onAnimationRepeat(Animator animator) {
- }
- })
- .start();
- mLoadErrorLinearLayout.animate()
- .y(-pxHeight)
- .setDuration(300)
- .start();
- } else {
- isSwiping = false;
- mImageView.animate()
- .y(0)
- .setDuration(300)
- .start();
- mLoadErrorLinearLayout.animate()
- .y(0)
- .setDuration(300)
- .start();
- }
-
- totalLengthY = 0.0f;
- touchY = -1.0f;
- return false;
- }
-
- @Override
- public void onSwipingDown(final MotionEvent event) {
- isSwiping = true;
- float nowY = event.getY();
- float offset;
- if (touchY == -1.0f) {
- offset = 0.0f;
- } else {
- offset = nowY - touchY;
- }
- totalLengthY += offset;
- touchY = nowY;
- mImageView.animate()
- .y(totalLengthY)
- .setDuration(0)
- .start();
- mLoadErrorLinearLayout.animate()
- .y(totalLengthY)
- .setDuration(0)
- .start();
- }
-
- @Override
- public boolean onSwipedDown(final MotionEvent event) {
- if (totalLengthY > pxHeight / 8) {
- mImageView.animate()
- .y(pxHeight)
- .setDuration(300)
- .setListener(new Animator.AnimatorListener() {
- @Override
- public void onAnimationStart(Animator animator) {
- activityColorAnimation.start();
- actionBarColorAnimation.start();
- actionBarElementColorAnimation.start();
- }
-
- @Override
- public void onAnimationEnd(Animator animator) {
- finish();
- }
-
- @Override
- public void onAnimationCancel(Animator animator) {
- }
-
- @Override
- public void onAnimationRepeat(Animator animator) {
- }
- })
- .start();
- mLoadErrorLinearLayout.animate()
- .y(pxHeight)
- .setDuration(300)
- .start();
- } else {
- isSwiping = false;
- mImageView.animate()
- .y(0)
- .setDuration(300)
- .start();
- mLoadErrorLinearLayout.animate()
- .y(0)
- .setDuration(300)
- .start();
- }
-
- totalLengthY = 0.0f;
- touchY = -1.0f;
-
- return false;
- }
- });
-
mImageView.setOnClickListener(view -> {
if (isActionBarHidden) {
getWindow().getDecorView().setSystemUiVisibility(
@@ -353,7 +169,6 @@ public class ViewGIFActivity extends AppCompatActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- mMenu = menu;
getMenuInflater().inflate(R.menu.view_gif_activity, menu);
return true;
}
@@ -435,14 +250,6 @@ public class ViewGIFActivity extends AppCompatActivity {
}
@Override
- public boolean dispatchTouchEvent(MotionEvent ev) {
- if (zoom == 1.0) {
- swipe.dispatchTouchEvent(ev);
- }
- return super.dispatchTouchEvent(ev);
- }
-
- @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE && grantResults.length > 0) {
if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
@@ -497,10 +304,4 @@ public class ViewGIFActivity extends AppCompatActivity {
manager.enqueue(request);
Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show();
}
-
- @Override
- protected void onPause() {
- super.onPause();
- overridePendingTransition(0, 0);
- }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java
index 68d65cb7..779d7fe7 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java
@@ -1,16 +1,12 @@
package ml.docilealligator.infinityforreddit.Activity;
import android.Manifest;
-import android.animation.Animator;
-import android.animation.ArgbEvaluator;
-import android.animation.ValueAnimator;
import android.app.DownloadManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
-import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
@@ -20,11 +16,9 @@ import android.os.Environment;
import android.text.Html;
import android.view.Menu;
import android.view.MenuItem;
-import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
-import android.widget.RelativeLayout;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -35,8 +29,6 @@ import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
-import com.alexvasilkov.gestures.GestureController;
-import com.alexvasilkov.gestures.State;
import com.alexvasilkov.gestures.views.GestureImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
@@ -46,8 +38,7 @@ import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
-import com.github.pwittchen.swipe.library.rx2.SimpleSwipeListener;
-import com.github.pwittchen.swipe.library.rx2.Swipe;
+import com.thefuntasty.hauler.HaulerView;
import java.io.File;
@@ -71,8 +62,8 @@ public class ViewImageActivity extends AppCompatActivity {
public static final String FILE_NAME_KEY = "FNK";
public static final String POST_TITLE_KEY = "PTK";
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
- @BindView(R.id.parent_relative_layout_view_image_activity)
- RelativeLayout mRelativeLayout;
+ @BindView(R.id.hauler_view_view_image_activity)
+ HaulerView mHaulerView;
@BindView(R.id.progress_bar_view_image_activity)
ProgressBar mProgressBar;
@BindView(R.id.image_view_view_image_activity)
@@ -84,15 +75,8 @@ public class ViewImageActivity extends AppCompatActivity {
SharedPreferences mSharedPreferences;
private boolean isActionBarHidden = false;
private boolean isDownloading = false;
- private Menu mMenu;
- private Swipe swipe;
private String mImageUrl;
private String mImageFileName;
- private float totalLengthY = 0.0f;
- private float touchY = -1.0f;
- private float initialZoom = 1.0f;
- private float zoom = 1.0f;
- private boolean isSwiping = false;
private RequestManager glide;
private String postTitle;
@@ -135,202 +119,16 @@ public class ViewImageActivity extends AppCompatActivity {
setTitle("");
}
- mLoadErrorLinearLayout.setOnClickListener(view -> {
- if (!isSwiping) {
- mProgressBar.setVisibility(View.VISIBLE);
- mLoadErrorLinearLayout.setVisibility(View.GONE);
- loadImage();
- }
- });
-
- float pxHeight = getResources().getDisplayMetrics().heightPixels;
-
- int activityColorFrom = getResources().getColor(android.R.color.black);
- int actionBarColorFrom = getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor);
- int actionBarElementColorFrom = getResources().getColor(android.R.color.white);
- int colorTo = getResources().getColor(android.R.color.transparent);
-
- final ValueAnimator activityColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), activityColorFrom, colorTo);
- final ValueAnimator actionBarColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), actionBarColorFrom, colorTo);
- final ValueAnimator actionBarElementColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), actionBarElementColorFrom, colorTo);
-
- activityColorAnimation.setDuration(300); // milliseconds
- actionBarColorAnimation.setDuration(300);
- actionBarElementColorAnimation.setDuration(300);
+ mHaulerView.setOnDragDismissedListener(dragDirection -> finish());
- activityColorAnimation.addUpdateListener(valueAnimator -> mRelativeLayout.setBackgroundColor((int) valueAnimator.getAnimatedValue()));
-
- actionBarColorAnimation.addUpdateListener(valueAnimator -> actionBar.setBackgroundDrawable(new ColorDrawable((int) valueAnimator.getAnimatedValue())));
-
- actionBarElementColorAnimation.addUpdateListener(valueAnimator -> {
- upArrow.setColorFilter((int) valueAnimator.getAnimatedValue(), PorterDuff.Mode.SRC_IN);
- if (mMenu != null) {
- Drawable drawable = mMenu.getItem(0).getIcon();
- //drawable.mutate();
- drawable.setColorFilter((int) valueAnimator.getAnimatedValue(), PorterDuff.Mode.SRC_IN);
- }
+ mLoadErrorLinearLayout.setOnClickListener(view -> {
+ mProgressBar.setVisibility(View.VISIBLE);
+ mLoadErrorLinearLayout.setVisibility(View.GONE);
+ loadImage();
});
loadImage();
- swipe = new Swipe();
- swipe.setListener(new SimpleSwipeListener() {
- @Override
- public void onSwipingUp(final MotionEvent event) {
- isSwiping = true;
- float nowY = event.getY();
- float offset;
- if (touchY == -1.0f) {
- offset = 0.0f;
- } else {
- offset = nowY - touchY;
- }
- totalLengthY += offset;
- touchY = nowY;
- mImageView.animate()
- .y(totalLengthY)
- .setDuration(0)
- .start();
- mLoadErrorLinearLayout.animate()
- .y(totalLengthY)
- .setDuration(0)
- .start();
- }
-
- @Override
- public boolean onSwipedUp(final MotionEvent event) {
- if (totalLengthY < -pxHeight / 8) {
- mImageView.animate()
- .y(-pxHeight)
- .setDuration(300)
- .setListener(new Animator.AnimatorListener() {
- @Override
- public void onAnimationStart(Animator animator) {
- activityColorAnimation.start();
- actionBarColorAnimation.start();
- actionBarElementColorAnimation.start();
- }
-
- @Override
- public void onAnimationEnd(Animator animator) {
- finish();
- }
-
- @Override
- public void onAnimationCancel(Animator animator) {
- }
-
- @Override
- public void onAnimationRepeat(Animator animator) {
- }
- })
- .start();
- mLoadErrorLinearLayout.animate()
- .y(-pxHeight)
- .setDuration(300)
- .start();
- } else {
- isSwiping = false;
- mImageView.animate()
- .y(0)
- .setDuration(300)
- .start();
- mLoadErrorLinearLayout.animate()
- .y(0)
- .setDuration(300)
- .start();
- }
-
- totalLengthY = 0.0f;
- touchY = -1.0f;
- return false;
- }
-
- @Override
- public void onSwipingDown(final MotionEvent event) {
- isSwiping = true;
- float nowY = event.getY();
- float offset;
- if (touchY == -1.0f) {
- offset = 0.0f;
- } else {
- offset = nowY - touchY;
- }
- totalLengthY += offset;
- touchY = nowY;
- mImageView.animate()
- .y(totalLengthY)
- .setDuration(0)
- .start();
- mLoadErrorLinearLayout.animate()
- .y(totalLengthY)
- .setDuration(0)
- .start();
- }
-
- @Override
- public boolean onSwipedDown(final MotionEvent event) {
- if (totalLengthY > pxHeight / 8) {
- mImageView.animate()
- .y(pxHeight)
- .setDuration(300)
- .setListener(new Animator.AnimatorListener() {
- @Override
- public void onAnimationStart(Animator animator) {
- activityColorAnimation.start();
- actionBarColorAnimation.start();
- actionBarElementColorAnimation.start();
- }
-
- @Override
- public void onAnimationEnd(Animator animator) {
- finish();
- }
-
- @Override
- public void onAnimationCancel(Animator animator) {
- }
-
- @Override
- public void onAnimationRepeat(Animator animator) {
- }
- })
- .start();
- mLoadErrorLinearLayout.animate()
- .y(pxHeight)
- .setDuration(300)
- .start();
- } else {
- isSwiping = false;
- mImageView.animate()
- .y(0)
- .setDuration(300)
- .start();
- mLoadErrorLinearLayout.animate()
- .y(0)
- .setDuration(300)
- .start();
- }
-
- totalLengthY = 0.0f;
- touchY = -1.0f;
-
- return false;
- }
- });
-
- mImageView.getController().addOnStateChangeListener(new GestureController.OnStateChangeListener() {
- @Override
- public void onStateChanged(State state) {
- zoom = state.getZoom();
- }
-
- @Override
- public void onStateReset(State oldState, State newState) {
- initialZoom = newState.getZoom();
- }
- });
-
mImageView.getController().getSettings().setMaxZoom(10f).setDoubleTapZoom(2f).setPanEnabled(true);
mImageView.setOnClickListener(view -> {
@@ -372,7 +170,6 @@ public class ViewImageActivity extends AppCompatActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- mMenu = menu;
getMenuInflater().inflate(R.menu.view_image_activity, menu);
return true;
}
@@ -454,14 +251,6 @@ public class ViewImageActivity extends AppCompatActivity {
}
@Override
- public boolean dispatchTouchEvent(MotionEvent ev) {
- if (Math.abs(zoom - initialZoom) <= 0.000001) {
- swipe.dispatchTouchEvent(ev);
- }
- return super.dispatchTouchEvent(ev);
- }
-
- @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE && grantResults.length > 0) {
if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
@@ -516,10 +305,4 @@ public class ViewImageActivity extends AppCompatActivity {
manager.enqueue(request);
Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show();
}
-
- @Override
- protected void onPause() {
- super.onPause();
- overridePendingTransition(0, 0);
- }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImgurMediaActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImgurMediaActivity.java
index e9040328..9e0b95e7 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImgurMediaActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImgurMediaActivity.java
@@ -19,6 +19,8 @@ import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;
+import com.thefuntasty.hauler.HaulerView;
+
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -56,6 +58,8 @@ public class ViewImgurMediaActivity extends AppCompatActivity {
public static final int IMGUR_TYPE_IMAGE = 2;
private static final String IMGUR_IMAGES_STATE = "IIS";
+ @BindView(R.id.hauler_view_view_imgur_media_activity)
+ HaulerView haulerView;
@BindView(R.id.progress_bar_view_imgur_media_activity)
ProgressBar progressBar;
@BindView(R.id.view_pager_view_imgur_media_activity)
@@ -109,6 +113,8 @@ public class ViewImgurMediaActivity extends AppCompatActivity {
images = savedInstanceState.getParcelableArrayList(IMGUR_IMAGES_STATE);
}
+ haulerView.setOnDragDismissedListener(dragDirection -> finish());
+
if (images == null) {
fetchImgurMedia(imgurId);
} else {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java
index fdf5c7d2..29b78878 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java
@@ -1,16 +1,12 @@
package ml.docilealligator.infinityforreddit.Activity;
import android.Manifest;
-import android.animation.Animator;
-import android.animation.ArgbEvaluator;
-import android.animation.ValueAnimator;
import android.app.DownloadManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
-import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
@@ -21,13 +17,11 @@ import android.os.Environment;
import android.text.Html;
import android.view.Menu;
import android.view.MenuItem;
-import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
-import android.widget.RelativeLayout;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -36,8 +30,6 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
-import com.github.pwittchen.swipe.library.rx2.SimpleSwipeListener;
-import com.github.pwittchen.swipe.library.rx2.Swipe;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
@@ -55,6 +47,7 @@ import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
+import com.thefuntasty.hauler.HaulerView;
import java.io.File;
@@ -86,8 +79,8 @@ public class ViewVideoActivity extends AppCompatActivity {
private static final String IS_MUTE_STATE = "IMS";
private static final String VIDEO_DOWNLOAD_URL_STATE = "VDUS";
private static final String VIDEO_URI_STATE = "VUS";
- @BindView(R.id.relative_layout_view_video_activity)
- RelativeLayout relativeLayout;
+ @BindView(R.id.hauler_view_view_video_activity)
+ HaulerView haulerView;
@BindView(R.id.progress_bar_view_video_activity)
ProgressBar progressBar;
@BindView(R.id.player_view_view_video_activity)
@@ -99,16 +92,11 @@ public class ViewVideoActivity extends AppCompatActivity {
private SimpleExoPlayer player;
private DataSource.Factory dataSourceFactory;
- private Menu mMenu;
- private Swipe swipe;
-
private String videoDownloadUrl;
private String videoFileName;
private boolean wasPlaying;
private boolean isDownloading = false;
private boolean isMute = false;
- private float totalLengthY = 0.0f;
- private float touchY = -1.0f;
private String postTitle;
private long resumePosition = -1;
@@ -155,6 +143,8 @@ public class ViewVideoActivity extends AppCompatActivity {
params.rightMargin = getResources().getDimensionPixelSize(resourceId);
}
+ haulerView.setOnDragDismissedListener(dragDirection -> finish());
+
Intent intent = getIntent();
mVideoUri = intent.getData();
postTitle = intent.getStringExtra(EXTRA_POST_TITLE);
@@ -168,156 +158,6 @@ public class ViewVideoActivity extends AppCompatActivity {
setTitle("");
}
- final float pxHeight = getResources().getDisplayMetrics().heightPixels;
-
- int activityColorFrom = getResources().getColor(android.R.color.black);
- int actionBarColorFrom = getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor);
- int actionBarElementColorFrom = getResources().getColor(android.R.color.white);
- int colorTo = getResources().getColor(android.R.color.transparent);
-
- final ValueAnimator activityColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), activityColorFrom, colorTo);
- final ValueAnimator actionBarColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), actionBarColorFrom, colorTo);
- final ValueAnimator actionBarElementColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), actionBarElementColorFrom, colorTo);
-
- activityColorAnimation.setDuration(300); // milliseconds
- actionBarColorAnimation.setDuration(300);
- actionBarElementColorAnimation.setDuration(300);
-
- activityColorAnimation.addUpdateListener(valueAnimator -> relativeLayout.setBackgroundColor((int) valueAnimator.getAnimatedValue()));
-
- actionBarColorAnimation.addUpdateListener(valueAnimator -> actionBar.setBackgroundDrawable(new ColorDrawable((int) valueAnimator.getAnimatedValue())));
-
- actionBarElementColorAnimation.addUpdateListener(valueAnimator -> {
- upArrow.setColorFilter((int) valueAnimator.getAnimatedValue(), PorterDuff.Mode.SRC_IN);
- if (mMenu != null) {
- Drawable drawable = mMenu.getItem(0).getIcon();
- drawable.setColorFilter((int) valueAnimator.getAnimatedValue(), PorterDuff.Mode.SRC_IN);
- }
- });
-
- swipe = new Swipe();
- swipe.setListener(new SimpleSwipeListener() {
- @Override
- public void onSwipingUp(final MotionEvent event) {
- float nowY = event.getY();
- float offset;
- if (touchY == -1.0f) {
- offset = 0.0f;
- } else {
- offset = nowY - touchY;
- }
- totalLengthY += offset;
- touchY = nowY;
- videoPlayerView.animate()
- .y(totalLengthY)
- .setDuration(0)
- .start();
- }
-
- @Override
- public boolean onSwipedUp(final MotionEvent event) {
- videoPlayerView.animate()
- .y(0)
- .setDuration(300)
- .start();
-
- if (totalLengthY < -pxHeight / 8) {
- videoPlayerView.animate()
- .y(-pxHeight)
- .setDuration(300)
- .setListener(new Animator.AnimatorListener() {
- @Override
- public void onAnimationStart(Animator animator) {
- activityColorAnimation.start();
- actionBarColorAnimation.start();
- actionBarElementColorAnimation.start();
- }
-
- @Override
- public void onAnimationEnd(Animator animator) {
- finish();
- }
-
- @Override
- public void onAnimationCancel(Animator animator) {
- }
-
- @Override
- public void onAnimationRepeat(Animator animator) {
- }
- })
- .start();
- } else {
- videoPlayerView.animate()
- .y(0)
- .setDuration(300)
- .start();
- }
-
- totalLengthY = 0.0f;
- touchY = -1.0f;
- return false;
- }
-
- @Override
- public void onSwipingDown(final MotionEvent event) {
- float nowY = event.getY();
- float offset;
- if (touchY == -1.0f) {
- offset = 0.0f;
- } else {
- offset = nowY - touchY;
- }
- totalLengthY += offset;
- touchY = nowY;
- videoPlayerView.animate()
- .y(totalLengthY)
- .setDuration(0)
- .start();
- }
-
- @Override
- public boolean onSwipedDown(final MotionEvent event) {
- if (totalLengthY > pxHeight / 8) {
- videoPlayerView.animate()
- .y(pxHeight)
- .setDuration(300)
- .setListener(new Animator.AnimatorListener() {
- @Override
- public void onAnimationStart(Animator animator) {
- activityColorAnimation.start();
- actionBarColorAnimation.start();
- actionBarElementColorAnimation.start();
- }
-
- @Override
- public void onAnimationEnd(Animator animator) {
- finish();
- }
-
- @Override
- public void onAnimationCancel(Animator animator) {
- }
-
- @Override
- public void onAnimationRepeat(Animator animator) {
- }
- })
- .start();
- } else {
- videoPlayerView.animate()
- .y(0)
- .setDuration(300)
- .start();
- }
-
- totalLengthY = 0.0f;
- touchY = -1.0f;
-
- return false;
- }
- });
-
videoPlayerView.setControllerVisibilityListener(visibility -> {
switch (visibility) {
case View.GONE:
@@ -394,8 +234,6 @@ public class ViewVideoActivity extends AppCompatActivity {
player.prepare(new DashMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri));
preparePlayer(savedInstanceState);
}
- } if (videoType == VIDEO_TYPE_REDGIFS) {
-
} else if (videoType == VIDEO_TYPE_DIRECT) {
videoDownloadUrl = mVideoUri.toString();
videoFileName = videoDownloadUrl.substring(videoDownloadUrl.lastIndexOf('/') + 1);
@@ -474,17 +312,10 @@ public class ViewVideoActivity extends AppCompatActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.view_video, menu);
- mMenu = menu;
return true;
}
@Override
- public boolean dispatchTouchEvent(MotionEvent ev) {
- swipe.dispatchTouchEvent(ev);
- return super.dispatchTouchEvent(ev);
- }
-
- @Override
protected void onDestroy() {
super.onDestroy();
player.release();
@@ -600,12 +431,6 @@ public class ViewVideoActivity extends AppCompatActivity {
}
@Override
- protected void onPause() {
- super.onPause();
- overridePendingTransition(0, 0);
- }
-
- @Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(IS_MUTE_STATE, isMute);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
index 7a1b6a78..e335bfa0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
@@ -2122,7 +2122,6 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mActivity.startActivity(intent);
} else if (post.getPostType() == Post.GIF_TYPE) {
Intent intent = new Intent(mActivity, ViewGIFActivity.class);
- intent.setData(Uri.parse(post.getVideoUrl()));
intent.putExtra(ViewGIFActivity.FILE_NAME_KEY, post.getSubredditName()
+ "-" + post.getId() + ".gif");
intent.putExtra(ViewGIFActivity.GIF_URL_KEY, post.getVideoUrl());
@@ -2220,12 +2219,21 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
imageView.setOnClickListener(view -> {
Post post = getItem(getAdapterPosition());
if (post != null) {
- Intent intent = new Intent(mActivity, ViewImageActivity.class);
- intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, post.getUrl());
- intent.putExtra(ViewImageActivity.FILE_NAME_KEY, post.getSubredditName()
- + "-" + post.getId() + ".jpg");
- intent.putExtra(ViewImageActivity.POST_TITLE_KEY, post.getTitle());
- mActivity.startActivity(intent);
+ if (post.getPostType() == Post.IMAGE_TYPE) {
+ Intent intent = new Intent(mActivity, ViewImageActivity.class);
+ intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, post.getUrl());
+ intent.putExtra(ViewImageActivity.FILE_NAME_KEY, post.getSubredditName()
+ + "-" + post.getId() + ".jpg");
+ intent.putExtra(ViewImageActivity.POST_TITLE_KEY, post.getTitle());
+ mActivity.startActivity(intent);
+ } else if (post.getPostType() == Post.GIF_TYPE) {
+ Intent intent = new Intent(mActivity, ViewGIFActivity.class);
+ intent.putExtra(ViewGIFActivity.FILE_NAME_KEY, post.getSubredditName()
+ + "-" + post.getId() + ".gif");
+ intent.putExtra(ViewGIFActivity.GIF_URL_KEY, post.getVideoUrl());
+ intent.putExtra(ViewGIFActivity.POST_TITLE_KEY, post.getTitle());
+ mActivity.startActivity(intent);
+ }
}
});
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurImageFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurImageFragment.java
index 3c9b5b41..ae047287 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurImageFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurImageFragment.java
@@ -63,7 +63,6 @@ public class ViewImgurImageFragment extends Fragment {
private Activity activity;
private RequestManager glide;
private ImgurMedia imgurMedia;
- private boolean isActionBarHidden = false;
private boolean isDownloading = false;
public ViewImgurImageFragment() {