-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
11 changed files
with
229 additions
and
25 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
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,16 @@ | ||
package com.porfir.dao | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import com.porfir.model.HistoryItem | ||
|
||
@Dao | ||
interface HistoryDao { | ||
@Query("SELECT * FROM history_items ORDER BY timestamp DESC") | ||
fun getAll(): List<HistoryItem> | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
fun insert(item: HistoryItem) | ||
} |
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,10 @@ | ||
package com.porfir.dao | ||
|
||
import androidx.room.Database | ||
import androidx.room.RoomDatabase | ||
import com.porfir.model.HistoryItem | ||
|
||
@Database(entities = [HistoryItem::class], version = 1, exportSchema = false) | ||
abstract class PorfirDatabase: RoomDatabase() { | ||
abstract fun historyDao(): HistoryDao | ||
} |
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,20 @@ | ||
package com.porfir.model | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
import com.idanatz.oneadapter.external.interfaces.Diffable | ||
|
||
@Entity(tableName = "history_items") | ||
data class HistoryItem( | ||
@PrimaryKey(autoGenerate = true) | ||
val id: Long, | ||
@ColumnInfo(name = "generated_text") | ||
val text: String, | ||
@ColumnInfo(name = "timestamp") | ||
val timestamp: Long | ||
): Diffable { | ||
override fun areContentTheSame(other: Any) = other is HistoryItem && other.id == id | ||
|
||
override fun getUniqueIdentifier(): Long = id | ||
} |
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,20 @@ | ||
package com.porfir.module | ||
|
||
import android.widget.TextView | ||
import com.idanatz.oneadapter.external.modules.ItemModule | ||
import com.idanatz.oneadapter.external.modules.ItemModuleConfig | ||
import com.idanatz.oneadapter.internal.holders.ViewBinder | ||
import com.porfir.R | ||
import com.porfir.model.HistoryItem | ||
|
||
class HistoryModule: ItemModule<HistoryItem>() { | ||
|
||
override fun provideModuleConfig() = object : ItemModuleConfig() { | ||
override fun withLayoutResource() = R.layout.history_item | ||
} | ||
|
||
override fun onBind(model: HistoryItem, viewBinder: ViewBinder) { | ||
val textView = viewBinder.findViewById<TextView>(R.id.history_item_text) | ||
textView.text = model.text | ||
} | ||
} |
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,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.cardview.widget.CardView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:card_view="http://schemas.android.com/apk/res-auto" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
|
||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center" | ||
card_view:cardCornerRadius="4dp" | ||
card_view:cardUseCompatPadding="true" | ||
app:contentPadding="10dp" | ||
android:foreground="?android:attr/selectableItemBackground" | ||
android:clickable="true"> | ||
|
||
<TextView | ||
android:id="@+id/history_item_text" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:textSize="18sp" /> | ||
|
||
</androidx.cardview.widget.CardView> |
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