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>2020-05-09 16:49:43 +0300
committerNiedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com>2020-05-09 17:19:41 +0300
commitf67438fb7749b6f724ecde1353d4b339fce66e40 (patch)
tree114e082d6a4ceec5b1e3ab685cc880ae517d0519 /app/src/main/java/it/niedermann/nextcloud/deck/ui
parent8939f70076952be8240e377e86d45454a456b49c (diff)
Use BrandedSnackbar for centralizing branding stuff
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/ui')
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java15
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/ui/board/accesscontrol/AccessControlDialogFragment.java6
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedSnackbar.java33
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentsFragment.java5
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/ui/card/details/CardDetailsFragment.java7
5 files changed, 48 insertions, 18 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java
index d878d9b77..ad4c02470 100644
--- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java
+++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java
@@ -79,6 +79,7 @@ import it.niedermann.nextcloud.deck.ui.board.EditBoardDialogFragment;
import it.niedermann.nextcloud.deck.ui.board.EditBoardListener;
import it.niedermann.nextcloud.deck.ui.branding.BrandedActivity;
import it.niedermann.nextcloud.deck.ui.branding.BrandedAlertDialogBuilder;
+import it.niedermann.nextcloud.deck.ui.branding.BrandedSnackbar;
import it.niedermann.nextcloud.deck.ui.card.CardAdapter;
import it.niedermann.nextcloud.deck.ui.card.EditActivity;
import it.niedermann.nextcloud.deck.ui.exception.ExceptionDialogFragment;
@@ -182,6 +183,7 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener
syncManager = new SyncManager(this);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+ BrandedSnackbar.make(binding.coordinatorLayout, "TEST", Snackbar.LENGTH_INDEFINITE).setAction("BLAH", (v) -> {}).show();
switchMap(syncManager.hasAccounts(), hasAccounts -> {
if (hasAccounts) {
@@ -386,8 +388,7 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener
if (createLiveData.hasError()) {
final Throwable error = createLiveData.getError();
assert error != null;
- Snackbar.make(binding.coordinatorLayout, Objects.requireNonNull(error.getLocalizedMessage()), Snackbar.LENGTH_LONG)
- .setActionTextColor(ColorUtil.isColorDark(Color.parseColor(mainViewModel.getCurrentAccount().getColor())) ? Color.WHITE : Color.parseColor(mainViewModel.getCurrentAccount().getColor()))
+ BrandedSnackbar.make(binding.coordinatorLayout, Objects.requireNonNull(error.getLocalizedMessage()), Snackbar.LENGTH_LONG)
.setAction(R.string.simple_more, v -> ExceptionDialogFragment.newInstance(error).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName()))
.show();
} else {
@@ -417,8 +418,7 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener
boardToCreate.setPermissionManage(true);
observeOnce(syncManager.createBoard(mainViewModel.getCurrentAccount().getId(), boardToCreate), this, createdBoard -> {
if (createdBoard == null) {
- Snackbar.make(binding.coordinatorLayout, "Open Deck in web interface first!", Snackbar.LENGTH_LONG)
- .setActionTextColor(ColorUtil.isColorDark(Color.parseColor(mainViewModel.getCurrentAccount().getColor())) ? Color.WHITE : Color.parseColor(mainViewModel.getCurrentAccount().getColor()))
+ BrandedSnackbar.make(binding.coordinatorLayout, "Open Deck in web interface first!", Snackbar.LENGTH_LONG)
// TODO implement action!
// .setAction(R.string.simple_open, v -> ExceptionDialogFragment.newInstance(throwable).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName()))
.show();
@@ -811,7 +811,7 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener
syncManager = importSyncManager;
setCurrentAccount(account);
- final Snackbar importSnackbar = Snackbar.make(binding.coordinatorLayout, R.string.account_is_getting_imported, Snackbar.LENGTH_INDEFINITE);
+ final Snackbar importSnackbar = BrandedSnackbar.make(binding.coordinatorLayout, R.string.account_is_getting_imported, Snackbar.LENGTH_INDEFINITE);
importSnackbar.show();
importSyncManager.synchronize(new IResponseCallback<Boolean>(mainViewModel.getCurrentAccount()) {
@Override
@@ -874,7 +874,7 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener
final Throwable error = accountLiveData.getError();
if (error instanceof SQLiteConstraintException) {
DeckLog.warn("Account already added");
- Snackbar.make(binding.coordinatorLayout, accountAlreadyAdded, Snackbar.LENGTH_LONG).show();
+ BrandedSnackbar.make(binding.coordinatorLayout, accountAlreadyAdded, Snackbar.LENGTH_LONG).show();
} else {
ExceptionDialogFragment.newInstance(error).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName());
ExceptionDialogFragment.newInstance(error).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName());
@@ -981,9 +981,8 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener
*/
private void showSyncFailedSnackbar(@NonNull Throwable throwable) {
if (!(throwable instanceof NextcloudHttpRequestFailedException) || ((NextcloudHttpRequestFailedException) throwable).getStatusCode() != HttpURLConnection.HTTP_UNAVAILABLE) {
- runOnUiThread(() -> Snackbar.make(binding.coordinatorLayout, R.string.synchronization_failed, Snackbar.LENGTH_LONG)
+ runOnUiThread(() -> BrandedSnackbar.make(binding.coordinatorLayout, R.string.synchronization_failed, Snackbar.LENGTH_LONG)
.setAction(R.string.simple_more, v -> ExceptionDialogFragment.newInstance(throwable).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName()))
- .setActionTextColor(ColorUtil.isColorDark(Color.parseColor(mainViewModel.getCurrentAccount().getColor())) ? Color.WHITE : Color.parseColor(mainViewModel.getCurrentAccount().getColor()))
.show());
}
}
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/board/accesscontrol/AccessControlDialogFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/board/accesscontrol/AccessControlDialogFragment.java
index 8a9bf417e..af399ccf3 100644
--- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/board/accesscontrol/AccessControlDialogFragment.java
+++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/board/accesscontrol/AccessControlDialogFragment.java
@@ -2,7 +2,6 @@ package it.niedermann.nextcloud.deck.ui.board.accesscontrol;
import android.app.Dialog;
import android.content.Context;
-import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
@@ -29,9 +28,9 @@ import it.niedermann.nextcloud.deck.ui.MainViewModel;
import it.niedermann.nextcloud.deck.ui.branding.BrandedActivity;
import it.niedermann.nextcloud.deck.ui.branding.BrandedAlertDialogBuilder;
import it.niedermann.nextcloud.deck.ui.branding.BrandedDialogFragment;
+import it.niedermann.nextcloud.deck.ui.branding.BrandedSnackbar;
import it.niedermann.nextcloud.deck.ui.card.UserAutoCompleteAdapter;
import it.niedermann.nextcloud.deck.ui.exception.ExceptionDialogFragment;
-import it.niedermann.nextcloud.deck.util.ColorUtil;
import static it.niedermann.nextcloud.deck.persistence.sync.adapters.db.util.LiveDataHelper.observeOnce;
import static it.niedermann.nextcloud.deck.ui.board.accesscontrol.AccessControlAdapter.HEADER_ITEM_LOCAL_ID;
@@ -114,8 +113,7 @@ public class AccessControlDialogFragment extends BrandedDialogFragment implement
observeOnce(wrappedDeleteLiveData, this, (ignored) -> {
if (wrappedDeleteLiveData.hasError()) {
DeckLog.logError(wrappedDeleteLiveData.getError());
- Snackbar.make(requireView(), getString(R.string.error_revoking_ac, ac.getUser().getDisplayname()), Snackbar.LENGTH_LONG)
- .setActionTextColor(ColorUtil.isColorDark(Color.parseColor(viewModel.getCurrentAccount().getColor())) ? Color.WHITE : Color.parseColor(viewModel.getCurrentAccount().getColor()))
+ BrandedSnackbar.make(requireView(), getString(R.string.error_revoking_ac, ac.getUser().getDisplayname()), Snackbar.LENGTH_LONG)
.setAction(R.string.simple_more, v -> ExceptionDialogFragment.newInstance(wrappedDeleteLiveData.getError()).show(getChildFragmentManager(), ExceptionDialogFragment.class.getSimpleName()))
.show();
}
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedSnackbar.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedSnackbar.java
new file mode 100644
index 000000000..b28b00ac0
--- /dev/null
+++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedSnackbar.java
@@ -0,0 +1,33 @@
+package it.niedermann.nextcloud.deck.ui.branding;
+
+import android.graphics.Color;
+import android.view.View;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.StringRes;
+
+import com.google.android.material.snackbar.BaseTransientBottomBar;
+import com.google.android.material.snackbar.Snackbar;
+
+import it.niedermann.nextcloud.deck.Application;
+import it.niedermann.nextcloud.deck.util.ColorUtil;
+
+public class BrandedSnackbar {
+
+ @NonNull
+ public static Snackbar make(
+ @NonNull View view, @NonNull CharSequence text, @BaseTransientBottomBar.Duration int duration) {
+ final Snackbar snackbar = Snackbar.make(view, text, duration);
+ if (Application.isBrandingEnabled(view.getContext())) {
+ int color = Application.readBrandMainColor(view.getContext());
+ snackbar.setActionTextColor(ColorUtil.isColorDark(color) ? Color.WHITE : color);
+ }
+ return snackbar;
+ }
+
+ @NonNull
+ public static Snackbar make(@NonNull View view, @StringRes int resId, @BaseTransientBottomBar.Duration int duration) {
+ return make(view, view.getResources().getText(resId), duration);
+ }
+
+} \ No newline at end of file
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentsFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentsFragment.java
index 95089e4de..f9574367f 100644
--- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentsFragment.java
+++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentsFragment.java
@@ -35,6 +35,7 @@ import it.niedermann.nextcloud.deck.model.enums.DBStatus;
import it.niedermann.nextcloud.deck.persistence.sync.SyncManager;
import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.util.WrappedLiveData;
import it.niedermann.nextcloud.deck.ui.branding.BrandedFragment;
+import it.niedermann.nextcloud.deck.ui.branding.BrandedSnackbar;
import it.niedermann.nextcloud.deck.ui.card.EditCardViewModel;
import it.niedermann.nextcloud.deck.util.FileUtils;
@@ -165,7 +166,7 @@ public class CardAttachmentsFragment extends BrandedFragment implements Attachme
for (Attachment existingAttachment : viewModel.getFullCard().getAttachments()) {
final String existingPath = existingAttachment.getLocalPath();
if (existingPath != null && existingPath.equals(path)) {
- Snackbar.make(binding.coordinatorLayout, R.string.attachment_already_exists, Snackbar.LENGTH_LONG).show();
+ BrandedSnackbar.make(binding.coordinatorLayout, R.string.attachment_already_exists, Snackbar.LENGTH_LONG).show();
return;
}
}
@@ -189,7 +190,7 @@ public class CardAttachmentsFragment extends BrandedFragment implements Attachme
if (liveData.hasError()) {
viewModel.getFullCard().getAttachments().remove(a);
adapter.removeAttachment(a);
- Snackbar.make(binding.coordinatorLayout, R.string.attachment_already_exists, Snackbar.LENGTH_LONG).show();
+ BrandedSnackbar.make(binding.coordinatorLayout, R.string.attachment_already_exists, Snackbar.LENGTH_LONG).show();
} else {
viewModel.getFullCard().getAttachments().remove(a);
adapter.removeAttachment(a);
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/details/CardDetailsFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/details/CardDetailsFragment.java
index cce36a879..f9cbf7af9 100644
--- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/details/CardDetailsFragment.java
+++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/details/CardDetailsFragment.java
@@ -46,6 +46,7 @@ import it.niedermann.nextcloud.deck.persistence.sync.SyncManager;
import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.util.WrappedLiveData;
import it.niedermann.nextcloud.deck.ui.branding.BrandedDatePickerDialog;
import it.niedermann.nextcloud.deck.ui.branding.BrandedFragment;
+import it.niedermann.nextcloud.deck.ui.branding.BrandedSnackbar;
import it.niedermann.nextcloud.deck.ui.branding.BrandedTimePickerDialog;
import it.niedermann.nextcloud.deck.ui.card.EditCardViewModel;
import it.niedermann.nextcloud.deck.ui.card.LabelAutoCompleteAdapter;
@@ -261,8 +262,7 @@ public class CardDetailsFragment extends BrandedFragment implements OnDateSetLis
observeOnce(createLabelLiveData, CardDetailsFragment.this, createdLabel -> {
if (createLabelLiveData.hasError()) {
DeckLog.logError(createLabelLiveData.getError());
- Snackbar.make(requireView(), getString(R.string.error_create_label, newLabel.getTitle()), Snackbar.LENGTH_LONG)
- .setActionTextColor(ColorUtil.isColorDark(Color.parseColor(viewModel.getAccount().getColor())) ? Color.WHITE : Color.parseColor(viewModel.getAccount().getColor()))
+ BrandedSnackbar.make(requireView(), getString(R.string.error_create_label, newLabel.getTitle()), Snackbar.LENGTH_LONG)
.setAction(R.string.simple_more, v -> ExceptionDialogFragment.newInstance(createLabelLiveData.getError()).show(getChildFragmentManager(), ExceptionDialogFragment.class.getSimpleName())).show();
} else {
newLabel.setLocalId(createdLabel.getLocalId());
@@ -355,10 +355,9 @@ public class CardDetailsFragment extends BrandedFragment implements OnDateSetLis
viewModel.getFullCard().getAssignedUsers().remove(user);
binding.peopleList.removeView(avatar);
((UserAutoCompleteAdapter) binding.people.getAdapter()).include(user);
- Snackbar.make(
+ BrandedSnackbar.make(
requireView(), getString(R.string.unassigned_user, user.getDisplayname()),
Snackbar.LENGTH_LONG)
- .setActionTextColor(ColorUtil.isColorDark(Color.parseColor(viewModel.getAccount().getColor())) ? Color.WHITE : Color.parseColor(viewModel.getAccount().getColor()))
.setAction(R.string.simple_undo, v1 -> {
viewModel.getFullCard().getAssignedUsers().add(user);
((UserAutoCompleteAdapter) binding.people.getAdapter()).exclude(user);