Skip to content

Commit

Permalink
#604 Sort trades and decks alphabetically
Browse files Browse the repository at this point in the history
Remove redundant casts
  • Loading branch information
AEFeinstein committed Jan 29, 2023
1 parent 16fe9b6 commit f8e5b7f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected void onCreate(Bundle savedInstanceState) {
/* Build the dialog */
MaterialDialog.Builder adb = new MaterialDialog.Builder(this);
adb
.items((CharSequence[]) mLaunchers)
.items(mLaunchers)
.alwaysCallMultiChoiceCallback()
.itemsCallbackMultiChoice(mSelectedIndices, (dialog, which, text) -> {
mSelectedIndices = which;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.gelakinetic.mtgfam.helpers.tcgp.MarketPriceInfo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -291,10 +292,13 @@ protected void onClick(ExpansionImageHelper.ExpansionImageData data) {
return DontShowDialog();
}

/* Sort alphabetically for convenience */
Arrays.sort(deckNames, String.CASE_INSENSITIVE_ORDER);

return new MaterialDialog.Builder(this.getParentCardViewFragment().mActivity)
.title(R.string.decklist_select_dialog_title)
.negativeText(R.string.dialog_cancel)
.items((CharSequence[]) deckNames)
.items(deckNames)
.itemsCallback((dialog, itemView, position, text) -> {

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.gelakinetic.mtgfam.helpers.tcgp.MarketPriceInfo;

import java.io.File;
import java.util.Arrays;
import java.util.Objects;

/**
Expand Down Expand Up @@ -190,10 +191,13 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
return DontShowDialog();
}

/* Sort deck names for convenience */
Arrays.sort(deckNames, String.CASE_INSENSITIVE_ORDER);

return new MaterialDialog.Builder(this.requireActivity())
.title(R.string.decklist_select_dialog_title)
.negativeText(R.string.dialog_cancel)
.items((CharSequence[]) deckNames)
.items(deckNames)
.itemsCallback((dialog, itemView, position, text) -> {

if (!getParentDecklistFragment().getDecklistReadError()) {
Expand Down Expand Up @@ -230,10 +234,13 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
return DontShowDialog();
}

/* Sort alphabetically for convenience */
Arrays.sort(deckNames, String.CASE_INSENSITIVE_ORDER);

return new MaterialDialog.Builder(this.requireActivity())
.title(R.string.decklist_delete_dialog_title)
.negativeText(R.string.dialog_cancel)
.items((CharSequence[]) deckNames)
.items(deckNames)
.itemsCallback((dialog, itemView, position, text) -> {

File toDelete = new File(getActivity().getFilesDir(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {

return new MaterialDialog.Builder(getActivity())
.title(R.string.gathering_delete)
.items((CharSequence[]) dProperNames)
.items(dProperNames)
.itemsCallback((dialog, itemView, position, text) -> {
GatheringsIO.DeleteGathering(dfGatherings[position], getActivity().getFilesDir(),
getActivity());
Expand All @@ -196,7 +196,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {

return new MaterialDialog.Builder(requireActivity())
.title(R.string.life_counter_remove_player)
.items((CharSequence[]) aNames)
.items(aNames)
.itemsCallback((dialog, itemView, position, text) -> {
getParentGatheringsFragment().mLinearLayout.removeViewAt(position);
getActivity().invalidateOptionsMenu();
Expand All @@ -221,7 +221,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {

return new MaterialDialog.Builder(getActivity())
.title(R.string.gathering_load)
.items((CharSequence[]) properNames)
.items(properNames)
.itemsCallback((dialog, itemView, position, text) -> {
getParentGatheringsFragment().mLinearLayout.removeAllViews();
getParentGatheringsFragment().mLargestPlayerNumber = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
/* Build the dialog */
builder.title(getString(R.string.life_counter_remove_player));

builder.items((CharSequence[]) names)
builder.items(names)
.itemsCallback((dialog, itemView, position, text) -> {
/* Remove the view from the GridLayout based on display mode, then remove the player
from the ArrayList and redraw. Also notify other players to remove this player from
Expand Down Expand Up @@ -144,7 +144,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
case DIALOG_CHANGE_DISPLAY: {

builder.title(R.string.pref_display_mode_title);
builder.items((CharSequence[]) getResources().getStringArray(R.array.display_array_entries))
builder.items(getResources().getStringArray(R.array.display_array_entries))
.itemsCallbackSingleChoice(getParentLifeCounterFragment().mDisplayMode,
(dialog, itemView, which, text) -> {
dialog.dismiss();
Expand Down Expand Up @@ -178,7 +178,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {

/* Set the AlertDialog title, items */
builder.title(R.string.life_counter_gathering_dialog_title);
builder.items((CharSequence[]) properNames)
builder.items(properNames)
.itemsCallback((dialog, itemView, position, text) -> {
/* Read the gathering from XML, clear and set all the info! changeDisplayMode() adds
the player Views */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.gelakinetic.mtgfam.helpers.database.FamiliarDbException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Objects;

/**
Expand Down Expand Up @@ -94,10 +95,13 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
return DontShowDialog();
}

/* Sort alphabetically for convenience */
Arrays.sort(deckNames, String.CASE_INSENSITIVE_ORDER);

return new MaterialDialog.Builder(this.requireActivity())
.title(R.string.decklist_select_dialog_title)
.negativeText(R.string.dialog_cancel)
.items((CharSequence[]) deckNames)
.items(deckNames)
.itemsCallback((dialog, itemView, position, text) -> {

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,13 @@ protected void onClick(ExpansionImageData data) {
return DontShowDialog();
}

/* Sort alphabetically for convenience */
Arrays.sort(tradeNames, String.CASE_INSENSITIVE_ORDER);

return new MaterialDialog.Builder(this.requireActivity())
.title(R.string.trader_load)
.negativeText(R.string.dialog_cancel)
.items((CharSequence[]) tradeNames)
.items(tradeNames)
.itemsCallback((dialog, itemView, position, text) -> {
/* First save any changes */
getParentTradeFragment().saveTrade(getParentTradeFragment().mCurrentTrade + TradeFragment.TRADE_EXTENSION);
Expand All @@ -590,10 +593,13 @@ protected void onClick(ExpansionImageData data) {
return DontShowDialog();
}

/* Sort alphabetically for convenience */
Arrays.sort(tradeNames, String.CASE_INSENSITIVE_ORDER);

return new MaterialDialog.Builder(this.requireActivity())
.title(R.string.trader_delete)
.negativeText(R.string.dialog_cancel)
.items((CharSequence[]) tradeNames)
.items(tradeNames)
.itemsCallback((dialog, itemView, position, text) -> {
File toDelete = new File(getActivity().getFilesDir(), tradeNames[position] +
TradeFragment.TRADE_EXTENSION);
Expand Down

0 comments on commit f8e5b7f

Please sign in to comment.