-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#15: Added Volley Request to retrieve data for nearby Privys
- Loading branch information
1 parent
a14375c
commit 6da55ae
Showing
10 changed files
with
197 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/pulkit4tech/privy/data/MarkerData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.pulkit4tech.privy.data; | ||
|
||
import com.google.android.gms.maps.model.LatLng; | ||
|
||
public class MarkerData { | ||
|
||
//TODO : This is dummy test => USE GSON to Parse JSON | ||
|
||
private LatLng test; | ||
|
||
public MarkerData(){ | ||
test = new LatLng(28.7037992,77.1006268); | ||
} | ||
|
||
public LatLng getTest() { | ||
return test; | ||
} | ||
|
||
public void setTest(LatLng test) { | ||
this.test = test; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.pulkit4tech.privy.data; | ||
|
||
public class PrivyPost { | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
app/src/main/java/com/pulkit4tech/privy/utilities/RequestData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.pulkit4tech.privy.utilities; | ||
|
||
import android.content.Context; | ||
import android.net.Uri; | ||
import android.util.Log; | ||
import android.widget.Toast; | ||
|
||
import com.android.volley.Request; | ||
import com.android.volley.RequestQueue; | ||
import com.android.volley.Response; | ||
import com.android.volley.VolleyError; | ||
import com.android.volley.toolbox.StringRequest; | ||
import com.android.volley.toolbox.Volley; | ||
import com.google.android.gms.maps.GoogleMap; | ||
import com.google.android.gms.maps.model.LatLng; | ||
import com.google.android.gms.maps.model.MarkerOptions; | ||
import com.pulkit4tech.privy.R; | ||
import com.pulkit4tech.privy.data.MarkerData; | ||
|
||
import java.util.ArrayList; | ||
|
||
import static com.pulkit4tech.privy.constants.Constants.DEBUG; | ||
|
||
|
||
public class RequestData { | ||
|
||
private LatLng myLocation; | ||
private ArrayList<MarkerData> markerData; | ||
private RequestQueue requestQueue; | ||
private Context mContext; | ||
private GoogleMap mMap; | ||
|
||
private String LOCATION = "location"; | ||
private String NAME_KEY = "name"; | ||
private String NAME_VALUE = "toilet"; | ||
private String GOOGLE_MAP_API_KEY = "key"; | ||
private String MAPS = "maps"; | ||
private String API = "api"; | ||
private String PLACE = "place"; | ||
private String NEARBY = "nearbysearch"; | ||
private String TYPE = "json"; | ||
|
||
public RequestData(Context mContext, GoogleMap mMap, LatLng myLocation){ | ||
this.myLocation = myLocation; | ||
this.mContext = mContext; | ||
this.mMap = mMap; | ||
} | ||
|
||
public void getMarkerData(){ | ||
requestQueue = Volley.newRequestQueue(mContext); | ||
Uri.Builder builder = new Uri.Builder(); | ||
builder.scheme("https") | ||
.authority(mContext.getResources().getString(R.string.request_api)) | ||
.appendPath(MAPS) | ||
.appendPath(API) | ||
.appendPath(PLACE) | ||
.appendPath(NEARBY) | ||
.appendPath(TYPE) | ||
.encodedQuery(LOCATION + "=" +String.format("%f,%f",myLocation.latitude,myLocation.longitude)) | ||
.appendQueryParameter(NAME_KEY,NAME_VALUE) | ||
.appendQueryParameter(GOOGLE_MAP_API_KEY,mContext.getResources().getString(R.string.google_maps_key)); | ||
|
||
final String requestUrl = builder.build().toString(); | ||
Log.d(DEBUG,"URL: " + requestUrl); | ||
|
||
StringRequest request = new StringRequest(Request.Method.GET, requestUrl, new Response.Listener<String>() { | ||
@Override | ||
public void onResponse(String response) { | ||
// testing response | ||
Toast.makeText(mContext,"Got response",Toast.LENGTH_SHORT).show(); | ||
Log.d(DEBUG, "Response: " + response); | ||
|
||
// dummy data test TODO : Replace with JSON parsing | ||
markerData = new ArrayList<>(); | ||
markerData.add(new MarkerData()); | ||
|
||
for (MarkerData data : markerData){ | ||
mMap.addMarker(new MarkerOptions().position(data.getTest()).title("Test")); | ||
} | ||
} | ||
}, new Response.ErrorListener() { | ||
@Override | ||
public void onErrorResponse(VolleyError error) { | ||
Toast.makeText(mContext,"ERROR!!",Toast.LENGTH_SHORT).show(); | ||
Log.d(DEBUG, error.toString()); | ||
} | ||
}); | ||
|
||
requestQueue.add(request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<resources> | ||
<string name="app_name">Privy</string> | ||
<string name="title_activity_privy_maps">Nearby Privy\'s</string> | ||
<string name="request_api">maps.googleapis.com</string> | ||
</resources> |