Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Niedermann <info@niedermann.it>2021-11-26 16:49:58 +0300
committerNiedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com>2021-11-29 17:28:10 +0300
commitae49c8f3777b0a58b65f23e9b2014130dfeae6e1 (patch)
tree59aaba0c777becb08bd526e62c47be0a616b41c0 /app/src/main
parent39be2d5049b6d65c764af45a7d969fb57ee466d5 (diff)
#1165 Fix onError callback in PushNotificationActivity
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationActivity.java16
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationViewModel.java228
-rw-r--r--app/src/main/res/layout/activity_push_notification.xml30
-rw-r--r--app/src/main/res/values/strings.xml3
4 files changed, 158 insertions, 119 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationActivity.java
index 4f165cc10..540575d1d 100644
--- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationActivity.java
+++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationActivity.java
@@ -18,6 +18,7 @@ import java.util.concurrent.Executors;
import it.niedermann.android.util.ColorUtil;
import it.niedermann.nextcloud.deck.DeckLog;
+import it.niedermann.nextcloud.deck.R;
import it.niedermann.nextcloud.deck.databinding.ActivityPushNotificationBinding;
import it.niedermann.nextcloud.deck.model.Account;
import it.niedermann.nextcloud.deck.ui.card.EditActivity;
@@ -75,6 +76,7 @@ public class PushNotificationActivity extends AppCompatActivity {
private void openCardOnSubmit(@NonNull Account account, long boardLocalId, long cardLocalId) {
DeckLog.info("Starting", EditActivity.class.getSimpleName(), "with [" + account + ", " + boardLocalId + ", " + cardLocalId + "]");
+
startActivity(EditActivity.createEditCardIntent(this, account, boardLocalId, cardLocalId));
finish();
}
@@ -92,11 +94,19 @@ public class PushNotificationActivity extends AppCompatActivity {
binding.progressWrapper.setVisibility(View.GONE);
binding.browserFallback.setVisibility(View.VISIBLE);
+ binding.errorWrapper.setVisibility(View.GONE);
}
private void displayError(Throwable throwable) {
- ExceptionDialogFragment.newInstance(throwable, null)
- .show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName());
+ DeckLog.error(throwable);
+
+ binding.errorExplanation.setText(getString(R.string.push_notification_link_empty, getString(R.string.push_notification_link_empty_link)));
+ binding.showError.setOnClickListener((v) -> ExceptionDialogFragment.newInstance(throwable, null)
+ .show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName()));
+
+ binding.progressWrapper.setVisibility(View.GONE);
+ binding.browserFallback.setVisibility(View.GONE);
+ binding.errorWrapper.setVisibility(View.VISIBLE);
}
@Override
@@ -113,6 +123,8 @@ public class PushNotificationActivity extends AppCompatActivity {
getSecondaryForegroundColorDependingOnTheme(this, mainColor), PorterDuff.Mode.SRC_IN);
binding.submit.setBackgroundColor(mainColor);
binding.submit.setTextColor(ColorUtil.INSTANCE.getForegroundColorForBackgroundColor(mainColor));
+ binding.showError.setBackgroundColor(mainColor);
+ binding.showError.setTextColor(ColorUtil.INSTANCE.getForegroundColorForBackgroundColor(mainColor));
} catch (Throwable t) {
DeckLog.logError(t);
}
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationViewModel.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationViewModel.java
index 95b6bfcae..f5beb0620 100644
--- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationViewModel.java
+++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationViewModel.java
@@ -3,11 +3,9 @@ package it.niedermann.nextcloud.deck.ui;
import static androidx.lifecycle.Transformations.distinctUntilChanged;
import static androidx.lifecycle.Transformations.map;
-import android.annotation.SuppressLint;
import android.app.Application;
import android.net.Uri;
import android.os.Bundle;
-import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -16,16 +14,12 @@ import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
-import com.nextcloud.android.sso.helper.SingleAccountHelper;
-
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Optional;
import it.niedermann.nextcloud.deck.DeckLog;
-import it.niedermann.nextcloud.deck.R;
import it.niedermann.nextcloud.deck.api.IResponseCallback;
-import it.niedermann.nextcloud.deck.api.ResponseCallback;
import it.niedermann.nextcloud.deck.model.Account;
import it.niedermann.nextcloud.deck.persistence.sync.SyncManager;
import it.niedermann.nextcloud.deck.util.ProjectUtil;
@@ -54,122 +48,122 @@ public class PushNotificationViewModel extends AndroidViewModel {
return;
}
- try {
+// try {
final long cardRemoteId = extractCardRemoteId(bundle)
.orElseThrow(() -> new IllegalArgumentException("Could not extract cardRemoteId"));
final var account = extractAccount(bundle)
.orElseThrow(() -> new IllegalArgumentException("Account not found"));
this.account.postValue(account);
-
- SingleAccountHelper.setCurrentAccount(getApplication(), account.getName());
- final var syncManager = new SyncManager(getApplication());
-
- final var card = syncManager.getCardByRemoteIDDirectly(account.getId(), cardRemoteId);
-
- if (card.isPresent()) {
- syncManager.synchronizeCard(new ResponseCallback<>(account) {
- @Override
- public void onResponse(Boolean response) {
- final var boardLocalId = extractBoardLocalId(syncManager, account.getId(), cardRemoteId);
- if (boardLocalId.isPresent()) {
- callback.onResponse(new CardInformation(account, boardLocalId.get(), card.get().getLocalId()));
- } else {
- DeckLog.wtf("Card with local ID", card.get().getLocalId(), "and remote ID", card.get().getId(), "is present, but could not find board for it.");
- publishErrorToCallback("Given localBoardId for cardRemoteId" + cardRemoteId + "is null.", null, callback, bundle);
- }
- }
-
- @Override
- public void onError(Throwable throwable) {
- super.onError(throwable);
- final var boardLocalId = extractBoardLocalId(syncManager, account.getId(), cardRemoteId);
- if (boardLocalId.isPresent()) {
- Toast.makeText(getApplication(), R.string.card_outdated, Toast.LENGTH_LONG).show();
- callback.onResponse(new CardInformation(account, boardLocalId.get(), card.get().getLocalId()));
- } else {
- DeckLog.wtf("Card with local ID", card.get().getLocalId(), "and remote ID", card.get().getId(), "is present, but could not find board for it.");
- publishErrorToCallback("Given localBoardId for cardRemoteId" + cardRemoteId + "is null.", null, callback, bundle);
- }
- }
- }, card.get());
- } else {
- final var boardLocalId = extractBoardLocalId(syncManager, account.getId(), cardRemoteId);
- if (boardLocalId.isPresent()) {
- DeckLog.info("Card is not yet available locally. Synchronize board with localId", boardLocalId);
- syncManager.synchronizeBoard(boardLocalId.get(), new ResponseCallback<>(account) {
- @Override
- public void onResponse(Boolean response) {
- final var card = syncManager.getCardByRemoteIDDirectly(account.getId(), cardRemoteId);
- if (card.isPresent()) {
- callback.onResponse(new CardInformation(account, boardLocalId.get(), card.get().getLocalId()));
- } else {
- publishErrorToCallback("Something went wrong while synchronizing the card" + cardRemoteId + " (cardRemoteId). Given fullCard is null.", null, callback, bundle);
- }
- }
-
- @SuppressLint("MissingSuperCall")
- @Override
- public void onError(Throwable throwable) {
- publishErrorToCallback("Something went wrong while synchronizing the board with localId" + boardLocalId, throwable, callback, bundle);
- }
- });
- } else {
- final var boardRemoteId = extractBoardRemoteId(bundle);
- if (boardRemoteId.isPresent()) {
- // TODO It should be enough to only fetch the board with the given boardRemoteId, not sure though whether it's worth the effort
- syncManager.synchronize(new ResponseCallback<>(account) {
- @Override
- public void onResponse(Boolean response) {
- final var card = syncManager.getCardByRemoteIDDirectly(account.getId(), cardRemoteId);
- if (card.isPresent()) {
- final var boardLocalId = extractBoardLocalId(syncManager, account.getId(), cardRemoteId);
- if (boardLocalId.isPresent()) {
- callback.onResponse(new CardInformation(account, boardLocalId.get(), card.get().getLocalId()));
- } else {
- DeckLog.wtf("Card with local ID", card.get().getLocalId(), "and remote ID", card.get().getId(), "is present, but could not find board for it.");
- publishErrorToCallback("Could not find board locally for card with remote ID" + cardRemoteId + "even after full synchronization", null, callback, bundle);
- }
- } else {
- publishErrorToCallback("Could not find card with remote ID" + cardRemoteId + "even after full synchronization", null, callback, bundle);
- }
- }
-
- @Override
- @SuppressLint("MissingSuperCall")
- public void onError(Throwable throwable) {
- publishErrorToCallback("Could not extract boardRemoteId", null, callback, bundle);
- }
- });
- } else {
- syncManager.synchronize(new ResponseCallback<>(account) {
- @Override
- public void onResponse(Boolean response) {
- final var card = syncManager.getCardByRemoteIDDirectly(account.getId(), cardRemoteId);
- if (card.isPresent()) {
- final var boardLocalId = extractBoardLocalId(syncManager, account.getId(), cardRemoteId);
- if (boardLocalId.isPresent()) {
- callback.onResponse(new CardInformation(account, boardLocalId.get(), card.get().getLocalId()));
- } else {
- DeckLog.wtf("Card with local ID", card.get().getLocalId(), "and remote ID", card.get().getId(), "is present, but could not find board for it.");
- publishErrorToCallback("Could not find board locally for card with remote ID" + cardRemoteId + "even after full synchronization", null, callback, bundle);
- }
- } else {
- publishErrorToCallback("Could not find card with remote ID" + cardRemoteId + "even after full synchronization", null, callback, bundle);
- }
- }
-
- @Override
- @SuppressLint("MissingSuperCall")
- public void onError(Throwable throwable) {
- publishErrorToCallback("Could not extract boardRemoteId", null, callback, bundle);
- }
- });
- }
- }
- }
- } catch (Throwable throwable) {
- publishErrorToCallback("", throwable, callback, bundle);
- }
+callback.onError(new Exception("BLAH"));
+// SingleAccountHelper.setCurrentAccount(getApplication(), account.getName());
+// final var syncManager = new SyncManager(getApplication());
+//
+// final var card = syncManager.getCardByRemoteIDDirectly(account.getId(), cardRemoteId);
+//
+// if (card.isPresent()) {
+// syncManager.synchronizeCard(new ResponseCallback<>(account) {
+// @Override
+// public void onResponse(Boolean response) {
+// final var boardLocalId = extractBoardLocalId(syncManager, account.getId(), cardRemoteId);
+// if (boardLocalId.isPresent()) {
+// callback.onResponse(new CardInformation(account, boardLocalId.get(), card.get().getLocalId()));
+// } else {
+// DeckLog.wtf("Card with local ID", card.get().getLocalId(), "and remote ID", card.get().getId(), "is present, but could not find board for it.");
+// publishErrorToCallback("Given localBoardId for cardRemoteId" + cardRemoteId + "is null.", null, callback, bundle);
+// }
+// }
+//
+// @Override
+// public void onError(Throwable throwable) {
+// super.onError(throwable);
+// final var boardLocalId = extractBoardLocalId(syncManager, account.getId(), cardRemoteId);
+// if (boardLocalId.isPresent()) {
+// Toast.makeText(getApplication(), R.string.card_outdated, Toast.LENGTH_LONG).show();
+// callback.onResponse(new CardInformation(account, boardLocalId.get(), card.get().getLocalId()));
+// } else {
+// DeckLog.wtf("Card with local ID", card.get().getLocalId(), "and remote ID", card.get().getId(), "is present, but could not find board for it.");
+// publishErrorToCallback("Given localBoardId for cardRemoteId" + cardRemoteId + "is null.", null, callback, bundle);
+// }
+// }
+// }, card.get());
+// } else {
+// final var boardLocalId = extractBoardLocalId(syncManager, account.getId(), cardRemoteId);
+// if (boardLocalId.isPresent()) {
+// DeckLog.info("Card is not yet available locally. Synchronize board with localId", boardLocalId);
+// syncManager.synchronizeBoard(boardLocalId.get(), new ResponseCallback<>(account) {
+// @Override
+// public void onResponse(Boolean response) {
+// final var card = syncManager.getCardByRemoteIDDirectly(account.getId(), cardRemoteId);
+// if (card.isPresent()) {
+// callback.onResponse(new CardInformation(account, boardLocalId.get(), card.get().getLocalId()));
+// } else {
+// publishErrorToCallback("Something went wrong while synchronizing the card" + cardRemoteId + " (cardRemoteId). Given fullCard is null.", null, callback, bundle);
+// }
+// }
+//
+// @SuppressLint("MissingSuperCall")
+// @Override
+// public void onError(Throwable throwable) {
+// publishErrorToCallback("Something went wrong while synchronizing the board with localId" + boardLocalId, throwable, callback, bundle);
+// }
+// });
+// } else {
+// final var boardRemoteId = extractBoardRemoteId(bundle);
+// if (boardRemoteId.isPresent()) {
+// // TODO It should be enough to only fetch the board with the given boardRemoteId, not sure though whether it's worth the effort
+// syncManager.synchronize(new ResponseCallback<>(account) {
+// @Override
+// public void onResponse(Boolean response) {
+// final var card = syncManager.getCardByRemoteIDDirectly(account.getId(), cardRemoteId);
+// if (card.isPresent()) {
+// final var boardLocalId = extractBoardLocalId(syncManager, account.getId(), cardRemoteId);
+// if (boardLocalId.isPresent()) {
+// callback.onResponse(new CardInformation(account, boardLocalId.get(), card.get().getLocalId()));
+// } else {
+// DeckLog.wtf("Card with local ID", card.get().getLocalId(), "and remote ID", card.get().getId(), "is present, but could not find board for it.");
+// publishErrorToCallback("Could not find board locally for card with remote ID" + cardRemoteId + "even after full synchronization", null, callback, bundle);
+// }
+// } else {
+// publishErrorToCallback("Could not find card with remote ID" + cardRemoteId + "even after full synchronization", null, callback, bundle);
+// }
+// }
+//
+// @Override
+// @SuppressLint("MissingSuperCall")
+// public void onError(Throwable throwable) {
+// publishErrorToCallback("Could not extract boardRemoteId", null, callback, bundle);
+// }
+// });
+// } else {
+// syncManager.synchronize(new ResponseCallback<>(account) {
+// @Override
+// public void onResponse(Boolean response) {
+// final var card = syncManager.getCardByRemoteIDDirectly(account.getId(), cardRemoteId);
+// if (card.isPresent()) {
+// final var boardLocalId = extractBoardLocalId(syncManager, account.getId(), cardRemoteId);
+// if (boardLocalId.isPresent()) {
+// callback.onResponse(new CardInformation(account, boardLocalId.get(), card.get().getLocalId()));
+// } else {
+// DeckLog.wtf("Card with local ID", card.get().getLocalId(), "and remote ID", card.get().getId(), "is present, but could not find board for it.");
+// publishErrorToCallback("Could not find board locally for card with remote ID" + cardRemoteId + "even after full synchronization", null, callback, bundle);
+// }
+// } else {
+// publishErrorToCallback("Could not find card with remote ID" + cardRemoteId + "even after full synchronization", null, callback, bundle);
+// }
+// }
+//
+// @Override
+// @SuppressLint("MissingSuperCall")
+// public void onError(Throwable throwable) {
+// publishErrorToCallback("Could not extract boardRemoteId", null, callback, bundle);
+// }
+// });
+// }
+// }
+// }
+// } catch (Throwable throwable) {
+// publishErrorToCallback("", throwable, callback, bundle);
+// }
}
/**
diff --git a/app/src/main/res/layout/activity_push_notification.xml b/app/src/main/res/layout/activity_push_notification.xml
index 21d543db3..6bda0323a 100644
--- a/app/src/main/res/layout/activity_push_notification.xml
+++ b/app/src/main/res/layout/activity_push_notification.xml
@@ -82,4 +82,34 @@
android:text="@string/open_in_browser" />
</LinearLayout>
</ScrollView>
+
+ <ScrollView
+ android:id="@+id/errorWrapper"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:visibility="gone"
+ android:padding="@dimen/spacer_2x">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/errorExplanation"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:autoLink="web"
+ tools:text="@string/push_notification_link_empty"/>
+
+ <com.google.android.material.button.MaterialButton
+ android:id="@+id/showError"
+ style="@style/Widget.MaterialComponents.Button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="@dimen/spacer_2x"
+ android:text="@string/show_error" />
+ </LinearLayout>
+ </ScrollView>
</LinearLayout> \ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index fbdab5862..d81859209 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -351,4 +351,7 @@
<string name="progress_import">Importing board %1$d of %2$d…</string>
<string name="progress_import_indeterminate">Importing boards…</string>
<string name="card_outdated">The content of this card might be outdated.</string>
+ <string name="show_error">Show error</string>
+ <string name="push_notification_link_empty">Due to a known issue in the Deck server app we are unfortunately not able to display this card. For more information see: %1$s</string>
+ <string name="push_notification_link_empty_link" translatable="false">https://github.com/nextcloud/deck/issues/3431</string>
</resources>