added quick action support #728
This commit is contained in:
parent
d229aa7a4f
commit
63019dad3f
|
@ -1,150 +0,0 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2015 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.util;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/3/14.
|
||||
*/
|
||||
public class LinkCreator implements Constants {
|
||||
|
||||
private static final String AUTHORITY_TWITTER = "twitter.com";
|
||||
private static final String AUTHORITY_FANFOU = "fanfou.com";
|
||||
|
||||
private LinkCreator() {
|
||||
}
|
||||
|
||||
public static Uri getTwidereStatusLink(UserKey accountKey, @NonNull String statusId) {
|
||||
final Uri.Builder builder = new Uri.Builder();
|
||||
builder.scheme(SCHEME_TWIDERE);
|
||||
builder.authority(AUTHORITY_STATUS);
|
||||
if (accountKey != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, accountKey.toString());
|
||||
}
|
||||
builder.appendQueryParameter(QUERY_PARAM_STATUS_ID, statusId);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Uri getTwidereUserLink(@Nullable UserKey accountKey, @Nullable UserKey userKey, String screenName) {
|
||||
final Uri.Builder builder = new Uri.Builder();
|
||||
builder.scheme(SCHEME_TWIDERE);
|
||||
builder.authority(AUTHORITY_USER);
|
||||
if (accountKey != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, accountKey.toString());
|
||||
}
|
||||
if (userKey != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_USER_KEY, userKey.toString());
|
||||
}
|
||||
if (screenName != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_SCREEN_NAME, screenName);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Uri getTwitterUserListLink(String userScreenName, String listName) {
|
||||
Uri.Builder builder = new Uri.Builder();
|
||||
builder.scheme(SCHEME_HTTPS);
|
||||
builder.authority(AUTHORITY_TWITTER);
|
||||
builder.appendPath(userScreenName);
|
||||
builder.appendPath(listName);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Uri getStatusWebLink(@NonNull ParcelableStatus status) {
|
||||
if (status.extras != null && !TextUtils.isEmpty(status.extras.external_url)) {
|
||||
return Uri.parse(status.extras.external_url);
|
||||
}
|
||||
if (USER_TYPE_FANFOU_COM.equals(status.account_key.getHost())) {
|
||||
return getFanfouStatusLink(status.id);
|
||||
}
|
||||
return getTwitterStatusLink(status.user_screen_name, status.id);
|
||||
}
|
||||
|
||||
public static Uri getQuotedStatusWebLink(ParcelableStatus status) {
|
||||
if (status.extras != null) {
|
||||
if (!TextUtils.isEmpty(status.extras.quoted_external_url)) {
|
||||
return Uri.parse(status.extras.quoted_external_url);
|
||||
} else if (!TextUtils.isEmpty(status.extras.external_url)) {
|
||||
return Uri.parse(status.extras.external_url);
|
||||
}
|
||||
}
|
||||
if (USER_TYPE_FANFOU_COM.equals(status.account_key.getHost())) {
|
||||
return getFanfouStatusLink(status.quoted_id);
|
||||
}
|
||||
return getTwitterStatusLink(status.quoted_user_screen_name, status.quoted_id);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Uri getUserWebLink(@NonNull ParcelableUser user) {
|
||||
if (user.extras != null && user.extras.statusnet_profile_url != null) {
|
||||
return Uri.parse(user.extras.statusnet_profile_url);
|
||||
}
|
||||
if (USER_TYPE_FANFOU_COM.equals(user.key.getHost())) {
|
||||
return getFanfouUserLink(user.key.getId());
|
||||
}
|
||||
return getTwitterUserLink(user.screen_name);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
static Uri getTwitterStatusLink(@NonNull String screenName, @NonNull String statusId) {
|
||||
Uri.Builder builder = new Uri.Builder();
|
||||
builder.scheme(SCHEME_HTTPS);
|
||||
builder.authority(AUTHORITY_TWITTER);
|
||||
builder.appendPath(screenName);
|
||||
builder.appendPath("status");
|
||||
builder.appendPath(statusId);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
static Uri getTwitterUserLink(String screenName) {
|
||||
Uri.Builder builder = new Uri.Builder();
|
||||
builder.scheme(SCHEME_HTTPS);
|
||||
builder.authority(AUTHORITY_TWITTER);
|
||||
builder.appendPath(screenName);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
static Uri getFanfouStatusLink(String id) {
|
||||
Uri.Builder builder = new Uri.Builder();
|
||||
builder.scheme(SCHEME_HTTP);
|
||||
builder.authority(AUTHORITY_FANFOU);
|
||||
builder.appendPath("statuses");
|
||||
builder.appendPath(id);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
static Uri getFanfouUserLink(String id) {
|
||||
Uri.Builder builder = new Uri.Builder();
|
||||
builder.scheme(SCHEME_HTTP);
|
||||
builder.authority(AUTHORITY_FANFOU);
|
||||
builder.appendPath(id);
|
||||
return builder.build();
|
||||
}
|
||||
}
|
|
@ -513,7 +513,7 @@ public final class Utils implements Constants {
|
|||
if (TextUtils.isEmpty(quoteFormat)) {
|
||||
quoteFormat = DEFAULT_QUOTE_FORMAT;
|
||||
}
|
||||
String result = quoteFormat.replace(FORMAT_PATTERN_LINK, LinkCreator.getStatusWebLink(status).toString());
|
||||
String result = quoteFormat.replace(FORMAT_PATTERN_LINK, LinkCreator.INSTANCE.getStatusWebLink(status).toString());
|
||||
result = result.replace(FORMAT_PATTERN_NAME, status.user_screen_name);
|
||||
result = result.replace(FORMAT_PATTERN_TEXT, status.text_plain);
|
||||
return result;
|
||||
|
|
|
@ -87,6 +87,7 @@ class UserListSelectorActivity : BaseActivity(),
|
|||
is ParcelableUserList -> {
|
||||
val data = Intent()
|
||||
data.putExtra(EXTRA_USER_LIST, item)
|
||||
data.putExtra(EXTRA_EXTRAS, intent.getBundleExtra(EXTRA_EXTRAS))
|
||||
setResult(Activity.RESULT_OK, data)
|
||||
finish()
|
||||
}
|
||||
|
|
|
@ -102,6 +102,7 @@ class UserSelectorActivity : BaseActivity(), OnItemClickListener, LoaderManager.
|
|||
val data = Intent()
|
||||
data.setExtrasClassLoader(classLoader)
|
||||
data.putExtra(EXTRA_USER, user)
|
||||
data.putExtra(EXTRA_EXTRAS, intent.getBundleExtra(EXTRA_EXTRAS))
|
||||
setResult(Activity.RESULT_OK, data)
|
||||
finish()
|
||||
}
|
||||
|
|
|
@ -31,11 +31,13 @@ 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.applyTheme
|
||||
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
|
||||
|
||||
|
@ -65,11 +67,24 @@ class CreateQuickAccessShortcutActivity : BaseActivity() {
|
|||
return
|
||||
}
|
||||
when (actionType) {
|
||||
"user" -> {
|
||||
"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_EXTRAS, Bundle {
|
||||
this[EXTRA_TYPE] = actionType
|
||||
this[EXTRA_ACCOUNT_KEY] = accountKey
|
||||
})
|
||||
startActivityForResult(selectUserListIntent, REQUEST_SELECT_USER_LIST)
|
||||
}
|
||||
else -> {
|
||||
setResult(Activity.RESULT_CANCELED)
|
||||
finish()
|
||||
|
@ -82,21 +97,79 @@ class CreateQuickAccessShortcutActivity : BaseActivity() {
|
|||
finish()
|
||||
return
|
||||
}
|
||||
val user = data.getParcelableExtra<ParcelableUser>(EXTRA_USER) ?: run {
|
||||
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)
|
||||
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]))
|
||||
})
|
||||
}
|
||||
"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]))
|
||||
})
|
||||
}
|
||||
else -> {
|
||||
val launchIntent = IntentUtils.userProfile(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()
|
||||
}
|
||||
REQUEST_SELECT_USER_LIST -> {
|
||||
if (resultCode != Activity.RESULT_OK || data == null) {
|
||||
setResult(Activity.RESULT_CANCELED)
|
||||
finish()
|
||||
return
|
||||
}
|
||||
|
||||
val launchIntent = IntentUtils.userProfile(user.account_key, 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]))
|
||||
})
|
||||
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) {
|
||||
"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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,9 @@ import org.mariotaku.twidere.model.util.ParcelableUserListUtils
|
|||
import org.mariotaku.twidere.text.validator.UserListNameValidator
|
||||
import org.mariotaku.twidere.util.*
|
||||
|
||||
class UserListFragment : AbsToolbarTabPagesFragment(), OnClickListener, LoaderCallbacks<SingleResponse<ParcelableUserList>>, SystemWindowsInsetsCallback, SupportFragmentCallback {
|
||||
class UserListFragment : AbsToolbarTabPagesFragment(), OnClickListener,
|
||||
LoaderCallbacks<SingleResponse<ParcelableUserList>>, SystemWindowsInsetsCallback,
|
||||
SupportFragmentCallback {
|
||||
|
||||
private var userListLoaderInitialized: Boolean = false
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.mariotaku.twidere.fragment.SensitiveContentWarningDialogFragment
|
|||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.util.ParcelableLocationUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableMediaUtils
|
||||
import org.mariotaku.twidere.util.LinkCreator.getTwidereUserListRelatedLink
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
|
@ -86,6 +87,30 @@ object IntentUtils {
|
|||
return intent
|
||||
}
|
||||
|
||||
fun userTimeline(accountKey: UserKey?, userKey: UserKey?, screenName: String?,
|
||||
@Referral referral: String? = null, profileUrl: String? = null): Intent {
|
||||
val uri = LinkCreator.getTwidereUserRelatedLink(AUTHORITY_USER_TIMELINE, accountKey,
|
||||
userKey, screenName)
|
||||
val intent = Intent(Intent.ACTION_VIEW, uri)
|
||||
if (referral != null) {
|
||||
intent.putExtra(EXTRA_REFERRAL, referral)
|
||||
}
|
||||
intent.putExtra(EXTRA_PROFILE_URL, profileUrl)
|
||||
return intent
|
||||
}
|
||||
|
||||
fun userFavorites(accountKey: UserKey?, userKey: UserKey?, screenName: String?,
|
||||
@Referral referral: String? = null, profileUrl: String? = null): Intent {
|
||||
val uri = LinkCreator.getTwidereUserRelatedLink(AUTHORITY_USER_FAVORITES, accountKey,
|
||||
userKey, screenName)
|
||||
val intent = Intent(Intent.ACTION_VIEW, uri)
|
||||
if (referral != null) {
|
||||
intent.putExtra(EXTRA_REFERRAL, referral)
|
||||
}
|
||||
intent.putExtra(EXTRA_PROFILE_URL, profileUrl)
|
||||
return intent
|
||||
}
|
||||
|
||||
fun openItems(context: Context, items: List<Parcelable>?) {
|
||||
if (items == null) return
|
||||
val extras = Bundle()
|
||||
|
@ -439,24 +464,11 @@ object IntentUtils {
|
|||
|
||||
}
|
||||
|
||||
fun openUserFollowers(context: Context,
|
||||
accountKey: UserKey?,
|
||||
userKey: UserKey?,
|
||||
fun openUserFollowers(context: Context, accountKey: UserKey?, userKey: UserKey?,
|
||||
screenName: String?) {
|
||||
val builder = Uri.Builder()
|
||||
builder.scheme(SCHEME_TWIDERE)
|
||||
builder.authority(AUTHORITY_USER_FOLLOWERS)
|
||||
if (accountKey != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, accountKey.toString())
|
||||
}
|
||||
if (userKey != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_USER_KEY, userKey.toString())
|
||||
}
|
||||
if (screenName != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_SCREEN_NAME, screenName)
|
||||
}
|
||||
val intent = Intent(Intent.ACTION_VIEW, builder.build())
|
||||
context.startActivity(intent)
|
||||
val intent = LinkCreator.getTwidereUserRelatedLink(AUTHORITY_USER_FOLLOWERS,
|
||||
accountKey, userKey, screenName)
|
||||
context.startActivity(Intent(Intent.ACTION_VIEW, intent))
|
||||
}
|
||||
|
||||
fun openUserFriends(context: Context,
|
||||
|
@ -480,35 +492,28 @@ object IntentUtils {
|
|||
|
||||
}
|
||||
|
||||
fun openUserListDetails(context: Context,
|
||||
accountKey: UserKey?,
|
||||
listId: String?,
|
||||
userId: UserKey?,
|
||||
screenName: String?, listName: String?) {
|
||||
val builder = Uri.Builder()
|
||||
builder.scheme(SCHEME_TWIDERE)
|
||||
builder.authority(AUTHORITY_USER_LIST)
|
||||
if (accountKey != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, accountKey.toString())
|
||||
}
|
||||
if (listId != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_LIST_ID, listId)
|
||||
}
|
||||
if (userId != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_USER_KEY, userId.toString())
|
||||
}
|
||||
if (screenName != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_SCREEN_NAME, screenName)
|
||||
}
|
||||
if (listName != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_LIST_NAME, listName)
|
||||
}
|
||||
val intent = Intent(Intent.ACTION_VIEW, builder.build())
|
||||
context.startActivity(intent)
|
||||
fun openUserListDetails(context: Context, accountKey: UserKey?, listId: String?,
|
||||
userId: UserKey?, screenName: String?, listName: String?) {
|
||||
context.startActivity(userListDetails(accountKey, listId, userId, screenName, listName))
|
||||
}
|
||||
|
||||
fun openUserListDetails(context: Context,
|
||||
userList: ParcelableUserList) {
|
||||
fun userListDetails(accountKey: UserKey?, listId: String?, userId: UserKey?, screenName: String?,
|
||||
listName: String?): Intent {
|
||||
return Intent(Intent.ACTION_VIEW, getTwidereUserListRelatedLink(AUTHORITY_USER_LIST,
|
||||
accountKey, listId, userId, screenName, listName))
|
||||
}
|
||||
|
||||
fun userListTimeline(accountKey: UserKey?, listId: String?, userId: UserKey?, screenName: String?,
|
||||
listName: String?): Intent {
|
||||
return Intent(Intent.ACTION_VIEW, getTwidereUserListRelatedLink(AUTHORITY_USER_LIST_TIMELINE,
|
||||
accountKey, listId, userId, screenName, listName))
|
||||
}
|
||||
|
||||
fun openUserListDetails(context: Context, userList: ParcelableUserList) {
|
||||
context.startActivity(userListDetails(context, userList))
|
||||
}
|
||||
|
||||
fun userListDetails(context: Context, userList: ParcelableUserList): Intent {
|
||||
val userKey = userList.user_key
|
||||
val listId = userList.id
|
||||
val extras = Bundle()
|
||||
|
@ -522,7 +527,7 @@ object IntentUtils {
|
|||
val intent = Intent(Intent.ACTION_VIEW, builder.build())
|
||||
intent.setExtrasClassLoader(context.classLoader)
|
||||
intent.putExtras(extras)
|
||||
context.startActivity(intent)
|
||||
return intent
|
||||
}
|
||||
|
||||
fun openGroupDetails(context: Context, group: ParcelableGroup) {
|
||||
|
|
|
@ -0,0 +1,169 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2015 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.util
|
||||
|
||||
import android.net.Uri
|
||||
import android.text.TextUtils
|
||||
import org.mariotaku.twidere.TwidereConstants.*
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.ParcelableUser
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/3/14.
|
||||
*/
|
||||
object LinkCreator {
|
||||
|
||||
private val AUTHORITY_TWITTER = "twitter.com"
|
||||
private val AUTHORITY_FANFOU = "fanfou.com"
|
||||
|
||||
fun getTwidereStatusLink(accountKey: UserKey?, statusId: String): Uri {
|
||||
val builder = Uri.Builder()
|
||||
builder.scheme(SCHEME_TWIDERE)
|
||||
builder.authority(AUTHORITY_STATUS)
|
||||
if (accountKey != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, accountKey.toString())
|
||||
}
|
||||
builder.appendQueryParameter(QUERY_PARAM_STATUS_ID, statusId)
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
fun getTwidereUserLink(accountKey: UserKey?, userKey: UserKey?, screenName: String?): Uri {
|
||||
return getTwidereUserRelatedLink(AUTHORITY_USER, accountKey, userKey, screenName)
|
||||
}
|
||||
|
||||
fun getTwidereUserRelatedLink(authority: String, accountKey: UserKey?, userKey: UserKey?,
|
||||
screenName: String?): Uri {
|
||||
val builder = Uri.Builder()
|
||||
builder.scheme(SCHEME_TWIDERE)
|
||||
builder.authority(authority)
|
||||
if (accountKey != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, accountKey.toString())
|
||||
}
|
||||
if (userKey != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_USER_KEY, userKey.toString())
|
||||
}
|
||||
if (screenName != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_SCREEN_NAME, screenName)
|
||||
}
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
fun getTwidereUserListRelatedLink(authority: String, accountKey: UserKey?, listId: String?,
|
||||
userId: UserKey?, screenName: String?, listName: String?): Uri {
|
||||
val builder = Uri.Builder()
|
||||
builder.scheme(SCHEME_TWIDERE)
|
||||
builder.authority(authority)
|
||||
if (accountKey != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, accountKey.toString())
|
||||
}
|
||||
if (listId != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_LIST_ID, listId)
|
||||
}
|
||||
if (userId != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_USER_KEY, userId.toString())
|
||||
}
|
||||
if (screenName != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_SCREEN_NAME, screenName)
|
||||
}
|
||||
if (listName != null) {
|
||||
builder.appendQueryParameter(QUERY_PARAM_LIST_NAME, listName)
|
||||
}
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
fun getTwitterUserListLink(userScreenName: String, listName: String): Uri {
|
||||
val builder = Uri.Builder()
|
||||
builder.scheme(SCHEME_HTTPS)
|
||||
builder.authority(AUTHORITY_TWITTER)
|
||||
builder.appendPath(userScreenName)
|
||||
builder.appendPath(listName)
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
fun getStatusWebLink(status: ParcelableStatus): Uri {
|
||||
if (status.extras != null && !TextUtils.isEmpty(status.extras.external_url)) {
|
||||
return Uri.parse(status.extras.external_url)
|
||||
}
|
||||
if (USER_TYPE_FANFOU_COM == status.account_key.host) {
|
||||
return getFanfouStatusLink(status.id)
|
||||
}
|
||||
return getTwitterStatusLink(status.user_screen_name, status.id)
|
||||
}
|
||||
|
||||
fun getQuotedStatusWebLink(status: ParcelableStatus): Uri {
|
||||
if (status.extras != null) {
|
||||
if (!TextUtils.isEmpty(status.extras.quoted_external_url)) {
|
||||
return Uri.parse(status.extras.quoted_external_url)
|
||||
} else if (!TextUtils.isEmpty(status.extras.external_url)) {
|
||||
return Uri.parse(status.extras.external_url)
|
||||
}
|
||||
}
|
||||
if (USER_TYPE_FANFOU_COM == status.account_key.host) {
|
||||
return getFanfouStatusLink(status.quoted_id)
|
||||
}
|
||||
return getTwitterStatusLink(status.quoted_user_screen_name, status.quoted_id)
|
||||
}
|
||||
|
||||
fun getUserWebLink(user: ParcelableUser): Uri {
|
||||
if (user.extras != null && user.extras.statusnet_profile_url != null) {
|
||||
return Uri.parse(user.extras.statusnet_profile_url)
|
||||
}
|
||||
if (USER_TYPE_FANFOU_COM == user.key.host) {
|
||||
return getFanfouUserLink(user.key.id)
|
||||
}
|
||||
return getTwitterUserLink(user.screen_name)
|
||||
}
|
||||
|
||||
internal fun getTwitterStatusLink(screenName: String, statusId: String): Uri {
|
||||
val builder = Uri.Builder()
|
||||
builder.scheme(SCHEME_HTTPS)
|
||||
builder.authority(AUTHORITY_TWITTER)
|
||||
builder.appendPath(screenName)
|
||||
builder.appendPath("status")
|
||||
builder.appendPath(statusId)
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
internal fun getTwitterUserLink(screenName: String): Uri {
|
||||
val builder = Uri.Builder()
|
||||
builder.scheme(SCHEME_HTTPS)
|
||||
builder.authority(AUTHORITY_TWITTER)
|
||||
builder.appendPath(screenName)
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
internal fun getFanfouStatusLink(id: String): Uri {
|
||||
val builder = Uri.Builder()
|
||||
builder.scheme(SCHEME_HTTP)
|
||||
builder.authority(AUTHORITY_FANFOU)
|
||||
builder.appendPath("statuses")
|
||||
builder.appendPath(id)
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
internal fun getFanfouUserLink(id: String): Uri {
|
||||
val builder = Uri.Builder()
|
||||
builder.scheme(SCHEME_HTTP)
|
||||
builder.authority(AUTHORITY_FANFOU)
|
||||
builder.appendPath(id)
|
||||
return builder.build()
|
||||
}
|
||||
}
|
|
@ -75,8 +75,9 @@
|
|||
</string-array>
|
||||
<string-array name="entries_quick_access_shortcut_types">
|
||||
<item>User</item>
|
||||
<item>List</item>
|
||||
<item>User timeline</item>
|
||||
<item>Favorite</item>
|
||||
<item>User Favorites</item>
|
||||
<item>List</item>
|
||||
<item>List timeline</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
|
|
@ -98,8 +98,9 @@
|
|||
</string-array>
|
||||
<string-array name="values_quick_access_shortcut_types">
|
||||
<item>user</item>
|
||||
<item>list</item>
|
||||
<item>user_timeline</item>
|
||||
<item>favorite</item>
|
||||
<item>user_favorites</item>
|
||||
<item>list</item>
|
||||
<item>list_timeline</item>
|
||||
</string-array>
|
||||
</resources>
|
Loading…
Reference in New Issue