use of io.realm.RealmList in project underlx by underlx.
the class EditNotifScheduleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
ruleId = getIntent().getStringExtra(EXTRA_RULE_ID);
} else {
ruleId = savedInstanceState.getString(STATE_RULE_ID);
}
setContentView(R.layout.activity_edit_notif_schedule);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
realm = Application.getDefaultRealmInstance(this);
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(final Realm realm) {
if (ruleId == null) {
rule = realm.createObject(NotificationRule.class, UUID.randomUUID().toString());
} else {
rule = realm.where(NotificationRule.class).equalTo("id", ruleId).findFirst();
if (rule == null) {
finish();
return;
}
}
ruleId = rule.getId();
List<Map<String, String>> data = new ArrayList<>();
weekDaysItem = new HashMap<>(3);
weekDaysItem.put("title", getString(R.string.act_edit_notif_schedule_days));
weekDaysItem.put("desc", "");
data.add(weekDaysItem);
startTimeItem = new HashMap<>(3);
startTimeItem.put("title", getString(R.string.act_edit_notif_schedule_start_time));
startTimeItem.put("desc", "");
data.add(startTimeItem);
endTimeItem = new HashMap<>(3);
endTimeItem.put("title", getString(R.string.act_edit_notif_schedule_end_time));
endTimeItem.put("desc", "");
data.add(endTimeItem);
listView = (ListView) findViewById(R.id.list_view);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position == 0) {
AlertDialog.Builder builder = new AlertDialog.Builder(EditNotifScheduleActivity.this);
DateFormatSymbols symbols = new DateFormatSymbols();
String[] dayNames = Arrays.copyOfRange(symbols.getWeekdays(), 1, 8);
final boolean[] checkedDays = new boolean[7];
for (int day : rule.getWeekDays()) {
checkedDays[day - 1] = true;
}
builder.setMultiChoiceItems(dayNames, checkedDays, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
checkedDays[which] = isChecked;
}
});
builder.setTitle(getString(R.string.act_edit_notif_schedule_days));
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
RealmList<Integer> days = rule.getWeekDays();
days.clear();
for (int i = 0; i < 7; i++) {
if (checkedDays[i]) {
days.add(i + 1);
}
}
}
});
updateUI();
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.create().show();
} else if (position == 1) {
RadialTimePickerDialogFragment rtpd = new RadialTimePickerDialogFragment().setOnTimeSetListener(EditNotifScheduleActivity.this).setStartTime((int) TimeUnit.MILLISECONDS.toHours(rule.getStartTime()) % 24, (int) TimeUnit.MILLISECONDS.toMinutes(rule.getStartTime()) % 60).setDoneText(getString(android.R.string.ok)).setCancelText(getString(android.R.string.cancel)).setThemeDark();
rtpd.show(getSupportFragmentManager(), TAG_START_TIME_PICKER);
} else if (position == 2) {
RadialTimePickerDialogFragment rtpd = new RadialTimePickerDialogFragment().setOnTimeSetListener(EditNotifScheduleActivity.this).setStartTime((int) TimeUnit.MILLISECONDS.toHours(rule.getEndTime()) % 24, (int) TimeUnit.MILLISECONDS.toMinutes(rule.getEndTime()) % 60).setDoneText(getString(android.R.string.ok)).setCancelText(getString(android.R.string.cancel)).setThemeDark();
rtpd.show(getSupportFragmentManager(), TAG_END_TIME_PICKER);
}
}
});
adapter = new SimpleAdapter(EditNotifScheduleActivity.this, data, android.R.layout.simple_list_item_2, new String[] { "title", "desc" }, new int[] { android.R.id.text1, android.R.id.text2 });
listView.setAdapter(adapter);
updateUI();
}
});
}
use of io.realm.RealmList in project xabber-android by redsolution.
the class PatreonManager method savePatreonToRealm.
public Single<XabberComClient.Patreon> savePatreonToRealm(XabberComClient.Patreon patreon) {
RealmList<PatreonGoalRealm> patreonGoals = new RealmList<>();
for (XabberComClient.PatreonGoal patreonGoal : patreon.getGoals()) {
PatreonGoalRealm patreonGoalRealm = new PatreonGoalRealm();
patreonGoalRealm.setGoal(patreonGoal.getGoal());
patreonGoalRealm.setTitle(patreonGoal.getTitle());
patreonGoals.add(patreonGoalRealm);
}
PatreonRealm patreonRealm = new PatreonRealm("1");
patreonRealm.setPledged(patreon.getPledged());
patreonRealm.setString(patreon.getString());
patreonRealm.setGoals(patreonGoals);
// TODO: 13.03.18 ANR - WRITE
final long startTime = System.currentTimeMillis();
Realm realm = RealmManager.getInstance().getNewRealm();
realm.beginTransaction();
PatreonRealm resultRealm = realm.copyToRealmOrUpdate(patreonRealm);
realm.commitTransaction();
XabberComClient.Patreon result = patreonRealmToDTO(resultRealm);
realm.close();
LogManager.d("REALM", Thread.currentThread().getName() + " save patreon data: " + (System.currentTimeMillis() - startTime));
Log.d(LOG_TAG, "Patreon was saved to Realm");
return Single.just(result);
}
use of io.realm.RealmList in project xabber-android by redsolution.
the class XabberAccountManager method saveOrUpdateXabberAccountToRealm.
public Single<XabberAccount> saveOrUpdateXabberAccountToRealm(XabberAccountDTO xabberAccount, String token) {
XabberAccount account;
XabberAccountRealm xabberAccountRealm = new XabberAccountRealm(String.valueOf(xabberAccount.getId()));
xabberAccountRealm.setToken(token);
xabberAccountRealm.setAccountStatus(xabberAccount.getAccountStatus());
xabberAccountRealm.setUsername(xabberAccount.getUsername());
xabberAccountRealm.setFirstName(xabberAccount.getFirstName());
xabberAccountRealm.setLastName(xabberAccount.getLastName());
xabberAccountRealm.setLanguage(xabberAccount.getLanguage());
xabberAccountRealm.setRegisterDate(xabberAccount.getRegistrationDate());
xabberAccountRealm.setNeedToVerifyPhone(xabberAccount.isNeedToVerifyPhone());
xabberAccountRealm.setPhone(xabberAccount.getPhone());
RealmList<XMPPUserRealm> realmUsers = new RealmList<>();
for (XMPPUserDTO user : xabberAccount.getXmppUsers()) {
XMPPUserRealm realmUser = new XMPPUserRealm(String.valueOf(user.getId()));
realmUser.setUsername(user.getUsername());
realmUser.setHost(user.getHost());
realmUser.setRegistration_date(user.getRegistrationDate());
realmUsers.add(realmUser);
}
xabberAccountRealm.setXmppUsers(realmUsers);
RealmList<EmailRealm> realmEmails = new RealmList<>();
for (EmailDTO email : xabberAccount.getEmails()) {
EmailRealm realmEmail = new EmailRealm(String.valueOf(email.getId()));
realmEmail.setEmail(email.getEmail());
realmEmail.setPrimary(email.isPrimary());
realmEmail.setVerified(email.isVerified());
realmEmails.add(realmEmail);
}
xabberAccountRealm.setEmails(realmEmails);
RealmList<SocialBindingRealm> realmSocials = new RealmList<>();
for (SocialBindingDTO social : xabberAccount.getSocialBindings()) {
SocialBindingRealm realmSocial = new SocialBindingRealm(String.valueOf(social.getId()));
realmSocial.setProvider(social.getProvider());
realmSocial.setUid(social.getUid());
realmSocial.setFirstName(social.getFirstName());
realmSocial.setLastName(social.getLastName());
realmSocials.add(realmSocial);
}
xabberAccountRealm.setSocialBindings(realmSocials);
Realm realm = RealmManager.getInstance().getNewBackgroundRealm();
realm.beginTransaction();
XabberAccountRealm accountRealm = realm.copyToRealmOrUpdate(xabberAccountRealm);
account = xabberAccountRealmToPOJO(accountRealm);
realm.commitTransaction();
realm.close();
this.account = account;
return Single.just(account);
}
use of io.realm.RealmList in project app by TourLive.
the class MaillotRepository method getAllMaillotsReturned.
@Override
public RealmList<Maillot> getAllMaillotsReturned() {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
RealmResults<Maillot> results = realm.where(Maillot.class).findAll();
RealmList<Maillot> res = new RealmList<>();
res.addAll(results);
return res;
}
use of io.realm.RealmList in project app by TourLive.
the class RaceGroupRepository method addInitialRaceGroup.
@Override
public void addInitialRaceGroup(RaceGroup raceGroup, OnSaveRaceGroupCallback callback) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
final RaceGroup transferRaceGroup = raceGroup;
realm.beginTransaction();
RaceGroup realmRaceGroup = realm.createObject(RaceGroup.class, UUID.randomUUID().toString());
realmRaceGroup.setType(transferRaceGroup.getType());
realmRaceGroup.setActualGapTime(transferRaceGroup.getActualGapTime());
realmRaceGroup.setHistoryGapTime(transferRaceGroup.getHistoryGapTime());
RealmList<Rider> res = new RealmList<>();
for (Rider r : transferRaceGroup.getRiders()) {
RealmResults<Rider> temp = realm.where(Rider.class).equalTo("startNr", r.getStartNr()).findAll();
res.addAll(temp);
}
realmRaceGroup.setPosition(transferRaceGroup.getPosition());
realmRaceGroup.setRiders(res);
realm.commitTransaction();
if (callback != null) {
callback.onSuccess(realmRaceGroup);
}
}
Aggregations