Open2
Android開発_Kotlin
roomを用いたローカルDB
roomを用いて複数のDBを持たそうとしたがやり方がわからなかったので、複数テーブルを持たせた。
下から、Entity、DAOはテーブルの数だけファイルをもち、Repository、ViewModelに関しては共通にした。
class DBRepository(private val nekoDAO: NEKODAO, private val inuDAO: INUDAO) {
val allNeko: Flow<List<NEKO>> = nekoDAO.getAlphabetizedNekos()
val allInu: Flow<List<INU>> = inuDAO.getAlphabetizedInus()
@Suppress("RedundantSuspendModifier")
@WorkerThread
suspend fun insertNeko(neko: NEKO) {
nekoDAO.insert(neko)
}
@WorkerThread
suspend fun deleteAllNeko(){
nekoDAO.deleteAll()
}
@Suppress("RedundantSuspendModifier")
@WorkerThread
suspend fun insertInu(sdH0010: INU) {
inuDAO.insert(sdH0010)
}
@WorkerThread
suspend fun deleteAllInu(){
inuDAO.deleteAll()
}
}
Repositoryが大きくなるので、複数DBでの接続の仕方を探す。
ボタンの丸み
通常だとか角ばっているので、丸みをつける。
ボタンのプロパティに項目が存在しないので、以下のファイルを作成する。
SampleApp\app\src\main\res\drawable\btn_round.xml
そして、以下の内容を記述する。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false">
<shape android:shape="rectangle" >
<corners android:radius="20dp" />
<solid android:color="#B5B5B5"/>
</shape>
</item>
<item android:state_pressed="true" >
<shape android:shape="rectangle" >
<corners android:radius="20dp" />
<solid android:color="#00ff00"/>
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="20dp" />
<solid android:color="#00ff00"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<solid android:color="@color/purple_700"/>
<corners android:radius="20dp" />
</shape>
</item>
</selector>
この際に、押したときの押した感(色が薄くなる)がなくなったので、
ボタンの記述部分に以下を追加した。
android:foreground="?attr/selectableItemBackgroundBorderless"