1
0
Fork 0

Welcome: error with Player import

This commit is contained in:
kauron 2015-07-21 00:58:36 +02:00
parent da6de00c5a
commit fccbca7dcc

View file

@ -95,7 +95,7 @@ public class Welcome extends ActionBarActivity {
Gson gson = new Gson(); Gson gson = new Gson();
String imp = input.getText().toString(); String imp = input.getText().toString();
Player player = gson Player player = gson
.fromJson(imp.substring(0, imp.indexOf(SEPARATOR)), Player.class); .fromJson(imp/*.substring(0, imp.indexOf(SEPARATOR))*/, Player.class);
p.edit().putString( p.edit().putString(
"player" + p.getInt("players", 0), "player" + p.getInt("players", 0),
player.getName()) player.getName())
@ -104,22 +104,22 @@ public class Welcome extends ActionBarActivity {
getSharedPreferences(player.getName(), MODE_PRIVATE) getSharedPreferences(player.getName(), MODE_PRIVATE)
); );
String errors = ""; String errors = "";
while (imp.length() != 1) { // while (imp.length() != 1) {
int powers = p.getInt("powers", 0); // int powers = p.getInt("powers", 0);
imp = imp.substring(imp.indexOf(SEPARATOR) + 1); // imp = imp.substring(imp.indexOf(SEPARATOR) + 1);
Power power = gson // Power power = gson
.fromJson(imp.substring(0, imp.indexOf(SEPARATOR)), Power.class); // .fromJson(imp.substring(0, imp.indexOf(SEPARATOR)), Power.class);
boolean match = false; // boolean match = false;
for (int i = 0; i < powers; i++) // for (int i = 0; i < powers; i++)
if (power.getName().equals(p.getString("power" + i, ""))) // if (power.getName().equals(p.getString("power" + i, "")))
match = true; // match = true;
if (!match) { // if (!match) {
p.edit().putString("power" + powers, power.getName()).apply(); // p.edit().putString("power" + powers, power.getName()).apply();
power.saveToPreferences(getSharedPreferences(power.getName(), MODE_PRIVATE)); // power.saveToPreferences(getSharedPreferences(power.getName(), MODE_PRIVATE));
} else { // } else {
errors += String.format(getString(R.string.power_already_exists), power.getName()); // errors += String.format(getString(R.string.power_already_exists), power.getName());
} // }
} // }
if (errors.isEmpty()) errors = getString(R.string.import_completed); if (errors.isEmpty()) errors = getString(R.string.import_completed);
SnackbarManager.show(Snackbar.with(activity).text(errors)); SnackbarManager.show(Snackbar.with(activity).text(errors));
load(); load();