Delete something related to downloading videos.

This commit is contained in:
Alex Ning 2019-09-19 21:58:40 +08:00
parent 7866b1c92e
commit cf84a6d431
10 changed files with 38 additions and 163 deletions

Binary file not shown.

View File

@ -6,8 +6,8 @@ android {
applicationId "ml.docilealligator.infinityforreddit"
minSdkVersion 21
targetSdkVersion 29
versionCode 10
versionName "1.0.9"
versionCode 11
versionName "1.1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
@ -33,16 +33,16 @@ repositories {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'com.google.android.material:material:1.1.0-alpha09'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0-alpha10'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.exoplayer:exoplayer:2.9.6'
implementation 'com.google.android.exoplayer:exoplayer-dash:2.9.6'
implementation 'com.google.android.exoplayer:exoplayer:2.10.4'
implementation 'com.google.android.exoplayer:exoplayer-dash:2.10.4'
implementation 'androidx.browser:browser:1.0.0'
implementation 'com.alexvasilkov:gesture-views:2.5.2'
implementation 'androidx.cardview:cardview:1.0.0'
@ -79,6 +79,6 @@ dependencies {
implementation 'com.evernote:android-state:1.4.1'
annotationProcessor 'com.evernote:android-state-processor:1.4.1'
implementation 'androidx.work:work-runtime:2.2.0'
implementation 'androidx.preference:preference:1.1.0-rc01'
implementation 'androidx.preference:preference:1.1.0'
implementation 'org.sufficientlysecure:html-textview:3.6'
}

View File

@ -2,6 +2,15 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ml.docilealligator.infinityforreddit">
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="22" />
<uses-permission-sdk-23 android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name=".Infinity"
android:allowBackup="true"
@ -249,13 +258,5 @@
android:enabled="true"
android:exported="false" />
</application>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="22" />
<uses-permission-sdk-23 android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

View File

@ -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;

View File

@ -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

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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

View File

@ -31,6 +31,6 @@ task clean(type: Delete) {
}
ext {
roomVersion = '2.2.0-beta01'
archLifecycleVersion = '2.2.0-alpha03'
roomVersion = '2.2.0-rc01'
archLifecycleVersion = '2.2.0-alpha04'
}