Skip to content

Commit

Permalink
Final App Complete Commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayhack committed Jun 20, 2021
1 parent 573d672 commit e4176b5
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bonushub.pax.model.local
package com.example.maztestmovieapp.model.database

import android.content.Context
import androidx.room.Database
Expand All @@ -8,11 +8,6 @@ import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import com.example.maztestmovieapp.model.database.*


/**
* =========Written By Ajay Thakur (18th Nov 2020)==========
**/

@Database(
entities = [Results::class],
version = 1, exportSchema = false
Expand All @@ -25,7 +20,7 @@ abstract class AppDatabase : RoomDatabase() {

companion object {
private var dbInstance: AppDatabase? = null
private var dbName: String = "HdfcDB"
private var dbName: String = "mazMovieDB"

@Synchronized
fun getDatabase(context: Context): AppDatabase? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.example.maztestmovieapp.model.database

import android.os.Parcelable
import androidx.annotation.NonNull
import androidx.room.Entity
import androidx.room.PrimaryKey
import kotlinx.parcelize.Parcelize

//region===============Results Data Class Used for mapping data from Https response and also used to store data in DB:-
@Parcelize
@Entity
data class Results(
Expand All @@ -15,4 +15,5 @@ data class Results(
var original_title: String = "",
var poster_path: String = "",
var isFavourite: Boolean = false,
var isClicked: Boolean = false) : Parcelable
var isClicked: Boolean = false) : Parcelable
//endregion
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package com.example.maztestmovieapp.service

import android.util.Log
import com.example.maztestmovieapp.model.MovieDBResponse
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Call
Expand Down Expand Up @@ -47,19 +42,9 @@ fun getClient(): Retrofit {
}
//endregion

//region========================CoroutineExceptionHandler:-
fun coroutineExceptionHandler(): CoroutineExceptionHandler {
return CoroutineExceptionHandler { _, t ->
GlobalScope.launch(Dispatchers.Main) {
t.printStackTrace()
Log.d("Failed To Connect", "Server Error")
}
}
}
//endregion


//region=================API Client to used with Retrofit Request:-
internal interface ApiClient{
@GET("movie/popular")
fun getPopularMovies(@Query("api_key") apiKey: String?): Call<MovieDBResponse>
}
}
//endregion
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ class ServiceRepository {

//region==========================Getting Data and Stubbing Data in Modal:-
fun getMutableLiveData(): MutableLiveData<ArrayList<Results?>>? {
val service : ApiClient = getClient().create(ApiClient :: class.java)
val call: Call<MovieDBResponse> =service.getPopularMovies("f8c2fb3301267b649b40cb8d22023776")
val service: ApiClient = getClient().create(ApiClient::class.java)
val call: Call<MovieDBResponse> =
service.getPopularMovies("f8c2fb3301267b649b40cb8d22023776")
call.enqueue(object : Callback<MovieDBResponse?> {
override fun onResponse(call: Call<MovieDBResponse?>, response: Response<MovieDBResponse?>) {
val movieResponse: MovieDBResponse? = response.body()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package com.example.maztestmovieapp.utils
import android.app.Activity
import android.app.Dialog
import android.os.Bundle
import android.view.*
import android.view.Window
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.example.maztestmovieapp.R

//region==================Base Activity to create Progress Dialog make other Activity use this functionality by extending this Activity:-
abstract class BaseActivity : AppCompatActivity(), IDialog {
private lateinit var progressDialog: Dialog
lateinit var progressTitleMsg: TextView
Expand Down Expand Up @@ -44,4 +45,5 @@ abstract class BaseActivity : AppCompatActivity(), IDialog {
interface IDialog {
fun showProgress(progressMsg: String = "Please Wait....")
fun hideProgress()
}
}
//endregion
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.bonushub.pax.model.local.AppDatabase
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.example.maztestmovieapp.R
import com.example.maztestmovieapp.databinding.ActivityDashboardBinding
import com.example.maztestmovieapp.databinding.MovieListItemBinding
import com.example.maztestmovieapp.model.database.AppDatabase
import com.example.maztestmovieapp.model.database.Results
import com.example.maztestmovieapp.utils.BaseActivity
import com.example.maztestmovieapp.viewmodal.DashboardViewModal
Expand Down Expand Up @@ -73,11 +73,11 @@ class DashBoardActivity : BaseActivity() {
//endregion

//region===============Below method is used to setUp RecyclerView of Top Rated Movies List:-
private fun setUpRecyclerView(){
private fun setUpRecyclerView() {
binding?.rvMovies?.apply {
layoutManager = if(orientation == Configuration.ORIENTATION_PORTRAIT) {
layoutManager = if (orientation == Configuration.ORIENTATION_PORTRAIT) {
GridLayoutManager(this@DashBoardActivity, 2)
} else{
} else {
GridLayoutManager(this@DashBoardActivity, 4)
}

Expand All @@ -95,6 +95,7 @@ class DashBoardActivity : BaseActivity() {
moviesLiveData = popularMovieDataFromDB
setUpRecyclerView()
hideProgress()
Toast.makeText(this@DashBoardActivity, "You are offline", Toast.LENGTH_LONG).show()
}
}else {
lifecycleScope.launch(Dispatchers.Main) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.maztestmovieapp.view

import android.os.Bundle
import android.view.View
import android.widget.Toast
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.example.maztestmovieapp.R
Expand All @@ -22,22 +23,26 @@ class MovieDetailPageActivity : BaseActivity() {
binding?.toolBar?.toolbarTitle?.text = getString(R.string.movie_detail_page)

//region===============Binding Movie Data with UI Elements:-
binding?.tvTitleLanguage?.text = movieData?.original_language?:""
binding?.tvTitle?.text = movieData?.original_title?:""
val moviePosterPath = "https://image.tmdb.org/t/p/w500" + movieData?.poster_path
binding?.posterImage?.let {
Glide.with(this)
.load(moviePosterPath).apply(RequestOptions().error(R.drawable.loading))
.into(it)
}
val rating = "${movieData?.vote_average?:0.0} / 10"
binding?.tvRating?.text = rating?:""
if (movieData != null) {
binding?.tvTitleLanguage?.text = movieData?.original_language ?: ""
binding?.tvTitle?.text = movieData?.original_title ?: ""
val moviePosterPath = "https://image.tmdb.org/t/p/w500" + movieData?.poster_path
binding?.posterImage?.let {
Glide.with(this)
.load(moviePosterPath).apply(RequestOptions().error(R.drawable.loading))
.into(it)
}
val rating = "${movieData?.vote_average ?: 0.0} / 10"
binding?.tvRating?.text = rating

if(movieData?.isFavourite == true)
binding?.favouriteIcon?.setImageResource(R.drawable.ic_favourite_24red)
else
binding?.favouriteIcon?.setImageResource(R.drawable.ic_favorite_24white)
//endregion
if (movieData?.isFavourite == true)
binding?.favouriteIcon?.setImageResource(R.drawable.ic_favourite_24red)
else
binding?.favouriteIcon?.setImageResource(R.drawable.ic_favorite_24white)
//endregion
} else {
Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG).show()
}
}

override fun onBackPressed() {
Expand Down

0 comments on commit e4176b5

Please sign in to comment.