/**
   * *********************************************************************************************
   * VOD시청
   */
  public void addWatchVod(Date watchDate, String assetId, String title) {
    // Realm Database **********************************************************************
    // Obtain a Realm instance
    Realm realm = Realm.getInstance(mContext);
    RealmResults<WatchVodObject> results = realm.where(WatchVodObject.class).findAll();
    long iSeq = 0;
    if (results == null) {
      //
    } else {
      if (results.size() == 0) {
        iSeq = 0;
      } else {
        iSeq = realm.where(WatchVodObject.class).maximumInt("iSeq") + 1;
      }
    }

    WatchVodObject obj = new WatchVodObject();
    obj.setiSeq((int) iSeq);
    obj.setdDate(watchDate);
    obj.setsAssetId(assetId);
    obj.setsTitle(title);
    realm.beginTransaction();
    WatchVodObject obj2 = realm.copyToRealm(obj);
    realm.commitTransaction();
    // Realm Database **********************************************************************
  }
 private void check(Realm realm) {
   RealmResults<Student> realmResults = realm.allObjects(Student.class);
   if (realmResults.size() != numberOfObjects) {
     throw new RuntimeException(
         String.format("Error in number of objectss.", realmResults.size(), numberOfObjects));
   }
 }
Example #3
0
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    ImageLoaderConfiguration conf = new ImageLoaderConfiguration.Builder(getActivity()).build();
    ImageLoader imageLoader = ImageLoader.getInstance();
    imageLoader.init(conf);

    adapter = new FriendsArrayAdapter(getActivity(), R.layout.row_friends, imageLoader, this);
    setListAdapter(adapter);

    realm = Realm.getInstance(getActivity());

    RealmResults<Friend> results = realm.allObjects(Friend.class); // TODO: Run async

    if (results.size() > 0) {
      if (!compact) {
        getListView().setVisibility(View.VISIBLE);
        progressBar.setVisibility(View.GONE);
      }
      adapter.update(results);
    }

    refreshFriends(); // TODO: Timeout on the refresh rate?
  }
Example #4
0
 /** Remove todos os objetos RealmVideo salvos no banco. */
 public static void cleanVideos() {
   Realm realm = Realm.getDefaultInstance();
   RealmResults<RealmVideo> results = realm.where(RealmVideo.class).findAll();
   realm.beginTransaction();
   results.clear();
   realm.commitTransaction();
 }
 @Override
 public void onStart(Intent intent, int startId) {
   super.onStart(intent, startId);
   // get today's day of month to query overhead of this same day
   Calendar cal = Calendar.getInstance();
   cal.setTime(new Date());
   int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
   // query realm for overhead to be created on this day
   RealmResults<OverheadModel> overheadsList =
       realm.where(OverheadModel.class).equalTo("dayOfMonth", dayOfMonth).findAll();
   // Get iterator
   Iterator<OverheadModel> iterator = overheadsList.iterator();
   // Create new transaction for each result
   while (iterator.hasNext()) {
     OverheadModel overhead = iterator.next();
     TransactionModel transaction = new TransactionModel(-1);
     transaction.setTransactionType(CreateTransactionActivity.TRANSACTION_TYPE_EXPENSE);
     transaction.setPrice(overhead.getPrice());
     transaction.setCategory(realm.copyFromRealm(overhead.getCategory()));
     transaction.setFromAccount(realm.copyFromRealm(overhead.getFromAccount()));
     transaction.setDate(cal.getTime());
     transaction.setComment(overhead.getComment());
     transaction.setPending(false);
     transaction.setDueToOrBy(0);
     transaction.setDueName(null);
     transactionRepository.saveTransaction(transaction);
   }
   // Set alarm for next month
   this.setUpNewAlarm();
   // Kill service
   stopSelf();
 }
  // 2016-03-29 시청예약시 데이타베이스 처리를 programId 로 하는데 서버에서 programId를 중복으로 보내고 있다
  // 그래서 시청시간을 추가함.
  public void removeWatchTvReserveAlarmWithProgramIdAndStartTime(
      String programId, String startTime) {
    int iSeq = 0;
    Realm realm = Realm.getInstance(mContext);
    realm.beginTransaction();
    RealmResults<WatchTvObject> results =
        mRealm
            .where(WatchTvObject.class)
            .equalTo("sProgramId", programId)
            .equalTo("sProgramBroadcastingStartTime", startTime)
            .findAll();
    if (results.size() > 0) {
      WatchTvObject obj = results.get(0);
      iSeq = obj.getiSeq();
      obj.removeFromRealm();
    } else {
      //
    }
    realm.commitTransaction();

    AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(mContext, WatchTvAlarmBroadcastReceiver.class);
    PendingIntent pendingIntent =
        PendingIntent.getBroadcast(mContext, iSeq, intent, PendingIntent.FLAG_NO_CREATE);
    if (pendingIntent != null) {
      alarmManager.cancel(pendingIntent);
      pendingIntent.cancel();
    }
  }
Example #7
0
 public void testSortSingleField() {
   RealmResults<AllTypes> sortedList = testRealm.allObjects(AllTypes.class);
   sortedList.sort(new String[] {FIELD_LONG}, new boolean[] {RealmResults.SORT_ORDER_DESCENDING});
   assertEquals(TEST_DATA_SIZE, sortedList.size());
   assertEquals(TEST_DATA_SIZE - 1, sortedList.first().getColumnLong());
   assertEquals(0, sortedList.last().getColumnLong());
 }
Example #8
0
  public void testSumGivesCorrectValue() {
    RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();

    Number sum = resultList.sum(FIELD_LONG);
    // Sum of numbers 0 to M-1: (M-1)*M/2
    assertEquals((TEST_DATA_SIZE - 1) * TEST_DATA_SIZE / 2, sum.intValue());
  }
Example #9
0
  // Test average on empty columns
  public void testAvgGivesCorrectValueForEmptyColumns() {
    RealmResults<NullTypes> resultList = testRealm.where(NullTypes.class).findAll();

    assertEquals(0d, resultList.average(NullTypes.FIELD_INTEGER_NOT_NULL), 0d);
    assertEquals(0d, resultList.average(NullTypes.FIELD_FLOAT_NOT_NULL), 0d);
    assertEquals(0d, resultList.average(NullTypes.FIELD_DOUBLE_NOT_NULL), 0d);
  }
 public void testGetItemId() {
   RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
   RealmAdapter realmAdapter = new RealmAdapter(getContext(), resultList, automaticUpdate);
   for (int i = 0; i < resultList.size(); i++) {
     assertEquals(i, realmAdapter.getItemId(i));
   }
 }
Example #11
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sleep);
    Realm realm = Realm.getDefaultInstance();

    Toolbar tb = (Toolbar) findViewById(R.id.toolbar);
    tb.setTitle("Sleep Summaries");
    setSupportActionBar(tb);

    if (getSupportActionBar() != null) {
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      getSupportActionBar().setDisplayShowHomeEnabled(true);
      final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
      upArrow.setColorFilter(Color.parseColor("#FFFFFF"), PorterDuff.Mode.SRC_ATOP);
      getSupportActionBar().setHomeAsUpIndicator(upArrow);
      tb.setTitleTextColor(Color.WHITE);
    }

    tb.setNavigationOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            onBackPressed();
          }
        });

    // Get all sleep data recorded and send this to adapter to populate the list

    RealmResults<Sleep> sleeps = realm.where(Sleep.class).findAll();
    sleeps.sort("startTime", Sort.DESCENDING);
    SleepAdapter sleepAdapter = new SleepAdapter(this, R.id.listView, sleeps, true);
    ListView listView = (ListView) findViewById(R.id.listView);
    listView.setAdapter(sleepAdapter);
  }
Example #12
0
  public void testAvgGivesCorrectValue() {
    RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
    double N = (double) TEST_DATA_SIZE;

    // Sum of numbers 1 to M: M*(M+1)/2
    // See setUp() for values of fields
    // N = TEST_DATA_SIZE

    // Type: double; a = 3.1415
    // a, a+1, ..., a+i, ..., a+N-1
    // sum = 3.1415*N + N*(N-1)/2
    // average = sum/N = 3.1415+(N-1)/2
    double average = 3.1415 + (N - 1.0) * 0.5;
    assertEquals(average, resultList.average(FIELD_DOUBLE), 0.0001);

    // Type: long
    // 0, 1, ..., N-1
    // sum = N*(N-1)/2
    // average = sum/N = (N-1)/2
    assertEquals(0.5 * (N - 1), resultList.average(FIELD_LONG), 0.0001);

    // Type: float; b = 1.234567
    // b, b+1, ..., b+i, ..., b+N-1
    // sum = b*N + N*(N-1)/2
    // average = sum/N = b + (N-1)/2
    assertEquals(1.234567 + 0.5 * (N - 1.0), resultList.average(FIELD_FLOAT), 0.0001);
  }
  /**
   * getWishList로 전체 찜 목록을 가져왔을때 호출되는 함수. 기존의 Wish들을 삭제하고, 파라메터의 어레이로 다시 채운다.
   *
   * @param arr
   */
  public void setAllWishList(JSONArray arr) {
    // Realm Database **********************************************************************
    // Obtain a Realm instance
    Realm realm = Realm.getInstance(mContext);

    // remove all
    realm.beginTransaction();
    realm.allObjects(WishObject.class).clear();
    for (int i = 0; i < arr.length(); i++) {
      try {
        JSONObject jo = arr.getJSONObject(i);
        JSONObject asset = jo.getJSONObject("asset");
        String assetId = asset.getString("assetId");
        RealmResults<WishObject> results =
            mRealm.where(WishObject.class).equalTo("sAssetId", assetId).findAll();
        if (results.size() > 0) {
          // skip
        } else {
          // 객체를 생성하거나 데이터를 수정하는 작업을 수행한다.
          WishObject wish = realm.createObject(WishObject.class); // Create a new object
          wish.setsAssetId(assetId);
          wish.setsPhoneNumber(jo.getString("phoneNumber"));
          wish.setsUserId(jo.getString("userId"));
        }
      } catch (JSONException e) {
        e.printStackTrace();
      }
    }
    // 트랜잭션 종료
    realm.commitTransaction();
    // Realm Database **********************************************************************
  }
Example #14
0
 // Test max on empty columns
 public void testMaxValueForEmptyColumns() {
   RealmResults<NullTypes> results = testRealm.where(NullTypes.class).findAll();
   assertNull(results.max(NullTypes.FIELD_INTEGER_NOT_NULL));
   assertNull(results.max(NullTypes.FIELD_FLOAT_NOT_NULL));
   assertNull(results.max(NullTypes.FIELD_DOUBLE_NOT_NULL));
   assertNull(results.maxDate(NullTypes.FIELD_DATE_NOT_NULL));
 }
Example #15
0
 public void testSortOnNonExistingColumn() {
   try {
     RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
     resultList.sort("Non-existing");
     fail("Column should not exist");
   } catch (IllegalArgumentException ignored) {
   }
 }
 /**
  * Test to see if a particular item that does exist in the same Realm does not exist in the result
  * set of another query.
  */
 public void testContainsSameRealmNotContained() {
   RealmResults<AllTypes> items =
       testRealm.where(AllTypes.class).lessThan(AllTypes.FIELD_LONG, 1000).findAll();
   AllTypes anotherType =
       testRealm.where(AllTypes.class).greaterThan(AllTypes.FIELD_LONG, 1000).findFirst();
   assertFalse(
       "Should not be able to find item in another result list.", items.contains(anotherType));
 }
Example #17
0
  // Test sum on nullable rows with all null values
  public void testSumGivesCorrectValueForAllNullRows() {
    TestHelper.populateAllNullRowsForNumericTesting(testRealm);

    RealmResults<NullTypes> resultList = testRealm.where(NullTypes.class).findAll();
    assertEquals(0, resultList.sum(NullTypes.FIELD_INTEGER_NULL).intValue());
    assertEquals(0f, resultList.sum(NullTypes.FIELD_FLOAT_NULL).floatValue(), 0f);
    assertEquals(0d, resultList.sum(NullTypes.FIELD_DOUBLE_NULL).doubleValue(), 0d);
  }
Example #18
0
  // Test min on nullable rows with partial null values
  public void testMinValueForPartialNullRows() {
    populatePartialNullRowsForNumericTesting();

    RealmResults<NullTypes> results = testRealm.where(NullTypes.class).findAll();
    assertEquals(0, results.min(NullTypes.FIELD_INTEGER_NULL).intValue());
    assertEquals(0f, results.min(NullTypes.FIELD_FLOAT_NULL).floatValue(), 0f);
    assertEquals(0d, results.min(NullTypes.FIELD_DOUBLE_NULL).doubleValue(), 0d);
  }
Example #19
0
  public void getFromDatabase() {
    mEntityList.clear();

    RealmResults<RealmZcool> zcoolRealmResults = mRealm.where(RealmZcool.class).findAll();
    for (int i = zcoolRealmResults.size() - 1; i >= 0; i--) {
      mEntityList.add(zcoolRealmResults.get(i).toEntity());
    }
  }
Example #20
0
 public void testIndexOf() {
   try {
     RealmResults<AllTypes> all = testRealm.allObjects(AllTypes.class);
     all.indexOf(all.first());
     fail();
   } catch (NoSuchMethodError ignored) {
   }
 }
Example #21
0
  // Test sum on nullable rows with partial null values
  public void testAvgGivesCorrectValueForPartialNullRows() {
    populatePartialNullRowsForNumericTesting();
    RealmResults<NullTypes> resultList = testRealm.where(NullTypes.class).findAll();

    assertEquals(1, resultList.sum(NullTypes.FIELD_INTEGER_NULL).intValue());
    assertEquals(2f, resultList.sum(NullTypes.FIELD_FLOAT_NULL).floatValue(), 0f);
    assertEquals(3d, resultList.sum(NullTypes.FIELD_DOUBLE_NULL).doubleValue(), 0d);
  }
Example #22
0
  // Test average on nullable rows with all null values
  public void testAvgGivesCorrectValueForAllNullRows() {
    TestHelper.populateAllNullRowsForNumericTesting(testRealm);

    RealmResults<NullTypes> resultList = testRealm.where(NullTypes.class).findAll();
    assertEquals(0d, resultList.average(NullTypes.FIELD_INTEGER_NULL), 0d);
    assertEquals(0d, resultList.average(NullTypes.FIELD_FLOAT_NULL), 0d);
    assertEquals(0d, resultList.average(NullTypes.FIELD_DOUBLE_NULL), 0d);
  }
  // Test average on nullable rows with partial null values
  public void testAvgForPartialNullRows() {
    populatePartialNullRowsForNumericTesting();
    RealmResults<NullTypes> resultList = testRealm.where(NullTypes.class).findAll();

    assertEquals(0.5, resultList.average(NullTypes.FIELD_INTEGER_NULL), 0d);
    assertEquals(1.0, resultList.average(NullTypes.FIELD_FLOAT_NULL), 0d);
    assertEquals(1.5, resultList.average(NullTypes.FIELD_DOUBLE_NULL), 0d);
  }
  @Override
  public View getView(int position, View view, ViewGroup parent) {

    LayoutInflater inflater = activity.getLayoutInflater();
    Type type = realmResults.get(position);

    // check which markers are available
    Boolean available = false;
    RealmResults<Marker> markers =
        Utils.realm.where(Marker.class).equalTo("city.id", Utils.city_id).findAll();
    for (int i = 0; i < markers.size(); i++) {
      Marker thisMarker = markers.get(i);
      if (thisMarker.getType() == type.getType()) {
        available = true;
      }
    }

    // marker type is available show in list
    if (available) {
      rowView = inflater.inflate(R.layout.custom_filter_list, null, true);

      TextView filterName = (TextView) rowView.findViewById(R.id.FilterName);
      TextView filterType = (TextView) rowView.findViewById(R.id.FilterType);
      ImageView filterIcon = (ImageView) rowView.findViewById(R.id.TypeIcon);
      Switch filterDisplay = (Switch) rowView.findViewById(R.id.DisplayToggle);

      // set label depending on language set
      Utils.language = Utils.preferences.getInt("language", 0);
      if (Utils.language == 0) {
        filterName.setText(type.getName_nl());
      } else if (Utils.language == 1) {
        filterName.setText(type.getName_en());
      } else if (Utils.language == 2) {
        filterName.setText(type.getName_es());
      } else {
        filterName.setText("int: " + Utils.language);
      }

      filterType.setText(String.format("%d", type.getType()));

      Context context = filterIcon.getContext();
      int id =
          context
              .getResources()
              .getIdentifier(type.getImage(), "drawable", context.getPackageName());
      Bitmap icon = BitmapFactory.decodeResource(context.getResources(), id);
      filterIcon.setImageBitmap(icon);

      filterDisplay.setChecked(type.getDisplay());

      rowView.setTag(type);

    } else {
      rowView = inflater.inflate(R.layout.custom_empty_list, null, true);
    }

    return rowView;
  }
 public boolean isBookmarkChannelWithChannelId(String channelId) {
   RealmResults<BookmarkChannelObject> results =
       mRealm.where(BookmarkChannelObject.class).equalTo("sChannelId", channelId).findAll();
   if (results.size() > 0) {
     return true;
   } else {
     return false;
   }
 }
 public boolean isWatchTvReserveWithProgramId(String programId) {
   RealmResults<WatchTvObject> results =
       mRealm.where(WatchTvObject.class).equalTo("sProgramId", programId).findAll();
   if (results.size() > 0) {
     return true;
   } else {
     return false;
   }
 }
Example #27
0
  // Test max on nullable rows with all null values
  public void testMaxValueForAllNullRows() {
    TestHelper.populateAllNullRowsForNumericTesting(testRealm);

    RealmResults<NullTypes> results = testRealm.where(NullTypes.class).findAll();
    assertNull(results.max(NullTypes.FIELD_INTEGER_NULL));
    assertNull(results.max(NullTypes.FIELD_FLOAT_NULL));
    assertNull(results.max(NullTypes.FIELD_DOUBLE_NULL));
    assertNull(results.maxDate(NullTypes.FIELD_DATE_NULL));
  }
Example #28
0
 public void testManyConditions() {
   RealmQuery<AllTypes> query = testRealm.where(AllTypes.class);
   query.equalTo(FIELD_LONG, 0);
   for (int i = 1; i < TEST_DATA_SIZE; i++) {
     query.or().equalTo(FIELD_LONG, i);
   }
   RealmResults<AllTypes> allTypesRealmResults = query.findAll();
   assertEquals(TEST_DATA_SIZE, allTypesRealmResults.size());
 }
 public boolean isWishAsset(String assetId) {
   RealmResults<WishObject> results =
       mRealm.where(WishObject.class).equalTo("sAssetId", assetId).findAll();
   if (results.size() > 0) {
     return true;
   } else {
     return false;
   }
 }
 public MainCategoryObject getMainCategoryObject(int i) {
   String sSortNo = String.valueOf(i);
   RealmResults<MainCategoryObject> results =
       mRealm.where(MainCategoryObject.class).equalTo("sSortNo", sSortNo).findAll();
   if (results.size() > 0) {
     return results.get(0);
   } else {
     return null;
   }
 }