diff options
Diffstat (limited to 'app')
3 files changed, 10 insertions, 39 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java index 8304b5733..75c75f628 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java @@ -1,10 +1,10 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters; +import static it.niedermann.nextcloud.deck.util.MimeTypeUtil.TEXT_PLAIN; + import android.content.Context; import android.content.SharedPreferences; import android.net.ConnectivityManager; -import android.net.Network; -import android.net.NetworkCapabilities; import android.net.NetworkInfo; import android.net.Uri; import android.webkit.MimeTypeMap; @@ -49,8 +49,6 @@ import okhttp3.MultipartBody; import okhttp3.RequestBody; import okhttp3.ResponseBody; -import static it.niedermann.nextcloud.deck.util.MimeTypeUtil.TEXT_PLAIN; - public class ServerAdapter { private final String prefKeyWifiOnly; @@ -80,20 +78,11 @@ public class ServerAdapter { ConnectivityManager cm = (ConnectivityManager) applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm != null) { if (sharedPreferences.getBoolean(prefKeyWifiOnly, false)) { - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { - Network network = cm.getActiveNetwork(); - NetworkCapabilities capabilities = cm.getNetworkCapabilities(network); - if (capabilities == null) { - return false; - } - return capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI); - } else { - NetworkInfo networkInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); - if (networkInfo == null) { - return false; - } - return networkInfo.isConnected(); + NetworkInfo networkInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); + if (networkInfo == null) { + return false; } + return networkInfo.isConnected(); } else { return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected(); } 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 48fbc3ea7..182d7d9fa 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 @@ -4,8 +4,6 @@ import static android.Manifest.permission.CAMERA; import static android.Manifest.permission.READ_CONTACTS; 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.M; import static android.view.View.GONE; import static android.view.View.VISIBLE; import static androidx.core.content.PermissionChecker.PERMISSION_GRANTED; @@ -252,7 +250,7 @@ public class CardAttachmentsFragment extends Fragment implements AttachmentDelet private void showGalleryPicker() { if (!(pickerAdapter instanceof GalleryAdapter)) { - if (isPermissionRequestNeeded(READ_EXTERNAL_STORAGE) || isPermissionRequestNeeded(CAMERA)) { + if (checkSelfPermission(requireActivity(), READ_EXTERNAL_STORAGE) != PERMISSION_GRANTED || checkSelfPermission(requireActivity(), CAMERA) != PERMISSION_GRANTED) { requestPermissions(new String[]{READ_EXTERNAL_STORAGE, CAMERA}, REQUEST_CODE_PICK_GALLERY_PERMISSION); } else { unbindPickerAdapter(); @@ -276,7 +274,7 @@ public class CardAttachmentsFragment extends Fragment implements AttachmentDelet private void showContactPicker() { if (!(pickerAdapter instanceof ContactAdapter)) { - if (isPermissionRequestNeeded(READ_CONTACTS)) { + if (checkSelfPermission(requireActivity(), READ_CONTACTS) != PERMISSION_GRANTED) { requestPermissions(new String[]{READ_CONTACTS}, REQUEST_CODE_PICK_CONTACT_PICKER_PERMISSION); } else { unbindPickerAdapter(); @@ -298,7 +296,7 @@ public class CardAttachmentsFragment extends Fragment implements AttachmentDelet private void showFilePicker() { if (!(pickerAdapter instanceof FileAdapter)) { - if (isPermissionRequestNeeded(READ_EXTERNAL_STORAGE)) { + if (checkSelfPermission(requireActivity(), READ_EXTERNAL_STORAGE) != PERMISSION_GRANTED) { requestPermissions(new String[]{READ_EXTERNAL_STORAGE}, REQUEST_CODE_PICK_FILE_PERMISSION); } else { openNativeFilePicker(); @@ -336,16 +334,6 @@ public class CardAttachmentsFragment extends Fragment implements AttachmentDelet .setType("*/*"), REQUEST_CODE_PICK_FILE); } - /** - * Checks the current Android version and whether the permission has already been granted. - * - * @param permission see {@link android.Manifest.permission} - * @return whether or not requesting permission is needed - */ - private boolean isPermissionRequestNeeded(@NonNull String permission) { - return SDK_INT >= M && checkSelfPermission(requireActivity(), permission) != PERMISSION_GRANTED; - } - private void unbindPickerAdapter() { if (pickerAdapter != null) { pickerAdapter.onDestroy(); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/exception/tips/TipsAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/exception/tips/TipsAdapter.java index 5588c12dc..589bc187a 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/exception/tips/TipsAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/exception/tips/TipsAdapter.java @@ -7,8 +7,6 @@ import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; -import android.os.Build.VERSION; -import android.os.Build.VERSION_CODES; import android.provider.Settings; import android.view.LayoutInflater; import android.view.ViewGroup; @@ -85,11 +83,7 @@ public class TipsAdapter extends RecyclerView.Adapter<TipsViewHolder> { add(R.string.error_dialog_tip_offline); add(R.string.error_dialog_tip_sync_only_on_wifi); } else if (throwable instanceof NextcloudApiNotRespondingException) { - if (VERSION.SDK_INT >= VERSION_CODES.M) { - add(R.string.error_dialog_tip_disable_battery_optimizations, new Intent().setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS).putExtra(INTENT_EXTRA_BUTTON_TEXT, R.string.error_action_open_battery_settings)); - } else { - add(R.string.error_dialog_tip_disable_battery_optimizations); - } + add(R.string.error_dialog_tip_disable_battery_optimizations, new Intent().setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS).putExtra(INTENT_EXTRA_BUTTON_TEXT, R.string.error_action_open_battery_settings)); add(R.string.error_dialog_tip_files_force_stop); add(R.string.error_dialog_tip_files_delete_storage); } else if (throwable instanceof SocketTimeoutException || throwable instanceof ConnectException) { |