Skip to content

Commit

Permalink
#409 Save current trades and decklists before loading new ones
Browse files Browse the repository at this point in the history
Default mCurrentTrade to AUTOSAVE_NAME so it gets saved on transition properly
  • Loading branch information
AEFeinstein committed May 23, 2018
1 parent 9adafb4 commit ce88ea2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class TradeFragment extends FamiliarListFragment {
/* Right List and Company */
public final ArrayList<MtgCard> mListRight = new ArrayList<>();

public String mCurrentTrade = "";
public String mCurrentTrade = AUTOSAVE_NAME;

private int mOrderAddedIdx = 0;

Expand Down Expand Up @@ -428,7 +428,7 @@ public void onResume() {
super.onResume();

String tradeToLoad = PreferenceAdapter.getLastLoadedTrade(getContext());
if(!tradeToLoad.isEmpty()) {
if (!tradeToLoad.isEmpty()) {
mCurrentTrade = tradeToLoad;
loadTrade(mCurrentTrade + TRADE_EXTENSION);
} else {
Expand All @@ -443,7 +443,7 @@ public void onResume() {
public void onPause() {

super.onPause();
if(!mCurrentTrade.isEmpty()) {
if (!mCurrentTrade.isEmpty()) {
PreferenceAdapter.setLastLoadedTrade(getContext(), mCurrentTrade);
saveTrade(mCurrentTrade + TRADE_EXTENSION);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
.items((CharSequence[]) deckNames)
.itemsCallback((dialog, itemView, position, text) -> {

/* First save the current deck */
DecklistHelpers.WriteCompressedDecklist(
getActivity(),
getParentDecklistFragment().mCompressedDecklist,
getParentDecklistFragment().mCurrentDeck + DecklistFragment.DECK_EXTENSION
);

/* Then read the next one */
getParentDecklistFragment()
.readAndCompressDecklist(null, deckNames[position]);
getParentDecklistFragment().mCurrentDeck = deckNames[position];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,9 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
.negativeText(R.string.dialog_cancel)
.items((CharSequence[]) tradeNames)
.itemsCallback((dialog, itemView, position, text) -> {
/* Load the trade, set the current trade name */
/* First save any changes */
getParentTradeFragment().saveTrade(getParentTradeFragment().mCurrentTrade + TradeFragment.TRADE_EXTENSION);
/* Then load the trade, set the current trade name */
getParentTradeFragment().loadTrade(tradeNames[position] + TradeFragment.TRADE_EXTENSION);
getParentTradeFragment().mCurrentTrade = tradeNames[position];

Expand Down

0 comments on commit ce88ea2

Please sign in to comment.