mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-07 11:17:25 +01:00
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.
This commit is contained in:
parent
30d2abe9c6
commit
cc0d78aedd
Binary file not shown.
Binary file not shown.
@ -2,15 +2,6 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="ml.docilealligator.infinityforreddit">
|
package="ml.docilealligator.infinityforreddit">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
|
||||||
|
|
||||||
<uses-permission-sdk-23 android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
|
||||||
|
|
||||||
<uses-permission
|
|
||||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
|
||||||
android:maxSdkVersion="22" />
|
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name=".Infinity"
|
android:name=".Infinity"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
@ -20,6 +11,23 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme"
|
android:theme="@style/AppTheme"
|
||||||
android:usesCleartextTraffic="true">
|
android:usesCleartextTraffic="true">
|
||||||
|
<activity android:name=".ShareDataResolverActivity">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:mimeType="image/*" />
|
||||||
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:mimeType="video/*" />
|
||||||
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:mimeType="text/plain" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".SettingsActivity"
|
android:name=".SettingsActivity"
|
||||||
android:label="@string/search_activity_label"
|
android:label="@string/search_activity_label"
|
||||||
@ -47,15 +55,11 @@
|
|||||||
android:theme="@style/AppTheme.NoActionBar"
|
android:theme="@style/AppTheme.NoActionBar"
|
||||||
android:windowSoftInputMode="adjustResize" />
|
android:windowSoftInputMode="adjustResize" />
|
||||||
|
|
||||||
<service
|
|
||||||
android:name=".SubmitPostService"
|
|
||||||
android:enabled="true"
|
|
||||||
android:exported="false" />
|
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".FilteredThingActivity"
|
android:name=".FilteredThingActivity"
|
||||||
android:parentActivityName=".MainActivity"
|
android:parentActivityName=".MainActivity"
|
||||||
android:theme="@style/AppTheme.NoActionBar" />
|
android:theme="@style/AppTheme.NoActionBar" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".SearchSubredditsResultActivity"
|
android:name=".SearchSubredditsResultActivity"
|
||||||
android:label="@string/search_subreddits_activity_label"
|
android:label="@string/search_subreddits_activity_label"
|
||||||
@ -172,7 +176,6 @@
|
|||||||
android:name=".ViewUserDetailActivity"
|
android:name=".ViewUserDetailActivity"
|
||||||
android:parentActivityName=".MainActivity"
|
android:parentActivityName=".MainActivity"
|
||||||
android:theme="@style/AppTheme.NoActionBarWithTranslucentWindow" />
|
android:theme="@style/AppTheme.NoActionBarWithTranslucentWindow" />
|
||||||
|
|
||||||
<provider
|
<provider
|
||||||
android:name="androidx.core.content.FileProvider"
|
android:name="androidx.core.content.FileProvider"
|
||||||
android:authorities="${applicationId}.provider"
|
android:authorities="${applicationId}.provider"
|
||||||
@ -182,6 +185,20 @@
|
|||||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
android:resource="@xml/file_paths" />
|
android:resource="@xml/file_paths" />
|
||||||
</provider>
|
</provider>
|
||||||
|
|
||||||
|
<service
|
||||||
|
android:name=".SubmitPostService"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="false" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
<uses-permission
|
||||||
|
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||||
|
android:maxSdkVersion="22" />
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
|
<uses-permission-sdk-23 android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@ -239,6 +239,11 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.into(iconGifImageView);
|
.into(iconGifImageView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
imageUri = getIntent().getData();
|
||||||
|
if(imageUri != null) {
|
||||||
|
loadImage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
iconGifImageView.setOnClickListener(view -> {
|
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_SPOILER, isSpoiler);
|
||||||
intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
|
intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
|
||||||
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_IMAGE);
|
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) {
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
startForegroundService(intent);
|
startForegroundService(intent);
|
||||||
@ -563,7 +569,8 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
if (submitImagePostEvent.errorMessage == null || submitImagePostEvent.errorMessage.equals("")) {
|
if (submitImagePostEvent.errorMessage == null || submitImagePostEvent.errorMessage.equals("")) {
|
||||||
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
|
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
|
||||||
} else {
|
} 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
|
|||||||
public class PostLinkActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback {
|
public class PostLinkActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback {
|
||||||
|
|
||||||
static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
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_NAME_STATE = "SNS";
|
||||||
private static final String SUBREDDIT_ICON_STATE = "SIS";
|
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)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.into(iconGifImageView);
|
.into(iconGifImageView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String link = getIntent().getStringExtra(EXTRA_LINK);
|
||||||
|
if(link != null) {
|
||||||
|
contentEditText.setText(link);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
iconGifImageView.setOnClickListener(view -> {
|
iconGifImageView.setOnClickListener(view -> {
|
||||||
@ -472,7 +478,8 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh
|
|||||||
if(submitTextOrLinkPostEvent.errorMessage == null) {
|
if(submitTextOrLinkPostEvent.errorMessage == null) {
|
||||||
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
|
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
|
||||||
} else {
|
} 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
|
|||||||
public class PostTextActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback {
|
public class PostTextActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback {
|
||||||
|
|
||||||
static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
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_NAME_STATE = "SNS";
|
||||||
private static final String SUBREDDIT_ICON_STATE = "SIS";
|
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)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.into(iconGifImageView);
|
.into(iconGifImageView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String text = getIntent().getStringExtra(EXTRA_CONTENT);
|
||||||
|
if(text != null) {
|
||||||
|
contentEditText.setText(text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
iconGifImageView.setOnClickListener(view -> {
|
iconGifImageView.setOnClickListener(view -> {
|
||||||
@ -472,7 +478,8 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh
|
|||||||
if(submitTextOrLinkPostEvent.errorMessage == null) {
|
if(submitTextOrLinkPostEvent.errorMessage == null) {
|
||||||
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
|
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
|
||||||
} else {
|
} 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ import android.view.Window;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.VideoView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@ -28,6 +27,14 @@ import androidx.core.content.ContextCompat;
|
|||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.RequestManager;
|
import com.bumptech.glide.RequestManager;
|
||||||
import com.bumptech.glide.request.RequestOptions;
|
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.dialog.MaterialAlertDialogBuilder;
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
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.capture_fab_post_video_activity) FloatingActionButton captureFab;
|
||||||
@BindView(R.id.select_from_library_fab_post_video_activity) FloatingActionButton selectFromLibraryFab;
|
@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.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 boolean mNullAccessToken = false;
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
@ -97,6 +104,7 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
private Uri videoUri;
|
private Uri videoUri;
|
||||||
private boolean loadSubredditIconSuccessful = true;
|
private boolean loadSubredditIconSuccessful = true;
|
||||||
private boolean isPosting;
|
private boolean isPosting;
|
||||||
|
private boolean wasPlaying;
|
||||||
|
|
||||||
private Flair flair;
|
private Flair flair;
|
||||||
private boolean isSpoiler = false;
|
private boolean isSpoiler = false;
|
||||||
@ -107,6 +115,9 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
private FlairBottomSheetFragment mFlairSelectionBottomSheetFragment;
|
private FlairBottomSheetFragment mFlairSelectionBottomSheetFragment;
|
||||||
private Snackbar mPostingSnackbar;
|
private Snackbar mPostingSnackbar;
|
||||||
|
|
||||||
|
private DataSource.Factory dataSourceFactory;
|
||||||
|
private SimpleExoPlayer player;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named("no_oauth")
|
@Named("no_oauth")
|
||||||
Retrofit mRetrofit;
|
Retrofit mRetrofit;
|
||||||
@ -171,6 +182,12 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
|
|
||||||
mGlide = Glide.with(this);
|
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);
|
mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE);
|
||||||
|
|
||||||
if(savedInstanceState != null) {
|
if(savedInstanceState != null) {
|
||||||
@ -237,6 +254,11 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.into(iconGifImageView);
|
.into(iconGifImageView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
videoUri = getIntent().getData();
|
||||||
|
if(videoUri != null) {
|
||||||
|
loadVideo();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
iconGifImageView.setOnClickListener(view -> {
|
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);
|
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 -> {
|
selectAgainTextView.setOnClickListener(view -> {
|
||||||
|
wasPlaying = false;
|
||||||
|
player.setPlayWhenReady(false);
|
||||||
videoUri = null;
|
videoUri = null;
|
||||||
|
videoPlayerView.setVisibility(View.GONE);
|
||||||
selectAgainTextView.setVisibility(View.GONE);
|
selectAgainTextView.setVisibility(View.GONE);
|
||||||
videoView.stopPlayback();
|
|
||||||
videoView.setVisibility(View.GONE);
|
|
||||||
constraintLayout.setVisibility(View.VISIBLE);
|
constraintLayout.setVisibility(View.VISIBLE);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -339,10 +357,11 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
|
|
||||||
private void loadVideo() {
|
private void loadVideo() {
|
||||||
constraintLayout.setVisibility(View.GONE);
|
constraintLayout.setVisibility(View.GONE);
|
||||||
videoView.setVisibility(View.VISIBLE);
|
|
||||||
selectAgainTextView.setVisibility(View.VISIBLE);
|
selectAgainTextView.setVisibility(View.VISIBLE);
|
||||||
videoView.setVideoURI(videoUri);
|
videoPlayerView.setVisibility(View.VISIBLE);
|
||||||
videoView.start();
|
player.prepare(new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(videoUri));
|
||||||
|
player.setPlayWhenReady(true);
|
||||||
|
wasPlaying = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displaySubredditIcon() {
|
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_SPOILER, isSpoiler);
|
||||||
intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
|
intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
|
||||||
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_VIDEO);
|
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) {
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
startForegroundService(intent);
|
startForegroundService(intent);
|
||||||
@ -468,10 +488,18 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
if(wasPlaying) {
|
||||||
|
player.setPlayWhenReady(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
videoView.stopPlayback();
|
player.setPlayWhenReady(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -526,7 +554,8 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
loadVideo();
|
loadVideo();
|
||||||
}
|
}
|
||||||
} else if (requestCode == CAPTURE_VIDEO_REQUEST_CODE) {
|
} else if (requestCode == CAPTURE_VIDEO_REQUEST_CODE) {
|
||||||
if(data != null) {
|
if(resultCode == RESULT_OK) {
|
||||||
|
if(data != null && data.getData() != null) {
|
||||||
videoUri = data.getData();
|
videoUri = data.getData();
|
||||||
loadVideo();
|
loadVideo();
|
||||||
} else {
|
} else {
|
||||||
@ -534,11 +563,13 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
EventBus.getDefault().unregister(this);
|
EventBus.getDefault().unregister(this);
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
player.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -572,7 +603,8 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
if (submitVideoPostEvent.errorMessage == null || submitVideoPostEvent.errorMessage.equals("")) {
|
if (submitVideoPostEvent.errorMessage == null || submitVideoPostEvent.errorMessage.equals("")) {
|
||||||
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
|
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
|
||||||
} else {
|
} 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -135,7 +135,7 @@ class SubmitPost {
|
|||||||
}
|
}
|
||||||
}).execute();
|
}).execute();
|
||||||
} else {
|
} 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.FILEPATH_KEY, "post_image.jpg");
|
||||||
uploadImageParams.put(RedditUtils.MIMETYPE_KEY, "image/jpeg");
|
uploadImageParams.put(RedditUtils.MIMETYPE_KEY, "image/jpeg");
|
||||||
|
|
||||||
Log.i("map", RedditUtils.getOAuthHeader(accessToken).toString());
|
|
||||||
Call<String> uploadImageCall = api.uploadImage(RedditUtils.getOAuthHeader(accessToken), uploadImageParams);
|
Call<String> uploadImageCall = api.uploadImage(RedditUtils.getOAuthHeader(accessToken), uploadImageParams);
|
||||||
uploadImageCall.enqueue(new Callback<String>() {
|
uploadImageCall.enqueue(new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
@ -417,7 +416,6 @@ class SubmitPost {
|
|||||||
} else {
|
} else {
|
||||||
errorString = error.getString(0);
|
errorString = error.getString(0);
|
||||||
}
|
}
|
||||||
errorString = errorString.substring(0, 1).toUpperCase() + errorString.substring(1);
|
|
||||||
submitPostListener.submitFailed(errorString);
|
submitPostListener.submitFailed(errorString);
|
||||||
} else {
|
} else {
|
||||||
submitPostListener.submitFailed(null);
|
submitPostListener.submitFailed(null);
|
||||||
|
@ -16,6 +16,7 @@ import android.widget.Toast;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
|
import androidx.core.app.NotificationManagerCompat;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.request.target.CustomTarget;
|
import com.bumptech.glide.request.target.CustomTarget;
|
||||||
@ -93,13 +94,13 @@ public class SubmitPostService extends Service {
|
|||||||
NotificationManager.IMPORTANCE_LOW
|
NotificationManager.IMPORTANCE_LOW
|
||||||
);
|
);
|
||||||
|
|
||||||
NotificationManager manager = getSystemService(NotificationManager.class);
|
NotificationManagerCompat manager = NotificationManagerCompat.from(this);
|
||||||
manager.createNotificationChannel(serviceChannel);
|
manager.createNotificationChannel(serviceChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(postType == EXTRA_POST_TEXT_OR_LINK) {
|
if(postType == EXTRA_POST_TEXT_OR_LINK) {
|
||||||
content = intent.getExtras().getString(EXTRA_CONTENT);
|
content = intent.getStringExtra(EXTRA_CONTENT);
|
||||||
kind = intent.getExtras().getString(EXTRA_KIND);
|
kind = intent.getStringExtra(EXTRA_KIND);
|
||||||
startForeground(NotificationUtils.SUBMIT_POST_SERVICE_NOTIFICATION_ID, createNotification(R.string.posting));
|
startForeground(NotificationUtils.SUBMIT_POST_SERVICE_NOTIFICATION_ID, createNotification(R.string.posting));
|
||||||
submitTextOrLinkPost();
|
submitTextOrLinkPost();
|
||||||
} else if(postType == EXTRA_POST_TYPE_IMAGE) {
|
} else if(postType == EXTRA_POST_TYPE_IMAGE) {
|
||||||
@ -171,6 +172,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
|
@Override
|
||||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||||
|
|
||||||
@ -180,6 +188,7 @@ public class SubmitPostService extends Service {
|
|||||||
|
|
||||||
private void submitVideoPost() {
|
private void submitVideoPost() {
|
||||||
try (ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(mediaUri, "r")) {
|
try (ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(mediaUri, "r")) {
|
||||||
|
if(pfd != null) {
|
||||||
FileInputStream in = new FileInputStream(pfd.getFileDescriptor());
|
FileInputStream in = new FileInputStream(pfd.getFileDescriptor());
|
||||||
byte[] buffer;
|
byte[] buffer;
|
||||||
buffer = new byte[in.available()];
|
buffer = new byte[in.available()];
|
||||||
@ -191,9 +200,11 @@ public class SubmitPostService extends Service {
|
|||||||
.into(new CustomTarget<Bitmap>() {
|
.into(new CustomTarget<Bitmap>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
||||||
|
String type = getContentResolver().getType(mediaUri);
|
||||||
|
if(type != null) {
|
||||||
SubmitPost.submitVideoPost(mOauthRetrofit, mUploadMediaRetrofit, mUploadVideoRetrofit,
|
SubmitPost.submitVideoPost(mOauthRetrofit, mUploadMediaRetrofit, mUploadVideoRetrofit,
|
||||||
mAccessToken, getResources().getConfiguration().locale, subredditName, title,
|
mAccessToken, getResources().getConfiguration().locale, subredditName, title,
|
||||||
buffer, getContentResolver().getType(mediaUri), resource, flair, isSpoiler, isNSFW,
|
buffer, type, resource, flair, isSpoiler, isNSFW,
|
||||||
new SubmitPost.SubmitPostListener() {
|
new SubmitPost.SubmitPostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void submitSuccessful(Post post) {
|
public void submitSuccessful(Post post) {
|
||||||
@ -210,6 +221,16 @@ public class SubmitPostService extends Service {
|
|||||||
stopService();
|
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
|
@Override
|
||||||
@ -217,6 +238,9 @@ public class SubmitPostService extends Service {
|
|||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
EventBus.getDefault().post(new SubmitVideoPostEvent(false, true, null));
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
EventBus.getDefault().post(new SubmitVideoPostEvent(false, true, null));
|
EventBus.getDefault().post(new SubmitVideoPostEvent(false, true, null));
|
||||||
|
@ -44,7 +44,6 @@ import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
|
|||||||
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
|
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
|
||||||
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
||||||
import com.google.android.exoplayer2.trackselection.TrackSelector;
|
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.ui.PlayerView;
|
||||||
import com.google.android.exoplayer2.upstream.DataSource;
|
import com.google.android.exoplayer2.upstream.DataSource;
|
||||||
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
|
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
|
||||||
@ -257,9 +256,7 @@ public class ViewVideoActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
videoPlayerView.setControllerVisibilityListener(new PlayerControlView.VisibilityListener() {
|
videoPlayerView.setControllerVisibilityListener(visibility -> {
|
||||||
@Override
|
|
||||||
public void onVisibilityChange(int visibility) {
|
|
||||||
switch (visibility) {
|
switch (visibility) {
|
||||||
case View.GONE:
|
case View.GONE:
|
||||||
getWindow().getDecorView().setSystemUiVisibility(
|
getWindow().getDecorView().setSystemUiVisibility(
|
||||||
@ -276,7 +273,6 @@ public class ViewVideoActivity extends AppCompatActivity {
|
|||||||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||||
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
|
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
|
||||||
@ -371,7 +367,7 @@ public class ViewVideoActivity extends AppCompatActivity {
|
|||||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||||
if(requestCode == PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE && grantResults.length > 0) {
|
if(requestCode == PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE && grantResults.length > 0) {
|
||||||
if(grantResults[0] == PackageManager.PERMISSION_DENIED) {
|
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) {
|
} else if(grantResults[0] == PackageManager.PERMISSION_GRANTED && isDownloading) {
|
||||||
download();
|
download();
|
||||||
}
|
}
|
||||||
|
@ -184,11 +184,12 @@
|
|||||||
android:textColor="@color/colorAccent"
|
android:textColor="@color/colorAccent"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
<VideoView
|
<com.google.android.exoplayer2.ui.PlayerView
|
||||||
android:id="@+id/video_view_post_video_activity"
|
android:id="@+id/player_view_post_video_activity"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="400dp"
|
||||||
android:visibility="gone"/>
|
android:visibility="gone"
|
||||||
|
app:controller_layout_id="@layout/exo_playback_control_view" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
@ -118,7 +118,8 @@
|
|||||||
<string name="select_an_image">Please select an image first</string>
|
<string name="select_an_image">Please select an image first</string>
|
||||||
<string name="posting">Posting</string>
|
<string name="posting">Posting</string>
|
||||||
<string name="post_failed">Could not post it</string>
|
<string name="post_failed">Could not post it</string>
|
||||||
<string name="error_processing_video">Error processing this video</string>
|
<string name="error_processing_image">Error processing image</string>
|
||||||
|
<string name="error_processing_video">Error processing video</string>
|
||||||
|
|
||||||
<string name="download_completed">Download completed</string>
|
<string name="download_completed">Download completed</string>
|
||||||
<string name="download_failed">Download Failed</string>
|
<string name="download_failed">Download Failed</string>
|
||||||
@ -197,8 +198,8 @@
|
|||||||
<string name="best">Best</string>
|
<string name="best">Best</string>
|
||||||
<string name="search">Search</string>
|
<string name="search">Search</string>
|
||||||
|
|
||||||
<string name="posting_video">Posting video</string>
|
<string name="posting_video">Posting Video</string>
|
||||||
<string name="posting_image">Posting image</string>
|
<string name="posting_image">Posting Image</string>
|
||||||
<string name="please_wait">Please wait.</string>
|
<string name="please_wait">Please wait.</string>
|
||||||
|
|
||||||
<string name="add_account">Add account</string>
|
<string name="add_account">Add account</string>
|
||||||
@ -283,7 +284,12 @@
|
|||||||
<string name="exit_when_submit_post">Leave?</string>
|
<string name="exit_when_submit_post">Leave?</string>
|
||||||
<string name="exit_when_submit_post_detail">The post will still be submitted even if you leave here.</string>
|
<string name="exit_when_submit_post_detail">The post will still be submitted even if you leave here.</string>
|
||||||
<string name="discard_post">Discard?</string>
|
<string name="discard_post">Discard?</string>
|
||||||
<string name="discard_post_detail">All the draft will not be saved.</string>
|
<string name="discard_post_detail">All the draft will NOT be saved.</string>
|
||||||
<string name="yes">Yes</string>
|
<string name="yes">Yes</string>
|
||||||
<string name="no">No</string>
|
<string name="no">No</string>
|
||||||
|
|
||||||
|
<string name="no_data_received">No data received</string>
|
||||||
|
<string name="no_image_path_received">No image path received</string>
|
||||||
|
<string name="no_video_path_received">No video path received</string>
|
||||||
|
<string name="cannot_handle_intent">Could not handle the share request</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user