hides other users' favs for mastodon
This commit is contained in:
parent
059c38b6bf
commit
d1472f0397
|
@ -69,7 +69,8 @@ class AccountsDumperPlugin(val context: Context) : DumperPlugin {
|
||||||
override fun dump(dumpContext: DumperContext) {
|
override fun dump(dumpContext: DumperContext) {
|
||||||
val argsAsList = dumpContext.argsAsList
|
val argsAsList = dumpContext.argsAsList
|
||||||
val subCommands = listOf(ExportCommand(context), ImportCommand(context),
|
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 subCommandName = argsAsList.firstOrNull()
|
||||||
val subCommand = subCommands.find { it.name == subCommandName } ?: run {
|
val subCommand = subCommands.find { it.name == subCommandName } ?: run {
|
||||||
throw DumpException("Usage: accounts <${subCommands.joinToString("|", transform = SubCommand::name)}> <args>")
|
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 {
|
companion object {
|
||||||
|
|
||||||
private val factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1")
|
private val factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1")
|
||||||
|
|
|
@ -1463,14 +1463,16 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
||||||
position = TAB_POSITION_STATUSES)
|
position = TAB_POSITION_STATUSES)
|
||||||
pagerAdapter.add(cls = UserMediaTimelineFragment::class.java, args = tabArgs,
|
pagerAdapter.add(cls = UserMediaTimelineFragment::class.java, args = tabArgs,
|
||||||
name = getString(R.string.media), type = TAB_TYPE_MEDIA, position = TAB_POSITION_MEDIA)
|
name = getString(R.string.media), type = TAB_TYPE_MEDIA, position = TAB_POSITION_MEDIA)
|
||||||
if (preferences[iWantMyStarsBackKey]) {
|
if (account?.type != AccountType.MASTODON || account?.key == userKey) {
|
||||||
pagerAdapter.add(cls = UserFavoritesFragment::class.java, args = tabArgs,
|
if (preferences[iWantMyStarsBackKey]) {
|
||||||
name = getString(R.string.title_favorites), type = TAB_TYPE_FAVORITES,
|
pagerAdapter.add(cls = UserFavoritesFragment::class.java, args = tabArgs,
|
||||||
position = TAB_POSITION_FAVORITES)
|
name = getString(R.string.title_favorites), type = TAB_TYPE_FAVORITES,
|
||||||
} else {
|
position = TAB_POSITION_FAVORITES)
|
||||||
pagerAdapter.add(cls = UserFavoritesFragment::class.java, args = tabArgs,
|
} else {
|
||||||
name = getString(R.string.title_likes), type = TAB_TYPE_FAVORITES,
|
pagerAdapter.add(cls = UserFavoritesFragment::class.java, args = tabArgs,
|
||||||
position = TAB_POSITION_FAVORITES)
|
name = getString(R.string.title_likes), type = TAB_TYPE_FAVORITES,
|
||||||
|
position = TAB_POSITION_FAVORITES)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,10 @@ import android.support.annotation.WorkerThread
|
||||||
import org.mariotaku.ktextension.isNullOrEmpty
|
import org.mariotaku.ktextension.isNullOrEmpty
|
||||||
import org.mariotaku.microblog.library.MicroBlog
|
import org.mariotaku.microblog.library.MicroBlog
|
||||||
import org.mariotaku.microblog.library.MicroBlogException
|
import org.mariotaku.microblog.library.MicroBlogException
|
||||||
|
import org.mariotaku.microblog.library.mastodon.Mastodon
|
||||||
import org.mariotaku.microblog.library.twitter.model.*
|
import org.mariotaku.microblog.library.twitter.model.*
|
||||||
import org.mariotaku.twidere.annotation.AccountType
|
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.api.toParcelable
|
||||||
import org.mariotaku.twidere.extension.model.isOfficial
|
import org.mariotaku.twidere.extension.model.isOfficial
|
||||||
import org.mariotaku.twidere.extension.model.newMicroBlogInstance
|
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.DataStoreUtils
|
||||||
import org.mariotaku.twidere.util.InternalTwitterContentUtils
|
import org.mariotaku.twidere.util.InternalTwitterContentUtils
|
||||||
import org.mariotaku.twidere.util.TwitterWrapper
|
import org.mariotaku.twidere.util.TwitterWrapper
|
||||||
|
import org.mariotaku.microblog.library.mastodon.model.TimelineOption as MastodonTimelineOption
|
||||||
|
|
||||||
class MediaTimelineLoader(
|
class MediaTimelineLoader(
|
||||||
context: Context,
|
context: Context,
|
||||||
|
@ -62,14 +64,17 @@ class MediaTimelineLoader(
|
||||||
return userKey.maybeEquals(accountKey)
|
return userKey.maybeEquals(accountKey)
|
||||||
} else {
|
} else {
|
||||||
val accountScreenName = DataStoreUtils.getAccountScreenName(context, accountKey)
|
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)
|
@Throws(MicroBlogException::class)
|
||||||
override fun getStatuses(account: AccountDetails, paging: Paging): List<ParcelableStatus> {
|
override fun getStatuses(account: AccountDetails, paging: Paging): List<ParcelableStatus> {
|
||||||
return getMicroBlogStatuses(account, paging).map {
|
when (account.type) {
|
||||||
it.toParcelable(account.key, account.type, profileImageSize)
|
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")
|
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) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue