From cf2a35f64ddab1a8734febd5e055a3425f276aae Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Thu, 26 Nov 2020 18:45:26 +0100 Subject: [PATCH] Drop Android 4.4 Support Signed-off-by: Andy Scherzinger --- build.gradle | 5 +- .../java/com/owncloud/android/MainApp.java | 64 ++++++++----------- .../authentication/AuthenticatorActivity.java | 12 +--- .../datastorage/DataStorageProvider.java | 37 ++++------- .../android/files/FileMenuFilter.java | 3 +- .../providers/DocumentsStorageProvider.java | 3 - .../android/ui/activity/EditorWebView.java | 1 - .../android/ui/activity/PassCodeActivity.java | 9 ++- .../activity/RichDocumentsEditorWebView.java | 3 - .../android/ui/activity/ToolbarActivity.java | 18 ++---- .../android/ui/adapter/PrintAdapter.java | 4 -- .../android/ui/asynctasks/PrintAsyncTask.java | 4 -- .../fragment/OCFileListBottomSheetDialog.java | 6 +- .../ui/fragment/OCFileListFragment.java | 26 +++----- .../ui/helpers/FileOperationsHelper.java | 7 +- .../ui/preview/PreviewTextFileFragment.java | 12 +--- .../ui/preview/PreviewTextStringFragment.java | 13 ++-- .../owncloud/android/utils/ThemeUtils.java | 17 ++--- .../providers/cursors/FileCursor.java | 4 +- .../providers/cursors/RootCursor.java | 9 +-- 20 files changed, 80 insertions(+), 177 deletions(-) diff --git a/build.gradle b/build.gradle index 8bb6a4bd81..a2d9475f41 100644 --- a/build.gradle +++ b/build.gradle @@ -98,9 +98,6 @@ for (TaskExecutionRequest tr : getGradle().getStartParameter().getTaskRequests() apply from: 'gplay.gradle' System.console().println("Applying gplay.gradle") } - if (arg.contains("lint")) { - testMinSdk = 19 - } } } @@ -129,7 +126,7 @@ android { compileSdkVersion 29 defaultConfig { - minSdkVersion 19 + minSdkVersion 21 targetSdkVersion 29 // arguments to be passed to functional tests diff --git a/src/main/java/com/owncloud/android/MainApp.java b/src/main/java/com/owncloud/android/MainApp.java index 32f5d13d34..ae4020a977 100644 --- a/src/main/java/com/owncloud/android/MainApp.java +++ b/src/main/java/com/owncloud/android/MainApp.java @@ -384,21 +384,30 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector { @SuppressLint("ApplySharedPref") // commit is done on purpose to write immediately private void fixStoragePath() { if (!preferences.isStoragePathFixEnabled()) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - StoragePoint[] storagePoints = DataStorageProvider.getInstance().getAvailableStoragePoints(); - String storagePath = preferences.getStoragePath(""); + StoragePoint[] storagePoints = DataStorageProvider.getInstance().getAvailableStoragePoints(); + String storagePath = preferences.getStoragePath(""); - if (TextUtils.isEmpty(storagePath)) { - if (preferences.getLastSeenVersionCode() != 0) { - // We already used the app, but no storage is set - fix that! - preferences.setStoragePath(Environment.getExternalStorageDirectory().getAbsolutePath()); - preferences.removeKeysMigrationPreference(); - } else { - // find internal storage path that's indexable - boolean set = false; + if (TextUtils.isEmpty(storagePath)) { + if (preferences.getLastSeenVersionCode() != 0) { + // We already used the app, but no storage is set - fix that! + preferences.setStoragePath(Environment.getExternalStorageDirectory().getAbsolutePath()); + preferences.removeKeysMigrationPreference(); + } else { + // find internal storage path that's indexable + boolean set = false; + for (StoragePoint storagePoint : storagePoints) { + if (storagePoint.getStorageType() == StoragePoint.StorageType.INTERNAL && + storagePoint.getPrivacyType() == StoragePoint.PrivacyType.PUBLIC) { + preferences.setStoragePath(storagePoint.getPath()); + preferences.removeKeysMigrationPreference(); + set = true; + break; + } + } + + if (!set) { for (StoragePoint storagePoint : storagePoints) { - if (storagePoint.getStorageType() == StoragePoint.StorageType.INTERNAL && - storagePoint.getPrivacyType() == StoragePoint.PrivacyType.PUBLIC) { + if (storagePoint.getPrivacyType() == StoragePoint.PrivacyType.PUBLIC) { preferences.setStoragePath(storagePoint.getPath()); preferences.removeKeysMigrationPreference(); set = true; @@ -406,27 +415,10 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector { } } - if (!set) { - for (StoragePoint storagePoint : storagePoints) { - if (storagePoint.getPrivacyType() == StoragePoint.PrivacyType.PUBLIC) { - preferences.setStoragePath(storagePoint.getPath()); - preferences.removeKeysMigrationPreference(); - set = true; - break; - } - } - - } } - preferences.setStoragePathFixEnabled(true); - } else { - preferences.removeKeysMigrationPreference(); - preferences.setStoragePathFixEnabled(true); } + preferences.setStoragePathFixEnabled(true); } else { - if (TextUtils.isEmpty(storagePath)) { - preferences.setStoragePath(Environment.getExternalStorageDirectory().getAbsolutePath()); - } preferences.removeKeysMigrationPreference(); preferences.setStoragePathFixEnabled(true); } @@ -479,12 +471,10 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector { connectivityService, powerManagementService); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - ReceiversHelper.registerPowerSaveReceiver(uploadsStorageManager, - accountManager, - connectivityService, - powerManagementService); - } + ReceiversHelper.registerPowerSaveReceiver(uploadsStorageManager, + accountManager, + connectivityService, + powerManagementService); } public static void notificationChannels() { diff --git a/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java index 1d5ac91efa..3b2ec1da1f 100644 --- a/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -330,13 +330,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity private void deleteCookies() { try { CookieSyncManager.createInstance(this); - CookieManager cookieManager = CookieManager.getInstance(); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - cookieManager.removeAllCookies(null); - } else { - cookieManager.removeAllCookie(); - } + CookieManager.getInstance().removeAllCookies(null); } catch (AndroidRuntimeException e) { Log_OC.e(TAG, e.getMessage()); } @@ -439,9 +433,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mLoginWebView.setVisibility(View.VISIBLE); ThemeUtils.colorStatusBar(AuthenticatorActivity.this, primaryColor); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - getWindow().setNavigationBarColor(primaryColor); - } + getWindow().setNavigationBarColor(primaryColor); } @Override diff --git a/src/main/java/com/owncloud/android/datastorage/DataStorageProvider.java b/src/main/java/com/owncloud/android/datastorage/DataStorageProvider.java index 8cb4336a7d..8070794fe7 100644 --- a/src/main/java/com/owncloud/android/datastorage/DataStorageProvider.java +++ b/src/main/java/com/owncloud/android/datastorage/DataStorageProvider.java @@ -21,7 +21,6 @@ package com.owncloud.android.datastorage; -import android.os.Build; import android.os.Environment; import com.owncloud.android.MainApp; @@ -67,34 +66,22 @@ public class DataStorageProvider { List paths = new ArrayList<>(); StoragePoint storagePoint; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - for (File f : MainApp.getAppContext().getExternalMediaDirs()) { - if (f != null && !paths.contains(f.getAbsolutePath())) { - storagePoint = new StoragePoint(); - storagePoint.setPath(f.getAbsolutePath()); - storagePoint.setDescription(f.getAbsolutePath()); - storagePoint.setPrivacyType(StoragePoint.PrivacyType.PUBLIC); - if (f.getAbsolutePath().startsWith("/storage/emulated/0")) { - storagePoint.setStorageType(StoragePoint.StorageType.INTERNAL); + for (File f : MainApp.getAppContext().getExternalMediaDirs()) { + if (f != null && !paths.contains(f.getAbsolutePath())) { + storagePoint = new StoragePoint(); + storagePoint.setPath(f.getAbsolutePath()); + storagePoint.setDescription(f.getAbsolutePath()); + storagePoint.setPrivacyType(StoragePoint.PrivacyType.PUBLIC); + if (f.getAbsolutePath().startsWith("/storage/emulated/0")) { + storagePoint.setStorageType(StoragePoint.StorageType.INTERNAL); + mCachedStoragePoints.add(storagePoint); + } else { + storagePoint.setStorageType(StoragePoint.StorageType.EXTERNAL); + if (isExternalStorageWritable()) { mCachedStoragePoints.add(storagePoint); - } else { - storagePoint.setStorageType(StoragePoint.StorageType.EXTERNAL); - if (isExternalStorageWritable()) { - mCachedStoragePoints.add(storagePoint); - } } } } - } else { - for (IStoragePointProvider p : mStorageProviders) { - if (p.canProvideStoragePoints()) { - mCachedStoragePoints.addAll(p.getAvailableStoragePoint()); - } - } - - for (int i = 0; i < mCachedStoragePoints.size(); i++) { - paths.add(mCachedStoragePoints.get(i).getPath()); - } } // Now we go add private ones diff --git a/src/main/java/com/owncloud/android/files/FileMenuFilter.java b/src/main/java/com/owncloud/android/files/FileMenuFilter.java index d0b0240060..6067d50dae 100644 --- a/src/main/java/com/owncloud/android/files/FileMenuFilter.java +++ b/src/main/java/com/owncloud/android/files/FileMenuFilter.java @@ -23,7 +23,6 @@ package com.owncloud.android.files; import android.content.ContentResolver; import android.content.Context; -import android.os.Build; import android.view.Menu; import android.view.MenuItem; @@ -333,7 +332,7 @@ public class FileMenuFilter { */ @NextcloudServer(max = 18) private boolean isRichDocumentEditingSupported(OCCapability capability, String mimeType) { - return isSingleFile() && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && + return isSingleFile() && (capability.getRichDocumentsMimeTypeList().contains(mimeType) || capability.getRichDocumentsOptionalMimeTypeList().contains(mimeType)) && capability.getRichDocumentsDirectEditing().isTrue(); diff --git a/src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java b/src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java index b262970865..3612aa8755 100644 --- a/src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java +++ b/src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java @@ -26,7 +26,6 @@ import android.accounts.Account; import android.accounts.AuthenticatorException; import android.accounts.OperationCanceledException; import android.annotation.SuppressLint; -import android.annotation.TargetApi; import android.content.ContentResolver; import android.content.Context; import android.content.res.AssetFileDescriptor; @@ -34,7 +33,6 @@ import android.database.Cursor; import android.graphics.Point; import android.net.Uri; import android.os.AsyncTask; -import android.os.Build; import android.os.Bundle; import android.os.CancellationSignal; import android.os.Handler; @@ -574,7 +572,6 @@ public class DocumentsStorageProvider extends DocumentsProvider { context.getContentResolver().notifyChange(toNotifyUri(parentFolder), null, false); } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) private void recursiveRevokePermission(Document document) { FileDataStorageManager storageManager = document.getStorageManager(); OCFile file = document.getFile(); diff --git a/src/main/java/com/owncloud/android/ui/activity/EditorWebView.java b/src/main/java/com/owncloud/android/ui/activity/EditorWebView.java index 91b9d87f36..13958e1706 100644 --- a/src/main/java/com/owncloud/android/ui/activity/EditorWebView.java +++ b/src/main/java/com/owncloud/android/ui/activity/EditorWebView.java @@ -112,7 +112,6 @@ public abstract class EditorWebView extends ExternalSiteWebView { finish(); } - @SuppressLint("AddJavascriptInterface") // suppress warning as webview is only used >= Lollipop @Override protected void onCreate(Bundle savedInstanceState) { webViewLayout = R.layout.richdocuments_webview; // TODO rename diff --git a/src/main/java/com/owncloud/android/ui/activity/PassCodeActivity.java b/src/main/java/com/owncloud/android/ui/activity/PassCodeActivity.java index cffce1e455..7b194a7346 100644 --- a/src/main/java/com/owncloud/android/ui/activity/PassCodeActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/PassCodeActivity.java @@ -23,7 +23,6 @@ package com.owncloud.android.ui.activity; import android.content.Intent; -import android.os.Build; import android.os.Bundle; import android.os.SystemClock; import android.text.Editable; @@ -364,12 +363,12 @@ public class PassCodeActivity extends AppCompatActivity implements Injectable { * @return 'True' when the key event was processed by this method. */ @Override - public boolean onKeyDown(int keyCode, KeyEvent event){ - if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount()== 0){ - if(ACTION_CHECK.equals(getIntent().getAction()) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { + if (ACTION_CHECK.equals(getIntent().getAction())) { moveTaskToBack(true); finishAndRemoveTask(); - }else if (ACTION_REQUEST_WITH_RESULT.equals(getIntent().getAction()) || + } else if (ACTION_REQUEST_WITH_RESULT.equals(getIntent().getAction()) || ACTION_CHECK_WITH_RESULT.equals(getIntent().getAction())) { finish(); }// else, do nothing, but report that the key was consumed to stay alive diff --git a/src/main/java/com/owncloud/android/ui/activity/RichDocumentsEditorWebView.java b/src/main/java/com/owncloud/android/ui/activity/RichDocumentsEditorWebView.java index 88495b6c32..a0de159d11 100644 --- a/src/main/java/com/owncloud/android/ui/activity/RichDocumentsEditorWebView.java +++ b/src/main/java/com/owncloud/android/ui/activity/RichDocumentsEditorWebView.java @@ -62,7 +62,6 @@ import java.lang.ref.WeakReference; import javax.inject.Inject; import androidx.annotation.NonNull; -import androidx.annotation.RequiresApi; import butterknife.ButterKnife; import butterknife.Unbinder; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -70,7 +69,6 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; /** * Opens document for editing via Richdocuments app in a web view */ -@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public class RichDocumentsEditorWebView extends EditorWebView { public static final int REQUEST_LOCAL_FILE = 101; private static final int REQUEST_REMOTE_FILE = 100; @@ -92,7 +90,6 @@ public class RichDocumentsEditorWebView extends EditorWebView { protected ClientFactory clientFactory; @SuppressFBWarnings("ANDROID_WEB_VIEW_JAVASCRIPT_INTERFACE") - @SuppressLint("AddJavascriptInterface") // suppress warning as webview is only used >= Lollipop @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/src/main/java/com/owncloud/android/ui/activity/ToolbarActivity.java b/src/main/java/com/owncloud/android/ui/activity/ToolbarActivity.java index 71a52651eb..727008193f 100644 --- a/src/main/java/com/owncloud/android/ui/activity/ToolbarActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/ToolbarActivity.java @@ -27,7 +27,6 @@ import android.annotation.SuppressLint; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.drawable.Drawable; -import android.os.Build; import android.os.Bundle; import android.view.View; import android.widget.FrameLayout; @@ -50,7 +49,6 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.AppCompatSpinner; import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; -import androidx.core.view.ViewCompat; /** * Base class providing toolbar registration functionality, see {@link #setupToolbar(boolean, boolean)}. @@ -161,22 +159,14 @@ public abstract class ToolbarActivity extends BaseActivity { @SuppressLint("PrivateResource") private void showHomeSearchToolbar(boolean isShow) { if (isShow) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - mAppBar.setStateListAnimator(AnimatorInflater.loadStateListAnimator(mAppBar.getContext(), - R.animator.appbar_elevation_off)); - } else { - ViewCompat.setElevation(mAppBar, 0); - } + mAppBar.setStateListAnimator(AnimatorInflater.loadStateListAnimator(mAppBar.getContext(), + R.animator.appbar_elevation_off)); mDefaultToolbar.setVisibility(View.GONE); mHomeSearchToolbar.setVisibility(View.VISIBLE); ThemeUtils.colorStatusBar(this, ContextCompat.getColor(this, R.color.bg_default)); } else { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - mAppBar.setStateListAnimator(AnimatorInflater.loadStateListAnimator(mAppBar.getContext(), - R.animator.appbar_elevation_on)); - } else { - ViewCompat.setElevation(mAppBar, getResources().getDimension(R.dimen.design_appbar_elevation)); - } + mAppBar.setStateListAnimator(AnimatorInflater.loadStateListAnimator(mAppBar.getContext(), + R.animator.appbar_elevation_on)); mDefaultToolbar.setVisibility(View.VISIBLE); mHomeSearchToolbar.setVisibility(View.GONE); ThemeUtils.colorStatusBar(this); diff --git a/src/main/java/com/owncloud/android/ui/adapter/PrintAdapter.java b/src/main/java/com/owncloud/android/ui/adapter/PrintAdapter.java index 3fe87eb98a..0827037358 100644 --- a/src/main/java/com/owncloud/android/ui/adapter/PrintAdapter.java +++ b/src/main/java/com/owncloud/android/ui/adapter/PrintAdapter.java @@ -21,7 +21,6 @@ package com.owncloud.android.ui.adapter; -import android.os.Build; import android.os.Bundle; import android.os.CancellationSignal; import android.os.ParcelFileDescriptor; @@ -40,9 +39,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.Objects; -import androidx.annotation.RequiresApi; - -@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public class PrintAdapter extends PrintDocumentAdapter { private static final String TAG = PrintAdapter.class.getSimpleName(); private static final String PDF_NAME = "finalPrint.pdf"; diff --git a/src/main/java/com/owncloud/android/ui/asynctasks/PrintAsyncTask.java b/src/main/java/com/owncloud/android/ui/asynctasks/PrintAsyncTask.java index ab491c7e58..b3ef92fbe1 100644 --- a/src/main/java/com/owncloud/android/ui/asynctasks/PrintAsyncTask.java +++ b/src/main/java/com/owncloud/android/ui/asynctasks/PrintAsyncTask.java @@ -22,7 +22,6 @@ package com.owncloud.android.ui.asynctasks; import android.os.AsyncTask; -import android.os.Build; import android.print.PrintAttributes; import android.print.PrintDocumentAdapter; import android.print.PrintManager; @@ -44,11 +43,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.lang.ref.WeakReference; -import androidx.annotation.RequiresApi; - import static android.content.Context.PRINT_SERVICE; -@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public class PrintAsyncTask extends AsyncTask { private static final String TAG = PrintAsyncTask.class.getSimpleName(); private static final String JOB_NAME = "Document"; diff --git a/src/main/java/com/owncloud/android/ui/fragment/OCFileListBottomSheetDialog.java b/src/main/java/com/owncloud/android/ui/fragment/OCFileListBottomSheetDialog.java index f5157748da..92bc52e41e 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/OCFileListBottomSheetDialog.java +++ b/src/main/java/com/owncloud/android/ui/fragment/OCFileListBottomSheetDialog.java @@ -21,7 +21,6 @@ package com.owncloud.android.ui.fragment; import android.content.Context; -import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -127,7 +126,6 @@ public class OCFileListBottomSheetDialog extends BottomSheetDialog { OCCapability capability = fileActivity.getCapabilities(); if (capability.getRichDocuments().isTrue() && capability.getRichDocumentsDirectEditing().isTrue() && - android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && capability.getRichDocumentsTemplatesAvailable().isTrue() && !file.isEncrypted()) { templates.setVisibility(View.VISIBLE); @@ -137,7 +135,6 @@ public class OCFileListBottomSheetDialog extends BottomSheetDialog { .getValue(user, ArbitraryDataProvider.DIRECT_EDITING); if (!json.isEmpty() && - android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !file.isEncrypted()) { DirectEditing directEditing = new Gson().fromJson(json, DirectEditing.class); @@ -174,8 +171,7 @@ public class OCFileListBottomSheetDialog extends BottomSheetDialog { } // create rich workspace - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && - FileMenuFilter.isEditorAvailable(getContext().getContentResolver(), + if (FileMenuFilter.isEditorAvailable(getContext().getContentResolver(), user, MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN) && file != null && !file.isEncrypted()) { diff --git a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index 1c599cc317..aa39c779e0 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -29,7 +29,6 @@ import android.content.Context; import android.content.Intent; import android.graphics.Color; import android.os.AsyncTask; -import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -1021,11 +1020,9 @@ public class OCFileListFragment extends ExtendedListFragment implements } else if (FileMenuFilter.isEditorAvailable(requireContext().getContentResolver(), accountManager.getUser(), file.getMimeType()) && - !file.isEncrypted() && - android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + !file.isEncrypted()) { mContainerActivity.getFileOperationsHelper().openFileWithTextEditor(file, getContext()); } else if (capability.getRichDocumentsMimeTypeList().contains(file.getMimeType()) && - android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && capability.getRichDocumentsDirectEditing().isTrue() && !file.isEncrypted()) { mContainerActivity.getFileOperationsHelper().openFileAsRichDocument(file, getContext()); } else { @@ -1091,22 +1088,15 @@ public class OCFileListFragment extends ExtendedListFragment implements } case R.id.action_edit: { // should not be necessary, as menu item is filtered, but better play safe - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - if (FileMenuFilter.isEditorAvailable(requireContext().getContentResolver(), - accountManager.getUser(), - singleFile.getMimeType())) { - mContainerActivity.getFileOperationsHelper().openFileWithTextEditor(singleFile, - getContext()); - } else { - mContainerActivity.getFileOperationsHelper().openFileAsRichDocument(singleFile, - getContext()); - } - - return true; + if (FileMenuFilter.isEditorAvailable(requireContext().getContentResolver(), + accountManager.getUser(), + singleFile.getMimeType())) { + mContainerActivity.getFileOperationsHelper().openFileWithTextEditor(singleFile, getContext()); } else { - DisplayUtils.showSnackMessage(getView(), "Not supported on older than Android 5"); - return false; + mContainerActivity.getFileOperationsHelper().openFileAsRichDocument(singleFile, getContext()); } + + return true; } case R.id.action_rename_file: { RenameFileDialogFragment dialog = RenameFileDialogFragment.newInstance(singleFile); diff --git a/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java b/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java index e2e24755b1..5de743a795 100755 --- a/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java +++ b/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java @@ -104,7 +104,6 @@ import java.util.regex.Pattern; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.annotation.RequiresApi; import androidx.core.content.FileProvider; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; @@ -288,14 +287,12 @@ public class FileOperationsHelper { if (optionalUser.isPresent() && FileMenuFilter.isEditorAvailable(fileActivity.getContentResolver(), optionalUser.get(), - file.getMimeType()) && - android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + file.getMimeType())) { openFileWithTextEditor(file, fileActivity); } else { Account account = fileActivity.getAccount(); OCCapability capability = fileActivity.getStorageManager().getCapability(account.name); if (capability.getRichDocumentsMimeTypeList().contains(file.getMimeType()) && - android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && capability.getRichDocumentsDirectEditing().isTrue()) { openFileAsRichDocument(file, fileActivity); return; @@ -360,7 +357,6 @@ public class FileOperationsHelper { } } - @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void openFileAsRichDocument(OCFile file, Context context) { Intent collaboraWebViewIntent = new Intent(context, RichDocumentsEditorWebView.class); collaboraWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TITLE, "Collabora"); @@ -369,7 +365,6 @@ public class FileOperationsHelper { context.startActivity(collaboraWebViewIntent); } - @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void openFileWithTextEditor(OCFile file, Context context) { Intent textEditorIntent = new Intent(context, TextEditorWebView.class); textEditorIntent.putExtra(ExternalSiteWebView.EXTRA_TITLE, "Text"); diff --git a/src/main/java/com/owncloud/android/ui/preview/PreviewTextFileFragment.java b/src/main/java/com/owncloud/android/ui/preview/PreviewTextFileFragment.java index f7ecc12ab6..9ac76dfc44 100644 --- a/src/main/java/com/owncloud/android/ui/preview/PreviewTextFileFragment.java +++ b/src/main/java/com/owncloud/android/ui/preview/PreviewTextFileFragment.java @@ -24,7 +24,6 @@ package com.owncloud.android.ui.preview; import android.accounts.Account; import android.os.AsyncTask; -import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.view.Menu; @@ -289,10 +288,6 @@ public class PreviewTextFileFragment extends PreviewTextFragment { menu.findItem(R.id.action_unset_favorite) ); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - FileMenuFilter.hideMenuItem(menu.findItem(R.id.action_edit)); - } - if (getFile().isSharedWithMe() && !getFile().canReshare()) { FileMenuFilter.hideMenuItem(menu.findItem(R.id.action_send_share_file)); } @@ -331,11 +326,8 @@ public class PreviewTextFileFragment extends PreviewTextFragment { } case R.id.action_edit: - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - containerActivity.getFileOperationsHelper().openFileWithTextEditor(getFile(), getContext()); - return true; - } - return false; + containerActivity.getFileOperationsHelper().openFileWithTextEditor(getFile(), getContext()); + return true; default: return super.onOptionsItemSelected(item); diff --git a/src/main/java/com/owncloud/android/ui/preview/PreviewTextStringFragment.java b/src/main/java/com/owncloud/android/ui/preview/PreviewTextStringFragment.java index 02a0897c58..19f4a4b37e 100644 --- a/src/main/java/com/owncloud/android/ui/preview/PreviewTextStringFragment.java +++ b/src/main/java/com/owncloud/android/ui/preview/PreviewTextStringFragment.java @@ -104,15 +104,10 @@ public class PreviewTextStringFragment extends PreviewTextFragment { } FloatingActionButton fabMain = requireActivity().findViewById(R.id.fab_main); - - if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - fabMain.setVisibility(View.GONE); - } else { - fabMain.setVisibility(View.VISIBLE); - fabMain.setEnabled(true); - fabMain.setOnClickListener(v -> edit()); - ThemeUtils.colorFloatingActionButton(fabMain, R.drawable.ic_edit, requireContext()); - } + fabMain.setVisibility(View.VISIBLE); + fabMain.setEnabled(true); + fabMain.setOnClickListener(v -> edit()); + ThemeUtils.colorFloatingActionButton(fabMain, R.drawable.ic_edit, requireContext()); return view; } diff --git a/src/main/java/com/owncloud/android/utils/ThemeUtils.java b/src/main/java/com/owncloud/android/utils/ThemeUtils.java index 6ec05cdf17..dbdf52429e 100644 --- a/src/main/java/com/owncloud/android/utils/ThemeUtils.java +++ b/src/main/java/com/owncloud/android/utils/ThemeUtils.java @@ -122,7 +122,7 @@ public final class ThemeUtils { } } - public static int calculateDarkColor(int color, Context context){ + public static int calculateDarkColor(int color, Context context) { try { return adjustLightness(-0.2f, color, -1f); } catch (Exception e) { @@ -364,7 +364,7 @@ public final class ThemeUtils { } public static void setStatusBarColor(Activity activity, @ColorInt int color) { - if (activity != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (activity != null) { activity.getWindow().setStatusBarColor(color); } } @@ -450,11 +450,7 @@ public final class ThemeUtils { */ public static void colorProgressBar(ProgressBar progressBar, @ColorInt int color) { if (progressBar != null) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - progressBar.setProgressTintList(ColorStateList.valueOf(color)); - } else { - ThemeUtils.colorHorizontalProgressBar(progressBar, color); - } + progressBar.setProgressTintList(ColorStateList.valueOf(color)); } } @@ -491,7 +487,7 @@ public final class ThemeUtils { } /** - * Sets the color of the status bar to {@code color} on devices with OS version lollipop or higher. + * Sets the color of the status bar to {@code color}. * * @param fragmentActivity fragment activity * @param color the color @@ -499,7 +495,7 @@ public final class ThemeUtils { public static void colorStatusBar(Activity fragmentActivity, @ColorInt int color) { Window window = fragmentActivity.getWindow(); boolean isLightTheme = lightTheme(color); - if (window != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (window != null) { window.setStatusBarColor(color); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { View decor = window.getDecorView(); @@ -668,7 +664,8 @@ public final class ThemeUtils { /** * Will change a menu item text tint - * @param item the menu item object + * + * @param item the menu item object * @param color the wanted color (as resource or color) */ public static void tintMenuItemText(MenuItem item, int color) { diff --git a/src/main/java/org/nextcloud/providers/cursors/FileCursor.java b/src/main/java/org/nextcloud/providers/cursors/FileCursor.java index f69de09b47..c7b8e9d197 100644 --- a/src/main/java/org/nextcloud/providers/cursors/FileCursor.java +++ b/src/main/java/org/nextcloud/providers/cursors/FileCursor.java @@ -88,9 +88,7 @@ public class FileCursor extends MatrixCursor { flags = flags | Document.FLAG_DIR_SUPPORTS_CREATE; } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - flags = Document.FLAG_SUPPORTS_RENAME | flags; - } + flags = Document.FLAG_SUPPORTS_RENAME | flags; newRow().add(Document.COLUMN_DOCUMENT_ID, document.getDocumentId()) .add(Document.COLUMN_DISPLAY_NAME, file.getFileName()) diff --git a/src/main/java/org/nextcloud/providers/cursors/RootCursor.java b/src/main/java/org/nextcloud/providers/cursors/RootCursor.java index 86b6f868fc..8b7d29ae30 100644 --- a/src/main/java/org/nextcloud/providers/cursors/RootCursor.java +++ b/src/main/java/org/nextcloud/providers/cursors/RootCursor.java @@ -43,10 +43,11 @@ public class RootCursor extends MatrixCursor { public void addRoot(DocumentsStorageProvider.Document document, Context context) { Account account = document.getAccount(); - int rootFlags = Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_RECENTS | Root.FLAG_SUPPORTS_SEARCH; - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { - rootFlags = rootFlags | Root.FLAG_SUPPORTS_IS_CHILD; - } + int rootFlags = + Root.FLAG_SUPPORTS_CREATE | + Root.FLAG_SUPPORTS_RECENTS | + Root.FLAG_SUPPORTS_SEARCH | + Root.FLAG_SUPPORTS_IS_CHILD; newRow().add(Root.COLUMN_ROOT_ID, account.name) .add(Root.COLUMN_DOCUMENT_ID, document.getDocumentId())