-
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.
- Loading branch information
1 parent
64c26cd
commit e19aa1e
Showing
19 changed files
with
260 additions
and
150 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.example.spinwill | ||
|
||
import android.content.Context | ||
import androidx.room.* | ||
import com.example.spinwill.database.local.SpinWillDbActions | ||
|
||
@Database(entities = [SpinWillItem::class], version = 1, exportSchema = false) | ||
abstract class AppWillRoomDatabase : RoomDatabase() { | ||
|
||
abstract fun getSpinWillDao(): SpinWillDaoImpl | ||
|
||
companion object { | ||
@Volatile | ||
private var instance: AppWillRoomDatabase? = null | ||
|
||
@JvmStatic | ||
fun getInstance(context: Context): AppWillRoomDatabase { | ||
return instance ?: synchronized(this) { | ||
instance ?: buildDatabase(context).also { | ||
instance = it | ||
} | ||
} | ||
} | ||
|
||
// Create 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): AppWillRoomDatabase { | ||
return Room.databaseBuilder( | ||
context, | ||
AppWillRoomDatabase::class.java, | ||
"SPINWILL_DB_123" | ||
).fallbackToDestructiveMigration().build() | ||
} | ||
} | ||
} | ||
|
||
|
||
@Dao | ||
interface SpinWillDaoImpl { | ||
@Query("SELECT * FROM spinwill_item") | ||
suspend fun getAllItems(): List<SpinWillItem> | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun insertAll(willItems: List<SpinWillItem>) | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun insert(willItem: SpinWillItem) | ||
|
||
@Delete | ||
suspend fun delete(willItem: SpinWillItem) | ||
|
||
@Query("DELETE FROM spinwill_item") | ||
suspend fun deleteAll() | ||
} | ||
|
||
class SpinWillDaoConc : SpinWillDbActions<SpinWillItem> { | ||
|
||
private lateinit var dao: SpinWillDaoImpl | ||
|
||
fun setDao(dao: SpinWillDaoImpl) { | ||
this.dao = dao | ||
} | ||
|
||
override suspend fun getAllItems(): List<SpinWillItem> { | ||
return dao.getAllItems() | ||
} | ||
|
||
override suspend fun insert(willItem: SpinWillItem) { | ||
return dao.insert(willItem) | ||
} | ||
|
||
override suspend fun insertAll(willItems: List<SpinWillItem>) { | ||
return dao.insertAll(willItems) | ||
} | ||
|
||
override suspend fun delete(willItem: SpinWillItem) { | ||
return dao.delete(willItem) | ||
} | ||
|
||
override suspend fun deleteAll() { | ||
return dao.deleteAll() | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
spinwill/src/main/java/com/example/spinwill/adapter/WillItemAdapter.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,8 @@ | ||
package com.example.spinwill.adapter | ||
|
||
import android.graphics.Bitmap | ||
|
||
interface WillItemAdapter<item> { | ||
fun getRewardImageUrl(item: item): String | ||
fun setRewardBitmap(item: item, bitmap: Bitmap) | ||
} |
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.