Răsfoiți Sursa

First bits of user info code

Mario Danic 8 ani în urmă
părinte
comite
5339fd7587

+ 1 - 1
build.gradle

@@ -28,7 +28,7 @@ configurations.all {
 }
 
 ext {
-    supportLibraryVersion = '24.2.1'
+    supportLibraryVersion = '25.1.0'
 
     travisBuild = System.getenv("TRAVIS") == "true"
 

+ 1 - 1
src/com/owncloud/android/datamodel/StringPair.java

@@ -21,7 +21,7 @@
 package com.owncloud.android.datamodel;
 
 /**
- * Model for storing key/value String pairs in a nicer way
+ * Created by mdjanic on 25/01/2017.
  */
 
 public class StringPair {

+ 27 - 144
src/com/owncloud/android/ui/activity/UserInfoActivity.java

@@ -1,38 +1,10 @@
-/**
- * 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;
-import android.text.TextUtils;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
@@ -44,7 +16,6 @@ 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;
@@ -60,38 +31,38 @@ import butterknife.ButterKnife;
 import butterknife.Unbinder;
 
 /**
- * This Activity presents the user information.
+ * Created by mdjanic on 25/01/2017.
  */
 
 public class UserInfoActivity extends FileActivity {
     private static final String TAG = UserInfoActivity.class.getSimpleName();
 
-    private static final String KEY_USER_DATA = "USER_DATA";
-    private static final String KEY_ACCOUNT = "ACCOUNT";
-    private static final String KEY_DISPLAY_NAME = "DISPLAY_NAME";
+    protected static final String KEY_USER_DATA = "USER_DATA";
+    protected static final String KEY_NEXTCLOUD_ACCOUNT = "NEXTCLOUD_ACCOUNT";
 
-    private static final int KEY_DELETE_CODE = 101;
 
     @BindView(R.id.generic_rv)
-    public RecyclerView genericRecyclerView;
+    RecyclerView genericRecyclerView;
 
     @BindView(R.id.multi_view)
-    public RelativeLayout multiView;
+    RelativeLayout multiView;
     @BindView(R.id.empty_list_view)
-    public LinearLayout multiListContainer;
+    LinearLayout multiListContainer;
     @BindView(R.id.empty_list_view_text)
-    public TextView multiListMessage;
+    TextView multiListMessage;
     @BindView(R.id.empty_list_view_headline)
-    public TextView multiListHeadline;
+    TextView multiListHeadline;
     @BindView(R.id.empty_list_icon)
-    public ImageView multiListIcon;
+    ImageView multiListIcon;
     @BindView(R.id.empty_list_progress)
-    public ProgressBar multiListProgressBar;
+    ProgressBar multiListProgressBar;
 
     @BindString(R.string.preview_sorry)
-    public String sorryMessage;
+    String sorryMessage;
 
-    private RecyclerView.Adapter adapter;
+    RecyclerView.LayoutManager layoutManager;
+
+    RecyclerView.Adapter adapter;
 
     private RecyclerView.Adapter adapter;
 
@@ -100,8 +71,6 @@ public class UserInfoActivity extends FileActivity {
     private UserInfo userInfo;
     private Account account;
 
-    private String displayName;
-
     @Override
     public void onCreate(Bundle savedInstanceState) {
         Log_OC.v(TAG, "onCreate() start");
@@ -109,42 +78,28 @@ public class UserInfoActivity extends FileActivity {
 
         Bundle bundle = getIntent().getExtras();
 
-        account = Parcels.unwrap(bundle.getParcelable(KEY_ACCOUNT));
-
-        if (savedInstanceState != null && savedInstanceState.containsKey(KEY_USER_DATA)) {
-            userInfo = Parcels.unwrap(savedInstanceState.getParcelable(KEY_USER_DATA));
-        }
-
-        if (bundle.containsKey(KEY_DISPLAY_NAME)) {
-            displayName = bundle.getString(KEY_DISPLAY_NAME);
-        } else if (userInfo != null && !TextUtils.isEmpty(userInfo.getDisplayName())) {
-            displayName = userInfo.getDisplayName();
+        if (bundle.containsKey(KEY_NEXTCLOUD_ACCOUNT)) {
+            account = Parcels.unwrap(bundle.getParcelable(KEY_NEXTCLOUD_ACCOUNT));
         }
 
         setContentView(R.layout.user_info_layout);
         unbinder = ButterKnife.bind(this);
 
         setupToolbar();
-        if (!TextUtils.isEmpty(displayName)) {
-            updateActionBarTitleAndHomeButtonByString(displayName);
-        } else {
-            updateActionBarTitleAndHomeButtonByString(getResources().getString(R.string.user_information_description));
-        }
+        updateActionBarTitleAndHomeButtonByString(getResources().getString(R.string.user_information_description));
 
-        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
+        layoutManager = new LinearLayoutManager(this);
         genericRecyclerView.setLayoutManager(layoutManager);
 
-        // This will be enabled once we migrate to new support libraries
-        
-        /*DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(genericRecyclerView.getContext(),
+        DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(genericRecyclerView.getContext(),
                 ((LinearLayoutManager)layoutManager).getOrientation());
-        genericRecyclerView.addItemDecoration(dividerItemDecoration);*/
+        genericRecyclerView.addItemDecoration(dividerItemDecoration);
 
-        if (userInfo != null) {
+        if (savedInstanceState != null && savedInstanceState.containsKey(KEY_USER_DATA)) {
+            userInfo = Parcels.unwrap(savedInstanceState.getParcelable(KEY_USER_DATA));
             adapter = new UserInfoAdapter(userInfo, UserInfoActivity.this);
-            genericRecyclerView.setAdapter(adapter);
-            multiView.setVisibility(View.GONE);
-            genericRecyclerView.setVisibility(View.VISIBLE);
+            multiView.setVisibility(View.VISIBLE);
+            genericRecyclerView.setVisibility(View.GONE);
         } else {
             setMultiListLoadingMessage();
             fetchAndSetData();
@@ -166,15 +121,8 @@ 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);
-                break;
         }
         return retval;
     }
@@ -205,69 +153,6 @@ 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() {
@@ -289,8 +174,8 @@ public class UserInfoActivity extends FileActivity {
                     });
                 } else {
                     // show error
-                    setMessageForMultiList(result.getLogMessage(), sorryMessage);
-                    Log_OC.d(TAG, result.getLogMessage());
+                    RemoteOperationResult remoteOperationResult = (RemoteOperationResult) result.getData().get(0);
+                    setMessageForMultiList(remoteOperationResult.getLogMessage(), sorryMessage);
                 }
             }
         });
@@ -298,8 +183,6 @@ public class UserInfoActivity extends FileActivity {
         t.start();
     }
 
-
-
     @Override
     protected void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);

+ 12 - 5
src/com/owncloud/android/ui/adapter/UserInfoAdapter.java

@@ -2,7 +2,6 @@
  * 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
@@ -40,7 +39,7 @@ import butterknife.BindView;
 import butterknife.ButterKnife;
 
 /**
- * This Adapter populates a RecyclerView with the user information.
+ * Created by mdjanic on 24/01/2017.
  */
 
 
@@ -61,6 +60,8 @@ public class UserInfoAdapter extends RecyclerView.Adapter<UserInfoAdapter.ViewHo
 
     @Override
     public int getItemViewType(int position) {
+        // Just as an example, return 0 or 2 depending on position
+        // Note that unlike in ListView adapters, types don't have to be contiguous
         if (position % 2 == 0) {
             return 0;
         } else {
@@ -98,9 +99,9 @@ public class UserInfoAdapter extends RecyclerView.Adapter<UserInfoAdapter.ViewHo
 
     public static class ViewHolder extends RecyclerView.ViewHolder {
         @BindView(R.id.attribute_headline_tv)
-        public TextView attributeHeadlineTextView;
+        TextView attributeHeadlineTextView;
         @BindView(R.id.attribute_value_tv)
-        public TextView attributeValueTextView;
+        TextView attributeValueTextView;
 
         public ViewHolder(View itemView) {
             super(itemView);
@@ -112,24 +113,30 @@ public class UserInfoAdapter extends RecyclerView.Adapter<UserInfoAdapter.ViewHo
         if (!TextUtils.isEmpty(userInfo.getDisplayName()) && context != null) {
             stringPairs.add(new StringPair(context.getResources().getString(R.string.user_info_full_name),
                     userInfo.getDisplayName()));
+        }
 
         if (!TextUtils.isEmpty((userInfo.getEmail())) && context != null) {
             stringPairs.add(new StringPair(context.getResources().getString(R.string.user_info_email),
                     userInfo.getEmail()));
+        }
 
         if (!TextUtils.isEmpty(userInfo.getPhone()) && context != null) {
             stringPairs.add(new StringPair(context.getResources().getString(R.string.user_info_phone),
                     userInfo.getPhone()));
+        }
 
         if (!TextUtils.isEmpty(userInfo.getAddress()) && context != null) {
             stringPairs.add(new StringPair(context.getResources().getString(R.string.user_info_address),
                     userInfo.getAddress()));
+        }
 
         if (!TextUtils.isEmpty(userInfo.getWebpage()) && context != null) {
             stringPairs.add(new StringPair(context.getResources().getString(R.string.user_info_website),
                     userInfo.getWebpage()));
+        }
 
-            if (!TextUtils.isEmpty(userInfo.getTwitter())) {
+        if (!TextUtils.isEmpty(userInfo.getTwitter())) {
+            if (context != null) {
                 stringPairs.add(new StringPair(context.getResources().getString(R.string.user_info_twitter),
                         userInfo.getTwitter()));
             }

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

@@ -58,6 +58,8 @@ import org.parceler.Parcels;
 import java.util.ArrayList;
 import java.util.Set;
 
+import butterknife.OnItemClick;
+
 /**
  * An Activity that allows the user to manage accounts.
  */
@@ -116,15 +118,8 @@ public class ManageAccountsActivity extends FileActivity
             @Override
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                 Account account = mAccountListAdapter.getItem(position).getAccount();
-                intent.putExtra(KEY_ACCOUNT, Parcels.wrap(account));
-                try {
-                    OwnCloudAccount oca = new OwnCloudAccount(account, MainApp.getAppContext());
-                    intent.putExtra(KEY_DISPLAY_NAME, oca.getDisplayName());
-                } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
-                    Log_OC.d(TAG, "Failed to find NC account");
-                }
-
-                startActivityForResult(intent, KEY_USER_INFO_REQUEST_CODE);
+                intent.putExtra("NEXTCLOUD_ACCOUNT", Parcels.wrap(account));
+                startActivity(intent);
             }
         });