-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Add] Implement movie details screen
- Loading branch information
1 parent
a5c2e75
commit b1db788
Showing
19 changed files
with
344 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
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
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
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
45 changes: 45 additions & 0 deletions
45
app/src/main/java/com/sun/android/ui/detail/DetailFragment.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.sun.android.ui.detail | ||
|
||
import androidx.core.os.bundleOf | ||
import androidx.lifecycle.Observer | ||
import com.sun.android.base.BaseFragment | ||
import com.sun.android.databinding.FragmentDetailBinding | ||
import com.sun.android.utils.extension.goBackFragment | ||
import com.sun.android.utils.extension.loadImageCircleWithUrl | ||
import com.sun.android.utils.extension.loadImageWithUrl | ||
import org.koin.androidx.viewmodel.ext.android.viewModel | ||
|
||
class DetailFragment : BaseFragment<FragmentDetailBinding>(FragmentDetailBinding::inflate) { | ||
|
||
override val viewModel: MovieDetailViewModel by viewModel() | ||
|
||
override fun initView() { | ||
binding.buttonImageBack.setOnClickListener { goBackFragment() } | ||
} | ||
|
||
override fun initData() { | ||
arguments?.run { | ||
val mMovieId = getInt(ARGUMENT_MOVIE_ID, -1) | ||
viewModel.requestMovieDetails(mMovieId) | ||
} | ||
} | ||
|
||
override fun bindData() { | ||
viewModel.movie.observe(viewLifecycleOwner, Observer { | ||
binding.imageBackDrop.loadImageWithUrl(it.backDropImage) | ||
binding.imageMovie.loadImageCircleWithUrl(it.urlImage) | ||
binding.textTitle.text = it.title | ||
binding.textDescription.text = it.overView | ||
binding.textRatting.text = it.vote.toString() | ||
binding.textTotalReview.text = it.voteCount.toString() | ||
}) | ||
} | ||
|
||
companion object { | ||
private const val ARGUMENT_MOVIE_ID = "ARGUMENT_MOVIE_ID" | ||
|
||
fun newInstance(movieId: Int) = DetailFragment().apply { | ||
arguments = bundleOf(ARGUMENT_MOVIE_ID to movieId) | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/sun/android/ui/detail/MovieDetailViewModel.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,19 @@ | ||
package com.sun.android.ui.detail | ||
|
||
import com.sun.android.base.BaseViewModel | ||
import com.sun.android.data.MovieRepository | ||
import com.sun.android.data.model.Movie | ||
import com.sun.android.utils.livedata.SingleLiveData | ||
|
||
class MovieDetailViewModel(private val movieRepository: MovieRepository) : BaseViewModel() { | ||
val movie = SingleLiveData<Movie>() | ||
|
||
fun requestMovieDetails(movieId: Int) { | ||
launchTaskSync(onRequest = { | ||
movieRepository.getDetailMovies(movieId) | ||
}, | ||
onSuccess = { | ||
movie.value = it | ||
}) | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
app/src/main/java/com/sun/android/utils/extension/FragmentExtension.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,54 @@ | ||
package com.sun.android.utils.extension | ||
|
||
import androidx.annotation.IdRes | ||
import androidx.fragment.app.Fragment | ||
import com.sun.android.R | ||
|
||
fun Fragment.addFragment( | ||
@IdRes containerId: Int, | ||
fragment: Fragment, | ||
addToBackStack: Boolean = false, | ||
tag: String? = fragment::class.java.simpleName | ||
) { | ||
activity?.supportFragmentManager?.apply { | ||
beginTransaction().apply { | ||
if (addToBackStack) { | ||
addToBackStack(tag) | ||
} | ||
setCustomAnimations( | ||
R.anim.slide_in_right, | ||
R.anim.slide_in_right, | ||
R.anim.slide_out_right, | ||
R.anim.slide_out_right | ||
) | ||
add(containerId, fragment, tag) | ||
}.commit() | ||
} | ||
} | ||
|
||
fun Fragment.replaceFragment( | ||
@IdRes containerId: Int, | ||
fragment: Fragment, | ||
addToBackStack: Boolean, | ||
tag: String? = fragment::class.java.simpleName | ||
) { | ||
activity?.supportFragmentManager?.apply { | ||
beginTransaction().apply { | ||
if (addToBackStack) { | ||
addToBackStack(tag) | ||
} | ||
replace(containerId, fragment, tag) | ||
}.commit() | ||
} | ||
} | ||
|
||
fun Fragment.goBackFragment(): Boolean { | ||
activity?.supportFragmentManager?.notNull { | ||
val isShowPreviousPage = it.backStackEntryCount > 0 | ||
if (isShowPreviousPage) { | ||
it.popBackStackImmediate() | ||
} | ||
return isShowPreviousPage | ||
} | ||
return false | ||
} |
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 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<set xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<translate | ||
android:duration="300" | ||
android:fromXDelta="100%" | ||
android:fromYDelta="0%" | ||
android:toXDelta="0%" | ||
android:toYDelta="0%" /> | ||
</set> |
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 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<set xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<translate | ||
android:duration="300" | ||
android:fromXDelta="0%" | ||
android:fromYDelta="0%" | ||
android:toXDelta="100%" | ||
android:toYDelta="0%" /> | ||
</set> |
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,11 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="32dp" | ||
android:height="32dp" | ||
android:autoMirrored="true" | ||
android:tint="#FFFFFF" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z" /> | ||
</vector> |
Oops, something went wrong.