diff options
3 files changed, 61 insertions, 72 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 7ccd237c1..4f165cc10 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 @@ -1,7 +1,10 @@ package it.niedermann.nextcloud.deck.ui; +import static it.niedermann.nextcloud.deck.ui.branding.BrandingUtil.getSecondaryForegroundColorDependingOnTheme; + import android.annotation.SuppressLint; import android.content.Intent; +import android.graphics.PorterDuff; import android.net.Uri; import android.view.View; @@ -15,7 +18,6 @@ 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; @@ -31,7 +33,7 @@ public class PushNotificationActivity extends AppCompatActivity { private ActivityPushNotificationBinding binding; private PushNotificationViewModel viewModel; private final ExecutorService executor = Executors.newSingleThreadExecutor(); - + private Intent intent; @Override protected void onResume() { @@ -39,7 +41,7 @@ public class PushNotificationActivity extends AppCompatActivity { Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this)); - final var intent = getIntent(); + intent = getIntent(); if (intent == null) { throw new IllegalArgumentException("Could not retrieve intent"); } @@ -50,15 +52,7 @@ public class PushNotificationActivity extends AppCompatActivity { setContentView(binding.getRoot()); setSupportActionBar(binding.toolbar); - viewModel.extractSubject(intent.getExtras()).ifPresent(binding.subject::setText); - - final var message = viewModel.extractMessage(intent.getExtras()); - if (message.isPresent()) { - binding.message.setText(message.get()); - binding.message.setVisibility(View.VISIBLE); - } - - binding.cancel.setOnClickListener((v) -> finish()); + binding.progress.setIndeterminate(true); viewModel.getAccount().observe(this, this::applyBrandToSubmitButton); executor.submit(() -> viewModel.getCardInformation(intent.getExtras(), new PushNotificationViewModel.PushNotificationCallback() { @Override @@ -80,23 +74,24 @@ public class PushNotificationActivity extends AppCompatActivity { } private void openCardOnSubmit(@NonNull Account account, long boardLocalId, long cardLocalId) { - binding.submit.setOnClickListener((v) -> { - DeckLog.info("Starting", EditActivity.class.getSimpleName(), "with [" + account + ", " + boardLocalId + ", " + cardLocalId + "]"); - startActivity(EditActivity.createEditCardIntent(this, account, boardLocalId, cardLocalId)); - finish(); - }); - binding.submit.setText(R.string.simple_open); - applyBrandToSubmitButton(account.getColor()); - binding.submit.setEnabled(true); - binding.progress.setVisibility(View.INVISIBLE); + DeckLog.info("Starting", EditActivity.class.getSimpleName(), "with [" + account + ", " + boardLocalId + ", " + cardLocalId + "]"); + startActivity(EditActivity.createEditCardIntent(this, account, boardLocalId, cardLocalId)); + finish(); } private void fallbackToBrowser(@NonNull Uri uri) { - DeckLog.warn("Falling back to browser as notification handler."); + DeckLog.warn("Falling back to browser as push notification handler:", uri); + binding.submit.setOnClickListener((v) -> startActivity(new Intent(Intent.ACTION_VIEW, uri))); - binding.submit.setText(R.string.open_in_browser); - binding.submit.setEnabled(true); - binding.progress.setVisibility(View.INVISIBLE); + + viewModel.extractSubject(intent.getExtras()).ifPresent(binding.subject::setText); + viewModel.extractMessage(intent.getExtras()).ifPresent(message -> { + binding.message.setText(message); + binding.message.setVisibility(View.VISIBLE); + }); + + binding.progressWrapper.setVisibility(View.GONE); + binding.browserFallback.setVisibility(View.VISIBLE); } private void displayError(Throwable throwable) { @@ -114,6 +109,8 @@ public class PushNotificationActivity extends AppCompatActivity { // TODO apply branding based on board color public void applyBrandToSubmitButton(@ColorInt int mainColor) { try { + binding.progress.getProgressDrawable().setColorFilter( + getSecondaryForegroundColorDependingOnTheme(this, mainColor), PorterDuff.Mode.SRC_IN); binding.submit.setBackgroundColor(mainColor); binding.submit.setTextColor(ColorUtil.INSTANCE.getForegroundColorForBackgroundColor(mainColor)); } catch (Throwable 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 1ab8ecc74..95b6bfcae 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 @@ -59,6 +59,7 @@ public class PushNotificationViewModel extends AndroidViewModel { .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()); diff --git a/app/src/main/res/layout/activity_push_notification.xml b/app/src/main/res/layout/activity_push_notification.xml index eb14f38d1..21d543db3 100644 --- a/app/src/main/res/layout/activity_push_notification.xml +++ b/app/src/main/res/layout/activity_push_notification.xml @@ -1,47 +1,59 @@ <?xml version="1.0" encoding="utf-8"?> -<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:orientation="vertical" tools:showIn="@layout/activity_push_notification"> - <LinearLayout - android:id="@+id/appBarLayout" + <com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="vertical"> + android:layout_height="wrap_content"> - <com.google.android.material.appbar.AppBarLayout + <androidx.appcompat.widget.Toolbar + android:id="@+id/toolbar" android:layout_width="match_parent" - android:layout_height="wrap_content"> + android:layout_height="?android:actionBarSize" + app:navigationIcon="@drawable/ic_arrow_back_white_24dp" + app:title="@string/app_name" /> + </com.google.android.material.appbar.AppBarLayout> - <androidx.appcompat.widget.Toolbar - android:id="@+id/toolbar" - android:layout_width="match_parent" - android:layout_height="?android:actionBarSize" - app:navigationIcon="@drawable/ic_arrow_back_white_24dp" - app:title="@string/app_name" /> - </com.google.android.material.appbar.AppBarLayout> + <LinearLayout + android:id="@+id/progressWrapper" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center" + android:orientation="vertical" + android:padding="@dimen/spacer_2x"> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginBottom="@dimen/spacer_2x" + android:text="@string/updating_card" + android:textAppearance="?attr/textAppearanceBody1" /> <ProgressBar android:id="@+id/progress" - style="@style/Widget.AppCompat.ProgressBar.Horizontal" + style="?android:attr/progressBarStyleHorizontal" + android:indeterminateTint="@color/defaultBrand" android:layout_width="match_parent" android:layout_height="wrap_content" android:indeterminate="true" /> </LinearLayout> <ScrollView + android:id="@+id/browserFallback" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_above="@+id/buttonBar" - android:layout_below="@id/appBarLayout" + 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 @@ -60,35 +72,14 @@ tools:maxLength="200" tools:text="@tools:sample/lorem/random" tools:visibility="visible" /> + + <com.google.android.material.button.MaterialButton + android:id="@+id/submit" + style="@style/Widget.MaterialComponents.Button" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="@dimen/spacer_2x" + android:text="@string/open_in_browser" /> </LinearLayout> </ScrollView> - - <LinearLayout - android:id="@+id/buttonBar" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_alignParentBottom="true" - android:orientation="horizontal" - android:padding="@dimen/spacer_2x" - android:weightSum="1.0"> - - <com.google.android.material.button.MaterialButton - android:id="@+id/cancel" - style="@style/Widget.MaterialComponents.Button.TextButton" - android:layout_width="0dp" - android:layout_height="wrap_content" - android:layout_marginEnd="@dimen/spacer_1x" - android:layout_weight=".5" - android:text="@string/simple_close" /> - - <com.google.android.material.button.MaterialButton - android:id="@+id/submit" - style="@style/Widget.MaterialComponents.Button" - android:layout_width="0dp" - android:layout_height="wrap_content" - android:layout_marginStart="@dimen/spacer_1x" - android:layout_weight=".5" - android:enabled="false" - android:text="@string/updating_card" /> - </LinearLayout> -</RelativeLayout>
\ No newline at end of file +</LinearLayout>
\ No newline at end of file |