Browse Source

add select/deselect all button

tobiasKaminsky 8 years ago
parent
commit
06d87d7a11

+ 43 - 0
src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactListFragment.java

@@ -39,6 +39,8 @@ import android.support.v7.app.AlertDialog;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
 import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
@@ -107,6 +109,15 @@ public class ContactListFragment extends FileFragment {
         return frag;
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+        super.onCreateOptionsMenu(menu, inflater);
+        inflater.inflate(R.menu.contactlist_menu, menu);
+    }
+
     @Override
     public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 
@@ -223,6 +234,12 @@ public class ContactListFragment extends FileFragment {
                 contactsPreferenceActivity.onBackPressed();
                 retval = true;
                 break;
+            case R.id.action_select_all:
+                item.setChecked(!item.isChecked());
+                setSelectAllMenuItem(item, item.isChecked());
+                contactListAdapter.selectAllFiles(item.isChecked());
+                retval = true;
+                break;
             default:
                 retval = super.onOptionsItemSelected(item);
                 break;
@@ -230,6 +247,15 @@ public class ContactListFragment extends FileFragment {
         return retval;
     }
 
+    private void setSelectAllMenuItem(MenuItem selectAll, boolean checked) {
+        selectAll.setChecked(checked);
+        if(checked) {
+            selectAll.setIcon(R.drawable.ic_select_none);
+        } else {
+            selectAll.setIcon(R.drawable.ic_select_all);
+        }
+    }
+
     static class ContactItemViewHolder extends RecyclerView.ViewHolder {
         private ImageView badge;
         private CheckedTextView name;
@@ -526,4 +552,21 @@ class ContactListAdapter extends RecyclerView.Adapter<ContactListFragment.Contac
     public int getItemCount() {
         return vCards.size();
     }
+
+    public void selectAllFiles(boolean select) {
+        checkedVCards = new HashSet<>();
+        if (select) {
+            for (int i = 0; i < vCards.size(); i++) {
+                checkedVCards.add(i);
+            }
+        }
+
+        if (checkedVCards.size() > 0) {
+            EventBus.getDefault().post(new VCardToggleEvent(true));
+        } else {
+            EventBus.getDefault().post(new VCardToggleEvent(false));
+        }
+
+        notifyDataSetChanged();
+    }
 }

+ 35 - 0
src/main/res/menu/contactlist_menu.xml

@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Nextcloud Android client application
+
+ @author Tobias Kaminsky
+ Copyright (C) 2017 Tobias Kaminsky
+ 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/>.
+ -->
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+      xmlns:app="http://schemas.android.com/apk/res-auto"
+      xmlns:tools="http://schemas.android.com/tools"
+      tools:ignore="AppCompatResource">
+
+    <item
+        android:id="@+id/action_select_all"
+        android:checkable="true"
+        android:contentDescription="@string/select_all"
+        android:title="@string/select_all"
+        android:icon="@drawable/ic_select_all"
+        app:showAsAction="always"/>
+
+</menu>