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 May 3, 2017 13:13
Notifications Action Example
//Prepare the intent
Intent intent = $MainActivity().intent()
.flags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK)
.get();
//Prepare pending intent
PendingIntent contentIntent = PendingIntent.getActivity(
this, 0, notificationIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
@smaugho
smaugho / DecleX.java
Created May 3, 2017 13:03
$DateDialog and $TimeDialog Actions
void selectDate() {
$DateDialog();
int $year = 0, $month = 0, $day = 0;
String selectedDate = String.format(Locale.US, "Selected date is %02d-%02d-%02d", $year , $month+1, $day);
$Toast(selectedDate);
}
void selectTime() {
$TimeDialog();
@smaugho
smaugho / DecleX.java
Created April 29, 2017 17:27
ProgressDialog Example
Dialog dialog = $ProgressDialog().message("Loading…").dialog();
//Execute time consuming actions
dialog.dismiss();
@smaugho
smaugho / DecleX.java
Created April 29, 2017 17:16
Toast using example
@Model
User_ user;
@Click
void sayHelloToUser() {
$Toast("Hello {user.getName()}!");
}
@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 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) {