Skip to content

Commit

Permalink
Remove SwipableListItem, instead use a contextual action bar, highlig…
Browse files Browse the repository at this point in the history
…ht selected items
  • Loading branch information
intrigus committed Nov 24, 2015
1 parent 75a4520 commit f5568e4
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@

import android.app.ListFragment;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.util.SparseBooleanArray;
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.*;
Expand Down Expand Up @@ -79,6 +84,54 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
getListView().setDividerHeight(0);
getListView().setDivider(null);
setListAdapter(new GroceryListAdapter(view.getContext(), basket));
getListView().setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {

@Override
public void onItemCheckedStateChanged(ActionMode mode, int position,
long id, boolean checked) {
mode.setTitle(getListView().getCheckedItemCount() + " " + getLocalizedString(Key.selected));
/*if (getListView().getCheckedItemCount() == 1) {
TODO add ability to edit an item in the basket
mode.getMenu().findItem(R.id.edit_item).setVisible(true);
} else {
mode.getMenu().findItem(R.id.edit_item).setVisible(false);
}*/
mode.getMenu().findItem(R.id.edit_item).setVisible(false); //Todo Remove this if todo above is done
}

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {

switch (item.getItemId()) {
case R.id.delete_item:
SparseBooleanArray selectedItems = getListView().getCheckedItemPositions();
for (int i = (selectedItems.size() - 1); i >= 0; i--) {
if (selectedItems.valueAt(i)) {
((GroceryListAdapter) getListView().getAdapter()).remove(selectedItems.keyAt(i));
}
}
mode.finish();
}
return false;
}

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.getMenuInflater().inflate(R.menu.context_menu, menu);
return true;
}

@Override
public void onDestroyActionMode(ActionMode mode) {
}

@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
});

if (getListAdapter().getCount() == 0) {
checkoutButton.setVisibility(View.INVISIBLE);
}
Expand All @@ -101,6 +154,11 @@ public long getItemId(int position) {
return position;
}

public void remove(int position){
basket.remove(position);
notifyDataSetChanged();
}

@Override
public Object getItem(int position) {
return basket.get(position).toString();
Expand All @@ -118,31 +176,6 @@ public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView; // re-use an existing view, if one is available
if (view == null) {
view = LayoutInflater.from(context).inflate(R.layout.basket_item, parent, false);
ViewSwipeTouchListener swipper = ((SwipableListItem) view).getSwipeListener();
final View finalView = view;
swipper.addEventListener(new ViewSwipeTouchListener.EventListener() {
@Override
public void onSwipeGestureBegin() {
parent.requestDisallowInterceptTouchEvent(true);
}

@Override
public void onSwipeGestureEnd() {
parent.requestDisallowInterceptTouchEvent(false);
}

@Override
public void onItemSwipped() {
// If view has already been processed, do nothing
if (finalView.getParent() == null) {
return;
}
int p = ((ListView) parent).getPositionForView(finalView);
Basket basket = RoboVMWebService.getInstance().getBasket();
basket.remove(p);
notifyDataSetChanged();
}
});
}

((TextView) view.findViewById(R.id.productTitle)).setText(order.getProduct().getName());
Expand All @@ -151,7 +184,6 @@ public void onItemSwipped() {
((TextView) view.findViewById(R.id.productSize)).setText(order.getSize().getName());

ImageView orderImage = (ImageView) view.findViewById(R.id.productImage);
orderImage.setImageResource(R.drawable.product_image);

Images.setImageFromUrlAsync(orderImage, order.getColor().getImageUrls().get(0));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public View getMainContent() {
}

public View getSecondaryContent() {
return secondaryContent == null ? secondaryContent = findViewById(R.id.swipeAfter) : secondaryContent;
return null;
// The id 'swipeAfter' doesn't exist anymore
//return secondaryContent == null ? secondaryContent = findViewById(R.id.swipeAfter) : secondaryContent;
}

@Override
Expand Down
7 changes: 7 additions & 0 deletions android/src/main/res/drawable/list_item_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_activated="true" android:drawable="@drawable/btn_bg_pressed" />
<item android:state_pressed="true" android:drawable="@drawable/btn_bg_pressed" />
<item android:state_enabled="false" android:drawable="@drawable/btn_bg_inactive" />
<item android:drawable="@android:color/white" />
</selector>
47 changes: 4 additions & 43 deletions android/src/main/res/layout/basket_item.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<org.robovm.store.views.SwipableListItem xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/SwipeContainer">
<LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/colorBackground"
android:id="@+id/swipeContent">
android:background="@drawable/list_item_selector"
android:id="@+id/swipeContent"><!--?android:attr/colorBackground-->
<ImageView
android:src="@android:drawable/ic_menu_gallery"
android:layout_width="72dp"
Expand Down Expand Up @@ -73,39 +69,4 @@
android:textSize="11sp"
android:textColor="#8c8c8c"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/swipeAfter"
android:visibility="invisible">
<TextView
android:text="Item removed"
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/sizeView"
android:textSize="20sp"
android:gravity="center"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:id="@+id/view1"
android:background="#aaaaaa"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"/>
<Button
android:text="Cancel"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@null"
android:layout_gravity="center"
android:textAllCaps="true"
android:paddingLeft="16dp"
android:paddingRight="16dp"/>
</LinearLayout>
</org.robovm.store.views.SwipableListItem>
</LinearLayout>
7 changes: 4 additions & 3 deletions android/src/main/res/layout/product_cell.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
android:paddingBottom="8dp"
android:background="#ffffff"
android:paddingRight="8dp"/>
<View
<!--<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:id="@id/view1"
android:background="@drawable/discrete_shadow"/>
android:id="@+id/view1"
android:background="@drawable/discrete_shadow"/>-->
<!-- This causes issues, because the id view1 is already defined! This layout also seems to be unused.-->
</LinearLayout>
<LinearLayout
android:orientation="vertical"
Expand Down
14 changes: 14 additions & 0 deletions android/src/main/res/menu/context_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:id="@+id/delete_item"
android:icon="@android:drawable/ic_menu_delete"
android:showAsAction="ifRoom|withText"
android:title="Delete" />
<item
android:id="@+id/edit_item"
android:icon="@android:drawable/ic_menu_edit"
android:showAsAction="ifRoom|withText"
android:title="Edit" />
</menu>
2 changes: 1 addition & 1 deletion core/src/main/java/org/robovm/store/util/I18N.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class I18N {
public enum Key {
checkout, brag_twitter, done, order_complete, order_received, processing_order, try_again, tweet_text, error, order_placed, unexpected_error, first_name_required, last_name_required, address_required, city_required, zip_code_required, phone_number_required, country_required, ok, processing_title, could_not_log_in, verify_credentials, logging_in, log_in_title, please_wait, placing_order, add_to_basket, size, color, free, products_list_title, shipping_title, shipping_information, first_name, last_name, phone_number, address, city, postal_code, country, state, select_country, select_state, place_order, your_basket_title, street_adress_1, basket_empty, go_add_something, brag_to_friends, explanation_text, street_adress_2
checkout, brag_twitter, done, order_complete, order_received, processing_order, try_again, tweet_text, error, order_placed, unexpected_error, first_name_required, last_name_required, address_required, city_required, zip_code_required, phone_number_required, country_required, ok, processing_title, could_not_log_in, verify_credentials, logging_in, log_in_title, please_wait, placing_order, add_to_basket, size, color, free, products_list_title, shipping_title, shipping_information, first_name, last_name, phone_number, address, city, postal_code, country, state, select_country, select_state, place_order, your_basket_title, street_adress_1, basket_empty, go_add_something, brag_to_friends, explanation_text, street_adress_2, selected
}

public static String getLocalizedString(Key key) {
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/resources/StringsBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ street_adress_2 = Street Address 2
basket_empty = Your basket is empty
go_add_something = Go back and add something there.
brag_to_friends = Brag to Friends
explanation_text = A small task is required to get your free shirt.\nPlease add your RoboVM account email address to LoginFragment.java then revisit this screen.
explanation_text = A small task is required to get your free shirt.\nPlease add your RoboVM account email address to LoginFragment.java then revisit this screen.
selected = selected
3 changes: 2 additions & 1 deletion core/src/main/resources/StringsBundle_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ street_adress_2 = Adresse 2
basket_empty=Ihr Warenkorb ist leer
go_add_something = Geh zurück und füg etwas hinzu.
brag_to_friends = Prahle bei deinen Freunden
explanation_text = Erledige eine kleine Aufgabe, um ein kostenloses T-Shirt zu bekommen.\nFüg deine RoboVM Account E-Mail-Adresse zu LoginFragment.java hinzu und komm hierher zurück.
explanation_text = Erledige eine kleine Aufgabe, um ein kostenloses T-Shirt zu bekommen.\nFüg deine RoboVM Account E-Mail-Adresse zu LoginFragment.java hinzu und komm hierher zurück.
selected=ausgewählt
3 changes: 2 additions & 1 deletion core/src/main/resources/StringsBundle_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ street_adress_2 = Street Address 2
basket_empty = Your basket is empty
go_add_something = Go back and add something there.
brag_to_friends = Brag to Friends
explanation_text = A small task is required to get your free shirt.\nPlease add your RoboVM account email address to LoginFragment.java then revisit this screen.
explanation_text = A small task is required to get your free shirt.\nPlease add your RoboVM account email address to LoginFragment.java then revisit this screen.
selected=selected

0 comments on commit f5568e4

Please sign in to comment.