Skip to content

Commit

Permalink
Refactor with Java 7/8 new syntaxes
Browse files Browse the repository at this point in the history
  • Loading branch information
h6ah4i committed Oct 7, 2018

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 04938f8 commit 0cc1325
Showing 24 changed files with 60 additions and 210 deletions.
Original file line number Diff line number Diff line change
@@ -56,26 +56,24 @@ public List<LibraryInfo> collect() {

// sort numerically
final Pattern p = Pattern.compile("^([0-9]+).*$");
Arrays.sort(dirs, new Comparator<String>() {
public int compare(String s1, String s2) {
try {
Matcher m1 = p.matcher(s1);
Matcher m2 = p.matcher(s2);
if (m1.find() && m2.find()) {
int n1 = Integer.parseInt(m1.group(1));
int n2 = Integer.parseInt(m2.group(1));

if (n1 == n2) {
return s1.compareTo(s2);
}

return n1 - n2;
} else {
Arrays.sort(dirs, (s1, s2) -> {
try {
Matcher m1 = p.matcher(s1);
Matcher m2 = p.matcher(s2);
if (m1.find() && m2.find()) {
int n1 = Integer.parseInt(m1.group(1));
int n2 = Integer.parseInt(m2.group(1));

if (n1 == n2) {
return s1.compareTo(s2);
}
} catch (RuntimeException e) {

return n1 - n2;
} else {
return s1.compareTo(s2);
}
} catch (RuntimeException e) {
return s1.compareTo(s2);
}
});

Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ public ExampleExpandableDataProvider() {
children.add(new ConcreteChildData(childId, childText));
}

mData.add(new Pair<GroupData, List<ChildData>>(group, children));
mData.add(new Pair<>(group, children));
}
}

Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ public ExampleSectionExpandableDataProvider() {
}
}

mData.add(new Pair<GroupData, List<ChildData>>(group, children));
mData.add(new Pair<>(group, children));
}
}

Original file line number Diff line number Diff line change
@@ -65,18 +65,8 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
} else {
builder.setMessage(getString(R.string.dialog_message_child_item_pinned, groupPosition, childPosition));
}
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
notifyItemPinnedDialogDismissed(true);
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> notifyItemPinnedDialogDismissed(true));
builder.setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.cancel());
builder.setCancelable(true);
return builder.create();
}
Original file line number Diff line number Diff line change
@@ -56,18 +56,8 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
final int itemPosition = getArguments().getInt(KEY_ITEM_POSITION, Integer.MIN_VALUE);

builder.setMessage(getString(R.string.dialog_message_item_pinned, itemPosition));
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
notifyItemPinnedDialogDismissed(true);
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> notifyItemPinnedDialogDismissed(true));
builder.setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.cancel());
builder.setCancelable(true);
return builder.create();
}
Original file line number Diff line number Diff line change
@@ -45,12 +45,9 @@ public void onCreate(Bundle savedInstanceState) {

RecyclerView recyclerView = findViewById(R.id.recycler_view);

OnListItemClickMessageListener clickListener = new OnListItemClickMessageListener() {
@Override
public void onItemClicked(String message) {
View container = findViewById(R.id.container);
Snackbar.make(container, message, Snackbar.LENGTH_SHORT).show();
}
OnListItemClickMessageListener clickListener = message -> {
View container = findViewById(R.id.container);
Snackbar.make(container, message, Snackbar.LENGTH_SHORT).show();
};

recyclerView.setLayoutManager(new LinearLayoutManager(this));
Original file line number Diff line number Diff line change
@@ -152,12 +152,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
MenuItem menuSwitchItem = menu.findItem(R.id.menu_switch_swap_mode);
CompoundButton actionView = menuSwitchItem.getActionView().findViewById(R.id.switch_view);

actionView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
updateItemMoveMode(isChecked);
}
});
actionView.setOnCheckedChangeListener((buttonView, isChecked) -> updateItemMoveMode(isChecked));
}

private void updateItemMoveMode(boolean swapMode) {
Original file line number Diff line number Diff line change
@@ -61,12 +61,7 @@ public void onItemRemoved(int position) {
R.string.snack_bar_text_item_removed,
Snackbar.LENGTH_LONG);

snackbar.setAction(R.string.snack_bar_action_undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
onItemUndoActionClicked();
}
});
snackbar.setAction(R.string.snack_bar_action_undo, v -> onItemUndoActionClicked());
snackbar.setActionTextColor(ContextCompat.getColor(this, R.color.snackbar_action_color_done));
snackbar.show();
}
Original file line number Diff line number Diff line change
@@ -87,18 +87,8 @@ public View getSwipeableContainerView() {

public DraggableSwipeableExampleAdapter(AbstractDataProvider dataProvider) {
mProvider = dataProvider;
mItemViewOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
onItemViewClick(v);
}
};
mSwipeableViewContainerOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
onSwipeableViewContainerClick(v);
}
};
mItemViewOnClickListener = v -> onItemViewClick(v);
mSwipeableViewContainerOnClickListener = v -> onSwipeableViewContainerClick(v);

// DraggableItemAdapter and SwipeableItemAdapter require stable ID, and also
// have to implement the getItemId() method appropriately.
Original file line number Diff line number Diff line change
@@ -43,12 +43,7 @@ private interface Expandable extends ExpandableItemConstants {

private RecyclerViewExpandableItemManager mExpandableItemManager;
private AbstractAddRemoveExpandableDataProvider mProvider;
private View.OnClickListener mItemOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
onClickItemView(v);
}
};
private View.OnClickListener mItemOnClickListener = v -> onClickItemView(v);

public static abstract class MyBaseViewHolder extends AbstractExpandableItemViewHolder {
public FrameLayout mContainer;
Original file line number Diff line number Diff line change
@@ -63,12 +63,7 @@ public void onGroupItemRemoved(int groupPosition) {
R.string.snack_bar_text_group_item_removed,
Snackbar.LENGTH_LONG);

snackbar.setAction(R.string.snack_bar_action_undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
onItemUndoActionClicked();
}
});
snackbar.setAction(R.string.snack_bar_action_undo, v -> onItemUndoActionClicked());
snackbar.setActionTextColor(ContextCompat.getColor(this, R.color.snackbar_action_color_done));
snackbar.show();
}
@@ -85,12 +80,7 @@ public void onChildItemRemoved(int groupPosition, int childPosition) {
R.string.snack_bar_text_child_item_removed,
Snackbar.LENGTH_LONG);

snackbar.setAction(R.string.snack_bar_action_undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
onItemUndoActionClicked();
}
});
snackbar.setAction(R.string.snack_bar_action_undo, v -> onItemUndoActionClicked());
snackbar.setActionTextColor(ContextCompat.getColor(this, R.color.snackbar_action_color_done));
snackbar.show();
}
Original file line number Diff line number Diff line change
@@ -129,18 +129,8 @@ public ExpandableDraggableSwipeableExampleAdapter(
AbstractExpandableDataProvider dataProvider) {
mExpandableItemManager = expandableItemManager;
mProvider = dataProvider;
mItemViewOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
onItemViewClick(v);
}
};
mSwipeableViewContainerOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
onSwipeableViewContainerClick(v);
}
};
mItemViewOnClickListener = v -> onItemViewClick(v);
mSwipeableViewContainerOnClickListener = v -> onSwipeableViewContainerClick(v);

// ExpandableItemAdapter, ExpandableDraggableItemAdapter and ExpandableSwipeableItemAdapter
// require stable ID, and also have to implement the getGroupItemId()/getChildItemId() methods appropriately.
Original file line number Diff line number Diff line change
@@ -44,12 +44,9 @@ public void onCreate(Bundle savedInstanceState) {

setContentView(R.layout.activity_demo_minimal);

OnListItemClickMessageListener clickListener = new OnListItemClickMessageListener() {
@Override
public void onItemClicked(String message) {
View container = findViewById(R.id.container);
Snackbar.make(container, message, Snackbar.LENGTH_SHORT).show();
}
OnListItemClickMessageListener clickListener = message -> {
View container = findViewById(R.id.container);
Snackbar.make(container, message, Snackbar.LENGTH_SHORT).show();
};

RecyclerView recyclerView = findViewById(R.id.recycler_view);
Original file line number Diff line number Diff line change
@@ -43,12 +43,9 @@ public void onCreate(Bundle savedInstanceState) {

setContentView(R.layout.activity_demo_minimal);

OnListItemClickMessageListener clickListener = new OnListItemClickMessageListener() {
@Override
public void onItemClicked(String message) {
View container = findViewById(R.id.container);
Snackbar.make(container, message, Snackbar.LENGTH_SHORT).show();
}
OnListItemClickMessageListener clickListener = message -> {
View container = findViewById(R.id.container);
Snackbar.make(container, message, Snackbar.LENGTH_SHORT).show();
};

RecyclerView recyclerView = findViewById(R.id.recycler_view);
Original file line number Diff line number Diff line change
@@ -41,12 +41,9 @@ public void onCreate(Bundle savedInstanceState) {

setContentView(R.layout.activity_demo_minimal);

OnListItemClickMessageListener clickListener = new OnListItemClickMessageListener() {
@Override
public void onItemClicked(String message) {
View container = findViewById(R.id.container);
Snackbar.make(container, message, Snackbar.LENGTH_SHORT).show();
}
OnListItemClickMessageListener clickListener = message -> {
View container = findViewById(R.id.container);
Snackbar.make(container, message, Snackbar.LENGTH_SHORT).show();
};

RecyclerView recyclerView = findViewById(R.id.recycler_view);
Original file line number Diff line number Diff line change
@@ -62,12 +62,7 @@ public void onItemRemoved(int position) {
R.string.snack_bar_text_item_removed,
Snackbar.LENGTH_LONG);

snackbar.setAction(R.string.snack_bar_action_undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
onItemUndoActionClicked();
}
});
snackbar.setAction(R.string.snack_bar_action_undo, v -> onItemUndoActionClicked());
snackbar.setActionTextColor(ContextCompat.getColor(this, R.color.snackbar_action_color_done));
snackbar.show();
}
Original file line number Diff line number Diff line change
@@ -77,18 +77,8 @@ public View getSwipeableContainerView() {

public SwipeableExampleAdapter(AbstractDataProvider dataProvider) {
mProvider = dataProvider;
mItemViewOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
onItemViewClick(v);
}
};
mSwipeableViewContainerOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
onSwipeableViewContainerClick(v);
}
};
mItemViewOnClickListener = v -> onItemViewClick(v);
mSwipeableViewContainerOnClickListener = v -> onSwipeableViewContainerClick(v);

// SwipeableItemAdapter requires stable ID, and also
// have to implement the getItemId() method appropriately.
Original file line number Diff line number Diff line change
@@ -85,18 +85,8 @@ public View getSwipeableContainerView() {

public SwipeableWithButtonExampleAdapter(AbstractDataProvider dataProvider) {
mProvider = dataProvider;
mSwipeableViewContainerOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
onSwipeableViewContainerClick(v);
}
};
mUnderSwipeableViewButtonOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
onUnderSwipeableViewButtonClick(v);
}
};
mSwipeableViewContainerOnClickListener = v -> onSwipeableViewContainerClick(v);
mUnderSwipeableViewButtonOnClickListener = v -> onUnderSwipeableViewButtonClick(v);

// SwipeableItemAdapter requires stable ID, and also
// have to implement the getItemId() method appropriately.
Original file line number Diff line number Diff line change
@@ -62,12 +62,7 @@ public void onItemRemoved(int position) {
R.string.snack_bar_text_item_removed,
Snackbar.LENGTH_LONG);

snackbar.setAction(R.string.snack_bar_action_undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
onItemUndoActionClicked();
}
});
snackbar.setAction(R.string.snack_bar_action_undo, v -> onItemUndoActionClicked());
snackbar.setActionTextColor(ContextCompat.getColor(this, R.color.snackbar_action_color_done));
snackbar.show();
}
Original file line number Diff line number Diff line change
@@ -77,18 +77,8 @@ public View getSwipeableContainerView() {

public SwipeOnLongPressExampleAdapter(AbstractDataProvider dataProvider) {
mProvider = dataProvider;
mItemViewOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
onItemViewClick(v);
}
};
mSwipeableViewContainerOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
onSwipeableViewContainerClick(v);
}
};
mItemViewOnClickListener = v -> onItemViewClick(v);
mSwipeableViewContainerOnClickListener = v -> onSwipeableViewContainerClick(v);

// SwipeableItemAdapter requires stable ID, and also
// have to implement the getItemId() method appropriately.
Original file line number Diff line number Diff line change
@@ -62,12 +62,7 @@ public void onItemRemoved(int position) {
R.string.snack_bar_text_item_removed,
Snackbar.LENGTH_LONG);

snackbar.setAction(R.string.snack_bar_action_undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
onItemUndoActionClicked();
}
});
snackbar.setAction(R.string.snack_bar_action_undo, v -> onItemUndoActionClicked());
snackbar.setActionTextColor(ContextCompat.getColor(this, R.color.snackbar_action_color_done));
snackbar.show();
}
Loading

0 comments on commit 0cc1325

Please sign in to comment.