MoviesData.java
is a Java class. I'm trying to pass it to another class from MainActivity.kt
to MovieRequest.kt
I'm trying to refactor and have very little idea about what I'm doing.
Here is MoviesData.java
public class MoviesData {
@NotNull
public final List<? extends Result> results;
public MoviesData(List<? extends Result> results) {
this.results = results;
}
}
This is the piece in MainActivity.kt
that is probably wrong:
val movieType = MoviesData( *****results:***** I don't know what to put here *****)
MovieRequest(movieType)
This is MovieRequest.kt
. Note that all of the instances of movieType
in this file are showing errors, so there's likely something wrong here as well:
open class MovieRequest(movieType: Array<String>) : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val request = ServiceBuilder.buildService(TmdbEndpoints::class.java)
val call = request.getMovies(getString(R.string.api_key))
call.enqueue(object : Callback<movieType> {
override fun onResponse(call: Call<movieType>, response: Response<movieType>) {
if (response.isSuccessful) {
progress_bar.visibility = View.GONE
recyclerView.apply {
setHasFixedSize(true)
layoutManager = LinearLayoutManager(this@MovieRequest)
adapter = MoviesAdapter(response.body()!!.results as List<Result>)
}
}
}
override fun onFailure(call: Call<MoviesData>, t: Throwable) {
Toast.makeText(this@MovieRequest, "${t.message}", Toast.LENGTH_SHORT).show()
}
})
}
}