Skip to content

Commit

Permalink
Merge pull request #3 from Urdzik/new_movie_detail
Browse files Browse the repository at this point in the history
New movie detail
  • Loading branch information
Slavik Urdzik authored Feb 6, 2020
2 parents fdf5255 + ab3bc92 commit 0ef23b4
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 30 deletions.
41 changes: 41 additions & 0 deletions app/src/main/java/com/example/movieapp/BindingAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Movie>?) {
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/example/movieapp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,7 +34,13 @@ fun List<DatabaseMovie>.asDomainModel(): List<Movie> {
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

)
}
}
4 changes: 2 additions & 2 deletions app/src/main/java/com/example/movieapp/database/Room.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -32,7 +32,7 @@ fun getDatabase(context: Context): MovieDatabase {
context.applicationContext,
MovieDatabase::class.java,
"movies"
).build()
).fallbackToDestructiveMigration().build()
}
}
return INSTANCE
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/com/example/movieapp/domain/Movie.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 13 additions & 2 deletions app/src/main/java/com/example/movieapp/network/MovieProperty.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,7 +30,12 @@ fun List<MovieProperty>.asDatabaseModal(): List<DatabaseMovie> {
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
)
}
}
51 changes: 29 additions & 22 deletions app/src/main/res/layout/detail_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
Expand All @@ -34,7 +34,8 @@
android:src="@android:color/background_dark"
app:imageUrl="@{viewModel.selectProperty.poster}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar" />
app:layout_constraintTop_toBottomOf="@+id/toolbar"
android:contentDescription="@string/plot" />

<TextView
android:id="@+id/title_detail"
Expand All @@ -43,7 +44,6 @@
android:layout_marginStart="24dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="16dp"
android:text="Title"
android:textColor="?attr/actionMenuTextColor"
android:textSize="24sp"
android:textStyle="bold"
Expand All @@ -59,7 +59,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/title_detail"
Expand All @@ -68,47 +67,50 @@
app:year="@{viewModel.selectProperty.year}"/>

<TextView
android:layout_marginEnd="16dp"
android:id="@+id/genre_ditale"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/year_ditale"
app:layout_constraintTop_toBottomOf="@+id/year_ditale"
tools:text="Documentary, History, War" />
tools:text="Documentary, History, War"
app:genre="@{viewModel.selectProperty.genre}"/>

<TextView
android:layout_marginEnd="16dp"
android:id="@+id/runtimes_ditale"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/genre_ditale"
app:layout_constraintTop_toBottomOf="@+id/genre_ditale"
tools:text="99 min" />
tools:text="99 min"
app:time="@{viewModel.selectProperty.time}"/>

<TextView
android:layout_marginEnd="16dp"
android:id="@+id/langue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/runtimes_ditale"
app:layout_constraintTop_toBottomOf="@+id/runtimes_ditale"
tools:text="English" />
tools:text="English"
app:language="@{viewModel.selectProperty.language}"/>

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Plot"
android:text="@string/plot"
android:textColor="?attr/editTextColor"
android:textSize="18sp"
android:textStyle="bold"
Expand All @@ -121,7 +123,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:layout_marginTop="24dp"
android:text="Writer"
android:text="@string/writer"
android:textColor="?attr/editTextColor"
android:textSize="18sp"
android:textStyle="bold"
Expand All @@ -133,33 +135,39 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Actors"
android:text="@string/actors"
android:textColor="?attr/editTextColor"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="@+id/textView5"
app:layout_constraintTop_toBottomOf="@+id/textView7" />

<TextView
tools:text="Peter Jackson"
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:layout_marginTop="8dp"
android:text="TextView"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/textView5"
app:layout_constraintTop_toBottomOf="@+id/textView5" />
app:layout_constraintTop_toBottomOf="@+id/textView5"
app:writer="@{viewModel.selectProperty.writer}"
tools:text="Peter Jackson" />

<TextView
tools:text="Mark Kermode, Peter Jackson"
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="TextView"
android:layout_marginEnd="16dp"
app:actors="@{viewModel.selectProperty.actors}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/textView7"
app:layout_constraintTop_toBottomOf="@+id/textView6" />
app:layout_constraintTop_toBottomOf="@+id/textView6"
tools:text="Mark Kermode, Peter Jackson" />


<TextView
Expand All @@ -168,7 +176,6 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/textView8"
app:layout_constraintTop_toBottomOf="@+id/textView4"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-night/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
<item name="colorPrimaryDark">#121212</item>
<item name="colorPrimary">@color/appColor</item>
</style>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<resources>
<string name="app_name">MovieApp</string>
<string name="plot">Plot</string>
<string name="writer">Writer</string>
<string name="actors">Actors</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#000</item>
<item name="colorPrimary">@color/appColor</item>
<item name="colorPrimaryDark">#fff</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
Expand Down

0 comments on commit 0ef23b4

Please sign in to comment.