Guest User

Untitled

a guest
May 27th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.83 KB | None | 0 0
  1. geoFire.setLocation(itemID,
  2. new GeoLocation(Double.parseDouble(currentLat.getText().toString()),
  3. Double.parseDouble(currentLng.getText().toString())));
  4.  
  5. databaseReferenceRequests.child(itemID).setValue(hRequest);
  6.  
  7. public void retrieveHelpRequests() {
  8.  
  9. geoQuery = geoFire.queryAtLocation(new GeoLocation(currentLatDouble, currentLngDouble), 0.5);
  10.  
  11. geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
  12. @Override
  13. public void onKeyEntered(String key, GeoLocation location) {
  14. databaseReference.child("help-requests").addListenerForSingleValueEvent(new ValueEventListener() {
  15. @Override
  16. public void onDataChange(DataSnapshot dataSnapshot) {
  17. Map<String, String> newRequest = (Map<String, String>) dataSnapshot.getValue();
  18. imageUID = newRequest.get("imageUIDh");
  19. homelessDescription = newRequest.get("homelessDescription");
  20. currentLat = newRequest.get("currentLat");
  21. currentLng = newRequest.get("currentLng");
  22. postedBy = newRequest.get("postedBy");
  23. postedAtTime = newRequest.get("postedAtTime");
  24. postedOnDate = newRequest.get("postedOnDate");
  25. utcFormatDateTime = newRequest.get("utcFormatDateTime");
  26.  
  27. String timeStr = utcFormatDateTime;
  28. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  29. df.setTimeZone(TimeZone.getTimeZone("UTC"));
  30. Date date = null;
  31. try {
  32. // error on line below
  33. date = df.parse(timeStr);
  34. } catch (ParseException e) {
  35. e.printStackTrace();
  36. }
  37. df.setTimeZone(TimeZone.getDefault());
  38. final String persisted = df.format(date);
  39.  
  40. // Parse string from DB - UTC timezone
  41. Date parsed = null;
  42. try {
  43. parsed = df.parse(persisted);
  44. } catch (ParseException e) {
  45. e.printStackTrace();
  46. }
  47.  
  48. // Now convert to whatever timezone for display purposes
  49. final SimpleDateFormat displayFormat = new SimpleDateFormat("h:mm a");
  50. displayFormat.setTimeZone(TimeZone.getDefault());
  51.  
  52. formattedTime = displayFormat.format(parsed);
  53.  
  54. prepareDataForRequests();
  55. }
  56.  
  57. @Override
  58. public void onCancelled(DatabaseError databaseError) {
  59. Snackbar snackbar = Snackbar
  60. .make(coordinatorLayout, databaseError.getMessage(), Snackbar.LENGTH_LONG);
  61. snackbar.setDuration(Snackbar.LENGTH_SHORT);
  62. snackbar.show();
  63. // helpRequestsLoadingDialog.dismiss();
  64. progressBarLoadingRequests.setVisibility(View.INVISIBLE);
  65. }
  66. });
  67.  
  68. databaseReference.child("help-requests").addValueEventListener(new ValueEventListener() {
  69. @Override
  70. public void onDataChange(final DataSnapshot dataSnapshot) {
  71. // adView.loadAd(request);
  72. card_ads2.setVisibility(View.VISIBLE);
  73. adView2.loadAd(request2);
  74. if (snackbar != null) {
  75. snackbar.dismiss();
  76. }
  77. progressBarLoadingRequests.setVisibility(View.INVISIBLE);
  78.  
  79. if (fastItemAdapter.getAdapterItemCount() == 0) {
  80. emptyRVtext.setVisibility(View.VISIBLE);
  81. emptyRVtexthh.setVisibility(View.VISIBLE);
  82. card_ads2.setVisibility(View.INVISIBLE);
  83. } else {
  84. emptyRVtext.setVisibility(View.INVISIBLE);
  85. emptyRVtexthh.setVisibility(View.INVISIBLE);
  86. }
  87.  
  88. // progressBarLoadingRequests.setVisibility(View.INVISIBLE);
  89. }
  90.  
  91. @Override
  92. public void onCancelled(DatabaseError databaseError) {
  93. Snackbar snackbar = Snackbar
  94. .make(coordinatorLayout, databaseError.getMessage(), Snackbar.LENGTH_LONG);
  95. snackbar.setDuration(Snackbar.LENGTH_SHORT);
  96. snackbar.show();
  97. // hRequestsLoadingDialog.dismiss();
  98. progressBarLoadingRequests.setVisibility(View.INVISIBLE);
  99. }
  100. });
  101. }
  102.  
  103. @Override
  104. public void onKeyExited(String key) {
  105.  
  106. }
  107.  
  108. @Override
  109. public void onKeyMoved(String key, GeoLocation location) {
  110.  
  111. }
  112.  
  113. @Override
  114. public void onGeoQueryReady() {
  115.  
  116. }
  117.  
  118. @Override
  119. public void onGeoQueryError(DatabaseError error) {
  120. Toast.makeText(getBaseContext(), "Error retriving geoquery", Toast.LENGTH_SHORT).show();
  121. }
  122. });
  123.  
  124. }
  125.  
  126. double radius = 0.5; // in km
  127. geoQuery = geoFire.queryAtLocation(new GeoLocation(currentLatDouble, currentLngDouble), radius);
  128.  
  129. Location userLocation = new Location("userLocation");
  130. userLocation.setLatitude(currentLatDouble);
  131. userLocation.setLongitude(currentLngDouble);
  132. geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
  133. @Override
  134. public void onKeyEntered(String key, GeoLocation location) {
  135. Location itemLocation = new Location("itemLocation");
  136. itemLocation.setLatitude(location.latitude);
  137. itemLocation.setLongitude(location.longitude);
  138. Log.d("distance to " + key" is", userLocation.distanceTo(itemLocation) + "");
  139. }
  140.  
  141. var geoQuery = geoFire.query({
  142. center: [37.4, -122.6],
  143. radius: 1.609 //kilometers
  144. });
  145.  
  146. geoQuery.on("key_entered", function(key, location, distance) {
  147. console.log("Bicycle shop " + key + " found at " + location + " (" + distance + " km away)");
  148. });
  149.  
  150. geoQuery.on("key_exited", function(key, location, distance) {
  151. console.log("Bicycle shop " + key + " left query to " + location + " (" + distance + " km away)");
  152. });
  153.  
  154. GeoQuery geoQuery = geoFire.queryAtLocation(currentUserLocation, 1.6);
Add Comment
Please, Sign In to add comment