Преглед на файлове

Replace Optional backport with actual java implementation available with sdk24+

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Andy Scherzinger преди 1 година
родител
ревизия
400496dc0c
променени са 28 файла, в които са добавени 30 реда и са изтрити 539 реда
  1. 1 1
      app/src/androidTest/java/com/owncloud/android/AbstractIT.java
  2. 1 1
      app/src/androidTest/java/com/owncloud/android/AbstractOnServerIT.java
  3. 1 1
      app/src/main/java/com/nextcloud/client/account/UserAccountManager.java
  4. 1 1
      app/src/main/java/com/nextcloud/client/account/UserAccountManagerImpl.java
  5. 2 2
      app/src/main/java/com/nextcloud/client/integrations/deck/DeckApi.kt
  6. 2 2
      app/src/main/java/com/nextcloud/client/integrations/deck/DeckApiImpl.kt
  7. 1 1
      app/src/main/java/com/nextcloud/client/jobs/AccountRemovalWork.kt
  8. 1 1
      app/src/main/java/com/nextcloud/client/jobs/download/FileDownloadWorker.kt
  9. 1 1
      app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadHelper.kt
  10. 1 1
      app/src/main/java/com/nextcloud/client/mixins/SessionMixin.kt
  11. 1 1
      app/src/main/java/com/nextcloud/client/widget/WidgetConfiguration.kt
  12. 1 1
      app/src/main/java/com/nextcloud/client/widget/WidgetRepository.kt
  13. 0 365
      app/src/main/java/com/nextcloud/java/util/Optional.java
  14. 0 121
      app/src/main/java/com/nextcloud/java/util/function/Predicate.java
  15. 0 26
      app/src/main/java/com/nextcloud/java/util/package-info.java
  16. 1 1
      app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java
  17. 1 1
      app/src/main/java/com/owncloud/android/services/OperationsService.java
  18. 2 1
      app/src/main/java/com/owncloud/android/ui/activity/BaseActivity.java
  19. 1 1
      app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java
  20. 2 1
      app/src/main/java/com/owncloud/android/ui/activity/EditorWebView.java
  21. 1 1
      app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java
  22. 1 1
      app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java
  23. 1 1
      app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.kt
  24. 2 1
      app/src/main/java/com/owncloud/android/ui/activity/ShareActivity.java
  25. 1 1
      app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java
  26. 1 1
      app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java
  27. 1 1
      app/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.java
  28. 1 1
      app/src/main/java/com/owncloud/android/utils/theme/CapabilityUtils.java

+ 1 - 1
app/src/androidTest/java/com/owncloud/android/AbstractIT.java

@@ -33,7 +33,6 @@ import com.nextcloud.client.network.ConnectivityService;
 import com.nextcloud.client.preferences.AppPreferencesImpl;
 import com.nextcloud.client.preferences.DarkMode;
 import com.nextcloud.common.NextcloudClient;
-import com.nextcloud.java.util.Optional;
 import com.nextcloud.test.GrantStoragePermissionRule;
 import com.nextcloud.test.RandomStringGenerator;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
@@ -70,6 +69,7 @@ import java.io.InputStream;
 import java.util.Collection;
 import java.util.Locale;
 import java.util.Objects;
+import java.util.Optional;
 
 import androidx.annotation.NonNull;
 import androidx.fragment.app.DialogFragment;

+ 1 - 1
app/src/androidTest/java/com/owncloud/android/AbstractOnServerIT.java

@@ -22,7 +22,6 @@ import com.nextcloud.client.device.PowerManagementService;
 import com.nextcloud.client.jobs.upload.FileUploadWorker;
 import com.nextcloud.client.network.Connectivity;
 import com.nextcloud.client.network.ConnectivityService;
-import com.nextcloud.java.util.Optional;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.UploadsStorageManager;
 import com.owncloud.android.db.OCUpload;
@@ -46,6 +45,7 @@ import org.junit.BeforeClass;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Optional;
 
 import androidx.annotation.NonNull;
 import androidx.test.platform.app.InstrumentationRegistry;

+ 1 - 1
app/src/main/java/com/nextcloud/client/account/UserAccountManager.java

@@ -11,7 +11,6 @@ import android.accounts.AccountManager;
 import android.app.Activity;
 import android.content.Intent;
 
-import com.nextcloud.java.util.Optional;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.common.OwnCloudAccount;
@@ -19,6 +18,7 @@ import com.owncloud.android.lib.common.accounts.AccountUtils;
 import com.owncloud.android.lib.resources.status.OwnCloudVersion;
 
 import java.util.List;
+import java.util.Optional;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;

+ 1 - 1
app/src/main/java/com/nextcloud/client/account/UserAccountManagerImpl.java

@@ -20,7 +20,6 @@ import android.preference.PreferenceManager;
 import android.text.TextUtils;
 
 import com.nextcloud.common.NextcloudClient;
-import com.nextcloud.java.util.Optional;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.authentication.AuthenticatorActivity;
@@ -40,6 +39,7 @@ import java.io.IOException;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Optional;
 
 import javax.inject.Inject;
 

+ 2 - 2
app/src/main/java/com/nextcloud/client/integrations/deck/DeckApi.kt

@@ -21,8 +21,8 @@ package com.nextcloud.client.integrations.deck
 
 import android.app.PendingIntent
 import com.nextcloud.client.account.User
-import com.nextcloud.java.util.Optional
 import com.owncloud.android.lib.resources.notifications.models.Notification
+import java.util.Optional
 
 /**
  * This API is for an integration with the [Nextcloud
@@ -41,5 +41,5 @@ interface DeckApi {
     fun createForwardToDeckActionIntent(
         notification: Notification,
         user: User
-    ): Optional<PendingIntent?>
+    ): Optional<PendingIntent>
 }

+ 2 - 2
app/src/main/java/com/nextcloud/client/integrations/deck/DeckApiImpl.kt

@@ -24,11 +24,11 @@ import android.content.Context
 import android.content.Intent
 import android.content.pm.PackageManager
 import com.nextcloud.client.account.User
-import com.nextcloud.java.util.Optional
 import com.owncloud.android.lib.resources.notifications.models.Notification
+import java.util.Optional
 
 class DeckApiImpl(private val context: Context, private val packageManager: PackageManager) : DeckApi {
-    override fun createForwardToDeckActionIntent(notification: Notification, user: User): Optional<PendingIntent?> {
+    override fun createForwardToDeckActionIntent(notification: Notification, user: User): Optional<PendingIntent> {
         if (APP_NAME.equals(notification.app, ignoreCase = true)) {
             val intent = Intent()
             for (appPackage in DECK_APP_PACKAGES) {

+ 1 - 1
app/src/main/java/com/nextcloud/client/jobs/AccountRemovalWork.kt

@@ -33,7 +33,6 @@ import com.nextcloud.client.account.UserAccountManager
 import com.nextcloud.client.core.Clock
 import com.nextcloud.client.preferences.AppPreferences
 import com.nextcloud.common.NextcloudClient
-import com.nextcloud.java.util.Optional
 import com.owncloud.android.MainApp
 import com.owncloud.android.R
 import com.owncloud.android.datamodel.ArbitraryDataProvider
@@ -55,6 +54,7 @@ import com.owncloud.android.ui.events.AccountRemovedEvent
 import com.owncloud.android.utils.EncryptionUtils
 import com.owncloud.android.utils.PushUtils
 import org.greenrobot.eventbus.EventBus
+import java.util.Optional
 
 /**
  * Removes account and all local files

+ 1 - 1
app/src/main/java/com/nextcloud/client/jobs/download/FileDownloadWorker.kt

@@ -19,7 +19,6 @@ import androidx.work.Worker
 import androidx.work.WorkerParameters
 import com.nextcloud.client.account.User
 import com.nextcloud.client.account.UserAccountManager
-import com.nextcloud.java.util.Optional
 import com.nextcloud.model.WorkerState
 import com.nextcloud.model.WorkerStateLiveData
 import com.nextcloud.utils.ForegroundServiceHelper
@@ -39,6 +38,7 @@ import com.owncloud.android.operations.DownloadType
 import com.owncloud.android.utils.theme.ViewThemeUtils
 import java.security.SecureRandom
 import java.util.AbstractList
+import java.util.Optional
 import java.util.Vector
 
 @Suppress("LongParameterList", "TooManyFunctions")

+ 1 - 1
app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadHelper.kt

@@ -16,7 +16,6 @@ import com.nextcloud.client.device.PowerManagementService
 import com.nextcloud.client.jobs.BackgroundJobManager
 import com.nextcloud.client.jobs.upload.FileUploadWorker.Companion.currentUploadFileOperation
 import com.nextcloud.client.network.ConnectivityService
-import com.nextcloud.java.util.Optional
 import com.owncloud.android.MainApp
 import com.owncloud.android.datamodel.OCFile
 import com.owncloud.android.datamodel.UploadsStorageManager
@@ -31,6 +30,7 @@ import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation
 import com.owncloud.android.lib.resources.files.model.RemoteFile
 import com.owncloud.android.utils.FileUtil
 import java.io.File
+import java.util.Optional
 import javax.inject.Inject
 
 @Suppress("TooManyFunctions")

+ 1 - 1
app/src/main/java/com/nextcloud/client/mixins/SessionMixin.kt

@@ -27,11 +27,11 @@ import android.content.Intent
 import android.os.Bundle
 import com.nextcloud.client.account.User
 import com.nextcloud.client.account.UserAccountManager
-import com.nextcloud.java.util.Optional
 import com.owncloud.android.datamodel.FileDataStorageManager
 import com.owncloud.android.lib.resources.status.OCCapability
 import com.owncloud.android.ui.activity.BaseActivity
 import com.owncloud.android.utils.theme.CapabilityUtils
+import java.util.Optional
 
 /**
  * Session mixin collects all account / user handling logic currently

+ 1 - 1
app/src/main/java/com/nextcloud/client/widget/WidgetConfiguration.kt

@@ -9,7 +9,7 @@ package com.nextcloud.client.widget
 
 import com.nextcloud.android.lib.resources.dashboard.DashboardButton
 import com.nextcloud.client.account.User
-import com.nextcloud.java.util.Optional
+import java.util.Optional
 
 data class WidgetConfiguration(
     val widgetId: String,

+ 1 - 1
app/src/main/java/com/nextcloud/client/widget/WidgetRepository.kt

@@ -13,7 +13,7 @@ import com.nextcloud.android.lib.resources.dashboard.DashboardButton
 import com.nextcloud.android.lib.resources.dashboard.DashboardWidget
 import com.nextcloud.client.account.User
 import com.nextcloud.client.account.UserAccountManager
-import com.nextcloud.java.util.Optional
+import java.util.Optional
 import javax.inject.Inject
 
 class WidgetRepository @Inject constructor(

+ 0 - 365
app/src/main/java/com/nextcloud/java/util/Optional.java

@@ -1,365 +0,0 @@
-/*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.nextcloud.java.util;
-
-import com.nextcloud.java.util.function.Predicate;
-
-import java.util.NoSuchElementException;
-
-import androidx.core.util.Consumer;
-import androidx.core.util.ObjectsCompat;
-import androidx.core.util.Supplier;
-import kotlin.jvm.functions.Function1;
-
-/**
- * This class is backported from Java 8 to be used on older Android API levels.
- * It uses available interfaces from Kotlin and androidx. It is semantically
- * identical with Java 8 API, allowing smooth migration when those APIs become
- * available.
- *
- * A container object which may or may not contain a non-null value.
- * If a value is present, {@code isPresent()} will return {@code true} and
- * {@code get()} will return the value.
- *
- * <p>Additional methods that depend on the presence or absence of a contained
- * value are provided, such as {@link #orElse(java.lang.Object) orElse()}
- * (return a default value if value not present) and
- * {@link #ifPresent(Consumer) ifPresent()} (execute a block
- * of code if the value is present).
- */
-public final class Optional<T> {
-    /**
-     * Common instance for {@code empty()}.
-     */
-    private static final Optional<?> EMPTY = new Optional<>();
-
-    /**
-     * If non-null, the value; if null, indicates no value is present
-     */
-    private final T value;
-
-    /**
-     * Constructs an empty instance.
-     *
-     * @implNote Generally only one empty instance, {@link Optional#EMPTY},
-     * should exist per VM.
-     */
-    private Optional() {
-        this.value = null;
-    }
-
-    /**
-     * Returns an empty {@code Optional} instance.  No value is present for this
-     * Optional.
-     *
-     * @apiNote Though it may be tempting to do so, avoid testing if an object
-     * is empty by comparing with {@code ==} against instances returned by
-     * {@code Option.empty()}. There is no guarantee that it is a singleton.
-     * Instead, use {@link #isPresent()}.
-     *
-     * @param <T> Type of the non-existent value
-     * @return an empty {@code Optional}
-     */
-    @SuppressWarnings("unchecked")
-    public static<T> Optional<T> empty() {
-        return (Optional<T>) EMPTY;
-    }
-
-    /**
-     * Constructs an instance with the value present.
-     *
-     * @param value the non-null value to be present
-     * @throws NullPointerException if value is null
-     */
-    private Optional(T value) {
-        if (value == null) {
-            throw new NullPointerException();
-        }
-        this.value = value;
-    }
-
-    /**
-     * Returns an {@code Optional} with the specified present non-null value.
-     *
-     * @param <T> the class of the value
-     * @param value the value to be present, which must be non-null
-     * @return an {@code Optional} with the value present
-     * @throws NullPointerException if value is null
-     */
-    public static <T> Optional<T> of(T value) {
-        return new Optional<>(value);
-    }
-
-    /**
-     * Returns an {@code Optional} describing the specified value, if non-null,
-     * otherwise returns an empty {@code Optional}.
-     *
-     * @param <T> the class of the value
-     * @param value the possibly-null value to describe
-     * @return an {@code Optional} with a present value if the specified value
-     * is non-null, otherwise an empty {@code Optional}
-     */
-    public static <T> Optional<T> ofNullable(T value) {
-        return value == null ? empty() : of(value);
-    }
-
-    /**
-     * If a value is present in this {@code Optional}, returns the value,
-     * otherwise throws {@code NoSuchElementException}.
-     *
-     * @return the non-null value held by this {@code Optional}
-     * @throws NoSuchElementException if there is no value present
-     *
-     * @see Optional#isPresent()
-     */
-    public T get() {
-        if (value == null) {
-            throw new NoSuchElementException("No value present");
-        }
-        return value;
-    }
-
-    /**
-     * Return {@code true} if there is a value present, otherwise {@code false}.
-     *
-     * @return {@code true} if there is a value present, otherwise {@code false}
-     */
-    public boolean isPresent() {
-        return value != null;
-    }
-
-    /**
-     * If a value is present, invoke the specified consumer with the value,
-     * otherwise do nothing.
-     *
-     * @param consumer block to be executed if a value is present
-     * @throws NullPointerException if value is present and {@code consumer} is
-     * null
-     */
-    public void ifPresent(Consumer<? super T> consumer) {
-        if (value != null) {
-            consumer.accept(value);
-        }
-    }
-
-    /**
-     * If a value is present, and the value matches the given predicate,
-     * return an {@code Optional} describing the value, otherwise return an
-     * empty {@code Optional}.
-     *
-     * @param predicate a predicate to apply to the value, if present
-     * @return an {@code Optional} describing the value of this {@code Optional}
-     * if a value is present and the value matches the given predicate,
-     * otherwise an empty {@code Optional}
-     * @throws NullPointerException if the predicate is null
-     */
-    public Optional<T> filter(Predicate<? super T> predicate) {
-        if (predicate == null) {
-            throw new NullPointerException();
-        }
-        if (!isPresent()) {
-            return this;
-        } else {
-            return predicate.test(value) ? this : empty();
-        }
-    }
-
-    /**
-     * If a value is present, apply the provided mapping function to it,
-     * and if the result is non-null, return an {@code Optional} describing the
-     * result.  Otherwise return an empty {@code Optional}.
-     *
-     * @apiNote This method supports post-processing on optional values, without
-     * the need to explicitly check for a return status.  For example, the
-     * following code traverses a stream of file names, selects one that has
-     * not yet been processed, and then opens that file, returning an
-     * {@code Optional<FileInputStream>}:
-     *
-     * <pre>{@code
-     *     Optional<FileInputStream> fis =
-     *         names.stream().filter(name -> !isProcessedYet(name))
-     *                       .findFirst()
-     *                       .map(name -> new FileInputStream(name));
-     * }</pre>
-     *
-     * Here, {@code findFirst} returns an {@code Optional<String>}, and then
-     * {@code map} returns an {@code Optional<FileInputStream>} for the desired
-     * file if one exists.
-     *
-     * @param <U> The type of the result of the mapping function
-     * @param mapper a mapping function to apply to the value, if present
-     * @return an {@code Optional} describing the result of applying a mapping
-     * function to the value of this {@code Optional}, if a value is present,
-     * otherwise an empty {@code Optional}
-     * @throws NullPointerException if the mapping function is null
-     */
-    public<U> Optional<U> map(Function1<? super T, ? extends U> mapper) {
-        if (mapper == null) {
-            throw new NullPointerException();
-        }
-        if (!isPresent()) {
-            return empty();
-        } else {
-            return Optional.ofNullable(mapper.invoke(value));
-        }
-    }
-
-    /**
-     * If a value is present, apply the provided {@code Optional}-bearing
-     * mapping function to it, return that result, otherwise return an empty
-     * {@code Optional}.  This method is similar to {@link #map(Function1)},
-     * but the provided mapper is one whose result is already an {@code Optional},
-     * and if invoked, {@code flatMap} does not wrap it with an additional
-     * {@code Optional}.
-     *
-     * @param <U> The type parameter to the {@code Optional} returned by
-     * @param mapper a mapping function to apply to the value, if present
-     *           the mapping function
-     * @return the result of applying an {@code Optional}-bearing mapping
-     * function to the value of this {@code Optional}, if a value is present,
-     * otherwise an empty {@code Optional}
-     * @throws NullPointerException if the mapping function is null or returns
-     * a null result
-     */
-    public<U> Optional<U> flatMap(Function1<? super T, Optional<U>> mapper) {
-        if(mapper == null) {
-            throw new NullPointerException();
-        }
-        if (!isPresent()) {
-            return empty();
-        } else {
-            Optional<U> u = mapper.invoke(value);
-            if (u == null) {
-                throw new NullPointerException();
-            }
-            return u;
-        }
-    }
-
-    /**
-     * Return the value if present, otherwise return {@code other}.
-     *
-     * @param other the value to be returned if there is no value present, may
-     * be null
-     * @return the value, if present, otherwise {@code other}
-     */
-    public T orElse(T other) {
-        return value != null ? value : other;
-    }
-
-    /**
-     * Return the value if present, otherwise invoke {@code other} and return
-     * the result of that invocation.
-     *
-     * @param other a {@code Supplier} whose result is returned if no value
-     * is present
-     * @return the value if present otherwise the result of {@code other.get()}
-     * @throws NullPointerException if value is not present and {@code other} is
-     * null
-     */
-    public T orElseGet(Supplier<? extends T> other) {
-        return value != null ? value : other.get();
-    }
-
-    /**
-     * Return the contained value, if present, otherwise throw an exception
-     * to be created by the provided supplier.
-     *
-     * @apiNote A method reference to the exception constructor with an empty
-     * argument list can be used as the supplier. For example,
-     * {@code IllegalStateException::new}
-     *
-     * @param <X> Type of the exception to be thrown
-     * @param exceptionSupplier The supplier which will return the exception to
-     * be thrown
-     * @return the present value
-     * @throws X if there is no value present
-     * @throws NullPointerException if no value is present and
-     * {@code exceptionSupplier} is null
-     */
-    public <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
-        if (value != null) {
-            return value;
-        } else {
-            throw exceptionSupplier.get();
-        }
-    }
-
-    /**
-     * Indicates whether some other object is "equal to" this Optional. The
-     * other object is considered equal if:
-     * <ul>
-     * <li>it is also an {@code Optional} and;
-     * <li>both instances have no value present or;
-     * <li>the present values are "equal to" each other via {@code equals()}.
-     * </ul>
-     *
-     * @param obj an object to be tested for equality
-     * @return {code true} if the other object is "equal to" this object
-     * otherwise {@code false}
-     */
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-
-        if (!(obj instanceof Optional)) {
-            return false;
-        }
-
-        Optional<?> other = (Optional<?>) obj;
-        return ObjectsCompat.equals(value, other.value);
-    }
-
-    /**
-     * Returns the hash code value of the present value, if any, or 0 (zero) if
-     * no value is present.
-     *
-     * @return hash code value of the present value or 0 if no value is present
-     */
-    @Override
-    public int hashCode() {
-        return ObjectsCompat.hashCode(value);
-    }
-
-    /**
-     * Returns a non-empty string representation of this Optional suitable for
-     * debugging. The exact presentation format is unspecified and may vary
-     * between implementations and versions.
-     *
-     * @implSpec If a value is present the result must include its string
-     * representation in the result. Empty and present Optionals must be
-     * unambiguously differentiable.
-     *
-     * @return the string representation of this instance
-     */
-    @Override
-    public String toString() {
-        return value != null
-            ? String.format("Optional[%s]", value)
-            : "Optional.empty";
-    }
-}

+ 0 - 121
app/src/main/java/com/nextcloud/java/util/function/Predicate.java

@@ -1,121 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.nextcloud.java.util.function;
-
-/**
- * This class is backported from Java 8 to be used on older Android API levels.
- *
- * Represents a predicate (boolean-valued function) of one argument.
- *
- * <p>This is a <a href="package-summary.html">functional interface</a>
- * whose functional method is {@link #test(Object)}.
- *
- * @param <T> the type of the input to the predicate
- */
-@FunctionalInterface
-public interface Predicate<T> {
-
-    /**
-     * Evaluates this predicate on the given argument.
-     *
-     * @param t the input argument
-     * @return {@code true} if the input argument matches the predicate,
-     * otherwise {@code false}
-     */
-    boolean test(T t);
-
-    /**
-     * Returns a composed predicate that represents a short-circuiting logical
-     * AND of this predicate and another.  When evaluating the composed
-     * predicate, if this predicate is {@code false}, then the {@code other}
-     * predicate is not evaluated.
-     *
-     * <p>Any exceptions thrown during evaluation of either predicate are relayed
-     * to the caller; if evaluation of this predicate throws an exception, the
-     * {@code other} predicate will not be evaluated.
-     *
-     * @param other a predicate that will be logically-ANDed with this
-     *              predicate
-     * @return a composed predicate that represents the short-circuiting logical
-     * AND of this predicate and the {@code other} predicate
-     * @throws NullPointerException if other is null
-     */
-    default Predicate<T> and(Predicate<? super T> other) {
-        if (other == null) {
-            throw new NullPointerException();
-        }
-        return (t) -> test(t) && other.test(t);
-    }
-
-    /**
-     * Returns a predicate that represents the logical negation of this
-     * predicate.
-     *
-     * @return a predicate that represents the logical negation of this
-     * predicate
-     */
-    default Predicate<T> negate() {
-        return (t) -> !test(t);
-    }
-
-    /**
-     * Returns a composed predicate that represents a short-circuiting logical
-     * OR of this predicate and another.  When evaluating the composed
-     * predicate, if this predicate is {@code true}, then the {@code other}
-     * predicate is not evaluated.
-     *
-     * <p>Any exceptions thrown during evaluation of either predicate are relayed
-     * to the caller; if evaluation of this predicate throws an exception, the
-     * {@code other} predicate will not be evaluated.
-     *
-     * @param other a predicate that will be logically-ORed with this
-     *              predicate
-     * @return a composed predicate that represents the short-circuiting logical
-     * OR of this predicate and the {@code other} predicate
-     * @throws NullPointerException if other is null
-     */
-    default Predicate<T> or(Predicate<? super T> other) {
-        if (other == null) {
-            throw new NullPointerException();
-        }
-        return (t) -> test(t) || other.test(t);
-    }
-
-    /**
-     * Returns a predicate that tests if two arguments are equal according
-     * to {@link androidx.core.util.ObjectsCompat#equals(Object, Object)}.
-     *
-     * @param <T> the type of arguments to the predicate
-     * @param targetRef the object reference with which to compare for equality,
-     *               which may be {@code null}
-     * @return a predicate that tests if two arguments are equal according
-     * to {@link androidx.core.util.ObjectsCompat#equals(Object, Object)}
-     */
-    static <T> Predicate<T> isEqual(Object targetRef) {
-        return (null == targetRef)
-            ? object -> object == null
-            : object -> targetRef.equals(object);
-    }
-}

+ 0 - 26
app/src/main/java/com/nextcloud/java/util/package-info.java

@@ -1,26 +0,0 @@
-/*
- * Nextcloud Android client application
- *
- * @author Chris Narkiewicz <hello@ezaquarii.com>
- * Copyright (C) 2019 Chris Narkiewicz
- * Copyright (C) 2019 Nextcloud GmbH
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-/**
- * This is a compatibility package providing some backported Java 8 classes
- * not available in some older Android runtimes.
- */
-package com.nextcloud.java.util;

+ 1 - 1
app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -85,7 +85,6 @@ import com.nextcloud.client.di.Injectable;
 import com.nextcloud.client.onboarding.FirstRunActivity;
 import com.nextcloud.client.onboarding.OnboardingService;
 import com.nextcloud.client.preferences.AppPreferences;
-import com.nextcloud.java.util.Optional;
 import com.nextcloud.utils.extensions.BundleExtensionsKt;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
@@ -135,6 +134,7 @@ import java.net.URLDecoder;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Optional;
 import java.util.concurrent.Executors;
 
 import javax.inject.Inject;

+ 1 - 1
app/src/main/java/com/owncloud/android/services/OperationsService.java

@@ -41,7 +41,6 @@ import android.util.Pair;
 
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.UserAccountManager;
-import com.nextcloud.java.util.Optional;
 import com.nextcloud.utils.extensions.IntentExtensionsKt;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
@@ -78,6 +77,7 @@ import com.owncloud.android.operations.UpdateShareViaLinkOperation;
 
 import java.io.IOException;
 import java.util.Iterator;
+import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.ConcurrentMap;

+ 2 - 1
app/src/main/java/com/owncloud/android/ui/activity/BaseActivity.java

@@ -17,12 +17,13 @@ import com.nextcloud.client.mixins.MixinRegistry;
 import com.nextcloud.client.mixins.SessionMixin;
 import com.nextcloud.client.preferences.AppPreferences;
 import com.nextcloud.client.preferences.DarkMode;
-import com.nextcloud.java.util.Optional;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.resources.status.OCCapability;
 
+import java.util.Optional;
+
 import javax.inject.Inject;
 
 import androidx.annotation.Nullable;

+ 1 - 1
app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -72,7 +72,6 @@ import com.nextcloud.client.network.ClientFactory;
 import com.nextcloud.client.onboarding.FirstRunActivity;
 import com.nextcloud.client.preferences.AppPreferences;
 import com.nextcloud.common.NextcloudClient;
-import com.nextcloud.java.util.Optional;
 import com.nextcloud.ui.ChooseAccountDialogFragment;
 import com.nextcloud.ui.composeActivity.ComposeActivity;
 import com.nextcloud.ui.composeActivity.ComposeDestination;
@@ -127,6 +126,7 @@ import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Optional;
 
 import javax.inject.Inject;
 

+ 2 - 1
app/src/main/java/com/owncloud/android/ui/activity/EditorWebView.java

@@ -40,7 +40,6 @@ import android.widget.Toast;
 
 import com.google.android.material.snackbar.Snackbar;
 import com.nextcloud.client.account.User;
-import com.nextcloud.java.util.Optional;
 import com.nextcloud.utils.extensions.IntentExtensionsKt;
 import com.owncloud.android.R;
 import com.owncloud.android.databinding.RichdocumentsWebviewBinding;
@@ -51,6 +50,8 @@ import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.MimeTypeUtil;
 import com.owncloud.android.utils.WebViewUtil;
 
+import java.util.Optional;
+
 import javax.inject.Inject;
 
 public abstract class EditorWebView extends ExternalSiteWebView {

+ 1 - 1
app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -74,7 +74,6 @@ import com.nextcloud.client.network.ClientFactory;
 import com.nextcloud.client.network.ConnectivityService;
 import com.nextcloud.client.preferences.AppPreferences;
 import com.nextcloud.client.utils.IntentUtil;
-import com.nextcloud.java.util.Optional;
 import com.nextcloud.model.WorkerState;
 import com.nextcloud.model.WorkerStateLiveData;
 import com.nextcloud.utils.extensions.BundleExtensionsKt;
@@ -150,6 +149,7 @@ import java.io.File;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.Optional;
 
 import javax.inject.Inject;
 

+ 1 - 1
app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java

@@ -41,7 +41,6 @@ import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.jobs.BackgroundJobManager;
 import com.nextcloud.client.jobs.download.FileDownloadHelper;
 import com.nextcloud.client.onboarding.FirstRunActivity;
-import com.nextcloud.java.util.Optional;
 import com.nextcloud.model.WorkerState;
 import com.nextcloud.model.WorkerStateLiveData;
 import com.nextcloud.utils.extensions.BundleExtensionsKt;
@@ -68,6 +67,7 @@ import org.greenrobot.eventbus.ThreadMode;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.Optional;
 import java.util.Set;
 
 import javax.inject.Inject;

+ 1 - 1
app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.kt

@@ -34,7 +34,6 @@ import com.nextcloud.client.account.User
 import com.nextcloud.client.account.UserAccountManager
 import com.nextcloud.client.jobs.NotificationWork
 import com.nextcloud.client.network.ClientFactory.CreationException
-import com.nextcloud.java.util.Optional
 import com.owncloud.android.R
 import com.owncloud.android.databinding.NotificationsLayoutBinding
 import com.owncloud.android.datamodel.ArbitraryDataProvider
@@ -49,6 +48,7 @@ import com.owncloud.android.ui.asynctasks.DeleteAllNotificationsTask
 import com.owncloud.android.ui.notifications.NotificationsContract
 import com.owncloud.android.utils.DisplayUtils
 import com.owncloud.android.utils.PushUtils
+import java.util.Optional
 
 /**
  * Activity displaying all server side stored notification items.

+ 2 - 1
app/src/main/java/com/owncloud/android/ui/activity/ShareActivity.java

@@ -27,7 +27,6 @@ import android.graphics.drawable.LayerDrawable;
 import android.os.Bundle;
 
 import com.nextcloud.client.account.User;
-import com.nextcloud.java.util.Optional;
 import com.owncloud.android.R;
 import com.owncloud.android.databinding.ShareActivityBinding;
 import com.owncloud.android.datamodel.OCFile;
@@ -45,6 +44,8 @@ import com.owncloud.android.ui.fragment.FileDetailsSharingProcessFragment;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.MimeTypeUtil;
 
+import java.util.Optional;
+
 import javax.inject.Inject;
 
 import androidx.fragment.app.Fragment;

+ 1 - 1
app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java

@@ -46,7 +46,6 @@ import com.nextcloud.client.device.PowerManagementService;
 import com.nextcloud.client.jobs.upload.FileUploadHelper;
 import com.nextcloud.client.jobs.upload.FileUploadWorker;
 import com.nextcloud.client.network.ConnectivityService;
-import com.nextcloud.java.util.Optional;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.databinding.UploadListHeaderBinding;
@@ -73,6 +72,7 @@ import com.owncloud.android.utils.theme.ViewThemeUtils;
 
 import java.io.File;
 import java.util.Arrays;
+import java.util.Optional;
 
 import androidx.annotation.NonNull;
 

+ 1 - 1
app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java

@@ -51,7 +51,6 @@ import com.nextcloud.client.jobs.BackgroundJobManager;
 import com.nextcloud.client.jobs.download.FileDownloadHelper;
 import com.nextcloud.client.jobs.upload.FileUploadHelper;
 import com.nextcloud.client.network.ConnectivityService;
-import com.nextcloud.java.util.Optional;
 import com.nextcloud.utils.EditorUtils;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
@@ -105,6 +104,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.Locale;
 import java.util.NoSuchElementException;
+import java.util.Optional;
 import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;

+ 1 - 1
app/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.java

@@ -38,7 +38,6 @@ import com.nextcloud.client.jobs.download.FileDownloadHelper;
 import com.nextcloud.client.jobs.download.FileDownloadWorker;
 import com.nextcloud.client.jobs.upload.FileUploadWorker;
 import com.nextcloud.client.preferences.AppPreferences;
-import com.nextcloud.java.util.Optional;
 import com.nextcloud.model.WorkerState;
 import com.nextcloud.model.WorkerStateLiveData;
 import com.nextcloud.utils.extensions.IntentExtensionsKt;
@@ -61,6 +60,7 @@ import com.owncloud.android.ui.fragment.OCFileListFragment;
 import com.owncloud.android.utils.MimeTypeUtil;
 
 import java.io.Serializable;
+import java.util.Optional;
 
 import javax.inject.Inject;
 

+ 1 - 1
app/src/main/java/com/owncloud/android/utils/theme/CapabilityUtils.java

@@ -28,7 +28,6 @@ import android.content.res.Resources;
 
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.UserAccountManagerImpl;
-import com.nextcloud.java.util.Optional;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.FileDataStorageManager;
@@ -37,6 +36,7 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Optional;
 
 public final class CapabilityUtils {
     private static final Map<String, OCCapability> cachedCapabilities = new HashMap<>();