improved quick access icon
This commit is contained in:
parent
6498392b6e
commit
f837f8920c
|
@ -28,8 +28,6 @@ import android.graphics.Canvas
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v7.app.AlertDialog
|
import android.support.v7.app.AlertDialog
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.load.resource.drawable.GlideDrawable
|
|
||||||
import nl.komponents.kovenant.deferred
|
|
||||||
import nl.komponents.kovenant.ui.failUi
|
import nl.komponents.kovenant.ui.failUi
|
||||||
import nl.komponents.kovenant.ui.successUi
|
import nl.komponents.kovenant.ui.successUi
|
||||||
import org.mariotaku.kpreferences.get
|
import org.mariotaku.kpreferences.get
|
||||||
|
@ -46,11 +44,13 @@ import org.mariotaku.twidere.constant.profileImageStyleKey
|
||||||
import org.mariotaku.twidere.extension.applyTheme
|
import org.mariotaku.twidere.extension.applyTheme
|
||||||
import org.mariotaku.twidere.extension.loadProfileImage
|
import org.mariotaku.twidere.extension.loadProfileImage
|
||||||
import org.mariotaku.twidere.fragment.BaseDialogFragment
|
import org.mariotaku.twidere.fragment.BaseDialogFragment
|
||||||
|
import org.mariotaku.twidere.fragment.ProgressDialogFragment
|
||||||
import org.mariotaku.twidere.model.ParcelableUser
|
import org.mariotaku.twidere.model.ParcelableUser
|
||||||
import org.mariotaku.twidere.model.ParcelableUserList
|
import org.mariotaku.twidere.model.ParcelableUserList
|
||||||
import org.mariotaku.twidere.model.UserKey
|
import org.mariotaku.twidere.model.UserKey
|
||||||
import org.mariotaku.twidere.util.IntentUtils
|
import org.mariotaku.twidere.util.IntentUtils
|
||||||
import org.mariotaku.twidere.util.glide.DeferredTarget
|
import org.mariotaku.twidere.util.glide.DeferredTarget
|
||||||
|
import java.lang.ref.WeakReference
|
||||||
|
|
||||||
class CreateQuickAccessShortcutActivity : BaseActivity() {
|
class CreateQuickAccessShortcutActivity : BaseActivity() {
|
||||||
|
|
||||||
|
@ -112,6 +112,24 @@ class CreateQuickAccessShortcutActivity : BaseActivity() {
|
||||||
val extras = data.getBundleExtra(EXTRA_EXTRAS)
|
val extras = data.getBundleExtra(EXTRA_EXTRAS)
|
||||||
val accountKey = extras.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
|
val accountKey = extras.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
|
||||||
val actionType = extras.getString(EXTRA_TYPE)
|
val actionType = extras.getString(EXTRA_TYPE)
|
||||||
|
addUserRelatedShortcut(actionType, accountKey, user)
|
||||||
|
}
|
||||||
|
REQUEST_SELECT_USER_LIST -> {
|
||||||
|
if (resultCode != Activity.RESULT_OK || data == null) {
|
||||||
|
setResult(Activity.RESULT_CANCELED)
|
||||||
|
finish()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val list = data.getParcelableExtra<ParcelableUserList>(EXTRA_USER_LIST)
|
||||||
|
val extras = data.getBundleExtra(EXTRA_EXTRAS)
|
||||||
|
val accountKey = extras.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
|
||||||
|
val actionType = extras.getString(EXTRA_TYPE)
|
||||||
|
addUserListRelatedShortcut(actionType, accountKey, list)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addUserRelatedShortcut(actionType: String?, accountKey: UserKey?, user: ParcelableUser) {
|
||||||
when (actionType) {
|
when (actionType) {
|
||||||
"user_timeline" -> {
|
"user_timeline" -> {
|
||||||
val launchIntent = IntentUtils.userTimeline(accountKey, user.key,
|
val launchIntent = IntentUtils.userTimeline(accountKey, user.key,
|
||||||
|
@ -138,42 +156,37 @@ class CreateQuickAccessShortcutActivity : BaseActivity() {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
|
val displayName = userColorNameManager.getDisplayName(user, preferences[nameFirstKey])
|
||||||
|
val deferred = Glide.with(this).loadProfileImage(this, user,
|
||||||
|
shapeStyle = preferences[profileImageStyleKey], cornerRadiusRatio = 0.1f,
|
||||||
|
size = getString(R.string.profile_image_size)).into(DeferredTarget())
|
||||||
|
val weakThis = WeakReference(this)
|
||||||
|
ProgressDialogFragment.show(supportFragmentManager, TAG_LOAD_ICON_PROGRESS)
|
||||||
|
deferred.promise.successUi { drawable ->
|
||||||
|
val activity = weakThis.get() ?: return@successUi
|
||||||
val launchIntent = IntentUtils.userProfile(accountKey, user.key,
|
val launchIntent = IntentUtils.userProfile(accountKey, user.key,
|
||||||
user.screen_name, profileUrl = user.extras?.statusnet_profile_url)
|
user.screen_name, profileUrl = user.extras?.statusnet_profile_url)
|
||||||
val requestBuilder = Glide.with(this).loadProfileImage(this, user, shapeStyle = preferences[profileImageStyleKey],
|
|
||||||
cornerRadiusRatio = 0.1f, size = getString(R.string.profile_image_size))
|
|
||||||
val deferred = deferred<GlideDrawable, Exception>()
|
|
||||||
requestBuilder.into(DeferredTarget(deferred))
|
|
||||||
deferred.promise.successUi { drawable ->
|
|
||||||
val icon = Bitmap.createBitmap(drawable.intrinsicWidth,
|
val icon = Bitmap.createBitmap(drawable.intrinsicWidth,
|
||||||
drawable.intrinsicHeight, Bitmap.Config.ARGB_8888)
|
drawable.intrinsicHeight, Bitmap.Config.ARGB_8888)
|
||||||
val canvas = Canvas(icon)
|
val canvas = Canvas(icon)
|
||||||
drawable.setBounds(0, 0, icon.width, icon.height)
|
drawable.setBounds(0, 0, icon.width, icon.height)
|
||||||
drawable.draw(canvas)
|
drawable.draw(canvas)
|
||||||
setResult(Activity.RESULT_OK, Intent().apply {
|
activity.setResult(Activity.RESULT_OK, Intent().apply {
|
||||||
putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent)
|
putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent)
|
||||||
putExtra(Intent.EXTRA_SHORTCUT_ICON, icon)
|
putExtra(Intent.EXTRA_SHORTCUT_ICON, icon)
|
||||||
putExtra(Intent.EXTRA_SHORTCUT_NAME, userColorNameManager.getDisplayName(user,
|
putExtra(Intent.EXTRA_SHORTCUT_NAME, displayName)
|
||||||
preferences[nameFirstKey]))
|
|
||||||
})
|
})
|
||||||
finish()
|
activity.finish()
|
||||||
}.failUi {
|
}.failUi {
|
||||||
setResult(Activity.RESULT_CANCELED)
|
val activity = weakThis.get() ?: return@failUi
|
||||||
finish()
|
activity.setResult(Activity.RESULT_CANCELED)
|
||||||
|
activity.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
REQUEST_SELECT_USER_LIST -> {
|
|
||||||
if (resultCode != Activity.RESULT_OK || data == null) {
|
private fun addUserListRelatedShortcut(actionType: String?, accountKey: UserKey?, list: ParcelableUserList) {
|
||||||
setResult(Activity.RESULT_CANCELED)
|
|
||||||
finish()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
val list = data.getParcelableExtra<ParcelableUserList>(EXTRA_USER_LIST)
|
|
||||||
val extras = data.getBundleExtra(EXTRA_EXTRAS)
|
|
||||||
val accountKey = extras.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
|
|
||||||
val actionType = extras.getString(EXTRA_TYPE)
|
|
||||||
when (actionType) {
|
when (actionType) {
|
||||||
"list_timeline" -> {
|
"list_timeline" -> {
|
||||||
val launchIntent = IntentUtils.userListTimeline(accountKey, list.id,
|
val launchIntent = IntentUtils.userListTimeline(accountKey, list.id,
|
||||||
|
@ -198,8 +211,6 @@ class CreateQuickAccessShortcutActivity : BaseActivity() {
|
||||||
}
|
}
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun onItemSelected(which: Int) {
|
private fun onItemSelected(which: Int) {
|
||||||
val actionType = resources.getStringArray(R.array.values_quick_access_shortcut_types)[which]
|
val actionType = resources.getStringArray(R.array.values_quick_access_shortcut_types)[which]
|
||||||
|
@ -231,4 +242,8 @@ class CreateQuickAccessShortcutActivity : BaseActivity() {
|
||||||
activity?.finish()
|
activity?.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val TAG_LOAD_ICON_PROGRESS = "load_icon_progress"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,19 +23,23 @@ import android.graphics.drawable.Drawable
|
||||||
import com.bumptech.glide.request.animation.GlideAnimation
|
import com.bumptech.glide.request.animation.GlideAnimation
|
||||||
import com.bumptech.glide.request.target.SimpleTarget
|
import com.bumptech.glide.request.target.SimpleTarget
|
||||||
import nl.komponents.kovenant.Deferred
|
import nl.komponents.kovenant.Deferred
|
||||||
|
import nl.komponents.kovenant.Promise
|
||||||
|
import nl.komponents.kovenant.deferred
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mariotaku on 2017/3/21.
|
* Created by mariotaku on 2017/3/21.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class DeferredTarget<R>(val deferred: Deferred<R, Exception>) : SimpleTarget<R>() {
|
class DeferredTarget<R>(private val deferredInstance: Deferred<R, Exception> = deferred()) : SimpleTarget<R>() {
|
||||||
|
|
||||||
|
val promise: Promise<R, Exception> get() = deferredInstance.promise
|
||||||
|
|
||||||
override fun onLoadFailed(e: Exception, errorDrawable: Drawable?) {
|
override fun onLoadFailed(e: Exception, errorDrawable: Drawable?) {
|
||||||
deferred.reject(e)
|
deferredInstance.reject(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResourceReady(resource: R, glideAnimation: GlideAnimation<in R>) {
|
override fun onResourceReady(resource: R, glideAnimation: GlideAnimation<in R>) {
|
||||||
deferred.resolve(resource)
|
deferredInstance.resolve(resource)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue