diff options
Diffstat (limited to 'app/src/main/java/xyz/adjutor/aniki/presentation/view')
-rw-r--r-- | app/src/main/java/xyz/adjutor/aniki/presentation/view/anime/DetailSearchAnimeActivity.kt | 78 |
1 files changed, 18 insertions, 60 deletions
diff --git a/app/src/main/java/xyz/adjutor/aniki/presentation/view/anime/DetailSearchAnimeActivity.kt b/app/src/main/java/xyz/adjutor/aniki/presentation/view/anime/DetailSearchAnimeActivity.kt index f9d1325..5acf1c3 100644 --- a/app/src/main/java/xyz/adjutor/aniki/presentation/view/anime/DetailSearchAnimeActivity.kt +++ b/app/src/main/java/xyz/adjutor/aniki/presentation/view/anime/DetailSearchAnimeActivity.kt @@ -7,39 +7,32 @@ import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions -import com.google.gson.GsonBuilder -import retrofit2.Call -import retrofit2.Callback -import retrofit2.Response -import retrofit2.Retrofit -import retrofit2.converter.gson.GsonConverterFactory import xyz.adjutor.aniki.R -import xyz.adjutor.aniki.data.anime.AnimeApi +import xyz.adjutor.aniki.presentation.controller.anime.DetailSearchAnimeController import xyz.adjutor.aniki.presentation.model.anime.AnimeResponse class DetailSearchAnimeActivity : AppCompatActivity() { - private var baseUrl = "https://api.jikan.moe/" - private val gson = GsonBuilder() - .setLenient() - .create() - - //used in the list - private val intentAnimeImageUrl = "theanimeimageurl" - private val intentAnimeTitle = "theanimetitle" - private val intentAnimeScore = "theanimescore" - - //only used for the detail - private val intentAnimeId = "theanimeid" - private val intentAnimeUrl = "theanimeurl" - private val intentAnimeEpisodes = "theanimeepisodes" - private val intentAnimeStartDate = "theanimestartdate" - private val intentAnimeEndDate = "theanimeenddate" + lateinit var controller: DetailSearchAnimeController override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_detail_search_anime) + controller = DetailSearchAnimeController() + + //used in the list + val intentAnimeImageUrl = "theanimeimageurl" + val intentAnimeTitle = "theanimetitle" + val intentAnimeScore = "theanimescore" + + //only used for the detail + val intentAnimeId = "theanimeid" + val intentAnimeUrl = "theanimeurl" + val intentAnimeEpisodes = "theanimeepisodes" + val intentAnimeStartDate = "theanimestartdate" + val intentAnimeEndDate = "theanimeenddate" + val animeImageUrl = intent.getStringExtra(intentAnimeImageUrl) val animeTitle = intent.getStringExtra(intentAnimeTitle) val animeScore = intent.getStringExtra(intentAnimeScore) @@ -88,7 +81,7 @@ class DetailSearchAnimeActivity : AppCompatActivity() { fieldIsNull() } - makeApiCall(baseUrl, animeId.toString()) + controller.onStart(this, animeId.toString()) } @@ -100,42 +93,7 @@ class DetailSearchAnimeActivity : AppCompatActivity() { } - private fun makeApiCall( - BASE_URL: String, - animeId: String - ) { //we take the rest of the data that we need from the internet - - val retrofit = Retrofit.Builder() - .baseUrl(BASE_URL) - .addConverterFactory(GsonConverterFactory.create(gson)) - .build() - - val service = retrofit.create(AnimeApi::class.java) - val call = service.getAnimeData(animeId) //based on the id - - call.enqueue(object : Callback<AnimeResponse> { - override fun onResponse( - call: Call<AnimeResponse>, - response: Response<AnimeResponse> - ) { - if (response.isSuccessful && response.body() != null) { //if the code returned is >= 200 and < 300 AND the the body ain't empty - - val anime = response.body() //getting the AnimeResponse fields - showDetail(anime!!) - - } else { - showError("API ERROR : is not successful") - } - } - - override fun onFailure(call: Call<AnimeResponse>, t: Throwable) { - showError("API ERROR : onFailure") - } - - }) - } - - private fun showDetail(anime: AnimeResponse) { + fun showDetail(anime: AnimeResponse) { //elements from AnimeResponse val tvSynopsis: TextView = findViewById(R.id.tv_synopsis) val tvRank: TextView = findViewById(R.id.tv_detail_rank) |