Search in sources :

Example 21 with RealmList

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();
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) ListView(android.widget.ListView) RealmList(io.realm.RealmList) ArrayList(java.util.ArrayList) List(java.util.List) Realm(io.realm.Realm) Toolbar(android.support.v7.widget.Toolbar) SimpleAdapter(android.widget.SimpleAdapter) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) AdapterView(android.widget.AdapterView) DateFormatSymbols(java.text.DateFormatSymbols) RadialTimePickerDialogFragment(com.codetroopers.betterpickers.radialtimepicker.RadialTimePickerDialogFragment)

Example 22 with RealmList

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);
}
Also used : PatreonGoalRealm(com.xabber.android.data.database.realm.PatreonGoalRealm) RealmList(io.realm.RealmList) PatreonRealm(com.xabber.android.data.database.realm.PatreonRealm) Realm(io.realm.Realm) PatreonRealm(com.xabber.android.data.database.realm.PatreonRealm) PatreonGoalRealm(com.xabber.android.data.database.realm.PatreonGoalRealm)

Example 23 with RealmList

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);
}
Also used : RealmList(io.realm.RealmList) XabberAccountRealm(com.xabber.android.data.database.realm.XabberAccountRealm) SocialBindingRealm(com.xabber.android.data.database.realm.SocialBindingRealm) XMPPUserRealm(com.xabber.android.data.database.realm.XMPPUserRealm) EmailRealm(com.xabber.android.data.database.realm.EmailRealm) SyncStateRealm(com.xabber.android.data.database.realm.SyncStateRealm) SocialBindingRealm(com.xabber.android.data.database.realm.SocialBindingRealm) Realm(io.realm.Realm) XabberAccountRealm(com.xabber.android.data.database.realm.XabberAccountRealm) XMPPUserRealm(com.xabber.android.data.database.realm.XMPPUserRealm) EmailRealm(com.xabber.android.data.database.realm.EmailRealm)

Example 24 with RealmList

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;
}
Also used : RealmList(io.realm.RealmList) Maillot(ch.hsr.sa.radiotour.dataaccess.models.Maillot) Realm(io.realm.Realm)

Example 25 with RealmList

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);
    }
}
Also used : RaceGroup(ch.hsr.sa.radiotour.dataaccess.models.RaceGroup) RealmList(io.realm.RealmList) Realm(io.realm.Realm) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider)

Aggregations

RealmList (io.realm.RealmList)39 Realm (io.realm.Realm)23 Rider (ch.hsr.sa.radiotour.dataaccess.models.Rider)17 Test (org.junit.Test)8 RaceGroup (ch.hsr.sa.radiotour.dataaccess.models.RaceGroup)7 Judgement (ch.hsr.sa.radiotour.dataaccess.models.Judgement)6 RiderStageConnection (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)6 JudgmentRiderConnection (ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection)4 Scheduler (io.reactivex.Scheduler)4 DynamicRealm (io.realm.DynamicRealm)4 RealmConfiguration (io.realm.RealmConfiguration)4 DialogInterface (android.content.DialogInterface)2 View (android.view.View)2 Maillot (ch.hsr.sa.radiotour.dataaccess.models.Maillot)2 Reward (ch.hsr.sa.radiotour.dataaccess.models.Reward)2 EmailRealm (com.xabber.android.data.database.realm.EmailRealm)2 SocialBindingRealm (com.xabber.android.data.database.realm.SocialBindingRealm)2 SyncStateRealm (com.xabber.android.data.database.realm.SyncStateRealm)2 XMPPUserRealm (com.xabber.android.data.database.realm.XMPPUserRealm)2 XabberAccountRealm (com.xabber.android.data.database.realm.XabberAccountRealm)2