Skip to content

Commit

Permalink
Merge pull request #36 from intive-FDV/improvements/sprint_3
Browse files Browse the repository at this point in the history
Improvements/sprint 3
  • Loading branch information
juanigdom authored Oct 14, 2021
2 parents 6128fc4 + 64ec4b8 commit 0e5808a
Show file tree
Hide file tree
Showing 108 changed files with 566 additions and 948 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"entities": [
{
"tableName": "ScreeningORMEntity",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `backdrop_path` TEXT, `genres` TEXT, `name` TEXT NOT NULL, `number_of_episodes` INTEGER, `number_of_seasons` INTEGER, `overview` TEXT NOT NULL, `poster_path` TEXT, `status` TEXT, `vote_average` REAL NOT NULL, `vote_count` INTEGER NOT NULL, `popularity` REAL NOT NULL, `release_date` TEXT, `media_type` TEXT NOT NULL, `adult` INTEGER NOT NULL, `genre_ids` TEXT, `video` INTEGER NOT NULL, `networks` TEXT NOT NULL, `my_rate` REAL NOT NULL, `my_favorite` INTEGER NOT NULL, PRIMARY KEY(`id`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `backdrop_path` TEXT, `genres` TEXT, `name` TEXT NOT NULL, `number_of_episodes` INTEGER, `number_of_seasons` INTEGER, `overview` TEXT NOT NULL, `poster_path` TEXT, `status` TEXT, `vote_average` REAL NOT NULL, `popularity` REAL NOT NULL, `release_date` TEXT, `media_type` TEXT NOT NULL, `adult` INTEGER NOT NULL, `genre_ids` TEXT, `video` INTEGER NOT NULL, `networks` TEXT NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
Expand Down Expand Up @@ -68,12 +68,6 @@
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "vote_count",
"columnName": "vote_count",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "popularity",
"columnName": "popularity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.content.Context
import androidx.room.Room
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.intive.tmdbandroid.entity.ScreeningORMEntity
import com.intive.tmdbandroid.entity.room.ScreeningORMEntity
import com.intive.tmdbandroid.model.Genre
import com.intive.tmdbandroid.model.Network
import junit.framework.TestCase
Expand Down Expand Up @@ -33,13 +33,14 @@ class LocalStorageTest : TestCase() {
poster_path = "POSTER_PATH",
status = "Online",
vote_average = 10.5,
vote_count = 100,
popularity = 34.0,
media_type = "tv",
adult = false,
genre_ids = null,
video = false,
networks = listOf(Network("/netflixlogo.jpg", "netflix", 123, "ARG"))
networks = listOf(Network("/netflixlogo.jpg")),
my_rate = 3.5,
my_favorite = true
)

private val screeningUpdate = ScreeningORMEntity(
Expand All @@ -54,13 +55,14 @@ class LocalStorageTest : TestCase() {
poster_path = "POSTER_PATH_2",
status = "Online",
vote_average = 10.5,
vote_count = 100,
popularity = 34.0,
media_type = "tv",
adult = false,
genre_ids = null,
video = false,
networks = listOf(Network("/netflixlogo.jpg", "netflix", 123, "ARG"))
networks = listOf(Network("/netflixlogo.jpg")),
my_rate = 3.5,
my_favorite = true
)

// Override function setUp() and annotate it with @Before
Expand Down Expand Up @@ -107,7 +109,7 @@ class LocalStorageTest : TestCase() {
dao.insertFavorite(screening)
val exists = dao.existAsFavorite(screening.id)

assertThat("Expecting result to be true", exists)
assertThat("Expecting result to be true", exists == screening)

dao.updateFavorite(screeningUpdate)
val tvShowsDeleted = dao.allFavorites()
Expand All @@ -122,6 +124,6 @@ class LocalStorageTest : TestCase() {
fun writeAndReadOneFailureTest() = runBlocking {
val exists = dao.existAsFavorite(screening.id)

assertThat("Expecting result to be true", !exists)
assertThat("Expecting result to be true", exists != screening)
}
}
14 changes: 10 additions & 4 deletions app/src/main/java/com/intive/tmdbandroid/common/RetrofitHelper.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package com.intive.tmdbandroid.common

import com.intive.tmdbandroid.BuildConfig
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import okhttp3.OkHttpClient

import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.time.Duration

object RetrofitHelper {
fun getRetrofit() : Retrofit {
val interceptor = HttpLoggingInterceptor()
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY)

val client = OkHttpClient.Builder().addInterceptor(interceptor).build()
val client = OkHttpClient.Builder()
.addInterceptor(interceptor)
.callTimeout(Duration.ofMinutes(1))
.connectTimeout(Duration.ofSeconds(30))
.readTimeout(Duration.ofSeconds(30))
.writeTimeout(Duration.ofSeconds(30))
.build()

return Retrofit.Builder()
.baseUrl(BuildConfig.API_BASE_URL)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ScreeningPagingSource(private val service: Service, private val type: Int)
companion object {
const val DEFAULT_PAGE_INDEX = 1

const val TYPE_TVSHOW = 1
const val TYPE_TV_SHOW = 1
const val TYPE_MOVIE = 2
}

Expand All @@ -21,13 +21,13 @@ class ScreeningPagingSource(private val service: Service, private val type: Int)
lateinit var screenings: List<Screening>

when (type) {
TYPE_TVSHOW -> {
TYPE_TV_SHOW -> {
service.getPaginatedPopularTVShows(pageNumber).collect { screenings = it.toScreeningList() }
}
TYPE_MOVIE -> {
service.getPaginatedPopularMovies(pageNumber).collect { screenings = it.toScreeningList() }
}
else -> throw RuntimeException("Ilegal type parameter")
else -> throw RuntimeException("Illegal type parameter")
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.intive.tmdbandroid.datasource.local

import androidx.room.*
import androidx.room.Dao
import com.intive.tmdbandroid.entity.ScreeningORMEntity
import com.intive.tmdbandroid.entity.room.ScreeningORMEntity
import com.intive.tmdbandroid.entity.SessionORMEntity

@Dao
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.intive.tmdbandroid.datasource.local
import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.intive.tmdbandroid.entity.ScreeningORMEntity
import com.intive.tmdbandroid.entity.room.ScreeningORMEntity
import com.intive.tmdbandroid.entity.SessionORMEntity
import com.intive.tmdbandroid.model.converter.GenreConverter
import com.intive.tmdbandroid.model.converter.IntConverter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package com.intive.tmdbandroid.datasource.network

import com.intive.tmdbandroid.entity.*
import com.intive.tmdbandroid.entity.network.ResultListTVShowOrMovies
import com.intive.tmdbandroid.entity.network.ResultCombinedCredits
import com.intive.tmdbandroid.entity.person.ResultPeopleEntity
import com.intive.tmdbandroid.entity.person.ResultPerson
import com.intive.tmdbandroid.entity.movie.ResultMoviesEntity
import com.intive.tmdbandroid.entity.tvshow.ResultTVShowsEntity
import com.intive.tmdbandroid.entity.video.VideoEntity
import com.intive.tmdbandroid.model.Movie
import com.intive.tmdbandroid.model.Session
import com.intive.tmdbandroid.model.TVShow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ package com.intive.tmdbandroid.datasource.network

import com.intive.tmdbandroid.BuildConfig
import com.intive.tmdbandroid.common.RetrofitHelper
import com.intive.tmdbandroid.entity.*
import com.intive.tmdbandroid.entity.network.ResultListTVShowOrMovies
import com.intive.tmdbandroid.entity.movie.ResultMoviesEntity
import com.intive.tmdbandroid.entity.person.ResultPeopleEntity
import com.intive.tmdbandroid.entity.person.ResultPerson
import com.intive.tmdbandroid.entity.tvshow.ResultTVShowsEntity
import com.intive.tmdbandroid.model.Movie
import com.intive.tmdbandroid.model.Screening
import com.intive.tmdbandroid.model.TVShow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@ class DetailAndSearchActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
val binding = ActivityDetailAndSearchBinding.inflate(layoutInflater)
setContentView(binding.root)
val context = binding.root.context

val navHost = supportFragmentManager.findFragmentById(R.id.nav_host_detail_and_search) as NavHostFragment
val navController = navHost.navController

val graph = navController
.navInflater.inflate(R.navigation.nav_graph)

val action = intent.extras?.getString("action", "search")
val action = intent.extras?.getString(
context.getString(R.string.intent_extra_key_action),
context.getString(R.string.intent_extra_key_action_default)
)

action.let {
if (it.equals("search")){
if (it.equals(context.getString(R.string.intent_extra_key_action_default))){
graph.startDestination = R.id.searchFragmentDest
} else {
graph.startDestination = R.id.detailFragmentDest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,19 @@ class DetailFragment : Fragment() {
viewModel.uiState.collect { state ->
when (state) {
is State.Success -> {
binding.layoutErrorDetail.errorContainer.visibility = View.GONE
binding.layoutLoadingDetail.progressBar.visibility = View.GONE
binding.layoutErrorDetail.root.visibility = View.GONE
binding.layoutLoadingDetail.root.visibility = View.GONE
screening = state.data
setupUI(binding)
}
is State.Error -> {
binding.layoutLoadingDetail.progressBar.visibility = View.GONE
binding.layoutErrorDetail.errorContainer.visibility = View.VISIBLE
binding.layoutLoadingDetail.root.visibility = View.GONE
binding.layoutErrorDetail.root.visibility = View.VISIBLE
binding.coordinatorContainerDetail.visibility = View.VISIBLE
}
else -> {
binding.layoutErrorDetail.errorContainer.visibility = View.GONE
binding.layoutLoadingDetail.progressBar.visibility = View.VISIBLE
binding.layoutErrorDetail.root.visibility = View.GONE
binding.layoutLoadingDetail.root.visibility = View.VISIBLE
}
}
}
Expand All @@ -174,8 +174,8 @@ class DetailFragment : Fragment() {
viewModel.watchlistUIState.collectLatest {
when (it) {
is State.Success -> {
binding.layoutErrorDetail.errorContainer.visibility = View.GONE
binding.layoutLoadingDetail.progressBar.visibility = View.GONE
binding.layoutErrorDetail.root.visibility = View.GONE
binding.layoutLoadingDetail.root.visibility = View.GONE
if (it.data == null) {
selectOrUnselectWatchlistFav(binding, false)
isSaveOnWatchlist = false
Expand All @@ -192,13 +192,12 @@ class DetailFragment : Fragment() {
showRateOrStar(binding)
}
State.Error -> {
binding.layoutLoadingDetail.progressBar.visibility = View.GONE
binding.layoutErrorDetail.errorContainer.visibility = View.VISIBLE
binding.coordinatorContainerDetail.visibility = View.VISIBLE
binding.layoutLoadingDetail.root.visibility = View.GONE
Toast.makeText(context, "Couldn't save to watchlist. Please try later", Toast.LENGTH_LONG).show()
}
else -> {
binding.layoutErrorDetail.errorContainer.visibility = View.GONE
binding.layoutLoadingDetail.progressBar.visibility = View.VISIBLE
binding.layoutErrorDetail.root.visibility = View.GONE
binding.layoutLoadingDetail.root.visibility = View.VISIBLE
}
}
}
Expand All @@ -217,9 +216,10 @@ class DetailFragment : Fragment() {
showDialog(it.data)
}
}
else -> {
is State.Error -> {
Toast.makeText(context, "There was an error. Please try again", Toast.LENGTH_LONG).show()
}
else -> { }
}
}
}
Expand Down Expand Up @@ -322,12 +322,10 @@ class DetailFragment : Fragment() {
) {
val percentage = (voteAverage * 10).toInt()

binding.popularityRatingNumber.text =
requireContext().resources.getString(R.string.popularity, percentage)


val context = binding.root.context

binding.popularityRatingNumber.text = context.getString(R.string.popularity, percentage)

when {
percentage < 25 -> binding.popularityThumbIcon.imageTintList =
ContextCompat.getColorStateList(context, R.color.red)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.CircularProgressDrawable
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.intive.tmdbandroid.R
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.intive.tmdbandroid.details.ui.adapters

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
Expand Down Expand Up @@ -54,6 +55,7 @@ class RecommendationAdapter(private val widthSize: Int, private val clickListene
val circularProgressDrawable = CircularProgressDrawable(itemView.context).apply {
strokeWidth = 5f
centerRadius = 25f
setColorSchemeColors(ContextCompat.getColor(context, R.color.material_on_background_emphasis_high_type))
}
circularProgressDrawable.start()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.intive.tmdbandroid.details.ui.person.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
Expand Down Expand Up @@ -46,6 +47,7 @@ class CombinedCreditsAdapter(
val circularProgressDrawable = CircularProgressDrawable(itemView.context).apply {
strokeWidth = 5f
centerRadius = 25f
setColorSchemeColors(ContextCompat.getColor(context, R.color.material_on_background_emphasis_high_type))
}
circularProgressDrawable.start()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.intive.tmdbandroid.common.State
import com.intive.tmdbandroid.databinding.FragmentDetailPersonBinding
import com.intive.tmdbandroid.details.ui.person.adapter.CombinedCreditsAdapter
import com.intive.tmdbandroid.details.ui.person.viewmodel.DetailPersonViewModel
import com.intive.tmdbandroid.entity.ResultPerson
import com.intive.tmdbandroid.entity.person.ResultPerson
import com.intive.tmdbandroid.model.Screening
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collectLatest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.intive.tmdbandroid.details.ui.person.viewmodel
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.intive.tmdbandroid.common.State
import com.intive.tmdbandroid.entity.ResultPerson
import com.intive.tmdbandroid.entity.person.ResultPerson
import com.intive.tmdbandroid.model.Screening
import com.intive.tmdbandroid.usecase.person.GetCombinedCreditsUseCase
import com.intive.tmdbandroid.usecase.person.GetDetailPersonUseCase
Expand Down
Loading

0 comments on commit 0e5808a

Please sign in to comment.