Skip to content

Commit

Permalink
Merge pull request #9 from gusentanan/development/v2
Browse files Browse the repository at this point in the history
Development/v2
  • Loading branch information
gusentanan authored Sep 7, 2023
2 parents 816f1af + 35df5b1 commit 4b0099c
Show file tree
Hide file tree
Showing 354 changed files with 2,724 additions and 1,700 deletions.
3 changes: 2 additions & 1 deletion .idea/gradle.xml

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

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
<td>All Movie</td>
</tr>
<tr>
<td><img src="assets/main.jpg" width=280 ></td>
<td><img src="assets/detail.jpg" width=280 ></td>
<td><img src="assets/allmovie.jpg" width=280 ></td>
<td><img src="arts/main.jpg" width=280 ></td>
<td><img src="arts/detail-1.jpg" width=280 ></td>
<td><img src="arts/allmovie.jpg" width=280 ></td>
</tr>
<tr>
<td><img src="assets/search.jpg" width=280 ></td>
<td><img src="assets/favoritee.jpg" width=280 ></td>
<td><img src="arts/search-2.jpg" width=280 ></td>
<td><img src="arts/favoritee.jpg" width=280 ></td>
</tr>
<td>Search</td>
<td>Favoritee</td>
Expand Down
14 changes: 6 additions & 8 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ android {
debug {
applicationIdSuffix = ".debug"
versionNameSuffix = "-debug"
isMinifyEnabled = true
isShrinkResources = true
isMinifyEnabled = false
isShrinkResources = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
Expand All @@ -48,12 +48,13 @@ android {

dependencies {

implementation(project(":core"))
implementation(project(":core-logic"))
implementation(project(":feature:detail"))
implementation(project(":feature:search"))
implementation(project(":feature:allmovie"))
implementation(project(":feature:favoritee"))
implementation(project(":utility"))
implementation(project(":common-ui"))

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.activity.ktx)
Expand All @@ -71,13 +72,10 @@ dependencies {
implementation(libs.lottie)
implementation(libs.material)
implementation(libs.splash.screen)

// sdp and ssp dep
implementation("com.intuit.sdp:sdp-android:1.1.0")
implementation("com.intuit.ssp:ssp-android:1.1.0")
implementation(libs.intuit.sdp)
implementation(libs.intuit.ssp)


//stepper dep
implementation("com.tbuonomo:dotsindicator:4.3")

}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<activity
android:name=".presentation.main.MainActivity"
android:exported="false"
android:theme="@style/Theme.MaterialComponents.Light.NoActionBar.Bridge"/>
android:theme="@style/AppThemeTranslucent"/>
</application>

</manifest>
3 changes: 1 addition & 2 deletions app/src/main/java/com/bagusmerta/moviee/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import com.bagusmerta.feature.detail.presentation.DetailViewModel
import com.bagusmerta.feature.favoritee.presentation.FavoriteeViewModel
import com.bagusmerta.feature.search.presentation.SearchViewModel
import com.bagusmerta.moviee.presentation.main.MainViewModel
import org.koin.android.ext.koin.androidApplication
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module

Expand All @@ -32,7 +31,7 @@ val useCaseModule = module {
}

val viewModelModule = module {
viewModel { MainViewModel(get(), androidApplication()) } // app context to access Resource or perform operation that require context
viewModel { MainViewModel(get()) }
viewModel { DetailViewModel(get()) }
viewModel { FavoriteeViewModel(get()) }
viewModel { SearchViewModel(get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,30 @@
package com.bagusmerta.moviee.presentation.main

import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.bagusmerta.core.domain.model.HomeFeed
import com.bagusmerta.core.domain.model.Moviee
import com.bagusmerta.core.utils.DataMapper
import com.bagusmerta.feature.detail.presentation.DetailActivity
import com.bagusmerta.feature.favoritee.presentation.FavoriteeActivity
import com.bagusmerta.feature.search.presentation.SearchActivity
import com.bagusmerta.moviee.R
import com.bagusmerta.moviee.databinding.ActivityMainBinding
import com.bagusmerta.moviee.helpers.Helpers
import com.bagusmerta.moviee.presentation.main.adapter.MainAdapter
import com.bagusmerta.utility.findRandom
import com.bagusmerta.utility.loadHighQualityImage
import com.bagusmerta.utility.makeGone
import com.bagusmerta.utility.makeInfoToast
import com.bagusmerta.utility.makeVisible
import com.bagusmerta.utility.extensions.changeBackgroundColorAppBar
import com.bagusmerta.utility.extensions.findRandom
import com.bagusmerta.utility.extensions.initTransparentStatusBar
import com.bagusmerta.utility.extensions.joinToGenreString
import com.bagusmerta.utility.extensions.loadCoilImageHQ
import com.bagusmerta.utility.extensions.makeGone
import com.bagusmerta.utility.extensions.makeInfoToast
import com.bagusmerta.utility.extensions.makeVisible
import org.koin.androidx.viewmodel.ext.android.viewModel
import timber.log.Timber
import kotlin.math.min

class MainActivity : AppCompatActivity() {

Expand All @@ -49,14 +52,15 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)
initTransparentStatusBar()
initAppBar()
observerAppBar()

initStateObserver()
initRecyclerView()
}

private fun initAppBar(){
window.statusBarColor = ContextCompat.getColor(this, R.color.colorSecondaryDark)
binding.apply {
btnFavorite.setOnClickListener{
startActivity(Intent(this@MainActivity, FavoriteeActivity::class.java))
Expand All @@ -67,31 +71,50 @@ class MainActivity : AppCompatActivity() {
}
}

private fun initStateObserver() {
with(mainViewModel){
getAllFeed()
private fun observerAppBar() {
binding.apply {
nestedScroll.setOnScrollChangeListener { _, _, scrollY, _, oldScrollY ->
if (scrollY > oldScrollY) { // scroll down
materialAppBarLayout.visibility = View.GONE
} else {
if (scrollY < oldScrollY) { // scroll up
materialAppBarLayout.visibility = View.VISIBLE

val colorInt = ContextCompat.getColor(
this@MainActivity,
com.bagusmerta.common_ui.R.color.black_transparent_light
)
val fraction = (min(255, scrollY).toFloat() / 255.0f).toDouble()
materialAppBarLayout.setBackgroundColor(colorInt.changeBackgroundColorAppBar(fraction))
}
}
}
}
}

resultBanner.observe(this@MainActivity){
private fun initStateObserver() {
with(mainViewModel) {
resultBanner.observe(this@MainActivity) {
runOnUiThread {
it?.let { data -> handleBannerResult(data) }
}
}
resultAllFeed.observe(this@MainActivity){
resultAllFeed.observe(this@MainActivity) {
runOnUiThread {
handleMovieeResult(it)
}
}
loadingState.observe(this@MainActivity){
loadingState.observe(this@MainActivity) {
handleLoadingState(it)
}
errorState.observe(this@MainActivity){
errorState.observe(this@MainActivity) {
handleErrorState(it)
}
}
}


private fun handleInfoState(msg: String){
private fun handleInfoState(msg: String) {
this.makeInfoToast(msg)
}

Expand All @@ -107,18 +130,18 @@ class MainActivity : AppCompatActivity() {
val banner: Moviee = bannerItems.findRandom()!!

binding.iWrapperBanner.apply {
if(data.isNotEmpty()){
if (data.isNotEmpty()) {
tvGenreBanner.makeVisible()
mbMoreInfoBanner.makeVisible()
}
ivBanner.loadHighQualityImage(banner.posterPath)
tvGenreBanner.text = Helpers.mappingMovieGenreListFromId(banner.genreId)
.joinToString("") { it.name.toString() }
ivBanner.loadCoilImageHQ(banner.posterPath)
tvGenreBanner.text = DataMapper.mappingMovieGenreListFromId(banner.genreId)
.map { it.name }
.joinToGenreString()

mbMoreInfoBanner.setOnClickListener {
startActivity(Intent(this@MainActivity, DetailActivity::class.java).apply {
putExtra(DetailActivity.MOVIEE, banner.id)
})
putExtra(DetailActivity.MOVIEE, banner.id) })
}
}
}
Expand Down Expand Up @@ -153,5 +176,4 @@ class MainActivity : AppCompatActivity() {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,21 @@
*/
package com.bagusmerta.moviee.presentation.main

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.bagusmerta.core.data.Resource
import com.bagusmerta.core.domain.model.HomeFeed
import com.bagusmerta.core.domain.model.Moviee
import com.bagusmerta.core.domain.usecase.MovieeUseCase
import com.bagusmerta.moviee.R
import com.bagusmerta.utility.datasource.MovieeHomeFeed
import io.reactivex.Observable
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import timber.log.Timber


class MainViewModel(private val useCase: MovieeUseCase, application: Application): AndroidViewModel(application) {
class MainViewModel(private val useCase: MovieeUseCase): ViewModel() {

private val mCompositeDisposable = CompositeDisposable()
private val _resultBanner = MutableLiveData<List<Moviee>?>()
Expand All @@ -40,6 +39,10 @@ class MainViewModel(private val useCase: MovieeUseCase, application: Application
private val _errorState = MutableLiveData<String>()
private val _emptyState = MutableLiveData<Boolean>()

init {
getAllFeed()
}

val resultBanner: LiveData<List<Moviee>?>
get() = _resultBanner

Expand All @@ -55,9 +58,6 @@ class MainViewModel(private val useCase: MovieeUseCase, application: Application
val errorState: LiveData<String>
get() = _errorState

private fun getMyStringResource(resId: Int): String {
return getApplication<Application>().getString(resId)
}
fun getAllFeed(){
Observable.zip(
useCase.getAllMovies().toObservable(),
Expand Down Expand Up @@ -89,8 +89,7 @@ class MainViewModel(private val useCase: MovieeUseCase, application: Application
private fun validateNewlyMovies(newly: Resource<List<Moviee>>){
when(newly){
is Resource.Success -> {
val homeFeed = HomeFeed(getMyStringResource(R.string.tv_newly_movies),
getMyStringResource(R.string.tv2_recommend_movies), newly.data, 1)
val homeFeed = HomeFeed(MovieeHomeFeed.NEWLY_MOVIES, newly.data)

_listFeed.add(homeFeed)
}
Expand All @@ -102,8 +101,8 @@ class MainViewModel(private val useCase: MovieeUseCase, application: Application
private fun validateUpcoming(upcoming: Resource<List<Moviee>>){
when(upcoming){
is Resource.Success -> {
val homeFeed = HomeFeed(getMyStringResource(R.string.tv_upcoming_movies),
getMyStringResource(R.string.tv2_upcoming_movies), upcoming.data, 2)
val homeFeed = HomeFeed(
MovieeHomeFeed.UPCOMING_MOVIES, upcoming.data)

_listFeed.add(homeFeed)
}
Expand All @@ -115,8 +114,9 @@ class MainViewModel(private val useCase: MovieeUseCase, application: Application
private fun validatePopular(popular: Resource<List<Moviee>>){
when(popular){
is Resource.Success -> {
val homeFeed = HomeFeed(getMyStringResource(R.string.tv_popular_movies),
getMyStringResource(R.string.tv2_popular_movies), popular.data, 3)
val homeFeed = HomeFeed(
MovieeHomeFeed.POPULAR_MOVIES, popular.data)

_listFeed.add(homeFeed)
}
is Resource.Error -> _errorState.postValue(popular.errorMessage)
Expand All @@ -127,8 +127,8 @@ class MainViewModel(private val useCase: MovieeUseCase, application: Application
private fun validateTopRated(top: Resource<List<Moviee>>){
when(top){
is Resource.Success -> {
val homeFeed = HomeFeed(getMyStringResource(R.string.tv_toprated_movies),
getMyStringResource(R.string.tv2_toprated_movies), top.data, 4)
val homeFeed = HomeFeed(
MovieeHomeFeed.TOP_RATED_MOVIES, top.data)

_listFeed.add(homeFeed)
}
Expand All @@ -140,8 +140,8 @@ class MainViewModel(private val useCase: MovieeUseCase, application: Application
private fun validateNowPLaying(now: Resource<List<Moviee>>){
when(now){
is Resource.Success -> {
val homeFeed = HomeFeed(getMyStringResource(R.string.tv_nowplaying_movies),
getMyStringResource(R.string.tv2_nowplaying_movies), now.data, 5)
val homeFeed = HomeFeed(
MovieeHomeFeed.NOW_PLAYING_MOVIES, now.data)

_listFeed.add(homeFeed)
}
Expand All @@ -150,7 +150,6 @@ class MainViewModel(private val useCase: MovieeUseCase, application: Application
}
}


private fun getBannerMovies(){
useCase.getAllMovies()
.doOnSubscribe {
Expand All @@ -173,5 +172,4 @@ class MainViewModel(private val useCase: MovieeUseCase, application: Application
mCompositeDisposable.clear()
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import android.content.Intent
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bagusmerta.common_ui.databinding.ItemMainComponentBinding
import com.bagusmerta.core.domain.model.Moviee
import com.bagusmerta.feature.detail.presentation.DetailActivity
import com.bagusmerta.moviee.databinding.ItemMainComponentBinding
import com.bagusmerta.utility.loadImage
import com.bagusmerta.utility.extensions.loadCoilImage

class HorizontalMovieListAdapter(private val context: Context): RecyclerView.Adapter<HorizontalMovieListAdapter.ViewHolder>(){

Expand All @@ -32,7 +32,7 @@ class HorizontalMovieListAdapter(private val context: Context): RecyclerView.Ada
inner class ViewHolder(private val binding: ItemMainComponentBinding): RecyclerView.ViewHolder(binding.root){
fun bind(item: Moviee){
binding.apply {
ivPoster.loadImage(item.posterPath)
ivPoster.loadCoilImage(item.posterPath)
tvMovieRating.text = item.rating.toString()

itemView.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class MainAdapter(private val context: Context): RecyclerView.Adapter<MainAdapte
inner class ViewHolder(private val binding: ItemHorizontalMovieListBinding): RecyclerView.ViewHolder(binding.root){
fun bind(item: HomeFeed){
binding.apply {
tvRecommendMovies.text = item.feedTitle
tv2RecommendMovies.text = item.feedSubHeader
tvRecommendMovies.text = item.feedResources?.text
tv2RecommendMovies.text = item.feedResources?.subText
btnSeeAllRecommend.setOnClickListener {
context.startActivity(Intent(context, AllMovieActivity::class.java).apply {
putExtra(AllMovieActivity.IDENTIFIER, item.movieSection)
putExtra(AllMovieActivity.IDENTIFIER, item.feedResources?.id)
})
}

Expand Down
Loading

0 comments on commit 4b0099c

Please sign in to comment.