This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggestions bar implementation (#724)
* Suggestions bar implementation * Fixed row click issue.
- Loading branch information
1 parent
e900283
commit fe5bacd
Showing
38 changed files
with
1,444 additions
and
478 deletions.
There are no files selected for viewing
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
35 changes: 35 additions & 0 deletions
35
app/src/common/shared/org/mozilla/vrbrowser/geolocation/GeolocationClient.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,35 @@ | ||
package org.mozilla.vrbrowser.geolocation; | ||
|
||
import com.loopj.android.http.AsyncHttpClient; | ||
import com.loopj.android.http.JsonHttpResponseHandler; | ||
|
||
import org.json.JSONObject; | ||
|
||
import java.util.function.Function; | ||
|
||
import cz.msebera.android.httpclient.Header; | ||
|
||
public class GeolocationClient { | ||
|
||
private static final int RETRY_SLEEP = 5 * 1000; | ||
|
||
private static AsyncHttpClient client = new AsyncHttpClient(); | ||
|
||
public static void getGeolocation(String aQuery, int retries, Function success, Function error) { | ||
client.cancelAllRequests(true); | ||
client.setMaxRetriesAndTimeout(retries, RETRY_SLEEP); | ||
client.get(aQuery, null, new JsonHttpResponseHandler("ISO-8859-1") { | ||
|
||
@Override | ||
public void onSuccess(int statusCode, Header[] headers, JSONObject response) { | ||
success.apply(GeolocationData.parse(response.toString())); | ||
} | ||
|
||
@Override | ||
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { | ||
error.apply(errorResponse); | ||
} | ||
|
||
}); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
app/src/common/shared/org/mozilla/vrbrowser/geolocation/GeolocationData.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,51 @@ | ||
package org.mozilla.vrbrowser.geolocation; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.util.Log; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
/** | ||
* Class representing a Geolocation success response (HTTP 200) | ||
*/ | ||
public class GeolocationData { | ||
|
||
private static final String LOGTAG = "VRB"; | ||
|
||
private JSONObject mData; | ||
|
||
private GeolocationData(JSONObject data) { | ||
mData = data; | ||
} | ||
|
||
@NonNull | ||
public static GeolocationData create(JSONObject data) { | ||
return new GeolocationData(data); | ||
} | ||
|
||
@NonNull | ||
public static GeolocationData parse(String aGeolocationJson) { | ||
try { | ||
return GeolocationData.create(new JSONObject(aGeolocationJson)); | ||
|
||
} catch (JSONException e) { | ||
Log.e(LOGTAG, "Error parsing geolocation data: " + e.getLocalizedMessage()); | ||
return null; | ||
} | ||
} | ||
|
||
public String getCountryCode() { | ||
return mData.optString("country_code", ""); | ||
} | ||
|
||
public String getCountryName() { | ||
return mData.optString("country_name", ""); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return mData.toString(); | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
app/src/common/shared/org/mozilla/vrbrowser/geolocation/GeolocationWrapper.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,52 @@ | ||
package org.mozilla.vrbrowser.geolocation; | ||
|
||
import android.content.Context; | ||
import android.support.annotation.NonNull; | ||
|
||
import org.mozilla.gecko.util.ThreadUtils; | ||
import org.mozilla.vrbrowser.R; | ||
import org.mozilla.vrbrowser.browser.SettingsStore; | ||
|
||
public class GeolocationWrapper { | ||
|
||
private static final int MAX_RETRIES = 2; | ||
private static final int RETRY_SLEEP = 5 * 1000; | ||
|
||
public static void update(final @NonNull Context aContext) { | ||
String endpoint = aContext.getString(R.string.geolocation_api_url); | ||
update(aContext, endpoint, 0, MAX_RETRIES); | ||
} | ||
|
||
private static void update(final @NonNull Context aContext, | ||
final @NonNull String endPoint, | ||
final int retryCount, | ||
final int maxRetries) { | ||
if (retryCount <= maxRetries - 1) { | ||
GeolocationClient.getGeolocation( | ||
endPoint, | ||
MAX_RETRIES, | ||
(data) -> { | ||
if (data == null) { | ||
if (retryCount <= maxRetries) { | ||
ThreadUtils.postDelayedToUiThread(() -> | ||
update(aContext, endPoint, retryCount + 1, maxRetries), | ||
RETRY_SLEEP); | ||
} | ||
|
||
} else { | ||
SettingsStore.getInstance(aContext).setGeolocationData(data.toString()); | ||
} | ||
return null; | ||
}, | ||
(error) -> { | ||
if (retryCount <= maxRetries) { | ||
ThreadUtils.postDelayedToUiThread(() -> | ||
update(aContext, endPoint, retryCount + 1, maxRetries), | ||
RETRY_SLEEP); | ||
} | ||
return null; | ||
}); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.