Skip to content

Commit

Permalink
#498 open link to a deck board/card directly in the deck app
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-niedermann committed Jun 28, 2020
1 parent fe11417 commit 2b4bd7f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
32 changes: 32 additions & 0 deletions app/src/main/java/it/niedermann/nextcloud/deck/Application.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.niedermann.nextcloud.deck;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
Expand Down Expand Up @@ -98,10 +99,33 @@ public static void saveBrandColors(@NonNull Context context, @ColorInt int mainC
editor.apply();
}

@SuppressLint("ApplySharedPref")
public static void saveBrandColorsSynchronously(@NonNull Context context, @ColorInt int mainColor, @ColorInt int textColor) {
if (isBrandingEnabled(context) && context instanceof BrandedActivity) {
final BrandedActivity activity = (BrandedActivity) context;
activity.applyBrand(mainColor, textColor);
BrandedActivity.applyBrandToStatusbar(activity.getWindow(), mainColor, textColor);
}
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
DeckLog.log("--- Write: shared_preference_theme_main" + " | " + mainColor);
DeckLog.log("--- Write: shared_preference_theme_text" + " | " + textColor);
editor.putInt(context.getString(R.string.shared_preference_theme_main), mainColor);
editor.putInt(context.getString(R.string.shared_preference_theme_text), textColor);
editor.commit();
}

// --------------------------------------
// Current account / board / stack states
// --------------------------------------

@SuppressLint("ApplySharedPref")
public static void saveCurrentAccountIdSynchronously(@NonNull Context context, long accountId) {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
DeckLog.log("--- Write: shared_preference_last_account" + " | " + accountId);
editor.putLong(context.getString(R.string.shared_preference_last_account), accountId);
editor.commit();
}

public static void saveCurrentAccountId(@NonNull Context context, long accountId) {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
DeckLog.log("--- Write: shared_preference_last_account" + " | " + accountId);
Expand All @@ -116,6 +140,14 @@ public static long readCurrentAccountId(@NonNull Context context) {
return accountId;
}

@SuppressLint("ApplySharedPref")
public static void saveCurrentBoardIdSynchronously(@NonNull Context context, long accountId, long boardId) {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
DeckLog.log("--- Write: shared_preference_last_board_for_account_" + accountId + " | " + boardId);
editor.putLong(context.getString(R.string.shared_preference_last_board_for_account_) + accountId, boardId);
editor.commit();
}

public static void saveCurrentBoardId(@NonNull Context context, long accountId, long boardId) {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
DeckLog.log("--- Write: shared_preference_last_board_for_account_" + accountId + " | " + boardId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
});
} else {
DeckLog.info("uri does not have userinfo. Looking for accounts on host " + uri.getHost());
syncManager.readAccountsForHostWithReadAccessToBoard(uri.getHost(), boardRemoteId).observe(this, (accounts) -> {
observeOnce(syncManager.readAccountsForHostWithReadAccessToBoard(uri.getHost(), boardRemoteId), this, (accounts) -> {
if (accounts.size() == 0) {
DeckLog.info("found no account on host with read access to this board");
openInBrowser();
Expand All @@ -97,17 +97,19 @@ public void applyBrand(int mainColor, int textColor) {

@UiThread
private void launchMainActivity(@NonNull Account account, Long boardRemoteId) {
SingleAccountHelper.setCurrentAccount(this, account.getName());
Application.saveCurrentAccountIdSynchronously(this, account.getId());
try {
Application.saveBrandColorsSynchronously(this, Color.parseColor(account.getColor()), Color.parseColor(account.getTextColor()));
} catch (Throwable t) {
DeckLog.logError(t);
}
syncManager = new SyncManager(this);
observeOnce(syncManager.getBoard(account.getId(), boardRemoteId), this, (board) -> {
try {
Application.saveBrandColors(this, Color.parseColor(account.getColor()), Color.parseColor(account.getTextColor()));
} catch (Throwable t) {
DeckLog.logError(t);
}
Application.saveCurrentBoardId(this, account.getId(), board.getLocalId());
SingleAccountHelper.setCurrentAccount(this, account.getName());
Application.saveCurrentBoardIdSynchronously(this, account.getId(), board.getLocalId());
DeckLog.info("starting " + MainActivity.class.getSimpleName() + " with [" + account + ", " + board.getLocalId() + "]");
Intent intent = new Intent(this, MainActivity.class)
.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
});
Expand Down

0 comments on commit 2b4bd7f

Please sign in to comment.