Loading app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java +8 −7 Original line number Diff line number Diff line Loading @@ -3,14 +3,12 @@ package it.niedermann.owncloud.notes.accountswitcher; import android.app.Dialog; import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.net.Uri; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.core.graphics.drawable.DrawableCompat; import androidx.fragment.app.DialogFragment; import com.bumptech.glide.Glide; Loading @@ -19,14 +17,16 @@ import com.bumptech.glide.request.RequestOptions; import java.util.List; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.branding.BrandedDialogFragment; import it.niedermann.owncloud.notes.databinding.DialogAccountSwitcherBinding; import it.niedermann.owncloud.notes.manageaccounts.ManageAccountsActivity; import it.niedermann.owncloud.notes.model.LocalAccount; import it.niedermann.owncloud.notes.persistence.NotesDatabase; import static it.niedermann.owncloud.notes.android.activity.NotesListViewActivity.manage_account; import static it.niedermann.owncloud.notes.branding.BrandingUtil.applyBrandToLayerDrawable; public class AccountSwitcherDialog extends DialogFragment { public class AccountSwitcherDialog extends BrandedDialogFragment { private static final String KEY_CURRENT_ACCOUNT_ID = "current_account_id"; Loading Loading @@ -69,10 +69,6 @@ public class AccountSwitcherDialog extends DialogFragment { .into(binding.currentAccountItemAvatar); binding.accountLayout.setOnClickListener((v) -> dismiss()); LayerDrawable ld = (LayerDrawable) binding.check.getDrawable(); Drawable ldDrawable = ld.findDrawableByLayerId(R.id.area); DrawableCompat.setTint(ldDrawable, currentLocalAccount.getColor()); AccountSwitcherAdapter adapter = new AccountSwitcherAdapter((localAccount -> { accountSwitcherListener.onAccountChosen(localAccount); dismiss(); Loading Loading @@ -111,4 +107,9 @@ public class AccountSwitcherDialog extends DialogFragment { return dialog; } @Override public void applyBrand(int mainColor, int textColor) { applyBrandToLayerDrawable((LayerDrawable) binding.check.getDrawable(), R.id.area, mainColor); } } app/src/main/java/it/niedermann/owncloud/notes/branding/BrandingUtil.java +11 −0 Original line number Diff line number Diff line Loading @@ -5,11 +5,13 @@ import android.content.SharedPreferences; import android.content.res.ColorStateList; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.util.Log; import android.view.MenuItem; import android.widget.EditText; import androidx.annotation.ColorInt; import androidx.annotation.IdRes; import androidx.annotation.NonNull; import androidx.core.graphics.drawable.DrawableCompat; import androidx.preference.PreferenceManager; Loading Loading @@ -120,4 +122,13 @@ public class BrandingUtil { menuItem.setIcon(drawable); } } public static void applyBrandToLayerDrawable(@NonNull LayerDrawable check, @IdRes int areaToColor, @ColorInt int mainColor) { final Drawable drawable = check.findDrawableByLayerId(areaToColor); if (drawable == null) { Log.e(TAG, "Could not find areaToColor (" + areaToColor + "). Cannot apply brand."); } else { DrawableCompat.setTint(drawable, mainColor); } } } app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountAdapter.java +15 −4 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ import it.niedermann.owncloud.notes.model.LocalAccount; public class ManageAccountAdapter extends RecyclerView.Adapter<ManageAccountViewHolder> { @Nullable private LocalAccount currentLocalAccount = null; @NonNull private final List<LocalAccount> localAccounts = new ArrayList<>(); @NonNull Loading @@ -42,18 +44,22 @@ public class ManageAccountAdapter extends RecyclerView.Adapter<ManageAccountView @Override public void onBindViewHolder(@NonNull ManageAccountViewHolder holder, int position) { holder.bind(localAccounts.get(position), onAccountClick, (localAccount -> { final LocalAccount localAccount = localAccounts.get(position); holder.bind(localAccount, (localAccountClicked) -> { setCurrentLocalAccount(localAccountClicked); onAccountClick.accept(localAccountClicked); }, (localAccountToDelete -> { if (onAccountDelete != null) { for (int i = 0; i < localAccounts.size(); i++) { if (localAccounts.get(i).getId() == localAccount.getId()) { if (localAccounts.get(i).getId() == localAccountToDelete.getId()) { localAccounts.remove(i); notifyItemRemoved(i); break; } } onAccountDelete.accept(localAccount); onAccountDelete.accept(localAccountToDelete); } })); }), currentLocalAccount != null && currentLocalAccount.getId() == localAccount.getId()); } @Override Loading @@ -66,4 +72,9 @@ public class ManageAccountAdapter extends RecyclerView.Adapter<ManageAccountView this.localAccounts.addAll(localAccounts); notifyDataSetChanged(); } public void setCurrentLocalAccount(@Nullable LocalAccount currentLocalAccount) { this.currentLocalAccount = currentLocalAccount; notifyDataSetChanged(); } } app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountViewHolder.java +15 −4 Original line number Diff line number Diff line package it.niedermann.owncloud.notes.manageaccounts; import android.graphics.drawable.LayerDrawable; import android.net.Uri; import android.view.View; Loading @@ -15,16 +16,20 @@ import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.databinding.ItemAccountChooseBinding; import it.niedermann.owncloud.notes.model.LocalAccount; import static android.view.View.GONE; import static android.view.View.VISIBLE; import static it.niedermann.owncloud.notes.branding.BrandingUtil.applyBrandToLayerDrawable; public class ManageAccountViewHolder extends RecyclerView.ViewHolder { ItemAccountChooseBinding binding; private ItemAccountChooseBinding binding; public ManageAccountViewHolder(@NonNull View itemView) { super(itemView); binding = ItemAccountChooseBinding.bind(itemView); } public void bind(@NonNull LocalAccount localAccount, @NonNull Consumer<LocalAccount> onAccountClick, @Nullable Consumer<LocalAccount> onAccountDelete) { public void bind(@NonNull LocalAccount localAccount, @NonNull Consumer<LocalAccount> onAccountClick, @Nullable Consumer<LocalAccount> onAccountDelete, boolean isCurrentAccount) { binding.accountItemLabel.setText(localAccount.getAccountName()); Glide.with(itemView.getContext()) .load(localAccount.getUrl() + "/index.php/avatar/" + Uri.encode(localAccount.getUserName()) + "/64") Loading @@ -33,10 +38,16 @@ public class ManageAccountViewHolder extends RecyclerView.ViewHolder { .into(binding.accountItemAvatar); itemView.setOnClickListener((v) -> onAccountClick.accept(localAccount)); if (onAccountDelete == null) { binding.delete.setVisibility(View.GONE); binding.delete.setVisibility(GONE); } else { binding.delete.setVisibility(View.VISIBLE); binding.delete.setVisibility(VISIBLE); binding.delete.setOnClickListener((v) -> onAccountDelete.accept(localAccount)); } if (isCurrentAccount) { binding.currentAccountIndicator.setVisibility(VISIBLE); applyBrandToLayerDrawable((LayerDrawable) binding.currentAccountIndicator.getDrawable(), R.id.area, localAccount.getColor()); } else { binding.currentAccountIndicator.setVisibility(GONE); } } } app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java +12 −0 Original line number Diff line number Diff line Loading @@ -5,7 +5,10 @@ import android.os.Bundle; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException; import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException; import com.nextcloud.android.sso.helper.SingleAccountHelper; import com.nextcloud.android.sso.model.SingleSignOnAccount; import java.util.List; Loading Loading @@ -46,12 +49,21 @@ public class ManageAccountsActivity extends LockedActivity { } if (localAccounts.size() > 0) { SingleAccountHelper.setCurrentAccount(getApplicationContext(), localAccounts.get(0).getAccountName()); adapter.setCurrentLocalAccount(localAccounts.get(0)); } else { setResult(AppCompatActivity.RESULT_FIRST_USER); finish(); } }); adapter.setLocalAccounts(localAccounts); try { SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(this); if (ssoAccount != null) { adapter.setCurrentLocalAccount(db.getLocalAccountByAccountName(ssoAccount.name)); } } catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) { e.printStackTrace(); } binding.accounts.setAdapter(adapter); } Loading Loading
app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java +8 −7 Original line number Diff line number Diff line Loading @@ -3,14 +3,12 @@ package it.niedermann.owncloud.notes.accountswitcher; import android.app.Dialog; import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.net.Uri; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.core.graphics.drawable.DrawableCompat; import androidx.fragment.app.DialogFragment; import com.bumptech.glide.Glide; Loading @@ -19,14 +17,16 @@ import com.bumptech.glide.request.RequestOptions; import java.util.List; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.branding.BrandedDialogFragment; import it.niedermann.owncloud.notes.databinding.DialogAccountSwitcherBinding; import it.niedermann.owncloud.notes.manageaccounts.ManageAccountsActivity; import it.niedermann.owncloud.notes.model.LocalAccount; import it.niedermann.owncloud.notes.persistence.NotesDatabase; import static it.niedermann.owncloud.notes.android.activity.NotesListViewActivity.manage_account; import static it.niedermann.owncloud.notes.branding.BrandingUtil.applyBrandToLayerDrawable; public class AccountSwitcherDialog extends DialogFragment { public class AccountSwitcherDialog extends BrandedDialogFragment { private static final String KEY_CURRENT_ACCOUNT_ID = "current_account_id"; Loading Loading @@ -69,10 +69,6 @@ public class AccountSwitcherDialog extends DialogFragment { .into(binding.currentAccountItemAvatar); binding.accountLayout.setOnClickListener((v) -> dismiss()); LayerDrawable ld = (LayerDrawable) binding.check.getDrawable(); Drawable ldDrawable = ld.findDrawableByLayerId(R.id.area); DrawableCompat.setTint(ldDrawable, currentLocalAccount.getColor()); AccountSwitcherAdapter adapter = new AccountSwitcherAdapter((localAccount -> { accountSwitcherListener.onAccountChosen(localAccount); dismiss(); Loading Loading @@ -111,4 +107,9 @@ public class AccountSwitcherDialog extends DialogFragment { return dialog; } @Override public void applyBrand(int mainColor, int textColor) { applyBrandToLayerDrawable((LayerDrawable) binding.check.getDrawable(), R.id.area, mainColor); } }
app/src/main/java/it/niedermann/owncloud/notes/branding/BrandingUtil.java +11 −0 Original line number Diff line number Diff line Loading @@ -5,11 +5,13 @@ import android.content.SharedPreferences; import android.content.res.ColorStateList; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.util.Log; import android.view.MenuItem; import android.widget.EditText; import androidx.annotation.ColorInt; import androidx.annotation.IdRes; import androidx.annotation.NonNull; import androidx.core.graphics.drawable.DrawableCompat; import androidx.preference.PreferenceManager; Loading Loading @@ -120,4 +122,13 @@ public class BrandingUtil { menuItem.setIcon(drawable); } } public static void applyBrandToLayerDrawable(@NonNull LayerDrawable check, @IdRes int areaToColor, @ColorInt int mainColor) { final Drawable drawable = check.findDrawableByLayerId(areaToColor); if (drawable == null) { Log.e(TAG, "Could not find areaToColor (" + areaToColor + "). Cannot apply brand."); } else { DrawableCompat.setTint(drawable, mainColor); } } }
app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountAdapter.java +15 −4 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ import it.niedermann.owncloud.notes.model.LocalAccount; public class ManageAccountAdapter extends RecyclerView.Adapter<ManageAccountViewHolder> { @Nullable private LocalAccount currentLocalAccount = null; @NonNull private final List<LocalAccount> localAccounts = new ArrayList<>(); @NonNull Loading @@ -42,18 +44,22 @@ public class ManageAccountAdapter extends RecyclerView.Adapter<ManageAccountView @Override public void onBindViewHolder(@NonNull ManageAccountViewHolder holder, int position) { holder.bind(localAccounts.get(position), onAccountClick, (localAccount -> { final LocalAccount localAccount = localAccounts.get(position); holder.bind(localAccount, (localAccountClicked) -> { setCurrentLocalAccount(localAccountClicked); onAccountClick.accept(localAccountClicked); }, (localAccountToDelete -> { if (onAccountDelete != null) { for (int i = 0; i < localAccounts.size(); i++) { if (localAccounts.get(i).getId() == localAccount.getId()) { if (localAccounts.get(i).getId() == localAccountToDelete.getId()) { localAccounts.remove(i); notifyItemRemoved(i); break; } } onAccountDelete.accept(localAccount); onAccountDelete.accept(localAccountToDelete); } })); }), currentLocalAccount != null && currentLocalAccount.getId() == localAccount.getId()); } @Override Loading @@ -66,4 +72,9 @@ public class ManageAccountAdapter extends RecyclerView.Adapter<ManageAccountView this.localAccounts.addAll(localAccounts); notifyDataSetChanged(); } public void setCurrentLocalAccount(@Nullable LocalAccount currentLocalAccount) { this.currentLocalAccount = currentLocalAccount; notifyDataSetChanged(); } }
app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountViewHolder.java +15 −4 Original line number Diff line number Diff line package it.niedermann.owncloud.notes.manageaccounts; import android.graphics.drawable.LayerDrawable; import android.net.Uri; import android.view.View; Loading @@ -15,16 +16,20 @@ import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.databinding.ItemAccountChooseBinding; import it.niedermann.owncloud.notes.model.LocalAccount; import static android.view.View.GONE; import static android.view.View.VISIBLE; import static it.niedermann.owncloud.notes.branding.BrandingUtil.applyBrandToLayerDrawable; public class ManageAccountViewHolder extends RecyclerView.ViewHolder { ItemAccountChooseBinding binding; private ItemAccountChooseBinding binding; public ManageAccountViewHolder(@NonNull View itemView) { super(itemView); binding = ItemAccountChooseBinding.bind(itemView); } public void bind(@NonNull LocalAccount localAccount, @NonNull Consumer<LocalAccount> onAccountClick, @Nullable Consumer<LocalAccount> onAccountDelete) { public void bind(@NonNull LocalAccount localAccount, @NonNull Consumer<LocalAccount> onAccountClick, @Nullable Consumer<LocalAccount> onAccountDelete, boolean isCurrentAccount) { binding.accountItemLabel.setText(localAccount.getAccountName()); Glide.with(itemView.getContext()) .load(localAccount.getUrl() + "/index.php/avatar/" + Uri.encode(localAccount.getUserName()) + "/64") Loading @@ -33,10 +38,16 @@ public class ManageAccountViewHolder extends RecyclerView.ViewHolder { .into(binding.accountItemAvatar); itemView.setOnClickListener((v) -> onAccountClick.accept(localAccount)); if (onAccountDelete == null) { binding.delete.setVisibility(View.GONE); binding.delete.setVisibility(GONE); } else { binding.delete.setVisibility(View.VISIBLE); binding.delete.setVisibility(VISIBLE); binding.delete.setOnClickListener((v) -> onAccountDelete.accept(localAccount)); } if (isCurrentAccount) { binding.currentAccountIndicator.setVisibility(VISIBLE); applyBrandToLayerDrawable((LayerDrawable) binding.currentAccountIndicator.getDrawable(), R.id.area, localAccount.getColor()); } else { binding.currentAccountIndicator.setVisibility(GONE); } } }
app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java +12 −0 Original line number Diff line number Diff line Loading @@ -5,7 +5,10 @@ import android.os.Bundle; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException; import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException; import com.nextcloud.android.sso.helper.SingleAccountHelper; import com.nextcloud.android.sso.model.SingleSignOnAccount; import java.util.List; Loading Loading @@ -46,12 +49,21 @@ public class ManageAccountsActivity extends LockedActivity { } if (localAccounts.size() > 0) { SingleAccountHelper.setCurrentAccount(getApplicationContext(), localAccounts.get(0).getAccountName()); adapter.setCurrentLocalAccount(localAccounts.get(0)); } else { setResult(AppCompatActivity.RESULT_FIRST_USER); finish(); } }); adapter.setLocalAccounts(localAccounts); try { SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(this); if (ssoAccount != null) { adapter.setCurrentLocalAccount(db.getLocalAccountByAccountName(ssoAccount.name)); } } catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) { e.printStackTrace(); } binding.accounts.setAdapter(adapter); } Loading