diff --git a/app/src/main/java/com/gh/common/util/DataUtils.java b/app/src/main/java/com/gh/common/util/DataUtils.java index fc42f3f726..065b1bb468 100644 --- a/app/src/main/java/com/gh/common/util/DataUtils.java +++ b/app/src/main/java/com/gh/common/util/DataUtils.java @@ -161,7 +161,8 @@ public class DataUtils { values.put(GhContentProvider.KEY_IS_ADULT, false); } - HaloApp.getInstance().getContentResolver().insert(Uri.parse("content://com.gh.gamecenter.provider/certification"), values); + new GhContentProvider().localInsert( HaloApp.getInstance().getApplication(),values); +// HaloApp.getInstance().getContentResolver().insert(Uri.parse("content://com.gh.gamecenter.provider/certification"), values); } }); } diff --git a/app/src/main/java/com/gh/gamecenter/provider/GhContentProvider.kt b/app/src/main/java/com/gh/gamecenter/provider/GhContentProvider.kt index 6ce9e18a34..91129dcc8b 100644 --- a/app/src/main/java/com/gh/gamecenter/provider/GhContentProvider.kt +++ b/app/src/main/java/com/gh/gamecenter/provider/GhContentProvider.kt @@ -1,11 +1,9 @@ package com.gh.gamecenter.provider -import android.content.ContentProvider -import android.content.ContentUris -import android.content.ContentValues -import android.content.UriMatcher +import android.content.* import android.database.Cursor import android.database.sqlite.SQLiteDatabase +import android.database.sqlite.SQLiteFullException import android.database.sqlite.SQLiteOpenHelper import android.net.Uri import android.text.TextUtils @@ -29,7 +27,7 @@ class GhContentProvider : ContentProvider() { mUriMatcher.addURI(AUTHORITY, SYNC_CERTIFICATION_TABLE_NAME, 2) } - override fun onCreate(): Boolean { + private fun initProviderSqliteHelper(context: Context?){ val helper: SQLiteOpenHelper = object : SQLiteOpenHelper(context, CERTIFICATION_DATABASE_NAME, null, 1) { override fun onCreate(db: SQLiteDatabase) { @@ -54,6 +52,9 @@ class GhContentProvider : ContentProvider() { } } mSqLiteDatabase = helper.writableDatabase + } + override fun onCreate(): Boolean { + initProviderSqliteHelper(context); return true } @@ -91,25 +92,49 @@ class GhContentProvider : ContentProvider() { override fun getType(uri: Uri): String? = null - override fun insert(uri: Uri, values: ContentValues?): Uri? { - val context = context ?: return null - if (mUriMatcher.match(uri) == 1) { - // 固定主键(只保留一条数据即可) + + fun localInsert(context: Context,values: ContentValues?){ + initProviderSqliteHelper(context) + try { values?.put(KEY_PRIMARY_KEY, 1) // 如果已存在则直接替换 - val rowId: Long? = mSqLiteDatabase?.insertWithOnConflict( + mSqLiteDatabase?.insertWithOnConflict( CERTIFICATION_TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_REPLACE ) - if (rowId != null && rowId > 0) { - val nameUri = ContentUris.withAppendedId(uri, rowId) - context.contentResolver.notifyChange(nameUri, null) - Utils.log("CertificationContentProvider", "insert success:" + uri.authority + ", status => " + values?.toString()) - return nameUri + + } catch (e: SQLiteFullException) { + Utils.toast(context,"数据库内存已满,无法同步") + } + } + + override fun insert(uri: Uri, values: ContentValues?): Uri? { + val context = context ?: return null + + if (mUriMatcher.match(uri) == 1) { + // 固定主键(只保留一条数据即可) + try { + values?.put(KEY_PRIMARY_KEY, 1) + // 如果已存在则直接替换 + val rowId: Long? = mSqLiteDatabase?.insertWithOnConflict( + CERTIFICATION_TABLE_NAME, + null, + values, + SQLiteDatabase.CONFLICT_REPLACE + ) + if (rowId != null && rowId > 0) { + val nameUri = ContentUris.withAppendedId(uri, rowId) + context.contentResolver.notifyChange(nameUri, null) + Utils.log("CertificationContentProvider", "insert success:" + uri.authority + ", status => " + values?.toString()) + return nameUri + } + } catch (e: SQLiteFullException) { + Utils.toast(context,"数据库内存已满,无法同步") } + } else if (mUriMatcher.match(uri) == 2) { val certificationStr = SPUtils.getString(Constants.SP_DEVICE_CERTIFICATION_PREFIX + HaloApp.getInstance().gid) diff --git a/libraries/LGLibrary b/libraries/LGLibrary index 692d58bc9b..2fb219f6c0 160000 --- a/libraries/LGLibrary +++ b/libraries/LGLibrary @@ -1 +1 @@ -Subproject commit 692d58bc9b494bf1d04db7809d43acbedaeb326c +Subproject commit 2fb219f6c06a14cb78341c14f5b8c847484df6cf