Skip to content

Instantly share code, notes, and snippets.

View sienatime's full-sized avatar

Siena Aguayo sienatime

View GitHub Profile
@Database(entities = {
Entry.class, Sense.class, CrossReference.class, EntryFts.class
}, version = 4, exportSchema = false) public abstract class AppDatabase extends RoomDatabase
Room.databaseBuilder(...)
.addMigrations(new Migration(3, 4) {
@Override public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("CREATE VIRTUAL TABLE IF NOT EXISTS `entriesFts` USING FTS4(`primary_kanji`, `primary_reading`, `other_kanji`, `other_readings`, content=`entries`)");
database.execSQL("INSERT INTO entriesFts(entriesFts) VALUES ('rebuild')");
}
})
.build();
@Fts4(contentEntity = Entry.class)
@Entity(tableName = "entriesFts")
public class EntryFts {
@ColumnInfo(name = "primary_kanji")
private String primaryKanji;
@NonNull
@ColumnInfo(name = "primary_reading")
private String primaryReading;
@Transaction @Query(
"SELECT entries.id, entries.primary_kanji, entries.primary_reading FROM entries "
+ "JOIN entriesFts ON (entries.id = entriesFts.docid) WHERE entriesFts MATCH :term")
DataSource.Factory<Integer, SearchResultEntry> searchByJapaneseTerm(String term);
public LiveData<PagedList<SearchResultEntry>> search(String term) {
String wildcardQuery = String.format("*%s*", term);
return new LivePagedListBuilder<>(entryDao.searchByJapaneseTerm(wildcardQuery), PAGE_SIZE).build();
}
@sienatime
sienatime / AppDatabase.java
Last active September 25, 2020 12:31
Code snippets for adding FTS support to Room (Android architecture components)
@Database(entities = {
Entry.class, Sense.class, CrossReference.class, EntryFts.class
}, version = 4, exportSchema = false) public abstract class AppDatabase extends RoomDatabase
@sienatime
sienatime / bright-material.theme
Created June 14, 2018 20:48
Custom theme based on Material Design for the highlight brew package
Description="Bright Material"
Default = { Colour="#757575" }
Canvas = { Colour="#FAFAFA" }
Number = { Colour="#ff9100" }
Escape = { Colour="#6a5acd" }
String = { Colour="#ff9100" }
StringPreProc = { Colour="#ff9100" }
BlockComment = { Colour="#BDBDBD", Italic=true }
PreProcessor = { Colour="#9C27B0" }
LineNum = { Colour="#BDBDBD" }