Skip to content

Commit

Permalink
Merge pull request #7 from Urdzik/the-movie-db-branch
Browse files Browse the repository at this point in the history
The movie db branch
  • Loading branch information
Slavik Urdzik authored Mar 2, 2020
2 parents 47a7cdf + 7b6069c commit 457259a
Show file tree
Hide file tree
Showing 20 changed files with 299 additions and 185 deletions.
87 changes: 87 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

# Built application files
*.apk
*.aar
*.ap_
*.aab

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/
# Uncomment the following line in case you need and you don't have the release build type files in your app
# release/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
*.iml
.idea
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
.cxx/

# Google Services (e.g. APIs or Firebase)
# google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json

# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md

# Version control
vcs.xml

# lint
lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<uses-permission android:name="android.permission.INTERNET"/>


<application
android:name=".dagger.App"
android:allowBackup="true"
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/com/example/movieapp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,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

// val myNavHostFragment: NavHostFragment = nav_host_fragment as NavHostFragment
// val inflater = myNavHostFragment.navController.navInflater
// val graph = inflater.inflate(R.navigation.navigation)
// myNavHostFragment.navController.graph = graph
}
}
2 changes: 0 additions & 2 deletions app/src/main/java/com/example/movieapp/dagger/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.example.movieapp.dagger.component.DaggerAppComponent
import com.example.movieapp.dagger.module.NetworkModule
import com.example.movieapp.ui.detail.DetailActivity


class App : Application(){
companion object{
lateinit var appComponent: AppComponent
Expand All @@ -19,5 +18,4 @@ class App : Application(){
.networkModule(NetworkModule(this))
.build()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class NetworkModule (private val application: Application) {
internal fun provideRetrofitInterface( okHttpClient: OkHttpClient): Retrofit = Retrofit.Builder()
.addConverterFactory(MoshiConverterFactory.create())
.addCallAdapterFactory(CoroutineCallAdapterFactory())
.baseUrl("https://raw.githubusercontent.com/Urdzik/helper/master/")
.baseUrl("https://api.themoviedb.org/3/movie/")
.client(okHttpClient)
.build()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ class ViewModelFactory @Inject constructor(private val viewModel: MutableMap<Cla
?: throw IllegalArgumentException(" model class $modelClass not found")
return viewModelProvider.get() as T
}

}
10 changes: 8 additions & 2 deletions app/src/main/java/com/example/movieapp/model/network/MovieApi.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.example.movieapp.model.network

import com.example.movieapp.model.network.data.MovieInfo
import com.example.movieapp.model.network.data.Results
import retrofit2.http.GET
import retrofit2.http.Path


//A retrofit service to fetch movie playlist.
interface MovieApi {
@GET("movie.json")
suspend fun getPropertyAsync(): List<NetworkMovie>
@GET("top_rated?api_key=26f381d6ab8dd659b22d983cab9aa255&language=ru&page=1")
suspend fun getPropertyAsync(): Results

@GET("{id}?api_key=26f381d6ab8dd659b22d983cab9aa255&language=ru")
suspend fun getMovieByID(@Path("id") id: Int): MovieInfo
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package com.example.movieapp.model.network

import com.example.movieapp.model.network.data.MovieInfo
import com.example.movieapp.model.network.data.NetworkMovie
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import javax.inject.Inject

class NetworkSource @Inject constructor(
private val api: MovieApi
) {
class NetworkSource @Inject constructor(private val api: MovieApi) {
suspend fun retrieveData(): List<NetworkMovie> = withContext(Dispatchers.IO) {
val playList = api.getPropertyAsync()
playList
playList.networkMovie
}
}

class MovieInfoSource @Inject constructor(private val api: MovieApi){
suspend fun retrieveInfoData(id: Int): MovieInfo = withContext(Dispatchers.IO){
val infoOfMovie = api.getMovieByID(id)
infoOfMovie
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.example.movieapp.model.network.data


data class MovieInfo (
val adult: Boolean,
val backdrop_path: String,
val belongs_to_collection: String,
val budget: Int,
val genres: List<Genres>,
val homepage: String,
val id: Int,
val imdb_id: String,
val original_language: String,
val original_title: String,
val overview: String,
val popularity: Double,
val poster_path: String,
val production_companies: List<ProductionCompanies>,
val production_countries: List<ProductionCountries>,
val release_date: String,
val revenue: Int,
val runtime: Int,
val spoken_languages: List<SpokenLanguages>,
val status: String,
val tagline: String,
val title: String,
val video: Boolean,
val vote_average: Double,
val vote_count: Int
)

data class SpokenLanguages (
val iso_639_1: String,
val name: String
)
data class ProductionCountries (
val iso_3166_1: String,
val name: String
)
data class ProductionCompanies (
val id: Int,
val logo_path: String,
val name: String,
val origin_country: String
)

data class Genres (
val id: Int,
val name: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.example.movieapp.model.network.data

import android.view.View
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

//Network object of movie for REST
@JsonClass(generateAdapter = true)
data class Results(
@Json(name = "results") val networkMovie: List<NetworkMovie>,
@Json(name = "page") val page: Int,
@Json(name = "total_results") val totalResults: Int,
@Json(name = "total_pages") val totalPages: Int
)

data class NetworkMovie(
val id: Int,
val adult: Boolean,
val popularity: Double,
val voteCount: Int,
val video: Boolean,
val poster_path: String,
val backdrop_path: String,
val original_language: String,
val original_title: String,
val genre_ids: List<Int>,
val title: String,
val vote_average: Double,
val overview: String,
val release_date: String
){
val plus18
get() = if (adult) View.VISIBLE else View.GONE
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package com.example.movieapp.ui.detail


import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import com.example.movieapp.R
import com.example.movieapp.dagger.App
import com.example.movieapp.dagger.module.viewModule.ViewModelFactory
import com.example.movieapp.databinding.DetailActivityBinding
import com.example.movieapp.model.network.NetworkMovie
import javax.inject.Inject


Expand All @@ -30,9 +30,9 @@ class DetailActivity : AppCompatActivity() {

viewModel = ViewModelProvider(this, viewModelFactory).get(DetailViewModel::class.java)

val movie: NetworkMovie = intent.getParcelableExtra("movie")
val movieId = intent.getIntExtra("movie", 0)

viewModel.getSelectMovie(movie)
viewModel.getSelectMovie(movieId)


// Create Toolbar and button of back in toolbar
Expand All @@ -45,18 +45,17 @@ class DetailActivity : AppCompatActivity() {
setHomeButtonEnabled(true)
setDisplayShowTitleEnabled(false)
}

//Button of back
setNavigationOnClickListener {
super.onBackPressed()
}
}

//Button of back


binding.viewModel = viewModel
binding.lifecycleOwner = this


}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package com.example.movieapp.ui.detail

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.example.movieapp.model.network.NetworkMovie
import androidx.lifecycle.viewModelScope
import com.example.movieapp.model.network.MovieInfoSource
import com.example.movieapp.model.network.data.MovieInfo
import com.example.movieapp.model.network.data.NetworkMovie
import kotlinx.coroutines.launch
import javax.inject.Inject

class DetailViewModel @Inject constructor() : ViewModel() {
class DetailViewModel @Inject constructor(private val movieInfoSource: MovieInfoSource) : ViewModel() {

//LiveData object of movie
private val _selectProperty = MutableLiveData<NetworkMovie>()
val selectProperty: LiveData<NetworkMovie>
private val _selectProperty = MutableLiveData<MovieInfo>()
val selectProperty: LiveData<MovieInfo>
get() = _selectProperty


fun getSelectMovie(networkMovie: NetworkMovie) {
_selectProperty.value = networkMovie
fun getSelectMovie(id: Int) {
viewModelScope.launch {
_selectProperty.value = movieInfoSource.retrieveInfoData(id)
}
}
}
Loading

0 comments on commit 457259a

Please sign in to comment.