improved shortcuts

This commit is contained in:
Mariotaku Lee 2017-08-27 01:29:20 +08:00
parent 16e1d2b977
commit 2d9e380353
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
84 changed files with 468 additions and 253 deletions

View File

@ -390,7 +390,7 @@
</intent-filter>
</activity>
<activity
android:name=".activity.shortcut.CreateComposeShortcutActivity"
android:name=".activity.shortcut.ComposeShortcutCreatorActivity"
android:enabled="@bool/use_legacy_widget_shortcuts"
android:icon="@mipmap/ic_shortcut_compose"
android:label="@string/title_compose"
@ -402,8 +402,31 @@
</intent-filter>
</activity>
<activity
android:name=".activity.shortcut.CreateQuickAccessShortcutActivity"
android:label="@string/title_quick_action"
android:name=".activity.shortcut.UserFavoritesShortcutCreatorActivity"
android:icon="@mipmap/ic_shortcut_favorite"
android:label="@string/title_favorites"
android:theme="@style/Theme.Twidere.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name=".activity.shortcut.UserTimelineShortcutCreatorActivity"
android:icon="@mipmap/ic_shortcut_quote"
android:label="@string/title_statuses"
android:theme="@style/Theme.Twidere.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name=".activity.shortcut.UserShortcutCreatorActivity"
android:icon="@mipmap/ic_shortcut_user"
android:label="@string/title_user"
android:theme="@style/Theme.Twidere.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT"/>

View File

@ -0,0 +1,98 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.activity.shortcut
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.support.v4.content.pm.ShortcutInfoCompat
import android.support.v4.content.pm.ShortcutManagerCompat
import nl.komponents.kovenant.Promise
import nl.komponents.kovenant.combine.and
import nl.komponents.kovenant.ui.alwaysUi
import nl.komponents.kovenant.ui.failUi
import nl.komponents.kovenant.ui.successUi
import org.mariotaku.twidere.TwidereConstants.*
import org.mariotaku.twidere.activity.AccountSelectorActivity
import org.mariotaku.twidere.activity.BaseActivity
import org.mariotaku.twidere.extension.dismissProgressDialog
import org.mariotaku.twidere.extension.showProgressDialog
import org.mariotaku.twidere.model.UserKey
import java.lang.ref.WeakReference
abstract class AbsShortcutCreatorActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (savedInstanceState != null) return
selectAccount()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
REQUEST_SELECT_ACCOUNT -> {
if (resultCode != Activity.RESULT_OK || data == null) {
setResult(Activity.RESULT_CANCELED)
finish()
return
}
val extras = data.getBundleExtra(EXTRA_EXTRAS)
val accountKey = data.getParcelableExtra<UserKey>(EXTRA_ACCOUNT_KEY) ?: run {
setResult(Activity.RESULT_CANCELED)
finish()
return
}
onAccountSelected(accountKey, extras)
}
}
}
protected abstract fun onAccountSelected(accountKey: UserKey, extras: Bundle?)
protected fun selectAccount() {
val selectAccountIntent = Intent(this, AccountSelectorActivity::class.java)
startActivityForResult(selectAccountIntent, REQUEST_SELECT_ACCOUNT)
}
protected fun addShortcut(task: () -> Promise<ShortcutInfoCompat, Exception>) {
val weakThis = WeakReference(this)
val promise = showProgressDialog(TAG_PROCESS_SHORTCUT_PROGRESS)
.and(task())
promise.successUi { (_, shortcut) ->
val activity = weakThis.get() ?: return@successUi
activity.setResult(Activity.RESULT_OK,
ShortcutManagerCompat.createShortcutResultIntent(activity, shortcut))
activity.finish()
}.failUi {
val activity = weakThis.get() ?: return@failUi
activity.setResult(Activity.RESULT_CANCELED)
activity.finish()
}.alwaysUi {
val activity = weakThis.get() ?: return@alwaysUi
activity.dismissProgressDialog(TAG_PROCESS_SHORTCUT_PROGRESS)
}
}
companion object {
private const val TAG_PROCESS_SHORTCUT_PROGRESS = "process_shortcut_progress"
}
}

View File

@ -0,0 +1,72 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.activity.shortcut
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import org.mariotaku.ktextension.Bundle
import org.mariotaku.ktextension.set
import org.mariotaku.twidere.TwidereConstants.*
import org.mariotaku.twidere.activity.UserListSelectorActivity
import org.mariotaku.twidere.model.ParcelableUserList
import org.mariotaku.twidere.model.UserKey
/**
* Created by mariotaku on 2017/8/26.
*/
abstract class AbsUserListRelatedShortcutCreatorActivity : AbsShortcutCreatorActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
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)
onUserListSelected(accountKey, list)
}
else -> {
super.onActivityResult(requestCode, resultCode, data)
}
}
}
override final fun onAccountSelected(accountKey: UserKey, extras: Bundle?) {
val selectUserListIntent = Intent(this, UserListSelectorActivity::class.java)
selectUserListIntent.putExtra(EXTRA_ACCOUNT_KEY, accountKey)
selectUserListIntent.putExtra(EXTRA_SHOW_MY_LISTS, true)
selectUserListIntent.putExtra(EXTRA_EXTRAS, Bundle {
this[EXTRA_ACCOUNT_KEY] = accountKey
})
startActivityForResult(selectUserListIntent, REQUEST_SELECT_USER_LIST)
}
protected abstract fun onUserListSelected(accountKey: UserKey?, userList: ParcelableUserList)
}

View File

@ -0,0 +1,66 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.activity.shortcut
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import org.mariotaku.ktextension.Bundle
import org.mariotaku.ktextension.set
import org.mariotaku.twidere.TwidereConstants.*
import org.mariotaku.twidere.activity.UserSelectorActivity
import org.mariotaku.twidere.model.ParcelableUser
import org.mariotaku.twidere.model.UserKey
/**
* Created by mariotaku on 2017/8/26.
*/
abstract class AbsUserRelatedShortcutCreatorActivity : AbsShortcutCreatorActivity() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
REQUEST_SELECT_USER -> {
if (resultCode != Activity.RESULT_OK || data == null) {
setResult(Activity.RESULT_CANCELED)
finish()
return
}
val user = data.getParcelableExtra<ParcelableUser>(EXTRA_USER)
val extras = data.getBundleExtra(EXTRA_EXTRAS)
val accountKey = extras.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
onUserSelected(accountKey, user)
}
else -> {
super.onActivityResult(requestCode, resultCode, data)
}
}
}
override final fun onAccountSelected(accountKey: UserKey, extras: Bundle?) {
val selectUserIntent = Intent(this, UserSelectorActivity::class.java)
selectUserIntent.putExtra(EXTRA_ACCOUNT_KEY, accountKey)
selectUserIntent.putExtra(EXTRA_EXTRAS, Bundle {
this[EXTRA_ACCOUNT_KEY] = accountKey
})
startActivityForResult(selectUserIntent, REQUEST_SELECT_USER)
}
protected abstract fun onUserSelected(accountKey: UserKey?, user: ParcelableUser)
}

View File

@ -29,7 +29,7 @@ import org.mariotaku.twidere.BuildConfig
import org.mariotaku.twidere.R
import org.mariotaku.twidere.constant.IntentConstants.INTENT_ACTION_COMPOSE
class CreateComposeShortcutActivity : Activity() {
class ComposeShortcutCreatorActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

View File

@ -1,238 +0,0 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.activity.shortcut
import android.app.Activity
import android.app.Dialog
import android.content.DialogInterface
import android.content.Intent
import android.os.Bundle
import android.support.v4.content.pm.ShortcutManagerCompat
import android.support.v7.app.AlertDialog
import nl.komponents.kovenant.combine.and
import nl.komponents.kovenant.ui.alwaysUi
import nl.komponents.kovenant.ui.failUi
import nl.komponents.kovenant.ui.successUi
import org.mariotaku.kpreferences.get
import org.mariotaku.ktextension.Bundle
import org.mariotaku.ktextension.set
import org.mariotaku.twidere.R
import org.mariotaku.twidere.TwidereConstants.*
import org.mariotaku.twidere.activity.AccountSelectorActivity
import org.mariotaku.twidere.activity.BaseActivity
import org.mariotaku.twidere.activity.UserListSelectorActivity
import org.mariotaku.twidere.activity.UserSelectorActivity
import org.mariotaku.twidere.constant.nameFirstKey
import org.mariotaku.twidere.extension.applyOnShow
import org.mariotaku.twidere.extension.applyTheme
import org.mariotaku.twidere.extension.dismissProgressDialog
import org.mariotaku.twidere.extension.showProgressDialog
import org.mariotaku.twidere.fragment.BaseDialogFragment
import org.mariotaku.twidere.model.ParcelableUser
import org.mariotaku.twidere.model.ParcelableUserList
import org.mariotaku.twidere.model.UserKey
import org.mariotaku.twidere.util.IntentUtils
import org.mariotaku.twidere.util.shortcut.ShortcutCreator
import java.lang.ref.WeakReference
class CreateQuickAccessShortcutActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (savedInstanceState == null) {
val df = QuickAccessShortcutTypeDialogFragment()
df.show(supportFragmentManager, "quick_access_shortcut_type")
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
REQUEST_SELECT_ACCOUNT -> {
if (resultCode != Activity.RESULT_OK || data == null) {
setResult(Activity.RESULT_CANCELED)
finish()
return
}
val actionType = data.getBundleExtra(EXTRA_EXTRAS)?.getString(EXTRA_TYPE)
val accountKey = data.getParcelableExtra<UserKey>(EXTRA_ACCOUNT_KEY) ?: run {
setResult(Activity.RESULT_CANCELED)
finish()
return
}
when (actionType) {
"user", "user_timeline", "user_favorites" -> {
val selectUserIntent = Intent(this, UserSelectorActivity::class.java)
selectUserIntent.putExtra(EXTRA_ACCOUNT_KEY, accountKey)
selectUserIntent.putExtra(EXTRA_EXTRAS, Bundle {
this[EXTRA_TYPE] = actionType
this[EXTRA_ACCOUNT_KEY] = accountKey
})
startActivityForResult(selectUserIntent, REQUEST_SELECT_USER)
}
"list", "list_timeline" -> {
val selectUserListIntent = Intent(this, UserListSelectorActivity::class.java)
selectUserListIntent.putExtra(EXTRA_ACCOUNT_KEY, accountKey)
selectUserListIntent.putExtra(EXTRA_SHOW_MY_LISTS, true)
selectUserListIntent.putExtra(EXTRA_EXTRAS, Bundle {
this[EXTRA_TYPE] = actionType
this[EXTRA_ACCOUNT_KEY] = accountKey
})
startActivityForResult(selectUserListIntent, REQUEST_SELECT_USER_LIST)
}
else -> {
setResult(Activity.RESULT_CANCELED)
finish()
}
}
}
REQUEST_SELECT_USER -> {
if (resultCode != Activity.RESULT_OK || data == null) {
setResult(Activity.RESULT_CANCELED)
finish()
return
}
val user = data.getParcelableExtra<ParcelableUser>(EXTRA_USER)
val extras = data.getBundleExtra(EXTRA_EXTRAS)
val accountKey = extras.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
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) {
"user_timeline" -> {
val launchIntent = IntentUtils.userTimeline(accountKey, user.key,
user.screen_name, profileUrl = user.extras?.statusnet_profile_url)
val icon = Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher)
setResult(Activity.RESULT_OK, Intent().apply {
putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent)
putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon)
putExtra(Intent.EXTRA_SHORTCUT_NAME, userColorNameManager.getDisplayName(user,
preferences[nameFirstKey]))
})
finish()
}
"user_favorites" -> {
val launchIntent = IntentUtils.userTimeline(accountKey, user.key,
user.screen_name, profileUrl = user.extras?.statusnet_profile_url)
val icon = Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher)
setResult(Activity.RESULT_OK, Intent().apply {
putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent)
putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon)
putExtra(Intent.EXTRA_SHORTCUT_NAME, userColorNameManager.getDisplayName(user,
preferences[nameFirstKey]))
})
finish()
}
else -> {
val weakThis = WeakReference(this)
val promise = showProgressDialog(TAG_LOAD_ICON_PROGRESS)
.and(ShortcutCreator.userShortcut(this, user.account_key, user))
promise.successUi { (_, shortcut) ->
val activity = weakThis.get() ?: return@successUi
activity.setResult(Activity.RESULT_OK,
ShortcutManagerCompat.createShortcutResultIntent(activity, shortcut))
activity.finish()
}.failUi {
val activity = weakThis.get() ?: return@failUi
activity.setResult(Activity.RESULT_CANCELED)
activity.finish()
}.alwaysUi {
val activity = weakThis.get() ?: return@alwaysUi
activity.dismissProgressDialog(TAG_LOAD_ICON_PROGRESS)
}
}
}
}
private fun addUserListRelatedShortcut(actionType: String?, accountKey: UserKey?, list: ParcelableUserList) {
when (actionType) {
"list_timeline" -> {
val launchIntent = IntentUtils.userListTimeline(accountKey, list.id,
list.user_key, list.user_screen_name, list.name)
val icon = Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher)
setResult(Activity.RESULT_OK, Intent().apply {
putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent)
putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon)
putExtra(Intent.EXTRA_SHORTCUT_NAME, list.name)
})
}
else -> {
val launchIntent = IntentUtils.userListDetails(accountKey, list.id,
list.user_key, list.user_screen_name, list.name)
val icon = Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher)
setResult(Activity.RESULT_OK, Intent().apply {
putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent)
putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon)
putExtra(Intent.EXTRA_SHORTCUT_NAME, list.name)
})
}
}
finish()
}
private fun onItemSelected(which: Int) {
val actionType = resources.getStringArray(R.array.values_quick_access_shortcut_types)[which]
val selectAccountIntent = Intent(this, AccountSelectorActivity::class.java)
selectAccountIntent.putExtra(EXTRA_EXTRAS, Bundle {
this[EXTRA_TYPE] = actionType
})
if (actionType == "list") {
selectAccountIntent.putExtra(EXTRA_ACCOUNT_HOST, USER_TYPE_TWITTER_COM)
}
startActivityForResult(selectAccountIntent, REQUEST_SELECT_ACCOUNT)
}
class QuickAccessShortcutTypeDialogFragment : BaseDialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val builder = AlertDialog.Builder(context)
builder.setItems(R.array.entries_quick_access_shortcut_types) { _, which ->
(activity as CreateQuickAccessShortcutActivity).onItemSelected(which)
}
return builder.create().apply {
applyOnShow { applyTheme() }
}
}
override fun onCancel(dialog: DialogInterface?) {
activity?.finish()
}
}
companion object {
private const val TAG_LOAD_ICON_PROGRESS = "load_icon_progress"
}
}

View File

@ -0,0 +1,36 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.activity.shortcut
import org.mariotaku.twidere.model.ParcelableUser
import org.mariotaku.twidere.model.UserKey
import org.mariotaku.twidere.util.shortcut.ShortcutCreator
/**
* Created by mariotaku on 2017/8/27.
*/
class UserFavoritesShortcutCreatorActivity : AbsUserRelatedShortcutCreatorActivity() {
override fun onUserSelected(accountKey: UserKey?, user: ParcelableUser) {
addShortcut { ShortcutCreator.userFavorites(this, accountKey, user) }
}
}

View File

@ -0,0 +1,36 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.activity.shortcut
import org.mariotaku.twidere.model.ParcelableUser
import org.mariotaku.twidere.model.UserKey
import org.mariotaku.twidere.util.shortcut.ShortcutCreator
/**
* Created by mariotaku on 2017/8/27.
*/
class UserShortcutCreatorActivity : AbsUserRelatedShortcutCreatorActivity() {
override fun onUserSelected(accountKey: UserKey?, user: ParcelableUser) {
addShortcut { ShortcutCreator.user(this, accountKey, user) }
}
}

View File

@ -0,0 +1,36 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.activity.shortcut
import org.mariotaku.twidere.model.ParcelableUser
import org.mariotaku.twidere.model.UserKey
import org.mariotaku.twidere.util.shortcut.ShortcutCreator
/**
* Created by mariotaku on 2017/8/27.
*/
class UserTimelineShortcutCreatorActivity : AbsUserRelatedShortcutCreatorActivity() {
override fun onUserSelected(accountKey: UserKey?, user: ParcelableUser) {
addShortcut { ShortcutCreator.userTimeline(this, accountKey, user) }
}
}

View File

@ -1042,7 +1042,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
R.id.add_to_home_screen -> {
if (!ShortcutManagerCompat.isRequestPinShortcutSupported(context)) return true
val promise = showProgressDialog(FRAGMENT_TAG_ADD_USER_SHORTCUT_TO_HOME_SCREEN)
.and(ShortcutCreator.userShortcut(context, user.account_key, user))
.and(ShortcutCreator.user(context, user.account_key, user))
val weakThis = WeakReference(this)
promise.successUi { (_, shortcut) ->
val fragment = weakThis.get() ?: return@successUi

View File

@ -32,6 +32,7 @@ import nl.komponents.kovenant.then
import org.mariotaku.kpreferences.get
import org.mariotaku.twidere.R
import org.mariotaku.twidere.annotation.ImageShapeStyle
import org.mariotaku.twidere.constant.iWantMyStarsBackKey
import org.mariotaku.twidere.constant.nameFirstKey
import org.mariotaku.twidere.constant.profileImageStyleKey
import org.mariotaku.twidere.extension.loadProfileImage
@ -51,12 +52,11 @@ object ShortcutCreator {
private const val adaptiveIconSizeDp = 108
private const val adaptiveIconOuterSidesDp = 18
fun userShortcut(context: Context, accountKey: UserKey?, user: ParcelableUser): Promise<ShortcutInfoCompat, Exception> {
fun user(context: Context, accountKey: UserKey?, user: ParcelableUser): Promise<ShortcutInfoCompat, Exception> {
val holder = DependencyHolder.get(context)
val preferences = holder.preferences
val userColorNameManager = holder.userColorNameManager
val profileImageStyle = if (useAdaptiveIcon) ImageShapeStyle.SHAPE_RECTANGLE else preferences[profileImageStyleKey]
val profileImageCornerRadiusRatio = if (useAdaptiveIcon) 0f else 0.1f
@ -67,7 +67,7 @@ object ShortcutCreator {
val weakContext = WeakReference(context)
return deferred.promise.then { drawable ->
val ctx = weakContext.get() ?: throw InterruptedException()
val builder = ShortcutInfoCompat.Builder(ctx, "user-shortcut-$accountKey-${user.key}")
val builder = ShortcutInfoCompat.Builder(ctx, "$accountKey:user:${user.key}")
builder.setIcon(drawable.toProfileImageIcon(ctx))
builder.setShortLabel(userColorNameManager.getDisplayName(user, preferences[nameFirstKey]))
val launchIntent = IntentUtils.userProfile(accountKey, user.key,
@ -77,6 +77,38 @@ object ShortcutCreator {
}
}
fun userFavorites(context: Context, accountKey: UserKey?, user: ParcelableUser): Promise<ShortcutInfoCompat, Exception> {
val holder = DependencyHolder.get(context)
val preferences = holder.preferences
val userColorNameManager = holder.userColorNameManager
val launchIntent = IntentUtils.userFavorites(accountKey, user.key,
user.screen_name, profileUrl = user.extras?.statusnet_profile_url)
val builder = ShortcutInfoCompat.Builder(context, "$accountKey:user-favorites:${user.key}")
builder.setIntent(launchIntent)
builder.setShortLabel(userColorNameManager.getDisplayName(user, preferences[nameFirstKey]))
if (preferences[iWantMyStarsBackKey]) {
builder.setIcon(IconCompat.createWithResource(context, R.mipmap.ic_shortcut_favorite))
} else {
builder.setIcon(IconCompat.createWithResource(context, R.mipmap.ic_shortcut_like))
}
return Promise.of(builder.build())
}
fun userTimeline(context: Context, accountKey: UserKey?, user: ParcelableUser): Promise<ShortcutInfoCompat, Exception> {
val holder = DependencyHolder.get(context)
val preferences = holder.preferences
val userColorNameManager = holder.userColorNameManager
val launchIntent = IntentUtils.userTimeline(accountKey, user.key,
user.screen_name, profileUrl = user.extras?.statusnet_profile_url)
val builder = ShortcutInfoCompat.Builder(context, "$accountKey:user-timeline:${user.key}")
builder.setIntent(launchIntent)
builder.setShortLabel(userColorNameManager.getDisplayName(user, preferences[nameFirstKey]))
builder.setIcon(IconCompat.createWithResource(context, R.mipmap.ic_shortcut_quote))
return Promise.of(builder.build())
}
private fun Drawable.toProfileImageIcon(context: Context): IconCompat {
if (useAdaptiveIcon) {
val density = context.resources.displayMetrics.density

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@mipmap/ic_launcher_adaptive_background"/>
<foreground android:drawable="@mipmap/ic_launcher_adaptive_foreground"/>
</adaptive-icon>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@mipmap/ic_shortcut_adaptive_background"/>
<background android:drawable="@color/bg_ic_shortcut_adaptive"/>
<foreground android:drawable="@mipmap/ic_shortcut_camera_adaptive_foreground"/>
</adaptive-icon>

View File

@ -19,6 +19,6 @@
-->
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@mipmap/ic_shortcut_adaptive_background"/>
<background android:drawable="@color/bg_ic_shortcut_adaptive"/>
<foreground android:drawable="@mipmap/ic_shortcut_compose_adaptive_foreground"/>
</adaptive-icon>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/bg_ic_shortcut_adaptive"/>
<foreground android:drawable="@mipmap/ic_shortcut_favorite_adaptive_foreground"/>
</adaptive-icon>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/bg_ic_shortcut_adaptive"/>
<foreground android:drawable="@mipmap/ic_shortcut_like_adaptive_foreground"/>
</adaptive-icon>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Twidere - Twitter client for Android
~
~ Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/bg_ic_shortcut_adaptive"/>
<foreground android:drawable="@mipmap/ic_shortcut_quote_adaptive_foreground"/>
</adaptive-icon>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Twidere - Twitter client for Android
~
~ Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/bg_ic_shortcut_adaptive"/>
<foreground android:drawable="@mipmap/ic_shortcut_user_adaptive_foreground"/>
</adaptive-icon>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 664 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 908 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 237 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1000 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 896 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 919 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 901 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 746 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 335 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 522 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 515 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 557 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 902 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

View File

@ -47,5 +47,6 @@
<color name="home_page_margin_color">#20333333</color>
<color name="bg_ic_launcher_adaptive">#85F1FF</color>
<color name="bg_ic_shortcut_adaptive">#FAFAFA</color>
</resources>