From 6a359bbbf8d4d1fcefe46c63db23c25f4f2c118e Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 26 Jan 2023 12:38:21 +0100 Subject: [PATCH] Redo upload --- .../activities/PeertubeUploadActivity.java | 16 +- .../android/peertube/helper/Helper.java | 23 ++ .../layout/activity_peertube_upload.xml | 210 ++++++++++-------- 3 files changed, 141 insertions(+), 108 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeUploadActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeUploadActivity.java index 559bc987..31f8cd6c 100644 --- a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeUploadActivity.java +++ b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeUploadActivity.java @@ -19,11 +19,9 @@ import static app.fedilab.android.peertube.activities.PeertubeMainActivity.userM import static app.fedilab.android.peertube.client.RetrofitPeertubeAPI.DataType.MY_CHANNELS; import static app.fedilab.android.peertube.helper.Helper.peertubeInformation; -import android.Manifest; import android.app.Activity; import android.app.PendingIntent; import android.content.Intent; -import android.content.pm.PackageManager; import android.graphics.Color; import android.net.Uri; import android.os.Build; @@ -34,8 +32,6 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Toast; -import androidx.core.app.ActivityCompat; -import androidx.core.content.ContextCompat; import androidx.documentfile.provider.DocumentFile; import androidx.lifecycle.ViewModelProvider; @@ -269,22 +265,14 @@ public class PeertubeUploadActivity extends BaseBarActivity { }); binding.setUploadFile.setEnabled(true); - binding.setUploadFile.setOnClickListener(v -> { - if (ContextCompat.checkSelfPermission(PeertubeUploadActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != - PackageManager.PERMISSION_GRANTED) { - ActivityCompat.requestPermissions(PeertubeUploadActivity.this, - new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, - MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE); - return; - } + binding.setUploadFile.setOnClickListener(v -> Helper.requestPermissionAndProceed(this, () -> { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("*/*"); String[] mimetypes = {"video/*"}; intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes); startActivityForResult(intent, PICK_IVDEO); - - }); + })); //Manage languages binding.setUploadChannel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { diff --git a/app/src/main/java/app/fedilab/android/peertube/helper/Helper.java b/app/src/main/java/app/fedilab/android/peertube/helper/Helper.java index ee4dcda2..e5d0e465 100644 --- a/app/src/main/java/app/fedilab/android/peertube/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/peertube/helper/Helper.java @@ -21,6 +21,7 @@ import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN; import static app.fedilab.android.mastodon.helper.Helper.dialogStyle; import static app.fedilab.android.peertube.activities.PeertubeMainActivity.typeOfConnection; +import android.Manifest; import android.annotation.SuppressLint; import android.app.Activity; import android.app.DownloadManager; @@ -28,6 +29,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.content.res.TypedArray; @@ -52,6 +54,7 @@ import android.widget.ImageView; import android.widget.Toast; import androidx.appcompat.app.AlertDialog; +import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import androidx.preference.PreferenceManager; @@ -766,6 +769,26 @@ public class Helper { } } + public static void requestPermissionAndProceed(Activity activity, PermissionGranted permissionGranted) { + if (Build.VERSION.SDK_INT >= 23) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { + if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, app.fedilab.android.mastodon.helper.Helper.EXTERNAL_STORAGE_REQUEST_CODE_MEDIA_SAVE); + } else { + permissionGranted.proceed(); + } + } else { + permissionGranted.proceed(); + } + } else { + permissionGranted.proceed(); + } + } + + public interface PermissionGranted { + void proceed(); + } + public static String readFileFromAssets(Context context, String filename) { String json; diff --git a/app/src/main/res/layouts/peertube/layout/activity_peertube_upload.xml b/app/src/main/res/layouts/peertube/layout/activity_peertube_upload.xml index 5d4baecd..afe72dac 100644 --- a/app/src/main/res/layouts/peertube/layout/activity_peertube_upload.xml +++ b/app/src/main/res/layouts/peertube/layout/activity_peertube_upload.xml @@ -18,79 +18,95 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + xmlns:app="http://schemas.android.com/apk/res-auto" tools:context=".peertube.activities.PeertubeUploadActivity"> - - - + android:layout_margin="12dp" + app:cardElevation="2dp"> - + - - + - + - + + - + - - + - + -