1
0
Fork 0

Health don't updating after onResume

This commit is contained in:
Carlos Galindo 2015-02-23 12:48:00 +01:00
parent 2501b899fd
commit 20e37b935b
4 changed files with 88 additions and 85 deletions

View file

@ -1,4 +1,4 @@
package com.ddns.kauron.dungeonmanager;
package com.kauron.dungeonmanager;
import android.app.Application;
import android.test.ApplicationTestCase;

View file

@ -40,20 +40,20 @@ public class HealthDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(com.ddns.kauron.dungeonmanager.R.string.new_energies_message)
.setTitle(com.ddns.kauron.dungeonmanager.R.string.new_energies)
.setPositiveButton(com.ddns.kauron.dungeonmanager.R.string.me, new DialogInterface.OnClickListener() {
builder.setMessage(com.kauron.dungeonmanager.R.string.new_energies_message)
.setTitle(com.kauron.dungeonmanager.R.string.new_energies)
.setPositiveButton(com.kauron.dungeonmanager.R.string.me, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mListener.heal(HealthDialogFragment.this, true);
}
})
.setNegativeButton(com.ddns.kauron.dungeonmanager.R.string.other, new DialogInterface.OnClickListener() {
.setNegativeButton(com.kauron.dungeonmanager.R.string.other, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
mListener.heal(HealthDialogFragment.this, false);
}
})
.setNeutralButton(com.ddns.kauron.dungeonmanager.R.string.cancel, new DialogInterface.OnClickListener() {
.setNeutralButton(com.kauron.dungeonmanager.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();

View file

@ -21,18 +21,18 @@ public class Introduction extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(com.ddns.kauron.dungeonmanager.R.layout.activity_introduction);
name = (EditText) findViewById(com.ddns.kauron.dungeonmanager.R.id.editNameIntro);
level = (EditText) findViewById(com.ddns.kauron.dungeonmanager.R.id.editLevelIntro);
setContentView(com.kauron.dungeonmanager.R.layout.activity_introduction);
name = (EditText) findViewById(com.kauron.dungeonmanager.R.id.editNameIntro);
level = (EditText) findViewById(com.kauron.dungeonmanager.R.id.editLevelIntro);
fue = (EditText) findViewById(com.ddns.kauron.dungeonmanager.R.id.FUE);
con = (EditText) findViewById(com.ddns.kauron.dungeonmanager.R.id.CON);
des = (EditText) findViewById(com.ddns.kauron.dungeonmanager.R.id.DES);
sab = (EditText) findViewById(com.ddns.kauron.dungeonmanager.R.id.SAB);
intel = (EditText) findViewById(com.ddns.kauron.dungeonmanager.R.id.INT);
car = (EditText) findViewById(com.ddns.kauron.dungeonmanager.R.id.CAR);
fue = (EditText) findViewById(com.kauron.dungeonmanager.R.id.FUE);
con = (EditText) findViewById(com.kauron.dungeonmanager.R.id.CON);
des = (EditText) findViewById(com.kauron.dungeonmanager.R.id.DES);
sab = (EditText) findViewById(com.kauron.dungeonmanager.R.id.SAB);
intel = (EditText) findViewById(com.kauron.dungeonmanager.R.id.INT);
car = (EditText) findViewById(com.kauron.dungeonmanager.R.id.CAR);
classSpinner = (Spinner) findViewById(com.ddns.kauron.dungeonmanager.R.id.classSpinner);
classSpinner = (Spinner) findViewById(com.kauron.dungeonmanager.R.id.classSpinner);
classSpinner.setAdapter(
new ArrayAdapter<>(
this,
@ -41,7 +41,7 @@ public class Introduction extends ActionBarActivity {
)
);
raceSpinner = (Spinner) findViewById(com.ddns.kauron.dungeonmanager.R.id.raceSpinner);
raceSpinner = (Spinner) findViewById(com.kauron.dungeonmanager.R.id.raceSpinner);
raceSpinner.setAdapter(
new ArrayAdapter<>(
this,
@ -55,7 +55,7 @@ public class Introduction extends ActionBarActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(com.ddns.kauron.dungeonmanager.R.menu.menu_introduction, menu);
getMenuInflater().inflate(com.kauron.dungeonmanager.R.menu.menu_introduction, menu);
return true;
}
@ -67,13 +67,13 @@ public class Introduction extends ActionBarActivity {
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == com.ddns.kauron.dungeonmanager.R.id.action_finish) {
if (id == com.kauron.dungeonmanager.R.id.action_finish) {
if(finished()) {
this.finish();
} else {
Toast.makeText(
getApplicationContext(),
com.ddns.kauron.dungeonmanager.R.string.missing_info_error,
com.kauron.dungeonmanager.R.string.missing_info_error,
Toast.LENGTH_LONG
).show();
}

View file

@ -31,7 +31,7 @@ public class MainActivity extends ActionBarActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(com.ddns.kauron.dungeonmanager.R.layout.activity_main);
setContentView(com.kauron.dungeonmanager.R.layout.activity_main);
undo = false;
invalidateOptionsMenu();
}
@ -39,13 +39,13 @@ public class MainActivity extends ActionBarActivity
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(com.ddns.kauron.dungeonmanager.R.menu.menu_main, menu);
getMenuInflater().inflate(com.kauron.dungeonmanager.R.menu.menu_main, menu);
return true;
}
@Override
public boolean onPrepareOptionsMenu (Menu menu) {
menu.findItem(com.ddns.kauron.dungeonmanager.R.id.action_undo).setVisible(undo);
menu.findItem(com.kauron.dungeonmanager.R.id.action_undo).setVisible(undo);
return true;
}
@ -59,10 +59,10 @@ public class MainActivity extends ActionBarActivity
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == com.ddns.kauron.dungeonmanager.R.id.action_cure) {
if (id == com.kauron.dungeonmanager.R.id.action_cure) {
showHealthDialog();
return true;
} else if (id == com.ddns.kauron.dungeonmanager.R.id.action_edit_basics) {
} else if (id == com.kauron.dungeonmanager.R.id.action_edit_basics) {
//TODO: try this startChildActivity()
SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE);
Intent intent = new Intent(this, Introduction.class);
@ -72,19 +72,19 @@ public class MainActivity extends ActionBarActivity
));
restoreData();
return true;
} else if (id == com.ddns.kauron.dungeonmanager.R.id.action_undo) {
} else if (id == com.kauron.dungeonmanager.R.id.action_undo) {
undo();
return true;
} else if (id == com.ddns.kauron.dungeonmanager.R.id.action_reset) {
} else if (id == com.kauron.dungeonmanager.R.id.action_reset) {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(getString(com.ddns.kauron.dungeonmanager.R.string.reset_confirmation_title));
alert.setMessage(getString(com.ddns.kauron.dungeonmanager.R.string.reset_confirmation));
alert.setTitle(getString(com.kauron.dungeonmanager.R.string.reset_confirmation_title));
alert.setMessage(getString(com.kauron.dungeonmanager.R.string.reset_confirmation));
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Toast.makeText(
getApplicationContext(),
com.ddns.kauron.dungeonmanager.R.string.message_reset,
com.kauron.dungeonmanager.R.string.message_reset,
Toast.LENGTH_LONG
).show();
getSharedPreferences("basics", MODE_PRIVATE).edit().clear().apply();
@ -146,14 +146,14 @@ public class MainActivity extends ActionBarActivity
if (hasCured == Player.NOT_CURED) {
Toast.makeText(
getApplicationContext(),
com.ddns.kauron.dungeonmanager.R.string.no_curative_efforts_error,
com.kauron.dungeonmanager.R.string.no_curative_efforts_error,
Toast.LENGTH_LONG
).show();
} else {
if(hasCured == Player.MAXED){
Toast.makeText(
getApplicationContext(),
com.ddns.kauron.dungeonmanager.R.string.maxed_curative,
com.kauron.dungeonmanager.R.string.maxed_curative,
Toast.LENGTH_LONG
).show();
}
@ -168,18 +168,18 @@ public class MainActivity extends ActionBarActivity
public void damage(final View view){
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(getString(com.ddns.kauron.dungeonmanager.R.string.suffer_damage));
alert.setTitle(getString(com.kauron.dungeonmanager.R.string.suffer_damage));
// Set an EditText view to get user input
final EditText input = new EditText(this);
input.setInputType(InputType.TYPE_CLASS_NUMBER);
input.setHint(com.ddns.kauron.dungeonmanager.R.string.suffer_damage_hint);
input.setHint(com.kauron.dungeonmanager.R.string.suffer_damage_hint);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Button pg = (Button) findViewById(com.ddns.kauron.dungeonmanager.R.id.pgCurrent);
Button pg = (Button) findViewById(com.kauron.dungeonmanager.R.id.pgCurrent);
try {
int preValue = Integer.parseInt(pg.getText().toString());
int damage = Integer.parseInt(input.getText().toString());
@ -212,26 +212,26 @@ public class MainActivity extends ActionBarActivity
private void healthStatusCheck() {
int status = player.getState();
int lastState = player.getLastState();
Button pg = (Button) findViewById(com.ddns.kauron.dungeonmanager.R.id.pgCurrent);
Button pg = (Button) findViewById(com.kauron.dungeonmanager.R.id.pgCurrent);
pg.setText(String.valueOf(player.getPg()));
if (status == Player.MUERTO) {
pg.setTextColor(Color.BLACK);
pg.setBackgroundColor(Color.RED);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(getString(com.ddns.kauron.dungeonmanager.R.string.reset_confirmation_title));
alert.setMessage(getString(com.ddns.kauron.dungeonmanager.R.string.reset_confirmation));
alert.setPositiveButton(com.ddns.kauron.dungeonmanager.R.string.action_undo, new DialogInterface.OnClickListener() {
alert.setTitle(getString(com.kauron.dungeonmanager.R.string.reset_confirmation_title));
alert.setMessage(getString(com.kauron.dungeonmanager.R.string.reset_confirmation));
alert.setPositiveButton(com.kauron.dungeonmanager.R.string.action_undo, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
undo();
}
});
alert.setNegativeButton(com.ddns.kauron.dungeonmanager.R.string.die, new DialogInterface.OnClickListener() {
alert.setNegativeButton(com.kauron.dungeonmanager.R.string.die, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Toast.makeText(
getApplicationContext(),
com.ddns.kauron.dungeonmanager.R.string.message_death,
com.kauron.dungeonmanager.R.string.message_death,
Toast.LENGTH_LONG
).show();
getSharedPreferences("basics", MODE_PRIVATE).edit().clear().apply();
@ -246,7 +246,7 @@ public class MainActivity extends ActionBarActivity
if(lastState != Player.SAME) {
Toast.makeText(
getApplicationContext(),
com.ddns.kauron.dungeonmanager.R.string.state_changed_debilitado,
com.kauron.dungeonmanager.R.string.state_changed_debilitado,
Toast.LENGTH_LONG
).show();
}
@ -256,13 +256,13 @@ public class MainActivity extends ActionBarActivity
if(lastState != Player.SAME) {
Toast.makeText(
getApplicationContext(),
com.ddns.kauron.dungeonmanager.R.string.state_changed_malherido,
com.kauron.dungeonmanager.R.string.state_changed_malherido,
Toast.LENGTH_LONG
).show();
}
} else {
pg.setTextColor(getResources().getColor(
com.ddns.kauron.dungeonmanager.R.color.abc_primary_text_material_dark
com.kauron.dungeonmanager.R.color.abc_primary_text_material_dark
));
pg.setBackgroundColor(android.R.drawable.btn_default);
}
@ -281,9 +281,9 @@ public class MainActivity extends ActionBarActivity
}
if(player == null) {
player = new Player(
p.getString("playerName", getString(com.ddns.kauron.dungeonmanager.R.string.adventurer_name)),
p.getString("className", getString(com.ddns.kauron.dungeonmanager.R.string.class_name)),
p.getString("raceName", getString(com.ddns.kauron.dungeonmanager.R.string.race_name)),
p.getString("playerName", getString(com.kauron.dungeonmanager.R.string.adventurer_name)),
p.getString("className", getString(com.kauron.dungeonmanager.R.string.class_name)),
p.getString("raceName", getString(com.kauron.dungeonmanager.R.string.race_name)),
p.getInt("level", 1),
new int[] {
p.getInt("fue", 10),
@ -296,9 +296,9 @@ public class MainActivity extends ActionBarActivity
new int[18],
new Power[4]);
} else {
player.setName(p.getString("playerName", getString(com.ddns.kauron.dungeonmanager.R.string.adventurer_name)));
player.setClassName(p.getString("className", getString(com.ddns.kauron.dungeonmanager.R.string.class_name)));
player.setRaceName(p.getString("raceName", getString(com.ddns.kauron.dungeonmanager.R.string.race_name)));
player.setName(p.getString("playerName", getString(com.kauron.dungeonmanager.R.string.adventurer_name)));
player.setClassName(p.getString("className", getString(com.kauron.dungeonmanager.R.string.class_name)));
player.setRaceName(p.getString("raceName", getString(com.kauron.dungeonmanager.R.string.race_name)));
player.setLevel(p.getInt("level", 1));
//TODO: restore pg
player.setAtk(new int[]{
@ -309,49 +309,52 @@ public class MainActivity extends ActionBarActivity
p.getInt("sab", 10),
p.getInt("car", 10),
});
}
player.setPg(p.getInt("pg", player.getMaxPg()));
healthStatusCheck();
updateCurativeString();
}
//set restored values to the respective fields
((TextView) findViewById(com.ddns.kauron.dungeonmanager.R.id.nameText)).setText(player.getName());
((TextView) findViewById(com.ddns.kauron.dungeonmanager.R.id.raceText)).setText(player.getRaceName());
((TextView) findViewById(com.ddns.kauron.dungeonmanager.R.id.classText)).setText(player.getClassName());
((TextView) findViewById(com.ddns.kauron.dungeonmanager.R.id.lvl)).setText(String.valueOf(player.getLevel()));
((TextView) findViewById(com.kauron.dungeonmanager.R.id.nameText)).setText(player.getName());
((TextView) findViewById(com.kauron.dungeonmanager.R.id.raceText)).setText(player.getRaceName());
((TextView) findViewById(com.kauron.dungeonmanager.R.id.classText)).setText(player.getClassName());
((TextView) findViewById(com.kauron.dungeonmanager.R.id.lvl)).setText(String.valueOf(player.getLevel()));
((Button) findViewById(com.ddns.kauron.dungeonmanager.R.id.pgCurrent)).setText(String.valueOf(player.getPg()));
((Button) findViewById(com.kauron.dungeonmanager.R.id.pgCurrent)).setText(String.valueOf(player.getPg()));
//attacks
((TextView) findViewById(com.ddns.kauron.dungeonmanager.R.id.FUE)).setText(
getString(com.ddns.kauron.dungeonmanager.R.string.FUE) + ":" + player.getFue()
((TextView) findViewById(com.kauron.dungeonmanager.R.id.FUE)).setText(
getString(com.kauron.dungeonmanager.R.string.FUE) + ":" + player.getFue()
);
((TextView) findViewById(com.ddns.kauron.dungeonmanager.R.id.CON)).setText(
getString(com.ddns.kauron.dungeonmanager.R.string.CON) + ":" + player.getCon()
((TextView) findViewById(com.kauron.dungeonmanager.R.id.CON)).setText(
getString(com.kauron.dungeonmanager.R.string.CON) + ":" + player.getCon()
);
((TextView) findViewById(com.ddns.kauron.dungeonmanager.R.id.DES)).setText(
getString(com.ddns.kauron.dungeonmanager.R.string.DES) + ":" + player.getDes()
((TextView) findViewById(com.kauron.dungeonmanager.R.id.DES)).setText(
getString(com.kauron.dungeonmanager.R.string.DES) + ":" + player.getDes()
);
((TextView) findViewById(com.ddns.kauron.dungeonmanager.R.id.INT)).setText(
getString(com.ddns.kauron.dungeonmanager.R.string.INT) + ":" + player.getInt()
((TextView) findViewById(com.kauron.dungeonmanager.R.id.INT)).setText(
getString(com.kauron.dungeonmanager.R.string.INT) + ":" + player.getInt()
);
((TextView) findViewById(com.ddns.kauron.dungeonmanager.R.id.SAB)).setText(
getString(com.ddns.kauron.dungeonmanager.R.string.SAB) + ":" + player.getSab()
((TextView) findViewById(com.kauron.dungeonmanager.R.id.SAB)).setText(
getString(com.kauron.dungeonmanager.R.string.SAB) + ":" + player.getSab()
);
((TextView) findViewById(com.ddns.kauron.dungeonmanager.R.id.CAR)).setText(
getString(com.ddns.kauron.dungeonmanager.R.string.CAR) + ":" + player.getCar()
((TextView) findViewById(com.kauron.dungeonmanager.R.id.CAR)).setText(
getString(com.kauron.dungeonmanager.R.string.CAR) + ":" + player.getCar()
);
//defenses
((TextView) findViewById(com.ddns.kauron.dungeonmanager.R.id.CA)).setText(
getString(com.ddns.kauron.dungeonmanager.R.string.CA) + ": " + player.getCa()
((TextView) findViewById(com.kauron.dungeonmanager.R.id.CA)).setText(
getString(com.kauron.dungeonmanager.R.string.CA) + ": " + player.getCa()
);
((TextView) findViewById(com.ddns.kauron.dungeonmanager.R.id.FORT)).setText(
getString(com.ddns.kauron.dungeonmanager.R.string.FORT) + ": " + player.getFort()
((TextView) findViewById(com.kauron.dungeonmanager.R.id.FORT)).setText(
getString(com.kauron.dungeonmanager.R.string.FORT) + ": " + player.getFort()
);
((TextView) findViewById(com.ddns.kauron.dungeonmanager.R.id.REF)).setText(
getString(com.ddns.kauron.dungeonmanager.R.string.REF) + ": " + player.getRef()
((TextView) findViewById(com.kauron.dungeonmanager.R.id.REF)).setText(
getString(com.kauron.dungeonmanager.R.string.REF) + ": " + player.getRef()
);
((TextView) findViewById(com.ddns.kauron.dungeonmanager.R.id.VOL)).setText(
getString(com.ddns.kauron.dungeonmanager.R.string.VOL) + ": " + player.getVol()
((TextView) findViewById(com.kauron.dungeonmanager.R.id.VOL)).setText(
getString(com.kauron.dungeonmanager.R.string.VOL) + ": " + player.getVol()
);
@ -368,22 +371,22 @@ public class MainActivity extends ActionBarActivity
// }
private void updateCurativeString() {
((TextView) findViewById(com.ddns.kauron.dungeonmanager.R.id.curativeEffortsText)).setText(
getString(com.ddns.kauron.dungeonmanager.R.string.curative_display_text1) + " " +
((TextView) findViewById(com.kauron.dungeonmanager.R.id.curativeEffortsText)).setText(
getString(com.kauron.dungeonmanager.R.string.curative_display_text1) + " " +
player.getCurativeEfforts() + " " +
getString(com.ddns.kauron.dungeonmanager.R.string.curative_display_text2) + " " +
getString(com.kauron.dungeonmanager.R.string.curative_display_text2) + " " +
player.getMaxCurativeEfforts() + " " +
getString(com.ddns.kauron.dungeonmanager.R.string.curative_display_text3)
getString(com.kauron.dungeonmanager.R.string.curative_display_text3)
);
}
private void undo() {
String message = "";
if(undoObject == CURRENT_PG){
((Button) findViewById(com.ddns.kauron.dungeonmanager.R.id.pgCurrent)).setText(String.valueOf(undoPreviousValue));
((Button) findViewById(com.kauron.dungeonmanager.R.id.pgCurrent)).setText(String.valueOf(undoPreviousValue));
player.setPg(undoPreviousValue);
undoObject = NULL;
message = getString(com.ddns.kauron.dungeonmanager.R.string.action_undo_current_pg);
message = getString(com.kauron.dungeonmanager.R.string.action_undo_current_pg);
}
Toast.makeText(
getApplicationContext(),