mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-22 21:06:09 +03:00
#916 Change remote account settings - UI
This commit is contained in:
parent
cb9164e249
commit
b788c07f36
7 changed files with 140 additions and 40 deletions
|
@ -34,6 +34,6 @@ public class AccountSwitcherViewHolder extends RecyclerView.ViewHolder {
|
|||
.apply(RequestOptions.circleCropTransform())
|
||||
.into(binding.accountItemAvatar);
|
||||
itemView.setOnClickListener((v) -> onAccountClick.accept(localAccount));
|
||||
binding.delete.setVisibility(View.GONE);
|
||||
binding.accountContextMenu.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package it.niedermann.owncloud.notes.manageaccounts;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -12,6 +13,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
import it.niedermann.owncloud.notes.persistence.NotesDatabase;
|
||||
import it.niedermann.owncloud.notes.shared.model.LocalAccount;
|
||||
|
||||
public class ManageAccountAdapter extends RecyclerView.Adapter<ManageAccountViewHolder> {
|
||||
|
@ -22,12 +24,21 @@ public class ManageAccountAdapter extends RecyclerView.Adapter<ManageAccountView
|
|||
private final List<LocalAccount> localAccounts = new ArrayList<>();
|
||||
@NonNull
|
||||
private final Consumer<LocalAccount> onAccountClick;
|
||||
@Nullable
|
||||
@NonNull
|
||||
private final Consumer<LocalAccount> onAccountDelete;
|
||||
@NonNull
|
||||
Consumer<LocalAccount> onChangeNotesPath;
|
||||
@NonNull
|
||||
Consumer<LocalAccount> onChangeFileSuffix;
|
||||
|
||||
public ManageAccountAdapter(@NonNull Consumer<LocalAccount> onAccountClick, @Nullable Consumer<LocalAccount> onAccountDelete) {
|
||||
public ManageAccountAdapter(@NonNull Consumer<LocalAccount> onAccountClick,
|
||||
@NonNull Consumer<LocalAccount> onAccountDelete,
|
||||
@NonNull Consumer<LocalAccount> onChangeNotesPath,
|
||||
@NonNull Consumer<LocalAccount> onChangeFileSuffix) {
|
||||
this.onAccountClick = onAccountClick;
|
||||
this.onAccountDelete = onAccountDelete;
|
||||
this.onChangeNotesPath = onChangeNotesPath;
|
||||
this.onChangeFileSuffix = onChangeFileSuffix;
|
||||
setHasStableIds(true);
|
||||
}
|
||||
|
||||
|
@ -49,17 +60,15 @@ public class ManageAccountAdapter extends RecyclerView.Adapter<ManageAccountView
|
|||
setCurrentLocalAccount(localAccountClicked);
|
||||
onAccountClick.accept(localAccountClicked);
|
||||
}, (localAccountToDelete -> {
|
||||
if (onAccountDelete != null) {
|
||||
for (int i = 0; i < localAccounts.size(); i++) {
|
||||
if (localAccounts.get(i).getId() == localAccountToDelete.getId()) {
|
||||
localAccounts.remove(i);
|
||||
notifyItemRemoved(i);
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < localAccounts.size(); i++) {
|
||||
if (localAccounts.get(i).getId() == localAccountToDelete.getId()) {
|
||||
localAccounts.remove(i);
|
||||
notifyItemRemoved(i);
|
||||
break;
|
||||
}
|
||||
onAccountDelete.accept(localAccountToDelete);
|
||||
}
|
||||
}), currentLocalAccount != null && currentLocalAccount.getId() == localAccount.getId());
|
||||
onAccountDelete.accept(localAccountToDelete);
|
||||
}), onChangeNotesPath, onChangeFileSuffix, currentLocalAccount != null && currentLocalAccount.getId() == localAccount.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,10 +2,14 @@ package it.niedermann.owncloud.notes.manageaccounts;
|
|||
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.net.Uri;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.core.util.Consumer;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
|
@ -23,14 +27,21 @@ import static it.niedermann.owncloud.notes.branding.BrandingUtil.applyBrandToLay
|
|||
|
||||
public class ManageAccountViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private ItemAccountChooseBinding binding;
|
||||
private final 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, boolean isCurrentAccount) {
|
||||
public void bind(
|
||||
@NonNull LocalAccount localAccount,
|
||||
@NonNull Consumer<LocalAccount> onAccountClick,
|
||||
@NonNull Consumer<LocalAccount> onAccountDelete,
|
||||
@NonNull Consumer<LocalAccount> onChangeNotesPath,
|
||||
@NonNull Consumer<LocalAccount> onChangeFileSuffix,
|
||||
boolean isCurrentAccount
|
||||
) {
|
||||
binding.accountName.setText(localAccount.getUserName());
|
||||
binding.accountHost.setText(Uri.parse(localAccount.getUrl()).getHost());
|
||||
Glide.with(itemView.getContext())
|
||||
|
@ -39,12 +50,25 @@ public class ManageAccountViewHolder extends RecyclerView.ViewHolder {
|
|||
.apply(RequestOptions.circleCropTransform())
|
||||
.into(binding.accountItemAvatar);
|
||||
itemView.setOnClickListener((v) -> onAccountClick.accept(localAccount));
|
||||
if (onAccountDelete == null) {
|
||||
binding.delete.setVisibility(GONE);
|
||||
} else {
|
||||
binding.delete.setVisibility(VISIBLE);
|
||||
binding.delete.setOnClickListener((v) -> onAccountDelete.accept(localAccount));
|
||||
}
|
||||
binding.accountContextMenu.setVisibility(VISIBLE);
|
||||
binding.accountContextMenu.setOnClickListener((v) -> {
|
||||
final PopupMenu popup = new PopupMenu(itemView.getContext(), v);
|
||||
popup.inflate(R.menu.menu_account);
|
||||
popup.setOnMenuItemClickListener(item -> {
|
||||
if (item.getItemId() == R.id.notes_path) {
|
||||
onChangeNotesPath.accept(localAccount);
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.file_suffix) {
|
||||
onChangeFileSuffix.accept(localAccount);
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.delete) {
|
||||
onAccountDelete.accept(localAccount);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
popup.show();
|
||||
});
|
||||
if (isCurrentAccount) {
|
||||
binding.currentAccountIndicator.setVisibility(VISIBLE);
|
||||
applyBrandToLayerDrawable((LayerDrawable) binding.currentAccountIndicator.getDrawable(), R.id.area, localAccount.getColor());
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package it.niedermann.owncloud.notes.manageaccounts;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
|
@ -10,9 +13,12 @@ import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException;
|
|||
import com.nextcloud.android.sso.helper.SingleAccountHelper;
|
||||
import com.nextcloud.android.sso.model.SingleSignOnAccount;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import it.niedermann.owncloud.notes.LockedActivity;
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
import it.niedermann.owncloud.notes.branding.BrandedAlertDialogBuilder;
|
||||
import it.niedermann.owncloud.notes.databinding.ActivityManageAccountsBinding;
|
||||
import it.niedermann.owncloud.notes.shared.model.LocalAccount;
|
||||
import it.niedermann.owncloud.notes.persistence.NotesDatabase;
|
||||
|
@ -22,6 +28,7 @@ public class ManageAccountsActivity extends LockedActivity {
|
|||
private ActivityManageAccountsBinding binding;
|
||||
private ManageAccountAdapter adapter;
|
||||
private NotesDatabase db = null;
|
||||
private List<LocalAccount> localAccounts = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
@ -34,27 +41,18 @@ public class ManageAccountsActivity extends LockedActivity {
|
|||
|
||||
db = NotesDatabase.getInstance(this);
|
||||
|
||||
List<LocalAccount> localAccounts = db.getAccounts();
|
||||
localAccounts.clear();
|
||||
localAccounts.addAll(db.getAccounts());
|
||||
|
||||
adapter = new ManageAccountAdapter((localAccount) -> SingleAccountHelper.setCurrentAccount(getApplicationContext(), localAccount.getAccountName()), (localAccount) -> {
|
||||
db.deleteAccount(localAccount);
|
||||
for (LocalAccount temp : localAccounts) {
|
||||
if (temp.getId() == localAccount.getId()) {
|
||||
localAccounts.remove(temp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (localAccounts.size() > 0) {
|
||||
SingleAccountHelper.setCurrentAccount(getApplicationContext(), localAccounts.get(0).getAccountName());
|
||||
adapter.setCurrentLocalAccount(localAccounts.get(0));
|
||||
} else {
|
||||
setResult(AppCompatActivity.RESULT_FIRST_USER);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
adapter = new ManageAccountAdapter(
|
||||
(localAccount) -> SingleAccountHelper.setCurrentAccount(getApplicationContext(), localAccount.getAccountName()),
|
||||
this::onAccountDelete,
|
||||
this::onChangeNotesPath,
|
||||
this::onChangeFileSuffix
|
||||
);
|
||||
adapter.setLocalAccounts(localAccounts);
|
||||
try {
|
||||
SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(this);
|
||||
final SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(this);
|
||||
if (ssoAccount != null) {
|
||||
adapter.setCurrentLocalAccount(db.getLocalAccountByAccountName(ssoAccount.name));
|
||||
}
|
||||
|
@ -64,6 +62,49 @@ public class ManageAccountsActivity extends LockedActivity {
|
|||
binding.accounts.setAdapter(adapter);
|
||||
}
|
||||
|
||||
private void onAccountDelete(@NonNull LocalAccount localAccount) {
|
||||
db.deleteAccount(localAccount);
|
||||
for (LocalAccount temp : localAccounts) {
|
||||
if (temp.getId() == localAccount.getId()) {
|
||||
localAccounts.remove(temp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (localAccounts.size() > 0) {
|
||||
SingleAccountHelper.setCurrentAccount(getApplicationContext(), localAccounts.get(0).getAccountName());
|
||||
adapter.setCurrentLocalAccount(localAccounts.get(0));
|
||||
} else {
|
||||
setResult(AppCompatActivity.RESULT_FIRST_USER);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
private void onChangeNotesPath(@NonNull LocalAccount localAccount) {
|
||||
final EditText editText = new EditText(this);
|
||||
new BrandedAlertDialogBuilder(this)
|
||||
.setTitle(R.string.settings_notes_path)
|
||||
.setMessage("Folder to store your notes in your Nextcloud")
|
||||
.setView(editText)
|
||||
.setNeutralButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(R.string.action_edit_save, (v, d) -> {
|
||||
Toast.makeText(this, "Submitted " + editText.getText(), Toast.LENGTH_LONG).show();
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
private void onChangeFileSuffix(@NonNull LocalAccount localAccount) {
|
||||
final EditText editText = new EditText(this);
|
||||
new BrandedAlertDialogBuilder(this)
|
||||
.setTitle(R.string.settings_file_suffix)
|
||||
.setMessage("File extension for new notes in your Nextcloud")
|
||||
.setView(editText)
|
||||
.setNeutralButton(android.R.string.cancel, null)
|
||||
.setPositiveButton("Save", (v, d) -> {
|
||||
Toast.makeText(this, "Submitted " + editText.getText(), Toast.LENGTH_LONG).show();
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyBrand(int mainColor, int textColor) {
|
||||
applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar);
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
</LinearLayout>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/delete"
|
||||
android:id="@+id/account_context_menu"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
|
@ -72,7 +72,7 @@
|
|||
android:focusable="false"
|
||||
android:scaleType="center"
|
||||
android:visibility="gone"
|
||||
app:srcCompat="@drawable/ic_delete_grey600_24dp"
|
||||
app:srcCompat="@drawable/ic_settings_grey600_24dp"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<View
|
||||
|
|
23
app/src/main/res/menu/menu_account.xml
Normal file
23
app/src/main/res/menu/menu_account.xml
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/notes_path"
|
||||
android:orderInCategory="10"
|
||||
android:title="@string/settings_notes_path"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/file_suffix"
|
||||
android:orderInCategory="20"
|
||||
android:title="@string/settings_file_suffix"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/delete"
|
||||
android:orderInCategory="30"
|
||||
android:title="@string/remove_account"
|
||||
app:showAsAction="never" />
|
||||
|
||||
</menu>
|
|
@ -295,4 +295,7 @@
|
|||
<string name="no_account_configured_yet">No account configured yet</string>
|
||||
<string name="no_other_accounts">You don\'t have configured any other accounts yet.</string>
|
||||
<string name="context_based_formatting">Context based formatting popover</string>
|
||||
<string name="settings_notes_path">Set folder</string>
|
||||
<string name="settings_file_suffix">File extension</string>
|
||||
<string name="remove_account">Remove account</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue