Skip to content

Commit

Permalink
Better updating of animal/species lists
Browse files Browse the repository at this point in the history
  • Loading branch information
pgmccann committed Jun 15, 2018
1 parent 93ef00d commit 9d16b0b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
7 changes: 7 additions & 0 deletions catch/src/main/java/uk/ac/masts/sifids/database/CatchDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,11 @@ public interface CatchDao {
@Query("DELETE FROM fish_1_form_row WHERE id = :id")
public void deleteFish1FormRow(int id);

@Query("DELETE FROM observation_species")
public void deleteAllObservationSpecies();

@Query("DELETE FROM observation_class")
public void deleteAllObservationClasses();


}
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,23 @@ public void run() {
}

@Override
public void onOpen(@NonNull SupportSQLiteDatabase db) {
public void onOpen(@NonNull final SupportSQLiteDatabase db) {
super.onOpen(db);
Executors.newSingleThreadExecutor().execute(new Runnable() {
@Override
public void run() {
CatchDao dao = getInstance(context).catchDao();
int observationClassesCount = dao.countObservationClasses();
int observationSpeciesCount = dao.countObservationSpecies();
int numSpecies = 0;
for (String[] species : ObservationSpecies.SPECIES.values()) {
numSpecies += species.length;
}
if (observationClassesCount > ObservationClass.ANIMALS.length
|| observationSpeciesCount > numSpecies) {
dao.deleteAllObservationSpecies();
dao.deleteAllObservationClasses();
}
if (dao.countObservationClasses() == 0) {
dao.insertObservationClasses(
ObservationClass.createObservationClasses());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@Entity(tableName = "observation_class")
public class ObservationClass extends EntityWithId {

private static final String[] ANIMALS = {"Seal", "Whale", "Dolphin", "Porpoise", "John Dory",
public static final String[] ANIMALS = {"Seal", "Whale", "Dolphin", "Porpoise", "John Dory",
"Basking Shark", "Wrasse", "Triggerfish", "Octopus"};

public String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
})
public class ObservationSpecies extends EntityWithId {

private static final Map<String, String[]> SPECIES = createSpeciesMap();
public static final Map<String, String[]> SPECIES = createSpeciesMap();

private static Map<String, String[]> createSpeciesMap() {
Map<String, String[]> speciesMap = new HashMap<>();
Expand Down

0 comments on commit 9d16b0b

Please sign in to comment.