Fixed NPE on list of shares in SearchShareesFragment; and some clean-up
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / fragment / ShareFileFragment.java
index 1b95186..5ee2a87 100644 (file)
@@ -2,6 +2,7 @@
  *   ownCloud Android client application
  *
  *   @author masensio
  *   ownCloud Android client application
  *
  *   @author masensio
+ *   @author David A. Velasco
  *   Copyright (C) 2015 ownCloud Inc.
  *
  *   This program is free software: you can redistribute it and/or modify
  *   Copyright (C) 2015 ownCloud Inc.
  *
  *   This program is free software: you can redistribute it and/or modify
@@ -32,8 +33,10 @@ import android.widget.Button;
 import android.widget.ImageView;
 import android.widget.ListView;
 import android.widget.TextView;
 import android.widget.ImageView;
 import android.widget.ListView;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import com.owncloud.android.R;
 
 import com.owncloud.android.R;
+import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.lib.common.utils.Log_OC;
@@ -137,8 +140,14 @@ public class ShareFileFragment extends Fragment
         addUserGroupButton.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
         addUserGroupButton.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
-                // Show Search Fragment
-                mListener.showSearchUsersAndGroups(mShares);
+                 boolean shareWithUsersEnable = AccountUtils.hasSearchUsersSupport(mAccount);
+                if (shareWithUsersEnable) {
+                    // Show Search Fragment
+                    mListener.showSearchUsersAndGroups();
+                } else {
+                    String message = getString(R.string.share_sharee_unavailable);
+                    Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
+                }
             }
         });
 
             }
         });
 
@@ -149,8 +158,13 @@ public class ShareFileFragment extends Fragment
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
 
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
 
-        // Load data to the list (start process with an Async Task)
-        mListener.refreshUsersOrGroupsListFromServer();
+        // Load data into the list
+        refreshUsersOrGroupsListFromDB();
+
+        // Request for a refresh of the data through the server (starts an Async Task)
+        if (mListener != null) {
+            mListener.refreshUsersOrGroupsListFromServer();
+        }
     }
 
     @Override
     }
 
     @Override
@@ -184,8 +198,12 @@ public class ShareFileFragment extends Fragment
 
     private void updateListOfUserGroups() {
         // Update list of users/groups
 
     private void updateListOfUserGroups() {
         // Update list of users/groups
-        mUserGroupsAdapter = new ShareUserListAdapter(getActivity().getApplicationContext(),
-                R.layout.share_user_item, mShares, this);
+        mUserGroupsAdapter = new ShareUserListAdapter(
+                getActivity(),
+                R.layout.share_user_item,
+                mShares,
+                this
+        );
 
         // Show data
         TextView noShares = (TextView) getView().findViewById(R.id.shareNoUsers);
 
         // Show data
         TextView noShares = (TextView) getView().findViewById(R.id.shareNoUsers);
@@ -221,7 +239,7 @@ public class ShareFileFragment extends Fragment
      * >Communicating with Other Fragments</a> for more information.
      */
     public interface OnShareFragmentInteractionListener {
      * >Communicating with Other Fragments</a> for more information.
      */
     public interface OnShareFragmentInteractionListener {
-        void showSearchUsersAndGroups(ArrayList<OCShare> shares);
+        void showSearchUsersAndGroups();
         void refreshUsersOrGroupsListFromServer();
         void unshareWith(OCShare share);
     }
         void refreshUsersOrGroupsListFromServer();
         void unshareWith(OCShare share);
     }