Skip to content

Commit

Permalink
Issue #217: onDataChange work now shifted to Thread
Browse files Browse the repository at this point in the history
  • Loading branch information
kukreja-vikramaditya committed Apr 1, 2018
1 parent 35ba305 commit 775c8c8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions app/src/main/java/com/macbitsgoa/ard/fragments/HomeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup
onItemTouchListener = new RecyclerItemClickListener(getContext(), homeRV, this);
homeRV.addOnItemTouchListener(onItemTouchListener);
homeRV.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));

setupSlideshow();
imageSlideShowVEL = getImageSlideShowVEL();
imageSlideshowRef.addValueEventListener(imageSlideShowVEL);

return view;
}

Expand Down Expand Up @@ -218,16 +223,12 @@ public void onStart() {

homeRefVEL = getHomeRefVEL();
annRefVEL = getAnnRefVEL();
imageSlideShowVEL = getImageSlideShowVEL();

homeRef.orderByChild(HomeItemKeys.DATE + "/time").limitToLast(5).addValueEventListener(homeRefVEL);
annRef.addValueEventListener(annRefVEL);
imageSlideshowRef.addValueEventListener(imageSlideShowVEL);

setupAnnouncementSlideshow();
appBarLayout.offsetTopAndBottom(appBarOffset);

setupSlideshow();
}

@Override
Expand All @@ -237,7 +238,6 @@ public void onStop() {
annSlideshowHandler.removeCallbacks(annSlideshowRunable);
}
//Remove firebase database listeners
imageSlideshowRef.removeEventListener(imageSlideShowVEL);
homeRef.removeEventListener(homeRefVEL);
annRef.removeEventListener(annRefVEL);

Expand All @@ -253,6 +253,7 @@ public void onStop() {
@Override
public void onDestroyView() {
super.onDestroyView();
imageSlideshowRef.removeEventListener(imageSlideShowVEL);
homeRV.removeOnItemTouchListener(onItemTouchListener);
unbinder.unbind();
}
Expand Down Expand Up @@ -334,7 +335,7 @@ private ValueEventListener getHomeRefVEL() {
@Override
public void onDataChange(final DataSnapshot dataSnapshot) {
AHC.logd(TAG, "query snapshot is " + dataSnapshot.toString());
HomeService.saveHomeSnapshotToRealm(dataSnapshot);
new Thread(() -> HomeService.saveHomeSnapshotToRealm(dataSnapshot)).start();
}

@Override
Expand All @@ -348,7 +349,7 @@ private ValueEventListener getAnnRefVEL() {
return new ValueEventListener() {
@Override
public void onDataChange(final DataSnapshot dataSnapshot) {
HomeService.saveAnnSnapshotToRealm(dataSnapshot);
new Thread(() -> HomeService.saveAnnSnapshotToRealm(dataSnapshot));
}

@Override
Expand Down

0 comments on commit 775c8c8

Please sign in to comment.