Skip to content

Instantly share code, notes, and snippets.

View smaugho's full-sized avatar

Adrián Rivero smaugho

  • DSpot Sp. z o.o
  • Wrocław, Poland
View GitHub Profile
@smaugho
smaugho / DecleX.java
Created April 29, 2017 14:12
Sugar Syntax with Actions
$PutModel(user).withProgress("Saving user...")
.onFailed().toast("An error occurred");
$PutModel(user).always().code("checkState();")
.onDone().toast("User was saved")
.onFailed().toast("An error occurred");
@smaugho
smaugho / DecleX.java
Last active May 3, 2017 13:42
Actions handling Future Results
@Click
void sendInformation() {
int informationType = getInformationType();
$Toast("The information type index is {informationType}");
}
int getInformationType() {
String[] types= {"Type 1", "Type 2", "Type 3"}
$AlertDialog().items(types).negativeButton("Cancel");
@smaugho
smaugho / DecleX.java
Last active April 29, 2017 13:01
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) {
@smaugho
smaugho / DecleX.java
Created April 29, 2017 12:51
Event Receiver method
@Event
void onAuthenticationDone(String userName) {
//Do some action after the event is triggered
}
@smaugho
smaugho / DecleX.java
Last active April 29, 2017 12:21
Multi-Threading Control with Actions
@Model
@Populate
List<Item> itemsList;
void sortAndUpdateItemsList() {
//This will run the following code in an Asynchronous (Background) Thread
$Background();
Collections.sort(itemsList,
@smaugho
smaugho / DecleX.java
Created April 29, 2017 12:09
Action Selectors
@Click
void selectAction() {
String[] actions = {"Action 1", "Action 2", "Action 3"}
$AlertDialog().items(actions)
.positiveButton("More Actions")
.negativeButton("Cancel");
if ($AlertDialog.ItemSelected) {
$Toast("Action selected was {actions[position]}");
@smaugho
smaugho / DecleX.java
Created April 29, 2017 11:51
OnActvityResult with DecleX
@EActivity(R.id.activity_main)
public class MainActivity extends Activity {
@Model
User_ user;
@Click
void showSettings() {
$SettingsActivity().userName(user.getName()).withResult();
if ($SettingsActivity.OnResult) {
@smaugho
smaugho / DecleX.java
Last active May 4, 2017 13:47
Passing Parameters when Navigating
@EActivity(R.id.activity_settings)
public class SettingsActivity extends Activity {
@Extra
String userName;
@Click
void showProfile() {
$ProfileFragment().userName(userName);
}
@smaugho
smaugho / DecleX.java
Created April 28, 2017 10:03
Animating Fragment
$ProfileFragment().transaction()
.setCustomAnimations(
R.anim.move_right_in,
R.anim.move_left_out
);
@smaugho
smaugho / DecleX.java
Last active May 4, 2017 13:01
Actions in fields
@EActivity(R.id.activity_settings)
public class SettingsActivity extends Activity {
@Click
$ProfileFragment showProfile;
@Click
$NotificationsFragment showNotifications;
...