mirror of
https://github.com/nextcloud/android.git
synced 2024-11-29 02:38:58 +03:00
Implement user information magic
This commit is contained in:
parent
5c94246275
commit
f4ab569226
5 changed files with 144 additions and 154 deletions
|
@ -1,7 +1,35 @@
|
|||
/**
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Mario Danic
|
||||
* Copyright (C) 2017 Mario Danic
|
||||
* Copyright (C) 2017 Nextcloud GmbH.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.activity;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.DividerItemDecoration;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
@ -17,6 +45,7 @@ import android.widget.RelativeLayout;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.authentication.AuthenticatorActivity;
|
||||
import com.owncloud.android.lib.common.UserInfo;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
|
@ -42,6 +71,8 @@ public class UserInfoActivity extends FileActivity {
|
|||
private static final String KEY_ACCOUNT = "ACCOUNT";
|
||||
private static final String KEY_DISPLAY_NAME = "DISPLAY_NAME";
|
||||
|
||||
private static final int KEY_DELETE_CODE = 101;
|
||||
|
||||
@BindView(R.id.generic_rv)
|
||||
RecyclerView genericRecyclerView;
|
||||
|
||||
|
@ -133,6 +164,12 @@ public class UserInfoActivity extends FileActivity {
|
|||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
break;
|
||||
case R.id.change_password:
|
||||
changeAccountPassword(account);
|
||||
break;
|
||||
case R.id.delete_account:
|
||||
openAccountRemovalConfirmationDialog(account);
|
||||
break;
|
||||
default:
|
||||
retval = super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
@ -165,6 +202,69 @@ public class UserInfoActivity extends FileActivity {
|
|||
}
|
||||
|
||||
|
||||
private void changeAccountPassword(Account account) {
|
||||
Intent updateAccountCredentials = new Intent(UserInfoActivity.this, AuthenticatorActivity.class);
|
||||
updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, account);
|
||||
updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION,
|
||||
AuthenticatorActivity.ACTION_UPDATE_TOKEN);
|
||||
startActivity(updateAccountCredentials);
|
||||
}
|
||||
|
||||
private void openAccountRemovalConfirmationDialog(Account account) {
|
||||
UserInfoActivity.AccountRemovalConfirmationDialog dialog =
|
||||
UserInfoActivity.AccountRemovalConfirmationDialog.newInstance(account);
|
||||
dialog.show(getFragmentManager(), "dialog");
|
||||
}
|
||||
|
||||
public static class AccountRemovalConfirmationDialog extends DialogFragment {
|
||||
|
||||
private Account account;
|
||||
|
||||
public static UserInfoActivity.AccountRemovalConfirmationDialog newInstance(Account account) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable(KEY_ACCOUNT, account);
|
||||
|
||||
UserInfoActivity.AccountRemovalConfirmationDialog dialog = new
|
||||
UserInfoActivity.AccountRemovalConfirmationDialog();
|
||||
dialog.setArguments(bundle);
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
account = getArguments().getParcelable(KEY_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, account.name))
|
||||
.setIcon(R.drawable.ic_warning)
|
||||
.setPositiveButton(R.string.common_ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable(KEY_ACCOUNT, Parcels.wrap(account));
|
||||
Intent intent = new Intent();
|
||||
intent.putExtras(bundle);
|
||||
if (getActivity() != null) {
|
||||
getActivity().setResult(KEY_DELETE_CODE, intent);
|
||||
getActivity().finish();
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.common_cancel, null)
|
||||
.create();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void fetchAndSetData() {
|
||||
Thread t = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
|
@ -195,6 +295,8 @@ public class UserInfoActivity extends FileActivity {
|
|||
t.start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
|
|
@ -2,18 +2,19 @@
|
|||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Mario Danic
|
||||
* Copyright (C) 2017 Mario Danic
|
||||
* Copyright (C) 2017 Nextcloud GmbH.
|
||||
* <p>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* at your option) any later version.
|
||||
* <p>
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
* <p>
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
|
|
@ -24,22 +24,17 @@ import android.accounts.AccountManager;
|
|||
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.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.graphics.drawable.DrawableCompat;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
|
@ -48,7 +43,6 @@ import android.widget.ListView;
|
|||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.authentication.AccountUtils;
|
||||
import com.owncloud.android.authentication.AuthenticatorActivity;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.files.services.FileDownloader;
|
||||
import com.owncloud.android.files.services.FileUploader;
|
||||
|
@ -62,11 +56,10 @@ import com.owncloud.android.utils.DisplayUtils;
|
|||
|
||||
import org.parceler.Parcels;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
import butterknife.OnItemClick;
|
||||
|
||||
/**
|
||||
* An Activity that allows the user to manage accounts.
|
||||
*/
|
||||
|
@ -79,6 +72,8 @@ public class ManageAccountsActivity extends FileActivity
|
|||
private static final String KEY_ACCOUNT = "ACCOUNT";
|
||||
private static final String KEY_DISPLAY_NAME = "DISPLAY_NAME";
|
||||
|
||||
private static final int KEY_USER_INFO_REQUEST_CODE = 13;
|
||||
private static final int KEY_DELETE_CODE = 101;
|
||||
|
||||
private ListView mListView;
|
||||
private final Handler mHandler = new Handler();
|
||||
|
@ -131,13 +126,30 @@ public class ManageAccountsActivity extends FileActivity
|
|||
Log_OC.d(TAG, "Failed to find NC account");
|
||||
}
|
||||
|
||||
startActivity(intent);
|
||||
startActivityForResult(intent, KEY_USER_INFO_REQUEST_CODE);
|
||||
}
|
||||
});
|
||||
|
||||
initializeComponentGetters();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
switch (resultCode) {
|
||||
case KEY_DELETE_CODE:
|
||||
if (data != null) {
|
||||
Bundle bundle = data.getExtras();
|
||||
if (bundle.containsKey(KEY_ACCOUNT)) {
|
||||
Account account = Parcels.unwrap(bundle.getParcelable(KEY_ACCOUNT));
|
||||
mAccountName = account.name;
|
||||
performAccountRemoval(account);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
Intent resultIntent = new Intent();
|
||||
|
@ -222,22 +234,6 @@ public class ManageAccountsActivity extends FileActivity
|
|||
return retval;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performAccountRemoval(Account account) {
|
||||
AccountRemovalConfirmationDialog dialog = AccountRemovalConfirmationDialog.newInstance(account);
|
||||
mAccountName = account.name;
|
||||
dialog.show(getFragmentManager(), "dialog");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changePasswordOfAccount(Account account) {
|
||||
Intent updateAccountCredentials = new Intent(ManageAccountsActivity.this, AuthenticatorActivity.class);
|
||||
updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, account);
|
||||
updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION,
|
||||
AuthenticatorActivity.ACTION_UPDATE_TOKEN);
|
||||
startActivity(updateAccountCredentials);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAccount() {
|
||||
AccountManager am = AccountManager.get(getApplicationContext());
|
||||
|
@ -276,20 +272,6 @@ public class ManageAccountsActivity extends FileActivity
|
|||
}, mHandler);
|
||||
}
|
||||
|
||||
public void switchAccount(Account account) {
|
||||
if (getAccount().name.equals(account.name)) {
|
||||
// current account selected, just go back
|
||||
finish();
|
||||
} else {
|
||||
// restart list of files with new account
|
||||
AccountUtils.setCurrentOwnCloudAccount(ManageAccountsActivity.this, account.name);
|
||||
Intent i = new Intent(ManageAccountsActivity.this, FileDisplayActivity.class);
|
||||
i.putExtra(FileActivity.EXTRA_ACCOUNT, account);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(AccountManagerFuture<Boolean> future) {
|
||||
if (future.isDone()) {
|
||||
|
@ -314,8 +296,13 @@ public class ManageAccountsActivity extends FileActivity
|
|||
AccountUtils.setCurrentOwnCloudAccount(this, accountName);
|
||||
}
|
||||
|
||||
mAccountListAdapter = new AccountListAdapter(this, getAccountListItems(), mTintedCheck);
|
||||
mListView.setAdapter(mAccountListAdapter);
|
||||
ArrayList<AccountListItem> accountListItemArray = getAccountListItems();
|
||||
if (accountListItemArray.size() > 1) {
|
||||
mAccountListAdapter = new AccountListAdapter(this, accountListItemArray, mTintedCheck);
|
||||
mListView.setAdapter(mAccountListAdapter);
|
||||
} else {
|
||||
onBackPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -359,6 +346,14 @@ public class ManageAccountsActivity extends FileActivity
|
|||
return new ManageAccountsServiceConnection();
|
||||
}
|
||||
|
||||
private void performAccountRemoval(Account account) {
|
||||
AccountManager am = (AccountManager) getSystemService(ACCOUNT_SERVICE);
|
||||
am.removeAccount(
|
||||
account,
|
||||
this,
|
||||
this.getHandler());
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines callbacks for service binding, passed to bindService()
|
||||
*/
|
||||
|
@ -388,48 +383,4 @@ public class ManageAccountsActivity extends FileActivity
|
|||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,13 +74,6 @@ public class AccountListAdapter extends ArrayAdapter<AccountListItem> implements
|
|||
viewHolder.checkViewItem.setImageDrawable(mTintedCheck);
|
||||
viewHolder.usernameViewItem = (TextView) convertView.findViewById(R.id.user_name);
|
||||
viewHolder.accountViewItem = (TextView) convertView.findViewById(R.id.account);
|
||||
viewHolder.passwordButtonItem = (ImageView) convertView.findViewById(R.id.passwordButton);
|
||||
viewHolder.removeButtonItem = (ImageView) convertView.findViewById(R.id.removeButton);
|
||||
|
||||
if(mListener == null) {
|
||||
viewHolder.passwordButtonItem.setVisibility(View.GONE);
|
||||
viewHolder.removeButtonItem.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
convertView.setTag(viewHolder);
|
||||
} else {
|
||||
|
@ -98,7 +91,6 @@ public class AccountListAdapter extends ArrayAdapter<AccountListItem> implements
|
|||
setUsername(viewHolder, account);
|
||||
setAvatar(viewHolder, account);
|
||||
setCurrentlyActiveState(viewHolder, account);
|
||||
setupListeners(position, viewHolder);
|
||||
|
||||
} // create add account action item
|
||||
else if (AccountListItem.TYPE_ACTION_ADD == accountListItem.getType() && mListener != null) {
|
||||
|
@ -131,26 +123,6 @@ public class AccountListAdapter extends ArrayAdapter<AccountListItem> implements
|
|||
viewHolder.accountViewItem.setTag(account.name);
|
||||
}
|
||||
|
||||
private void setupListeners(final int position, AccountViewHolderItem viewHolder) {
|
||||
if (mListener != null) {
|
||||
/// bind listener to change password
|
||||
viewHolder.passwordButtonItem.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mListener.changePasswordOfAccount(mValues.get(position).getAccount());
|
||||
}
|
||||
});
|
||||
|
||||
/// bind listener to remove account
|
||||
viewHolder.removeButtonItem.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mListener.performAccountRemoval(mValues.get(position).getAccount());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void setCurrentlyActiveState(AccountViewHolderItem viewHolder, Account account) {
|
||||
if (AccountUtils.getCurrentOwnCloudAccount(getContext()).name.equals(account.name)) {
|
||||
viewHolder.checkViewItem.setVisibility(View.VISIBLE);
|
||||
|
@ -195,9 +167,6 @@ public class AccountListAdapter extends ArrayAdapter<AccountListItem> implements
|
|||
* Listener interface for Activities using the {@link AccountListAdapter}
|
||||
*/
|
||||
public interface AccountListAdapterListener {
|
||||
void performAccountRemoval(Account account);
|
||||
|
||||
void changePasswordOfAccount(Account account);
|
||||
|
||||
void createAccount();
|
||||
}
|
||||
|
@ -211,8 +180,5 @@ public class AccountListAdapter extends ArrayAdapter<AccountListItem> implements
|
|||
|
||||
TextView usernameViewItem;
|
||||
TextView accountViewItem;
|
||||
|
||||
ImageView passwordButtonItem;
|
||||
ImageView removeButtonItem;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
-->
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/account_item_layout_height"
|
||||
android:orientation="horizontal"
|
||||
android:weightSum="1">
|
||||
|
@ -60,9 +60,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_toEndOf="@id/avatar_container"
|
||||
android:layout_toLeftOf="@+id/passwordButton"
|
||||
android:layout_toRightOf="@id/avatar_container"
|
||||
android:layout_toStartOf="@id/passwordButton"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
|
@ -96,32 +94,4 @@
|
|||
android:textColor="?android:attr/textColorSecondary"/>
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/passwordButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_toLeftOf="@+id/removeButton"
|
||||
android:layout_toStartOf="@id/removeButton"
|
||||
android:paddingBottom="@dimen/standard_padding"
|
||||
android:paddingLeft="@dimen/standard_half_padding"
|
||||
android:paddingRight="@dimen/standard_half_padding"
|
||||
android:paddingTop="@dimen/standard_padding"
|
||||
android:src="@drawable/ic_key"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/removeButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingBottom="@dimen/standard_padding"
|
||||
android:paddingLeft="@dimen/standard_half_padding"
|
||||
android:paddingRight="@dimen/standard_padding"
|
||||
android:paddingTop="@dimen/standard_padding"
|
||||
android:src="@drawable/ic_action_delete_grey"/>
|
||||
|
||||
</RelativeLayout>
|
Loading…
Reference in a new issue