-
Notifications
You must be signed in to change notification settings - Fork 0
S song develop #12
base: develop
Are you sure you want to change the base?
S song develop #12
Changes from all commits
1be855a
74815ed
56934c2
0416b55
d33aadc
82cf42a
6d9ff13
cc44c50
2e109e7
8b9c5f3
fe5da29
75b9cb1
08127fc
3440b9f
97cef74
207b6cc
f97a0c2
5e0a31b
63d7b11
d128558
d5d77f6
f79a554
130d577
52d84ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Search My Profile in Github | ||
|
||
## branch | ||
|
||
### hunki - like develop | ||
|
||
### feature_hunki : using to make feat |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.siba.searchmvvmpractice.injection | ||
|
||
import android.content.Context | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.siba.searchmvvmpractice.local.database.SearchTermDatabase | ||
import com.siba.searchmvvmpractice.remote.RetrofitService | ||
import com.siba.searchmvvmpractice.remote.api.RetrofitBuilder | ||
import com.siba.searchmvvmpractice.repository.SearchRepository | ||
import com.siba.searchmvvmpractice.ui.base.SearchViewModelFactory | ||
|
||
object Injection { | ||
|
||
private fun provideRetrofitService(): RetrofitService { | ||
return RetrofitBuilder.retrofitService | ||
} | ||
|
||
private fun provideMainRepository(context: Context): SearchRepository { | ||
val database = SearchTermDatabase.getInstance(context) | ||
return SearchRepository(provideRetrofitService(), database.searchTermDao) | ||
} | ||
|
||
fun provideSearchViewModelFactory(context: Context): ViewModelProvider.Factory { | ||
return SearchViewModelFactory(provideMainRepository(context)) | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.siba.searchmvvmpractice.local.dao | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import com.siba.searchmvvmpractice.local.entity.RecentSearchTerm | ||
|
||
@Dao | ||
interface SearchTermDao { | ||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun insertKeyword(recentSearchTerm: RecentSearchTerm) | ||
|
||
@Query("DELETE FROM recent_search_term_table") | ||
fun clear() | ||
|
||
@Query("SELECT * FROM recent_search_term_table") | ||
fun getAllKeyword(): LiveData<List<RecentSearchTerm>> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.siba.searchmvvmpractice.local.database | ||
|
||
import android.content.Context | ||
import androidx.room.Database | ||
import androidx.room.Room | ||
import androidx.room.RoomDatabase | ||
import com.siba.searchmvvmpractice.local.dao.SearchTermDao | ||
import com.siba.searchmvvmpractice.local.entity.RecentSearchTerm | ||
|
||
@Database(entities = [RecentSearchTerm::class], version = 1) | ||
abstract class SearchTermDatabase : RoomDatabase() { | ||
abstract val searchTermDao: SearchTermDao | ||
|
||
companion object { | ||
@Volatile | ||
private var INSTANCE: SearchTermDatabase? = null | ||
|
||
fun getInstance(context: Context): SearchTermDatabase { | ||
synchronized(this) { | ||
var instance = INSTANCE | ||
|
||
if (instance == null) { | ||
instance = Room.databaseBuilder( | ||
context.applicationContext, | ||
SearchTermDatabase::class.java, | ||
"search_keyword_history_database2" | ||
).build() | ||
INSTANCE = instance | ||
} | ||
return instance | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.siba.searchmvvmpractice.local.entity | ||
|
||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity(tableName = "recent_search_term_table") | ||
|
||
data class RecentSearchTerm( | ||
@PrimaryKey(autoGenerate = true) | ||
val searchTermId: Int = 0, | ||
val keyword: String | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.siba.searchmvvmpractice.remote | ||
|
||
import com.siba.searchmvvmpractice.remote.model.UserCatalog | ||
import com.siba.searchmvvmpractice.remote.model.UserRepositoryCatalog | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
interface RetrofitService { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 리트로핏 서비스 리트로핏에 대한 서비스? 뭔가 이름이 이상하다고 생각해 |
||
@GET("search/users") | ||
suspend fun getUsers( | ||
@Query("q") user: String | ||
): UserCatalog | ||
|
||
@GET("search/repositories") | ||
suspend fun getRepositories( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 프로젝트 안에서도 레포지터리가 있고 우리가 원하는 깃헙의 온라인 레포지터리도 있어서 그 두가지의 구분으로 나라면 getOnlineRepositories 뭐 이런 느낌으로 했을 것 같음! |
||
@Query("q") repositoryName: String | ||
): UserRepositoryCatalog | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.siba.searchmvvmpractice.remote.api | ||
|
||
import com.siba.searchmvvmpractice.remote.RetrofitService | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
|
||
object RetrofitBuilder { | ||
private const val URL = "https://api.github.com" | ||
|
||
private fun getRetrofit(): Retrofit { | ||
return Retrofit.Builder() | ||
.baseUrl(URL) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
} | ||
|
||
val retrofitService: RetrofitService = getRetrofit().create(RetrofitService::class.java) | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분에 대한 코드인데 사실 구글에서 하라는 대로긴 하지만 너무 깊게 depth가 들어가는 부분이라 나는 이 부분은 좀 자바 같다고 생각하는데 어떻게 생각해?
depth를 줄이고 가독성 있게 만드는 방법이 있지 않을까?
그리고 약간 return 값이 instance인데 내부 변수인 이 친구를 던지는 이유는 뭘까..? 따로 변수를 만들지 않아도 충분히 가능한 부분 같아
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이런 식으로 하면 기존 코드보다 뎁스도 줄이고 가독성도 해치지 않는다고 생각해
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
해당 함수가 SearchTermDatabase 타입의 INSTANCE를 던져주는데 만약 null이라면 동기화 블럭에 들어가서 Room 데이터베이스 빌더로 데이터 베이스 만들어주고 그걸 INSTANCE에 apply하는거지
기존 코드랑 똑같은데 다르게 작성해서 indent 를 줄이고 조금더 읽으면서 한눈에 파악되게 작성한거고
큰 차이점이 있다면 미리 우리가 선언해둔 인스턴스에 값이 들어있다면 동기화 블럭을 거치지 않아도 해당 인스턴스를 던져주는 느낌?
난 기존코드를 생각했을때 INSTANCE가 있던 없던 동기화 블럭에 간다고 생각해서
굳이 이미 INSTANCE가 있을때도 멀티스레드 세이프티하게 인스턴스를 던져줄 필요가 없다고 생각했어 어짜피 그땐 동일한 INSTANCE를 가져가니까