diff --git a/app/src/main/java/com/example/movieapp/BindingAdapter.kt b/app/src/main/java/com/example/movieapp/BindingAdapter.kt index b567886..cb4a5e0 100644 --- a/app/src/main/java/com/example/movieapp/BindingAdapter.kt +++ b/app/src/main/java/com/example/movieapp/BindingAdapter.kt @@ -51,6 +51,47 @@ fun TextView.bindYear(year: Int?) { } } +//Binding adapter used to display time from object +@BindingAdapter("time") +fun TextView.bindTime(time: String?) { + time?.let { + text = time + } +} + +//Binding adapter used to display language from object +@BindingAdapter("language") +fun TextView.bindLanguage(language: String?) { + language?.let { + text = language + } +} + +//Binding adapter used to display writer from object +@BindingAdapter("writer") +fun TextView.bindWriter(writer: String?) { + writer?.let { + text = writer + } +} + +//Binding adapter used to display actors from object +@BindingAdapter("actors") +fun TextView.bindActors(actors: String?) { + actors?.let { + text = actors + } +} + +//Binding adapter used to display genre from object +@BindingAdapter("genre") +fun TextView.bindGenre(genre: String?) { + genre?.let { + text = genre + } +} + + //Binding adapter used to set adapter of RecyclerView @BindingAdapter("listData") fun bindRecyclerView(recyclerView: RecyclerView, data: List?) { diff --git a/app/src/main/java/com/example/movieapp/MainActivity.kt b/app/src/main/java/com/example/movieapp/MainActivity.kt index 5a4dfee..c041d5d 100644 --- a/app/src/main/java/com/example/movieapp/MainActivity.kt +++ b/app/src/main/java/com/example/movieapp/MainActivity.kt @@ -3,6 +3,8 @@ package com.example.movieapp import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatDelegate +import androidx.navigation.fragment.NavHostFragment +import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { @@ -12,5 +14,10 @@ class MainActivity : AppCompatActivity() { //Function for Light-Dark theme AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.getDefaultNightMode()) + + val myNavHostFragment: NavHostFragment = nav_host_fragment as NavHostFragment + val inflater = myNavHostFragment.navController.navInflater + val graph = inflater.inflate(R.navigation.navigation) + myNavHostFragment.navController.graph = graph } } diff --git a/app/src/main/java/com/example/movieapp/database/DatabaseEntities.kt b/app/src/main/java/com/example/movieapp/database/DatabaseEntities.kt index fbe60a8..163cce0 100644 --- a/app/src/main/java/com/example/movieapp/database/DatabaseEntities.kt +++ b/app/src/main/java/com/example/movieapp/database/DatabaseEntities.kt @@ -17,7 +17,12 @@ data class DatabaseMovie( val poster: String, val year: Int, val rated: String, - val plot: String + val plot: String, + val genre: String, + val time: String, + val language: String, + val writer: String, + val actors: String ) //Convert database object to movie object @@ -29,7 +34,13 @@ fun List.asDomainModel(): List { poster = it.poster, year = it.year, rated = it.rated, - plot = it.plot + plot = it.plot, + genre = it.genre, + time = it.time, + language = it.language, + writer = it.writer, + actors = it.actors + ) } } diff --git a/app/src/main/java/com/example/movieapp/database/Room.kt b/app/src/main/java/com/example/movieapp/database/Room.kt index 631d17b..eec0322 100644 --- a/app/src/main/java/com/example/movieapp/database/Room.kt +++ b/app/src/main/java/com/example/movieapp/database/Room.kt @@ -16,7 +16,7 @@ interface MovieDao { } //Create DAO object -@Database(entities = [DatabaseMovie::class], version = 1) +@Database(entities = [DatabaseMovie::class], version = 2) abstract class MovieDatabase : RoomDatabase() { abstract val movieDao: MovieDao } @@ -32,7 +32,7 @@ fun getDatabase(context: Context): MovieDatabase { context.applicationContext, MovieDatabase::class.java, "movies" - ).build() + ).fallbackToDestructiveMigration().build() } } return INSTANCE diff --git a/app/src/main/java/com/example/movieapp/domain/Movie.kt b/app/src/main/java/com/example/movieapp/domain/Movie.kt index fb8e3bc..939c1c4 100644 --- a/app/src/main/java/com/example/movieapp/domain/Movie.kt +++ b/app/src/main/java/com/example/movieapp/domain/Movie.kt @@ -16,7 +16,12 @@ data class Movie( val poster: String, val year: Int, val rated: String, - val plot: String + val plot: String, + val genre: String, + val time: String, + val language: String, + val writer: String, + val actors: String ) : Parcelable { val isR get() = rated == "R" diff --git a/app/src/main/java/com/example/movieapp/network/MovieProperty.kt b/app/src/main/java/com/example/movieapp/network/MovieProperty.kt index e27c8b8..451ddc4 100644 --- a/app/src/main/java/com/example/movieapp/network/MovieProperty.kt +++ b/app/src/main/java/com/example/movieapp/network/MovieProperty.kt @@ -12,7 +12,13 @@ data class MovieProperty( @Json(name = "Poster") val poster: String, @Json(name = "Year") val year: Int, @Json(name = "Rated") val rated: String, - @Json(name = "Plot") val plot: String + @Json(name = "Plot") val plot: String, + @Json(name = "Genre") val genre: String, + @Json(name = "Runtime") val time: String, + @Json(name = "Language") val language: String, + @Json(name = "Writer") val writer: String, + @Json(name = "Actors") val actors:String + ) //Convert network result to database object @@ -24,7 +30,12 @@ fun List.asDatabaseModal(): List { poster = it.poster, year = it.year, rated = it.rated, - plot = it.plot + plot = it.plot, + genre = it.genre, + time = it.time, + language = it.language, + writer = it.writer, + actors = it.actors ) } } \ No newline at end of file diff --git a/app/src/main/res/layout/detail_fragment.xml b/app/src/main/res/layout/detail_fragment.xml index f95a0f5..e3ba214 100644 --- a/app/src/main/res/layout/detail_fragment.xml +++ b/app/src/main/res/layout/detail_fragment.xml @@ -13,7 +13,7 @@ android:id="@+id/frameLayout" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".detail.DetailFragment"> + tools:context=".ui.detail.DetailFragment"> + app:layout_constraintTop_toBottomOf="@+id/toolbar" + android:contentDescription="@string/plot" /> + tools:text="Documentary, History, War" + app:genre="@{viewModel.selectProperty.genre}"/> + tools:text="99 min" + app:time="@{viewModel.selectProperty.time}"/> + tools:text="English" + app:language="@{viewModel.selectProperty.language}"/> + app:layout_constraintTop_toBottomOf="@+id/textView5" + app:writer="@{viewModel.selectProperty.writer}" + tools:text="Peter Jackson" /> + app:layout_constraintTop_toBottomOf="@+id/textView6" + tools:text="Mark Kermode, Peter Jackson" /> false #121212 + @color/appColor \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c0f91ed..a2f9cb0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,6 @@ MovieApp + Plot + Writer + Actors diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 0257b5d..a61e140 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -3,7 +3,7 @@