Skip to content

Instantly share code, notes, and snippets.

Avatar

Aditya Ladwa adityaladwa

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am ladwaaditya on github.
  • I am adi7ya (https://keybase.io/adi7ya) on keybase.
  • I have a public key ASA1clHNjrtj9NeZe_a5iO32Uv-VyAJLt_1OHTHTim4ixwo

To claim this, I am signing this object:

@adityaladwa
adityaladwa / RxSchedulerExtensionForJunit5.kt
Last active Jun 25, 2020
RxJava Scheduler Override rule for Junit5
View RxSchedulerExtensionForJunit5.kt
package com.ladwa.aditya
import io.reactivex.Scheduler
import io.reactivex.android.plugins.RxAndroidPlugins
import io.reactivex.plugins.RxJavaPlugins
import io.reactivex.schedulers.Schedulers
import org.junit.jupiter.api.extension.AfterEachCallback
import org.junit.jupiter.api.extension.BeforeEachCallback
import org.junit.jupiter.api.extension.ExtensionContext
import java.util.concurrent.Callable
View OkhttpBuilder.kt
val okhttpClientBuilder = OkHttpClient.Builder()
val networkInterceptor = NetworkInterceptor(context)
okhttpClientBuilder.addInterceptor(networkInterceptor)
val okhttpClient = okhttpClientBuilder.build()
View MainActivity.java
viewModel.login()
.subscribeWith(new DisposableSingleObserver<Result>() {
@Override
public void onSuccess(Result result) {
//Handle Success
}
@Override
public void onError(Throwable e) {
if (e instanceof NetworkInterceptor.NoNetworkException) {
@adityaladwa
adityaladwa / NetworkInterceptor.kt
Last active Nov 20, 2020
An okhttp interceptor to check internet connection before making a http request
View NetworkInterceptor.kt
class NetworkInterceptor(context: Context) : Interceptor {
private val mApplicationContext: Context = context.applicationContext
private val isConnected: Boolean
get() {
val cm = mApplicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork = cm.activeNetworkInfo
return activeNetwork != null && activeNetwork.isConnectedOrConnecting
}
@adityaladwa
adityaladwa / build.gradle
Created Feb 26, 2017 — forked from IlyaEremin/build.gradle
Example of managing dependencies in separate file
View build.gradle
apply from: 'deps.gradle'
// ...
dependencies {
compile supportLibs
compile rxJavaLibs
compile retrofitLibs
compile okHttpLibs
View Presenter.java
public void onClickReference(User user) {
Toast.makeText(this.context, "Clicked Listener method " + user.getFirstName() + user.getLastName(), Toast.LENGTH_SHORT).show();
user.setClicked(user.isClicked());
}
View User.java
public class User extends BaseObservable {
private boolean clicked;
@Bindable public boolean isClicked() {
return clicked;
}
public void setClicked(boolean clicked) {
this.clicked = !clicked;
View MainActivity.java
User user = new User("Aditya", "Ladwa", 22, true);
View activity_main.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{user.firstName}"
android:visibility="@{user.clicked ? View.INVISIBLE : View.VISIBLE}"/>