From 3b9fc620b449ce2a9747fc125fb7a48bdee2031e Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Fri, 24 Apr 2015 13:41:52 +0200 Subject: [PATCH] Fixed power editing saving --- .idea/misc.xml | 2 +- .../kauron/dungeonmanager/AttackAdapter.java | 5 ++- .../com/kauron/dungeonmanager/Player.java | 3 +- .../kauron/dungeonmanager/PowerEditor.java | 10 ++--- .../com/kauron/dungeonmanager/ShowPlayer.java | 41 ++++++++++--------- .../com/kauron/dungeonmanager/Welcome.java | 8 ++-- .../main/res/layout/activity_power_editor.xml | 1 + app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 9 files changed, 40 insertions(+), 32 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index b0c0cbc..4eca83f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,7 +13,7 @@ - + diff --git a/app/src/main/java/com/kauron/dungeonmanager/AttackAdapter.java b/app/src/main/java/com/kauron/dungeonmanager/AttackAdapter.java index 7a8212a..a292127 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/AttackAdapter.java +++ b/app/src/main/java/com/kauron/dungeonmanager/AttackAdapter.java @@ -38,7 +38,10 @@ class AttackAdapter extends ArrayAdapter { ((TextView) mView.findViewById(R.id.frequency)).setText(attack.getFrequencyString()); ((TextView) mView.findViewById(R.id.extra)).setText(attack.getRangeString() + " " + attack.getDistance()); mView.setBackgroundColor(attack.getFreqColor(getContext())); - mView.getBackground().setAlpha((position % 2) * 127 + 128); + if (attack.isUsed()) + mView.getBackground().setAlpha(0); + else + mView.getBackground().setAlpha((position % 2) * 127 + 128); } return mView; } diff --git a/app/src/main/java/com/kauron/dungeonmanager/Player.java b/app/src/main/java/com/kauron/dungeonmanager/Player.java index bd1ccd1..6afe9e8 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/Player.java +++ b/app/src/main/java/com/kauron/dungeonmanager/Player.java @@ -109,9 +109,8 @@ class Player implements Serializable { private int classInt, raceInt; private String name; private int level; - //TODO: use dice dialogs private int[] atk, def; - //TODO: implement fully operational powers displayed as cards + //TODO: implement fully operational powers (die rolling) Player (SharedPreferences p) { this.name = p.getString(NAME, "Player"); diff --git a/app/src/main/java/com/kauron/dungeonmanager/PowerEditor.java b/app/src/main/java/com/kauron/dungeonmanager/PowerEditor.java index 709c4a0..b6538cc 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/PowerEditor.java +++ b/app/src/main/java/com/kauron/dungeonmanager/PowerEditor.java @@ -99,13 +99,12 @@ public class PowerEditor extends ActionBarActivity { public void saveClick(View view) { - //TODO: change strings per resources boolean readyToSave = true; for ( int i = 0; i < edits.length; i++ ) { String s = edits[i].getText().toString().trim(); if (s.length() == 0) { - edits[i].setError("This field is required"); + edits[i].setError(getString(R.string.required)); readyToSave = false; } else { strings[i] = s; @@ -132,14 +131,13 @@ public class PowerEditor extends ActionBarActivity { for (int i = 0; i < powers; i++) { if (p.getString("power" + power, "").equals(saveName)) saveName += "2"; } + p.edit().putString("power" + powers, saveName) + .putInt("powers", powers + 1) + .apply(); } else { saveName = originalName; } - p.edit().putString("power" + powers, saveName) - .putInt("powers", powers + 1) - .apply(); - SharedPreferences.Editor ed = getSharedPreferences( saveName, MODE_PRIVATE).edit(); for (int i = 0; i < strings.length; i++) diff --git a/app/src/main/java/com/kauron/dungeonmanager/ShowPlayer.java b/app/src/main/java/com/kauron/dungeonmanager/ShowPlayer.java index 0807bfc..3e0f990 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/ShowPlayer.java +++ b/app/src/main/java/com/kauron/dungeonmanager/ShowPlayer.java @@ -460,13 +460,14 @@ public class ShowPlayer extends ActionBarActivity { int n = p.getInt("powers",0); int elements = 0; ListView attackList = (ListView) findViewById(R.id.attackList); - AttackAdapter adapter = (AttackAdapter) attackList.getAdapter(); + final AttackAdapter adapter = (AttackAdapter) attackList.getAdapter(); if ( adapter != null ) elements = adapter.getCount(); if ( elements < n && adapter != null ) { for ( int i = elements; i < n; i++ ) { SharedPreferences sav = getSharedPreferences(p.getString("power" + i, ""), MODE_PRIVATE); + //TODO: solve error when closing the editor adapter.add( new Power ( sav ) ); } } else if ( n != 0 ) { @@ -499,18 +500,18 @@ public class ShowPlayer extends ActionBarActivity { View nameText = dialog.findViewById(R.id.nameText); int color = power.getFreqColor(getApplicationContext()); nameText.setBackgroundColor(color); - //TODO: fix the title gap - ((TextView) nameText) .setText(power.getName()); - ((TextView) dialog.findViewById(R.id.typeText)) .setText(power.getTypeString()); - ((TextView) dialog.findViewById(R.id.rangeText)) .setText(power.getRangeString() + " "); - ((TextView) dialog.findViewById(R.id.freqText)) .setText(power.getFrequencyString()); - ((TextView) dialog.findViewById(R.id.keywordsText)) .setText(power.getKeywords()); - ((TextView) dialog.findViewById(R.id.distanceText)) .setText(String.valueOf(power.getDistance())); + + ((TextView) nameText).setText(power.getName()); + ((TextView) dialog.findViewById(R.id.typeText)).setText(power.getTypeString()); + ((TextView) dialog.findViewById(R.id.rangeText)).setText(power.getRangeString() + " "); + ((TextView) dialog.findViewById(R.id.freqText)).setText(power.getFrequencyString()); + ((TextView) dialog.findViewById(R.id.keywordsText)).setText(power.getKeywords()); + ((TextView) dialog.findViewById(R.id.distanceText)).setText(String.valueOf(power.getDistance())); ((TextView) dialog.findViewById(R.id.objectiveText)).setText(power.getObjective()); ((TextView) dialog.findViewById(R.id.impactText)).setText(power.getImpact()); - ((TextView) dialog.findViewById(R.id.otherText)) .setText(power.getOther()); + ((TextView) dialog.findViewById(R.id.otherText)).setText(power.getOther()); - String[] attack = getResources().getStringArray(R.array.attack_array); + String[] attack = getResources().getStringArray(R.array.attack_array); String[] defense = getResources().getStringArray(R.array.defense_array); ((TextView) dialog.findViewById(R.id.attackText)).setText(attack[power.getAtk()] + " " + getResources().getString(R.string.vs) @@ -519,15 +520,17 @@ public class ShowPlayer extends ActionBarActivity { Button useButton = (Button) dialog.findViewById(R.id.useButton); useButton.setBackgroundColor(color); useButton.setTextColor(getResources().getColor(R.color.white)); - useButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - //TODO: use power - Toast.makeText(getApplicationContext(), "Power used!", Toast.LENGTH_LONG).show(); - power.use(); - } - }); - //TODO: edit power + if (power.isUsed()) { + useButton.getBackground().setAlpha(0); + useButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //TODO: use power + Toast.makeText(getApplicationContext(), "Power used!", Toast.LENGTH_LONG).show(); + power.use(); + } + }); + } dialog.show(); } }); diff --git a/app/src/main/java/com/kauron/dungeonmanager/Welcome.java b/app/src/main/java/com/kauron/dungeonmanager/Welcome.java index d72d980..47ca964 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/Welcome.java +++ b/app/src/main/java/com/kauron/dungeonmanager/Welcome.java @@ -106,7 +106,7 @@ public class Welcome extends ActionBarActivity { @Override public boolean onItemLongClick(final AdapterView parent, View view, final int position, long id) { AlertDialog.Builder alert = new AlertDialog.Builder(activity); - alert.setItems(new String[]{"Delete", "Edit"}, new DialogInterface.OnClickListener() { + alert.setItems(new String[]{"Delete", "Edit", "Export"}, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if ( which == 0 ) { @@ -131,11 +131,13 @@ public class Welcome extends ActionBarActivity { load(); ed.remove("player" + (max - 1)).apply(); } - } else { - //edit the item + } else if (which == 1) { + //TODO: edit the player Toast.makeText( activity, "Editor not implemented yet", Toast.LENGTH_LONG) .show(); + } else { + //TODO: export as filesh } } }); diff --git a/app/src/main/res/layout/activity_power_editor.xml b/app/src/main/res/layout/activity_power_editor.xml index e811f96..aac5ed0 100644 --- a/app/src/main/res/layout/activity_power_editor.xml +++ b/app/src/main/res/layout/activity_power_editor.xml @@ -6,6 +6,7 @@ android:orientation="vertical"> + Reflejos Voluntad + Este campo es obligatorio \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5609c15..931a9c8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -105,6 +105,7 @@ One creature Power Editor Save player + This field is required Frequency