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:
authorNiedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com>2020-10-03 18:35:42 +0300
committerGitHub <noreply@github.com>2020-10-03 18:35:42 +0300
commit37d398fc200c5cea427c081e86d3f6d809233e16 (patch)
tree0e88364ab0676a6f61a8556b000cb0a77d66ff62 /app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationActivity.java
parent32a997114b12aecfaf81135841a168e3230e3983 (diff)
Push notification rework (#692)
* #569 Sync card on Push Notification Signed-off-by: Stefan Niedermann <info@niedermann.it> * implemented sync functions * #569 Sync card on Push Notification Signed-off-by: Stefan Niedermann <info@niedermann.it> * #569 Sync card on Push Notification Signed-off-by: Stefan Niedermann <info@niedermann.it> * #569 Sync card on Push Notification Signed-off-by: Stefan Niedermann <info@niedermann.it> * #569 Sync card on Push Notification Signed-off-by: Stefan Niedermann <info@niedermann.it> * #569 Sync card on Push Notification Signed-off-by: Stefan Niedermann <info@niedermann.it> * catch OfflineException Co-authored-by: desperateCoder <echotodevnull@gmail.com>
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationActivity.java')
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationActivity.java129
1 files changed, 88 insertions, 41 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 b0438c40b..702f96912 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
@@ -14,12 +14,14 @@ import com.nextcloud.android.sso.helper.SingleAccountHelper;
import it.niedermann.nextcloud.deck.DeckLog;
import it.niedermann.nextcloud.deck.R;
+import it.niedermann.nextcloud.deck.api.IResponseCallback;
import it.niedermann.nextcloud.deck.databinding.ActivityPushNotificationBinding;
import it.niedermann.nextcloud.deck.model.Account;
import it.niedermann.nextcloud.deck.persistence.sync.SyncManager;
import it.niedermann.nextcloud.deck.ui.card.EditActivity;
import it.niedermann.nextcloud.deck.ui.exception.ExceptionHandler;
import it.niedermann.nextcloud.deck.util.ColorUtil;
+import it.niedermann.nextcloud.deck.util.ProjectUtil;
import static android.graphics.Color.parseColor;
import static it.niedermann.nextcloud.deck.persistence.sync.adapters.db.util.LiveDataHelper.observeOnce;
@@ -58,6 +60,7 @@ public class PushNotificationActivity extends AppCompatActivity {
}
final String link = getIntent().getStringExtra(KEY_LINK);
+ long[] ids = ProjectUtil.extractBoardIdAndCardIdFromUrl(link);
binding.cancel.setOnClickListener((v) -> finish());
@@ -66,54 +69,98 @@ public class PushNotificationActivity extends AppCompatActivity {
final String accountString = getIntent().getStringExtra(KEY_ACCOUNT);
DeckLog.verbose("cardRemoteIdString = " + cardRemoteIdString);
- if (cardRemoteIdString != null) {
- try {
- final int cardRemoteId = Integer.parseInt(cardRemoteIdString);
- observeOnce(accountReadingSyncManager.readAccount(accountString), this, (account -> {
- if (account != null) {
- SingleAccountHelper.setCurrentAccount(this, account.getName());
- final SyncManager syncManager = new SyncManager(this);
- DeckLog.verbose("account: " + account);
- observeOnce(syncManager.getLocalBoardIdByCardRemoteIdAndAccount(cardRemoteId, account), PushNotificationActivity.this, (boardLocalId -> {
- DeckLog.verbose("BoardLocalId " + boardLocalId);
- if (boardLocalId != null) {
- observeOnce(syncManager.synchronizeCardByRemoteId(cardRemoteId, account), PushNotificationActivity.this, (fullCard -> {
- DeckLog.verbose("FullCard: " + fullCard);
- if (fullCard != null) {
- runOnUiThread(() -> {
- binding.submit.setOnClickListener((v) -> launchEditActivity(account, boardLocalId, fullCard.getLocalId()));
- binding.submit.setText(R.string.simple_open);
- applyBrandToSubmitButton(account);
- binding.submit.setEnabled(true);
- binding.progress.setVisibility(View.INVISIBLE);
- });
- } else {
- DeckLog.warn("Something went wrong while synchronizing the card " + cardRemoteId + " (cardRemoteId). Given fullCard is null.");
- applyBrandToSubmitButton(account);
- fallbackToBrowser(link);
- }
- }));
- } else {
- DeckLog.warn("Given localBoardId for cardRemoteId " + cardRemoteId + " is null.");
- applyBrandToSubmitButton(account);
- fallbackToBrowser(link);
- }
- }));
- } else {
- DeckLog.warn("Given account for " + accountString + " is null.");
- fallbackToBrowser(link);
- }
- }));
- } catch (NumberFormatException e) {
- DeckLog.logError(e);
+ if (ids.length == 2) {
+ if (cardRemoteIdString != null) {
+ try {
+ final int cardRemoteId = Integer.parseInt(cardRemoteIdString);
+ observeOnce(accountReadingSyncManager.readAccount(accountString), this, (account -> {
+ if (account != null) {
+ SingleAccountHelper.setCurrentAccount(this, account.getName());
+ final SyncManager syncManager = new SyncManager(this);
+ DeckLog.verbose("account: " + account);
+ observeOnce(syncManager.getBoardByRemoteId(account.getId(), ids[0]), PushNotificationActivity.this, (board -> {
+ DeckLog.verbose("BoardLocalId " + board);
+ if (board != null) {
+ observeOnce(syncManager.getCardByRemoteID(account.getId(), cardRemoteId), PushNotificationActivity.this, (card -> {
+ DeckLog.verbose("Card: " + card);
+ if (card != null) {
+ syncManager.synchronizeCard(new IResponseCallback<Boolean>(account) {
+ @Override
+ public void onResponse(Boolean response) {
+ openCardOnSubmit(account, board.getLocalId(), card.getLocalId());
+ }
+
+ @Override
+ public void onError(Throwable throwable) {
+ super.onError(throwable);
+ openCardOnSubmit(account, board.getLocalId(), card.getLocalId());
+ }
+ }, card);
+ } else {
+ DeckLog.info("Card is not yet available locally. Synchronize board with localId " + board);
+
+ syncManager.synchronizeBoard(new IResponseCallback<Boolean>(account) {
+ @Override
+ public void onResponse(Boolean response) {
+ runOnUiThread(() -> {
+ observeOnce(syncManager.getCardByRemoteID(account.getId(), cardRemoteId), PushNotificationActivity.this, (card -> {
+ DeckLog.verbose("Card: " + card);
+ if (card != null) {
+ openCardOnSubmit(account, board.getLocalId(), card.getLocalId());
+ } else {
+ DeckLog.warn("Something went wrong while synchronizing the card " + cardRemoteId + " (cardRemoteId). Given fullCard is null.");
+ applyBrandToSubmitButton(account);
+ fallbackToBrowser(link);
+ }
+ }));
+ });
+ }
+
+ @Override
+ public void onError(Throwable throwable) {
+ super.onError(throwable);
+ DeckLog.warn("Something went wrong while synchronizing the board with localId " + board + ".");
+ applyBrandToSubmitButton(account);
+ fallbackToBrowser(link);
+ }
+ }, board.getLocalId());
+ }
+ }));
+ } else {
+ DeckLog.warn("Given localBoardId for cardRemoteId " + cardRemoteId + " is null.");
+ applyBrandToSubmitButton(account);
+ fallbackToBrowser(link);
+ }
+ }));
+ } else {
+ DeckLog.warn("Given account for " + accountString + " is null.");
+ fallbackToBrowser(link);
+ }
+ }));
+ } catch (NumberFormatException e) {
+ DeckLog.logError(e);
+ fallbackToBrowser(link);
+ }
+ } else {
+ DeckLog.warn(KEY_CARD_REMOTE_ID + " is null.");
fallbackToBrowser(link);
}
} else {
- DeckLog.warn(KEY_CARD_REMOTE_ID + " is null.");
+ DeckLog.warn("Link does not contain two IDs (expected one board id and one card id): " + link);
fallbackToBrowser(link);
}
}
+ private void openCardOnSubmit(@NonNull Account account, long boardLocalId, long cardlocalId) {
+ runOnUiThread(() -> {
+ binding.submit.setOnClickListener((v) -> launchEditActivity(account, boardLocalId, cardlocalId));
+ binding.submit.setText(R.string.simple_open);
+ applyBrandToSubmitButton(account);
+ binding.submit.setEnabled(true);
+ binding.progress.setVisibility(View.INVISIBLE);
+ });
+ }
+
/**
* If anything goes wrong and we cannot open the card directly, we fall back to open the given link in the webbrowser
*/