Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.speruser.english_it;
- import android.content.ContentValues;
- import android.content.Context;
- import android.database.sqlite.SQLiteDatabase;
- import com.android.volley.Request;
- import com.android.volley.Response;
- import com.android.volley.VolleyError;
- import com.android.volley.toolbox.JsonArrayRequest;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.ArrayList;
- public class CheckDbVersion extends JParser {
- CheckDbVersion(String url, Context context, SQLiteDatabase db) {
- super(url, context, db);
- }
- public void jsonParse(final VersionInterface callback){
- final JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, getUrl(), null,
- new Response.Listener<JSONArray>() {
- @Override
- public void onResponse(JSONArray response) {
- try{
- ArrayList<DbVersionObj> Arrobj = new ArrayList<>();
- for(int i=0;i<response.length();i++){
- JSONObject obj = response.getJSONObject(i);
- String db_version = obj.getString("db_version");
- Arrobj.add(new DbVersionObj(String.valueOf(i+1),db_version));
- }
- callback.checkVersion(Arrobj.get(0)); //send to interface
- }catch (JSONException e){
- e.printStackTrace();
- }
- }
- },
- new Response.ErrorListener()
- {
- @Override
- public void onErrorResponse(VolleyError error){
- }
- }
- );
- getRequestQueue().add(jsonArrayRequest);
- }
- public void changeDbVersion(String newVersion){
- getDbInstance().execSQL("DROP TABLE db_version");
- getDbInstance().execSQL("CREATE TABLE IF NOT EXISTS db_version (db_version_id INTEGER PRIMARY KEY AUTOINCREMENT, db_version INTEGER NOT NULL)");
- ContentValues val = new ContentValues();
- val.put("db_version", newVersion);
- getDbInstance().insertOrThrow("db_version", null, val);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement