Fixed playerList, now the players can be deleted and added
Editor still missing
This commit is contained in:
parent
aebb20542e
commit
30515a5384
7 changed files with 211 additions and 103 deletions
|
@ -114,9 +114,6 @@ public class Introduction extends ActionBarActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean finished() {
|
private boolean finished() {
|
||||||
SharedPreferences p = getSharedPreferences(Welcome.PREFERENCES, MODE_PRIVATE);
|
|
||||||
int i = p.getInt("players", 0);
|
|
||||||
SharedPreferences.Editor ed = getSharedPreferences("player" + i, MODE_PRIVATE).edit();
|
|
||||||
String nameString = name.getText().toString().trim();
|
String nameString = name.getText().toString().trim();
|
||||||
int classInt = classSpinner.getSelectedItemPosition();
|
int classInt = classSpinner.getSelectedItemPosition();
|
||||||
int raceInt = raceSpinner.getSelectedItemPosition();
|
int raceInt = raceSpinner.getSelectedItemPosition();
|
||||||
|
@ -139,19 +136,28 @@ public class Introduction extends ActionBarActivity {
|
||||||
if (!this.sab.getText().toString().isEmpty())
|
if (!this.sab.getText().toString().isEmpty())
|
||||||
sab = Integer.parseInt(this.sab.getText().toString());
|
sab = Integer.parseInt(this.sab.getText().toString());
|
||||||
|
|
||||||
if(first) {
|
// if(first) {
|
||||||
if (
|
if (
|
||||||
!nameString.isEmpty() &&
|
!nameString.isEmpty() &&
|
||||||
classInt != Player.NULL &&
|
classInt != Player.NULL &&
|
||||||
raceInt != Player.NULL &&
|
raceInt != Player.NULL &&
|
||||||
pxInt != -1 &&
|
pxInt != -1 &&
|
||||||
car != 0 &&
|
car != 0 &&
|
||||||
fue != 0 &&
|
fue != 0 &&
|
||||||
con != 0 &&
|
con != 0 &&
|
||||||
des != 0 &&
|
des != 0 &&
|
||||||
intel != 0 &&
|
intel != 0 &&
|
||||||
sab != 0
|
sab != 0
|
||||||
) {
|
) {
|
||||||
|
SharedPreferences p = getSharedPreferences(Welcome.PREFERENCES, MODE_PRIVATE);
|
||||||
|
int i = p.getInt("players", 0);
|
||||||
|
String saveName = nameString;
|
||||||
|
for (int j = 0; j < i; j++) {
|
||||||
|
saveName += p.getString("player" + j, "").equals(saveName) ? "2" : "";
|
||||||
|
}
|
||||||
|
p.edit().putString("player" + i, saveName).putInt("players", i + 1).apply();
|
||||||
|
SharedPreferences.Editor ed = getSharedPreferences(saveName, MODE_PRIVATE).edit();
|
||||||
|
|
||||||
//first save it all
|
//first save it all
|
||||||
ed.putString("playerName", nameString);
|
ed.putString("playerName", nameString);
|
||||||
ed.putInt("classInt", classInt);
|
ed.putInt("classInt", classInt);
|
||||||
|
@ -164,25 +170,25 @@ public class Introduction extends ActionBarActivity {
|
||||||
ed.putInt("sab", sab);
|
ed.putInt("sab", sab);
|
||||||
ed.putInt("con", con);
|
ed.putInt("con", con);
|
||||||
ed.putInt("des", des);
|
ed.putInt("des", des);
|
||||||
|
//TEMP
|
||||||
|
ed.apply();
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
// } else {
|
||||||
if (!nameString.isEmpty()) ed.putString("playerName", nameString);
|
// if (!nameString.isEmpty()) ed.putString("playerName", nameString);
|
||||||
if (classInt != Player.NULL) ed.putInt("classInt", classInt);
|
// if (classInt != Player.NULL) ed.putInt("classInt", classInt);
|
||||||
if (raceInt != Player.NULL) ed.putInt("raceInt", raceInt);
|
// if (raceInt != Player.NULL) ed.putInt("raceInt", raceInt);
|
||||||
if (pxInt != -1) ed.putInt("px", pxInt);
|
// if (pxInt != -1) ed.putInt("px", pxInt);
|
||||||
|
//
|
||||||
|
// if (fue != 0) ed.putInt("fue", fue);
|
||||||
|
// if (car != 0) ed.putInt("car", car);
|
||||||
|
// if (intel != 0) ed.putInt("int", intel);
|
||||||
|
// if (sab != 0) ed.putInt("sab", sab);
|
||||||
|
// if (con != 0) ed.putInt("con", con);
|
||||||
|
// if (des != 0) ed.putInt("des", des);
|
||||||
|
// }
|
||||||
|
|
||||||
if (fue != 0) ed.putInt("fue", fue);
|
|
||||||
if (car != 0) ed.putInt("car", car);
|
|
||||||
if (intel != 0) ed.putInt("int", intel);
|
|
||||||
if (sab != 0) ed.putInt("sab", sab);
|
|
||||||
if (con != 0) ed.putInt("con", con);
|
|
||||||
if (des != 0) ed.putInt("des", des);
|
|
||||||
}
|
|
||||||
ed.apply();
|
|
||||||
getSharedPreferences(Welcome.PREFERENCES, MODE_PRIVATE).edit()
|
|
||||||
.putInt("players", i + 1).apply();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.kauron.dungeonmanager;
|
package com.kauron.dungeonmanager;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
@ -44,10 +45,22 @@ public class MainActivity extends ActionBarActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
//Initializing activity (setting toolbar as actionbar)
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
p = getSharedPreferences("player" + getIntent().getIntExtra("player", 0), MODE_PRIVATE);
|
|
||||||
|
//Loading player
|
||||||
|
try{
|
||||||
|
String name = getSharedPreferences(Welcome.PREFERENCES, MODE_PRIVATE)
|
||||||
|
.getString("player" + getIntent().getIntExtra("player", 0), "null");
|
||||||
|
p = getSharedPreferences(name, MODE_PRIVATE);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Toast.makeText(getApplicationContext(), "Error loading character", Toast.LENGTH_LONG).show();
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Performing all the findViewById commands
|
||||||
xpBar = (ProgressBar) findViewById(R.id.xpBar);
|
xpBar = (ProgressBar) findViewById(R.id.xpBar);
|
||||||
curativeEffortsBar = (ProgressBar) findViewById(R.id.curativeEffortsBar);
|
curativeEffortsBar = (ProgressBar) findViewById(R.id.curativeEffortsBar);
|
||||||
pgBar = (ProgressBar) findViewById(R.id.pgBar);
|
pgBar = (ProgressBar) findViewById(R.id.pgBar);
|
||||||
|
@ -66,12 +79,8 @@ public class MainActivity extends ActionBarActivity {
|
||||||
curativeEffortsBar.getProgressDrawable()
|
curativeEffortsBar.getProgressDrawable()
|
||||||
.setColorFilter(getResources().getColor(R.color.surges_bar), PorterDuff.Mode.SRC_IN);
|
.setColorFilter(getResources().getColor(R.color.surges_bar), PorterDuff.Mode.SRC_IN);
|
||||||
undo = false;
|
undo = false;
|
||||||
//begin
|
|
||||||
restoreData();
|
restoreData();
|
||||||
pgUpdate();
|
|
||||||
ceUpdate();
|
|
||||||
pxUpdate();
|
|
||||||
//end
|
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,11 +93,12 @@ public class MainActivity extends ActionBarActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPrepareOptionsMenu (Menu menu) {
|
public boolean onPrepareOptionsMenu (Menu menu) {
|
||||||
menu.findItem(R.id.action_undo).setEnabled(undo);
|
MenuItem menuUndo = menu.findItem(R.id.action_undo);
|
||||||
|
menuUndo.setEnabled(undo);
|
||||||
if (undo)
|
if (undo)
|
||||||
menu.findItem(R.id.action_undo).getIcon().setAlpha(255);
|
menuUndo.getIcon().setAlpha(255);
|
||||||
else
|
else
|
||||||
menu.findItem(R.id.action_undo).getIcon().setAlpha(128);
|
menuUndo.getIcon().setAlpha(128);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +158,9 @@ public class MainActivity extends ActionBarActivity {
|
||||||
// Player.LEVEL_PX[player.getLevel() - 1],
|
// Player.LEVEL_PX[player.getLevel() - 1],
|
||||||
// true, player.getPx() - Player.LEVEL_PX[player.getLevel() - 1]
|
// true, player.getPx() - Player.LEVEL_PX[player.getLevel() - 1]
|
||||||
// );
|
// );
|
||||||
} catch(Exception e) {}
|
} catch(Exception e) {
|
||||||
|
Toast.makeText(getApplicationContext(), "There was an error leveling up", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
alert.show();
|
alert.show();
|
||||||
|
@ -337,17 +349,14 @@ public class MainActivity extends ActionBarActivity {
|
||||||
undo();
|
undo();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
final Activity activity = this;
|
||||||
alert.setNegativeButton(R.string.die, new DialogInterface.OnClickListener() {
|
alert.setNegativeButton(R.string.die, new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int whichButton) {
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
//TODO: fix snackbar on death
|
SnackbarManager.show(
|
||||||
Toast.makeText(getApplicationContext(),
|
Snackbar
|
||||||
R.string.message_death, Toast.LENGTH_LONG).show();
|
.with(activity)
|
||||||
// SnackbarManager.show(
|
.text(R.string.message_death)
|
||||||
// Snackbar
|
);
|
||||||
// .with(this)
|
|
||||||
// .text(R.string.message_death)
|
|
||||||
// );
|
|
||||||
p.edit().clear().apply();
|
p.edit().clear().apply();
|
||||||
restoreData();
|
restoreData();
|
||||||
}
|
}
|
||||||
|
@ -387,15 +396,6 @@ public class MainActivity extends ActionBarActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restoreData(){
|
private void restoreData(){
|
||||||
int i = getIntent().getIntExtra("player", 0);
|
|
||||||
if (!p.getBoolean("saved", false)) {
|
|
||||||
if (i == -1) {
|
|
||||||
Intent intent = new Intent(this, Introduction.class);
|
|
||||||
startActivity(intent.putExtra(
|
|
||||||
"first_time",
|
|
||||||
!p.getBoolean("saved", false)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
player = new Player(
|
player = new Player(
|
||||||
p.getString("playerName", getString(R.string.adventurer_name)),
|
p.getString("playerName", getString(R.string.adventurer_name)),
|
||||||
|
@ -481,7 +481,7 @@ public class MainActivity extends ActionBarActivity {
|
||||||
|
|
||||||
//defenses
|
//defenses
|
||||||
((TextView) findViewById(R.id.CA)).setText(
|
((TextView) findViewById(R.id.CA)).setText(
|
||||||
getString(R.string.CA) + ": " + player.getCa()
|
getString(R.string.CA) + ":" + player.getCa()
|
||||||
);
|
);
|
||||||
((TextView) findViewById(R.id.FORT)).setText(
|
((TextView) findViewById(R.id.FORT)).setText(
|
||||||
getString(R.string.FORT) + ":" + player.getFort()
|
getString(R.string.FORT) + ":" + player.getFort()
|
||||||
|
@ -490,7 +490,7 @@ public class MainActivity extends ActionBarActivity {
|
||||||
getString(R.string.REF) + ":" + player.getRef()
|
getString(R.string.REF) + ":" + player.getRef()
|
||||||
);
|
);
|
||||||
((TextView) findViewById(R.id.VOL)).setText(
|
((TextView) findViewById(R.id.VOL)).setText(
|
||||||
getString(R.string.VOL) + ": " + player.getVol()
|
getString(R.string.VOL) + ":" + player.getVol()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.kauron.dungeonmanager;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
|
||||||
|
public class PlayerDBHandler extends SQLiteOpenHelper {
|
||||||
|
|
||||||
|
private static final int DB_VERSION = 1;
|
||||||
|
private static final String DB_NAME = "dnd.db";
|
||||||
|
|
||||||
|
public static final String TABLE_PLAYERS = "players";
|
||||||
|
public static final String C_ID="_id", C_NAME="name", C_CLASS="class", C_RACE="race";
|
||||||
|
public static final String C_PG="pg", C_PG_MAX="pgMax", C_SURGES="surges", C_SURGES_MAX="surgesMax";
|
||||||
|
public static final String C_PX = "px", C_ATK = "atk", C_ABILITY = "ability", C_POWER_ID="powerID";
|
||||||
|
|
||||||
|
//TODO: complete class and implement database to save the players instead of sharedprefs
|
||||||
|
//TODO: not using it at the moment
|
||||||
|
public PlayerDBHandler(Context context, SQLiteDatabase.CursorFactory factory) {
|
||||||
|
super(context, DB_NAME, factory, DB_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(SQLiteDatabase db) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
|
db.execSQL("DROP TABLE IF EXISTS " + TABLE_PLAYERS);
|
||||||
|
onCreate(db);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPlayer(Player p) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updatePlayer (Player p) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deletePlayer (Player p) {
|
||||||
|
SQLiteDatabase db = getWritableDatabase();
|
||||||
|
db.execSQL(
|
||||||
|
"DELETE FROM " + TABLE_PLAYERS + " WTHERE " //TODO: complete
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,16 +1,21 @@
|
||||||
package com.kauron.dungeonmanager;
|
package com.kauron.dungeonmanager;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ListAdapter;
|
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
public class Welcome extends ActionBarActivity {
|
public class Welcome extends ActionBarActivity {
|
||||||
|
|
||||||
|
@ -18,6 +23,7 @@ public class Welcome extends ActionBarActivity {
|
||||||
|
|
||||||
private SharedPreferences p;
|
private SharedPreferences p;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -55,6 +61,7 @@ public class Welcome extends ActionBarActivity {
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: load all players with secondary constructor (except the ones created by introduction and haven't passed by MainActivity)
|
||||||
private void load() {
|
private void load() {
|
||||||
int n = p.getInt("players",0);
|
int n = p.getInt("players",0);
|
||||||
ListView playerList = (ListView) findViewById(R.id.listView);
|
ListView playerList = (ListView) findViewById(R.id.listView);
|
||||||
|
@ -64,50 +71,54 @@ public class Welcome extends ActionBarActivity {
|
||||||
elements = adapter.getCount();
|
elements = adapter.getCount();
|
||||||
if ( elements < n && adapter != null ) {
|
if ( elements < n && adapter != null ) {
|
||||||
playerList.setVisibility(View.VISIBLE);
|
playerList.setVisibility(View.VISIBLE);
|
||||||
|
findViewById(R.id.help_text).setVisibility(View.VISIBLE);
|
||||||
findViewById(R.id.no_players_text).setVisibility(View.GONE);
|
findViewById(R.id.no_players_text).setVisibility(View.GONE);
|
||||||
for ( int i = elements; i < n; i++ ) {
|
for ( int i = elements; i < n; i++ ) {
|
||||||
SharedPreferences sav = getSharedPreferences("player" + i, MODE_PRIVATE);
|
SharedPreferences sav = getSharedPreferences(p.getString("player" + i, ""), MODE_PRIVATE);
|
||||||
adapter.add(
|
if (sav.contains(Player.NAME))
|
||||||
new Player(
|
adapter.add(
|
||||||
sav.getString(Player.NAME, "player" + i),
|
new Player(
|
||||||
sav.getInt(Player.CLASS, 0),
|
sav.getString(Player.NAME, "player" + i),
|
||||||
sav.getInt(Player.RACE, 0),
|
sav.getInt(Player.CLASS, 0),
|
||||||
sav.getInt(Player.PX, 0),
|
sav.getInt(Player.RACE, 0),
|
||||||
new int[] {
|
sav.getInt(Player.PX, 0),
|
||||||
sav.getInt("fue", 10),
|
new int[] {
|
||||||
sav.getInt("con", 10),
|
sav.getInt("fue", 10),
|
||||||
sav.getInt("des", 10),
|
sav.getInt("con", 10),
|
||||||
sav.getInt("int", 10),
|
sav.getInt("des", 10),
|
||||||
sav.getInt("sab", 10),
|
sav.getInt("int", 10),
|
||||||
sav.getInt("car", 10)
|
sav.getInt("sab", 10),
|
||||||
},
|
sav.getInt("car", 10)
|
||||||
new int[18],
|
},
|
||||||
new Power[4]
|
new int[18],
|
||||||
));
|
new Power[4]
|
||||||
|
));
|
||||||
}
|
}
|
||||||
} else if ( n != 0 ) {
|
} else if ( n != 0 ) {
|
||||||
playerList.setVisibility(View.VISIBLE);
|
playerList.setVisibility(View.VISIBLE);
|
||||||
|
findViewById(R.id.help_text).setVisibility(View.VISIBLE);
|
||||||
findViewById(R.id.no_players_text).setVisibility(View.GONE);
|
findViewById(R.id.no_players_text).setVisibility(View.GONE);
|
||||||
Player[] players = new Player[n];
|
Player[] players = new Player[n];
|
||||||
for ( int i = 0; i < n; i++ ) {
|
for ( int i = 0; i < n; i++ ) {
|
||||||
//TODO: fill the information for the player creation
|
//TODO: fill the information for the player creation
|
||||||
SharedPreferences sav = getSharedPreferences("player" + i, MODE_PRIVATE);
|
SharedPreferences sav = getSharedPreferences(p.getString("player" + i, ""), MODE_PRIVATE);
|
||||||
players[i] = new Player(
|
if (sav.contains(Player.NAME))
|
||||||
sav.getString(Player.NAME, "player" + i),
|
players[i] = new Player(
|
||||||
sav.getInt(Player.CLASS, 0),
|
sav.getString(Player.NAME, "player" + i),
|
||||||
sav.getInt(Player.RACE, 0),
|
sav.getInt(Player.CLASS, 0),
|
||||||
sav.getInt(Player.PX, 0),
|
sav.getInt(Player.RACE, 0),
|
||||||
new int[] {
|
sav.getInt(Player.PX, 0),
|
||||||
sav.getInt("fue", 10),
|
new int[] {
|
||||||
sav.getInt("con", 10),
|
sav.getInt("fue", 10),
|
||||||
sav.getInt("des", 10),
|
sav.getInt("con", 10),
|
||||||
sav.getInt("int", 10),
|
sav.getInt("des", 10),
|
||||||
sav.getInt("sab", 10),
|
sav.getInt("int", 10),
|
||||||
sav.getInt("car", 10)
|
sav.getInt("sab", 10),
|
||||||
},
|
sav.getInt("car", 10)
|
||||||
new int[18],
|
},
|
||||||
new Power[4]
|
new int[18],
|
||||||
);
|
new Power[4]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
playerList.setAdapter(new PlayerAdapter(this, players));
|
playerList.setAdapter(new PlayerAdapter(this, players));
|
||||||
|
@ -120,8 +131,51 @@ public class Welcome extends ActionBarActivity {
|
||||||
).putExtra("player", position));
|
).putExtra("player", position));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
final ActionBarActivity activity = this;
|
||||||
|
playerList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||||
|
@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() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
if ( which == 0 ) {
|
||||||
|
//delete the item
|
||||||
|
String name = p.getString("player" + position, "");
|
||||||
|
if (name != null && !name.isEmpty()) {
|
||||||
|
getSharedPreferences(name, MODE_PRIVATE).edit().clear().apply();
|
||||||
|
Log.d("Tag", activity.getApplicationContext().getFilesDir().getParent()
|
||||||
|
+ File.separator + "shared_prefs" + File.separator + name + ".xml");
|
||||||
|
try {
|
||||||
|
if(!new File(activity.getApplicationContext().getFilesDir().getParent()
|
||||||
|
+ File.separator + "shared_prefs" + File.separator + name + ".xml").delete())
|
||||||
|
throw new Exception();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Toast.makeText(getApplicationContext(), "Error deleting player files", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
int max = p.getInt("players", 0);
|
||||||
|
SharedPreferences.Editor ed = p.edit();
|
||||||
|
for (int i = position; i < max - 1; i++)
|
||||||
|
ed.putString("player" + i, p.getString("player" + (i + 1), "max"));
|
||||||
|
ed.putInt("players", max - 1).apply();
|
||||||
|
load();
|
||||||
|
ed.remove("player" + (max - 1)).apply();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//edit the item
|
||||||
|
Toast.makeText(
|
||||||
|
activity, "Editor not implemented yet", Toast.LENGTH_LONG)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
alert.show();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
playerList.setVisibility(View.GONE);
|
playerList.setVisibility(View.GONE);
|
||||||
|
findViewById(R.id.help_text).setVisibility(View.GONE);
|
||||||
findViewById(R.id.no_players_text).setVisibility(View.VISIBLE);
|
findViewById(R.id.no_players_text).setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,14 +25,6 @@
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
</android.support.v7.widget.Toolbar>
|
</android.support.v7.widget.Toolbar>
|
||||||
|
|
||||||
<Button
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:id="@+id/finish_button"
|
|
||||||
android:onClick="finishButton"
|
|
||||||
android:layout_gravity="center_horizontal"
|
|
||||||
android:text="Save character" />
|
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
|
|
@ -45,6 +45,13 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:id="@+id/listView"
|
android:id="@+id/listView"
|
||||||
android:layout_gravity="center_horizontal" />
|
android:layout_gravity="center_horizontal" />
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/help_text"
|
||||||
|
android:text="@string/help_welcome_text"
|
||||||
|
android:layout_gravity="center"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -90,4 +90,5 @@
|
||||||
<string name="add_player">Add player</string>
|
<string name="add_player">Add player</string>
|
||||||
<string name="zero" translatable="false">0</string>
|
<string name="zero" translatable="false">0</string>
|
||||||
<string name="no_players">No players, please add one</string>
|
<string name="no_players">No players, please add one</string>
|
||||||
|
<string name="help_welcome_text">Press a player to open, long press for options</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Reference in a new issue