88import android .databinding .Bindable ;
99import android .databinding .ObservableArrayList ;
1010import android .databinding .ObservableBoolean ;
11+ import android .databinding .ObservableInt ;
1112import android .os .Handler ;
1213import android .support .v7 .app .AlertDialog ;
1314import android .support .v7 .view .menu .MenuBuilder ;
@@ -69,6 +70,16 @@ public class ExplorerViewModel extends BaseObservable {
6970 @ Bindable
7071 public ObservableArrayList <FileViewModel > files ;
7172
73+ /**
74+ * Indicates whether the view is in selection mode.
75+ */
76+ public ObservableBoolean isSelectionMode ;
77+
78+ /**
79+ * The number of selected items
80+ */
81+ public ObservableInt numberSelectedItems ;
82+
7283 /**
7384 * Default constructor.
7485 * @param context The context of the current activity.
@@ -77,6 +88,8 @@ public ExplorerViewModel(Context context) {
7788 this .context = context ;
7889 this .isLoading = new ObservableBoolean (false );
7990 this .files = new ObservableArrayList <FileViewModel >();
91+ this .isSelectionMode = new ObservableBoolean (false );
92+ this .numberSelectedItems = new ObservableInt (0 );
8093 this .changeDirectory ("/" );
8194 }
8295
@@ -236,4 +249,31 @@ else if(item.getItemId() == KEY_ADD_NEW_FAVORITE) {
236249
237250 popupMenu .show ();
238251 }
252+
253+ /**
254+ * Refresh the number of selected items.
255+ */
256+ public void refreshSelectedItems () {
257+ int total = 0 ;
258+
259+ for (FileViewModel file : files ) {
260+ if (file .isSelected .get ()) {
261+ total ++;
262+ }
263+ }
264+
265+ this .numberSelectedItems .set (total );
266+ }
267+
268+ /**
269+ * Clear the selection.
270+ * @param view The current view.
271+ */
272+ public void clearSelection (View view ) {
273+ for (FileViewModel file : files ) {
274+ file .isSelected .set (false );
275+ }
276+
277+ this .isSelectionMode .set (false );
278+ }
239279}
0 commit comments