Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. package com.example.speruser.english_it;
  2. import android.content.ContentValues;
  3. import android.content.Context;
  4. import android.database.sqlite.SQLiteDatabase;
  5. import com.android.volley.Request;
  6. import com.android.volley.Response;
  7. import com.android.volley.VolleyError;
  8. import com.android.volley.toolbox.JsonArrayRequest;
  9. import org.json.JSONArray;
  10. import org.json.JSONException;
  11. import org.json.JSONObject;
  12.  
  13. import java.util.ArrayList;
  14.  
  15. public class CheckDbVersion extends JParser {
  16. CheckDbVersion(String url, Context context, SQLiteDatabase db) {
  17. super(url, context, db);
  18. }
  19. public void jsonParse(final VersionInterface callback){
  20. final JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, getUrl(), null,
  21. new Response.Listener<JSONArray>() {
  22. @Override
  23. public void onResponse(JSONArray response) {
  24. try{
  25. ArrayList<DbVersionObj> Arrobj = new ArrayList<>();
  26. for(int i=0;i<response.length();i++){
  27. JSONObject obj = response.getJSONObject(i);
  28. String db_version = obj.getString("db_version");
  29. Arrobj.add(new DbVersionObj(String.valueOf(i+1),db_version));
  30. }
  31. callback.checkVersion(Arrobj.get(0)); //send to interface
  32.  
  33. }catch (JSONException e){
  34. e.printStackTrace();
  35. }
  36. }
  37. },
  38. new Response.ErrorListener()
  39. {
  40. @Override
  41. public void onErrorResponse(VolleyError error){
  42. }
  43. }
  44. );
  45.  
  46. getRequestQueue().add(jsonArrayRequest);
  47. }
  48. public void changeDbVersion(String newVersion){
  49. getDbInstance().execSQL("DROP TABLE db_version");
  50. getDbInstance().execSQL("CREATE TABLE IF NOT EXISTS db_version (db_version_id INTEGER PRIMARY KEY AUTOINCREMENT, db_version INTEGER NOT NULL)");
  51. ContentValues val = new ContentValues();
  52. val.put("db_version", newVersion);
  53. getDbInstance().insertOrThrow("db_version", null, val);
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement