Эх сурвалжийг харах

Implement user information magic

Mario Danic 8 жил өмнө
parent
commit
fad7f9f4d5

+ 102 - 0
src/com/owncloud/android/ui/activity/UserInfoActivity.java

@@ -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;
 package com.owncloud.android.ui.activity;
 
 
 import android.accounts.Account;
 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.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
 import android.support.v7.widget.DividerItemDecoration;
 import android.support.v7.widget.DividerItemDecoration;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
 import android.support.v7.widget.RecyclerView;
@@ -17,6 +45,7 @@ import android.widget.RelativeLayout;
 import android.widget.TextView;
 import android.widget.TextView;
 
 
 import com.owncloud.android.R;
 import com.owncloud.android.R;
+import com.owncloud.android.authentication.AuthenticatorActivity;
 import com.owncloud.android.lib.common.UserInfo;
 import com.owncloud.android.lib.common.UserInfo;
 import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 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_ACCOUNT = "ACCOUNT";
     private static final String KEY_DISPLAY_NAME = "DISPLAY_NAME";
     private static final String KEY_DISPLAY_NAME = "DISPLAY_NAME";
 
 
+    private static final int KEY_DELETE_CODE = 101;
+
     @BindView(R.id.generic_rv)
     @BindView(R.id.generic_rv)
     RecyclerView genericRecyclerView;
     RecyclerView genericRecyclerView;
 
 
@@ -135,6 +166,12 @@ public class UserInfoActivity extends FileActivity {
             case android.R.id.home:
             case android.R.id.home:
                 onBackPressed();
                 onBackPressed();
                 break;
                 break;
+            case R.id.change_password:
+                changeAccountPassword(account);
+                break;
+            case R.id.delete_account:
+                openAccountRemovalConfirmationDialog(account);
+                break;
             default:
             default:
                 retval = super.onOptionsItemSelected(item);
                 retval = super.onOptionsItemSelected(item);
         }
         }
@@ -167,6 +204,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() {
     private void fetchAndSetData() {
         Thread t = new Thread(new Runnable() {
         Thread t = new Thread(new Runnable() {
             public void run() {
             public void run() {
@@ -197,6 +297,8 @@ public class UserInfoActivity extends FileActivity {
         t.start();
         t.start();
     }
     }
 
 
+
+
     @Override
     @Override
     protected void onSaveInstanceState(Bundle outState) {
     protected void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
         super.onSaveInstanceState(outState);

+ 4 - 3
src/com/owncloud/android/ui/adapter/UserInfoAdapter.java

@@ -2,18 +2,19 @@
  * Nextcloud Android client application
  * Nextcloud Android client application
  *
  *
  * @author Mario Danic
  * @author Mario Danic
+ * Copyright (C) 2017 Mario Danic
  * Copyright (C) 2017 Nextcloud GmbH.
  * Copyright (C) 2017 Nextcloud GmbH.
- * <p>
+ *
  * This program is free software: you can redistribute it and/or modify
  * 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
  * 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
  * the Free Software Foundation, either version 3 of the License, or
  * at your option) any later version.
  * at your option) any later version.
- * <p>
+ *
  * This program is distributed in the hope that it will be useful,
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Affero General Public License for more details.
  * GNU Affero General Public License for more details.
- * <p>
+ *
  * You should have received a copy of the GNU Affero General Public License
  * 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/>.
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  */

+ 5 - 5
src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java

@@ -34,6 +34,7 @@ import android.os.Handler;
 import android.os.IBinder;
 import android.os.IBinder;
 import android.support.v4.content.ContextCompat;
 import android.support.v4.content.ContextCompat;
 import android.support.v4.graphics.drawable.DrawableCompat;
 import android.support.v4.graphics.drawable.DrawableCompat;
+import android.util.Log;
 import android.view.MenuItem;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.View;
 import android.widget.AdapterView;
 import android.widget.AdapterView;
@@ -55,11 +56,10 @@ import com.owncloud.android.utils.DisplayUtils;
 
 
 import org.parceler.Parcels;
 import org.parceler.Parcels;
 
 
+import java.lang.reflect.Array;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.Set;
 import java.util.Set;
 
 
-import butterknife.OnItemClick;
-
 /**
 /**
  * An Activity that allows the user to manage accounts.
  * An Activity that allows the user to manage accounts.
  */
  */
@@ -72,6 +72,8 @@ public class ManageAccountsActivity extends FileActivity
     private static final String KEY_ACCOUNT = "ACCOUNT";
     private static final String KEY_ACCOUNT = "ACCOUNT";
     private static final String KEY_DISPLAY_NAME = "DISPLAY_NAME";
     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 ListView mListView;
     private final Handler mHandler = new Handler();
     private final Handler mHandler = new Handler();
@@ -124,7 +126,7 @@ public class ManageAccountsActivity extends FileActivity
                     Log_OC.d(TAG, "Failed to find NC account");
                     Log_OC.d(TAG, "Failed to find NC account");
                 }
                 }
 
 
-                startActivity(intent);
+                startActivityForResult(intent, KEY_USER_INFO_REQUEST_CODE);
             }
             }
         });
         });
 
 
@@ -145,8 +147,6 @@ public class ManageAccountsActivity extends FileActivity
                     }
                     }
                 }
                 }
                 break;
                 break;
-            default:
-                break;
         }
         }
     }
     }