This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abstract class ItemViewHolder<T : Any, VH>(itemView: View) : RecyclerView.ViewHolder(itemView) { | |
| lateinit var item: T | |
| var onClick: ((view: View, position: Int, holder: VH, item: T) -> Unit)? = null | |
| init { | |
| itemView.setOnClickListener { callOnClick(it) } | |
| } | |
| fun callOnClick(view: View) { | |
| onClick?.let { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Apis { | |
| public static StarWarsApi getSwarWarsApi() { | |
| Gson gson = new GsonBuilder() | |
| .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) | |
| .create(); | |
| Retrofit retrofit = new Retrofit.Builder() | |
| .baseUrl("http://swapi.co/api/") | |
| .addConverterFactory(GsonConverterFactory.create(gson)) | |
| .build(); | |
| return retrofit.create(StarWarsApi.class); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MainActivity extends AppCompatActivity { | |
| RecyclerView recyclerView; | |
| SwipeRefreshLayout swipeRefreshLayout; | |
| FilmAdapter filmAdapter; | |
| StarWarsApi starWarsApi; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MainActivity extends AppCompatActivity implements HomeContract.HomeView { | |
| RecyclerView recyclerView; | |
| SwipeRefreshLayout swipeRefreshLayout; | |
| FilmAdapter filmAdapter; | |
| HomeContract.HomePresenter presenter; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class HomePresenter implements HomeContract.HomePresenter { | |
| private HomeContract.HomeView view; | |
| private StarWarsApi starWarsApi; | |
| public HomePresenter(HomeContract.HomeView view) { | |
| this.view = view; | |
| starWarsApi = Apis.getSwarWarsApi(); | |
| view.showTitle("All Star Wars Films"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface HomeContract { | |
| interface HomeView { | |
| void showLoading(); | |
| void hideLoading(); | |
| void showTitle(String title); | |
| void showMessage(String message); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class PersonAdapter extends RecyclerView.Adapter<PersonAdapter.PersonHolder> { | |
| private List<Person> list; | |
| public PersonAdapter(@NonNull List<Person> list) { | |
| this.list = list; | |
| } | |
| @Override | |
| public PersonHolder onCreateViewHolder(ViewGroup parent, int viewType) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Person { | |
| public String name; | |
| public int age; | |
| public boolean isChecked; | |
| public Person(String name, int age) { | |
| this.name = name; | |
| this.age = age; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MainActivity extends AppCompatActivity { | |
| RecyclerView recyclerView; | |
| List<Person> people; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| recyclerView = (RecyclerView) findViewById(R.id.recyclerView); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Person { | |
| public String name; | |
| public int age; | |
| public Person(String name, int age) { | |
| this.name = name; | |
| this.age = age; | |
| } | |
| } |