소스 검색

优化apn数据库

losion.liu@sikey.com.cn 11 달 전
부모
커밋
b6d4e5d1e8

+ 4 - 6
app/src/main/java/com/xplora/xpsettings/Activity/ApnDeleteActivity.java

@@ -23,8 +23,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 public class ApnDeleteActivity extends BaseActivity {
-    public String apn_id = "";
-    public String name = "";
+    public ApnModel mApnModel = new ApnModel();
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -35,8 +34,7 @@ public class ApnDeleteActivity extends BaseActivity {
     }
 
     private void initIntent() {
-        apn_id = getIntent().getStringExtra(Constant.INTENT_LIST_INDEX);
-        name = getIntent().getStringExtra(Constant.INTENT_VIEW_VALUE);
+        mApnModel = (ApnModel) getIntent().getSerializableExtra(Constant.INTENT_RESULT_VALUE);
     }
 
     private void initView() {
@@ -50,7 +48,7 @@ public class ApnDeleteActivity extends BaseActivity {
         }
 
         if (textName != null) {
-            textName.setText(name);
+            textName.setText(mApnModel.name.trim());
         }
 
         if (cancelButton != null) {
@@ -81,7 +79,7 @@ public class ApnDeleteActivity extends BaseActivity {
     public void clickSureButton() {
         Intent intent = new Intent();
         intent.setAction(Constant.INTENT_RESULT_ACTION_REMOVE);
-        intent.putExtra(Constant.INTENT_RESULT_VALUE, apn_id);
+        intent.putExtra(Constant.INTENT_RESULT_VALUE, mApnModel);
         setResult(RESULT_OK, intent);
         finish();
     }

+ 7 - 8
app/src/main/java/com/xplora/xpsettings/Activity/ApnListActivity.java

@@ -160,8 +160,7 @@ public class ApnListActivity extends BaseActivity {
                 if (!isCustom)
                     return true;
                 Intent intent = new Intent(ApnListActivity.this, ApnDeleteActivity.class);
-                intent.putExtra(Constant.INTENT_LIST_INDEX, apnModel.apn_id);
-                intent.putExtra(Constant.INTENT_VIEW_VALUE, apnModel.name.trim());
+                intent.putExtra(Constant.INTENT_RESULT_VALUE, mApnList.get(position));
                 startActivityForResult(intent, 0);
                 return true;
             }
@@ -188,8 +187,8 @@ public class ApnListActivity extends BaseActivity {
                 updateAPN(apnModel);
             }
         } else if (data.getAction().equals(Constant.INTENT_RESULT_ACTION_REMOVE)) {
-            String apn_id = data.getStringExtra(Constant.INTENT_RESULT_VALUE);
-            deleteApn(apn_id);
+            ApnModel model = (ApnModel)data.getSerializableExtra(Constant.INTENT_RESULT_VALUE);
+            deleteApn(model);
         }
     }
 
@@ -209,10 +208,10 @@ public class ApnListActivity extends BaseActivity {
         reloadView();
     }
 
-    void deleteApn(String _id) {
-        Log.d(TAG, "deleteApn: " + _id);
-        ApnManager.deleteAPN(getApplicationContext(), _id);
-        DatabaseHelper.deleteAPN(this, _id);
+    void deleteApn(ApnModel model) {
+        Log.d(TAG, "deleteApn: " + model.apn_id);
+        ApnManager.deleteAPN(getApplicationContext(), model.apn_id);
+        DatabaseHelper.deleteAPN(this, model._id);
         reloadView();
     }
 

+ 5 - 4
app/src/main/java/com/xplora/xpsettings/Data/DatabaseHelper.java

@@ -110,7 +110,7 @@ public class DatabaseHelper {
         } else {
             ArrayList<ApnModel> arrayList = new ArrayList<>();
             ContentResolver resolver = context.getContentResolver();
-            Uri uri = Uri.parse(DB_GOPLAY_APN + "/" + 0);
+            Uri uri = Uri.parse(DB_GOPLAY_APN);
             Cursor cursor = resolver.query(uri, null, null, null, null);
             if (cursor == null) {
                 Log.d(TAG, "getApnList: cursor == null");
@@ -124,6 +124,7 @@ public class DatabaseHelper {
             Log.d(TAG, "getApnList: db ok");
             do {
                 ApnModel bean = new ApnModel();
+                bean._id = cursor.getString(cursor.getColumnIndex("_id"));
                 bean.apn_id = cursor.getString(cursor.getColumnIndex("apn_id"));
                 bean.name = cursor.getString(cursor.getColumnIndex("name"));
                 bean.apn_name = cursor.getString(cursor.getColumnIndex("apn_name"));
@@ -191,7 +192,7 @@ public class DatabaseHelper {
 
         } else {
             new Thread(()->{
-                Uri uri = Uri.parse(DB_GOPLAY_APN + "/" + model.apn_id);
+                Uri uri = Uri.parse(DB_GOPLAY_APN + "/" + model._id);
                 ContentValues values = new ContentValues();
                 values.put("apn_id", model.apn_id);
                 values.put("name", model.name);
@@ -219,12 +220,12 @@ public class DatabaseHelper {
         }
     }
 
-    public static void deleteAPN(Context context, String apnId) {
+    public static void deleteAPN(Context context, String _id) {
         if (Macros.DEBUG) {
 
         } else {
             new Thread(()->{
-                Uri uri = Uri.parse(DB_GOPLAY_APN + "/" + apnId);
+                Uri uri = Uri.parse(DB_GOPLAY_APN + "/" + _id);
                 int row = context.getContentResolver().delete(uri, null, null);
                 Log.d(TAG, "updateAPN: " + row);
             }).start();

+ 1 - 0
app/src/main/java/com/xplora/xpsettings/Model/ApnModel.java

@@ -3,6 +3,7 @@ package com.xplora.xpsettings.Model;
 import java.io.Serializable;
 
 public class ApnModel implements Serializable {
+    public String _id = "";
     public String apn_id = "";
     public String name = "";
     public String apn_name = "";