Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. package com.isaac.appet.HomeFragment;
  2.  
  3. import android.graphics.Bitmap;
  4. import android.graphics.drawable.Drawable;
  5. import android.widget.ImageView;
  6.  
  7. import java.io.Serializable;
  8.  
  9. import io.realm.RealmList;
  10. import io.realm.RealmObject;
  11. import io.realm.annotations.PrimaryKey;
  12.  
  13. public class Pets extends RealmObject implements Serializable {
  14.  
  15. @PrimaryKey
  16. long id;
  17. public String petType;
  18. private String petName;
  19. private String petUrlImage;
  20. private RealmList<Alarms> alarms = new RealmList<>();
  21.  
  22. public long getId() {
  23. return id;
  24. }
  25.  
  26. public void setId(long id) {
  27. this.id = id;
  28. }
  29.  
  30. public String getPetType() {
  31. return petType;
  32. }
  33.  
  34. public void setPetType(String petType) {
  35. this.petType = petType;
  36. }
  37.  
  38. public RealmList<Alarms> getAlarms() {
  39. return alarms;
  40. }
  41.  
  42. public void setAlarms(RealmList<Alarms> alarms) {
  43. this.alarms = alarms;
  44. }
  45.  
  46. public String getPetUrlImage() {
  47. return petUrlImage;
  48. }
  49.  
  50. public void setPetUrlImage(String petUrlImage) {
  51. this.petUrlImage = petUrlImage;
  52. }
  53.  
  54. public String getPetName() {
  55. return petName;
  56. }
  57.  
  58. public void setPetName(String petName) {
  59. this.petName = petName;
  60. }
  61.  
  62. }
  63.  
  64. btnSaveAlarm.setOnClickListener(new View.OnClickListener() {
  65. @Override
  66. public void onClick(View v) {
  67.  
  68. realm.beginTransaction();
  69.  
  70. Alarms alarm = new Alarms();
  71.  
  72. alarm.setTitle(etAlarmTitle.getText().toString());
  73. alarm.setTime(etAlarmTime.getText().toString());
  74. alarm.setDesc(etAlarmDesc.getText().toString());
  75.  
  76. Number maxId = realm.where(Alarms.class).max("id");
  77. long nextID;
  78.  
  79. if (maxId == null) {
  80. nextID = 1;
  81. } else {
  82. nextID = maxId.longValue() + 1;
  83. }
  84.  
  85. alarm.setId(nextID);
  86.  
  87. realm.copyToRealmOrUpdate(alarm);
  88. realm.commitTransaction();
  89.  
  90. finish();
  91.  
  92. }
  93. });
  94.  
  95. adapter.setOnClickListener(new View.OnClickListener() {
  96. @Override
  97. public void onClick(View v) {
  98. int position = adapter.getPositionFromView(v);
  99. Pets pressPet = pets.get(position);
  100.  
  101. RealmResults<Alarms> results = realm.where(Alarms.class).findAll();
  102.  
  103. alarms.clear();
  104. alarms.addAll(pressPet.getAlarms());
  105.  
  106.  
  107. adapterAlarms.notifyDataSetChanged();
  108. }
  109. });
  110.  
  111. package com.isaac.appet.HomeFragment;
  112.  
  113. import java.io.Serializable;
  114.  
  115. import io.realm.RealmList;
  116. import io.realm.RealmObject;
  117. import io.realm.annotations.PrimaryKey;
  118.  
  119. public class Alarms extends RealmObject implements Serializable {
  120.  
  121. @PrimaryKey
  122. long id;
  123. RealmList<Pets> namePetAlarm;
  124. String title;
  125. String desc;
  126. String time;
  127.  
  128. public long getId() { return id; }
  129.  
  130. public void setId(long id) { this.id = id; }
  131.  
  132. public RealmList<Pets> getNamePetAlarm() {
  133. return namePetAlarm;
  134. }
  135.  
  136. public void setNamePetAlarm(RealmList<Pets> namePetAlarm) {
  137. this.namePetAlarm = namePetAlarm;
  138. }
  139.  
  140. public String getTitle() {
  141. return title;
  142. }
  143.  
  144. public void setTitle(String title) {
  145. this.title = title;
  146. }
  147.  
  148. public String getDesc() {
  149. return desc;
  150. }
  151.  
  152. public void setDesc(String desc) {
  153. this.desc = desc;
  154. }
  155.  
  156. public String getTime() {
  157. return time;
  158. }
  159.  
  160. public void setTime(String time) {
  161. this.time = time;
  162. }
  163.  
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement