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 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 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 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 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
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 MainActivity extends AppCompatActivity { | |
StringAdapter adapter; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
adapter = new StringAdapter( | |
Arrays.asList("Harry Potter", "Ron Weasley"), |
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
package com.example.android.testing.notes.notes | |
import com.example.android.testing.notes.data.Note | |
import com.example.android.testing.notes.data.NotesRepository | |
import com.nhaarman.mockito_kotlin.* | |
import org.jetbrains.spek.api.Spek | |
import org.jetbrains.spek.api.dsl.given | |
import org.jetbrains.spek.api.dsl.it | |
import org.jetbrains.spek.api.dsl.on |
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
/** | |
* Returns a list containing only elements matching the given [predicate]. | |
*/ | |
public inline fun <T> Iterable<T>.filter(predicate: (T) -> Boolean): List<T> { | |
return filterTo(ArrayList<T>(), predicate) | |
} | |
/** | |
* Appends all elements matching the given [predicate] to the given [destination]. | |
*/ |
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 Predicate<T> { | |
Boolean check(T element); | |
} |