fixed a possible memleak in login activity

hides dm for mastodon
This commit is contained in:
Mariotaku Lee 2017-04-24 16:56:51 +08:00
parent f78e46978b
commit cdf819fa0d
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
3 changed files with 26 additions and 19 deletions

View File

@ -354,15 +354,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher,
} and task {
val activity = weakThis.get() ?: throw InterruptedException()
val registry = activity.mastodonApplicationRegistry
return@task Pair(host, registry[host] ?: run {
val endpoint = Endpoint("https://$host/api/")
val mastodon = newMicroBlogInstance(activity, endpoint, EmptyAuthorization(),
AccountType.MASTODON, Mastodon::class.java)
val registered = mastodon.registerApplication("Twidere for Android",
MASTODON_CALLBACK_URL, scopes, TWIDERE_PROJECT_URL)
registry[host] = registered
return@run registered
})
return@task Pair(host, registry[host] ?: registry.fetch(host, scopes))
}.successUi { (host, app) ->
val activity = weakThis.get() ?: return@successUi
val endpoint = Endpoint("https://$host/")
@ -417,12 +409,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher,
private fun dismissDialogFragment(tag: String) {
executeAfterFragmentResumed {
val fm = supportFragmentManager
val f = fm.findFragmentByTag(tag)
if (f is DialogFragment) {
f.dismiss()
}
Unit
it.supportFragmentManager.dismissDialogFragment(tag)
}
}

View File

@ -364,8 +364,6 @@ class AccountsDashboardFragment : BaseFragment(), LoaderCallbacks<AccountsInfo>,
}
val menu = navigationView.menu
menu.setItemAvailability(R.id.interactions, !hasInteractionsTab)
menu.setItemAvailability(R.id.messages, !hasDmTab)
menu.setItemAvailability(R.id.favorites, useStarsForLikes)
menu.setItemAvailability(R.id.likes, !useStarsForLikes)
menu.setItemAvailability(R.id.premium_features, extraFeaturesService.isSupported())
@ -381,16 +379,20 @@ class AccountsDashboardFragment : BaseFragment(), LoaderCallbacks<AccountsInfo>,
var hasGroups = false
var hasPublicTimeline = false
var hasNetworkPublicTimeline = false
var hasDirectMessages = false
when (account.type) {
AccountType.TWITTER -> {
hasDirectMessages = !hasDmTab
hasLists = true
}
AccountType.STATUSNET -> {
hasDirectMessages = !hasDmTab
hasGroups = true
hasPublicTimeline = !hasPublicTimelineTab
hasNetworkPublicTimeline = !hasNetworkPublicTimelineTab
}
AccountType.FANFOU -> {
hasDirectMessages = !hasDmTab
hasPublicTimeline = !hasPublicTimelineTab
}
AccountType.MASTODON -> {
@ -398,6 +400,7 @@ class AccountsDashboardFragment : BaseFragment(), LoaderCallbacks<AccountsInfo>,
hasNetworkPublicTimeline = !hasNetworkPublicTimelineTab
}
}
menu.setItemAvailability(R.id.messages, hasDirectMessages)
menu.setItemAvailability(R.id.groups, hasGroups)
menu.setItemAvailability(R.id.lists, hasLists)
menu.setItemAvailability(R.id.public_timeline, hasPublicTimeline)

View File

@ -20,15 +20,21 @@
package org.mariotaku.twidere.util
import android.content.Context
import org.mariotaku.microblog.library.MicroBlogException
import org.mariotaku.microblog.library.mastodon.Mastodon
import org.mariotaku.microblog.library.mastodon.model.RegisteredApplication
import org.mariotaku.twidere.TwidereConstants.ETAG_MASTODON_APPS_PREFERENCES_NAME
import org.mariotaku.microblog.library.twitter.auth.EmptyAuthorization
import org.mariotaku.restfu.http.Endpoint
import org.mariotaku.twidere.TwidereConstants.*
import org.mariotaku.twidere.annotation.AccountType
import org.mariotaku.twidere.extension.model.newMicroBlogInstance
import java.io.IOException
/**
* Created by mariotaku on 2017/4/17.
*/
class MastodonApplicationRegistry(context: Context) {
class MastodonApplicationRegistry(private val context: Context) {
private val preferences = context.getSharedPreferences(ETAG_MASTODON_APPS_PREFERENCES_NAME,
Context.MODE_PRIVATE)
@ -51,4 +57,15 @@ class MastodonApplicationRegistry(context: Context) {
editor.apply()
return true
}
@Throws(MicroBlogException::class)
fun fetch(host: String, scopes: Array<String>): RegisteredApplication {
val endpoint = Endpoint("https://$host/api/")
val mastodon = newMicroBlogInstance(context, endpoint, EmptyAuthorization(),
AccountType.MASTODON, Mastodon::class.java)
val registered = mastodon.registerApplication("Twidere for Android", MASTODON_CALLBACK_URL,
scopes, TWIDERE_PROJECT_URL)
this[host] = registered
return registered
}
}