-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrates data to sqflite instead of shared preferences (#10)
* feat: migrates data to sqflite instead of shared preferences * feat: adds correct theming and version from package * feat: migrates android widget to use room sqlite databas * fix: counter reset and editing * fix: fixes android home screen widget * fix: accesibility colors for android widget * feat: adds theme chooser features todo: improve implementation * fix: improves theme switch button and code * fix: removed imports * build: version bump
- Loading branch information
1 parent
07734c8
commit 64d031d
Showing
69 changed files
with
1,675 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
android/app/src/main/java/codingale/cr/dwi/database/CounterDAO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package codingale.cr.dwi.database | ||
|
||
import androidx.room.Dao | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import androidx.room.Update | ||
|
||
@Dao | ||
interface CounterDAO { | ||
@Query("SELECT * FROM time_counters") | ||
suspend fun getAll(): List<CounterEntity> | ||
|
||
@Query("SELECT * FROM time_counters WHERE id = :counterId") | ||
suspend fun findById(counterId: String): CounterEntity | ||
|
||
@Update(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun update(counter: CounterEntity) | ||
} |
12 changes: 12 additions & 0 deletions
12
android/app/src/main/java/codingale/cr/dwi/database/CounterEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package codingale.cr.dwi.database | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity(tableName = "time_counters") | ||
data class CounterEntity ( | ||
@PrimaryKey @ColumnInfo(name = "id") val id: String, | ||
@ColumnInfo(name = "title") var title: String?, | ||
@ColumnInfo(name = "created_at") var createdAt: String? | ||
) |
35 changes: 35 additions & 0 deletions
35
android/app/src/main/java/codingale/cr/dwi/database/DWIDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package codingale.cr.dwi.database | ||
|
||
import android.content.Context | ||
import androidx.room.Database | ||
import androidx.room.Room | ||
import androidx.room.RoomDatabase | ||
|
||
@Database(entities = [CounterEntity::class], version = 1) | ||
abstract class DWIDatabase : RoomDatabase() { | ||
abstract fun counterDao(): CounterDAO | ||
|
||
companion object { | ||
// Singleton prevents multiple instances of database opening at the | ||
// same time. | ||
@Volatile | ||
private var INSTANCE: DWIDatabase? = null | ||
|
||
fun getDatabase(context: Context): DWIDatabase { | ||
// if the INSTANCE is not null, then return it, | ||
// if it is, then create the database | ||
return INSTANCE ?: synchronized(this) { | ||
val instance = Room.databaseBuilder( | ||
context.applicationContext, | ||
DWIDatabase::class.java, | ||
DATABASE_NAME | ||
) | ||
.enableMultiInstanceInvalidation() | ||
.build() | ||
INSTANCE = instance | ||
// return instance | ||
instance | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
android/app/src/main/java/codingale/cr/dwi/database/kDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package codingale.cr.dwi.database | ||
|
||
const val DATABASE_NAME= "dwi_local.db" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="primary">#56F0D4</color> | ||
<color name="primary">#4400ff</color> | ||
<color name="ic_launcher_background">#56F0D4</color> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
library data; | ||
|
||
export 'repositories/repositories.dart'; | ||
export 'local/database/database.dart'; | ||
export 'services/services.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const kDatabaseName = "dwi_local.db"; | ||
const kDatabaseVersion = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import 'dart:io'; | ||
|
||
export 'constants/constants.dart'; | ||
export 'migrations/migrations.dart'; | ||
export 'repositories/repositories.dart'; | ||
export 'entities/entities.dart'; | ||
export 'support/support.dart'; | ||
|
||
import 'package:data/local/database/constants/constants.dart'; | ||
import 'package:data/local/database/migrations/migrations.dart'; | ||
import 'package:sqflite/sqflite.dart'; | ||
|
||
_onConfigure(Database db) async { | ||
// Adds support for cascade delete | ||
await db.execute("PRAGMA foreign_keys = ON"); | ||
} | ||
|
||
_onCreate(Database db, int version) async { | ||
await migrations[version]?.create(db); | ||
} | ||
|
||
_onUpgrade(Database db, int oldVersion, int newVersion) async { | ||
int pendingQty = newVersion - oldVersion; | ||
List<int> pendingMigrations = List.generate(pendingQty, (i) => i + 1); | ||
|
||
await Future.forEach<int>(pendingMigrations, (versionDiff) async { | ||
await migrations[newVersion]?.up(db); | ||
}); | ||
} | ||
|
||
_onDowngrade(Database db, int oldVersion, int newVersion) async { | ||
int pendingQty = newVersion - oldVersion; | ||
List<int> pendingMigrations = List.generate(pendingQty, (i) => i + 1); | ||
|
||
await Future.forEach<int>(pendingMigrations, (versionDiff) async { | ||
await migrations[newVersion]?.down(db); | ||
}); | ||
} | ||
|
||
Future<Database> openDWIDatabase() async { | ||
var databasesPath = await getDatabasesPath(); | ||
var path = databasesPath + '/' + kDatabaseName; | ||
|
||
await Directory(databasesPath).create(recursive: true); | ||
|
||
return await openDatabase( | ||
path, | ||
version: kDatabaseVersion, | ||
onConfigure: _onConfigure, | ||
onCreate: _onCreate, | ||
onUpgrade: _onUpgrade, | ||
onDowngrade: _onDowngrade, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'time_counter.entity.dart'; |
Oops, something went wrong.