aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-06-04 02:05:57 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-06-04 02:05:57 +0000
commit4927f8278643e8deccede688a96183f139ce9691 (patch)
tree4ad7f3e47c861fdb9d39ce3c39e94cbe4d763b74 /app
parentbb42cb713d76d997d16b5bfbc4052672c9031fed (diff)
downloadinfinity-for-reddit-4927f8278643e8deccede688a96183f139ce9691.tar
infinity-for-reddit-4927f8278643e8deccede688a96183f139ce9691.tar.gz
infinity-for-reddit-4927f8278643e8deccede688a96183f139ce9691.tar.bz2
infinity-for-reddit-4927f8278643e8deccede688a96183f139ce9691.tar.lz
infinity-for-reddit-4927f8278643e8deccede688a96183f139ce9691.tar.xz
infinity-for-reddit-4927f8278643e8deccede688a96183f139ce9691.tar.zst
infinity-for-reddit-4927f8278643e8deccede688a96183f139ce9691.zip
Remove ViewImgurGifFragment.
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImgurMediaActivity.java33
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurGifFragment.java222
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ImgurMedia.java5
-rw-r--r--app/src/main/res/layout/fragment_view_imgur_gif.xml38
-rw-r--r--app/src/main/res/values/strings.xml2
5 files changed, 8 insertions, 292 deletions
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 d0f0071f..e04d6048 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImgurMediaActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImgurMediaActivity.java
@@ -33,7 +33,6 @@ import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.API.ImgurAPI;
import ml.docilealligator.infinityforreddit.ContentFontStyle;
import ml.docilealligator.infinityforreddit.FontStyle;
-import ml.docilealligator.infinityforreddit.Fragment.ViewImgurGifFragment;
import ml.docilealligator.infinityforreddit.Fragment.ViewImgurImageFragment;
import ml.docilealligator.infinityforreddit.Fragment.ViewImgurVideoFragment;
import ml.docilealligator.infinityforreddit.ImgurMedia;
@@ -178,17 +177,7 @@ public class ViewImgurMediaActivity extends AppCompatActivity {
@Override
public void onPageSelected(int position) {
- switch (images.get(position).getType()) {
- case ImgurMedia.TYPE_GIF:
- setTitle("GIF " + (position + 1) + "/" + images.size());
- break;
- case ImgurMedia.TYPE_VIDEO:
- setTitle("Video "+ (position + 1) + "/" + images.size());
- break;
- default:
- setTitle("Image " + (position + 1) + "/" + images.size());
-
- }
+ setToolbarTitle(position);
}
@Override
@@ -200,16 +189,10 @@ public class ViewImgurMediaActivity extends AppCompatActivity {
}
private void setToolbarTitle(int position) {
- switch (images.get(position).getType()) {
- case ImgurMedia.TYPE_GIF:
- setTitle("GIF " + (position + 1) + "/" + images.size());
- break;
- case ImgurMedia.TYPE_VIDEO:
- setTitle("Video "+ (position + 1) + "/" + images.size());
- break;
- default:
- setTitle("Image " + (position + 1) + "/" + images.size());
-
+ if (images.get(position).getType() == ImgurMedia.TYPE_VIDEO) {
+ setTitle(getString(R.string.view_imgur_media_activity_video_label, position + 1, images.size()));
+ } else {
+ setTitle(getString(R.string.view_imgur_media_activity_image_label, position + 1, images.size()));
}
}
@@ -250,12 +233,6 @@ public class ViewImgurMediaActivity extends AppCompatActivity {
bundle.putParcelable(ViewImgurVideoFragment.EXTRA_IMGUR_VIDEO, imgurMedia);
fragment.setArguments(bundle);
return fragment;
- } else if (imgurMedia.getType() == ImgurMedia.TYPE_GIF) {
- ViewImgurGifFragment fragment = new ViewImgurGifFragment();
- Bundle bundle = new Bundle();
- bundle.putParcelable(ViewImgurGifFragment.EXTRA_IMGUR_GIF, imgurMedia);
- fragment.setArguments(bundle);
- return fragment;
} else {
ViewImgurImageFragment fragment = new ViewImgurImageFragment();
Bundle bundle = new Bundle();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurGifFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurGifFragment.java
deleted file mode 100644
index bc552268..00000000
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurGifFragment.java
+++ /dev/null
@@ -1,222 +0,0 @@
-package ml.docilealligator.infinityforreddit.Fragment;
-
-import android.app.Activity;
-import android.app.DownloadManager;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.graphics.drawable.Drawable;
-import android.net.Uri;
-import android.os.Build;
-import android.os.Bundle;
-import android.os.Environment;
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.LinearLayout;
-import android.widget.ProgressBar;
-import android.widget.Toast;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.core.content.FileProvider;
-import androidx.fragment.app.Fragment;
-
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.RequestManager;
-import com.bumptech.glide.load.DataSource;
-import com.bumptech.glide.load.engine.GlideException;
-import com.bumptech.glide.load.resource.gif.GifDrawable;
-import com.bumptech.glide.request.RequestListener;
-import com.bumptech.glide.request.target.Target;
-
-import java.io.File;
-
-import butterknife.BindView;
-import butterknife.ButterKnife;
-import ml.docilealligator.infinityforreddit.AsyncTask.SaveGIFToFileAsyncTask;
-import ml.docilealligator.infinityforreddit.BuildConfig;
-import ml.docilealligator.infinityforreddit.ImgurMedia;
-import ml.docilealligator.infinityforreddit.R;
-import pl.droidsonroids.gif.GifImageView;
-
-/**
- * A simple {@link Fragment} subclass.
- */
-public class ViewImgurGifFragment extends Fragment {
-
- public static final String EXTRA_IMGUR_GIF = "EIG";
- private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
-
- @BindView(R.id.progress_bar_view_imgur_gif_fragment)
- ProgressBar progressBar;
- @BindView(R.id.image_view_view_imgur_gif_fragment)
- GifImageView imageView;
- @BindView(R.id.load_image_error_linear_layout_view_imgur_gif_fragment)
- LinearLayout errorLinearLayout;
-
- private Activity activity;
- private RequestManager glide;
- private ImgurMedia imgurMedia;
- private boolean isActionBarHidden = false;
- private boolean isDownloading = false;
-
- public ViewImgurGifFragment() {
- // Required empty public constructor
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- // Inflate the layout for this fragment
- View rootView = inflater.inflate(R.layout.fragment_view_imgur_gif, container, false);
-
- ButterKnife.bind(this, rootView);
-
- setHasOptionsMenu(true);
-
- imgurMedia = getArguments().getParcelable(EXTRA_IMGUR_GIF);
- glide = Glide.with(activity);
- loadGif();
-
- return rootView;
- }
-
- private void loadGif() {
- glide.load(imgurMedia.getLink()).listener(new RequestListener<Drawable>() {
- @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
- progressBar.setVisibility(View.GONE);
- errorLinearLayout.setVisibility(View.VISIBLE);
- return false;
- }
-
- @Override
- public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
- progressBar.setVisibility(View.GONE);
- return false;
- }
- }).into(imageView);
- }
-
- @Override
- public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
- inflater.inflate(R.menu.view_imgur_image_fragments, menu);
- super.onCreateOptionsMenu(menu, inflater);
- }
-
- @Override
- public boolean onOptionsItemSelected(@NonNull MenuItem item) {
- switch (item.getItemId()) {
- case R.id.action_download_view_imgur_image_fragments:
- return true;
- case R.id.action_share_view_imgur_image_fragments:
- Toast.makeText(activity, R.string.save_gif_before_sharing, Toast.LENGTH_SHORT).show();
- glide.asGif().load(imgurMedia.getLink()).listener(new RequestListener<GifDrawable>() {
- @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<GifDrawable> target, boolean isFirstResource) {
- return false;
- }
-
- @Override
- public boolean onResourceReady(GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) {
- if (activity.getExternalCacheDir() != null) {
- new SaveGIFToFileAsyncTask(resource, activity.getExternalCacheDir().getPath(),
- imgurMedia.getFileName(),
- new SaveGIFToFileAsyncTask.SaveGIFToFileAsyncTaskListener() {
- @Override
- public void saveSuccess(File imageFile) {
- Uri uri = FileProvider.getUriForFile(activity,
- BuildConfig.APPLICATION_ID + ".provider", imageFile);
- Intent shareIntent = new Intent();
- shareIntent.setAction(Intent.ACTION_SEND);
- shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
- shareIntent.setType("image/*");
- shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- startActivity(Intent.createChooser(shareIntent, getString(R.string.share)));
- }
-
- @Override
- public void saveFailed() {
- Toast.makeText(activity,
- R.string.cannot_save_gif, Toast.LENGTH_SHORT).show();
- }
- }).execute();
- } else {
- Toast.makeText(activity,
- R.string.cannot_get_storage, Toast.LENGTH_SHORT).show();
- }
- return false;
- }
- }).submit();
- return true;
- }
-
- return false;
- }
-
- @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) {
- Toast.makeText(activity, R.string.no_storage_permission, Toast.LENGTH_SHORT).show();
- } else if (grantResults[0] == PackageManager.PERMISSION_GRANTED && isDownloading) {
- download();
- }
- isDownloading = false;
- }
- }
-
- private void download() {
- DownloadManager.Request request = new DownloadManager.Request(Uri.parse(imgurMedia.getLink()));
- request.setTitle(imgurMedia.getFileName());
-
- request.allowScanningByMediaScanner();
- request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
-
- //Android Q support
- if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
- request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, imgurMedia.getFileName());
- } else {
- String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
- File directory = new File(path + "/Infinity/");
- boolean saveToInfinityFolder = true;
- if (!directory.exists()) {
- if (!directory.mkdir()) {
- saveToInfinityFolder = false;
- }
- } else {
- if (directory.isFile()) {
- if (!(directory.delete() && directory.mkdir())) {
- saveToInfinityFolder = false;
- }
- }
- }
-
- if (saveToInfinityFolder) {
- request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES + "/Infinity/", imgurMedia.getFileName());
- } else {
- request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, imgurMedia.getFileName());
- }
- }
-
- DownloadManager manager = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE);
-
- if (manager == null) {
- Toast.makeText(activity, R.string.download_failed, Toast.LENGTH_SHORT).show();
- return;
- }
-
- manager.enqueue(request);
- Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show();
- }
-
- @Override
- public void onAttach(@NonNull Context context) {
- super.onAttach(context);
- activity = (Activity) context;
- }
-}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ImgurMedia.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ImgurMedia.java
index 6ae818b1..d2979b7f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ImgurMedia.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ImgurMedia.java
@@ -5,8 +5,7 @@ import android.os.Parcelable;
public class ImgurMedia implements Parcelable {
public static final int TYPE_IMAGE = 0;
- public static final int TYPE_GIF = 1;
- public static final int TYPE_VIDEO = 2;
+ public static final int TYPE_VIDEO = 1;
private String id;
private String title;
private String description;
@@ -19,8 +18,6 @@ public class ImgurMedia implements Parcelable {
this.description = description;
if (type.contains("mp4")) {
this.type = TYPE_VIDEO;
- } else if (type.contains("gif")) {
- this.type = TYPE_GIF;
} else {
this.type = TYPE_IMAGE;
}
diff --git a/app/src/main/res/layout/fragment_view_imgur_gif.xml b/app/src/main/res/layout/fragment_view_imgur_gif.xml
deleted file mode 100644
index 4a0697f4..00000000
--- a/app/src/main/res/layout/fragment_view_imgur_gif.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/constraintLayout"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".Fragment.ViewImgurImageFragment">
-
- <ProgressBar
- android:id="@+id/progress_bar_view_imgur_gif_fragment"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerInParent="true" />
-
- <pl.droidsonroids.gif.GifImageView
- android:id="@+id/image_view_view_imgur_gif_fragment"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
-
- <LinearLayout
- android:id="@+id/load_image_error_linear_layout_view_imgur_gif_fragment"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:visibility="gone">
-
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:drawableTop="@drawable/ic_error_outline_white_24dp"
- android:layout_gravity="center"
- android:gravity="center"
- android:textColor="@android:color/white"
- android:text="@string/error_loading_gif_tap_to_retry"
- android:textSize="?attr/font_default" />
-
- </LinearLayout>
-
-</RelativeLayout> \ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index e4bf34b2..7194dcf4 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -26,6 +26,8 @@
<string name="edit_multi_reddit_activity_label">Edit Multireddit</string>
<string name="selected_subeddits_activity_label">Selected Subreddits</string>
<string name="report_activity_label">Report</string>
+ <string name="view_imgur_media_activity_image_label">Image %1$d/%2$d</string>
+ <string name="view_imgur_media_activity_video_label">Video %1$d/%2$d</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>