diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-12-17 18:29:42 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-12-17 18:29:42 +0300 |
commit | 31d87729ece6c431ee104c3dfb5650a6cbe09bb8 (patch) | |
tree | 72234dcdea84b130977bc1ff389139b9fca4c73f /app/src/main | |
parent | cdccd97f47913dad61880116da90ff8885cb070b (diff) |
version bump to 1.13.41.13.4
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.java | 183 |
1 files changed, 95 insertions, 88 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 85e5f944a..2e3337948 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 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.ui.card.EditActivity; +import it.niedermann.nextcloud.deck.ui.exception.ExceptionDialogFragment; import it.niedermann.nextcloud.deck.ui.exception.ExceptionHandler; import it.niedermann.nextcloud.deck.util.ProjectUtil; @@ -40,8 +41,9 @@ public class PushNotificationActivity extends AppCompatActivity { super.onResume(); Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this)); + final Intent intent = getIntent(); - if (getIntent() == null) { + if (intent == null) { throw new IllegalArgumentException("Could not retrieve intent"); } @@ -51,108 +53,113 @@ public class PushNotificationActivity extends AppCompatActivity { setContentView(binding.getRoot()); setSupportActionBar(binding.toolbar); - binding.subject.setText(getIntent().getStringExtra(KEY_SUBJECT)); + binding.subject.setText(intent.getStringExtra(KEY_SUBJECT)); - final String message = getIntent().getStringExtra(KEY_MESSAGE); + final String message = intent.getStringExtra(KEY_MESSAGE); if (!TextUtils.isEmpty(message)) { binding.message.setText(message); binding.message.setVisibility(View.VISIBLE); } - final String link = getIntent().getStringExtra(KEY_LINK); + final String link = intent.getStringExtra(KEY_LINK); final long[] ids; try { ids = ProjectUtil.extractBoardIdAndCardIdFromUrl(link); - } catch (Throwable t) { - DeckLog.logError(t); - finish(); - return; - } - binding.cancel.setOnClickListener((v) -> finish()); - - final String cardRemoteIdString = getIntent().getStringExtra(KEY_CARD_REMOTE_ID); - final String accountString = getIntent().getStringExtra(KEY_ACCOUNT); - - DeckLog.verbose("cardRemoteIdString = " + cardRemoteIdString); - if (ids.length == 2) { - if (cardRemoteIdString != null) { - try { - final int cardRemoteId = Integer.parseInt(cardRemoteIdString); - observeOnce(viewModel.readAccount(accountString), this, (account -> { - if (account != null) { - viewModel.setAccount(account.getName()); - DeckLog.verbose("account: " + account); - observeOnce(viewModel.getBoardByRemoteId(account.getId(), ids[0]), PushNotificationActivity.this, (board -> { - DeckLog.verbose("BoardLocalId " + board); - if (board != null) { - observeOnce(viewModel.getCardByRemoteID(account.getId(), cardRemoteId), PushNotificationActivity.this, (card -> { - DeckLog.verbose("Card: " + card); - if (card != null) { - viewModel.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); - - viewModel.synchronizeBoard(new IResponseCallback<Boolean>(account) { - @Override - public void onResponse(Boolean response) { - runOnUiThread(() -> { - observeOnce(viewModel.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); + binding.cancel.setOnClickListener((v) -> finish()); + + final String cardRemoteIdString = intent.getStringExtra(KEY_CARD_REMOTE_ID); + final String accountString = intent.getStringExtra(KEY_ACCOUNT); + + DeckLog.verbose("cardRemoteIdString = " + cardRemoteIdString); + if (ids.length == 2) { + if (cardRemoteIdString != null) { + try { + final int cardRemoteId = Integer.parseInt(cardRemoteIdString); + observeOnce(viewModel.readAccount(accountString), this, (account -> { + if (account != null) { + viewModel.setAccount(account.getName()); + DeckLog.verbose("account: " + account); + observeOnce(viewModel.getBoardByRemoteId(account.getId(), ids[0]), PushNotificationActivity.this, (board -> { + DeckLog.verbose("BoardLocalId " + board); + if (board != null) { + observeOnce(viewModel.getCardByRemoteID(account.getId(), cardRemoteId), PushNotificationActivity.this, (card -> { + DeckLog.verbose("Card: " + card); + if (card != null) { + viewModel.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); + + viewModel.synchronizeBoard(new IResponseCallback<Boolean>(account) { + @Override + public void onResponse(Boolean response) { + runOnUiThread(() -> { + observeOnce(viewModel.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); } - } else { - DeckLog.warn("Link does not contain two IDs (expected one board id and one card id): " + link); - fallbackToBrowser(link); + } catch (Throwable t) { + final String params = "Error while receiving push notification:\n" + + KEY_SUBJECT + ": [" + intent.getStringExtra(KEY_SUBJECT) + "]\n" + + KEY_MESSAGE + ": [" + intent.getStringExtra(KEY_MESSAGE) + "]\n" + + KEY_LINK + ": [" + intent.getStringExtra(KEY_LINK) + "]\n" + + KEY_CARD_REMOTE_ID + ": [" + intent.getStringExtra(KEY_CARD_REMOTE_ID) + "]\n" + + KEY_ACCOUNT + ": [" + intent.getStringExtra(KEY_ACCOUNT) + "]"; + ExceptionDialogFragment.newInstance(new Exception(params, t), null).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName()); + DeckLog.logError(t); } } |