Skip to content

Instantly share code, notes, and snippets.

View adityaladwa's full-sized avatar

Aditya Ladwa adityaladwa

View GitHub Profile
public class Presenter {
private Context context;
public Presenter(Context context) {
this.context = context;
}
public void onClickMethod(View view) {
Toast.makeText(this.context, "Clicked Method reference button", Toast.LENGTH_SHORT).show();
}
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
//Set presenter binding
binding.setPresenter(new Presenter(this));
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="user"
type="com.ladwa.aditya.databinding_blitzkrieg.User"/>
<variable
<data>
<import type="android.view.View"/>
</data>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{user.firstName}"
android:visibility="@{user.clicked ? View.INVISIBLE : View.VISIBLE}"/>
User user = new User("Aditya", "Ladwa", 22, true);
public class User extends BaseObservable {
private boolean clicked;
@Bindable public boolean isClicked() {
return clicked;
}
public void setClicked(boolean clicked) {
this.clicked = !clicked;
public void onClickReference(User user) {
Toast.makeText(this.context, "Clicked Listener method " + user.getFirstName() + user.getLastName(), Toast.LENGTH_SHORT).show();
user.setClicked(user.isClicked());
}
@adityaladwa
adityaladwa / build.gradle
Created February 26, 2017 13:39 — forked from IlyaEremin/build.gradle
Example of managing dependencies in separate file
apply from: 'deps.gradle'
// ...
dependencies {
compile supportLibs
compile rxJavaLibs
compile retrofitLibs
compile okHttpLibs
@adityaladwa
adityaladwa / NetworkInterceptor.kt
Last active November 20, 2020 09:57
An okhttp interceptor to check internet connection before making a http request
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
}