Skip to content

Commit 0019e8a

Browse files
committed
feat: ui - search 리스트뷰 구현
1 parent 244a383 commit 0019e8a

4 files changed

Lines changed: 68 additions & 5 deletions

File tree

app/src/main/java/com/seok/gfd/room/dao/SearchGithubIdDao.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ private const val TABLE_NAME = "search_github_ids"
88
@Dao
99
interface SearchGithubIdDao {
1010
@Insert(onConflict = OnConflictStrategy.REPLACE)
11-
suspend fun insert(searchGithubId: SearchGithubId) : Long
11+
suspend fun insert(searchGithubId: SearchGithubId): Long
1212

1313
@Delete
1414
suspend fun delete(searchGithubId: SearchGithubId)
1515

16-
@Query("SELECT * FROM $TABLE_NAME WHERE gid_name LIKE :gidName || '%' ORDER BY created DESC")
17-
suspend fun selectAll(gidName : String) : List<SearchGithubId>
16+
@Query("SELECT * FROM $TABLE_NAME WHERE gid_name = :gidName LIKE '%' || :gidName || '%' ORDER BY created DESC")
17+
suspend fun selectAll(gidName: String): List<SearchGithubId>
18+
19+
@Query("SELECT * FROM $TABLE_NAME ORDER BY created DESC")
20+
suspend fun selectAll(): List<SearchGithubId>
1821

1922
@Query("delete from $TABLE_NAME")
2023
suspend fun deleteAll()
24+
}

app/src/main/java/com/seok/gfd/viewmodel/GithubIdViewModel.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import android.app.Application
44
import androidx.lifecycle.AndroidViewModel
55
import androidx.lifecycle.LiveData
66
import androidx.lifecycle.MutableLiveData
7-
import androidx.room.Room
87
import com.seok.gfd.room.AppDatabase
98
import com.seok.gfd.room.entity.SearchGithubId
109
import kotlinx.coroutines.runBlocking
@@ -27,7 +26,11 @@ class GithubIdViewModel(val context: Application) : AndroidViewModel(context){
2726
fun getGithubId(name : String){
2827
val database = AppDatabase.getInstance(context)
2928
runBlocking {
30-
_githubIds.value = database.searchGithubIdDao().selectAll(name)
29+
if(name == "" || name.isEmpty()) {
30+
_githubIds.value = database.searchGithubIdDao().selectAll(name)
31+
}else{
32+
_githubIds.value = database.searchGithubIdDao().selectAll()
33+
}
3134
database.close()
3235
}
3336
}

app/src/main/res/layout/activity_search.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,13 @@
7878
app:layout_constraintCircleRadius="30dp"
7979
app:layout_constraintEnd_toEndOf="parent"
8080
app:layout_constraintStart_toStartOf="parent"/>
81+
82+
<androidx.recyclerview.widget.RecyclerView
83+
android:id="@+id/search_recycler_view"
84+
android:layout_width="0dp"
85+
android:layout_height="0dp"
86+
app:layout_constraintBottom_toTopOf="@+id/search_btn_ok"
87+
app:layout_constraintEnd_toEndOf="parent"
88+
app:layout_constraintStart_toStartOf="parent"
89+
app:layout_constraintTop_toBottomOf="@+id/search_layout_id" />
8190
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="100dp">
7+
8+
<com.google.android.material.card.MaterialCardView
9+
android:id="@+id/item_search_card_view"
10+
android:layout_width="match_parent"
11+
android:layout_height="match_parent"
12+
android:clickable="true"
13+
app:cardCornerRadius="0dp"
14+
app:cardElevation="0dp"
15+
app:layout_constraintBottom_toBottomOf="parent"
16+
app:layout_constraintEnd_toEndOf="parent"
17+
app:layout_constraintStart_toStartOf="parent"
18+
app:layout_constraintTop_toTopOf="parent">
19+
20+
<androidx.constraintlayout.widget.ConstraintLayout
21+
android:layout_width="match_parent"
22+
android:layout_height="match_parent">
23+
24+
<TextView
25+
android:id="@+id/item_search_txt_github_id"
26+
android:layout_width="0dp"
27+
android:layout_height="wrap_content"
28+
android:layout_marginStart="20dp"
29+
android:layout_marginEnd="20dp"
30+
android:textSize="20sp"
31+
app:layout_constraintBottom_toBottomOf="parent"
32+
app:layout_constraintEnd_toStartOf="@+id/imageView2"
33+
app:layout_constraintStart_toStartOf="parent"
34+
app:layout_constraintTop_toTopOf="parent" />
35+
36+
<ImageView
37+
android:id="@+id/imageView2"
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:layout_marginEnd="20dp"
41+
app:layout_constraintBottom_toBottomOf="parent"
42+
app:layout_constraintEnd_toEndOf="parent"
43+
app:layout_constraintTop_toTopOf="parent"
44+
app:srcCompat="@drawable/ic_close_gray" />
45+
</androidx.constraintlayout.widget.ConstraintLayout>
46+
</com.google.android.material.card.MaterialCardView>
47+
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)