This file contains 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
private ProfileViewModel viewModel; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
ActivityProfileBinding binding = DataBindingUtil.setContentView(this, LAYOUT_ACTIVITY); | |
viewModel = new ProfileViewModel(this); | |
binding.setViewModel(viewModel); | |
} |
This file contains 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 void onResume() { | |
isLoading.set(this.user.get() == null); | |
userRepo.getUser(this::onUserLoaded); | |
} |
This file contains 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 abstract class BindingActivity extends AppCompatActivity { | |
… | |
@Override | |
protected void onStart() { | |
super.onStart(); | |
viewModel.onStart(); | |
} | |
@Override |
This file contains 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
private AppCompatActivity binding; | |
private ActivityViewModel viewModel; | |
public abstract ActivityViewModel onCreate(); | |
public abstract @IdRes int getVariable(); | |
public abstract @LayoutRes int getLayoutId(); | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); |
This file contains 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 abstract class ActivityViewModel extends BaseObservable { | |
protected Activity activity; | |
public ActivityViewModel(Activity activity) { | |
this.activity = activity; | |
} | |
public Activity getActivity() { | |
return activity; |
This file contains 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 abstract class BindingActivity<B extends ViewDataBinding, VM extends ActivityViewModel> extends AppCompatActivity { | |
private B binding; | |
private VM viewModel; | |
public B getBinding() { | |
return binding; | |
} | |
} | |
This file contains 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 ProfileActivity | |
extends BindingActivity<ActivityProfileBinding, ProfileViewModel> { | |
@Override | |
public ProfileViewModel onCreate() { | |
return new ProfileViewModel(this); | |
} | |
@Override | |
public int getVariable() { |
This file contains 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
<layout | |
xmlns:android="http://schemas.android.com/apk/res/android"> | |
<data> | |
<variable | |
name="viewModel" | |
type="com.stfalcon.androidmvvmexample.features.dialogs.input.InputDialogVM"/> | |
</data> | |
<EditText |
This file contains 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 final ObservableField<String> field = new ObservableField<String>() { | |
@Override | |
public String get() { | |
// TODO: your logic | |
return super.get(); | |
} | |
@Override | |
public void set(String value) { | |
// TODO: your logic |
This file contains 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
field.addOnPropertyChangedCallback(new OnPropertyChangedCallback() { | |
@Override | |
public void onPropertyChanged(Observable sender, int propertyId) { | |
// TODO: your logic | |
} | |
}); |
OlderNewer