-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
인기영화 목록 보기 #34
Open
taeiim
wants to merge
20
commits into
StudyFork:taeiim
Choose a base branch
from
taeiim:movie-coroutine
base: taeiim
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+990
−105
Open
인기영화 목록 보기 #34
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
206d0b5
MovieApp 프로젝트 생성
taeiim e8272e6
ToyProject 삭제
taeiim 9582750
MainActivity 패키지 변경
taeiim 4ac8deb
Gradle Retrofit 추가
taeiim d780d31
MovieApiProvider 추가
taeiim 6e816de
MovieApi-getMoviePopular 추가
taeiim 0d38a0e
MoviePopular Model 추가
taeiim 7458b3a
gradle glide, viewmodel, koin, coroutine 추가
taeiim aefc0ac
BaseActivity 추가
taeiim 4cef894
ActivityMain, recyclerView item layout 추가
taeiim 3832d43
MovieRepository, RemoteDataSource 추가
taeiim 1e89c0f
koin 추가
taeiim 07f0a5d
MainViewModel 추가
taeiim 25b68e5
gradle lifecycle, coroutine 추가
taeiim 51d1444
Base 추가
taeiim f9ee7ef
data 관련 클래스 추가
taeiim 6f8613e
Koin module 추가
taeiim 2a02700
MainActivity, ViewModel, RecyclerAdapter 추가
taeiim c973c9a
Manifest 수정
taeiim 1942eaa
api key BuildConfig 내부 변수 추가
taeiim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,66 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
apply plugin: 'kotlin-android' | ||
|
||
apply plugin: 'kotlin-kapt' | ||
|
||
android { | ||
compileSdkVersion 29 | ||
buildToolsVersion "29.0.2" | ||
defaultConfig { | ||
applicationId "com.god.taeiim.movieapp" | ||
minSdkVersion 21 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
|
||
buildConfigField "String", "SECRET_KEY" , "\"d8cef1cded16cd9e5bae792da0d70ed7\"" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
dataBinding { | ||
enabled = true | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
implementation "androidx.appcompat:appcompat:$app_compat_version" | ||
|
||
//test | ||
testImplementation "junit:junit:$junit_version" | ||
androidTestImplementation "androidx.test:runner:$test_runner_version" | ||
androidTestImplementation "androidx.test.espresso:espresso-core:$core_version" | ||
|
||
implementation "com.google.android.material:material:$material_version" | ||
implementation "androidx.constraintlayout:constraintlayout:$constraintlayout_version" | ||
|
||
//retrofit | ||
implementation "com.squareup.retrofit2:retrofit:$retrofit_version" | ||
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version" | ||
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_version" | ||
|
||
//glide | ||
implementation "com.github.bumptech.glide:glide:$glide_version" | ||
annotationProcessor "com.github.bumptech.glide:compiler:$glide_version" | ||
|
||
//ViewModel, LiveData | ||
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version" | ||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" | ||
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version" | ||
|
||
//koin | ||
implementation "org.koin:koin-core:$koin_version" | ||
implementation "org.koin:koin-androidx-viewmodel:$koin_version" | ||
|
||
//coroutine | ||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutine_version" | ||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine_version" | ||
} |
File renamed without changes.
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
9 changes: 6 additions & 3 deletions
9
ToyProject/app/src/main/AndroidManifest.xml → MovieApp/app/src/main/AndroidManifest.xml
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
16 changes: 16 additions & 0 deletions
16
MovieApp/app/src/main/java/com/god/taeiim/movieapp/MovieAppApplication.kt
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.god.taeiim.movieapp | ||
|
||
import android.app.Application | ||
import com.god.taeiim.movieapp.di.dataSourceModule | ||
import com.god.taeiim.movieapp.di.networkModule | ||
import com.god.taeiim.movieapp.di.viewModelModule | ||
import com.god.taeiim.movieapp.ext.setupKoin | ||
|
||
class MovieAppApplication : Application() { | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
setupKoin(this, viewModelModule, networkModule, dataSourceModule) | ||
} | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
MovieApp/app/src/main/java/com/god/taeiim/movieapp/base/BaseAction.kt
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,3 @@ | ||
package com.god.taeiim.movieapp.base | ||
|
||
interface BaseAction |
20 changes: 20 additions & 0 deletions
20
MovieApp/app/src/main/java/com/god/taeiim/movieapp/base/BaseActivity.kt
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.god.taeiim.movieapp.base | ||
|
||
import android.os.Bundle | ||
import androidx.annotation.LayoutRes | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.databinding.ViewDataBinding | ||
|
||
abstract class BaseActivity<B : ViewDataBinding>( | ||
@LayoutRes private val layoutResId: Int | ||
) : AppCompatActivity() { | ||
|
||
protected lateinit var binding: B | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = DataBindingUtil.setContentView(this, layoutResId) | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
MovieApp/app/src/main/java/com/god/taeiim/movieapp/base/BaseRecyclerAdapter.kt
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,48 @@ | ||
package com.god.taeiim.movieapp.base | ||
|
||
import android.view.ViewGroup | ||
import androidx.annotation.LayoutRes | ||
import androidx.databinding.ViewDataBinding | ||
import androidx.recyclerview.widget.RecyclerView | ||
|
||
|
||
open class BaseRecyclerAdapter<ITEM, B : ViewDataBinding>( | ||
@LayoutRes val layoutResId: Int, | ||
val bindingVariableId: Int? = null | ||
) : RecyclerView.Adapter<BaseRecyclerViewHolder<B>>() { | ||
|
||
private val items = mutableListOf<ITEM>() | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseRecyclerViewHolder<B> = | ||
object : BaseRecyclerViewHolder<B>( | ||
layoutResId, | ||
parent, | ||
bindingVariableId | ||
) {} | ||
|
||
override fun getItemCount(): Int = items.size | ||
|
||
override fun onBindViewHolder(holder: BaseRecyclerViewHolder<B>, position: Int) = | ||
holder.onBindViewHolder(items[position]) | ||
|
||
protected fun getItem(position: Int): ITEM = | ||
items.getOrNull(position) ?: throw ArrayIndexOutOfBoundsException() | ||
|
||
fun updateItems(items: List<ITEM>?) { | ||
this.items.run { | ||
clear() | ||
items?.let { | ||
addAll(it) | ||
} | ||
} | ||
|
||
notifyDataSetChanged() | ||
} | ||
|
||
fun clearItems() { | ||
val size = items.size | ||
this.items.clear() | ||
notifyItemRangeRemoved(0, size) | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
MovieApp/app/src/main/java/com/god/taeiim/movieapp/base/BaseRecyclerViewHolder.kt
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,28 @@ | ||
package com.god.taeiim.movieapp.base | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.annotation.LayoutRes | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.databinding.ViewDataBinding | ||
import androidx.recyclerview.widget.RecyclerView | ||
|
||
open class BaseRecyclerViewHolder<B : ViewDataBinding>( | ||
@LayoutRes layoutRes: Int, | ||
parent: ViewGroup, | ||
private val bindingVariableId: Int? | ||
) : RecyclerView.ViewHolder(LayoutInflater.from(parent.context).inflate(layoutRes, parent, false)) { | ||
|
||
private val binding: B = DataBindingUtil.bind(itemView)!! | ||
|
||
fun onBindViewHolder(item: Any?) { | ||
if (bindingVariableId == null) | ||
return | ||
|
||
binding.run { | ||
setVariable(bindingVariableId, item) | ||
executePendingBindings() | ||
} | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
MovieApp/app/src/main/java/com/god/taeiim/movieapp/base/BaseViewModel.kt
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,30 @@ | ||
package com.god.taeiim.movieapp.base | ||
|
||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import com.god.taeiim.movieapp.ext.toLiveData | ||
import kotlin.properties.Delegates | ||
|
||
abstract class BaseViewModel<ViewState : BaseViewState, ViewAction : BaseAction>( | ||
initialState: ViewState | ||
) : ViewModel() { | ||
|
||
private val stateMutableLiveData = MutableLiveData<ViewState>() | ||
val stateLiveData = stateMutableLiveData.toLiveData() | ||
|
||
protected var state by Delegates.observable(initialState) { _, old, new -> | ||
stateMutableLiveData.value = new | ||
} | ||
|
||
fun sendAction(viewAction: ViewAction) { | ||
state = onReduceState(viewAction) | ||
} | ||
|
||
fun loadData() { | ||
onLoadData() | ||
} | ||
|
||
protected open fun onLoadData() {} | ||
|
||
protected abstract fun onReduceState(viewAction: ViewAction): ViewState | ||
} |
3 changes: 3 additions & 0 deletions
3
MovieApp/app/src/main/java/com/god/taeiim/movieapp/base/BaseViewState.kt
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,3 @@ | ||
package com.god.taeiim.movieapp.base | ||
|
||
interface BaseViewState |
14 changes: 14 additions & 0 deletions
14
MovieApp/app/src/main/java/com/god/taeiim/movieapp/binding/ViewBinding.kt
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,14 @@ | ||
package com.god.taeiim.movieapp.binding | ||
|
||
import android.widget.ImageView | ||
import androidx.databinding.BindingAdapter | ||
import com.bumptech.glide.Glide | ||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners | ||
|
||
@BindingAdapter("loadPosterImg") | ||
fun ImageView.loadPosterImg(url: String?) { | ||
Glide.with(context) | ||
.load("https://image.tmdb.org/t/p/w300$url") | ||
.transform(RoundedCorners(8)) | ||
.into(this) | ||
} |
45 changes: 45 additions & 0 deletions
45
MovieApp/app/src/main/java/com/god/taeiim/movieapp/data/model/MoviePopular.kt
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,45 @@ | ||
package com.god.taeiim.movieapp.data.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class MoviePopular( | ||
@SerializedName("page") | ||
val page: Int = 0, | ||
@SerializedName("results") | ||
val movies: List<Movie> = listOf(), | ||
@SerializedName("total_pages") | ||
val totalPages: Int = 0, | ||
@SerializedName("total_results") | ||
val totalResults: Int = 0 | ||
) | ||
|
||
data class Movie( | ||
@SerializedName("adult") | ||
val adult: Boolean = false, | ||
@SerializedName("backdrop_path") | ||
val backdropPath: String = "", | ||
@SerializedName("genre_ids") | ||
val genreIds: List<Int> = listOf(), | ||
@SerializedName("id") | ||
val id: Int = 0, | ||
@SerializedName("original_language") | ||
val originalLanguage: String = "", | ||
@SerializedName("original_title") | ||
val originalTitle: String = "", | ||
@SerializedName("overview") | ||
val overview: String = "", | ||
@SerializedName("popularity") | ||
val popularity: Double = 0.0, | ||
@SerializedName("poster_path") | ||
val posterPath: String = "", | ||
@SerializedName("release_date") | ||
val releaseDate: String = "", | ||
@SerializedName("title") | ||
val title: String = "", | ||
@SerializedName("video") | ||
val video: Boolean = false, | ||
@SerializedName("vote_average") | ||
val voteAverage: Double = 0.0, | ||
@SerializedName("vote_count") | ||
val voteCount: Int = 0 | ||
) |
10 changes: 10 additions & 0 deletions
10
MovieApp/app/src/main/java/com/god/taeiim/movieapp/data/repository/MovieRepository.kt
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.god.taeiim.movieapp.data.repository | ||
|
||
import com.god.taeiim.movieapp.data.model.Movie | ||
|
||
|
||
interface MovieRepository { | ||
|
||
suspend fun getPopularMovies(page: Int): List<Movie> | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
MovieApp/app/src/main/java/com/god/taeiim/movieapp/data/repository/MovieRepositoryImpl.kt
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,15 @@ | ||
package com.god.taeiim.movieapp.data.repository | ||
|
||
import com.god.taeiim.movieapp.data.model.Movie | ||
import com.god.taeiim.movieapp.data.source.remote.MovieRemoteDataSource | ||
|
||
|
||
class MovieRepositoryImpl( | ||
private val movieRemoteDataSource: MovieRemoteDataSource | ||
) : MovieRepository { | ||
|
||
override suspend fun getPopularMovies(page: Int): List<Movie> { | ||
return movieRemoteDataSource.getPopularMovies(page) | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
MovieApp/app/src/main/java/com/god/taeiim/movieapp/data/source/MovieApi.kt
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.god.taeiim.movieapp.data.source | ||
|
||
import com.god.taeiim.movieapp.data.model.MoviePopular | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
interface MovieApi { | ||
@GET("movie/popular") | ||
suspend fun getMoviePopular(@Query("page") page: Int): MoviePopular | ||
} |
9 changes: 9 additions & 0 deletions
9
...App/app/src/main/java/com/god/taeiim/movieapp/data/source/remote/MovieRemoteDataSource.kt
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,9 @@ | ||
package com.god.taeiim.movieapp.data.source.remote | ||
|
||
import com.god.taeiim.movieapp.data.model.Movie | ||
|
||
interface MovieRemoteDataSource { | ||
|
||
suspend fun getPopularMovies(page: Int): List<Movie> | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...app/src/main/java/com/god/taeiim/movieapp/data/source/remote/MovieRemoteDataSourceImpl.kt
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,18 @@ | ||
package com.god.taeiim.movieapp.data.source.remote | ||
|
||
import com.god.taeiim.movieapp.data.model.Movie | ||
import com.god.taeiim.movieapp.data.source.MovieApi | ||
import retrofit2.HttpException | ||
|
||
class MovieRemoteDataSourceImpl(private val movieApi: MovieApi) : | ||
MovieRemoteDataSource { | ||
|
||
override suspend fun getPopularMovies(page: Int): List<Movie> { | ||
return try { | ||
movieApi.getMoviePopular(page).movies | ||
} catch (e: HttpException) { | ||
listOf() | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
이부분에 대해서 공부 한번 해보시면 좋을꺼 같습니다.