├── .gitignore
├── .metadata
├── CHANGELOG.md
├── LICENSE
├── README.md
├── android
├── .gitignore
├── build.gradle
├── gradle.properties
├── settings.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── kotlin
│ └── com
│ └── kf
│ └── flutter_vk_sdk
│ ├── FlutterVKApiDelegate.kt
│ ├── FlutterVKResultDelegate.kt
│ └── FlutterVKSdkPlugin.kt
├── example
├── .gitignore
├── .metadata
├── README.md
├── android
│ ├── app
│ │ ├── build.gradle
│ │ └── src
│ │ │ ├── debug
│ │ │ └── AndroidManifest.xml
│ │ │ ├── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── kotlin
│ │ │ │ └── com
│ │ │ │ │ └── kf
│ │ │ │ │ └── flutter_vk_sdk_example
│ │ │ │ │ └── MainActivity.kt
│ │ │ └── res
│ │ │ │ ├── drawable
│ │ │ │ └── launch_background.xml
│ │ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ └── values
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ └── profile
│ │ │ └── AndroidManifest.xml
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ └── gradle-wrapper.properties
│ └── settings.gradle
├── ios
│ ├── Flutter
│ │ ├── AppFrameworkInfo.plist
│ │ ├── Debug.xcconfig
│ │ └── Release.xcconfig
│ ├── Podfile
│ ├── Podfile.lock
│ ├── Runner.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ └── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ └── xcschemes
│ │ │ └── Runner.xcscheme
│ ├── Runner.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ ├── IDEWorkspaceChecks.plist
│ │ │ └── WorkspaceSettings.xcsettings
│ └── Runner
│ │ ├── AppDelegate.swift
│ │ ├── Assets.xcassets
│ │ ├── AppIcon.appiconset
│ │ │ ├── Contents.json
│ │ │ ├── Icon-App-1024x1024@1x.png
│ │ │ ├── Icon-App-20x20@1x.png
│ │ │ ├── Icon-App-20x20@2x.png
│ │ │ ├── Icon-App-20x20@3x.png
│ │ │ ├── Icon-App-29x29@1x.png
│ │ │ ├── Icon-App-29x29@2x.png
│ │ │ ├── Icon-App-29x29@3x.png
│ │ │ ├── Icon-App-40x40@1x.png
│ │ │ ├── Icon-App-40x40@2x.png
│ │ │ ├── Icon-App-40x40@3x.png
│ │ │ ├── Icon-App-60x60@2x.png
│ │ │ ├── Icon-App-60x60@3x.png
│ │ │ ├── Icon-App-76x76@1x.png
│ │ │ ├── Icon-App-76x76@2x.png
│ │ │ └── Icon-App-83.5x83.5@2x.png
│ │ └── LaunchImage.imageset
│ │ │ ├── Contents.json
│ │ │ ├── LaunchImage.png
│ │ │ ├── LaunchImage@2x.png
│ │ │ ├── LaunchImage@3x.png
│ │ │ └── README.md
│ │ ├── Base.lproj
│ │ ├── LaunchScreen.storyboard
│ │ └── Main.storyboard
│ │ ├── Info.plist
│ │ └── Runner-Bridging-Header.h
├── lib
│ └── main.dart
├── pubspec.lock
├── pubspec.yaml
└── test
│ └── widget_test.dart
├── flutter_vk_sdk.iml
├── ios
├── .gitignore
├── Assets
│ └── .gitkeep
├── Classes
│ ├── FlutterVKSdkPlugin.h
│ ├── FlutterVKSdkPlugin.m
│ └── SwiftFlutterVKSdkPlugin.swift
└── flutter_vk_sdk.podspec
├── lib
├── flutter_vk_sdk.dart
├── models
│ ├── attachment.dart
│ └── vk_access_token.dart
├── ui
│ ├── vk_share_page.dart
│ └── vk_theme.dart
├── utils
│ └── share_utils.dart
├── vk_api
│ ├── photos.dart
│ ├── video.dart
│ ├── vk_api.dart
│ └── wall.dart
├── vk_method_call.dart
├── vk_response_parser.dart
└── vk_scope.dart
├── pubspec.lock
├── pubspec.yaml
└── test
└── flutter_vk_sdk_test.dart
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .dart_tool/
3 |
4 | .packages
5 | .pub/
6 |
7 | build/
8 |
9 | .idea/
10 |
--------------------------------------------------------------------------------
/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled and should not be manually edited.
5 |
6 | version:
7 | revision: 7a4c33425ddd78c54aba07d86f3f9a4a0051769b
8 | channel: stable
9 |
10 | project_type: plugin
11 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## 0.1.0
2 |
3 | * kotlin update to 1.3.50
4 | * gradle update to 3.5.0
5 |
6 | ## 0.0.1
7 |
8 | * TODO: Describe initial release.
9 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | TODO: Add your license here.
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # flutter_vk_sdk
2 |
3 | [](https://pub.dev/packages/flutter_vk_sdk)
4 |
5 | Flutter vk sdk project.
6 |
7 | This plugin is based on:
8 | - Android: [vk-android-sdk v2.1.0](https://github.com/VKCOM/vk-android-sdk/tree/2.1.0)
9 | - iOS: [vk-ios-sdk](https://github.com/VKCOM/vk-ios-sdk)
10 |
11 | ## Installation
12 |
13 | First, add [*`flutter_vk_sdk`*](https://pub.dev/packages/flutter_vk_sdk#-installing-tab-) as a dependency in [your pubspec.yaml file](https://flutter.io/platform-plugins/).
14 |
15 | ```
16 | flutter_vk_sdk: ^0.0.6+4
17 | ```
18 |
19 | ### Android
20 |
21 | In your android res/values create strings.xml and fill with this examples
22 | ```xml
23 |
24 |
25 | YOUR_VK_APP_ID
26 |
27 | ```
28 |
29 | ### iOS
30 |
31 | * AppDelegate
32 | ```
33 | import UIKit
34 | import Flutter
35 | import VK_ios_sdk
36 |
37 | @UIApplicationMain
38 | @objc class AppDelegate: FlutterAppDelegate {
39 | override func application(
40 | _ application: UIApplication,
41 | didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
42 | ) -> Bool {
43 | GeneratedPluginRegistrant.register(with: self)
44 | return super.application(application, didFinishLaunchingWithOptions: launchOptions)
45 | }
46 |
47 | override func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
48 | VKSdk.processOpen(url, fromApplication: "")
49 | return true
50 | }
51 | }
52 | ```
53 |
54 | * info.plist
55 | ```
56 | CFBundleURLTypes
57 |
58 |
59 | CFBundleTypeRole
60 | Editor
61 | CFBundleURLName
62 | vk{YOUR_APP_ID}
63 | CFBundleURLSchemes
64 |
65 | vk{YOUR_APP_ID}
66 |
67 |
68 |
69 |
70 |
71 | LSApplicationQueriesSchemes
72 |
73 | vk
74 | vk-share
75 | vkauthorize
76 |
77 | ```
78 |
79 | ## Dart usage
80 |
--------------------------------------------------------------------------------
/android/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | group 'com.kf.flutter_vk_sdk'
2 | version '1.0-SNAPSHOT'
3 |
4 | buildscript {
5 | ext.kotlin_version = '1.3.50'
6 | repositories {
7 | google()
8 | jcenter()
9 | }
10 |
11 | dependencies {
12 | classpath 'com.android.tools.build:gradle:3.5.0'
13 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14 | }
15 | }
16 |
17 | rootProject.allprojects {
18 | repositories {
19 | google()
20 | jcenter()
21 | }
22 | }
23 |
24 | apply plugin: 'com.android.library'
25 | apply plugin: 'kotlin-android'
26 |
27 | android {
28 | compileSdkVersion 28
29 |
30 | sourceSets {
31 | main.java.srcDirs += 'src/main/kotlin'
32 | }
33 | defaultConfig {
34 | minSdkVersion 16
35 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
36 | }
37 | lintOptions {
38 | disable 'InvalidPackage'
39 | }
40 | }
41 |
42 | dependencies {
43 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
44 | implementation 'com.vk:androidsdk:2.1.0'
45 | }
46 |
--------------------------------------------------------------------------------
/android/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Xmx1536M
2 |
--------------------------------------------------------------------------------
/android/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'flutter_vk_sdk'
2 |
--------------------------------------------------------------------------------
/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/android/src/main/kotlin/com/kf/flutter_vk_sdk/FlutterVKApiDelegate.kt:
--------------------------------------------------------------------------------
1 | package com.kf.flutter_vk_sdk
2 |
3 | import android.net.Uri
4 | import android.util.Log
5 |
6 | import io.flutter.plugin.common.MethodChannel
7 |
8 | import com.vk.api.sdk.*
9 | import com.vk.api.sdk.exceptions.VKApiExecutionException
10 | import com.vk.api.sdk.internal.ApiCommand
11 |
12 | class FlutterVKApiDelegate {
13 |
14 | private fun finishWithResult(result: MethodChannel.Result, value: String) {
15 | Log.d("VK API DELEGATE", "___________________SET RESULT: $value")
16 | result.success(value)
17 | }
18 |
19 | private fun finishWithError(result: MethodChannel.Result, methodName: String, error: VKApiExecutionException) {
20 | val code = FlutterVKResults.getErrorCode(methodName)
21 | val message = error.errorMsg
22 | val detail = FlutterVKResults.error(error)
23 | Log.d("VK API DELEGATE", "___________________SET ERROR: $code $message $detail")
24 | result.error(code, message, detail)
25 | }
26 |
27 | fun apiMethodCall(arguments: Map, _result: MethodChannel.Result) {
28 | val methodName: String = arguments["method"] as String
29 | Log.d("VK API DELEGATE", "___________________METHOD: $methodName")
30 | var args: Map? = null
31 | if (arguments.containsKey("arguments")) args = arguments["arguments"] as Map
32 | var retryCount: Int? = null
33 | if (arguments.containsKey("retry_count")) retryCount = arguments["retry_count"] as Int
34 | var skipValidation: Boolean? = null
35 | if (arguments.containsKey("skip_validation")) skipValidation = arguments["skip_validation"] as Boolean
36 |
37 | val command = RawApiCommand(methodName, args, retryCount, skipValidation)
38 | VK.execute(command, object : VKApiCallback {
39 | override fun success(result: String) {
40 | finishWithResult(_result, result)
41 | }
42 |
43 | override fun fail(error: VKApiExecutionException) {
44 | finishWithError(_result, methodName, error)
45 | }
46 | })
47 | }
48 |
49 | fun getPostCommandArguments(arguments: Map?): Map? {
50 | if (arguments == null) return null
51 | return arguments.map {
52 | val value = it.value.toString()
53 | if (value.startsWith("file:///")) Pair(it.key, Uri.parse(value))
54 | else Pair(it.key, value)
55 | }.toMap()
56 | }
57 |
58 | fun postMethodCall(arguments: Map, _result: MethodChannel.Result) {
59 | val url: String = arguments["url"] as String
60 | Log.d("VK API DELEGATE", "___________________POST URL: $url")
61 | var args: Map? = null
62 | if (arguments.containsKey("arguments")) args = getPostCommandArguments(arguments["arguments"] as Map)
63 | var retryCount: Int? = null
64 | if (arguments.containsKey("retry_count")) retryCount = arguments["retry_count"] as Int
65 | var timeout: Long? = null
66 | if (arguments.containsKey("timeout")) timeout = arguments["timeout"] as Long
67 | val command = RawPostCommand(url, args, retryCount, timeout)
68 | VK.execute(command, object : VKApiCallback {
69 | override fun success(result: String) {
70 | finishWithResult(_result, result)
71 | }
72 |
73 | override fun fail(error: VKApiExecutionException) {
74 | finishWithError(_result, "post_method_call", error)
75 | }
76 | })
77 | }
78 | }
79 |
80 |
81 | class RawApiCommand(private val method: String, private val args: Map?,
82 | private val retryCount: Int?, private val skipValidation: Boolean?) : ApiCommand() {
83 | companion object {
84 | const val RETRY_COUNT = 3
85 | }
86 |
87 | override fun onExecute(manager: VKApiManager): String {
88 | val callBuilder = VKMethodCall.Builder()
89 | callBuilder.method(method)
90 | callBuilder.version(manager.config.version)
91 | if (args != null) callBuilder.args(args)
92 |
93 | val retryCount = retryCount ?: RETRY_COUNT
94 | callBuilder.retryCount(retryCount)
95 | if (skipValidation != null) callBuilder.skipValidation(skipValidation)
96 |
97 | return manager.execute(callBuilder.build(), RawVKApiResponseParser())
98 | }
99 | }
100 |
101 | class RawVKApiResponseParser : VKApiResponseParser {
102 | override fun parse(response: String): String {
103 | return response
104 | }
105 | }
106 |
107 |
108 | class RawPostCommand(private val url: String, private val args: Map?,
109 | private val retryCount: Int?, private val timeout: Long?) : ApiCommand() {
110 | companion object {
111 | const val RETRY_COUNT = 3
112 | }
113 |
114 | override fun onExecute(manager: VKApiManager): String {
115 | val callBuilder = VKHttpPostCall.Builder()
116 | callBuilder.url(url)
117 | args?.forEach { (k, v) ->
118 | when (v) {
119 | is Uri -> callBuilder.args(k, v)
120 | is String -> callBuilder.args(k, v)
121 | }
122 | }
123 |
124 | val retryCount = retryCount ?: RETRY_COUNT
125 | callBuilder.retryCount(retryCount)
126 | if (timeout != null) callBuilder.timeout(timeout)
127 |
128 | return manager.execute(callBuilder.build(), null, RawVKApiResponseParser())
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/android/src/main/kotlin/com/kf/flutter_vk_sdk/FlutterVKResultDelegate.kt:
--------------------------------------------------------------------------------
1 | package com.kf.flutter_vk_sdk
2 |
3 | import android.content.Context
4 | import android.content.Intent
5 | import android.content.SharedPreferences
6 | import android.util.Log
7 |
8 | import io.flutter.plugin.common.MethodChannel
9 | import io.flutter.plugin.common.PluginRegistry
10 |
11 | import com.vk.api.sdk.auth.VKAccessToken
12 | import com.vk.api.sdk.auth.VKAuthCallback
13 | import com.vk.api.sdk.auth.VKScope
14 | import com.vk.api.sdk.exceptions.VKApiExecutionException
15 | import com.vk.api.sdk.VK
16 |
17 | class FlutterVKSdkDelegate constructor(val registrar: PluginRegistry.Registrar) : PluginRegistry.ActivityResultListener {
18 | private var loginCallback: VKAuthCallback? = null
19 | private var pendingResult: MethodChannel.Result? = null
20 |
21 | companion object {
22 | private const val VK_APP_AUTH_CODE = 282
23 | const val PREFERENCE_NAME = "com.vkontakte.android_pref_name"
24 | const val NEED_LOGIN_ERROR_MSG: String = "NEED_LOGIN"
25 | val defaultScope: Collection = emptySet()
26 | }
27 |
28 | init {
29 | registrar.addActivityResultListener(this)
30 | }
31 |
32 | fun setPendingResult(methodName: String, result: MethodChannel.Result): Boolean {
33 | if (pendingResult != null) {
34 | val message = "$methodName called while another VK operation was in progress."
35 | Log.d("VK DELEGATE", "_______________________CONFLICT ERROR: ${message}")
36 | result.error(getErrorCode("conflict"), message, null)
37 | return false
38 | }
39 | pendingResult = result
40 | return true
41 | }
42 |
43 | private fun getErrorCode(methodName: String): String {
44 | return FlutterVKResults.getErrorCode(methodName)
45 | }
46 |
47 | private fun getCanceledCode(methodName: String): String {
48 | return FlutterVKResults.getCanceledCode(methodName)
49 | }
50 |
51 | private fun clearPending() {
52 | pendingResult = null
53 | loginCallback = null
54 | }
55 |
56 | private fun finishWithResult(result: Any?) {
57 | Log.d("VK DELEGATE", "_______________________SET RESULT: ${result}")
58 | pendingResult?.success(result)
59 | clearPending()
60 | }
61 |
62 | private fun finishWithError(code: String?, message: String?, detail: Any?) {
63 | Log.d("VK DELEGATE", "_______________________SET ERROR: ${code} ${message} ${detail}")
64 | pendingResult?.error(code, message, detail)
65 | clearPending()
66 | }
67 |
68 | fun scopesFromString(scopesStr: String?): Collection {
69 | if (scopesStr == null) return defaultScope
70 | val arr = scopesStr.split(",")
71 | val scopes = arr.map {
72 | val s = it.trim()
73 | VKScope.valueOf(s.toUpperCase())
74 | }
75 | return scopes
76 | }
77 |
78 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean {
79 | if (loginCallback == null) return false
80 | var intent = data
81 | if (intent == null && requestCode == VK_APP_AUTH_CODE) intent = Intent()
82 | return VK.onActivityResult(requestCode, resultCode, intent, loginCallback!!)
83 | }
84 |
85 | // fun initialize(appId: Int, apiVersion: String) {
86 | // if (appId == 0) {
87 | // throw RuntimeException("your_app_id is not found in your resources.xml")
88 | // }
89 | //
90 | // val context = registrar.context()
91 | // VK.setConfig(VKApiConfig(
92 | // context = context,
93 | // appId = appId,
94 | // version = apiVersion,
95 | // validationHandler = VKDefaultValidationHandler(context))
96 | // )
97 | // }
98 |
99 | fun isLoggedIn(): Boolean {
100 | return VK.isLoggedIn()
101 | }
102 |
103 | fun getCurrentAccessToken(result: MethodChannel.Result) {
104 | val token = VKAccessToken.restore(getPreferences(registrar.context()))
105 | result.success(FlutterVKResults.accessToken(token))
106 | }
107 |
108 | fun login(scopes: String?, result: MethodChannel.Result) {
109 | val scopeCollection = scopesFromString(scopes)
110 | val methodName = FlutterVKSdkPlugin.LOGIN_ACTION
111 | if (!setPendingResult(methodName, result)) return
112 | loginCallback = object : VKAuthCallback {
113 | override fun onLogin(token: VKAccessToken) {
114 | finishWithResult(FlutterVKResults.successLogin(token))
115 | }
116 |
117 | override fun onLoginFailed(errorCode: Int) {
118 | val code = if (errorCode == VKAuthCallback.AUTH_CANCELED) getCanceledCode(methodName) else getErrorCode(methodName)
119 | finishWithError(code, null, null)
120 | }
121 | }
122 | VK.login(registrar.activity(), scopeCollection)
123 | }
124 |
125 | fun logout(result: MethodChannel.Result) {
126 | VK.logout()
127 | result.success(null)
128 | }
129 |
130 | fun isLoggedIn(result: MethodChannel.Result) {
131 | result.success(isLoggedIn())
132 | }
133 |
134 | fun getPreferences(context: Context): SharedPreferences = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE)
135 | }
136 |
137 | object FlutterVKResults {
138 | private const val UNKNOWN_METHOD: String = "UNKNOWN"
139 |
140 | fun getErrorCode(methodName: String): String {
141 | var name = methodName
142 | if (name.isEmpty()) name = UNKNOWN_METHOD
143 | return "${name.toLowerCase()}_error"
144 | }
145 |
146 | fun getCanceledCode(methodName: String): String {
147 | var name = methodName
148 | if (name.isEmpty()) name = UNKNOWN_METHOD
149 | return "${name.toLowerCase()}_canceled"
150 | }
151 |
152 | fun successLogin(token: VKAccessToken): Map? {
153 | return accessToken(token)
154 | }
155 |
156 | fun error(error: VKApiExecutionException): Map {
157 | val res = HashMap()
158 | res["code"] = error.code
159 | res["apiMethod"] = error.apiMethod
160 | res["hasLocalizedMessage"] = error.hasLocalizedMessage
161 | res["errorMsg"] = error.errorMsg
162 | res["detailMessage"] = error.message
163 | if (error.extra != null) res["extra"] = error.extra.toString()
164 | if (error.executeErrors != null)
165 | res["executeErrors"] = error.executeErrors?.map { error(it) }?.joinToString(prefix = "[", postfix = "]")
166 | return res
167 | }
168 |
169 | fun accessToken(token: VKAccessToken?): Map? {
170 | if (token == null) return null
171 | return mapOf(
172 | "token" to token.accessToken,
173 | "userId" to token.userId,
174 | "secret" to token.secret,
175 | "email" to token.email,
176 | "phone" to token.phone,
177 | "phoneAccessKey" to token.phoneAccessKey,
178 | "created" to token.created
179 | )
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/android/src/main/kotlin/com/kf/flutter_vk_sdk/FlutterVKSdkPlugin.kt:
--------------------------------------------------------------------------------
1 | package com.kf.flutter_vk_sdk
2 |
3 | import android.util.Log
4 |
5 | import io.flutter.plugin.common.MethodCall
6 | import io.flutter.plugin.common.MethodChannel
7 | import io.flutter.plugin.common.MethodChannel.MethodCallHandler
8 | import io.flutter.plugin.common.MethodChannel.Result
9 | import io.flutter.plugin.common.PluginRegistry.Registrar
10 |
11 | class FlutterVKSdkPlugin : MethodCallHandler {
12 |
13 | private var delegate: FlutterVKSdkDelegate
14 | private var apiDelegate: FlutterVKApiDelegate
15 |
16 | constructor(registrar: Registrar) {
17 | Log.d("VK PLUGIN", "_________________________CALL CONSTRUCTOR")
18 | delegate = FlutterVKSdkDelegate(registrar)
19 | apiDelegate = FlutterVKApiDelegate()
20 | }
21 |
22 | companion object {
23 | private const val CHANNEL_NAME: String = "com.fb.fluttervksdk/vk"
24 | const val APP_ID_ARGUMENT: String = "app_id"
25 | const val API_VERSION_ARGUMENT: String = "api_version"
26 | const val SCOPE_ARGUMENT: String = "scope"
27 |
28 | const val INITIALIZE_ACTION: String = "initialize"
29 | const val IS_LOGGED_IN_ACTION: String = "is_logged_in"
30 | const val LOGIN_ACTION: String = "login"
31 | const val LOGOUT_ACTION: String = "logout"
32 | const val GET_ACCESS_TOKEN_ACTION: String = "get_access_token"
33 | const val API_ACTION: String = "api_method_call"
34 | const val POST_ACTION: String = "post_method_call"
35 |
36 | @JvmStatic
37 | fun registerWith(registrar: Registrar) {
38 | val channel = MethodChannel(registrar.messenger(), CHANNEL_NAME)
39 | channel.setMethodCallHandler(FlutterVKSdkPlugin(registrar))
40 | }
41 | }
42 |
43 | override fun onMethodCall(call: MethodCall, result: Result) {
44 | Log.d("VK PLUGIN", "_________________________CALL METHOD: ${call.method}")
45 | when (call.method) {
46 | // INITIALIZE_ACTION -> {
47 | // val appIdArg: String? = call.argument(APP_ID_ARGUMENT)
48 | // val appId = appIdArg?.toInt() ?: 0
49 | // val apiVersion: String = call.argument(API_VERSION_ARGUMENT) ?: ""
50 | // delegate.initialize(appId, apiVersion)
51 | // result.success(null)
52 | // }
53 | LOGIN_ACTION -> {
54 | val scope: String? = call.argument(SCOPE_ARGUMENT)
55 | delegate.login(scope, result)
56 | }
57 | LOGOUT_ACTION -> {
58 | delegate.logout(result)
59 | }
60 | IS_LOGGED_IN_ACTION -> {
61 | delegate.isLoggedIn(result)
62 | }
63 | GET_ACCESS_TOKEN_ACTION -> {
64 | delegate.getCurrentAccessToken(result)
65 | }
66 | API_ACTION -> {
67 | val arguments = call.arguments