-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8c47272
Showing
52 changed files
with
2,822 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
# From: https://github.com/cashapp/sqldelight | ||
|
||
# The website is built using MkDocs with the Material theme. | ||
# https://squidfunk.github.io/mkdocs-material/ | ||
# It requires Python to run. | ||
# Install the packages with the following command: | ||
# pip install mkdocs mkdocs-material | ||
|
||
PROJECT_NAME='VK SDK Android' | ||
|
||
# Should be changed after each major and minor release. | ||
# Also, previous docs subdirectory should be added to .gitignore file. | ||
CURRENT_VERSION_DOCS_DIR_PREFIX='0.0' | ||
|
||
set -ex | ||
|
||
# Generate the API docs | ||
./gradlew dokka | ||
|
||
# Dokka filenames like `-http-url/index.md` don't work well with MkDocs <title> tags. | ||
# Assign metadata to the file's first Markdown heading. | ||
# https://www.mkdocs.org/user-guide/writing-your-docs/#meta-data | ||
title_markdown_file() { | ||
TITLE_PATTERN="s/^[#]+ *(.*)/title: \1 - $PROJECT_NAME/" | ||
echo "---" > "$1.fixed" | ||
# shellcheck disable=SC2129 | ||
# shellcheck disable=SC2002 | ||
cat "$1" | sed -E "$TITLE_PATTERN" | grep "title: " | head -n 1 >> "$1.fixed" | ||
echo "---" >> "$1.fixed" | ||
echo >> "$1.fixed" | ||
cat "$1" >> "$1.fixed" | ||
mv "$1.fixed" "$1" | ||
} | ||
|
||
set +x | ||
# shellcheck disable=SC2044 | ||
for MARKDOWN_FILE in $(find docs/$CURRENT_VERSION_DOCS_DIR_PREFIX.x -name '*.md'); do | ||
echo "$MARKDOWN_FILE" | ||
title_markdown_file "$MARKDOWN_FILE" | ||
done | ||
set -x | ||
|
||
# Copy in special files that GitHub wants in the project root. | ||
cp README.md docs/index.md | ||
cp auth/CHANGELOG.md docs/changelog-auth.md | ||
|
||
# Project README.md is also used as the main page for the docs, | ||
# but all links are relative, so we must fix it when copying | ||
sed -i -e 's+docs/images+images+g' docs/index.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Documentation | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
deploy-website: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout the repo | ||
uses: actions/checkout@v2 | ||
|
||
- name: Prepare mkdocs | ||
run: .github/workflows/docs_prepare.sh | ||
|
||
- name: Deploy documentation | ||
uses: mhausenblas/mkdocs-deploy-gh-pages@master | ||
env: | ||
PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }} | ||
|
||
env: | ||
GRADLE_OPTS: -Dorg.gradle.configureondemand=true -Dorg.gradle.parallel=true -Dkotlin.incremental=false -Dorg.gradle.jvmargs="-Xmx3g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- '*' | ||
|
||
jobs: | ||
macos-build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout the repo | ||
uses: actions/checkout@v2 | ||
- name: Publish the artifacts for Android | ||
env: | ||
ORG_GRADLE_PROJECT_SONATYPE_NEXUS_USERNAME: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPE_NEXUS_USERNAME }} | ||
ORG_GRADLE_PROJECT_SONATYPE_NEXUS_PASSWORD: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPE_NEXUS_PASSWORD }} | ||
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.ORG_GRADLE_PROJECT_signingKey }} | ||
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.ORG_GRADLE_PROJECT_signingPassword }} | ||
run: ./gradlew uploadArchives --no-daemon | ||
|
||
env: | ||
GRADLE_OPTS: -Dorg.gradle.configureondemand=true -Dorg.gradle.parallel=false -Dkotlin.incremental=false -Dorg.gradle.jvmargs="-Xmx3g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# ItelliJ, Gradle | ||
build | ||
.gradle | ||
.idea | ||
*.iml | ||
local.properties | ||
|
||
# MacOS | ||
.DS_Store | ||
|
||
# Docs | ||
/docs/0.0.x | ||
/docs/index.md | ||
/docs/changelog-auth.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Peter Samokhin | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# VK SDK Android | ||
![cover](docs/images/android_cover.png) | ||
|
||
<p align="center">Some Android-specific features built into Unofficial VK SDK for Android</p> | ||
|
||
--- | ||
|
||
![Build](https://github.com/vksdk/vk-sdk-android/workflows/Release/badge.svg) ![Documentation](https://github.com/vksdk/vk-sdk-android/workflows/Documentation/badge.svg) [![Kotlin 1.3.72](https://img.shields.io/badge/Kotlin-1.3.72-blue.svg?style=flat)](http://kotlinlang.org) [![API version](https://img.shields.io/badge/API%20version-5.103-blue?style=flat&logo=vk&logoColor=white)](https://vk.com/dev/versions) | ||
[![GitHub license](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat)](https://github.com/vksdk/vk-sdk-android/blob/master/LICENSE) | ||
|
||
The official VK Android SDK is monstrous, has poor API, does not contain some important features and their code leaves much to be desired. | ||
This is the reason why this SDK is created. | ||
See the available features below. | ||
|
||
See the documentation: [https://vksdk.github.io/vk-sdk-android](https://vksdk.github.io/vk-sdk-android) | ||
|
||
Latest versions: [![maven-central](https://img.shields.io/badge/Maven%20Central-0.0.1-yellowgreen?style=flat)](https://search.maven.org/search?q=g:com.petersamokhin.vksdk.android) | ||
|
||
## Authorize | ||
[![Android minSdkVersion](https://img.shields.io/badge/minSdkVersion-16-yellowgreen)](https://img.shields.io/badge/minSdkVersion-16-yellowgreen) [![Android targetSdkVersion](https://img.shields.io/badge/targetSdkVersion-29-green)](https://img.shields.io/badge/targetSdkVersion-29-green) | ||
|
||
[Authorization code flow](https://vk.com/dev/authcode_flow_user) is not supported by the official VK SDK and by the official app. | ||
But it is supported by this auth feature. | ||
|
||
Easiest way to authorize user with VK and get the token: | ||
|
||
```kotlin | ||
// From here: https://vk.com/apps?act=manage | ||
// Choose the app and get the ID from here: https://vk.com/editapp?id=XXX | ||
// Or go here: https://vk.com/editapp?id=XXX§ion=options and see the App ID | ||
val appId = 1 | ||
val scopes = listOf(VkAuth.Scope.Offline, VkAuth.Scope.Email) | ||
|
||
VkAuth.login(activity, appId, VkAuth.ResponseType.AccessToken, scopes) { result -> | ||
when (result) { | ||
is VkAuthResult.AccessToken -> { | ||
// do something with result.accessToken | ||
} | ||
is VkAuthResult.Error -> { | ||
// do something with result.error | ||
} | ||
} | ||
} | ||
``` | ||
|
||
For other information and for details, see the documentation: [https://vksdk.github.io/vk-sdk-android/auth/](https://vksdk.github.io/vk-sdk-android/auth/) | ||
|
||
## License | ||
See the [License](https://github.com/vksdk/vk-sdk-android/blob/master/LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Releasing | ||
|
||
1. Change the version in `gradle.properties` to a non-SNAPSHOT verson. | ||
2. Update the `CHANGELOG.md` for the impending release. | ||
3. Update the `README.md` with the new version. | ||
4. `git commit -am "Prepare for release X.Y.Z."` (where X.Y.Z is the new version) | ||
5. `git tag -a X.Y.Z -m "Version X.Y.Z"` (where X.Y.Z is the new version) | ||
6. Update the `gradle.properties` to the next SNAPSHOT version. | ||
7. `git push && git push --tags` | ||
8. Wait until the "Publish a release" action completes, then visit [Sonatype Nexus](https://oss.sonatype.org/) and promote the artifacts. | ||
9. Update the sample app to the release version and send a PR. | ||
|
||
If some step fails, drop the Sonatype repo, fix the problem, commit, and start again at step 5. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Change log | ||
|
||
Version 0.0.1 *(2020-04-27)* | ||
---------------------------- | ||
|
||
First release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
plugins { | ||
id("com.android.library") | ||
kotlin("android") | ||
kotlin("android.extensions") | ||
id("kotlin-android") | ||
id("kotlin-android-extensions") | ||
} | ||
|
||
android { | ||
compileSdkVersion(Config.Android.compileSdk) | ||
defaultConfig { | ||
minSdkVersion(Config.Android.minSdk) | ||
targetSdkVersion(Config.Android.compileSdk) | ||
buildToolsVersion(Config.Android.buildToolsVersion) | ||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
|
||
// applicationId = "${project.property("GROUP").toString()}.auth" | ||
versionCode = 1 | ||
versionName = "0.0.1" | ||
} | ||
buildTypes { | ||
getByName("release") { | ||
isMinifyEnabled = false | ||
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") | ||
consumerProguardFile("consumer-rules.pro") | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = JavaVersion.VERSION_1_8.toString() | ||
} | ||
sourceSets { | ||
val main by getting {} | ||
val test by getting {} | ||
val androidTest by getting {} | ||
main.java.srcDirs("src/main/kotlin") | ||
test.java.srcDirs("src/test/kotlin") | ||
androidTest.java.srcDirs("src/androidTest/kotlin") | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar")))) | ||
implementation(kotlin("stdlib-jdk8", Config.Versions.Kotlin.kotlin)) | ||
|
||
implementation("androidx.appcompat:appcompat:${Config.Versions.Android.appCompat}") | ||
implementation("androidx.core:core-ktx:${Config.Versions.Android.coreKtx}") | ||
implementation("androidx.constraintlayout:constraintlayout:${Config.Versions.Android.constraintLayout}") | ||
|
||
testImplementation("junit:junit:${Config.Versions.Test.junit}") | ||
|
||
androidTestImplementation("androidx.test:runner:${Config.Versions.AndroidTest.runner}") | ||
androidTestImplementation("androidx.test.ext:junit:${Config.Versions.AndroidTest.extJunit}") | ||
androidTestImplementation("androidx.test.espresso:espresso-core:${Config.Versions.AndroidTest.espressoCore}") | ||
androidTestImplementation("org.mockito:mockito-android:${Config.Versions.Test.mockito}") | ||
} | ||
|
||
apply(from = "$rootDir/gradle/mavenpublish.gradle") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-keep class com.petersamokhin.vksdk.android.auth.VkAuth$** { *; } | ||
-keep class com.petersamokhin.vksdk.android.model.* { *; } | ||
-keep class com.petersamokhin.vksdk.android.error.* { *; } | ||
|
||
-keepnames @kotlin.Metadata class com.petersamokhin.vksdk.android.auth.VkAuth$** | ||
-keepnames @kotlin.Metadata class com.petersamokhin.vksdk.android.model.* | ||
-keepnames @kotlin.Metadata class com.petersamokhin.vksdk.android.error.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
POM_ARTIFACT_ID=auth | ||
POM_NAME=VK SDK Android Auth | ||
POM_DESCRIPTION=VK SDK Android, module Auth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
35 changes: 35 additions & 0 deletions
35
...ndroidTest/kotlin/com/petersamokhin/vksdk/android/auth/VkAuthParamsInstrumentationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.petersamokhin.vksdk.android.auth | ||
|
||
import org.junit.Assert.* | ||
import org.junit.Test | ||
|
||
class VkAuthParamsInstrumentationTest { | ||
@Test | ||
fun shouldCorrectlyBuildBundle() { | ||
val params = VkAuth.AuthParams( | ||
1, VkAuth.ResponseType.AccessToken, "https://oauth.vk.com/blank.html", "offline" | ||
) | ||
val bundle = params.asBundle(false) | ||
|
||
assertEquals(params.clientId, bundle.getInt("client_id")) | ||
assertEquals(params.redirectUri, bundle.getString("redirect_uri")) | ||
assertEquals(params.scope, bundle.getString("scope")) | ||
assertEquals(params.revoke, bundle.getBoolean("revoke")) | ||
} | ||
|
||
@Test | ||
fun shouldCorrectlyBuildBundleWithIgnored() { | ||
val params = VkAuth.AuthParams( | ||
1, VkAuth.ResponseType.AccessToken, "https://oauth.vk.com/blank.html", "offline" | ||
) | ||
val bundle = params.asBundle(true) | ||
|
||
assertEquals(params.clientId, bundle.getInt("client_id")) | ||
assertEquals(params.redirectUri, bundle.getString("redirect_uri")) | ||
assertEquals(params.scope, bundle.getString("scope")) | ||
assertEquals(params.revoke, bundle.getBoolean("revoke")) | ||
assertEquals(params.responseType.stringValue, bundle.getString("response_type")) | ||
assertEquals(params.display.stringValue, bundle.getString("display")) | ||
assertEquals(params.state, bundle.getString("state")) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...rc/androidTest/kotlin/com/petersamokhin/vksdk/android/auth/activity/VkAuthActivityTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.petersamokhin.vksdk.android.auth.activity | ||
|
||
import android.app.Activity | ||
import com.petersamokhin.vksdk.android.auth.VkAuth | ||
import org.junit.Test | ||
import org.junit.Assert.* | ||
import org.mockito.Mockito.mock | ||
|
||
class VkAuthActivityTest { | ||
@Test | ||
fun intent() { | ||
val activity = mock(Activity::class.java) | ||
val params = VkAuth.AuthParams( | ||
1, VkAuth.ResponseType.AccessToken, "https://oauth.vk.com/blank.html", "offline" | ||
) | ||
val intent = VkAuthActivity.intent(activity, params) | ||
|
||
assertEquals(params.asQuery(), intent.getStringExtra(VkAuthActivity.EXTRA_AUTH_QUERY)) | ||
assertEquals(params.redirectUri, intent.getStringExtra(VkAuthActivity.EXTRA_AUTH_REDIRECT_URI)) | ||
} | ||
} |
Oops, something went wrong.