diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-08-07 14:21:11 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2020-08-09 17:34:09 +0300 |
commit | c1fa83e50a51b45890abece095d7f608007b1cca (patch) | |
tree | 935f1c97ac973db36fa2bdf90049945c0df5d721 /app | |
parent | 3a4de050b07dc1627b6c69cd3938c12829d648d1 (diff) |
#646 Problem with uploading file (attachment)
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/AndroidManifest.xml | 1 | ||||
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentsFragment.java | 33 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 1 |
3 files changed, 18 insertions, 17 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b683b764a..9fe16e5eb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,6 +4,7 @@ package="it.niedermann.nextcloud.deck"> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> + <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <application android:name="it.niedermann.nextcloud.deck.DeckApplication" diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentsFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentsFragment.java index 460682ca0..42ecdbcc8 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentsFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentsFragment.java @@ -1,21 +1,19 @@ package it.niedermann.nextcloud.deck.ui.card.attachments; -import android.Manifest; import android.content.ContentResolver; import android.content.Intent; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.core.app.SharedElementCallback; -import androidx.core.content.PermissionChecker; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.GridLayoutManager; @@ -43,7 +41,12 @@ import it.niedermann.nextcloud.deck.ui.branding.BrandedSnackbar; import it.niedermann.nextcloud.deck.ui.card.EditCardViewModel; import it.niedermann.nextcloud.deck.ui.exception.ExceptionDialogFragment; +import static android.Manifest.permission.READ_EXTERNAL_STORAGE; import static android.app.Activity.RESULT_OK; +import static android.os.Build.VERSION.SDK_INT; +import static android.os.Build.VERSION_CODES.KITKAT; +import static android.os.Build.VERSION_CODES.M; +import static androidx.core.content.PermissionChecker.PERMISSION_GRANTED; import static androidx.core.content.PermissionChecker.checkSelfPermission; import static it.niedermann.nextcloud.deck.persistence.sync.adapters.db.util.LiveDataHelper.observeOnce; import static it.niedermann.nextcloud.deck.ui.branding.BrandingUtil.applyBrandToFAB; @@ -124,12 +127,8 @@ public class CardAttachmentsFragment extends BrandedFragment implements Attachme updateEmptyContentView(); } - if (viewModel.canEdit()) { - binding.fab.setOnClickListener(v -> { - startActivityForResult(new Intent(Intent.ACTION_GET_CONTENT) - .addCategory(Intent.CATEGORY_OPENABLE) - .setType("*/*"), REQUEST_CODE_ADD_FILE); - }); + if (viewModel.canEdit() && SDK_INT >= KITKAT) { + binding.fab.setOnClickListener(v -> pickFile()); binding.fab.show(); binding.attachmentsList.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override @@ -147,16 +146,14 @@ public class CardAttachmentsFragment extends BrandedFragment implements Attachme return binding.getRoot(); } - @RequiresApi(api = Build.VERSION_CODES.KITKAT) + @RequiresApi(api = KITKAT) public void pickFile() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission(requireActivity(), Manifest.permission.READ_CONTACTS) != PermissionChecker.PERMISSION_GRANTED) { - requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, - REQUEST_CODE_ADD_FILE_PERMISSION); + if (SDK_INT >= M && checkSelfPermission(requireActivity(), READ_EXTERNAL_STORAGE) != PERMISSION_GRANTED) { + requestPermissions(new String[]{READ_EXTERNAL_STORAGE}, REQUEST_CODE_ADD_FILE_PERMISSION); } else { - Intent intent = new Intent(Intent.ACTION_GET_CONTENT) + startActivityForResult(new Intent(Intent.ACTION_GET_CONTENT) .addCategory(Intent.CATEGORY_OPENABLE) - .setType("*/*"); - startActivityForResult(intent, REQUEST_CODE_ADD_FILE); + .setType("*/*"), REQUEST_CODE_ADD_FILE); } } @@ -248,8 +245,10 @@ public class CardAttachmentsFragment extends BrandedFragment implements Attachme //noinspection SwitchStatementWithTooFewBranches switch (requestCode) { case REQUEST_CODE_ADD_FILE_PERMISSION: - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + if (SDK_INT >= KITKAT && checkSelfPermission(requireActivity(), READ_EXTERNAL_STORAGE) == PERMISSION_GRANTED) { pickFile(); + } else { + Toast.makeText(requireContext(), R.string.cannot_upload_files_without_permission, Toast.LENGTH_LONG).show(); } break; default: diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4924ed8c4..a6286e338 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -309,4 +309,5 @@ <string name="single_card">Single card</string> <string name="project_type_room">Talk room</string> <string name="simple_move">Move</string> + <string name="cannot_upload_files_without_permission">Can not upload files without permission</string> </resources> |