tobiasKaminsky 9 ani în urmă
părinte
comite
d761f24572

+ 10 - 0
res/layout/grid_image.xml

@@ -64,6 +64,16 @@
             android:layout_marginBottom="4dp"
             android:layout_marginRight="4dp"
             android:src="@drawable/ic_available_offline" />
+
+        <ImageView
+            android:id="@+id/custom_checkbox"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_vertical|bottom"
+            android:layout_marginLeft="4dp"
+            android:layout_marginRight="4dp"
+            android:gravity=""
+            android:src="@android:drawable/checkbox_off_background" />
     </FrameLayout>
 
 </LinearLayout>

+ 10 - 1
res/layout/grid_item.xml

@@ -65,7 +65,16 @@
             android:layout_marginRight="2dp"
             android:src="@drawable/ic_available_offline" />
 
-
+        <ImageView
+            android:id="@+id/custom_checkbox"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_vertical|bottom"
+            android:layout_marginLeft="4dp"
+            android:layout_marginRight="4dp"
+            android:gravity=""
+            android:src="@android:drawable/checkbox_off_background"
+            android:elevation="30dp" />
 
     </FrameLayout>
 

+ 78 - 18
src/com/owncloud/android/ui/adapter/FileListListAdapter.java

@@ -24,9 +24,16 @@
 package com.owncloud.android.ui.adapter;
 
 
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Vector;
+
 import android.accounts.Account;
 import android.content.Context;
 import android.graphics.Bitmap;
+import android.graphics.Color;
 import android.os.Build;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -73,7 +80,9 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
     private boolean mGridMode;
 
     private enum ViewType {LIST_ITEM, GRID_IMAGE, GRID_ITEM };
-    
+
+    private HashMap<Integer, Boolean> mSelection = new HashMap<Integer, Boolean>();
+
     public FileListListAdapter(
             boolean justFolders, 
             Context context,
@@ -188,33 +197,33 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
                     TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
                     TextView fileSizeSeparatorV = (TextView) view.findViewById(R.id.file_separator);
                     TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
-                    ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
+
 
                     lastModV.setVisibility(View.VISIBLE);
                     lastModV.setText(DisplayUtils.getRelativeTimestamp(mContext, file.getModificationTimestamp()));
 
-                    checkBoxV.setVisibility(View.GONE);
+
 
                     fileSizeSeparatorV.setVisibility(View.VISIBLE);
                     fileSizeV.setVisibility(View.VISIBLE);
                     fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
 
                     if (!file.isFolder()) {
-                        AbsListView parentList = (AbsListView)parent;
-                        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
-                            if (parentList.getChoiceMode() == AbsListView.CHOICE_MODE_NONE) {
-                                checkBoxV.setVisibility(View.GONE);
-                            } else {
-                                if (parentList.isItemChecked(position)) {
-                                    checkBoxV.setImageResource(
-                                            R.drawable.ic_checkbox_marked);
-                                } else {
-                                    checkBoxV.setImageResource(
-                                            R.drawable.ic_checkbox_blank_outline);
-                                }
-                                checkBoxV.setVisibility(View.VISIBLE);
-                            }
-                        }
+//                        AbsListView parentList = (AbsListView)parent;
+//                        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+//                            if (parentList.getChoiceMode() == AbsListView.CHOICE_MODE_NONE) {
+//                                checkBoxV.setVisibility(View.GONE);
+//                            } else {
+//                                if (parentList.isItemChecked(position)) {
+//                                    checkBoxV.setImageResource(
+//                                            R.drawable.ic_checkbox_marked);
+//                                } else {
+//                                    checkBoxV.setImageResource(
+//                                            R.drawable.ic_checkbox_blank_outline);
+//                                }
+//                                checkBoxV.setVisibility(View.VISIBLE);
+//                            }
+//                        }
 
                     } else { //Folder
                         fileSizeSeparatorV.setVisibility(View.GONE);
@@ -289,6 +298,25 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
 
                     break;
             }
+
+            ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
+            checkBoxV.setVisibility(View.GONE);
+
+            AbsListView parentList = (AbsListView)parent;
+            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+                if (parentList.getChoiceMode() == AbsListView.CHOICE_MODE_NONE) {
+                    checkBoxV.setVisibility(View.GONE);
+                } else if (parentList.getCheckedItemCount() > 0){
+                    if (parentList.isItemChecked(position)) {
+                        checkBoxV.setImageResource(
+                                android.R.drawable.checkbox_on_background);
+                    } else {
+                        checkBoxV.setImageResource(
+                                android.R.drawable.checkbox_off_background);
+                    }
+                    checkBoxV.setVisibility(View.VISIBLE);
+                }
+            }
             
             // For all Views
             
@@ -353,6 +381,12 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
             }
         }
 
+        if (mSelection.get(position) != null) {
+            view.setBackgroundColor(R.color.owncloud_blue);
+        } else {
+            view.setBackgroundColor(Color.WHITE);
+        }
+
         return view;
     }
 
@@ -439,4 +473,30 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
     public boolean isGridMode() {
         return mGridMode;
     }
+
+    public void setNewSelection(int position, boolean checked) {
+        mSelection.put(position, checked);
+        notifyDataSetChanged();
+    }
+
+    public void removeSelection(int position) {
+        mSelection.remove(position);
+        notifyDataSetChanged();
+    }
+
+    public void removeSelection(){
+         mSelection.clear();
+        notifyDataSetChanged();
+    }
+
+    public ArrayList<Integer> getCheckedItemPositions() {
+        ArrayList<Integer> ids = new ArrayList<Integer>();
+
+        for (Map.Entry<Integer, Boolean> entry : mSelection.entrySet()){
+            if (entry.getValue()){
+                ids.add(entry.getKey());
+            }
+        }
+        return ids;
+    }
 }

+ 1 - 0
src/com/owncloud/android/ui/dialog/AccountActionsDialogFragment.java

@@ -39,6 +39,7 @@ public class AccountActionsDialogFragment extends DialogFragment implements
      * Listener interface for the file action fragment.
      */
     public interface FileActionsDialogFragmentListener {
+        // TODO Tobi change to int array?
         public boolean onFileActionChosen(int menuId, int filePosition);
     }
 

+ 50 - 1
src/com/owncloud/android/ui/fragment/ExtendedListFragment.java

@@ -24,7 +24,10 @@ import android.os.Build;
 import android.os.Bundle;
 import android.support.v4.app.Fragment;
 import android.support.v4.widget.SwipeRefreshLayout;
+import android.view.ActionMode;
 import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.AbsListView;
@@ -161,15 +164,61 @@ public class ExtendedListFragment extends Fragment
                              Bundle savedInstanceState) {
         Log_OC.d(TAG, "onCreateView");
 
+        // TODO Tobi remove
+//         AbsListView.MultiChoiceModeListener listener = new AbsListView.MultiChoiceModeListener() {
+//            @Override
+//            public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
+//                // Capture total checked items
+//                final int checkedCount = mListView.getCheckedItemCount();
+//                // Set the CAB title according to total checked items
+//                mode.setTitle(checkedCount + " Selected");
+//                // Calls toggleSelection method from ListViewAdapter Class
+//                 // mAdapter.toggleSelection(position);
+//
+//                if (checked){
+//                    mAdapter.setNewSelection(position,checked);
+//                } else {
+//                    mAdapter.removeSelection(position);
+//                }
+//            }
+//
+//            @Override
+//            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
+//                mode.getMenuInflater().inflate(R.menu.context, menu);
+//                return true;
+//            }
+//
+//            @Override
+//            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
+//                return false;
+//            }
+//
+//            @Override
+//            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
+//                return false;
+//            }
+//
+//            @Override
+//            public void onDestroyActionMode(ActionMode mode) {
+//                // mAdapter.removeSelection();
+//            }
+//        };
+
         View v = inflater.inflate(R.layout.list_fragment, null);
 
         mListView = (ExtendedListView)(v.findViewById(R.id.list_root));
         mListView.setOnItemClickListener(this);
+        mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
+        // mListView.setMultiChoiceModeListener(listener);
         mListFooterView = inflater.inflate(R.layout.list_footer, null, false);
 
         mGridView = (GridViewWithHeaderAndFooter) (v.findViewById(R.id.grid_root));
         mGridView.setNumColumns(GridView.AUTO_FIT);
-        mGridView.setOnItemClickListener(this);
+        // mGridView.setOnItemClickListener(this);
+        mGridView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
+
+        // mGridView.setMultiChoiceModeListener(listener);
+
         mGridFooterView = inflater.inflate(R.layout.list_footer, null, false);
 
         if (savedInstanceState != null) {

+ 75 - 5
src/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -30,6 +30,7 @@ import android.os.Build;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
 import android.support.v4.widget.SwipeRefreshLayout;
+import android.view.ActionMode;
 import android.view.ContextMenu;
 import android.view.LayoutInflater;
 import android.view.Menu;
@@ -37,6 +38,7 @@ import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.AbsListView;
 import android.widget.AdapterView;
 import android.widget.AdapterView.AdapterContextMenuInfo;
 import android.widget.PopupMenu;
@@ -335,16 +337,83 @@ public class OCFileListFragment extends ExtendedListFragment
     }
 
     private void registerLongClickListener() {
-        getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
-            public boolean onItemLongClick(AdapterView<?> arg0, View v,
-                                           int index, long arg3) {
-                showFileAction(index);
+        getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
+            @Override
+            public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
+                // Capture total checked items
+                final int checkedCount = getListView().getCheckedItemCount();
+                // Set the CAB title according to total checked items
+                mode.setTitle(checkedCount + " Selected");
+
+                if (checked){
+                    mAdapter.setNewSelection(position,checked);
+                } else {
+                    mAdapter.removeSelection(position);
+                }
+            }
+
+            @Override
+            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
+
+                Bundle args = getArguments();
+                boolean allowContextualActions =
+                        (args == null) ? true : args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, true);
+                if (allowContextualActions) {
+                    MenuInflater inflater = getActivity().getMenuInflater();
+                    inflater.inflate(R.menu.file_actions_menu, menu);
+                    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
+                    OCFile targetFile = (OCFile) mAdapter.getItem(info.position);
+
+                    if (mContainerActivity.getStorageManager() != null) {
+                        FileMenuFilter mf = new FileMenuFilter(
+                                targetFile,
+                                mContainerActivity.getStorageManager().getAccount(),
+                                mContainerActivity,
+                                getActivity()
+                        );
+                        mf.filter(menu);
+                    }
+
+                    /// TODO break this direct dependency on FileDisplayActivity... if possible
+                    MenuItem item = menu.findItem(R.id.action_open_file_with);
+                    FileFragment frag = ((FileDisplayActivity)getActivity()).getSecondFragment();
+                    if (frag != null && frag instanceof FileDetailFragment &&
+                            frag.getFile().getFileId() == targetFile.getFileId()) {
+                        item = menu.findItem(R.id.action_see_details);
+                        if (item != null) {
+                            item.setVisible(false);
+                            item.setEnabled(false);
+                        }
+                    }
+                }
+
+                mode.getMenuInflater().inflate(R.menu.file_actions_menu, menu);
                 return true;
             }
+
+            @Override
+            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
+                return false;
+            }
+
+            @Override
+            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
+                if (mAdapter.getCheckedItemPositions().size() == 1) {
+                    return onFileActionChosen(item.getItemId(), mAdapter.getCheckedItemPositions().get(0));
+                } else if (mAdapter.getCheckedItemPositions().size() > 1){
+                    return false;
+                }
+                return false;
+            }
+
+            @Override
+            public void onDestroyActionMode(ActionMode mode) {
+                mAdapter.removeSelection();
+            }
         });
     }
 
-
+    // TODO Tobi needed?
     private void showFileAction(int fileIndex) {
         Bundle args = getArguments();
         PopupMenu pm = new PopupMenu(getActivity(),null);
@@ -492,6 +561,7 @@ public class OCFileListFragment extends ExtendedListFragment
     /**
      * {@inheritDoc}
      */
+    // TODO Tobi needed?
     @Override
     public void onCreateContextMenu(
             ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {