code cleanup
This commit is contained in:
parent
ec49301585
commit
42361c9fbe
|
@ -1 +1 @@
|
|||
e42684a358dfcd05b5ad3d2d544f613ba7259256
|
||||
dd0844dbbe382a92fb135be9979788e5f2f6d312
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.mariotaku.twidere.model.tab;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
@ -10,6 +11,7 @@ import org.mariotaku.kpreferences.SharedPreferencesExtensionsKt;
|
|||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.constant.PreferenceKeysKt;
|
||||
import org.mariotaku.twidere.dagger.DependencyHolder;
|
||||
import org.mariotaku.twidere.singleton.PreferencesSingleton;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -203,7 +205,8 @@ public abstract class DrawableHolder {
|
|||
@Override
|
||||
public Drawable createDrawable(Context context) {
|
||||
final DependencyHolder holder = DependencyHolder.Companion.get(context);
|
||||
if (SharedPreferencesExtensionsKt.get(holder.preferences, PreferenceKeysKt.getIWantMyStarsBackKey())) {
|
||||
final SharedPreferences preferences = PreferencesSingleton.INSTANCE.get(context);
|
||||
if (SharedPreferencesExtensionsKt.get(preferences, PreferenceKeysKt.getIWantMyStarsBackKey())) {
|
||||
return ContextCompat.getDrawable(context, R.drawable.ic_action_star);
|
||||
}
|
||||
return ContextCompat.getDrawable(context, R.drawable.ic_action_heart);
|
||||
|
|
|
@ -119,11 +119,11 @@ open class BaseActivity : ChameleonActivity(), IBaseActivity<BaseActivity>, IThe
|
|||
protected val isDialogTheme: Boolean
|
||||
get() = ThemeUtils.getBooleanFromAttribute(this, R.attr.isDialogTheme)
|
||||
|
||||
override final val currentThemeBackgroundAlpha by lazy {
|
||||
final override val currentThemeBackgroundAlpha by lazy {
|
||||
themeBackgroundAlpha
|
||||
}
|
||||
|
||||
override final val currentThemeBackgroundOption by lazy {
|
||||
final override val currentThemeBackgroundOption by lazy {
|
||||
themeBackgroundOption
|
||||
}
|
||||
|
||||
|
|
|
@ -355,7 +355,6 @@ class MediaViewerActivity : BaseActivity(), IMediaViewerActivity, MediaSwipeClos
|
|||
when (media.type) {
|
||||
ParcelableMedia.Type.IMAGE -> {
|
||||
val mediaUrl = media.media_url
|
||||
?: return Fragment.instantiate(this, ExternalBrowserPageFragment::class.java.name, args) as MediaViewerFragment
|
||||
args.putParcelable(EXTRA_MEDIA_URI, Uri.parse(mediaUrl))
|
||||
if (mediaUrl.endsWith(".gif")) {
|
||||
return Fragment.instantiate(this, GifPageFragment::class.java.name, args) as MediaViewerFragment
|
||||
|
|
|
@ -12,9 +12,9 @@ import org.mariotaku.twidere.TwidereConstants.*
|
|||
import org.mariotaku.twidere.activity.content.FavoriteConfirmDialogActivity
|
||||
import org.mariotaku.twidere.activity.content.RetweetQuoteDialogActivity
|
||||
import org.mariotaku.twidere.app.TwidereApplication
|
||||
import org.mariotaku.twidere.dagger.DependencyHolder
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.theme.UserTheme
|
||||
import org.mariotaku.twidere.singleton.PreferencesSingleton
|
||||
import org.mariotaku.twidere.util.Analyzer
|
||||
import org.mariotaku.twidere.util.IntentUtils
|
||||
import java.util.*
|
||||
|
@ -22,7 +22,7 @@ import java.util.*
|
|||
class WebLinkHandlerActivity : Activity() {
|
||||
|
||||
private val userTheme: Chameleon.Theme by lazy {
|
||||
val preferences = DependencyHolder.get(this).preferences
|
||||
val preferences = PreferencesSingleton.get(this)
|
||||
return@lazy UserTheme.get(this, preferences)
|
||||
}
|
||||
|
||||
|
@ -315,7 +315,7 @@ class WebLinkHandlerActivity : Activity() {
|
|||
if (pathSegments.size < 2) return Pair(null, false)
|
||||
when (pathSegments[1]) {
|
||||
"moments" -> {
|
||||
val preferences = DependencyHolder.get(this).preferences
|
||||
val preferences = PreferencesSingleton.get(this)
|
||||
val (intent, _) = IntentUtils.browse(this, preferences, userTheme, uri, true)
|
||||
return Pair(intent, true)
|
||||
}
|
||||
|
@ -335,7 +335,7 @@ class WebLinkHandlerActivity : Activity() {
|
|||
}
|
||||
"redirect" -> {
|
||||
val url = uri.getQueryParameter("url")?.let(Uri::parse) ?: return Pair(null, false)
|
||||
val preferences = DependencyHolder.get(this).preferences
|
||||
val preferences = PreferencesSingleton.get(this)
|
||||
val (intent, _) = IntentUtils.browse(this, preferences, userTheme, url, false)
|
||||
return Pair(intent, true)
|
||||
}
|
||||
|
|
|
@ -20,8 +20,11 @@
|
|||
package org.mariotaku.twidere.activity.feedback
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.activity.BaseActivity
|
||||
import org.mariotaku.twidere.fragment.BaseDialogFragment
|
||||
|
||||
class FeedbackActivity : BaseActivity() {
|
||||
|
||||
|
@ -30,4 +33,24 @@ class FeedbackActivity : BaseActivity() {
|
|||
setContentView(R.layout.activity_feedback)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
super.onCreateOptionsMenu(menu)
|
||||
menuInflater.inflate(R.menu.menu_feedback, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.send -> {
|
||||
|
||||
return true
|
||||
}
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
class SendMethodDialogFragment: BaseDialogFragment() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,26 +20,20 @@
|
|||
package org.mariotaku.twidere.dagger
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import okhttp3.Cache
|
||||
import okhttp3.ConnectionPool
|
||||
import okhttp3.Dns
|
||||
import org.mariotaku.restfu.http.RestHttpClient
|
||||
import org.mariotaku.twidere.dagger.component.GeneralComponent
|
||||
import org.mariotaku.twidere.model.DefaultFeatures
|
||||
import org.mariotaku.twidere.util.ActivityTracker
|
||||
import org.mariotaku.twidere.util.ExternalThemeManager
|
||||
import org.mariotaku.twidere.util.NotificationManagerWrapper
|
||||
import org.mariotaku.twidere.util.ReadStateManager
|
||||
import org.mariotaku.twidere.util.lang.ApplicationContextSingletonHolder
|
||||
import org.mariotaku.twidere.util.media.MediaPreloader
|
||||
import org.mariotaku.twidere.util.media.ThumborWrapper
|
||||
import org.mariotaku.twidere.util.premium.ExtraFeaturesService
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/12/31.
|
||||
*/
|
||||
class DependencyHolder internal constructor(context: Context) {
|
||||
class DependencyHolder internal constructor(val context: Context) {
|
||||
@Inject
|
||||
lateinit var readStateManager: ReadStateManager
|
||||
internal set
|
||||
|
@ -47,27 +41,9 @@ class DependencyHolder internal constructor(context: Context) {
|
|||
lateinit var restHttpClient: RestHttpClient
|
||||
internal set
|
||||
@Inject
|
||||
lateinit var externalThemeManager: ExternalThemeManager
|
||||
internal set
|
||||
@Inject
|
||||
lateinit var activityTracker: ActivityTracker
|
||||
internal set
|
||||
@Inject
|
||||
lateinit var dns: Dns
|
||||
internal set
|
||||
@Inject
|
||||
lateinit var preferences: SharedPreferences
|
||||
internal set
|
||||
@Inject
|
||||
lateinit var connectionPool: ConnectionPool
|
||||
internal set
|
||||
@Inject
|
||||
lateinit var cache: Cache
|
||||
internal set
|
||||
@Inject
|
||||
lateinit var defaultFeatures: DefaultFeatures
|
||||
internal set
|
||||
@Inject
|
||||
lateinit var mediaPreloader: MediaPreloader
|
||||
internal set
|
||||
@Inject
|
||||
|
@ -75,9 +51,6 @@ class DependencyHolder internal constructor(context: Context) {
|
|||
internal set
|
||||
|
||||
@Inject
|
||||
lateinit var extraFeaturesService: ExtraFeaturesService
|
||||
internal set
|
||||
@Inject
|
||||
lateinit var notificationManager: NotificationManagerWrapper
|
||||
internal set
|
||||
|
||||
|
@ -85,14 +58,5 @@ class DependencyHolder internal constructor(context: Context) {
|
|||
GeneralComponent.get(context).inject(this)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private var sInstance: DependencyHolder? = null
|
||||
|
||||
fun get(context: Context): DependencyHolder {
|
||||
if (sInstance != null) return sInstance!!
|
||||
sInstance = DependencyHolder(context)
|
||||
return sInstance!!
|
||||
}
|
||||
}
|
||||
companion object :ApplicationContextSingletonHolder<DependencyHolder>(::DependencyHolder)
|
||||
}
|
||||
|
|
|
@ -36,17 +36,16 @@ import dagger.Module
|
|||
import dagger.Provides
|
||||
import okhttp3.Cache
|
||||
import okhttp3.ConnectionPool
|
||||
import okhttp3.Dns
|
||||
import okhttp3.OkHttpClient
|
||||
import org.mariotaku.mediaviewer.library.FileCache
|
||||
import org.mariotaku.mediaviewer.library.MediaDownloader
|
||||
import org.mariotaku.restfu.http.RestHttpClient
|
||||
import org.mariotaku.restfu.okhttp3.OkHttpRestClient
|
||||
import org.mariotaku.twidere.Constants.*
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_CACHE_SIZE_LIMIT
|
||||
import org.mariotaku.twidere.extension.model.load
|
||||
import org.mariotaku.twidere.model.DefaultFeatures
|
||||
import org.mariotaku.twidere.singleton.BusSingleton
|
||||
import org.mariotaku.twidere.singleton.CacheSingleton
|
||||
import org.mariotaku.twidere.taskcontroller.refresh.RefreshTaskController
|
||||
import org.mariotaku.twidere.taskcontroller.sync.JobSchedulerSyncController
|
||||
import org.mariotaku.twidere.taskcontroller.sync.LegacySyncController
|
||||
|
@ -131,8 +130,9 @@ class ApplicationModule(private val application: Application) {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun restHttpClient(prefs: SharedPreferences, dns: Dns, connectionPool: ConnectionPool,
|
||||
cache: Cache): RestHttpClient {
|
||||
fun restHttpClient(prefs: SharedPreferences): RestHttpClient {
|
||||
val dns = TwidereDns.get(application)
|
||||
val cache = CacheSingleton.get(application)
|
||||
val conf = HttpClientFactory.HttpClientConfiguration(prefs)
|
||||
val client = HttpClientFactory.createRestHttpClient(conf, dns, cache)
|
||||
PreferenceChangeNotifier.get(application).register(KEY_ENABLE_PROXY, KEY_PROXY_ADDRESS, KEY_PROXY_TYPE,
|
||||
|
@ -191,16 +191,6 @@ class ApplicationModule(private val application: Application) {
|
|||
return preloader
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun dns(preferences: SharedPreferences): Dns {
|
||||
val dns = TwidereDns(application, preferences)
|
||||
PreferenceChangeNotifier.get(application).register(KEY_DNS_SERVER, KEY_TCP_DNS_QUERY, KEY_BUILTIN_DNS_RESOLVER) {
|
||||
dns.reloadDnsSettings()
|
||||
}
|
||||
return dns
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun mediaDownloader(client: RestHttpClient, thumbor: ThumborWrapper): MediaDownloader {
|
||||
|
@ -292,8 +282,9 @@ class ApplicationModule(private val application: Application) {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun okHttpClient(preferences: SharedPreferences, dns: Dns, connectionPool: ConnectionPool,
|
||||
cache: Cache): OkHttpClient {
|
||||
fun okHttpClient(preferences: SharedPreferences): OkHttpClient {
|
||||
val dns = TwidereDns.get(application)
|
||||
val cache = CacheSingleton.get(application)
|
||||
val conf = HttpClientFactory.HttpClientConfiguration(preferences)
|
||||
val builder = OkHttpClient.Builder()
|
||||
HttpClientFactory.initOkHttpClient(conf, builder, dns, cache)
|
||||
|
@ -302,7 +293,9 @@ class ApplicationModule(private val application: Application) {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun dataSourceFactory(preferences: SharedPreferences, dns: Dns, cache: Cache): DataSource.Factory {
|
||||
fun dataSourceFactory(preferences: SharedPreferences): DataSource.Factory {
|
||||
val dns = TwidereDns.get(application)
|
||||
val cache = CacheSingleton.get(application)
|
||||
val conf = HttpClientFactory.HttpClientConfiguration(preferences)
|
||||
val builder = OkHttpClient.Builder()
|
||||
HttpClientFactory.initOkHttpClient(conf, builder, dns, cache)
|
||||
|
@ -312,10 +305,8 @@ class ApplicationModule(private val application: Application) {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun cache(preferences: SharedPreferences): Cache {
|
||||
val cacheSizeMB = preferences.getInt(KEY_CACHE_SIZE_LIMIT, 300).coerceIn(100..500)
|
||||
// Convert to bytes
|
||||
return Cache(getCacheDir("network", cacheSizeMB * 1048576L), cacheSizeMB * 1048576L)
|
||||
fun cache(): Cache {
|
||||
return CacheSingleton.get(application)
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -23,6 +23,8 @@ import android.content.Context
|
|||
import android.content.SharedPreferences
|
||||
import android.os.Build
|
||||
import org.mariotaku.twidere.TwidereConstants
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
val Context.defaultSharedPreferences: SharedPreferences
|
||||
|
@ -36,3 +38,8 @@ fun Context.overriding(withLocale: Locale): Context {
|
|||
this
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.getCacheDir(dirName: String, sizeInBytes: Long): File {
|
||||
return Utils.getExternalCacheDir(this, dirName, sizeInBytes)
|
||||
?: Utils.getInternalCacheDir(this, dirName)
|
||||
}
|
||||
|
|
|
@ -4,13 +4,9 @@ import android.content.Context
|
|||
import android.net.Uri
|
||||
import android.text.TextUtils
|
||||
import org.mariotaku.microblog.library.*
|
||||
import org.mariotaku.microblog.library.FanfouStream
|
||||
import org.mariotaku.microblog.library.Mastodon
|
||||
import org.mariotaku.microblog.library.MastodonOAuth2
|
||||
import org.mariotaku.microblog.library.MastodonStreaming
|
||||
import org.mariotaku.microblog.library.twitter.*
|
||||
import org.mariotaku.microblog.library.auth.BasicAuthorization
|
||||
import org.mariotaku.microblog.library.auth.EmptyAuthorization
|
||||
import org.mariotaku.microblog.library.twitter.TwitterWeb
|
||||
import org.mariotaku.restfu.RestAPIFactory
|
||||
import org.mariotaku.restfu.RestRequest
|
||||
import org.mariotaku.restfu.http.Authorization
|
||||
|
@ -24,6 +20,8 @@ import org.mariotaku.twidere.Constants.DEFAULT_TWITTER_API_URL_FORMAT
|
|||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.dagger.DependencyHolder
|
||||
import org.mariotaku.twidere.model.account.cred.*
|
||||
import org.mariotaku.twidere.singleton.CacheSingleton
|
||||
import org.mariotaku.twidere.singleton.PreferencesSingleton
|
||||
import org.mariotaku.twidere.util.HttpClientFactory
|
||||
import org.mariotaku.twidere.util.InternalTwitterContentUtils
|
||||
import org.mariotaku.twidere.util.MicroBlogAPIFactory
|
||||
|
@ -31,6 +29,7 @@ import org.mariotaku.twidere.util.MicroBlogAPIFactory.sFanfouConstantPool
|
|||
import org.mariotaku.twidere.util.MicroBlogAPIFactory.sTwitterConstantPool
|
||||
import org.mariotaku.twidere.util.api.*
|
||||
import org.mariotaku.twidere.util.media.TwidereMediaDownloader
|
||||
import org.mariotaku.twidere.util.net.TwidereDns
|
||||
|
||||
fun Credentials.getAuthorization(cls: Class<*>?): Authorization {
|
||||
if (cls != null) {
|
||||
|
@ -152,21 +151,23 @@ fun <T> newMicroBlogInstance(context: Context, endpoint: Endpoint, auth: Authori
|
|||
var extraRequestParams: Map<String, String>? = null
|
||||
when (cls) {
|
||||
TwitterUpload::class.java -> {
|
||||
val conf = HttpClientFactory.HttpClientConfiguration(holder.preferences)
|
||||
val conf = HttpClientFactory.HttpClientConfiguration(PreferencesSingleton.get(context))
|
||||
// Use longer timeout for uploading
|
||||
conf.readTimeoutSecs = 30
|
||||
conf.writeTimeoutSecs = 30
|
||||
conf.connectionTimeoutSecs = 60
|
||||
val uploadHttpClient = HttpClientFactory.createRestHttpClient(conf, holder.dns,
|
||||
holder.cache)
|
||||
val dns = TwidereDns.get(context)
|
||||
val cache = CacheSingleton.get(context)
|
||||
val uploadHttpClient = HttpClientFactory.createRestHttpClient(conf, dns, cache)
|
||||
factory.setHttpClient(uploadHttpClient)
|
||||
}
|
||||
TwitterUserStream::class.java, FanfouStream::class.java, MastodonStreaming::class.java -> {
|
||||
val conf = HttpClientFactory.HttpClientConfiguration(holder.preferences)
|
||||
val conf = HttpClientFactory.HttpClientConfiguration(PreferencesSingleton.get(context))
|
||||
// Use longer read timeout for streaming
|
||||
conf.readTimeoutSecs = 300
|
||||
val streamHttpClient = HttpClientFactory.createRestHttpClient(conf, holder.dns,
|
||||
holder.cache)
|
||||
val dns = TwidereDns.get(context)
|
||||
val cache = CacheSingleton.get(context)
|
||||
val streamHttpClient = HttpClientFactory.createRestHttpClient(conf, dns, cache)
|
||||
factory.setHttpClient(streamHttpClient)
|
||||
}
|
||||
else -> {
|
||||
|
|
|
@ -20,14 +20,11 @@
|
|||
package org.mariotaku.twidere.fragment
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.support.v4.app.DialogFragment
|
||||
import nl.komponents.kovenant.Promise
|
||||
import okhttp3.Dns
|
||||
import org.mariotaku.restfu.http.RestHttpClient
|
||||
import org.mariotaku.twidere.dagger.component.GeneralComponent
|
||||
import org.mariotaku.twidere.fragment.iface.IBaseFragment
|
||||
import org.mariotaku.twidere.util.DebugModeUtils
|
||||
import org.mariotaku.twidere.util.KeyboardShortcutsHandler
|
||||
import org.mariotaku.twidere.util.premium.ExtraFeaturesService
|
||||
import org.mariotaku.twidere.util.sync.DataSyncProvider
|
||||
|
@ -38,8 +35,6 @@ open class BaseDialogFragment : DialogFragment(), IBaseFragment<BaseDialogFragme
|
|||
@Inject
|
||||
lateinit var keyboardShortcutsHandler: KeyboardShortcutsHandler
|
||||
@Inject
|
||||
lateinit var dns: Dns
|
||||
@Inject
|
||||
lateinit var extraFeaturesService: ExtraFeaturesService
|
||||
@Inject
|
||||
lateinit var restHttpClient: RestHttpClient
|
||||
|
|
|
@ -25,7 +25,6 @@ import android.support.v4.app.Fragment
|
|||
import android.support.v4.text.BidiFormatter
|
||||
import android.view.View
|
||||
import nl.komponents.kovenant.Promise
|
||||
import okhttp3.Dns
|
||||
import org.mariotaku.restfu.http.RestHttpClient
|
||||
import org.mariotaku.twidere.dagger.component.GeneralComponent
|
||||
import org.mariotaku.twidere.fragment.iface.IBaseFragment
|
||||
|
@ -62,8 +61,6 @@ open class BaseFragment : Fragment(), IBaseFragment<BaseFragment> {
|
|||
@Inject
|
||||
lateinit var restHttpClient: RestHttpClient
|
||||
@Inject
|
||||
lateinit var dns: Dns
|
||||
@Inject
|
||||
lateinit var syncPreferences: SyncPreferences
|
||||
@Inject
|
||||
lateinit var externalThemeManager: ExternalThemeManager
|
||||
|
|
|
@ -78,7 +78,7 @@ class HostMappingsListFragment : AbsContentListViewFragment<HostMappingsListFrag
|
|||
when (item.itemId) {
|
||||
R.id.delete -> {
|
||||
val array = listView.checkedItemPositions ?: return false
|
||||
(dns as? TwidereDns)?.beginMappingTransaction {
|
||||
TwidereDns.get(context!!).beginMappingTransaction {
|
||||
(0 until array.size()).filter {
|
||||
array.valueAt(it)
|
||||
}.forEach {
|
||||
|
@ -207,7 +207,7 @@ class HostMappingsListFragment : AbsContentListViewFragment<HostMappingsListFrag
|
|||
} else {
|
||||
dialog.editAddress.string
|
||||
}).takeUnless(String?::isNullOrEmpty) ?: return
|
||||
(dns as? TwidereDns)?.putMapping(host, address)
|
||||
TwidereDns.get(context!!).putMapping(host, address)
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.mariotaku.twidere.extension.model.newMicroBlogInstance
|
|||
import org.mariotaku.twidere.extension.restfu.headers
|
||||
import org.mariotaku.twidere.extension.restfu.set
|
||||
import org.mariotaku.twidere.model.account.cred.OAuthCredentials
|
||||
import org.mariotaku.twidere.singleton.PreferencesSingleton
|
||||
import org.mariotaku.twidere.util.DataStoreUtils
|
||||
import org.mariotaku.twidere.util.MicroBlogAPIFactory
|
||||
import org.mariotaku.twidere.util.net.SystemDnsFetcher
|
||||
|
@ -106,9 +107,8 @@ class NetworkDiagnosticsFragment : BaseFragment() {
|
|||
logPrintln("Text below may have personal information, BE CAREFUL TO MAKE IT PUBLIC",
|
||||
LogText.State.WARNING)
|
||||
logPrintln()
|
||||
val holder = DependencyHolder.get(context)
|
||||
val dns = holder.dns
|
||||
val prefs = holder.preferences
|
||||
val dns = TwidereDns.get(context)
|
||||
val prefs = PreferencesSingleton.get(context)
|
||||
logPrintln(("Network preferences"))
|
||||
logPrintln(("using_resolver: ${prefs.getBoolean(KEY_BUILTIN_DNS_RESOLVER, false)}"))
|
||||
logPrintln(("tcp_dns_query: ${prefs.getBoolean(KEY_TCP_DNS_QUERY, false)}"))
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.mariotaku.twidere.R
|
|||
import org.mariotaku.twidere.annotation.TabAccountFlags
|
||||
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_USER
|
||||
import org.mariotaku.twidere.constant.iWantMyStarsBackKey
|
||||
import org.mariotaku.twidere.dagger.DependencyHolder
|
||||
import org.mariotaku.twidere.fragment.timeline.FavoritesTimelineFragment
|
||||
import org.mariotaku.twidere.model.Tab
|
||||
import org.mariotaku.twidere.model.tab.DrawableHolder
|
||||
|
@ -33,6 +32,7 @@ import org.mariotaku.twidere.model.tab.StringHolder
|
|||
import org.mariotaku.twidere.model.tab.TabConfiguration
|
||||
import org.mariotaku.twidere.model.tab.argument.UserArguments
|
||||
import org.mariotaku.twidere.model.tab.conf.UserExtraConfiguration
|
||||
import org.mariotaku.twidere.singleton.PreferencesSingleton
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2016/11/27.
|
||||
|
@ -67,7 +67,7 @@ class FavoriteTimelineTabConfiguration : TabConfiguration() {
|
|||
object FavoriteStringHolder : StringHolder() {
|
||||
|
||||
override fun createString(context: Context): String {
|
||||
if (DependencyHolder.get(context).preferences[iWantMyStarsBackKey]) {
|
||||
if (PreferencesSingleton.get(context)[iWantMyStarsBackKey]) {
|
||||
return context.getString(R.string.title_favorites)
|
||||
}
|
||||
return context.getString(R.string.title_likes)
|
||||
|
|
|
@ -32,7 +32,6 @@ import android.os.Handler
|
|||
import android.os.Looper
|
||||
import android.os.Process
|
||||
import android.support.v4.text.BidiFormatter
|
||||
import okhttp3.Dns
|
||||
import org.mariotaku.ktextension.isNullOrEmpty
|
||||
import org.mariotaku.ktextension.mapToArray
|
||||
import org.mariotaku.ktextension.toLongOr
|
||||
|
@ -69,8 +68,6 @@ class TwidereDataProvider : ContentProvider(), LazyLoadCallback {
|
|||
@Inject
|
||||
internal lateinit var notificationManager: NotificationManagerWrapper
|
||||
@Inject
|
||||
internal lateinit var dns: Dns
|
||||
@Inject
|
||||
internal lateinit var bidiFormatter: BidiFormatter
|
||||
@Inject
|
||||
internal lateinit var contentNotificationManager: ContentNotificationManager
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.mariotaku.twidere.constant.promotionsEnabledKey
|
|||
import org.mariotaku.twidere.dagger.DependencyHolder
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.promise.MessagePromises
|
||||
import org.mariotaku.twidere.singleton.PreferencesSingleton
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
|
||||
/**
|
||||
|
@ -84,7 +85,7 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||
|
||||
private fun setPromotionsEnabled(context: Context, intent: Intent, enabled: Boolean) {
|
||||
val holder = DependencyHolder.get(context)
|
||||
holder.preferences[promotionsEnabledKey] = enabled
|
||||
PreferencesSingleton.get(context)[promotionsEnabledKey] = enabled
|
||||
val notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1)
|
||||
if (notificationId != -1) {
|
||||
holder.notificationManager.cancel(notificationId)
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package org.mariotaku.twidere.singleton
|
||||
|
||||
import okhttp3.Cache
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants
|
||||
import org.mariotaku.twidere.extension.getCacheDir
|
||||
import org.mariotaku.twidere.util.lang.ApplicationContextSingletonHolder
|
||||
|
||||
object CacheSingleton : ApplicationContextSingletonHolder<Cache>(creator@{
|
||||
val preferences = PreferencesSingleton.get(it)
|
||||
val cacheSizeMB = preferences.getInt(SharedPreferenceConstants.KEY_CACHE_SIZE_LIMIT, 300).coerceIn(100..500)
|
||||
// Convert to bytes
|
||||
return@creator Cache(it.getCacheDir("network", cacheSizeMB * 1048576L), cacheSizeMB * 1048576L)
|
||||
})
|
|
@ -478,4 +478,5 @@ object Utils {
|
|||
context.applicationContext.sendBroadcast(intent)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -33,10 +33,13 @@ import okhttp3.Request
|
|||
import org.mariotaku.twidere.dagger.DependencyHolder
|
||||
import org.mariotaku.twidere.model.media.AuthenticatedUri
|
||||
import org.mariotaku.twidere.model.media.NoThumborUrl
|
||||
import org.mariotaku.twidere.singleton.CacheSingleton
|
||||
import org.mariotaku.twidere.singleton.PreferencesSingleton
|
||||
import org.mariotaku.twidere.util.HttpClientFactory
|
||||
import org.mariotaku.twidere.util.UserAgentUtils
|
||||
import org.mariotaku.twidere.util.glide.NoThumborUrlLoader.Companion.HEADER_NO_THUMBOR
|
||||
import org.mariotaku.twidere.util.media.ThumborWrapper
|
||||
import org.mariotaku.twidere.util.net.TwidereDns
|
||||
import org.mariotaku.twidere.util.okhttp.ModifyRequestInterceptor
|
||||
import java.io.InputStream
|
||||
|
||||
|
@ -49,9 +52,11 @@ class TwidereGlideModule : AppGlideModule() {
|
|||
override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
|
||||
val holder = DependencyHolder.get(context)
|
||||
val builder = OkHttpClient.Builder()
|
||||
val conf = HttpClientFactory.HttpClientConfiguration(holder.preferences)
|
||||
val conf = HttpClientFactory.HttpClientConfiguration(PreferencesSingleton.get(context))
|
||||
val thumbor = holder.thumbor
|
||||
HttpClientFactory.initOkHttpClient(conf, builder, holder.dns, holder.cache)
|
||||
val dns = TwidereDns.get(context)
|
||||
val cache = CacheSingleton.get(context)
|
||||
HttpClientFactory.initOkHttpClient(conf, builder, dns, cache)
|
||||
val userAgent = try {
|
||||
UserAgentUtils.getDefaultUserAgentStringSafe(context)
|
||||
} catch (e: Exception) {
|
||||
|
|
|
@ -26,15 +26,18 @@ import android.util.TimingLogger
|
|||
import okhttp3.Dns
|
||||
import org.mariotaku.ktextension.toIntOr
|
||||
import org.mariotaku.twidere.BuildConfig
|
||||
import org.mariotaku.twidere.Constants.*
|
||||
import org.mariotaku.twidere.TwidereConstants.HOST_MAPPING_PREFERENCES_NAME
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants.*
|
||||
import org.mariotaku.twidere.singleton.PreferencesSingleton
|
||||
import org.mariotaku.twidere.util.lang.ApplicationContextSingletonHolder
|
||||
import org.mariotaku.twidere.util.preference.PreferenceChangeNotifier
|
||||
import org.xbill.DNS.*
|
||||
import java.io.IOException
|
||||
import java.net.InetAddress
|
||||
import java.net.UnknownHostException
|
||||
import java.util.*
|
||||
|
||||
class TwidereDns(val context: Context, private val preferences: SharedPreferences) : Dns {
|
||||
class TwidereDns private constructor(val context: Context) : Dns {
|
||||
|
||||
private val hostMapping = context.getSharedPreferences(HOST_MAPPING_PREFERENCES_NAME,
|
||||
Context.MODE_PRIVATE)
|
||||
|
@ -44,6 +47,11 @@ class TwidereDns(val context: Context, private val preferences: SharedPreference
|
|||
private var useResolver: Boolean = false
|
||||
|
||||
init {
|
||||
PreferenceChangeNotifier.get(context).register(KEY_DNS_SERVER, KEY_TCP_DNS_QUERY,
|
||||
KEY_BUILTIN_DNS_RESOLVER) {
|
||||
reloadDnsSettings()
|
||||
}
|
||||
|
||||
reloadDnsSettings()
|
||||
}
|
||||
|
||||
|
@ -75,6 +83,7 @@ class TwidereDns(val context: Context, private val preferences: SharedPreference
|
|||
|
||||
fun reloadDnsSettings() {
|
||||
this.resolver = null
|
||||
val preferences = PreferencesSingleton.get(context)
|
||||
useResolver = preferences.getBoolean(KEY_BUILTIN_DNS_RESOLVER, false)
|
||||
}
|
||||
|
||||
|
@ -197,9 +206,10 @@ class TwidereDns(val context: Context, private val preferences: SharedPreference
|
|||
|
||||
private fun getResolver(): Resolver {
|
||||
return this.resolver ?: run {
|
||||
val preferences = PreferencesSingleton.get(context)
|
||||
val tcp = preferences.getBoolean(KEY_TCP_DNS_QUERY, false)
|
||||
val servers = preferences.getString(KEY_DNS_SERVER, null)?.split(';', ',', ' ') ?:
|
||||
SystemDnsFetcher.get(context)
|
||||
val servers = preferences.getString(KEY_DNS_SERVER, null)?.split(';', ',', ' ')
|
||||
?: SystemDnsFetcher.get(context)
|
||||
val resolvers = servers?.mapNotNull {
|
||||
val segs = it.split("#", limit = 2)
|
||||
if (segs.isEmpty()) return@mapNotNull null
|
||||
|
@ -232,7 +242,7 @@ class TwidereDns(val context: Context, private val preferences: SharedPreference
|
|||
return listOf(resolved)
|
||||
}
|
||||
|
||||
companion object {
|
||||
companion object : ApplicationContextSingletonHolder<TwidereDns>(::TwidereDns) {
|
||||
|
||||
private val RESOLVER_LOGTAG = "TwidereDns"
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ import org.mariotaku.twidere.fragment.BaseFragment
|
|||
import org.mariotaku.twidere.model.ParcelableUser
|
||||
import org.mariotaku.twidere.model.ParcelableUserList
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.singleton.PreferencesSingleton
|
||||
import org.mariotaku.twidere.util.IntentUtils
|
||||
import org.mariotaku.twidere.util.UserColorNameManager
|
||||
import org.mariotaku.twidere.util.glide.DeferredTarget
|
||||
|
@ -60,7 +61,7 @@ object ShortcutCreator {
|
|||
|
||||
fun user(context: Context, accountKey: UserKey?, user: ParcelableUser): Promise<ShortcutInfoCompat, Exception> {
|
||||
val holder = DependencyHolder.get(context)
|
||||
val preferences = holder.preferences
|
||||
val preferences = PreferencesSingleton.get(context)
|
||||
val userColorNameManager = UserColorNameManager.get(context)
|
||||
|
||||
val profileImageStyle = if (useAdaptiveIcon) ImageShapeStyle.SHAPE_RECTANGLE else preferences[profileImageStyleKey]
|
||||
|
@ -84,7 +85,7 @@ object ShortcutCreator {
|
|||
|
||||
fun userFavorites(context: Context, accountKey: UserKey?, user: ParcelableUser): Promise<ShortcutInfoCompat, Exception> {
|
||||
val holder = DependencyHolder.get(context)
|
||||
val preferences = holder.preferences
|
||||
val preferences = PreferencesSingleton.get(context)
|
||||
val userColorNameManager = UserColorNameManager.get(context)
|
||||
|
||||
val launchIntent = IntentUtils.userFavorites(accountKey, user.key,
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.mariotaku.twidere.constant.themeBackgroundOptionKey
|
|||
import org.mariotaku.twidere.dagger.DependencyHolder
|
||||
import org.mariotaku.twidere.extension.view.measureChildIgnoringInsets
|
||||
import org.mariotaku.twidere.graphic.drawable.userprofile.ActionBarDrawable
|
||||
import org.mariotaku.twidere.singleton.PreferencesSingleton
|
||||
import org.mariotaku.twidere.util.ThemeUtils
|
||||
|
||||
internal class HeaderBehavior(context: Context, attrs: AttributeSet? = null) :
|
||||
|
@ -54,7 +55,7 @@ internal class HeaderBehavior(context: Context, attrs: AttributeSet? = null) :
|
|||
|
||||
init {
|
||||
cardBackgroundColor = if (context.hasApplication) {
|
||||
val preferences = DependencyHolder.get(context).preferences
|
||||
val preferences = PreferencesSingleton.get(context)
|
||||
ThemeUtils.getCardBackgroundColor(context,
|
||||
preferences[themeBackgroundOptionKey], preferences[themeBackgroundAlphaKey])
|
||||
} else {
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/send"
|
||||
android:icon="@drawable/ic_action_send"
|
||||
android:title="@string/action_send"
|
||||
app:showAsAction="always" />
|
||||
</menu>
|
Loading…
Reference in New Issue