Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- protected String doInBackground(String... strings) {
- URL url;
- HttpURLConnection urlConnection;
- List<NewPublicService> passwordManagersList = new ArrayList<>();
- List<NewPublicService> authenticatorsList = new ArrayList<>();
- try {
- url = new URL(strings[0]);
- urlConnection = (HttpURLConnection) url.openConnection();
- int responseCode = urlConnection.getResponseCode();
- if (responseCode == HttpURLConnection.HTTP_OK) {
- response = readStream(urlConnection.getInputStream());
- Log.v("Response", response);
- JSONArray jsonArray = null;
- try {
- jsonArray = new JSONArray(response);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- for (int i = 0; i < jsonArray.length(); i++) {
- try {
- NewPublicService newPublicService = new NewPublicService();
- JSONObject jsonObject = new JSONObject(jsonArray.get(i).toString());
- newPublicService.setN((String) jsonObject.get("n"));
- newPublicService.setR((Boolean) jsonObject.get("r"));
- newPublicService.setS((Boolean) jsonObject.get("s"));
- String test = String.valueOf(jsonObject.get("i"));
- Long L = Long.valueOf(test);
- newPublicService.setI(L);
- newPublicService.setU((long) jsonObject.get("u"));
- try {
- if (!newPublicService.getS()) {
- //add to password manager list
- passwordManagersList.add(newPublicService);
- } else {
- //add to auth list
- authenticatorsList.add(newPublicService);
- }
- } catch (OutOfMemoryError error) {
- error.printStackTrace();
- break;
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- try {
- PasswordManagersListPref.with(Engine.getInstance().getContext()).savePasswordManagerList(Engine.getInstance().getContext(), passwordManagersList);
- AuthenticatorsListPref.with(Engine.getInstance().getContext()).saveAuthenticatorsList(Engine.getInstance().getContext(), authenticatorsList);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement