fixed a possible memleak in login activity
hides dm for mastodon
This commit is contained in:
parent
f78e46978b
commit
cdf819fa0d
|
@ -354,15 +354,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher,
|
||||||
} and task {
|
} and task {
|
||||||
val activity = weakThis.get() ?: throw InterruptedException()
|
val activity = weakThis.get() ?: throw InterruptedException()
|
||||||
val registry = activity.mastodonApplicationRegistry
|
val registry = activity.mastodonApplicationRegistry
|
||||||
return@task Pair(host, registry[host] ?: run {
|
return@task Pair(host, registry[host] ?: registry.fetch(host, scopes))
|
||||||
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
|
|
||||||
})
|
|
||||||
}.successUi { (host, app) ->
|
}.successUi { (host, app) ->
|
||||||
val activity = weakThis.get() ?: return@successUi
|
val activity = weakThis.get() ?: return@successUi
|
||||||
val endpoint = Endpoint("https://$host/")
|
val endpoint = Endpoint("https://$host/")
|
||||||
|
@ -417,12 +409,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher,
|
||||||
|
|
||||||
private fun dismissDialogFragment(tag: String) {
|
private fun dismissDialogFragment(tag: String) {
|
||||||
executeAfterFragmentResumed {
|
executeAfterFragmentResumed {
|
||||||
val fm = supportFragmentManager
|
it.supportFragmentManager.dismissDialogFragment(tag)
|
||||||
val f = fm.findFragmentByTag(tag)
|
|
||||||
if (f is DialogFragment) {
|
|
||||||
f.dismiss()
|
|
||||||
}
|
|
||||||
Unit
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -364,8 +364,6 @@ class AccountsDashboardFragment : BaseFragment(), LoaderCallbacks<AccountsInfo>,
|
||||||
}
|
}
|
||||||
val menu = navigationView.menu
|
val menu = navigationView.menu
|
||||||
menu.setItemAvailability(R.id.interactions, !hasInteractionsTab)
|
menu.setItemAvailability(R.id.interactions, !hasInteractionsTab)
|
||||||
menu.setItemAvailability(R.id.messages, !hasDmTab)
|
|
||||||
|
|
||||||
menu.setItemAvailability(R.id.favorites, useStarsForLikes)
|
menu.setItemAvailability(R.id.favorites, useStarsForLikes)
|
||||||
menu.setItemAvailability(R.id.likes, !useStarsForLikes)
|
menu.setItemAvailability(R.id.likes, !useStarsForLikes)
|
||||||
menu.setItemAvailability(R.id.premium_features, extraFeaturesService.isSupported())
|
menu.setItemAvailability(R.id.premium_features, extraFeaturesService.isSupported())
|
||||||
|
@ -381,16 +379,20 @@ class AccountsDashboardFragment : BaseFragment(), LoaderCallbacks<AccountsInfo>,
|
||||||
var hasGroups = false
|
var hasGroups = false
|
||||||
var hasPublicTimeline = false
|
var hasPublicTimeline = false
|
||||||
var hasNetworkPublicTimeline = false
|
var hasNetworkPublicTimeline = false
|
||||||
|
var hasDirectMessages = false
|
||||||
when (account.type) {
|
when (account.type) {
|
||||||
AccountType.TWITTER -> {
|
AccountType.TWITTER -> {
|
||||||
|
hasDirectMessages = !hasDmTab
|
||||||
hasLists = true
|
hasLists = true
|
||||||
}
|
}
|
||||||
AccountType.STATUSNET -> {
|
AccountType.STATUSNET -> {
|
||||||
|
hasDirectMessages = !hasDmTab
|
||||||
hasGroups = true
|
hasGroups = true
|
||||||
hasPublicTimeline = !hasPublicTimelineTab
|
hasPublicTimeline = !hasPublicTimelineTab
|
||||||
hasNetworkPublicTimeline = !hasNetworkPublicTimelineTab
|
hasNetworkPublicTimeline = !hasNetworkPublicTimelineTab
|
||||||
}
|
}
|
||||||
AccountType.FANFOU -> {
|
AccountType.FANFOU -> {
|
||||||
|
hasDirectMessages = !hasDmTab
|
||||||
hasPublicTimeline = !hasPublicTimelineTab
|
hasPublicTimeline = !hasPublicTimelineTab
|
||||||
}
|
}
|
||||||
AccountType.MASTODON -> {
|
AccountType.MASTODON -> {
|
||||||
|
@ -398,6 +400,7 @@ class AccountsDashboardFragment : BaseFragment(), LoaderCallbacks<AccountsInfo>,
|
||||||
hasNetworkPublicTimeline = !hasNetworkPublicTimelineTab
|
hasNetworkPublicTimeline = !hasNetworkPublicTimelineTab
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
menu.setItemAvailability(R.id.messages, hasDirectMessages)
|
||||||
menu.setItemAvailability(R.id.groups, hasGroups)
|
menu.setItemAvailability(R.id.groups, hasGroups)
|
||||||
menu.setItemAvailability(R.id.lists, hasLists)
|
menu.setItemAvailability(R.id.lists, hasLists)
|
||||||
menu.setItemAvailability(R.id.public_timeline, hasPublicTimeline)
|
menu.setItemAvailability(R.id.public_timeline, hasPublicTimeline)
|
||||||
|
|
|
@ -20,15 +20,21 @@
|
||||||
package org.mariotaku.twidere.util
|
package org.mariotaku.twidere.util
|
||||||
|
|
||||||
import android.content.Context
|
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.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
|
import java.io.IOException
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mariotaku on 2017/4/17.
|
* 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,
|
private val preferences = context.getSharedPreferences(ETAG_MASTODON_APPS_PREFERENCES_NAME,
|
||||||
Context.MODE_PRIVATE)
|
Context.MODE_PRIVATE)
|
||||||
|
|
||||||
|
@ -51,4 +57,15 @@ class MastodonApplicationRegistry(context: Context) {
|
||||||
editor.apply()
|
editor.apply()
|
||||||
return true
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue