Skip to content

Instantly share code, notes, and snippets.

@smaugho
Last active April 29, 2017 13:01
Show Gist options
  • Save smaugho/e84645e7980e95c246a153d2a6d23342 to your computer and use it in GitHub Desktop.
Save smaugho/e84645e7980e95c246a153d2a6d23342 to your computer and use it in GitHub Desktop.
Example with $LoadModel and $PutModel
@EFragment(R.id.fragment_address)
public class AddressFragment extends Fragment {
@Model(lazy = true)
@Populate
@Recollect(validate = true)
User user;
@AfterViews
void loadUser(View userInformation) {
Dialog progressDialog = $ProgressDialog()
.message("Loading user...")
.dialog();
$LoadModel(user);
if ($LoadModel.Failed) {
progressDialog.dismiss();
$Toast("The user information couldn't be fetched");
}
progressDialog.dismiss();
userInformation.setEnabled(true);
}
@Click
void save() {
$AlertDialog()
.message("Are you sure you want to save these changes?")
.positiveButton("Yes").negativeButton("No");
$PutModel(user);
if ($PutModel.Failed) {
$Toast("User {user.fullName()} couldn't be saved");
}
$Toast("User {user.fullName()} has been saved");
getActivity().onBackPressed();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment