-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrated to room from realm, missing the delete use case and tests
- Loading branch information
Showing
50 changed files
with
1,555 additions
and
1,415 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
41 changes: 41 additions & 0 deletions
41
sampleApp/src/main/java/com/zeyad/usecases/app/AppDatabase.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,41 @@ | ||
package com.zeyad.usecases.app | ||
|
||
import android.arch.persistence.room.Database | ||
import android.arch.persistence.room.Room | ||
import android.arch.persistence.room.RoomDatabase | ||
import android.content.Context | ||
import com.zeyad.usecases.app.screens.user.User | ||
import com.zeyad.usecases.app.screens.user.detail.Repository | ||
|
||
@Database(entities = [User::class, Repository::class], version = 1) | ||
abstract class AppDatabase : RoomDatabase() { | ||
|
||
abstract fun userDao(): UserDao | ||
abstract fun repoDao(): RepoDao | ||
|
||
companion object { | ||
|
||
@Volatile | ||
private var instance: AppDatabase? = null | ||
|
||
fun getInstance(context: Context): AppDatabase { | ||
return instance ?: synchronized(this) { | ||
instance ?: buildDatabase(context).also { instance = it } | ||
} | ||
} | ||
|
||
// Create and pre-populate the database. See this article for more details: | ||
// https://medium.com/google-developers/7-pro-tips-for-room-fbadea4bfbd1#4785 | ||
private fun buildDatabase(context: Context): AppDatabase { | ||
return Room.databaseBuilder(context, AppDatabase::class.java, "app.room") | ||
// .addCallback(object : RoomDatabase.Callback() { | ||
// override fun onCreate(db: SupportSQLiteDatabase) { | ||
// super.onCreate(db) | ||
// val request = OneTimeWorkRequestBuilder<SeedDatabaseWorker>().build() | ||
// WorkManager.getInstance().enqueue(request) | ||
// } | ||
// }) | ||
.build() | ||
} | ||
} | ||
} |
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 com.zeyad.usecases.app | ||
|
||
import android.arch.persistence.room.Dao | ||
import com.zeyad.usecases.app.screens.user.User | ||
import com.zeyad.usecases.app.screens.user.detail.Repository | ||
import com.zeyad.usecases.db.BaseDao | ||
|
||
@Dao | ||
interface UserDao : BaseDao<User> | ||
|
||
@Dao | ||
interface RepoDao : BaseDao<Repository> |
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
6 changes: 0 additions & 6 deletions
6
sampleApp/src/main/java/com/zeyad/usecases/app/LibraryModule.kt
This file was deleted.
Oops, something went wrong.
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
19 changes: 13 additions & 6 deletions
19
sampleApp/src/main/java/com/zeyad/usecases/app/screens/user/User.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 |
---|---|---|
@@ -1,26 +1,33 @@ | ||
package com.zeyad.usecases.app.screens.user | ||
|
||
import android.arch.persistence.room.ColumnInfo | ||
import android.arch.persistence.room.Entity | ||
import android.arch.persistence.room.PrimaryKey | ||
import android.os.Parcelable | ||
import com.google.gson.annotations.SerializedName | ||
import io.realm.RealmObject | ||
import io.realm.annotations.PrimaryKey | ||
import com.zeyad.usecases.app.R.id.id | ||
import kotlinx.android.parcel.Parcelize | ||
|
||
/** | ||
* @author zeyad on 1/10/17. | ||
*/ | ||
@Entity | ||
@Parcelize | ||
open class User(@PrimaryKey | ||
@SerializedName(LOGIN) | ||
open class User(@SerializedName(LOGIN) | ||
var login: String = "", | ||
@SerializedName(ID) | ||
var id: Int = 0, | ||
@PrimaryKey var id: Int = 0, | ||
@SerializedName(AVATAR_URL) | ||
var avatarUrl: String = "") : RealmObject(), Parcelable { | ||
@ColumnInfo(name = AVATAR_URL) | ||
var avatarUrl: String = "") : Parcelable { | ||
|
||
companion object { | ||
const val LOGIN = "login" | ||
private const val ID = "id" | ||
private const val AVATAR_URL = "avatar_url" | ||
|
||
fun isEmpty(user: User): Boolean { | ||
return user.login.isEmpty() && id <= 0 && user.avatarUrl.isEmpty() | ||
} | ||
} | ||
} |
27 changes: 12 additions & 15 deletions
27
sampleApp/src/main/java/com/zeyad/usecases/app/screens/user/detail/Repository.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 |
---|---|---|
@@ -1,28 +1,25 @@ | ||
package com.zeyad.usecases.app.screens.user.detail | ||
|
||
import android.arch.persistence.room.ColumnInfo | ||
import android.arch.persistence.room.Entity | ||
import android.arch.persistence.room.PrimaryKey | ||
import android.os.Parcelable | ||
import com.google.gson.annotations.SerializedName | ||
import com.zeyad.usecases.app.screens.user.User | ||
import io.realm.RealmObject | ||
import kotlinx.android.parcel.Parcelize | ||
|
||
/** | ||
* @author zeyad on 1/25/17. | ||
*/ | ||
@Entity | ||
@Parcelize | ||
open class Repository(@SerializedName("id") | ||
var id: Int = 0, | ||
@PrimaryKey var id: Int = 0, | ||
@SerializedName("name") | ||
var name: String? = null, | ||
var name: String = "", | ||
@SerializedName("full_name") | ||
var fullName: String? = null, | ||
@SerializedName("owner") | ||
internal var owner: User? = null) : RealmObject(), Parcelable { | ||
|
||
companion object { | ||
|
||
fun isEmpty(repository: Repository?): Boolean { | ||
return repository == null || repository.name == null && repository.fullName == null && repository.owner == null | ||
} | ||
} | ||
} | ||
@ColumnInfo(name = "full_name") | ||
var fullName: String = "" | ||
// , | ||
// @SerializedName("owner") | ||
// var owner: User = User()) : Parcelable | ||
) : Parcelable |
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
Oops, something went wrong.