diff options
author | Stefan Niedermann <info@niedermann.it> | 2021-03-28 23:31:42 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2021-03-28 23:31:42 +0300 |
commit | 5be64e67e159752acd75585956185c41d788d13c (patch) | |
tree | a31406eba93a2a73d3588547fa5b832bbd73620f /app | |
parent | 2c78161918da4b3248d55441906df470f3cc9c41 (diff) |
Avoid shortly visible unsupported-version-hint
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/DataPropagationHelper.java | 48 | ||||
-rw-r--r-- | app/src/main/res/layout/activity_main.xml | 4 |
2 files changed, 25 insertions, 27 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/DataPropagationHelper.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/DataPropagationHelper.java index fa5483b26..46f6d52d6 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/DataPropagationHelper.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/DataPropagationHelper.java @@ -1,5 +1,10 @@ package it.niedermann.nextcloud.deck.persistence.sync.helpers; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import java.util.function.BiConsumer; + import it.niedermann.nextcloud.deck.api.IResponseCallback; import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.model.enums.DBStatus; @@ -9,19 +14,21 @@ import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.DataBaseAdapter import it.niedermann.nextcloud.deck.persistence.sync.helpers.providers.AbstractSyncDataProvider; public class DataPropagationHelper { - private ServerAdapter serverAdapter; - private DataBaseAdapter dataBaseAdapter; + @NonNull + private final ServerAdapter serverAdapter; + @NonNull + private final DataBaseAdapter dataBaseAdapter; - public DataPropagationHelper(ServerAdapter serverAdapter, DataBaseAdapter dataBaseAdapter) { + public DataPropagationHelper(@NonNull ServerAdapter serverAdapter, @NonNull DataBaseAdapter dataBaseAdapter) { this.serverAdapter = serverAdapter; this.dataBaseAdapter = dataBaseAdapter; } - - public <T extends IRemoteEntity> void createEntity(final AbstractSyncDataProvider<T> provider, T entity, IResponseCallback<T> callback){ + public <T extends IRemoteEntity> void createEntity(@NonNull final AbstractSyncDataProvider<T> provider, @NonNull T entity, IResponseCallback<T> callback){ createEntity(provider, entity, callback, null); } - public <T extends IRemoteEntity> void createEntity(final AbstractSyncDataProvider<T> provider, T entity, IResponseCallback<T> callback, OnResponseAction<T> actionOnResponse){ + + public <T extends IRemoteEntity> void createEntity(@NonNull final AbstractSyncDataProvider<T> provider, @NonNull T entity, IResponseCallback<T> callback, @Nullable BiConsumer<T, T> actionOnResponse){ final long accountId = callback.getAccount().getId(); entity.setStatus(DBStatus.LOCAL_EDITED.getId()); long newID; @@ -32,8 +39,7 @@ public class DataPropagationHelper { return; } entity.setLocalId(newID); - boolean connected = serverAdapter.hasInternetConnection(); - if (connected) { + if (serverAdapter.hasInternetConnection()) { try { provider.createOnServer(serverAdapter, dataBaseAdapter, accountId, new IResponseCallback<T>(callback.getAccount()) { @Override @@ -42,7 +48,7 @@ public class DataPropagationHelper { response.setAccountId(accountId); response.setLocalId(newID); if (actionOnResponse != null) { - actionOnResponse.onResponse(entity, response); + actionOnResponse.accept(entity, response); } response.setStatus(DBStatus.UP_TO_DATE.getId()); provider.updateInDB(dataBaseAdapter, accountId, response, false); @@ -64,7 +70,7 @@ public class DataPropagationHelper { } } - public <T extends IRemoteEntity> void updateEntity(final AbstractSyncDataProvider<T> provider, T entity, IResponseCallback<T> callback){ + public <T extends IRemoteEntity> void updateEntity(@NonNull final AbstractSyncDataProvider<T> provider, @NonNull T entity, @NonNull IResponseCallback<T> callback){ final long accountId = callback.getAccount().getId(); entity.setStatus(DBStatus.LOCAL_EDITED.getId()); try { @@ -73,8 +79,7 @@ public class DataPropagationHelper { callback.onError(t); return; } - boolean connected = serverAdapter.hasInternetConnection(); - if (entity.getId() != null && connected) { + if (entity.getId() != null && serverAdapter.hasInternetConnection()) { try { provider.updateOnServer(serverAdapter, dataBaseAdapter, accountId, new IResponseCallback<T>(new Account(accountId)) { @Override @@ -89,9 +94,7 @@ public class DataPropagationHelper { @Override public void onError(Throwable throwable) { super.onError(throwable); - new Thread(() -> { - callback.onError(throwable); - }).start(); + new Thread(() -> callback.onError(throwable)).start(); } }, entity); } catch (Throwable t) { @@ -101,11 +104,11 @@ public class DataPropagationHelper { callback.onResponse(entity); } } - public <T extends IRemoteEntity> void deleteEntity(final AbstractSyncDataProvider<T> provider, T entity, IResponseCallback<Void> callback){ + + public <T extends IRemoteEntity> void deleteEntity(@NonNull final AbstractSyncDataProvider<T> provider, @NonNull T entity, @NonNull IResponseCallback<Void> callback){ final long accountId = callback.getAccount().getId(); provider.deleteInDB(dataBaseAdapter, accountId, entity); - boolean connected = serverAdapter.hasInternetConnection(); - if (entity.getId() != null && connected) { + if (entity.getId() != null && serverAdapter.hasInternetConnection()) { try { provider.deleteOnServer(serverAdapter, accountId, new IResponseCallback<Void>(new Account(accountId)) { @Override @@ -119,21 +122,14 @@ public class DataPropagationHelper { @Override public void onError(Throwable throwable) { super.onError(throwable); - new Thread(() -> { - callback.onError(throwable); - }).start(); + new Thread(() -> callback.onError(throwable)).start(); } }, entity, dataBaseAdapter); } catch (Throwable t) { callback.onError(t); } - } else { callback.onResponse(null); } } - - public interface OnResponseAction <T> { - void onResponse(T entity, T response); - } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ac3fba3f9..54a630beb 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -63,7 +63,9 @@ android:text="@string/info_box_version_not_supported" android:textColor="@android:color/white" android:textSize="14sp" - app:drawableStartCompat="@drawable/ic_warning_white_24dp" /> + android:visibility="gone" + app:drawableStartCompat="@drawable/ic_warning_white_24dp" + tools:visibility="visible" /> <it.niedermann.nextcloud.deck.ui.view.EmptyContentView android:id="@+id/empty_content_view_boards" |