From c9d8a3ea771ffe6b93b81b7f3475af83e2fb1a40 Mon Sep 17 00:00:00 2001 From: Meng Li Date: Sat, 10 Oct 2020 23:51:26 +0900 Subject: [PATCH 1/4] Load avatar --- demoapp/build.gradle | 11 ++++++++++- .../mushare/demoapp/ui/login/ProfileActivity.kt | 17 ++++++++++------- .../src/main/res/layout/activity_profile.xml | 16 +++++++++++++--- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/demoapp/build.gradle b/demoapp/build.gradle index d4ccf4e..356a6e3 100644 --- a/demoapp/build.gradle +++ b/demoapp/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: "kotlin-kapt" android { compileSdkVersion 29 @@ -13,7 +14,7 @@ android { defaultConfig { applicationId "com.mushare.demoapp" - minSdkVersion 16 + minSdkVersion 19 targetSdkVersion 29 versionCode 1 versionName "1.0" @@ -30,6 +31,11 @@ android { } +repositories { + jcenter() + maven { url "https://jitpack.io" } //Make sure to add this in your project for uCrop +} + dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" @@ -39,6 +45,9 @@ dependencies { implementation 'androidx.annotation:annotation:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' + implementation 'com.github.dhaval2404:imagepicker:1.7.5' + implementation 'com.github.bumptech.glide:glide:4.11.0' + kapt 'com.github.bumptech.glide:compiler:4.11.0' testImplementation 'junit:junit:4.13' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' diff --git a/demoapp/src/main/java/com/mushare/demoapp/ui/login/ProfileActivity.kt b/demoapp/src/main/java/com/mushare/demoapp/ui/login/ProfileActivity.kt index 80e9432..bbf3a16 100644 --- a/demoapp/src/main/java/com/mushare/demoapp/ui/login/ProfileActivity.kt +++ b/demoapp/src/main/java/com/mushare/demoapp/ui/login/ProfileActivity.kt @@ -2,11 +2,9 @@ package com.mushare.demoapp.ui.login; import android.os.Bundle import android.util.Log -import android.widget.Button -import android.widget.EditText -import android.widget.TextView -import android.widget.Toast +import android.widget.* import androidx.appcompat.app.AppCompatActivity +import com.bumptech.glide.Glide import com.mushare.demoapp.R import com.mushare.plutosdk.Pluto import com.mushare.plutosdk.getToken @@ -21,16 +19,21 @@ class ProfileActivity : AppCompatActivity() { } private lateinit var nameEditText: WeakReference + private lateinit var avatarImageView: WeakReference override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_profile) - nameEditText = WeakReference(findViewById(R.id.profile_name)) + nameEditText = WeakReference(findViewById(R.id.profile_name)) + avatarImageView = WeakReference(findViewById(R.id.profile_avatar)) - Pluto.getInstance()?.myInfo(success = { - nameEditText.get()?.setText(it.name) + Pluto.getInstance()?.myInfo(success = { user -> + nameEditText.get()?.setText(user.name) + avatarImageView.get()?.let { + Glide.with(this).load(user.avatar).into(it) + } }) Pluto.getInstance()?.getToken(completion = { diff --git a/demoapp/src/main/res/layout/activity_profile.xml b/demoapp/src/main/res/layout/activity_profile.xml index 8c94c96..218dad5 100644 --- a/demoapp/src/main/res/layout/activity_profile.xml +++ b/demoapp/src/main/res/layout/activity_profile.xml @@ -4,12 +4,22 @@ android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"> + + @@ -20,7 +30,7 @@ android:layout_height="wrap_content" app:layout_constraintTop_toBottomOf="@id/profile_name" android:layout_marginStart="20dp" - android:layout_marginTop="10dp" + android:layout_marginTop="20dp" android:layout_marginEnd="20dp" android:text="Update Username" /> @@ -31,7 +41,7 @@ android:layout_height="wrap_content" app:layout_constraintTop_toBottomOf="@id/profile_update_name" android:layout_marginStart="20dp" - android:layout_marginTop="10dp" + android:layout_marginTop="0dp" android:layout_marginEnd="20dp" android:text="Refresh Token"/> From 9d7b1066e5000e862ce735337ade609df439fce9 Mon Sep 17 00:00:00 2001 From: Meng Li Date: Sun, 11 Oct 2020 00:50:04 +0900 Subject: [PATCH 2/4] Add image picker --- demoapp/build.gradle | 1 + demoapp/src/main/AndroidManifest.xml | 3 ++- .../demoapp/ui/login/ProfileActivity.kt | 27 +++++++++++++++++++ .../src/main/res/layout/activity_profile.xml | 15 +++++++++-- 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/demoapp/build.gradle b/demoapp/build.gradle index 356a6e3..d78ddfd 100644 --- a/demoapp/build.gradle +++ b/demoapp/build.gradle @@ -46,6 +46,7 @@ dependencies { implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' implementation 'com.github.dhaval2404:imagepicker:1.7.5' + implementation 'com.github.florent37:inline-activity-result-kotlin:1.0.4' implementation 'com.github.bumptech.glide:glide:4.11.0' kapt 'com.github.bumptech.glide:compiler:4.11.0' testImplementation 'junit:junit:4.13' diff --git a/demoapp/src/main/AndroidManifest.xml b/demoapp/src/main/AndroidManifest.xml index 8a91dc4..9fd7c18 100644 --- a/demoapp/src/main/AndroidManifest.xml +++ b/demoapp/src/main/AndroidManifest.xml @@ -10,7 +10,8 @@ android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" - android:theme="@style/AppTheme"> + android:theme="@style/AppTheme" + android:requestLegacyExternalStorage="true"> diff --git a/demoapp/src/main/java/com/mushare/demoapp/ui/login/ProfileActivity.kt b/demoapp/src/main/java/com/mushare/demoapp/ui/login/ProfileActivity.kt index bbf3a16..e0681e3 100644 --- a/demoapp/src/main/java/com/mushare/demoapp/ui/login/ProfileActivity.kt +++ b/demoapp/src/main/java/com/mushare/demoapp/ui/login/ProfileActivity.kt @@ -1,15 +1,21 @@ package com.mushare.demoapp.ui.login; +import android.app.Activity +import android.graphics.Bitmap +import android.graphics.BitmapFactory import android.os.Bundle +import android.util.Base64 import android.util.Log import android.widget.* import androidx.appcompat.app.AppCompatActivity import com.bumptech.glide.Glide +import com.github.dhaval2404.imagepicker.ImagePicker import com.mushare.demoapp.R import com.mushare.plutosdk.Pluto import com.mushare.plutosdk.getToken import com.mushare.plutosdk.myInfo import com.mushare.plutosdk.updateName +import java.io.ByteArrayOutputStream import java.lang.ref.WeakReference class ProfileActivity : AppCompatActivity() { @@ -40,6 +46,27 @@ class ProfileActivity : AppCompatActivity() { findViewById(R.id.profile_access_token).text = it ?: "Refresh failed" }) + findViewById