From 9aeb975ffb54b9e0d9a99fe62ca752543ca1aa33 Mon Sep 17 00:00:00 2001 From: kauron Date: Fri, 20 Feb 2015 23:36:01 +0100 Subject: [PATCH] Error Correction --- .idea/vcs.xml | 2 +- DungeonManager.iml | 4 +- app/app.iml | 4 +- .../kauron/dungeonmanager/Introduction.java | 55 ++++++++++----- .../kauron/dungeonmanager/MainActivity.java | 70 +++++++++++++++---- .../ddns/kauron/dungeonmanager/Player.java | 2 + .../main/res/layout/activity_introduction.xml | 56 +++++++++++---- app/src/main/res/layout/activity_main.xml | 13 ++-- app/src/main/res/values/strings.xml | 4 +- 9 files changed, 152 insertions(+), 58 deletions(-) diff --git a/.idea/vcs.xml b/.idea/vcs.xml index def6a6a..c80f219 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,7 +1,7 @@ - + diff --git a/DungeonManager.iml b/DungeonManager.iml index 2a02201..42f4ed5 100644 --- a/DungeonManager.iml +++ b/DungeonManager.iml @@ -1,5 +1,5 @@ - + @@ -7,7 +7,7 @@ - + diff --git a/app/app.iml b/app/app.iml index 9724666..e8f6572 100644 --- a/app/app.iml +++ b/app/app.iml @@ -1,5 +1,5 @@ - + @@ -9,6 +9,7 @@ + diff --git a/app/src/main/java/com/ddns/kauron/dungeonmanager/Introduction.java b/app/src/main/java/com/ddns/kauron/dungeonmanager/Introduction.java index f7118cb..651ad2a 100644 --- a/app/src/main/java/com/ddns/kauron/dungeonmanager/Introduction.java +++ b/app/src/main/java/com/ddns/kauron/dungeonmanager/Introduction.java @@ -11,7 +11,7 @@ import android.widget.Toast; public class Introduction extends ActionBarActivity { - EditText name, className, raceName, level, maxPg; + EditText name, className, raceName, level, maxPg, curativeEfforts, maxCurativeEfforts, pgE; @Override protected void onCreate(Bundle savedInstanceState) { @@ -23,6 +23,9 @@ public class Introduction extends ActionBarActivity { raceName = (EditText) findViewById(R.id.editRaceIntro); level = (EditText) findViewById(R.id.editLevelIntro); maxPg = (EditText) findViewById(R.id.editMaxPgIntro); + curativeEfforts = (EditText) findViewById(R.id.editEffortIntro); + maxCurativeEfforts = (EditText) findViewById(R.id.editMaxEffortIntro); + pgE = (EditText) findViewById(R.id.editPgIntro); } @@ -61,42 +64,58 @@ public class Introduction extends ActionBarActivity { private boolean finished() { SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE); SharedPreferences.Editor ed = p.edit(); + String nameString = name.getText().toString(); String classString = className.getText().toString(); String raceString = raceName.getText().toString(); - int levelInt = 0, maxPgInt = 0; - try { + + int levelInt = 0, maxPgInt = 0, pg = 0, curEff = 0, mCurEff = 0; + if (!level.getText().toString().isEmpty()) levelInt = Integer.parseInt(level.getText().toString()); - maxPgInt = Integer.parseInt(level.getText().toString()); - } catch (Exception e) {} + if (!maxPg.getText().toString().isEmpty()) + maxPgInt = Integer.parseInt(maxPg.getText().toString()); + if (!pgE.getText().toString().isEmpty()) + pg = Integer.parseInt(pgE.getText().toString()); + if (!curativeEfforts.getText().toString().isEmpty()) + curEff = Integer.parseInt(curativeEfforts.getText().toString()); + if (!maxCurativeEfforts.getText().toString().isEmpty()) + mCurEff = Integer.parseInt(maxCurativeEfforts.getText().toString()); + if(getIntent().getExtras().getBoolean("first_time")) { - if (!nameString.isEmpty() && + if ( + !nameString.isEmpty() && !classString.isEmpty() && !raceString.isEmpty() && levelInt != 0 && - maxPgInt != 0) { + maxPgInt != 0 && + pg != 0 && + curEff != 0 && + mCurEff != 0 + ) { //first save it all ed.putString("playerName", nameString); ed.putString("className", classString); ed.putString("raceName", raceString); - if(p.getInt("pg", Integer.MIN_VALUE) == Integer.MIN_VALUE) - ed.putInt("pg", maxPgInt); ed.putInt("level", levelInt); ed.putInt("maxPg", maxPgInt); + ed.putInt("pg", pg); + ed.putInt("maxCurativeEfforts", mCurEff); + ed.putInt("curativeEfforts", curEff); ed.putBoolean("saved", true); - ed.apply(); - return true; } else { return false; } } else { - if(!nameString.isEmpty()) ed.putString("playerName", nameString); - if(!classString.isEmpty()) ed.putString("className", classString); - if(!raceString.isEmpty()) ed.putString("raceName", raceString); - if(levelInt != 0) ed.putInt("level", levelInt); - if(maxPgInt != 0) ed.putInt("maxPg", maxPgInt); - ed.apply(); - return true; + if (!nameString.isEmpty()) ed.putString("playerName", nameString); + if (!classString.isEmpty()) ed.putString("className", classString); + if (!raceString.isEmpty()) ed.putString("raceName", raceString); + if (levelInt != 0) ed.putInt("level", levelInt); + if (maxPgInt != 0) ed.putInt("maxPg", maxPgInt); + if (pg != 0) ed.putInt("pg", pg); + if (mCurEff != 0) ed.putInt("maxCurativeEfforts", mCurEff); + if (curEff != 0) ed.putInt("curativeEfforts", curEff); } + ed.apply(); + return true; } } diff --git a/app/src/main/java/com/ddns/kauron/dungeonmanager/MainActivity.java b/app/src/main/java/com/ddns/kauron/dungeonmanager/MainActivity.java index f00d3e0..e976e51 100644 --- a/app/src/main/java/com/ddns/kauron/dungeonmanager/MainActivity.java +++ b/app/src/main/java/com/ddns/kauron/dungeonmanager/MainActivity.java @@ -9,6 +9,7 @@ import android.graphics.Color; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.text.InputType; +import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -63,6 +64,7 @@ public class MainActivity extends ActionBarActivity showHealthDialog(); return true; } else if (id == R.id.action_edit_basics) { + //TODO: try this startChildActivity() SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE); Intent intent = new Intent(this, Introduction.class); startActivity(intent.putExtra( @@ -103,6 +105,33 @@ public class MainActivity extends ActionBarActivity dialog.show(getFragmentManager(), "HealthDialogFragment"); } + @Override + protected void onPause() { + super.onPause(); + Log.e("UTIL", "pause"); + } + + @Override + protected void onResume() { + super.onResume(); + Log.e("UTIL", "resume"); + restoreData(); + } + + @Override + protected void onStop() { + super.onStop(); + Log.e("UTIL", "stop"); + saveData(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + saveData(); + Log.e("UTIL", "destroy"); + } + @Override public void curativeEffort(DialogFragment dialog, boolean uses) { int hasCured = player.recoverPg(Player.USE_CURATIVE_EFFORT, uses); @@ -182,19 +211,23 @@ public class MainActivity extends ActionBarActivity private void restoreData(){ SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE); //restore state - player = new Player( - p.getString("playerName", getString(R.string.adventurer_name)), - p.getString("className", getString(R.string.class_name)), - p.getString("raceName", getString(R.string.race_name)), - p.getInt("level", 1), - p.getInt("maxPg", 15), - p.getInt("pg", 15), - p.getInt("maxCurativeEfforts", 5), - p.getInt("curativeEfforts", 5), - new int[6], - new int[3], - new int[18], - new Power[4]); + if(player == null) { + player = new Player( + p.getString("playerName", getString(R.string.adventurer_name)), + p.getString("className", getString(R.string.class_name)), + p.getString("raceName", getString(R.string.race_name)), + p.getInt("level", 1), + p.getInt("maxPg", 15), + p.getInt("pg", 15), + p.getInt("maxCurativeEfforts", 5), + p.getInt("curativeEfforts", 5), + new int[6], + new int[3], + new int[18], + new Power[4]); + } else { + + } //set restored values to the respective fields ((TextView) findViewById(R.id.nameText)).setText(player.getName()); ((TextView) findViewById(R.id.raceText)).setText(player.getRaceName()); @@ -204,6 +237,15 @@ public class MainActivity extends ActionBarActivity } private void saveData() { - + getSharedPreferences("basics", MODE_PRIVATE).edit() + .putString("playerName", player.getName()) + .putString("className", player.getClassName()) + .putString("raceName", player.getRaceName()) + .putInt("level", player.getLevel()) + .putInt("maxPg", player.getMaxPg()) + .putInt("pg", player.getPg()) + .putInt("maxCurativeEfforts", player.getMaxCurativeEfforts()) + .putInt("curativeEfforts", player.getCurativeEfforts()) + .apply(); } } \ No newline at end of file diff --git a/app/src/main/java/com/ddns/kauron/dungeonmanager/Player.java b/app/src/main/java/com/ddns/kauron/dungeonmanager/Player.java index 269229a..7bea75c 100644 --- a/app/src/main/java/com/ddns/kauron/dungeonmanager/Player.java +++ b/app/src/main/java/com/ddns/kauron/dungeonmanager/Player.java @@ -60,6 +60,8 @@ public class Player { } + public int getMaxCurativeEfforts() {return maxCurativeEfforts;} + public int getCurativeEfforts() {return curativeEfforts;} public void setCurativeEffort(int curativeEfforts) {this.curativeEfforts = curativeEfforts;} diff --git a/app/src/main/res/layout/activity_introduction.xml b/app/src/main/res/layout/activity_introduction.xml index 1cf0a9c..e154f66 100644 --- a/app/src/main/res/layout/activity_introduction.xml +++ b/app/src/main/res/layout/activity_introduction.xml @@ -23,10 +23,10 @@ android:inputType="textPersonName" android:ems="10" android:id="@+id/editRaceIntro" - android:layout_below="@+id/editClassIntro" - android:layout_alignParentLeft="true" - android:layout_alignParentStart="true" - android:hint="@string/race_name" /> + android:hint="@string/race_name" + android:layout_below="@+id/editNameIntro" + android:layout_toRightOf="@+id/editClassIntro" + android:layout_toEndOf="@+id/editClassIntro" /> + android:layout_toRightOf="@+id/editNameIntro" + android:layout_alignRight="@+id/editRaceIntro" + android:layout_alignEnd="@+id/editRaceIntro" /> + android:width="70dp" + android:layout_below="@+id/editClassIntro" + android:layout_alignParentLeft="true" + android:layout_alignParentStart="true" + android:layout_toLeftOf="@+id/editMaxEffortIntro" + android:layout_toStartOf="@+id/editMaxEffortIntro" /> + android:layout_below="@+id/editRaceIntro" + android:layout_alignParentRight="true" + android:layout_alignParentEnd="true" /> + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 87bb4d0..de1bce2 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -23,12 +23,13 @@ android:layout_alignParentTop="true" android:layout_toLeftOf="@+id/pgCurrent" android:layout_toStartOf="@+id/pgCurrent" - android:id="@+id/linearLayout"> + android:id="@+id/linearLayout" + android:layout_alignBottom="@+id/pgCurrent"> DungeonManager Cure Undo + PG + Curative efforts Dungeons and Dragons Save Create event @@ -26,7 +28,7 @@ Done Level - Curative efforts + Max curative efforts Max PG You need to fill all the information You don\'t have any curative efforts left!