hides other users' favs for mastodon

This commit is contained in:
Mariotaku Lee 2017-04-19 19:30:07 +08:00
parent 059c38b6bf
commit d1472f0397
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
4 changed files with 64 additions and 13 deletions

View File

@ -69,7 +69,8 @@ class AccountsDumperPlugin(val context: Context) : DumperPlugin {
override fun dump(dumpContext: DumperContext) {
val argsAsList = dumpContext.argsAsList
val subCommands = listOf(ExportCommand(context), ImportCommand(context),
ListCommand(context), GetCommand(context), SetCommand(context))
ListCommand(context), GetCommand(context), SetCommand(context),
SetJsonCommand(context))
val subCommandName = argsAsList.firstOrNull()
val subCommand = subCommands.find { it.name == subCommandName } ?: run {
throw DumpException("Usage: accounts <${subCommands.joinToString("|", transform = SubCommand::name)}> <args>")
@ -210,6 +211,33 @@ class AccountsDumperPlugin(val context: Context) : DumperPlugin {
}
class SetJsonCommand(val context: Context) : SubCommand("set-json") {
override fun execute(dumpContext: DumperContext, args: Array<String>) {
if (args.size != 3) {
throw DumpException("Usage: accounts $name <account_key> <field> <json>")
}
val am = AccountManager.get(context)
val docContext = try {
am.docContext(args[0])
} catch (e: Utils.NoAccountException) {
throw DumpException("Account not found")
}
val value = args[2]
val path = args[1]
if (value.startsWith("{")) {
docContext.set(path, JSONObject(value))
} else if (value.startsWith("[")) {
docContext.set(path, JSONArray(value))
}
val details = docContext.read("$", Object::class.java)?.let {
JsonSerializer.parse(it.toString(), AccountDetails::class.java)
} ?: return
details.account.updateDetails(am, details)
dumpContext.stdout.println("$path = ${docContext.read(path, Object::class.java)?.prettyPrint()}")
}
}
companion object {
private val factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1")

View File

@ -1463,14 +1463,16 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
position = TAB_POSITION_STATUSES)
pagerAdapter.add(cls = UserMediaTimelineFragment::class.java, args = tabArgs,
name = getString(R.string.media), type = TAB_TYPE_MEDIA, position = TAB_POSITION_MEDIA)
if (preferences[iWantMyStarsBackKey]) {
pagerAdapter.add(cls = UserFavoritesFragment::class.java, args = tabArgs,
name = getString(R.string.title_favorites), type = TAB_TYPE_FAVORITES,
position = TAB_POSITION_FAVORITES)
} else {
pagerAdapter.add(cls = UserFavoritesFragment::class.java, args = tabArgs,
name = getString(R.string.title_likes), type = TAB_TYPE_FAVORITES,
position = TAB_POSITION_FAVORITES)
if (account?.type != AccountType.MASTODON || account?.key == userKey) {
if (preferences[iWantMyStarsBackKey]) {
pagerAdapter.add(cls = UserFavoritesFragment::class.java, args = tabArgs,
name = getString(R.string.title_favorites), type = TAB_TYPE_FAVORITES,
position = TAB_POSITION_FAVORITES)
} else {
pagerAdapter.add(cls = UserFavoritesFragment::class.java, args = tabArgs,
name = getString(R.string.title_likes), type = TAB_TYPE_FAVORITES,
position = TAB_POSITION_FAVORITES)
}
}
}

View File

@ -25,8 +25,10 @@ import android.support.annotation.WorkerThread
import org.mariotaku.ktextension.isNullOrEmpty
import org.mariotaku.microblog.library.MicroBlog
import org.mariotaku.microblog.library.MicroBlogException
import org.mariotaku.microblog.library.mastodon.Mastodon
import org.mariotaku.microblog.library.twitter.model.*
import org.mariotaku.twidere.annotation.AccountType
import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable
import org.mariotaku.twidere.extension.model.api.toParcelable
import org.mariotaku.twidere.extension.model.isOfficial
import org.mariotaku.twidere.extension.model.newMicroBlogInstance
@ -36,7 +38,7 @@ import org.mariotaku.twidere.model.UserKey
import org.mariotaku.twidere.util.DataStoreUtils
import org.mariotaku.twidere.util.InternalTwitterContentUtils
import org.mariotaku.twidere.util.TwitterWrapper
import org.mariotaku.microblog.library.mastodon.model.TimelineOption as MastodonTimelineOption
class MediaTimelineLoader(
context: Context,
@ -62,14 +64,17 @@ class MediaTimelineLoader(
return userKey.maybeEquals(accountKey)
} else {
val accountScreenName = DataStoreUtils.getAccountScreenName(context, accountKey)
return accountScreenName != null && accountScreenName.equals(screenName!!, ignoreCase = true)
return accountScreenName != null && accountScreenName.equals(screenName, ignoreCase = true)
}
}
@Throws(MicroBlogException::class)
override fun getStatuses(account: AccountDetails, paging: Paging): List<ParcelableStatus> {
return getMicroBlogStatuses(account, paging).map {
it.toParcelable(account.key, account.type, profileImageSize)
when (account.type) {
AccountType.MASTODON -> return getMastodonStatuses(account, paging)
else -> return getMicroBlogStatuses(account, paging).map {
it.toParcelable(account.key, account.type, profileImageSize)
}
}
}
@ -127,4 +132,12 @@ class MediaTimelineLoader(
}
throw MicroBlogException("Not implemented")
}
private fun getMastodonStatuses(account: AccountDetails, paging: Paging): List<ParcelableStatus> {
val mastodon = account.newMicroBlogInstance(context, Mastodon::class.java)
val option = MastodonTimelineOption()
option.onlyMedia(true)
return UserTimelineLoader.getMastodonStatuses(mastodon, userKey, screenName, paging,
option).map { it.toParcelable(account.key) }
}
}

View File

@ -191,4 +191,12 @@ class UserTimelineLoader(
}
}
}
companion object {
fun getMastodonStatuses(mastodon: Mastodon, userKey: UserKey?, screenName: String?, paging: Paging,
option: MastodonTimelineOption?): List<MastodonStatus> {
val id = userKey?.id ?: throw MicroBlogException("Only ID are supported at this moment")
return mastodon.getStatuses(id, paging, option)
}
}
}