Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions res/layout/account_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
android:textColor="@color/textColor"
android:textSize="@dimen/two_line_primary_text_size"/>

<ImageView
<ImageButton
android:id="@+id/passwordButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -52,9 +52,10 @@
android:paddingTop="@dimen/standard_padding"
android:paddingBottom="@dimen/standard_padding"
android:paddingRight="@dimen/standard_half_padding"
android:background="?android:selectableItemBackground"
android:src="@drawable/ic_key"/>

<ImageView
<ImageButton
android:id="@+id/removeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -63,6 +64,7 @@
android:paddingTop="@dimen/standard_padding"
android:paddingBottom="@dimen/standard_padding"
android:paddingRight="@dimen/standard_padding"
android:src="@drawable/ic_close"/>
android:background="?android:selectableItemBackground"
android:src="@drawable/ic_action_delete"/>

</LinearLayout>
1 change: 1 addition & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<string name="about_title">About</string>
<string name="change_password">Change password</string>
<string name="delete_account">Remove account</string>
<string name="delete_account_warning">Delete account %s?\n\nDeleting cannot be undone.</string>
<string name="create_account">Create account</string>
<string name="upload_chooser_title">Upload from &#8230;</string>
<string name="uploader_info_dirname">Folder name</string>
Expand Down
67 changes: 59 additions & 8 deletions src/com/owncloud/android/ui/activity/ManageAccountsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@
import android.accounts.AccountManagerCallback;
import android.accounts.AccountManagerFuture;
import android.accounts.OperationCanceledException;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.MenuItem;
import android.widget.ListView;

Expand Down Expand Up @@ -115,8 +121,7 @@ public void onBackPressed() {
resultIntent.putExtra(KEY_ACCOUNT_LIST_CHANGED, hasAccountListChanged());
resultIntent.putExtra(KEY_CURRENT_ACCOUNT_CHANGED, hasCurrentAccountChanged());
setResult(RESULT_OK, resultIntent);

finish();

super.onBackPressed();
}

Expand Down Expand Up @@ -164,7 +169,7 @@ private void initializeComponentGetters() {
*/
private ArrayList<AccountListItem> getAccountListItems() {
Account[] accountList = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
ArrayList<AccountListItem> adapterAccountList = new ArrayList<AccountListItem>(accountList.length);
ArrayList<AccountListItem> adapterAccountList = new ArrayList<>(accountList.length);
for (Account account : accountList) {
adapterAccountList.add(new AccountListItem(account));
}
Expand All @@ -191,11 +196,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

@Override
public void removeAccount(Account account) {
AccountManager am = (AccountManager) this.getSystemService(ACCOUNT_SERVICE);
public void performAccountRemoval(Account account) {
AccountRemovalConfirmationDialog dialog = AccountRemovalConfirmationDialog.newInstance(account);
mAccountName = account.name;
am.removeAccount(account, ManageAccountsActivity.this, mHandler);
Log_OC.d(TAG, "Remove an account " + account.name);
dialog.show(getFragmentManager(), "dialog");
}

@Override
Expand Down Expand Up @@ -267,7 +271,7 @@ public void run(AccountManagerFuture<Boolean> future) {
}

mAccountListAdapter = new AccountListAdapter(this, getAccountListItems());
mAccountListAdapter.notifyDataSetChanged();
mListView.setAdapter(mAccountListAdapter);
}
}

Expand All @@ -285,6 +289,8 @@ protected void onDestroy() {
super.onDestroy();
}

public Handler getHandler() { return mHandler; }

// Methods for ComponentsGetter
@Override
public FileDownloader.FileDownloaderBinder getFileDownloaderBinder() {
Expand Down Expand Up @@ -343,4 +349,49 @@ public void onServiceDisconnected(ComponentName component) {
}
}
}

public static class AccountRemovalConfirmationDialog extends DialogFragment {

private static final String ARG__ACCOUNT = "account";

private Account mAccount;

public static AccountRemovalConfirmationDialog newInstance(Account account) {
Bundle bundle = new Bundle();
bundle.putParcelable(ARG__ACCOUNT, account);

AccountRemovalConfirmationDialog dialog = new AccountRemovalConfirmationDialog();
dialog.setArguments(bundle);

return dialog;
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAccount = getArguments().getParcelable(ARG__ACCOUNT);
}

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity(), R.style.Theme_ownCloud_Dialog)
.setTitle(R.string.delete_account)
.setMessage(getResources().getString(R.string.delete_account_warning, mAccount.name))
.setIcon(R.drawable.ic_warning)
.setPositiveButton(R.string.common_ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
AccountManager am = (AccountManager) getActivity().getSystemService(ACCOUNT_SERVICE);
am.removeAccount(
mAccount,
(ManageAccountsActivity)getActivity(),
((ManageAccountsActivity)getActivity()).getHandler());
}
})
.setNegativeButton(R.string.common_cancel, null)
.create();
}
}
}
22 changes: 7 additions & 15 deletions src/com/owncloud/android/ui/adapter/AccountListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@
package com.owncloud.android.ui.adapter;

import android.accounts.Account;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.owncloud.android.R;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.ui.TextDrawable;
import com.owncloud.android.ui.activity.BaseActivity;
import com.owncloud.android.ui.activity.ManageAccountsActivity;
import com.owncloud.android.utils.DisplayUtils;
Expand All @@ -57,10 +55,6 @@ public AccountListAdapter(BaseActivity context, List<AccountListItem> values) {
this.mAccountAvatarRadiusDimension = context.getResources().getDimension(R.dimen.list_item_avatar_icon_radius);
}

public void setAccountList(List<AccountListItem> values) {
this.mValues = values;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
AccountViewHolderItem viewHolder;
Expand All @@ -72,8 +66,8 @@ public View getView(final int position, View convertView, ViewGroup parent) {
viewHolder = new AccountViewHolderItem();
viewHolder.textViewItem = (TextView) convertView.findViewById(R.id.user_name);
viewHolder.imageViewItem = (ImageView) convertView.findViewById(R.id.user_icon);
viewHolder.passwordButtonItem = (ImageView) convertView.findViewById(R.id.passwordButton);
viewHolder.removeButtonItem = (ImageView) convertView.findViewById(R.id.removeButton);
viewHolder.passwordButtonItem = (ImageButton) convertView.findViewById(R.id.passwordButton);
viewHolder.removeButtonItem = (ImageButton) convertView.findViewById(R.id.removeButton);

convertView.setTag(viewHolder);
} else {
Expand Down Expand Up @@ -111,9 +105,7 @@ public void onClick(View v) {
viewHolder.removeButtonItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.removeAccount(mValues.get(position).getAccount());
mValues.remove(position);
AccountListAdapter.this.notifyDataSetChanged();
mListener.performAccountRemoval(mValues.get(position).getAccount());
}
});
} // create add account action item
Expand Down Expand Up @@ -152,7 +144,7 @@ public boolean shouldCallGeneratedCallback(String tag, Object callContext) {
* Listener interface for Activities using the {@link AccountListAdapter}
*/
public interface AccountListAdapterListener {
void removeAccount(Account account);
void performAccountRemoval(Account account);

void changePasswordOfAccount(Account account);

Expand All @@ -166,7 +158,7 @@ static class AccountViewHolderItem {
TextView textViewItem;
ImageView imageViewItem;

ImageView passwordButtonItem;
ImageView removeButtonItem;
ImageButton passwordButtonItem;
ImageButton removeButtonItem;
}
}