Skip to content
This repository has been archived by the owner on Jan 26, 2023. It is now read-only.

S song develop #12

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions README.md
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
35 changes: 34 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
}

android {
Expand Down Expand Up @@ -30,16 +31,48 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
dataBinding{
enabled = true
}
kotlinOptions{
jvmTarget = "1.8"
}
}

dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

// retrofit
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:retrofit:2.6.0'
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'

// coroutine
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.0'

// liveData
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'

// viewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$version_lifecycle"

// ktx
implementation "androidx.core:core-ktx:1.3.2"
implementation "androidx.fragment:fragment-ktx:1.2.5"
implementation "androidx.activity:activity-ktx:1.1.0"

// Room database
implementation "androidx.room:room-runtime:$version_room"
kapt "androidx.room:room-compiler:$version_room"

// Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:$version_room"
}
6 changes: 4 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.siba.searchmvvmpractice">

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.SearchMVVMPractice">
<activity android:name=".MainActivity">
<activity android:name="com.siba.searchmvvmpractice.ui.presentation.activity.SearchActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
11 changes: 0 additions & 11 deletions app/src/main/java/com/siba/searchmvvmpractice/MainActivity.kt

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
Comment on lines +18 to +30

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분에 대한 코드인데 사실 구글에서 하라는 대로긴 하지만 너무 깊게 depth가 들어가는 부분이라 나는 이 부분은 좀 자바 같다고 생각하는데 어떻게 생각해?
depth를 줄이고 가독성 있게 만드는 방법이 있지 않을까?

그리고 약간 return 값이 instance인데 내부 변수인 이 친구를 던지는 이유는 뭘까..? 따로 변수를 만들지 않아도 충분히 가능한 부분 같아

Copy link

@jinsu4755 jinsu4755 Dec 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
fun getInstance(context: Context): SearchTermDatabase = INSTANCE ?: synchronized(this) {
INSTANCE ?: Room.databaseBuilder(
context.applicationContext,
SearchTermDatabase::class.java,
"search_keyword_history_database2"
).build().apply {
INSTANCE = this
}
}

이런 식으로 하면 기존 코드보다 뎁스도 줄이고 가독성도 해치지 않는다고 생각해

Copy link

@jinsu4755 jinsu4755 Dec 2, 2020

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를 가져가니까

}
}
}
}
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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리트로핏 서비스 리트로핏에 대한 서비스? 뭔가 이름이 이상하다고 생각해
나였으면 GitHubSearchService 혹은 SearchService 로 할 것 같아

@GET("search/users")
suspend fun getUsers(
@Query("q") user: String
): UserCatalog

@GET("search/repositories")
suspend fun getRepositories(

Choose a reason for hiding this comment

The 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)

}
Loading