-
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 22 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
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 { | ||
|
||
fun provideRetrofitService() : RetrofitService{ | ||
return RetrofitBuilder.retrofitService | ||
} | ||
|
||
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,17 @@ | ||
package com.siba.searchmvvmpractice.local.dao | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.room.* | ||
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,19 @@ | ||
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.Path | ||
import retrofit2.http.Query | ||
|
||
interface RetrofitService { | ||
@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) | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.siba.searchmvvmpractice.remote.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class UserCatalog( | ||
@SerializedName("total_count") | ||
val total_count : Int, | ||
@SerializedName("incomplete_results") | ||
val incomplete_results : Boolean, | ||
@SerializedName("items") | ||
val users : List<Users> | ||
) | ||
data class Users ( | ||
@SerializedName("login") | ||
val login : String, | ||
@SerializedName("id") | ||
val id : Int, | ||
@SerializedName("node_id") | ||
val node_id : String, | ||
@SerializedName("avatar_url") | ||
val avatar_url : String, | ||
@SerializedName("gravatar_id") | ||
val gravatar_id : String, | ||
@SerializedName("url") | ||
val url : String, | ||
@SerializedName("html_url") | ||
val html_url : String, | ||
@SerializedName("followers_url") | ||
val followers_url : String, | ||
@SerializedName("following_url") | ||
val following_url : String, | ||
@SerializedName("gists_url") | ||
val gists_url : String, | ||
@SerializedName("starred_url") | ||
val starred_url : String, | ||
@SerializedName("subscriptions_url") | ||
val subscriptions_url : String, | ||
@SerializedName("organizations_url") | ||
val organizations_url : String, | ||
@SerializedName("repos_url") | ||
val repos_url : String, | ||
@SerializedName("events_url") | ||
val events_url : String, | ||
@SerializedName("received_events_url") | ||
val received_events_url : String, | ||
@SerializedName("type") | ||
val type : String, | ||
@SerializedName("site_admin") | ||
val site_admin : Boolean, | ||
@SerializedName("score") | ||
val score : Double | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.siba.searchmvvmpractice.remote.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class UserRepositoryCatalog ( | ||
@SerializedName("total_count") | ||
val total_count : Int, | ||
@SerializedName("incomplete_results") | ||
val incomplete_results : Boolean, | ||
@SerializedName("items") | ||
val userRepository : List<UserRepository> | ||
) | ||
data class UserRepository ( | ||
@SerializedName("full_name") | ||
val full_name : String, | ||
@SerializedName("html_url") | ||
val html_url : String | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.siba.searchmvvmpractice.repository | ||
|
||
import com.siba.searchmvvmpractice.local.dao.SearchTermDao | ||
import com.siba.searchmvvmpractice.local.entity.RecentSearchTerm | ||
import com.siba.searchmvvmpractice.remote.RetrofitService | ||
import com.siba.searchmvvmpractice.remote.model.UserCatalog | ||
import com.siba.searchmvvmpractice.remote.model.UserRepositoryCatalog | ||
import com.siba.searchmvvmpractice.remote.model.Users | ||
|
||
class SearchRepository( | ||
private val retrofitService: RetrofitService, | ||
private val searchTermDao: SearchTermDao | ||
) { | ||
suspend fun fetchUser(userName : String) : UserCatalog = retrofitService.getUsers(userName) | ||
|
||
suspend fun fetchRepo(repositoryName : String) : UserRepositoryCatalog = retrofitService.getRepositories(repositoryName) | ||
|
||
suspend fun insert(recentSearchTerm: RecentSearchTerm){ | ||
searchTermDao.insertKeyword(recentSearchTerm) | ||
} | ||
|
||
fun getAll() = searchTermDao.getAllKeyword() | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,32 @@ | ||||||||||||||||||||||||
package com.siba.searchmvvmpractice.ui.adapter | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
import android.view.LayoutInflater | ||||||||||||||||||||||||
import android.view.View | ||||||||||||||||||||||||
import android.view.ViewGroup | ||||||||||||||||||||||||
import androidx.databinding.DataBindingUtil | ||||||||||||||||||||||||
import androidx.recyclerview.widget.RecyclerView | ||||||||||||||||||||||||
import com.siba.searchmvvmpractice.BR | ||||||||||||||||||||||||
import com.siba.searchmvvmpractice.R | ||||||||||||||||||||||||
import com.siba.searchmvvmpractice.databinding.RepoItemBinding | ||||||||||||||||||||||||
import com.siba.searchmvvmpractice.remote.model.UserRepository | ||||||||||||||||||||||||
import com.siba.searchmvvmpractice.remote.model.UserRepositoryCatalog | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
class RepoAdapter<B : RepoItemBinding> : RecyclerView.Adapter<RepoAdapter<B>.RepoViewHolder<B>>() { | ||||||||||||||||||||||||
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. 제네릭을 써서 컴파일시 강한 타입 검사와 손쉬운 타입 변화가 될 수 있는 건 좋은데 어짜피 해당 뷰 홀더에는 하나의 뷰 홀더를 사용하고 있고 그래서 뭔가 RepoItemBinding 라는 클래스 타입을 B라는 제네릭으로 축약해버린거 같아서 아쉽다... |
||||||||||||||||||||||||
var data = mutableListOf<UserRepository>() | ||||||||||||||||||||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RepoViewHolder<B> = | ||||||||||||||||||||||||
RepoViewHolder<B>(LayoutInflater.from(parent.context).inflate(R.layout.repo_item,parent,false)) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
override fun onBindViewHolder(holder: RepoViewHolder<B>, position: Int) { | ||||||||||||||||||||||||
holder.bind(data[position]) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
override fun getItemCount(): Int = data.size | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
inner class RepoViewHolder<B : RepoItemBinding>(itemView : View) : RecyclerView.ViewHolder(itemView) { | ||||||||||||||||||||||||
val binding : B = DataBindingUtil.bind(itemView)!! | ||||||||||||||||||||||||
fun bind(userRepository : UserRepository){ | ||||||||||||||||||||||||
binding.setVariable(BR.userRepository,userRepository) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
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.
Suggested change
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. 역시천재 |
||||||||||||||||||||||||
|
||||||||||||||||||||||||
} |
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.
리트로핏 서비스 리트로핏에 대한 서비스? 뭔가 이름이 이상하다고 생각해
나였으면 GitHubSearchService 혹은 SearchService 로 할 것 같아