-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#15: Added Volley Request to retrieve data for nearby Privys #20
Merged
+197
−39
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.