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

Partially fix stuff

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 8 жил өмнө
parent
commit
c774aa3040

+ 3 - 3
src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -39,6 +39,7 @@ import android.content.pm.PackageManager;
 import android.content.res.Resources.NotFoundException;
 import android.content.res.Resources.NotFoundException;
 import android.os.Build;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Bundle;
+import android.os.Handler;
 import android.os.IBinder;
 import android.os.IBinder;
 import android.os.Parcelable;
 import android.os.Parcelable;
 import android.support.design.widget.BottomNavigationView;
 import android.support.design.widget.BottomNavigationView;
@@ -232,6 +233,7 @@ public class FileDisplayActivity extends HookActivity
     protected void onPostCreate(Bundle savedInstanceState) {
     protected void onPostCreate(Bundle savedInstanceState) {
         super.onPostCreate(savedInstanceState);
         super.onPostCreate(savedInstanceState);
 
 
+
         if (!PermissionUtil.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
         if (!PermissionUtil.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
             // Check if we should show an explanation
             // Check if we should show an explanation
             if (PermissionUtil.shouldShowRequestPermissionRationale(this,
             if (PermissionUtil.shouldShowRequestPermissionRationale(this,
@@ -270,8 +272,6 @@ public class FileDisplayActivity extends HookActivity
         setIndeterminate(mSyncInProgress);
         setIndeterminate(mSyncInProgress);
         // always AFTER setContentView(...) in onCreate(); to work around bug in its implementation
         // always AFTER setContentView(...) in onCreate(); to work around bug in its implementation
 
 
-        setBackgroundText();
-
         upgradeNotificationForInstantUpload();
         upgradeNotificationForInstantUpload();
     }
     }
 
 
@@ -1274,7 +1274,7 @@ public class FileDisplayActivity extends HookActivity
      * loading or folder is empty
      * loading or folder is empty
      */
      */
     private void setBackgroundText() {
     private void setBackgroundText() {
-        OCFileListFragment ocFileListFragment = getListOfFilesFragment();
+        final OCFileListFragment ocFileListFragment = getListOfFilesFragment();
         if (ocFileListFragment != null) {
         if (ocFileListFragment != null) {
             if (!mSyncInProgress) {
             if (!mSyncInProgress) {
                 ocFileListFragment.setEmptyListMessage(ExtendedListFragment.SearchType.NO_SEARCH);
                 ocFileListFragment.setEmptyListMessage(ExtendedListFragment.SearchType.NO_SEARCH);

+ 3 - 11
src/main/java/com/owncloud/android/ui/adapter/FileListListAdapter.java

@@ -574,17 +574,9 @@ public class FileListListAdapter extends BaseAdapter {
         ArrayList<ContentValues> contentValues = new ArrayList<>();
         ArrayList<ContentValues> contentValues = new ArrayList<>();
 
 
         for (int i = 0; i < objects.size(); i++) {
         for (int i = 0; i < objects.size(); i++) {
-            OCFile ocFile;
-
-            // try to find it in database
-            ocFile = mStorageManager.getFileByPath(((RemoteFile) objects.get(i)).getRemotePath());
-
-            if (ocFile == null) {
-                // new
-                ocFile = FileStorageUtils.fillOCFile((RemoteFile) objects.get(i));
-                searchForLocalFileInDefaultPath(ocFile);
-                ocFile = mStorageManager.saveFileWithParent(ocFile, mContext);
-            }
+            OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) objects.get(i));
+            searchForLocalFileInDefaultPath(ocFile);
+            ocFile = mStorageManager.saveFileWithParent(ocFile, mContext);
 
 
             if (!onlyImages || MimeTypeUtil.isImage(ocFile)) {
             if (!onlyImages || MimeTypeUtil.isImage(ocFile)) {
                 mFiles.add(ocFile);
                 mFiles.add(ocFile);

+ 6 - 2
src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java

@@ -426,6 +426,10 @@ public class ExtendedListFragment extends Fragment
         return v;
         return v;
     }
     }
 
 
+    public void setEmptyListVisible() {
+        mEmptyListContainer.setVisibility(View.VISIBLE);
+    }
+
     protected void setupEmptyList(View view) {
     protected void setupEmptyList(View view) {
         mEmptyListContainer = (LinearLayout) view.findViewById(R.id.empty_list_view);
         mEmptyListContainer = (LinearLayout) view.findViewById(R.id.empty_list_view);
         mEmptyListMessage = (TextView) view.findViewById(R.id.empty_list_view_text);
         mEmptyListMessage = (TextView) view.findViewById(R.id.empty_list_view_text);
@@ -447,7 +451,6 @@ public class ExtendedListFragment extends Fragment
             mTops = savedInstanceState.getIntegerArrayList(KEY_TOPS);
             mTops = savedInstanceState.getIntegerArrayList(KEY_TOPS);
             mHeightCell = savedInstanceState.getInt(KEY_HEIGHT_CELL);
             mHeightCell = savedInstanceState.getInt(KEY_HEIGHT_CELL);
             setMessageForEmptyList(savedInstanceState.getString(KEY_EMPTY_LIST_MESSAGE));
             setMessageForEmptyList(savedInstanceState.getString(KEY_EMPTY_LIST_MESSAGE));
-
         } else {
         } else {
             mIndexes = new ArrayList<>();
             mIndexes = new ArrayList<>();
             mFirstPositions = new ArrayList<>();
             mFirstPositions = new ArrayList<>();
@@ -643,6 +646,7 @@ public class ExtendedListFragment extends Fragment
 
 
                     mEmptyListIcon.setVisibility(View.VISIBLE);
                     mEmptyListIcon.setVisibility(View.VISIBLE);
                     mEmptyListProgress.setVisibility(View.GONE);
                     mEmptyListProgress.setVisibility(View.GONE);
+                    mEmptyListMessage.setVisibility(View.VISIBLE);
                 }
                 }
             }
             }
         });
         });
@@ -653,7 +657,7 @@ public class ExtendedListFragment extends Fragment
             @Override
             @Override
             public void run() {
             public void run() {
 
 
-                if (searchType == SearchType.NO_SEARCH) {
+                if (searchType == SearchType.NO_SEARCH && mEmptyListProgress.getVisibility() == View.GONE) {
                     setMessageForEmptyList(
                     setMessageForEmptyList(
                             R.string.file_list_empty_headline,
                             R.string.file_list_empty_headline,
                             R.string.file_list_empty,
                             R.string.file_list_empty,

+ 54 - 44
src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -183,6 +183,7 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
         if (savedInstanceState != null) {
         if (savedInstanceState != null) {
             currentSearchType = Parcels.unwrap(savedInstanceState.getParcelable(KEY_CURRENT_SEARCH_TYPE));
             currentSearchType = Parcels.unwrap(savedInstanceState.getParcelable(KEY_CURRENT_SEARCH_TYPE));
             searchEvent = Parcels.unwrap(savedInstanceState.getParcelable(OCFileListFragment.SEARCH_EVENT));
             searchEvent = Parcels.unwrap(savedInstanceState.getParcelable(OCFileListFragment.SEARCH_EVENT));
+            setEmptyView(searchEvent);
         }
         }
         searchFragment = currentSearchType != null;
         searchFragment = currentSearchType != null;
     }
     }
@@ -1254,6 +1255,39 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
 
 
     }
     }
 
 
+    private void setEmptyView(SearchEvent event) {
+
+        if (event != null) {
+            if (event.getSearchType().equals(SearchOperation.SearchType.FILE_SEARCH)) {
+                setEmptyListMessage(SearchType.FILE_SEARCH);
+            } else if (event.getSearchType().equals(SearchOperation.SearchType.CONTENT_TYPE_SEARCH)) {
+                if (event.getSearchQuery().equals("image/%")) {
+                    setEmptyListMessage(SearchType.PHOTO_SEARCH);
+                    menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_GRID_AND_SORT;
+                } else if (event.getSearchQuery().equals("video/%")) {
+                    setEmptyListMessage(SearchType.VIDEO_SEARCH);
+                    menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SEARCH;
+                }
+            } else if (event.getSearchType().equals(SearchOperation.SearchType.FAVORITE_SEARCH)) {
+                setEmptyListMessage(SearchType.FAVORITE_SEARCH);
+                menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SORT;
+            } else if (event.getSearchType().equals(SearchOperation.SearchType.RECENTLY_ADDED_SEARCH)) {
+                setEmptyListMessage(SearchType.RECENTLY_ADDED_SEARCH);
+                menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SORT;
+            } else if (event.getSearchType().equals(SearchOperation.SearchType.RECENTLY_MODIFIED_SEARCH)) {
+                setEmptyListMessage(SearchType.RECENTLY_MODIFIED_SEARCH);
+                menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SORT;
+            } else if (event.getSearchType().equals(SearchOperation.SearchType.SHARED_SEARCH)) {
+                setEmptyListMessage(SearchType.SHARED_FILTER);
+                menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SEARCH;
+            }
+
+            if (!currentSearchType.equals(SearchType.FILE_SEARCH) && getActivity() != null) {
+                getActivity().invalidateOptionsMenu();
+            }
+        }
+    }
+
     @Subscribe(threadMode = ThreadMode.MAIN)
     @Subscribe(threadMode = ThreadMode.MAIN)
     public void onMessageEvent(ChangeMenuEvent changeMenuEvent) {
     public void onMessageEvent(ChangeMenuEvent changeMenuEvent) {
         menuItemAddRemoveValue = MenuItemAddRemove.ADD_GRID_AND_SORT_WITH_SEARCH;
         menuItemAddRemoveValue = MenuItemAddRemove.ADD_GRID_AND_SORT_WITH_SEARCH;
@@ -1302,7 +1336,7 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
     }
     }
 
 
     @Subscribe(threadMode = ThreadMode.BACKGROUND)
     @Subscribe(threadMode = ThreadMode.BACKGROUND)
-    public void onMessageEvent(SearchEvent event) {
+    public void onMessageEvent(final SearchEvent event) {
         searchFragment = true;
         searchFragment = true;
         setEmptyListLoadingMessage();
         setEmptyListLoadingMessage();
         mAdapter.setData(new ArrayList<>(), SearchType.NO_SEARCH, mContainerActivity.getStorageManager());
         mAdapter.setData(new ArrayList<>(), SearchType.NO_SEARCH, mContainerActivity.getStorageManager());
@@ -1387,6 +1421,20 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
             }
             }
         };
         };
 
 
+        if (currentSearchType.equals(SearchType.PHOTO_SEARCH)) {
+            new Handler(Looper.getMainLooper()).post(new Runnable() {
+                @Override
+                public void run() {
+                    switchToGridView();
+                }
+            });
+        } else if (currentSearchType.equals(SearchType.NO_SEARCH) || currentSearchType.equals(
+                SearchType.REGULAR_FILTER)) {
+            new Handler(Looper.getMainLooper()).post(switchViewsRunnable);
+        } else {
+            new Handler(Looper.getMainLooper()).post(switchViewsRunnable);
+        }
+
         final RemoteOperation remoteOperation;
         final RemoteOperation remoteOperation;
         if (!currentSearchType.equals(SearchType.SHARED_FILTER)) {
         if (!currentSearchType.equals(SearchType.SHARED_FILTER)) {
             remoteOperation = new SearchOperation(event.getSearchQuery(), event.getSearchType());
             remoteOperation = new SearchOperation(event.getSearchQuery(), event.getSearchType());
@@ -1409,7 +1457,11 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
 
 
                     if (remoteOperationResult.isSuccess() && remoteOperationResult.getData() != null
                     if (remoteOperationResult.isSuccess() && remoteOperationResult.getData() != null
                             && !isCancelled() && searchFragment) {
                             && !isCancelled() && searchFragment) {
-                        mAdapter.setData(remoteOperationResult.getData(), currentSearchType, storageManager);
+                        if (remoteOperationResult.getData() == null || remoteOperationResult.getData().size() == 0) {
+                            setEmptyView(event);
+                        } else {
+                            mAdapter.setData(remoteOperationResult.getData(), currentSearchType, storageManager);
+                        }
                     }
                     }
 
 
                     return remoteOperationResult.isSuccess();
                     return remoteOperationResult.isSuccess();
@@ -1428,48 +1480,6 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
 
 
         remoteOperationAsyncTask.execute(true);
         remoteOperationAsyncTask.execute(true);
 
 
-        if (event.getSearchType().equals(SearchOperation.SearchType.FILE_SEARCH)) {
-            setEmptyListMessage(SearchType.FILE_SEARCH);
-
-        } else if (event.getSearchType().equals(SearchOperation.SearchType.CONTENT_TYPE_SEARCH)) {
-            if (event.getSearchQuery().equals("image/%")) {
-                setEmptyListMessage(SearchType.PHOTO_SEARCH);
-                menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_GRID_AND_SORT;
-            } else if (event.getSearchQuery().equals("video/%")) {
-                setEmptyListMessage(SearchType.VIDEO_SEARCH);
-                menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SEARCH;
-            }
-        } else if (event.getSearchType().equals(SearchOperation.SearchType.FAVORITE_SEARCH)) {
-            setEmptyListMessage(SearchType.FAVORITE_SEARCH);
-            menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SORT;
-        } else if (event.getSearchType().equals(SearchOperation.SearchType.RECENTLY_ADDED_SEARCH)) {
-            setEmptyListMessage(SearchType.RECENTLY_ADDED_SEARCH);
-            menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SORT;
-        } else if (event.getSearchType().equals(SearchOperation.SearchType.RECENTLY_MODIFIED_SEARCH)) {
-            setEmptyListMessage(SearchType.RECENTLY_MODIFIED_SEARCH);
-            menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SORT;
-        } else if (event.getSearchType().equals(SearchOperation.SearchType.SHARED_SEARCH)) {
-            setEmptyListMessage(SearchType.SHARED_FILTER);
-            menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SEARCH;
-        }
-
-        if (!currentSearchType.equals(SearchType.FILE_SEARCH) && getActivity() != null) {
-            getActivity().invalidateOptionsMenu();
-        }
-
-        if (currentSearchType.equals(SearchType.PHOTO_SEARCH)) {
-            new Handler(Looper.getMainLooper()).post(new Runnable() {
-                @Override
-                public void run() {
-                    switchToGridView();
-                }
-            });
-        } else if (currentSearchType.equals(SearchType.NO_SEARCH) || currentSearchType.equals(
-                SearchType.REGULAR_FILTER)) {
-            new Handler(Looper.getMainLooper()).post(switchViewsRunnable);
-        } else {
-            new Handler(Looper.getMainLooper()).post(switchViewsRunnable);
-        }
     }
     }
 
 
     private void setTitle(@StringRes final int title) {
     private void setTitle(@StringRes final int title) {

+ 8 - 7
src/main/res/layout/empty_list.xml

@@ -18,8 +18,8 @@
   You should have received a copy of the GNU Affero General Public
   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/>.
   License along with this program. If not, see <http://www.gnu.org/licenses/>.
 -->
 -->
-<LinearLayout android:id="@+id/empty_list_view"
-              xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:id="@+id/empty_list_view"
               android:layout_width="match_parent"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:layout_height="wrap_content"
               android:layout_gravity="center"
               android:layout_gravity="center"
@@ -34,14 +34,14 @@
         android:layout_height="72dp"
         android:layout_height="72dp"
         android:contentDescription="@string/file_list_folder"
         android:contentDescription="@string/file_list_folder"
         android:src="@drawable/ic_list_empty_folder"
         android:src="@drawable/ic_list_empty_folder"
-        android:tint="@color/primary"/>
+        android:tint="@color/primary"
+        android:visibility="gone"/>
 
 
     <ProgressBar
     <ProgressBar
         android:id="@+id/empty_list_progress"
         android:id="@+id/empty_list_progress"
         android:layout_width="72dp"
         android:layout_width="72dp"
         android:layout_height="72dp"
         android:layout_height="72dp"
-        android:layout_gravity="center_horizontal"
-        android:visibility="gone"/>
+        android:layout_gravity="center_horizontal"/>
 
 
     <TextView
     <TextView
         android:id="@+id/empty_list_view_headline"
         android:id="@+id/empty_list_view_headline"
@@ -53,7 +53,7 @@
         android:maxLines="2"
         android:maxLines="2"
         android:paddingBottom="@dimen/standard_padding"
         android:paddingBottom="@dimen/standard_padding"
         android:paddingTop="@dimen/standard_padding"
         android:paddingTop="@dimen/standard_padding"
-        android:text="@string/file_list_empty_headline"
+        android:text="@string/file_list_loading"
         android:textSize="26sp"/>
         android:textSize="26sp"/>
 
 
     <TextView
     <TextView
@@ -64,6 +64,7 @@
         android:ellipsize="end"
         android:ellipsize="end"
         android:gravity="center"
         android:gravity="center"
         android:maxLines="3"
         android:maxLines="3"
-        android:text="@string/file_list_empty"/>
+        android:text="@string/file_list_empty"
+        android:visibility="gone"/>
 
 
 </LinearLayout>
 </LinearLayout>

+ 1 - 1
src/main/res/layout/list_fragment.xml

@@ -33,7 +33,7 @@
         android:layout_height="match_parent"
         android:layout_height="match_parent"
         android:footerDividersEnabled="false"
         android:footerDividersEnabled="false"
         android:visibility="visible" >
         android:visibility="visible" >
-        
+
         <com.owncloud.android.ui.ExtendedListView
         <com.owncloud.android.ui.ExtendedListView
             android:id="@+id/list_root"
             android:id="@+id/list_root"
             android:layout_width="match_parent"
             android:layout_width="match_parent"