Created
February 3, 2020 09:15
-
-
Save Zamay/ab60cf9bb86b9982a4317b0a0cf26f39 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
private void loadKeitaroUrl(String keitaroUrl) { | |
Log.w("debug", "Requiring... " + keitaroUrl); | |
StringRequest stringRequest = new StringRequest(Request.Method.GET, keitaroUrl, | |
new Response.Listener<String>() { | |
@Override | |
public void onResponse(String response) { | |
Log.d("debug", "Successful response " + response); | |
parseData(response); | |
} | |
}, new Response.ErrorListener() { | |
@Override | |
public void onErrorResponse(VolleyError error) { | |
Log.w("debug", "Request is failed"); | |
webView.loadUrl(WHITE_PAGE_URL); | |
} | |
}); | |
RequestQueue queue = Volley.newRequestQueue(this); | |
queue.add(stringRequest); | |
} | |
private void parseData(String response) { | |
try { | |
JSONObject jsonObject = new JSONObject(response); | |
String url = jsonObject.getString("url"); | |
String showIn = jsonObject.getString("showIn"); | |
if (showIn.equals("webView")) { | |
if (url.equals(WHITE_PAGE_URL)) { | |
SharedPreferences.Editor editor = sharedPreferences.edit(); | |
editor.putBoolean(SHOW_WHITE_PAGE.toString(), true); | |
editor.apply(); | |
Log.w("debug", "Saved url: " + url); | |
} else { | |
subscribeInOneSignal(); | |
} | |
Log.w("debug", "Got url: " + url); | |
webView.loadUrl(url); | |
} else if (showIn.equals("browser")) { | |
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); | |
startActivity(browserIntent); | |
} else { | |
webView.loadUrl(WHITE_PAGE_URL); | |
} | |
} catch (JSONException e) { | |
Log.e("parseDataError", e.getMessage()); | |
e.printStackTrace(); | |
webView.loadUrl(WHITE_PAGE_URL); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment