Unverified Commit e78b3646 authored by Mathieu Féry (Mathius)'s avatar Mathieu Féry (Mathius)
Browse files

Add name regeneration and update db and code after that

parent 3ce8d81c
Pipeline #28848 failed with stages
in 1 minute and 7 seconds
......@@ -45,6 +45,9 @@ public class DnDSheetDBTest {
sheet.changeGIF(ctx, GIFObject.getGIFObject(ctx, "Hi'"));
assertTrue(db.updateGIF(sheet));
assertEquals(db.getDnDSheet(sheet.hashCode()).getGIF(), sheet.getGIF());
sheet.generateName(ctx);
assertTrue(db.updateName(sheet));
assertEquals(db.getDnDSheet(sheet.hashCode()).getName(), sheet.getName());
assertTrue(db.removeDnDSheet(sheet));
dropDBs();
}
......@@ -77,6 +80,7 @@ public class DnDSheetDBTest {
assertFalse(sheet.removeFav(ctx, dbVersion));
assertFalse(sheet.updateFav(ctx, dbVersion));
sheet.changeGIF(ctx, gif);
sheet.generateName(ctx);
assertTrue(sheet.addFav(ctx, dbVersion));
assertTrue(sheet.updateFav(ctx, dbVersion));
assertTrue(sheet.removeFav(ctx, dbVersion));
......
......@@ -104,7 +104,7 @@ public class DisplayResultActivity extends AppCompatActivity {
v_hp = "No HP";
}
lbl_displayResult_name.setText(m_sheet.name);
lbl_displayResult_name.setText(m_sheet.getName());
lbl_displayResult_class.setText(m_sheet.caracterClass.toString());
lbl_displayResult_description.setText(m_sheet.appearance);
lbl_displayResult_system.setText(m_sheet.system.longName);
......
......@@ -125,7 +125,7 @@ public class ListResultsAdapter extends RecyclerView.Adapter<ListResultsAdapter.
*/
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.getM_lbl_name().setText(m_data.get(position).name);
holder.getM_lbl_name().setText(m_data.get(position).getName());
holder.getM_lbl_scpecie().setText(m_data.get(position).caracterClass.toString());
holder.getM_lbl_description().setText(m_data.get(position).appearance);
holder.getM_lbl_system().setText(m_data.get(position).system.longName);
......
......@@ -61,7 +61,7 @@ public class DnDSheet implements Serializable {
protected GIFObject gif;
public final String searchGIF;
public final TenorArgs tenorArgs;
public final String name;
protected String name;
/**
* Basic Constructor for create sheet if all arguments are provided.
* @param hp : Integer represent hp of this character
......@@ -139,7 +139,52 @@ public class DnDSheet implements Serializable {
this(hp, thac9, ac, appearance, caracterClass, personality, system, languages, equipment,
notes, spells, saves, attr, skills, GIFObject.getGIFObject(ctx, String.format(
"%s,%s,%s", caracterClass, appearance, system), tenorArgs),
Name.getRandomName(ctx, personality, appearance, caracterClass.name));
generateName(ctx, personality, appearance, caracterClass));
}
/**
* For change GIF and update Fav is necessary (In Default DB)
* @param ctx : Context for access database and fetch name
*/
public void generateName(@NonNull Context ctx) {
generateName(ctx, DnDSheetDB.DATABASE_VERSION);
}
/**
* For change GIF and update Fav is necessary
* @param ctx : Context for access database and fetch name
* @param dbVersion : Version of database
*/
public void generateName(@NonNull Context ctx, int dbVersion) {
this.name = generateName(ctx, appearance, personality, caracterClass);
if (isFav(ctx, dbVersion))
updateFav(ctx, dbVersion);
}
/**
* Method for generate name related to information given
* @param ctx : Context for fetch name
* @param appearance : String represent appearance of this character
* @param personality : String represent personality of this character
* @param caracterClass : DnDClass represent class of this character
* @return name
*/
public static String generateName(@NonNull Context ctx, @Nullable String appearance,
@Nullable String personality,
@NonNull DnDClass caracterClass) {
return Name.getRandomName(ctx,
personality != null ? personality : "",
appearance != null ? appearance : "",
caracterClass.name
);
}
/**
* Accessor for name property
* @return name
*/
public String getName() {
return name;
}
/**
......@@ -169,7 +214,8 @@ public class DnDSheet implements Serializable {
* @return favIsUpdated
*/
public boolean updateFav(@NonNull Context ctx, int dbVersion) {
return new DnDSheetDB(ctx, dbVersion).updateGIF(this);
DnDSheetDB db = new DnDSheetDB(ctx, dbVersion);
return db.updateGIF(this) && db.updateName(this);
}
/**
......
......@@ -149,6 +149,22 @@ public class DnDSheetDB extends BaseDB {
return true;
}
/**
* Method for update Name of sheet
* @param sheet : Sheet to update
* @return isUpdated
*/
public boolean updateName(DnDSheet sheet) {
if (getDnDSheet(sheet.hashCode()) == null)
return false;
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Vars.NAME, sheet.getName());
db.update(tableName(), values, String.format("%s = ?", Vars._ID), new String[]{
String.valueOf(sheet.hashCode())});
return true;
}
/**
* Method for get all sheets save in database
* @return sheets
......@@ -290,7 +306,7 @@ public class DnDSheetDB extends BaseDB {
new GIFArtifactDB(ctx, currentVersion).insertGIFArtifact(sheet.getGIF().artifact);
values.put(Vars.SAVES_ID, sheet.saves.hashCode());
new DnDSavesDB(ctx, currentVersion).insertDnDSaves(sheet.saves);
values.put(Vars.NAME, sheet.name);
values.put(Vars.NAME, sheet.getName());
values.put(Vars._ID, sheet.hashCode());
SQLiteDatabase db = this.getWritableDatabase();
db.insert(tableName(), null, values);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment