From 0612336e62287b354a0f635151cde9fa9ad1c524 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Sun, 23 Apr 2017 11:54:18 +0800 Subject: [PATCH] fixed #774 fixed #777 added display name fallback --- .../extension/model/api/mastodon/AccountExtensions.kt | 8 +++++--- .../extension/model/api/mastodon/StatusExtensions.kt | 4 ++-- .../twidere/fragment/statuses/StatusesSearchFragment.kt | 9 ++------- .../twidere/loader/statuses/MediaStatusesSearchLoader.kt | 4 ++-- .../loader/statuses/NetworkPublicTimelineLoader.kt | 2 +- .../twidere/loader/statuses/TweetSearchLoader.kt | 2 +- 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/AccountExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/AccountExtensions.kt index a06699af9..37bd365fd 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/AccountExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/AccountExtensions.kt @@ -46,7 +46,7 @@ fun Account.toParcelable(accountKey: UserKey, position: Long = 0): ParcelableUse obj.key = getKey(accountKey.host) obj.created_at = createdAt?.time ?: -1 obj.is_protected = isLocked - obj.name = displayName?.takeIf(String::isNotEmpty) ?: username + obj.name = name obj.screen_name = username if (note?.isHtml ?: false) { val descriptionHtml = HtmlSpanBuilder.fromHtml(note, note) @@ -70,6 +70,8 @@ fun Account.toParcelable(accountKey: UserKey, position: Long = 0): ParcelableUse return obj } -val Account.host: String? get() = acct?.let(UserKey::valueOf)?.host +inline val Account.host: String? get() = acct?.let(UserKey::valueOf)?.host -fun Account.getKey(host: String?) = UserKey(id, acct?.let(UserKey::valueOf)?.host ?: host) \ No newline at end of file +inline val Account.name: String? get() = displayName?.takeIf(String::isNotEmpty) ?: username + +fun Account.getKey(host: String?) = UserKey(id, acct?.let(UserKey::valueOf)?.host ?: host) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/StatusExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/StatusExtensions.kt index 9c7ddeb1a..4f31612bc 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/StatusExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/StatusExtensions.kt @@ -54,7 +54,7 @@ fun Status.toParcelable(accountKey: UserKey): ParcelableStatus { result.retweet_id = retweetedStatus.id result.retweet_timestamp = retweetedStatus.createdAt?.time ?: 0 result.retweeted_by_user_key = retweetAccount.getKey(accountKey.host) - result.retweeted_by_user_name = retweetAccount.displayName + result.retweeted_by_user_name = retweetAccount.name result.retweeted_by_user_screen_name = retweetAccount.username result.retweeted_by_user_profile_image = retweetAccount.avatar @@ -79,7 +79,7 @@ fun Status.toParcelable(accountKey: UserKey): ParcelableStatus { val account = status.account result.user_key = account.getKey(accountKey.host) - result.user_name = account.displayName + result.user_name = account.name result.user_screen_name = account.username result.user_profile_image_url = account.avatar result.user_is_protected = account.isLocked diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/statuses/StatusesSearchFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/statuses/StatusesSearchFragment.kt index 5fbcba951..3b930c208 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/statuses/StatusesSearchFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/statuses/StatusesSearchFragment.kt @@ -20,7 +20,6 @@ package org.mariotaku.twidere.fragment.statuses import android.content.Context -import android.graphics.Rect import android.os.Bundle import android.support.v4.content.Loader import org.mariotaku.twidere.TwidereConstants.* @@ -73,12 +72,8 @@ open class StatusesSearchFragment : ParcelableStatusesFragment() { val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1) val makeGap = args.getBoolean(EXTRA_MAKE_GAP, true) val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false) - return TweetSearchLoader(activity, accountKey, query, adapterData, savedStatusesFileArgs, tabPosition, fromUser, - makeGap, loadingMore) - } - - override fun fitSystemWindows(insets: Rect) { - super.fitSystemWindows(insets) + return TweetSearchLoader(activity, accountKey, query, adapterData, savedStatusesFileArgs, + tabPosition, fromUser, makeGap, loadingMore) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/MediaStatusesSearchLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/MediaStatusesSearchLoader.kt index 8427bb2d5..5410dc290 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/MediaStatusesSearchLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/MediaStatusesSearchLoader.kt @@ -76,9 +76,9 @@ open class MediaStatusesSearchLoader( protected open fun processQuery(details: AccountDetails, query: String): String { if (details.type == AccountType.TWITTER) { if (details.extras?.official ?: false) { - return TweetSearchLoader.smQuery(query, pagination) + return TweetSearchLoader.smQuery("$query filter:media", pagination) } - return "$query exclude:retweets filter:media" + return "$query filter:media exclude:retweets" } return query } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/NetworkPublicTimelineLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/NetworkPublicTimelineLoader.kt index 32bc2fd59..c5512d172 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/NetworkPublicTimelineLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/NetworkPublicTimelineLoader.kt @@ -53,7 +53,7 @@ class NetworkPublicTimelineLoader( when (account.type) { AccountType.MASTODON -> { val mastodon = account.newMicroBlogInstance(context, Mastodon::class.java) - return mastodon.getPublicTimeline(paging, true).mapToPaginated { + return mastodon.getPublicTimeline(paging, false).mapToPaginated { it.toParcelable(account) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/TweetSearchLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/TweetSearchLoader.kt index 6a834e451..1e8bfa0c5 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/TweetSearchLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/TweetSearchLoader.kt @@ -130,7 +130,7 @@ open class TweetSearchLoader( companion object { fun smQuery(query: String, pagination: Pagination?): String { - var universalQueryText = "$query filter:media" + var universalQueryText = query if (pagination !is SinceMaxPagination) return universalQueryText pagination.maxId?.let { maxId ->