diff --git a/BibliaDaoGenerator/src/main/java/pl/surecase/eu/BibliaDaoGenerator.java b/BibliaDaoGenerator/src/main/java/pl/surecase/eu/BibliaDaoGenerator.java index f33dad4..1063e45 100644 --- a/BibliaDaoGenerator/src/main/java/pl/surecase/eu/BibliaDaoGenerator.java +++ b/BibliaDaoGenerator/src/main/java/pl/surecase/eu/BibliaDaoGenerator.java @@ -20,7 +20,7 @@ public static void main(String args[]) throws Exception { verses.addStringProperty("text"); Entity books = schema.addEntity("Book"); - books.addLongProperty("ordering").primaryKey().unique(); + books.addLongProperty("indice").primaryKey().unique(); books.setTableName("books"); books.addStringProperty("name"); books.addStringProperty("abbreviation"); diff --git a/app/src/main/assets/databases/biblia_arc.db.zip b/app/src/main/assets/databases/biblia_arc.db.zip index 437a569..c1612a8 100644 Binary files a/app/src/main/assets/databases/biblia_arc.db.zip and b/app/src/main/assets/databases/biblia_arc.db.zip differ diff --git a/app/src/main/java-gen/greendao/Book.java b/app/src/main/java-gen/greendao/Book.java index 1a041a1..0fa0568 100644 --- a/app/src/main/java-gen/greendao/Book.java +++ b/app/src/main/java-gen/greendao/Book.java @@ -6,7 +6,7 @@ */ public class Book { - private Long ordering; + private Long indice; private String name; private String abbreviation; private String testament; @@ -14,23 +14,23 @@ public class Book { public Book() { } - public Book(Long ordering) { - this.ordering = ordering; + public Book(Long indice) { + this.indice = indice; } - public Book(Long ordering, String name, String abbreviation, String testament) { - this.ordering = ordering; + public Book(Long indice, String name, String abbreviation, String testament) { + this.indice = indice; this.name = name; this.abbreviation = abbreviation; this.testament = testament; } - public Long getOrdering() { - return ordering; + public Long getIndice() { + return indice; } - public void setOrdering(Long ordering) { - this.ordering = ordering; + public void setIndice(Long indice) { + this.indice = indice; } public String getName() { diff --git a/app/src/main/java-gen/greendao/BookDao.java b/app/src/main/java-gen/greendao/BookDao.java index cbff31a..b57bca6 100644 --- a/app/src/main/java-gen/greendao/BookDao.java +++ b/app/src/main/java-gen/greendao/BookDao.java @@ -23,7 +23,7 @@ public class BookDao extends AbstractDao { * Can be used for QueryBuilder and for referencing column names. */ public static class Properties { - public final static Property Ordering = new Property(0, Long.class, "ordering", true, "ORDERING"); + public final static Property Indice = new Property(0, Long.class, "indice", true, "INDICE"); public final static Property Name = new Property(1, String.class, "name", false, "NAME"); public final static Property Abbreviation = new Property(2, String.class, "abbreviation", false, "ABBREVIATION"); public final static Property Testament = new Property(3, String.class, "testament", false, "TESTAMENT"); @@ -42,7 +42,7 @@ public BookDao(DaoConfig config, DaoSession daoSession) { public static void createTable(SQLiteDatabase db, boolean ifNotExists) { String constraint = ifNotExists? "IF NOT EXISTS ": ""; db.execSQL("CREATE TABLE " + constraint + "'books' (" + // - "'ORDERING' INTEGER PRIMARY KEY UNIQUE ," + // 0: ordering + "'INDICE' INTEGER PRIMARY KEY UNIQUE ," + // 0: indice "'NAME' TEXT," + // 1: name "'ABBREVIATION' TEXT," + // 2: abbreviation "'TESTAMENT' TEXT);"); // 3: testament @@ -59,9 +59,9 @@ public static void dropTable(SQLiteDatabase db, boolean ifExists) { protected void bindValues(SQLiteStatement stmt, Book entity) { stmt.clearBindings(); - Long ordering = entity.getOrdering(); - if (ordering != null) { - stmt.bindLong(1, ordering); + Long indice = entity.getIndice(); + if (indice != null) { + stmt.bindLong(1, indice); } String name = entity.getName(); @@ -90,7 +90,7 @@ public Long readKey(Cursor cursor, int offset) { @Override public Book readEntity(Cursor cursor, int offset) { Book entity = new Book( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // ordering + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // indice cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // abbreviation cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // testament @@ -101,7 +101,7 @@ public Book readEntity(Cursor cursor, int offset) { /** @inheritdoc */ @Override public void readEntity(Cursor cursor, Book entity, int offset) { - entity.setOrdering(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setIndice(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); entity.setAbbreviation(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); entity.setTestament(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); @@ -110,7 +110,7 @@ public void readEntity(Cursor cursor, Book entity, int offset) { /** @inheritdoc */ @Override protected Long updateKeyAfterInsert(Book entity, long rowId) { - entity.setOrdering(rowId); + entity.setIndice(rowId); return rowId; } @@ -118,7 +118,7 @@ protected Long updateKeyAfterInsert(Book entity, long rowId) { @Override public Long getKey(Book entity) { if(entity != null) { - return entity.getOrdering(); + return entity.getIndice(); } else { return null; } diff --git a/app/src/main/java/com/cubolabs/bibliaofflinearc/data/BibliaDatabase.java b/app/src/main/java/com/cubolabs/bibliaofflinearc/data/BibliaDatabase.java index 218809c..a251583 100644 --- a/app/src/main/java/com/cubolabs/bibliaofflinearc/data/BibliaDatabase.java +++ b/app/src/main/java/com/cubolabs/bibliaofflinearc/data/BibliaDatabase.java @@ -10,7 +10,7 @@ public class BibliaDatabase extends SQLiteAssetHelper { //private static final String TAG = SQLiteAssetHelper.class.getSimpleName(); private static final String DATABASE_NAME = "biblia_arc.db"; - private static final int DATABASE_VERSION = 10; + private static final int DATABASE_VERSION = 11; private static DaoSession daoSession; private static DaoMaster daoMaster; diff --git a/app/src/main/java/com/cubolabs/bibliaofflinearc/data/ListaDeVersiculos.java b/app/src/main/java/com/cubolabs/bibliaofflinearc/data/ListaDeVersiculos.java index 61c9daa..643da09 100644 --- a/app/src/main/java/com/cubolabs/bibliaofflinearc/data/ListaDeVersiculos.java +++ b/app/src/main/java/com/cubolabs/bibliaofflinearc/data/ListaDeVersiculos.java @@ -72,28 +72,40 @@ public ArrayList Busca(String s) { return listaDeVersos; } + public Verse UltimoCapitulo(String livroSigla) { + QueryBuilder pqb = verseDao.queryBuilder(); + return pqb + .where(VerseDao.Properties.Book.eq(livroSigla)) + .orderDesc(VerseDao.Properties.Chapter).limit(1).unique(); + } + public Verse ProximoCapitulo(String nomeDoLivro, int capitulo) { - Verse proximoCapitulo; + Verse proximoCapitulo = null; Book book = bookDao.queryBuilder() .where(BookDao.Properties.Name.eq(nomeDoLivro)).unique(); - QueryBuilder pqb = verseDao.queryBuilder(); + Verse ultimo = UltimoCapitulo(book.getAbbreviation()); - proximoCapitulo = pqb.where(pqb.and( - VerseDao.Properties.Book.eq(book.getAbbreviation()), - VerseDao.Properties.Chapter.eq(capitulo+1)), - VerseDao.Properties.Verse.eq(1)) - .unique(); - if (proximoCapitulo == null) { + QueryBuilder pqb = verseDao.queryBuilder(); + if (capitulo < ultimo.getChapter()) { + proximoCapitulo = pqb.where(pqb.and( + VerseDao.Properties.Book.eq(book.getAbbreviation()), + VerseDao.Properties.Chapter.eq(capitulo+1)), + VerseDao.Properties.Verse.eq(1)) + .unique(); + } + else { Book nextBook = bookDao.queryBuilder() - .where(BookDao.Properties.Ordering.eq(capitulo-1)).unique(); + .where(BookDao.Properties.Indice.eq(book.getIndice()+1)).unique(); pqb = verseDao.queryBuilder(); - proximoCapitulo = pqb.where(pqb.and( - VerseDao.Properties.Book.eq(nextBook.getAbbreviation()), - VerseDao.Properties.Chapter.eq(1), - VerseDao.Properties.Verse.eq(1))) - .unique(); + if (nextBook != null) { + proximoCapitulo = pqb.where(pqb.and( + VerseDao.Properties.Book.eq(nextBook.getAbbreviation()), + VerseDao.Properties.Chapter.eq(1), + VerseDao.Properties.Verse.eq(1))) + .unique(); + } } return proximoCapitulo; @@ -112,13 +124,17 @@ public Verse CapituloAnterior(String nomeDoLivro, int capitulo) { VerseDao.Properties.Chapter.eq(capitulo-1)), VerseDao.Properties.Verse.eq(1)) .unique(); - if (capituloAnterior == null) { + + if (capituloAnterior == null && book.getIndice() > 1) { Book previousBook = bookDao.queryBuilder() - .where(BookDao.Properties.Ordering.eq(capitulo-1)).unique(); + .where(BookDao.Properties.Indice.eq(book.getIndice()-1)).unique(); + pqb = verseDao.queryBuilder(); + Verse ultimo = UltimoCapitulo(previousBook.getAbbreviation()); + capituloAnterior = pqb.where(pqb.and( VerseDao.Properties.Book.eq(previousBook.getAbbreviation()), - VerseDao.Properties.Chapter.eq(1), + VerseDao.Properties.Chapter.eq(ultimo.getChapter()), VerseDao.Properties.Verse.eq(1))) .unique(); } diff --git a/app/src/main/java/com/cubolabs/bibliaofflinearc/ui/MyGestureDetector.java b/app/src/main/java/com/cubolabs/bibliaofflinearc/ui/MyGestureDetector.java index 9fec046..76abca5 100644 --- a/app/src/main/java/com/cubolabs/bibliaofflinearc/ui/MyGestureDetector.java +++ b/app/src/main/java/com/cubolabs/bibliaofflinearc/ui/MyGestureDetector.java @@ -40,7 +40,6 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve //Toast.makeText(getActivity(), "Left Swipe", Toast.LENGTH_SHORT).show(); Verse proximo = listaDeVersiculos.ProximoCapitulo(livro, capitulo); if (proximo != null) { - Book book = listaDeLivros.ByAbbreviation(proximo.getBook()); Fragment newFragment = VersiculosFragment.newInstance( book.getName(), @@ -61,8 +60,8 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve } else if (e2.getX() - e1.getX() > VersiculosFragment.SWIPE_MIN_DISTANCE && Math.abs(velocityX) > VersiculosFragment.SWIPE_THRESHOLD_VELOCITY) { //Toast.makeText(getActivity(), "Right Swipe", Toast.LENGTH_SHORT).show(); Verse anterior = listaDeVersiculos.CapituloAnterior(livro, capitulo); - Book book = listaDeLivros.ByAbbreviation(anterior.getBook()); if (anterior != null) { + Book book = listaDeLivros.ByAbbreviation(anterior.getBook()); Fragment newFragment = VersiculosFragment.newInstance( book.getName(), anterior.getChapter() @@ -81,7 +80,7 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve } } } catch (Exception e) { - Log.d("MyGestureDetector.onFling", e.getMessage()); + Log.d("GestureDetector.onFling", e.getLocalizedMessage()); // nothing } return false;