From 9721030240190cee7d6e808213e29b29b85f1e10 Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Sun, 22 Dec 2019 16:03:51 +0300 Subject: [PATCH] version: 2.2.1 --- dependencies.gradle | 10 +++++----- .../app/src/main/java/com/vk/sdk/sample/PathUtils.kt | 3 ++- .../src/main/java/com/vk/sdk/sample/UserActivity.kt | 4 ++-- .../src/main/java/com/vk/sdk/sample/models/VKUser.kt | 6 +++--- vk-sdk-core/build.gradle | 4 ++++ .../java/com/vk/api/sdk/VKApiValidationHandler.kt | 2 +- .../main/java/com/vk/api/sdk/auth/VKAccessToken.kt | 6 +++--- .../main/java/com/vk/api/sdk/auth/VKAuthManager.kt | 10 +++++++++- .../java/com/vk/api/sdk/exceptions/VKApiCodes.kt | 2 ++ .../java/com/vk/api/sdk/internal/VKInitProvider.kt | 12 ++++++------ .../com/vk/api/sdk/okhttp/FileFullRequestBody.kt | 6 ++---- .../java/com/vk/api/sdk/ui/VKWebViewAuthActivity.kt | 2 +- .../java/com/vk/api/sdk/utils/ThreadLocalDelegate.kt | 2 +- .../src/main/java/com/vk/api/sdk/utils/VKUtils.kt | 4 +++- 14 files changed, 44 insertions(+), 29 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index 8f24d38a03..fccb87748e 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,13 +1,13 @@ ext.sdkVersions = [ - code : '14', - name : '2.2.0', + code : '15', + name : '2.2.1', minSdk : 16, targetSdk : 28, - compileSdk : '28', - buildTools : '28.0.3', + compileSdk : '29', + buildTools : '29.0.2', - kotlin : '1.3.41', + kotlin : '1.3.61', androidX : '1.0.0', okHttp : '3.12.1', diff --git a/samples/app/src/main/java/com/vk/sdk/sample/PathUtils.kt b/samples/app/src/main/java/com/vk/sdk/sample/PathUtils.kt index 4b82757169..8233032c4a 100644 --- a/samples/app/src/main/java/com/vk/sdk/sample/PathUtils.kt +++ b/samples/app/src/main/java/com/vk/sdk/sample/PathUtils.kt @@ -31,7 +31,8 @@ import android.provider.MediaStore object PathUtils { fun getPath(context: Context, uri: Uri): String { if (uri.scheme == "file") { - return uri.path + if (uri.path != null) return uri.path!! + return "" } val proj = arrayOf(MediaStore.Images.Media.DATA) val cursor = context.contentResolver.query(uri, proj, null, null, null) diff --git a/samples/app/src/main/java/com/vk/sdk/sample/UserActivity.kt b/samples/app/src/main/java/com/vk/sdk/sample/UserActivity.kt index 5b6307787b..9209decd12 100644 --- a/samples/app/src/main/java/com/vk/sdk/sample/UserActivity.kt +++ b/samples/app/src/main/java/com/vk/sdk/sample/UserActivity.kt @@ -122,8 +122,8 @@ class UserActivity: Activity() { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == IMAGE_REQ_CODE) { - if (resultCode == RESULT_OK && data != null) { - sharePost(Uri.parse(PathUtils.getPath(this, data.data))) + if (resultCode == RESULT_OK && data != null && data.data != null) { + sharePost(Uri.parse(PathUtils.getPath(this, data.data!!))) } else { sharePost() } diff --git a/samples/app/src/main/java/com/vk/sdk/sample/models/VKUser.kt b/samples/app/src/main/java/com/vk/sdk/sample/models/VKUser.kt index 79eab614a9..7b5987e735 100644 --- a/samples/app/src/main/java/com/vk/sdk/sample/models/VKUser.kt +++ b/samples/app/src/main/java/com/vk/sdk/sample/models/VKUser.kt @@ -37,9 +37,9 @@ data class VKUser( constructor(parcel: Parcel) : this( parcel.readInt(), - parcel.readString(), - parcel.readString(), - parcel.readString(), + parcel.readString()!!, + parcel.readString()!!, + parcel.readString()!!, parcel.readByte() != 0.toByte()) override fun writeToParcel(parcel: Parcel, flags: Int) { diff --git a/vk-sdk-core/build.gradle b/vk-sdk-core/build.gradle index e5dca4f830..0e4bd9c568 100644 --- a/vk-sdk-core/build.gradle +++ b/vk-sdk-core/build.gradle @@ -26,6 +26,10 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply from: '../dependencies.gradle' +ext.POM_GROUP_ID = "com.vk" +ext.POM_ARTIFACT_ID = sdkPublish.POM_ARTIFACT_ID +ext.POM_VERSION = sdkVersions.name + android { compileSdkVersion "$sdkVersions.compileSdk".toInteger() buildToolsVersion "$sdkVersions.buildTools" diff --git a/vk-sdk-core/src/main/java/com/vk/api/sdk/VKApiValidationHandler.kt b/vk-sdk-core/src/main/java/com/vk/api/sdk/VKApiValidationHandler.kt index 8b80903ff3..0edd0c5e05 100644 --- a/vk-sdk-core/src/main/java/com/vk/api/sdk/VKApiValidationHandler.kt +++ b/vk-sdk-core/src/main/java/com/vk/api/sdk/VKApiValidationHandler.kt @@ -53,6 +53,6 @@ interface VKApiValidationHandler { } } class Credentials(val secret: String?, val token: String?, val uid: Int?) { - val isValid = !(token.isNullOrBlank() || secret.isNullOrEmpty()) + val isValid = !token.isNullOrBlank() } } \ No newline at end of file diff --git a/vk-sdk-core/src/main/java/com/vk/api/sdk/auth/VKAccessToken.kt b/vk-sdk-core/src/main/java/com/vk/api/sdk/auth/VKAccessToken.kt index d33236e47a..983c1cf311 100644 --- a/vk-sdk-core/src/main/java/com/vk/api/sdk/auth/VKAccessToken.kt +++ b/vk-sdk-core/src/main/java/com/vk/api/sdk/auth/VKAccessToken.kt @@ -34,7 +34,7 @@ class VKAccessToken(params: Map) { Pair(SECRET, secret), Pair(HTTPS_REQUIRED, "1"))) - val userId: Int? + val userId: Int val accessToken: String val secret: String? val created: Long @@ -48,7 +48,7 @@ class VKAccessToken(params: Map) { get() = expirationDate <= 0 || created + expirationDate * 1000 > System.currentTimeMillis() init { - this.userId = params[USER_ID]?.toIntOrNull() + this.userId = params[USER_ID]?.toInt()!! this.accessToken = params[ACCESS_TOKEN]!! this.secret = params[SECRET] this.httpsRequired = "1" == params[HTTPS_REQUIRED] @@ -84,7 +84,7 @@ class VKAccessToken(params: Map) { result[HTTPS_REQUIRED] = if (httpsRequired) "1" else "0" result[CREATED] = created.toString() result[EXPIRES_IN] = expirationDate.toString() - result[USER_ID] = userId?.toString() + result[USER_ID] = userId.toString() result[EMAIL] = email result[PHONE] = phone result[PHONE_ACCESS_KEY] = phoneAccessKey diff --git a/vk-sdk-core/src/main/java/com/vk/api/sdk/auth/VKAuthManager.kt b/vk-sdk-core/src/main/java/com/vk/api/sdk/auth/VKAuthManager.kt index fe1a5450d2..59899bdf06 100644 --- a/vk-sdk-core/src/main/java/com/vk/api/sdk/auth/VKAuthManager.kt +++ b/vk-sdk-core/src/main/java/com/vk/api/sdk/auth/VKAuthManager.kt @@ -28,6 +28,7 @@ import android.app.Activity import android.content.Context import android.content.Intent import android.content.SharedPreferences +import android.util.Log import com.vk.api.sdk.VK import com.vk.api.sdk.ui.VKWebViewAuthActivity import com.vk.api.sdk.utils.VKUtils @@ -105,7 +106,14 @@ internal class VKAuthManager { else -> return null } - return if (tokenParams != null && tokenParams[VK_AUTH_ERROR] == null) VKAuthResult(VKAccessToken(tokenParams)) else null + return if (tokenParams != null && tokenParams[VK_AUTH_ERROR] == null) { + try { + VKAuthResult(VKAccessToken(tokenParams)) + } catch (e: Exception) { + Log.e(VKAuthManager::class.java.simpleName, "Failed to get VK token", e) + null + } + } else null } diff --git a/vk-sdk-core/src/main/java/com/vk/api/sdk/exceptions/VKApiCodes.kt b/vk-sdk-core/src/main/java/com/vk/api/sdk/exceptions/VKApiCodes.kt index e90b516f18..cf41b8bb8b 100644 --- a/vk-sdk-core/src/main/java/com/vk/api/sdk/exceptions/VKApiCodes.kt +++ b/vk-sdk-core/src/main/java/com/vk/api/sdk/exceptions/VKApiCodes.kt @@ -65,6 +65,7 @@ object VKApiCodes { const val CODE_ACCESS_POLLS_WITHOUT_VOTE = 253 const val CODE_PHOTO_ALBUM_LIMIT_EXCEED = 300 const val CODE_OPERATION_NOT_PERMITTED = 500 + const val CODE_NOT_ENOUGH_MONEY_ON_OWNER_BALANCE = 504 const val CODE_ADVERTISE_CABINET_NO_PERMISSIONS_FOR_OPERATION = 600 const val CODE_ADVERTISE_CABINET_ERROR = 603 const val CODE_VIDEO_ALREADY_ADDED = 800 @@ -94,6 +95,7 @@ object VKApiCodes { const val CODE_INVALID_SID = 1113 const val CODE_SIGN_UP_CODE_INCORRECT = 1110 const val CODE_SIGN_UP_PASSWORD_UNALLOWABLE = 1111 + const val CODE_STICKERS_DISABLED = 1191 const val CODE_ACCOUNT_INVALID_SCREEN_NAME = 1260 diff --git a/vk-sdk-core/src/main/java/com/vk/api/sdk/internal/VKInitProvider.kt b/vk-sdk-core/src/main/java/com/vk/api/sdk/internal/VKInitProvider.kt index 035d6013af..13b9c5c1c6 100644 --- a/vk-sdk-core/src/main/java/com/vk/api/sdk/internal/VKInitProvider.kt +++ b/vk-sdk-core/src/main/java/com/vk/api/sdk/internal/VKInitProvider.kt @@ -13,20 +13,20 @@ import com.vk.api.sdk.VK class VKInitProvider: ContentProvider() { override fun onCreate(): Boolean { try { - VK.initialize(context) + VK.initialize(context!!) } catch (e: Exception) { Log.e(VKInitProvider::class.java.simpleName, "Failed to initialize the VK SDK", e) } return false } - override fun insert(uri: Uri?, p1: ContentValues?): Uri? = null + override fun insert(uri: Uri, p1: ContentValues?): Uri? = null - override fun query(uri: Uri?, p1: Array?, p2: String?, p3: Array?, p4: String?): Cursor? = null + override fun query(uri: Uri, p1: Array?, p2: String?, p3: Array?, p4: String?): Cursor? = null - override fun update(uri: Uri?, p1: ContentValues?, p2: String?, p3: Array?): Int = 0 + override fun update(uri: Uri, p1: ContentValues?, p2: String?, p3: Array?): Int = 0 - override fun delete(uri: Uri?, p1: String?, p2: Array?): Int = 0 + override fun delete(uri: Uri, p1: String?, p2: Array?): Int = 0 - override fun getType(uri: Uri?): String? = null + override fun getType(uri: Uri): String? = null } \ No newline at end of file diff --git a/vk-sdk-core/src/main/java/com/vk/api/sdk/okhttp/FileFullRequestBody.kt b/vk-sdk-core/src/main/java/com/vk/api/sdk/okhttp/FileFullRequestBody.kt index 9877524ccd..38b6c0ddaa 100644 --- a/vk-sdk-core/src/main/java/com/vk/api/sdk/okhttp/FileFullRequestBody.kt +++ b/vk-sdk-core/src/main/java/com/vk/api/sdk/okhttp/FileFullRequestBody.kt @@ -39,12 +39,10 @@ import okhttp3.MediaType import okhttp3.RequestBody import okio.BufferedSink -internal class FileFullRequestBody(private val context: Context?, private val fileUri: Uri?) : RequestBody() { +internal class FileFullRequestBody(private val context: Context?, private val fileUri: Uri) : RequestBody() { init { - if (context == null) { - throw IllegalArgumentException("context is null") - } + requireNotNull(context) { "context is null" } if (fileUri == null) { throw IllegalArgumentException("fileUri is null") } diff --git a/vk-sdk-core/src/main/java/com/vk/api/sdk/ui/VKWebViewAuthActivity.kt b/vk-sdk-core/src/main/java/com/vk/api/sdk/ui/VKWebViewAuthActivity.kt index edcce5602b..a30691762a 100644 --- a/vk-sdk-core/src/main/java/com/vk/api/sdk/ui/VKWebViewAuthActivity.kt +++ b/vk-sdk-core/src/main/java/com/vk/api/sdk/ui/VKWebViewAuthActivity.kt @@ -160,7 +160,7 @@ open class VKWebViewAuthActivity: Activity() { if (uri.getQueryParameter("success") != null) { val token = uri.getQueryParameter("access_token") val secret = uri.getQueryParameter("secret") - val userId = uri.getQueryParameter("user_id").toInt() + val userId = uri.getQueryParameter("user_id")?.toInt() validationResult = VKApiValidationHandler.Credentials(secret, token, userId) } } diff --git a/vk-sdk-core/src/main/java/com/vk/api/sdk/utils/ThreadLocalDelegate.kt b/vk-sdk-core/src/main/java/com/vk/api/sdk/utils/ThreadLocalDelegate.kt index 8bd0b1109b..2ec6a63a8d 100644 --- a/vk-sdk-core/src/main/java/com/vk/api/sdk/utils/ThreadLocalDelegate.kt +++ b/vk-sdk-core/src/main/java/com/vk/api/sdk/utils/ThreadLocalDelegate.kt @@ -45,7 +45,7 @@ internal class ThreadLocalDelegateImpl(val factory: () -> T) : ThreadLocalDel } override fun get(): T { - return value.get() + return value.get()!! } } diff --git a/vk-sdk-core/src/main/java/com/vk/api/sdk/utils/VKUtils.kt b/vk-sdk-core/src/main/java/com/vk/api/sdk/utils/VKUtils.kt index 3f270a0c09..b3f30aba4f 100644 --- a/vk-sdk-core/src/main/java/com/vk/api/sdk/utils/VKUtils.kt +++ b/vk-sdk-core/src/main/java/com/vk/api/sdk/utils/VKUtils.kt @@ -64,7 +64,9 @@ object VKUtils { for (keyValueString in keyValuePairs) { val keyValueArray = keyValueString.split("=") - parameters[keyValueArray[0]] = keyValueArray[1] + if (keyValueArray.size > 1) { + parameters[keyValueArray[0]] = keyValueArray[1] + } } return parameters }