diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-09-19 13:58:40 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-09-19 13:58:40 +0000 |
commit | cf84a6d431cbf979587722eb725bd736cb487209 (patch) | |
tree | 530d8787d8cb0c6bf51477bffb800eb8b9bfb408 /app/src/main/java | |
parent | 7866b1c92ef3abbe222095b7a95f8301cf5a6068 (diff) | |
download | infinity-for-reddit-cf84a6d431cbf979587722eb725bd736cb487209.tar infinity-for-reddit-cf84a6d431cbf979587722eb725bd736cb487209.tar.gz infinity-for-reddit-cf84a6d431cbf979587722eb725bd736cb487209.tar.bz2 infinity-for-reddit-cf84a6d431cbf979587722eb725bd736cb487209.tar.lz infinity-for-reddit-cf84a6d431cbf979587722eb725bd736cb487209.tar.xz infinity-for-reddit-cf84a6d431cbf979587722eb725bd736cb487209.tar.zst infinity-for-reddit-cf84a6d431cbf979587722eb725bd736cb487209.zip |
Delete something related to downloading videos.
Diffstat (limited to 'app/src/main/java')
5 files changed, 20 insertions, 146 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java index ac80f670..ada28849 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java @@ -431,13 +431,8 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie Intent intent = new Intent(mActivity, ViewVideoActivity.class); intent.setData(gifVideoUri); intent.putExtra(ViewVideoActivity.TITLE_KEY, mPost.getTitle()); - intent.putExtra(ViewVideoActivity.IS_HLS_VIDEO_KEY, mPost.isHLSVideo()); - intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, mPost.isDownloadableGifOrVideo()); - if(mPost.isDownloadableGifOrVideo()) { - intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, mPost.getGifOrVideoDownloadUrl()); - intent.putExtra(ViewVideoActivity.SUBREDDIT_KEY, mPost.getSubredditName()); - intent.putExtra(ViewVideoActivity.ID_KEY, mPost.getId()); - } + intent.putExtra(ViewVideoActivity.SUBREDDIT_KEY, mPost.getSubredditName()); + intent.putExtra(ViewVideoActivity.ID_KEY, mPost.getId()); mActivity.startActivity(intent); }); break; @@ -449,13 +444,8 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie Intent intent = new Intent(mActivity, ViewVideoActivity.class); intent.setData(videoUri); intent.putExtra(ViewVideoActivity.TITLE_KEY, mPost.getTitle()); - intent.putExtra(ViewVideoActivity.IS_HLS_VIDEO_KEY, mPost.isHLSVideo()); - intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, mPost.isDownloadableGifOrVideo()); - if(mPost.isDownloadableGifOrVideo()) { - intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, mPost.getGifOrVideoDownloadUrl()); - intent.putExtra(ViewVideoActivity.SUBREDDIT_KEY, mPost.getSubredditName()); - intent.putExtra(ViewVideoActivity.ID_KEY, mPost.getId()); - } + intent.putExtra(ViewVideoActivity.SUBREDDIT_KEY, mPost.getSubredditName()); + intent.putExtra(ViewVideoActivity.ID_KEY, mPost.getId()); mActivity.startActivity(intent); }); break; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java index c6a980b8..f18da1cf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java @@ -268,12 +268,11 @@ class ParsePost { post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, gilded, flair, hidden, - spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, true); + spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); post.setVideoUrl(videoUrl); - post.setDownloadableGifOrVideo(false); } else if(data.has(JSONUtils.PREVIEW_KEY)){ if(data.getJSONObject(JSONUtils.PREVIEW_KEY).has(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY)) { //Gif video post (HLS) @@ -284,11 +283,10 @@ class ParsePost { post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, gilded, flair, hidden, spoiler, nsfw, stickied, archived, locked, saved, - isCrosspost, true); + isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); post.setVideoUrl(videoUrl); - post.setDownloadableGifOrVideo(false); } else { if (url.endsWith("jpg") || url.endsWith("png")) { //Image post diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java index bf963745..3a522d29 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java @@ -30,7 +30,6 @@ class Post implements Parcelable { private String previewUrl; private String url; private String videoUrl; - private String gifOrVideoDownloadUrl; private String permalink; private String flair; private int score; @@ -47,15 +46,12 @@ class Post implements Parcelable { private boolean locked; private boolean saved; private boolean isCrosspost; - private boolean isHLSVideo; - private boolean isDownloadableGifOrVideo; private String crosspostParentId; Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author, String postTime, String title, String previewUrl, String permalink, int score, int postType, int voteType, int gilded, String flair, boolean hidden, boolean spoiler, boolean nsfw, - boolean stickied, boolean archived, boolean locked, boolean saved, boolean isCrosspost, - boolean isHLSVideo) { + boolean stickied, boolean archived, boolean locked, boolean saved, boolean isCrosspost) { this.id = id; this.fullName = fullName; this.subredditName = subredditName; @@ -79,7 +75,6 @@ class Post implements Parcelable { this.locked = locked; this.saved = saved; this.isCrosspost = isCrosspost; - this.isHLSVideo = isHLSVideo; } Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author, @@ -155,7 +150,6 @@ class Post implements Parcelable { previewUrl = in.readString(); url = in.readString(); videoUrl = in.readString(); - gifOrVideoDownloadUrl = in.readString(); permalink = in.readString(); flair = in.readString(); score = in.readInt(); @@ -172,8 +166,6 @@ class Post implements Parcelable { locked = in.readByte() != 0; saved = in.readByte() != 0; isCrosspost = in.readByte() != 0; - isHLSVideo = in.readByte() != 0; - isDownloadableGifOrVideo = in.readByte() != 0; crosspostParentId = in.readString(); } @@ -265,14 +257,6 @@ class Post implements Parcelable { return videoUrl; } - String getGifOrVideoDownloadUrl() { - return gifOrVideoDownloadUrl; - } - - void setGifOrVideoDownloadUrl(String gifOrVideoDownloadUrl) { - this.gifOrVideoDownloadUrl = gifOrVideoDownloadUrl; - } - String getPermalink() { return permalink; } @@ -354,18 +338,6 @@ class Post implements Parcelable { return 0; } - boolean isHLSVideo() { - return isHLSVideo; - } - - void setDownloadableGifOrVideo(boolean isDownloadableGifOrVideo) { - this.isDownloadableGifOrVideo = isDownloadableGifOrVideo; - } - - boolean isDownloadableGifOrVideo() { - return isDownloadableGifOrVideo; - } - boolean isStickied() { return stickied; } @@ -414,7 +386,6 @@ class Post implements Parcelable { parcel.writeString(previewUrl); parcel.writeString(url); parcel.writeString(videoUrl); - parcel.writeString(gifOrVideoDownloadUrl); parcel.writeString(permalink); parcel.writeString(flair); parcel.writeInt(score); @@ -431,8 +402,6 @@ class Post implements Parcelable { parcel.writeByte((byte) (locked ? 1 : 0)); parcel.writeByte((byte) (saved ? 1 : 0)); parcel.writeByte((byte) (isCrosspost ? 1 : 0)); - parcel.writeByte((byte) (isHLSVideo ? 1 : 0)); - parcel.writeByte((byte) (isDownloadableGifOrVideo ? 1 : 0)); parcel.writeString(crosspostParentId); } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java index 15b5187b..fdad950c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java @@ -420,13 +420,8 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo Intent intent = new Intent(mContext, ViewVideoActivity.class); intent.setData(gifVideoUri); intent.putExtra(ViewVideoActivity.TITLE_KEY, title); - intent.putExtra(ViewVideoActivity.IS_HLS_VIDEO_KEY, post.isHLSVideo()); - intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, post.isDownloadableGifOrVideo()); - if(post.isDownloadableGifOrVideo()) { - intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, post.getGifOrVideoDownloadUrl()); - intent.putExtra(ViewVideoActivity.SUBREDDIT_KEY, subredditName); - intent.putExtra(ViewVideoActivity.ID_KEY, id); - } + intent.putExtra(ViewVideoActivity.SUBREDDIT_KEY, subredditName); + intent.putExtra(ViewVideoActivity.ID_KEY, id); mContext.startActivity(intent); }); break; @@ -438,13 +433,8 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo Intent intent = new Intent(mContext, ViewVideoActivity.class); intent.setData(videoUri); intent.putExtra(ViewVideoActivity.TITLE_KEY, title); - intent.putExtra(ViewVideoActivity.IS_HLS_VIDEO_KEY, post.isHLSVideo()); - intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, post.isDownloadableGifOrVideo()); - if(post.isDownloadableGifOrVideo()) { - intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, post.getGifOrVideoDownloadUrl()); - intent.putExtra(ViewVideoActivity.SUBREDDIT_KEY, subredditName); - intent.putExtra(ViewVideoActivity.ID_KEY, id); - } + intent.putExtra(ViewVideoActivity.SUBREDDIT_KEY, subredditName); + intent.putExtra(ViewVideoActivity.ID_KEY, id); mContext.startActivity(intent); }); break; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java index ec336d65..0dbac0b4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java @@ -4,8 +4,6 @@ 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.pm.PackageManager; import android.content.res.Configuration; @@ -16,7 +14,6 @@ import android.media.AudioManager; import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.os.Environment; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; @@ -37,7 +34,6 @@ 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; -import com.google.android.exoplayer2.source.ExtractorMediaSource; import com.google.android.exoplayer2.source.hls.HlsMediaSource; import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; @@ -45,13 +41,9 @@ import com.google.android.exoplayer2.trackselection.TrackSelection; import com.google.android.exoplayer2.trackselection.TrackSelector; import com.google.android.exoplayer2.ui.PlayerView; import com.google.android.exoplayer2.upstream.DataSource; -import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter; -import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory; import com.google.android.exoplayer2.util.Util; -import java.io.File; - import butterknife.BindView; import butterknife.ButterKnife; @@ -60,9 +52,6 @@ public class ViewVideoActivity extends AppCompatActivity { private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0; static final String TITLE_KEY = "TK"; - static final String IS_HLS_VIDEO_KEY = "IHVK"; - static final String IS_DOWNLOADABLE_KEY = "IDK"; - static final String DOWNLOAD_URL_KEY = "DUK"; static final String SUBREDDIT_KEY = "SK"; static final String ID_KEY = "IK"; @@ -71,13 +60,11 @@ public class ViewVideoActivity extends AppCompatActivity { private Uri mVideoUri; private SimpleExoPlayer player; + private DataSource.Factory dataSourceFactory; private Menu mMenu; private Swipe swipe; - private String mGifOrVideoFileName; - private String mDownloadUrl; - private boolean mIsHLSVideo; private boolean wasPlaying; private boolean isDownloading = false; private float totalLengthY = 0.0f; @@ -112,13 +99,6 @@ public class ViewVideoActivity extends AppCompatActivity { Intent intent = getIntent(); mVideoUri = intent.getData(); - mIsHLSVideo = intent.getExtras().getBoolean(IS_HLS_VIDEO_KEY); - - if(intent.getExtras().getBoolean(IS_DOWNLOADABLE_KEY)) { - mGifOrVideoFileName = intent.getStringExtra(SUBREDDIT_KEY) - + "-" + intent.getStringExtra(ID_KEY).substring(3) + ".gif"; - mDownloadUrl = intent.getStringExtra(DOWNLOAD_URL_KEY); - } final float pxHeight = getResources().getDisplayMetrics().heightPixels; @@ -285,39 +265,26 @@ public class ViewVideoActivity extends AppCompatActivity { } }); - DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector); videoPlayerView.setPlayer(player); - DataSource.Factory dataSourceFactory; - + // Produces DataSource instances through which media data is loaded. + dataSourceFactory = new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "Infinity")); // Prepare the player with the source. - if(mIsHLSVideo) { - // Produces DataSource instances through which media data is loaded. - dataSourceFactory = new DefaultHttpDataSourceFactory( - Util.getUserAgent(this, "Infinity")); - player.prepare(new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri)); - } else { - // Produces DataSource instances through which media data is loaded. - dataSourceFactory = new DefaultDataSourceFactory(this, - Util.getUserAgent(this, "Infinity"), bandwidthMeter); - player.prepare(new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri)); - } + player.prepare(new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri)); player.setRepeatMode(Player.REPEAT_MODE_ALL); player.setPlayWhenReady(true); wasPlaying = true; } - @Override + /*@Override public boolean onCreateOptionsMenu(Menu menu) { - if(!mIsHLSVideo) { - getMenuInflater().inflate(R.menu.view_video, menu); - mMenu = menu; - } + getMenuInflater().inflate(R.menu.view_video, menu); + mMenu = menu; return true; - } + }*/ @Override public boolean dispatchTouchEvent(MotionEvent ev) { @@ -390,47 +357,7 @@ public class ViewVideoActivity extends AppCompatActivity { } private void download() { - DownloadManager.Request request = new DownloadManager.Request(Uri.parse(mDownloadUrl)); - request.setTitle(mGifOrVideoFileName); - - 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, mGifOrVideoFileName); - } 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/", mGifOrVideoFileName); - } else { - request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, mGifOrVideoFileName); - } - } - - DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); - - if(manager == null) { - Toast.makeText(this, R.string.download_failed, Toast.LENGTH_SHORT).show(); - return; - } - - manager.enqueue(request); - Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show(); + isDownloading = false; } @Override |