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
/** | |
* This is a contract between chat view and chat presenter. | |
* | |
*/ | |
public interface ChatContract { | |
interface View extends BaseView<Presenter>, EventListener { | |
void onMessageDelivered(ChatMessage chatMessage); | |
} |
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
/** | |
* Closes the socket connection when app is in background and | |
* connects to socket when the app is in foreground. | |
*/ | |
public class AppLifeCycleObserver implements LifecycleObserver { | |
private Context mContext; | |
/** | |
* Use this constructor to create a new AppLifeCycleObserver |
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 BaseApplication extends Application { | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
// Observer to detect if the app is in background or foreground. | |
AppLifeCycleObserver lifeCycleObserver | |
= new AppLifeCycleObserver(getApplicationContext()); | |
// Adding the above observer to process lifecycle |
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
dependencies { | |
implementation 'com.android.support:appcompat-v7:27.1.1' | |
implementation 'androidx.constraintlayout:constraintlayout:1.1.2' | |
// RxJava library and RxAndroid for Android specific bindings | |
implementation 'io.reactivex.rxjava2:rxjava:2.2.0' | |
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2' | |
// Retrofit and OkHttp | |
implementation 'com.squareup.retrofit2:retrofit:2.4.0' |
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
{ | |
"userId": 1, | |
"id": 1, | |
"title": "delectus aut autem", | |
"completed": false | |
} |
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 Todo { | |
String userId; | |
int id; | |
String title; | |
boolean completed; | |
public String getFormattedInfo() { | |
StringBuilder builder = new StringBuilder(); | |
builder.append("Title: " + title + "\n\n"); |
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 ApiService { | |
@GET("/todos/1") | |
Flowable<Todo> getFirstTodo(); | |
} |
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 HttpClient { | |
private static final String API_BASE_URL = "https://jsonplaceholder.typicode.com/"; | |
private static Retrofit retrofit = new Retrofit.Builder() | |
.baseUrl(API_BASE_URL) | |
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | |
.addConverterFactory(GsonConverterFactory.create()) | |
.build(); | |
private static ApiService apiService = retrofit.create(ApiService.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 SchedulerProvider { | |
// UI thread | |
public static Scheduler ui() { | |
return AndroidSchedulers.mainThread(); | |
} | |
// IO thread | |
public static Scheduler io() { | |
return Schedulers.io(); |
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 { | |
private ApiService apiService = HttpClient.getApiService(); | |
private TextView tvStatus, tvInfo; | |
private Button btnHttpRequest, btnReset; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); |