aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator/infinityforreddit
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-08-28 08:41:36 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-08-28 08:41:36 +0000
commitcc0d78aeddb90346c136fc4eafe03d80b95e93fa (patch)
treeb871b8fb573886c876bc0197a3c46e2bcfd72553 /app/src/main/java/ml/docilealligator/infinityforreddit
parent30d2abe9c691bf1603495bd7ae1abebbc447e0a8 (diff)
downloadinfinity-for-reddit-cc0d78aeddb90346c136fc4eafe03d80b95e93fa.tar
infinity-for-reddit-cc0d78aeddb90346c136fc4eafe03d80b95e93fa.tar.gz
infinity-for-reddit-cc0d78aeddb90346c136fc4eafe03d80b95e93fa.tar.bz2
infinity-for-reddit-cc0d78aeddb90346c136fc4eafe03d80b95e93fa.tar.lz
infinity-for-reddit-cc0d78aeddb90346c136fc4eafe03d80b95e93fa.tar.xz
infinity-for-reddit-cc0d78aeddb90346c136fc4eafe03d80b95e93fa.tar.zst
infinity-for-reddit-cc0d78aeddb90346c136fc4eafe03d80b95e93fa.zip
Receiving images, videos and texts to directly submitting different kinds of posts. Fixed video was not shown after selected from picker in PostVideoActivity. Handle some cases that the posts cannot be submitted. Minor bugs fixed.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java70
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ShareDataResolverActivity.java77
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPostService.java104
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java38
8 files changed, 234 insertions, 86 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java
index aedaf37b..aa9a34d3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java
@@ -239,6 +239,11 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.into(iconGifImageView);
}
+
+ imageUri = getIntent().getData();
+ if(imageUri != null) {
+ loadImage();
+ }
}
iconGifImageView.setOnClickListener(view -> {
@@ -448,6 +453,7 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_IMAGE);
+ intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(intent);
@@ -563,7 +569,8 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
if (submitImagePostEvent.errorMessage == null || submitImagePostEvent.errorMessage.equals("")) {
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
} else {
- Snackbar.make(coordinatorLayout, submitImagePostEvent.errorMessage, Snackbar.LENGTH_SHORT).show();
+ Snackbar.make(coordinatorLayout, submitImagePostEvent.errorMessage.substring(0, 1).toUpperCase()
+ + submitImagePostEvent.errorMessage.substring(1), Snackbar.LENGTH_SHORT).show();
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java
index f64cdcee..426eb062 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java
@@ -48,6 +48,7 @@ import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
public class PostLinkActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback {
static final String EXTRA_SUBREDDIT_NAME = "ESN";
+ static final String EXTRA_LINK = "EL";
private static final String SUBREDDIT_NAME_STATE = "SNS";
private static final String SUBREDDIT_ICON_STATE = "SIS";
@@ -210,6 +211,11 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.into(iconGifImageView);
}
+
+ String link = getIntent().getStringExtra(EXTRA_LINK);
+ if(link != null) {
+ contentEditText.setText(link);
+ }
}
iconGifImageView.setOnClickListener(view -> {
@@ -472,7 +478,8 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh
if(submitTextOrLinkPostEvent.errorMessage == null) {
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
} else {
- Snackbar.make(coordinatorLayout, submitTextOrLinkPostEvent.errorMessage, Snackbar.LENGTH_SHORT).show();
+ Snackbar.make(coordinatorLayout, submitTextOrLinkPostEvent.errorMessage.substring(0, 1).toUpperCase()
+ + submitTextOrLinkPostEvent.errorMessage.substring(1), Snackbar.LENGTH_SHORT).show();
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java
index 6364cde9..257c97ef 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java
@@ -48,6 +48,7 @@ import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
public class PostTextActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback {
static final String EXTRA_SUBREDDIT_NAME = "ESN";
+ static final String EXTRA_CONTENT = "EC";
private static final String SUBREDDIT_NAME_STATE = "SNS";
private static final String SUBREDDIT_ICON_STATE = "SIS";
@@ -210,6 +211,11 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.into(iconGifImageView);
}
+
+ String text = getIntent().getStringExtra(EXTRA_CONTENT);
+ if(text != null) {
+ contentEditText.setText(text);
+ }
}
iconGifImageView.setOnClickListener(view -> {
@@ -472,7 +478,8 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh
if(submitTextOrLinkPostEvent.errorMessage == null) {
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
} else {
- Snackbar.make(coordinatorLayout, submitTextOrLinkPostEvent.errorMessage, Snackbar.LENGTH_SHORT).show();
+ Snackbar.make(coordinatorLayout, submitTextOrLinkPostEvent.errorMessage.substring(0, 1).toUpperCase()
+ + submitTextOrLinkPostEvent.errorMessage.substring(1), Snackbar.LENGTH_SHORT).show();
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java
index 50ba6912..ec5b1bca 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java
@@ -14,7 +14,6 @@ import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
-import android.widget.VideoView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -28,6 +27,14 @@ import androidx.core.content.ContextCompat;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
+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.ui.PlayerView;
+import com.google.android.exoplayer2.upstream.DataSource;
+import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
+import com.google.android.exoplayer2.util.Util;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
@@ -85,7 +92,7 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
@BindView(R.id.capture_fab_post_video_activity) FloatingActionButton captureFab;
@BindView(R.id.select_from_library_fab_post_video_activity) FloatingActionButton selectFromLibraryFab;
@BindView(R.id.select_again_text_view_post_video_activity) TextView selectAgainTextView;
- @BindView(R.id.video_view_post_video_activity) VideoView videoView;
+ @BindView(R.id.player_view_post_video_activity) PlayerView videoPlayerView;
private boolean mNullAccessToken = false;
private String mAccessToken;
@@ -97,6 +104,7 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
private Uri videoUri;
private boolean loadSubredditIconSuccessful = true;
private boolean isPosting;
+ private boolean wasPlaying;
private Flair flair;
private boolean isSpoiler = false;
@@ -107,6 +115,9 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
private FlairBottomSheetFragment mFlairSelectionBottomSheetFragment;
private Snackbar mPostingSnackbar;
+ private DataSource.Factory dataSourceFactory;
+ private SimpleExoPlayer player;
+
@Inject
@Named("no_oauth")
Retrofit mRetrofit;
@@ -171,6 +182,12 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
mGlide = Glide.with(this);
+ player = ExoPlayerFactory.newSimpleInstance(this);
+ videoPlayerView.setPlayer(player);
+ dataSourceFactory = new DefaultDataSourceFactory(this,
+ Util.getUserAgent(this, "Infinity"));
+ player.setRepeatMode(Player.REPEAT_MODE_ALL);
+
mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE);
if(savedInstanceState != null) {
@@ -237,6 +254,11 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.into(iconGifImageView);
}
+
+ videoUri = getIntent().getData();
+ if(videoUri != null) {
+ loadVideo();
+ }
}
iconGifImageView.setOnClickListener(view -> {
@@ -312,16 +334,12 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
startActivityForResult(Intent.createChooser(intent,getResources().getString(R.string.select_from_gallery)), PICK_VIDEO_REQUEST_CODE);
});
- videoView.setOnPreparedListener(mediaPlayer -> {
- mediaPlayer.setLooping(true);
- mediaPlayer.setVolume(0, 0);
- });
-
selectAgainTextView.setOnClickListener(view -> {
+ wasPlaying = false;
+ player.setPlayWhenReady(false);
videoUri = null;
+ videoPlayerView.setVisibility(View.GONE);
selectAgainTextView.setVisibility(View.GONE);
- videoView.stopPlayback();
- videoView.setVisibility(View.GONE);
constraintLayout.setVisibility(View.VISIBLE);
});
}
@@ -339,10 +357,11 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
private void loadVideo() {
constraintLayout.setVisibility(View.GONE);
- videoView.setVisibility(View.VISIBLE);
selectAgainTextView.setVisibility(View.VISIBLE);
- videoView.setVideoURI(videoUri);
- videoView.start();
+ videoPlayerView.setVisibility(View.VISIBLE);
+ player.prepare(new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(videoUri));
+ player.setPlayWhenReady(true);
+ wasPlaying = true;
}
private void displaySubredditIcon() {
@@ -442,6 +461,7 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_VIDEO);
+ intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(intent);
@@ -469,9 +489,17 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
}
@Override
+ protected void onStart() {
+ super.onStart();
+ if(wasPlaying) {
+ player.setPlayWhenReady(true);
+ }
+ }
+
+ @Override
protected void onStop() {
super.onStop();
- videoView.stopPlayback();
+ player.setPlayWhenReady(false);
}
@Override
@@ -526,11 +554,13 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
loadVideo();
}
} else if (requestCode == CAPTURE_VIDEO_REQUEST_CODE) {
- if(data != null) {
- videoUri = data.getData();
- loadVideo();
- } else {
- Snackbar.make(coordinatorLayout, R.string.error_getting_video, Snackbar.LENGTH_SHORT).show();
+ if(resultCode == RESULT_OK) {
+ if(data != null && data.getData() != null) {
+ videoUri = data.getData();
+ loadVideo();
+ } else {
+ Snackbar.make(coordinatorLayout, R.string.error_getting_video, Snackbar.LENGTH_SHORT).show();
+ }
}
}
}
@@ -539,6 +569,7 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
protected void onDestroy() {
EventBus.getDefault().unregister(this);
super.onDestroy();
+ player.release();
}
@Override
@@ -572,7 +603,8 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
if (submitVideoPostEvent.errorMessage == null || submitVideoPostEvent.errorMessage.equals("")) {
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
} else {
- Snackbar.make(coordinatorLayout, submitVideoPostEvent.errorMessage, Snackbar.LENGTH_SHORT).show();
+ Snackbar.make(coordinatorLayout, submitVideoPostEvent.errorMessage.substring(0, 1).toUpperCase()
+ + submitVideoPostEvent.errorMessage.substring(1), Snackbar.LENGTH_SHORT).show();
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ShareDataResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ShareDataResolverActivity.java
new file mode 100644
index 00000000..92d2b290
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ShareDataResolverActivity.java
@@ -0,0 +1,77 @@
+package ml.docilealligator.infinityforreddit;
+
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.util.Patterns;
+import android.widget.Toast;
+
+import androidx.appcompat.app.AppCompatActivity;
+
+public class ShareDataResolverActivity extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ Intent receivedIntent = getIntent();
+ String action = receivedIntent.getAction();
+ String type = receivedIntent.getType();
+
+ if(Intent.ACTION_SEND.equals(action) && type != null) {
+ if("text/plain".equals(type)) {
+ String text = receivedIntent.getStringExtra(Intent.EXTRA_TEXT);
+ if(text != null) {
+ if(Patterns.WEB_URL.matcher(text).matches()) {
+ //It's a link
+ Intent intent = new Intent(this, PostLinkActivity.class);
+ intent.putExtra(PostLinkActivity.EXTRA_LINK, text);
+ startActivity(intent);
+ } else {
+ Intent intent = new Intent(this, PostTextActivity.class);
+ intent.putExtra(PostTextActivity.EXTRA_CONTENT, text);
+ startActivity(intent);
+ }
+ } else {
+ Toast.makeText(this, R.string.no_data_received, Toast.LENGTH_SHORT).show();
+ }
+ } else if(type.equals("image/gif")) {
+ Uri videoUri = receivedIntent.getParcelableExtra(Intent.EXTRA_STREAM);
+ if(videoUri != null) {
+ Intent intent = new Intent(this, PostVideoActivity.class);
+ intent.setData(videoUri);
+ intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ startActivity(intent);
+ } else {
+ Toast.makeText(this, R.string.no_video_path_received, Toast.LENGTH_SHORT).show();
+ }
+ } else if(type.startsWith("image/")) {
+ Uri imageUri = receivedIntent.getParcelableExtra(Intent.EXTRA_STREAM);
+ if(imageUri != null) {
+ Intent intent = new Intent(this, PostImageActivity.class);
+ intent.setData(imageUri);
+ intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ startActivity(intent);
+ } else {
+ Toast.makeText(this, R.string.no_image_path_received, Toast.LENGTH_SHORT).show();
+ }
+ } else if(type.startsWith("video/")) {
+ Uri videoUri = receivedIntent.getParcelableExtra(Intent.EXTRA_STREAM);
+ if(videoUri != null) {
+ Intent intent = new Intent(this, PostVideoActivity.class);
+ intent.setData(videoUri);
+ intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ startActivity(intent);
+ } else {
+ Toast.makeText(this, R.string.no_video_path_received, Toast.LENGTH_SHORT).show();
+ }
+ } else {
+ Toast.makeText(this, R.string.cannot_handle_intent, Toast.LENGTH_SHORT).show();
+ }
+ } else {
+ Toast.makeText(this, R.string.cannot_handle_intent, Toast.LENGTH_SHORT).show();
+ }
+
+ finish();
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java
index 018d3a7c..fe8c1e79 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java
@@ -135,7 +135,7 @@ class SubmitPost {
}
}).execute();
} else {
- submitPostListener.submitFailed("Error: " + response.code());
+ submitPostListener.submitFailed(response.message());
}
}
@@ -234,7 +234,6 @@ class SubmitPost {
uploadImageParams.put(RedditUtils.FILEPATH_KEY, "post_image.jpg");
uploadImageParams.put(RedditUtils.MIMETYPE_KEY, "image/jpeg");
- Log.i("map", RedditUtils.getOAuthHeader(accessToken).toString());
Call<String> uploadImageCall = api.uploadImage(RedditUtils.getOAuthHeader(accessToken), uploadImageParams);
uploadImageCall.enqueue(new Callback<String>() {
@Override
@@ -417,7 +416,6 @@ class SubmitPost {
} else {
errorString = error.getString(0);
}
- errorString = errorString.substring(0, 1).toUpperCase() + errorString.substring(1);
submitPostListener.submitFailed(errorString);
} else {
submitPostListener.submitFailed(null);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPostService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPostService.java
index efb6a7df..f3e42109 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPostService.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPostService.java
@@ -16,6 +16,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
+import androidx.core.app.NotificationManagerCompat;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.CustomTarget;
@@ -93,13 +94,13 @@ public class SubmitPostService extends Service {
NotificationManager.IMPORTANCE_LOW
);
- NotificationManager manager = getSystemService(NotificationManager.class);
+ NotificationManagerCompat manager = NotificationManagerCompat.from(this);
manager.createNotificationChannel(serviceChannel);
}
if(postType == EXTRA_POST_TEXT_OR_LINK) {
- content = intent.getExtras().getString(EXTRA_CONTENT);
- kind = intent.getExtras().getString(EXTRA_KIND);
+ content = intent.getStringExtra(EXTRA_CONTENT);
+ kind = intent.getStringExtra(EXTRA_KIND);
startForeground(NotificationUtils.SUBMIT_POST_SERVICE_NOTIFICATION_ID, createNotification(R.string.posting));
submitTextOrLinkPost();
} else if(postType == EXTRA_POST_TYPE_IMAGE) {
@@ -172,6 +173,13 @@ public class SubmitPostService extends Service {
}
@Override
+ public void onLoadFailed(@Nullable Drawable errorDrawable) {
+ EventBus.getDefault().post(new SubmitImagePostEvent(false, getString(R.string.error_processing_image)));
+
+ stopService();
+ }
+
+ @Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
@@ -180,43 +188,59 @@ public class SubmitPostService extends Service {
private void submitVideoPost() {
try (ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(mediaUri, "r")) {
- FileInputStream in = new FileInputStream(pfd.getFileDescriptor());
- byte[] buffer;
- buffer = new byte[in.available()];
- while (in.read(buffer) != -1);
-
- Glide.with(this)
- .asBitmap()
- .load(mediaUri)
- .into(new CustomTarget<Bitmap>() {
- @Override
- public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
- SubmitPost.submitVideoPost(mOauthRetrofit, mUploadMediaRetrofit, mUploadVideoRetrofit,
- mAccessToken, getResources().getConfiguration().locale, subredditName, title,
- buffer, getContentResolver().getType(mediaUri), resource, flair, isSpoiler, isNSFW,
- new SubmitPost.SubmitPostListener() {
- @Override
- public void submitSuccessful(Post post) {
- EventBus.getDefault().post(new SubmitVideoPostEvent(true, false, null));
- Toast.makeText(SubmitPostService.this, R.string.video_is_processing, Toast.LENGTH_SHORT).show();
-
- stopService();
- }
-
- @Override
- public void submitFailed(@Nullable String errorMessage) {
- EventBus.getDefault().post(new SubmitVideoPostEvent(false, false, errorMessage));
-
- stopService();
- }
- });
- }
-
- @Override
- public void onLoadCleared(@Nullable Drawable placeholder) {
-
- }
- });
+ if(pfd != null) {
+ FileInputStream in = new FileInputStream(pfd.getFileDescriptor());
+ byte[] buffer;
+ buffer = new byte[in.available()];
+ while (in.read(buffer) != -1);
+
+ Glide.with(this)
+ .asBitmap()
+ .load(mediaUri)
+ .into(new CustomTarget<Bitmap>() {
+ @Override
+ public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
+ String type = getContentResolver().getType(mediaUri);
+ if(type != null) {
+ SubmitPost.submitVideoPost(mOauthRetrofit, mUploadMediaRetrofit, mUploadVideoRetrofit,
+ mAccessToken, getResources().getConfiguration().locale, subredditName, title,
+ buffer, type, resource, flair, isSpoiler, isNSFW,
+ new SubmitPost.SubmitPostListener() {
+ @Override
+ public void submitSuccessful(Post post) {
+ EventBus.getDefault().post(new SubmitVideoPostEvent(true, false, null));
+ Toast.makeText(SubmitPostService.this, R.string.video_is_processing, Toast.LENGTH_SHORT).show();
+
+ stopService();
+ }
+
+ @Override
+ public void submitFailed(@Nullable String errorMessage) {
+ EventBus.getDefault().post(new SubmitVideoPostEvent(false, false, errorMessage));
+
+ stopService();
+ }
+ });
+ } else {
+ EventBus.getDefault().post(new SubmitVideoPostEvent(false, true, null));
+ }
+ }
+
+ @Override
+ public void onLoadFailed(@Nullable Drawable errorDrawable) {
+ EventBus.getDefault().post(new SubmitVideoPostEvent(false, true, null));
+
+ stopService();
+ }
+
+ @Override
+ public void onLoadCleared(@Nullable Drawable placeholder) {
+
+ }
+ });
+ } else {
+ EventBus.getDefault().post(new SubmitVideoPostEvent(false, true, null));
+ }
} catch (IOException e) {
e.printStackTrace();
EventBus.getDefault().post(new SubmitVideoPostEvent(false, true, null));
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java
index 5d8a3e07..bffc0a9c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java
@@ -44,7 +44,6 @@ import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.trackselection.TrackSelector;
-import com.google.android.exoplayer2.ui.PlayerControlView;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
@@ -257,25 +256,22 @@ public class ViewVideoActivity extends AppCompatActivity {
}
});
- videoPlayerView.setControllerVisibilityListener(new PlayerControlView.VisibilityListener() {
- @Override
- public void onVisibilityChange(int visibility) {
- switch (visibility) {
- case View.GONE:
- getWindow().getDecorView().setSystemUiVisibility(
- View.SYSTEM_UI_FLAG_LAYOUT_STABLE
- | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
- | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
- | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
- | View.SYSTEM_UI_FLAG_FULLSCREEN
- | View.SYSTEM_UI_FLAG_IMMERSIVE);
- break;
- case View.VISIBLE:
- getWindow().getDecorView().setSystemUiVisibility(
- View.SYSTEM_UI_FLAG_LAYOUT_STABLE
- | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
- | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
- }
+ videoPlayerView.setControllerVisibilityListener(visibility -> {
+ switch (visibility) {
+ case View.GONE:
+ getWindow().getDecorView().setSystemUiVisibility(
+ View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
+ | View.SYSTEM_UI_FLAG_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_IMMERSIVE);
+ break;
+ case View.VISIBLE:
+ getWindow().getDecorView().setSystemUiVisibility(
+ View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
});
@@ -371,7 +367,7 @@ public class ViewVideoActivity extends AppCompatActivity {
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(this, "No storage permission to save this file", Toast.LENGTH_SHORT).show();
+ Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show();
} else if(grantResults[0] == PackageManager.PERMISSION_GRANTED && isDownloading) {
download();
}