code cleanup
This commit is contained in:
parent
868b69e2c7
commit
57fa9b854a
|
@ -44,8 +44,8 @@ subprojects {
|
|||
Kotlin : "${kotlinVersion}",
|
||||
SupportLib : '27.0.1',
|
||||
SupportTest : '1.0.0',
|
||||
MariotakuCommons : '0.9.20',
|
||||
RestFu : '0.9.60',
|
||||
MariotakuCommons : '0.9.21',
|
||||
RestFu : '0.9.61',
|
||||
ObjectCursor : '0.9.21',
|
||||
PlayServices : '11.6.0',
|
||||
PlayBilling : '1.0',
|
||||
|
|
|
@ -50,6 +50,8 @@ android {
|
|||
}
|
||||
|
||||
dexOptions {
|
||||
additionalParameters += '--minimal-main-dex'
|
||||
additionalParameters += '--set-max-idx-number=48000'
|
||||
}
|
||||
|
||||
aaptOptions {
|
||||
|
@ -255,12 +257,13 @@ dependencies {
|
|||
implementation "com.github.mariotaku.ObjectCursor:core:${libVersions['ObjectCursor']}"
|
||||
implementation "com.github.mariotaku.ExportablePreferences:core:${libVersions['ExportablePreferences']}"
|
||||
implementation "com.github.mariotaku:AbstractTask:${libVersions['AbstractTask']}"
|
||||
implementation "com.github.mariotaku.CommonsLibrary:parcel:${libVersions['MariotakuCommons']}"
|
||||
implementation "com.github.mariotaku.CommonsLibrary:collection:${libVersions['MariotakuCommons']}"
|
||||
implementation "com.github.mariotaku.CommonsLibrary:io:${libVersions['MariotakuCommons']}"
|
||||
implementation "com.github.mariotaku.CommonsLibrary:logansquare:${libVersions['MariotakuCommons']}"
|
||||
implementation "com.github.mariotaku.CommonsLibrary:objectcursor:${libVersions['MariotakuCommons']}"
|
||||
implementation "com.github.mariotaku.CommonsLibrary:parcel:${libVersions['MariotakuCommons']}"
|
||||
implementation "com.github.mariotaku.CommonsLibrary:text:${libVersions['MariotakuCommons']}"
|
||||
implementation "com.github.mariotaku.CommonsLibrary:text-kotlin:${libVersions['MariotakuCommons']}"
|
||||
implementation "com.github.mariotaku.CommonsLibrary:objectcursor:${libVersions['MariotakuCommons']}"
|
||||
implementation "com.github.mariotaku.CommonsLibrary:logansquare:${libVersions['MariotakuCommons']}"
|
||||
implementation "com.github.mariotaku:KPreferences:${libVersions['KPreferences']}"
|
||||
implementation "com.github.mariotaku:Chameleon:${libVersions['Chameleon']}"
|
||||
implementation "com.github.mariotaku.UniqR:android:${libVersions['UniqR']}"
|
||||
|
|
|
@ -1054,10 +1054,10 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
|
|||
builder.setTitle(R.string.auto_refresh)
|
||||
builder.setMessage(R.string.message_auto_refresh_confirm)
|
||||
builder.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
kPreferences[defaultAutoRefreshKey] = true
|
||||
preferences[defaultAutoRefreshKey] = true
|
||||
}
|
||||
builder.setNegativeButton(R.string.action_no_thanks) { _, _ ->
|
||||
kPreferences[defaultAutoRefreshKey] = false
|
||||
preferences[defaultAutoRefreshKey] = false
|
||||
}
|
||||
val dialog = builder.create()
|
||||
dialog.onShow { it.applyTheme() }
|
||||
|
@ -1065,7 +1065,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
|
|||
}
|
||||
|
||||
override fun onDismiss(dialog: DialogInterface?) {
|
||||
kPreferences[defaultAutoRefreshAskedKey] = true
|
||||
preferences[defaultAutoRefreshAskedKey] = true
|
||||
super.onDismiss(dialog)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,11 +34,8 @@ import com.bumptech.glide.Glide
|
|||
import nl.komponents.kovenant.android.startKovenant
|
||||
import nl.komponents.kovenant.android.stopKovenant
|
||||
import nl.komponents.kovenant.task
|
||||
import okhttp3.Dns
|
||||
import org.mariotaku.kpreferences.KPreferences
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.kpreferences.set
|
||||
import org.mariotaku.mediaviewer.library.MediaDownloader
|
||||
import org.mariotaku.restfu.http.RestHttpClient
|
||||
import org.mariotaku.twidere.BuildConfig
|
||||
import org.mariotaku.twidere.Constants
|
||||
|
@ -58,10 +55,6 @@ import org.mariotaku.twidere.util.*
|
|||
import org.mariotaku.twidere.util.content.TwidereSQLiteOpenHelper
|
||||
import org.mariotaku.twidere.util.dagger.GeneralComponent
|
||||
import org.mariotaku.twidere.util.emoji.EmojiOneShortCodeMap
|
||||
import org.mariotaku.twidere.util.media.MediaPreloader
|
||||
import org.mariotaku.twidere.util.media.ThumborWrapper
|
||||
import org.mariotaku.twidere.util.net.TwidereDns
|
||||
import org.mariotaku.twidere.util.notification.ContentNotificationManager
|
||||
import org.mariotaku.twidere.util.notification.NotificationChannelsManager
|
||||
import org.mariotaku.twidere.util.premium.ExtraFeaturesService
|
||||
import org.mariotaku.twidere.util.promotion.PromotionService
|
||||
|
@ -79,16 +72,10 @@ class TwidereApplication : Application(), OnSharedPreferenceChangeListener {
|
|||
@Inject
|
||||
lateinit internal var restHttpClient: RestHttpClient
|
||||
@Inject
|
||||
lateinit internal var dns: Dns
|
||||
@Inject
|
||||
lateinit internal var mediaDownloader: MediaDownloader
|
||||
@Inject
|
||||
lateinit internal var defaultFeatures: DefaultFeatures
|
||||
@Inject
|
||||
lateinit internal var externalThemeManager: ExternalThemeManager
|
||||
@Inject
|
||||
lateinit internal var kPreferences: KPreferences
|
||||
@Inject
|
||||
lateinit internal var autoRefreshController: AutoRefreshController
|
||||
@Inject
|
||||
lateinit internal var syncController: SyncController
|
||||
|
@ -96,12 +83,6 @@ class TwidereApplication : Application(), OnSharedPreferenceChangeListener {
|
|||
lateinit internal var extraFeaturesService: ExtraFeaturesService
|
||||
@Inject
|
||||
lateinit internal var promotionService: PromotionService
|
||||
@Inject
|
||||
lateinit internal var mediaPreloader: MediaPreloader
|
||||
@Inject
|
||||
lateinit internal var contentNotificationManager: ContentNotificationManager
|
||||
@Inject
|
||||
lateinit internal var thumbor: ThumborWrapper
|
||||
|
||||
val sqLiteDatabase: SQLiteDatabase by lazy {
|
||||
StrictModeUtils.checkDiskIO()
|
||||
|
@ -181,9 +162,6 @@ class TwidereApplication : Application(), OnSharedPreferenceChangeListener {
|
|||
KEY_PROXY_PASSWORD, KEY_CONNECTION_TIMEOUT, KEY_RETRY_ON_NETWORK_ISSUE -> {
|
||||
HttpClientFactory.reloadConnectivitySettings(this)
|
||||
}
|
||||
KEY_DNS_SERVER, KEY_TCP_DNS_QUERY, KEY_BUILTIN_DNS_RESOLVER -> {
|
||||
reloadDnsSettings()
|
||||
}
|
||||
KEY_CREDENTIALS_TYPE, KEY_API_URL_FORMAT, KEY_CONSUMER_KEY, KEY_CONSUMER_SECRET,
|
||||
KEY_SAME_OAUTH_SIGNING_URL -> {
|
||||
preferences[apiLastChangeKey] = System.currentTimeMillis()
|
||||
|
@ -191,15 +169,6 @@ class TwidereApplication : Application(), OnSharedPreferenceChangeListener {
|
|||
KEY_EMOJI_SUPPORT -> {
|
||||
externalThemeManager.reloadEmojiPreferences()
|
||||
}
|
||||
KEY_THUMBOR_ENABLED, KEY_THUMBOR_ADDRESS, KEY_THUMBOR_SECURITY_KEY -> {
|
||||
thumbor.reloadSettings(preferences)
|
||||
}
|
||||
KEY_MEDIA_PRELOAD, KEY_PRELOAD_WIFI_ONLY -> {
|
||||
mediaPreloader.reloadOptions(preferences)
|
||||
}
|
||||
KEY_NAME_FIRST, KEY_I_WANT_MY_STARS_BACK -> {
|
||||
contentNotificationManager.updatePreferences()
|
||||
}
|
||||
streamingEnabledKey.key, streamingPowerSavingKey.key,
|
||||
streamingNonMeteredNetworkKey.key -> {
|
||||
val streamingIntent = Intent(this, StreamingService::class.java)
|
||||
|
@ -228,7 +197,7 @@ class TwidereApplication : Application(), OnSharedPreferenceChangeListener {
|
|||
}
|
||||
|
||||
private fun loadDefaultFeatures() {
|
||||
val lastUpdated = kPreferences[defaultFeatureLastUpdated]
|
||||
val lastUpdated = sharedPreferences[defaultFeatureLastUpdated]
|
||||
if (lastUpdated > 0 && TimeUnit.MILLISECONDS.toHours(System.currentTimeMillis() - lastUpdated) < 12) {
|
||||
return
|
||||
}
|
||||
|
@ -240,7 +209,7 @@ class TwidereApplication : Application(), OnSharedPreferenceChangeListener {
|
|||
}.fail {
|
||||
DebugLog.w(LOGTAG, "Unable to load remote features", it)
|
||||
}.always {
|
||||
kPreferences[defaultFeatureLastUpdated] = System.currentTimeMillis()
|
||||
sharedPreferences[defaultFeatureLastUpdated] = System.currentTimeMillis()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -294,10 +263,6 @@ class TwidereApplication : Application(), OnSharedPreferenceChangeListener {
|
|||
Analyzer.init(this)
|
||||
}
|
||||
|
||||
private fun reloadDnsSettings() {
|
||||
(dns as? TwidereDns)?.reloadDnsSettings()
|
||||
}
|
||||
|
||||
private fun initializeAsyncTask() {
|
||||
// AsyncTask class needs to be loaded in UI thread.
|
||||
// So we load it here to comply the rule.
|
||||
|
@ -312,9 +277,7 @@ class TwidereApplication : Application(), OnSharedPreferenceChangeListener {
|
|||
var instance: TwidereApplication? = null
|
||||
private set
|
||||
|
||||
fun getInstance(context: Context): TwidereApplication {
|
||||
return context.applicationContext as TwidereApplication
|
||||
}
|
||||
fun getInstance(context: Context) = context.applicationContext as TwidereApplication
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,11 +41,12 @@ import okhttp3.Cache
|
|||
import okhttp3.ConnectionPool
|
||||
import okhttp3.Dns
|
||||
import okhttp3.OkHttpClient
|
||||
import org.mariotaku.kpreferences.KPreferences
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.mediaviewer.library.FileCache
|
||||
import org.mariotaku.mediaviewer.library.MediaDownloader
|
||||
import org.mariotaku.restfu.http.RestHttpClient
|
||||
import org.mariotaku.twidere.Constants
|
||||
import org.mariotaku.twidere.TwidereConstants.*
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_CACHE_SIZE_LIMIT
|
||||
import org.mariotaku.twidere.constant.autoRefreshCompatibilityModeKey
|
||||
import org.mariotaku.twidere.extension.model.load
|
||||
|
@ -59,12 +60,12 @@ import org.mariotaku.twidere.util.media.ThumborWrapper
|
|||
import org.mariotaku.twidere.util.media.TwidereMediaDownloader
|
||||
import org.mariotaku.twidere.util.net.TwidereDns
|
||||
import org.mariotaku.twidere.util.notification.ContentNotificationManager
|
||||
import org.mariotaku.twidere.util.preference.PreferenceChangeNotifier
|
||||
import org.mariotaku.twidere.util.refresh.AutoRefreshController
|
||||
import org.mariotaku.twidere.util.refresh.JobSchedulerAutoRefreshController
|
||||
import org.mariotaku.twidere.util.refresh.LegacyAutoRefreshController
|
||||
import org.mariotaku.twidere.util.schedule.StatusScheduleProvider
|
||||
import org.mariotaku.twidere.util.sync.*
|
||||
import org.mariotaku.twidere.util.text.TwitterValidator
|
||||
import java.io.File
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
@ -103,8 +104,8 @@ class ApplicationModule(private val application: Application) {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun kPreferences(sharedPreferences: SharedPreferences): KPreferences {
|
||||
return KPreferences(sharedPreferences)
|
||||
fun preferenceChangeNotifier(preferences: SharedPreferences): PreferenceChangeNotifier {
|
||||
return PreferenceChangeNotifier(preferences)
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -167,25 +168,37 @@ class ApplicationModule(private val application: Application) {
|
|||
@Provides
|
||||
@Singleton
|
||||
fun contentNotificationManager(activityTracker: ActivityTracker, userColorNameManager: UserColorNameManager,
|
||||
notificationManagerWrapper: NotificationManagerWrapper,
|
||||
preferences: SharedPreferences): ContentNotificationManager {
|
||||
return ContentNotificationManager(application, activityTracker, userColorNameManager, notificationManagerWrapper, preferences)
|
||||
notificationManagerWrapper: NotificationManagerWrapper, preferences: SharedPreferences,
|
||||
notifier: PreferenceChangeNotifier): ContentNotificationManager {
|
||||
val manager = ContentNotificationManager(application, activityTracker, userColorNameManager,
|
||||
notificationManagerWrapper, preferences)
|
||||
notifier.register(KEY_NAME_FIRST, KEY_I_WANT_MY_STARS_BACK) {
|
||||
manager.updatePreferences()
|
||||
}
|
||||
return manager
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun mediaLoaderWrapper(preferences: SharedPreferences): MediaPreloader {
|
||||
fun mediaPreloader(preferences: SharedPreferences, notifier: PreferenceChangeNotifier): MediaPreloader {
|
||||
val preloader = MediaPreloader(application)
|
||||
preloader.reloadOptions(preferences)
|
||||
val cm = application.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||
preloader.isNetworkMetered = ConnectivityManagerCompat.isActiveNetworkMetered(cm)
|
||||
notifier.register(KEY_MEDIA_PRELOAD, KEY_PRELOAD_WIFI_ONLY) {
|
||||
preloader.reloadOptions(preferences)
|
||||
}
|
||||
return preloader
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun dns(preferences: SharedPreferences): Dns {
|
||||
return TwidereDns(application, preferences)
|
||||
fun dns(preferences: SharedPreferences, notifier: PreferenceChangeNotifier): Dns {
|
||||
val dns = TwidereDns(application, preferences)
|
||||
notifier.register(KEY_DNS_SERVER, KEY_TCP_DNS_QUERY, KEY_BUILTIN_DNS_RESOLVER) {
|
||||
dns.reloadDnsSettings()
|
||||
}
|
||||
return dns
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -208,9 +221,12 @@ class ApplicationModule(private val application: Application) {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun thumborWrapper(preferences: SharedPreferences): ThumborWrapper {
|
||||
fun thumborWrapper(preferences: SharedPreferences, notifier: PreferenceChangeNotifier): ThumborWrapper {
|
||||
val thumbor = ThumborWrapper()
|
||||
thumbor.reloadSettings(preferences)
|
||||
notifier.register(KEY_THUMBOR_ENABLED, KEY_THUMBOR_ADDRESS, KEY_THUMBOR_SECURITY_KEY) {
|
||||
thumbor.reloadSettings(preferences)
|
||||
}
|
||||
return thumbor
|
||||
}
|
||||
|
||||
|
@ -221,11 +237,11 @@ class ApplicationModule(private val application: Application) {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun autoRefreshController(kPreferences: KPreferences): AutoRefreshController {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !kPreferences[autoRefreshCompatibilityModeKey]) {
|
||||
return JobSchedulerAutoRefreshController(application, kPreferences)
|
||||
fun autoRefreshController(preferences: SharedPreferences): AutoRefreshController {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !preferences[autoRefreshCompatibilityModeKey]) {
|
||||
return JobSchedulerAutoRefreshController(application, preferences)
|
||||
}
|
||||
return LegacyAutoRefreshController(application, kPreferences)
|
||||
return LegacyAutoRefreshController(application, preferences)
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.mariotaku.twidere.fragment
|
||||
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_AUTO_REFRESH
|
||||
import org.mariotaku.twidere.constant.defaultAutoRefreshKey
|
||||
|
@ -29,7 +30,7 @@ class AccountRefreshSettingsFragment : BaseAccountPreferenceFragment() {
|
|||
get() = R.xml.preferences_account_refresh
|
||||
|
||||
override val switchPreferenceDefault: Boolean
|
||||
get() = kPreferences[defaultAutoRefreshKey]
|
||||
get() = preferences[defaultAutoRefreshKey]
|
||||
|
||||
override val switchPreferenceKey: String?
|
||||
get() = KEY_AUTO_REFRESH
|
||||
|
|
|
@ -27,7 +27,6 @@ import com.bumptech.glide.Glide
|
|||
import com.bumptech.glide.RequestManager
|
||||
import com.squareup.otto.Bus
|
||||
import okhttp3.Dns
|
||||
import org.mariotaku.kpreferences.KPreferences
|
||||
import org.mariotaku.restfu.http.RestHttpClient
|
||||
import org.mariotaku.twidere.util.AsyncTwitterWrapper
|
||||
import org.mariotaku.twidere.util.DebugModeUtils
|
||||
|
@ -46,8 +45,6 @@ open class BaseDialogFragment : DialogFragment() {
|
|||
@Inject
|
||||
lateinit var preferences: SharedPreferences
|
||||
@Inject
|
||||
lateinit var kPreferences: KPreferences
|
||||
@Inject
|
||||
lateinit var keyboardShortcutsHandler: KeyboardShortcutsHandler
|
||||
@Inject
|
||||
lateinit var bus: Bus
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.mariotaku.twidere.fragment
|
|||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.graphics.Rect
|
||||
import android.media.RingtoneManager
|
||||
import android.net.Uri
|
||||
|
@ -31,7 +32,6 @@ import android.support.v7.preference.Preference
|
|||
import android.support.v7.preference.PreferenceFragmentCompat
|
||||
import com.squareup.otto.Bus
|
||||
import nl.komponents.kovenant.Promise
|
||||
import org.mariotaku.kpreferences.KPreferences
|
||||
import org.mariotaku.twidere.fragment.iface.IBaseFragment
|
||||
import org.mariotaku.twidere.preference.RingtonePreference
|
||||
import org.mariotaku.twidere.util.KeyboardShortcutsHandler
|
||||
|
@ -48,7 +48,7 @@ abstract class BasePreferenceFragment : PreferenceFragmentCompat(), IBaseFragmen
|
|||
@Inject
|
||||
lateinit var userColorNameManager: UserColorNameManager
|
||||
@Inject
|
||||
lateinit var kPreferences: KPreferences
|
||||
lateinit var preferences: SharedPreferences
|
||||
@Inject
|
||||
lateinit var syncController: SyncController
|
||||
@Inject
|
||||
|
|
|
@ -35,7 +35,7 @@ class CreateUserBlockDialogFragment : AbsUserMuteBlockDialogFragment() {
|
|||
}
|
||||
|
||||
override fun getTitle(user: ParcelableUser): String {
|
||||
val displayName = userColorNameManager.getDisplayName(user, kPreferences[nameFirstKey])
|
||||
val displayName = userColorNameManager.getDisplayName(user, preferences[nameFirstKey])
|
||||
return getString(R.string.title_block_user, displayName)
|
||||
}
|
||||
|
||||
|
|
|
@ -253,13 +253,13 @@ class NetworkDiagnosticsFragment : BaseFragment() {
|
|||
}
|
||||
|
||||
override fun onPreExecute() {
|
||||
val fragment = fragment ?: return
|
||||
val fragment = fragment?.takeUnless { it.isDetached } ?: return
|
||||
fragment.diagStart()
|
||||
super.onPreExecute()
|
||||
}
|
||||
|
||||
override fun onPostExecute(u: Unit) {
|
||||
val fragment = fragment ?: return
|
||||
val fragment = fragment?.takeUnless { it.isDetached } ?: return
|
||||
logPrintln()
|
||||
logPrintln(("Done. You can send this log to me, and I'll contact you to solve related issue."))
|
||||
fragment.logReady()
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.mariotaku.twidere.fragment
|
||||
|
||||
import android.support.v4.app.FragmentManager
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.ktextension.Bundle
|
||||
import org.mariotaku.ktextension.set
|
||||
import org.mariotaku.twidere.R
|
||||
|
@ -30,12 +31,12 @@ import org.mariotaku.twidere.promise.BlockPromises
|
|||
|
||||
class ReportUserSpamDialogFragment : AbsUserMuteBlockDialogFragment() {
|
||||
override fun getMessage(user: ParcelableUser): String {
|
||||
val displayName = userColorNameManager.getDisplayName(user, kPreferences[nameFirstKey])
|
||||
val displayName = userColorNameManager.getDisplayName(user, preferences[nameFirstKey])
|
||||
return getString(R.string.report_user_confirm_message, displayName)
|
||||
}
|
||||
|
||||
override fun getTitle(user: ParcelableUser): String {
|
||||
val displayName = userColorNameManager.getDisplayName(user, kPreferences[nameFirstKey])
|
||||
val displayName = userColorNameManager.getDisplayName(user, preferences[nameFirstKey])
|
||||
return getString(R.string.report_user, displayName)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.accounts.AccountManager
|
|||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.database.Cursor
|
||||
import android.graphics.PorterDuff
|
||||
import android.net.Uri
|
||||
|
@ -22,7 +23,6 @@ import com.bumptech.glide.RequestManager
|
|||
import kotlinx.android.synthetic.main.fragment_content_listview.*
|
||||
import nl.komponents.kovenant.then
|
||||
import nl.komponents.kovenant.ui.alwaysUi
|
||||
import org.mariotaku.kpreferences.KPreferences
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.ktextension.*
|
||||
import org.mariotaku.library.objectcursor.ObjectCursor
|
||||
|
@ -235,7 +235,7 @@ class FilteredUsersFragment : BaseFiltersFragment() {
|
|||
@Inject
|
||||
lateinit var userColorNameManager: UserColorNameManager
|
||||
@Inject
|
||||
lateinit var preferences: KPreferences
|
||||
lateinit var preferences: SharedPreferences
|
||||
|
||||
private val nameFirst: Boolean
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@ import android.view.MenuItem
|
|||
import com.squareup.otto.Subscribe
|
||||
import nl.komponents.kovenant.combine.and
|
||||
import nl.komponents.kovenant.ui.alwaysUi
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.kpreferences.set
|
||||
import org.mariotaku.ktextension.toWeak
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.TwidereConstants.SYNC_PREFERENCES_NAME
|
||||
|
@ -29,7 +31,7 @@ class SyncSettingsFragment : BasePreferenceFragment() {
|
|||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
|
||||
syncProvider = kPreferences[dataSyncProviderInfoKey]
|
||||
syncProvider = preferences[dataSyncProviderInfoKey]
|
||||
setHasOptionsMenu(true)
|
||||
}
|
||||
|
||||
|
@ -59,7 +61,7 @@ class SyncSettingsFragment : BasePreferenceFragment() {
|
|||
df.show(childFragmentManager, "disconnect_confirm")
|
||||
}
|
||||
R.id.sync_now -> {
|
||||
val providerInfo = kPreferences[dataSyncProviderInfoKey]!!
|
||||
val providerInfo = preferences[dataSyncProviderInfoKey]!!
|
||||
syncController.performSync(providerInfo)
|
||||
}
|
||||
else -> {
|
||||
|
@ -75,14 +77,14 @@ class SyncSettingsFragment : BasePreferenceFragment() {
|
|||
}
|
||||
|
||||
private fun cleanupAndDisconnect() {
|
||||
val providerInfo = kPreferences[dataSyncProviderInfoKey] ?: return
|
||||
val providerInfo = preferences[dataSyncProviderInfoKey] ?: return
|
||||
val weakThis = toWeak()
|
||||
val task = showProgressDialog("cleanup_sync_cache").
|
||||
and(syncController.cleanupSyncCache(providerInfo))
|
||||
task.alwaysUi {
|
||||
val f = weakThis.get() ?: return@alwaysUi
|
||||
f.dismissProgressDialog("cleanup_sync_cache")
|
||||
f.kPreferences[dataSyncProviderInfoKey] = null
|
||||
f.preferences[dataSyncProviderInfoKey] = null
|
||||
DataSyncProvider.Factory.notifyUpdate(f.context!!)
|
||||
f.activity?.finish()
|
||||
}
|
||||
|
@ -91,7 +93,7 @@ class SyncSettingsFragment : BasePreferenceFragment() {
|
|||
class DisconnectSyncConfirmDialogFragment : BaseDialogFragment() {
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val builder = AlertDialog.Builder(context!!)
|
||||
val providerInfo = kPreferences[dataSyncProviderInfoKey]!!
|
||||
val providerInfo = preferences[dataSyncProviderInfoKey]!!
|
||||
val entry = DataSyncProvider.Factory.getProviderEntry(context!!, providerInfo.type)!!
|
||||
builder.setMessage(getString(R.string.message_sync_disconnect_from_name_confirm, entry.name))
|
||||
builder.setPositiveButton(R.string.action_sync_disconnect) { _, _ ->
|
||||
|
|
|
@ -22,10 +22,11 @@ package org.mariotaku.twidere.service
|
|||
import android.annotation.TargetApi
|
||||
import android.app.job.JobParameters
|
||||
import android.app.job.JobService
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Build
|
||||
import nl.komponents.kovenant.ui.failUi
|
||||
import nl.komponents.kovenant.ui.successUi
|
||||
import org.mariotaku.kpreferences.KPreferences
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.ktextension.deadline
|
||||
import org.mariotaku.twidere.annotation.AutoRefreshType
|
||||
import org.mariotaku.twidere.constant.autoRefreshCompatibilityModeKey
|
||||
|
@ -42,7 +43,7 @@ class JobTaskService : JobService() {
|
|||
@Inject
|
||||
internal lateinit var taskServiceRunner: TaskServiceRunner
|
||||
@Inject
|
||||
internal lateinit var kPreferences: KPreferences
|
||||
internal lateinit var preferences: SharedPreferences
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
@ -50,7 +51,7 @@ class JobTaskService : JobService() {
|
|||
}
|
||||
|
||||
override fun onStartJob(params: JobParameters): Boolean {
|
||||
if (kPreferences[autoRefreshCompatibilityModeKey]) return false
|
||||
if (preferences[autoRefreshCompatibilityModeKey]) return false
|
||||
val action = getTaskAction(params.jobId) ?: return false
|
||||
val promise = taskServiceRunner.createPromise(action) ?: return false
|
||||
promise.deadline(3, TimeUnit.MINUTES).successUi {
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.content.SharedPreferences
|
|||
import com.squareup.otto.Bus
|
||||
import com.twitter.Extractor
|
||||
import org.mariotaku.abstask.library.AbstractTask
|
||||
import org.mariotaku.kpreferences.KPreferences
|
||||
import org.mariotaku.restfu.http.RestHttpClient
|
||||
import org.mariotaku.twidere.model.DefaultFeatures
|
||||
import org.mariotaku.twidere.util.AsyncTwitterWrapper
|
||||
|
@ -32,8 +31,6 @@ abstract class BaseAbstractTask<Params, Result, Callback>(val context: Context)
|
|||
@Inject
|
||||
lateinit var preferences: SharedPreferences
|
||||
@Inject
|
||||
lateinit var kPreferences: KPreferences
|
||||
@Inject
|
||||
lateinit var manager: UserColorNameManager
|
||||
@Inject
|
||||
lateinit var errorInfoStore: ErrorInfoStore
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.mariotaku.twidere.task
|
|||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.widget.Toast
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.microblog.library.MicroBlog
|
||||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.mastodon.Mastodon
|
||||
|
@ -80,7 +81,7 @@ class CreateUserMuteTask(
|
|||
}
|
||||
|
||||
override fun showSucceededMessage(params: AbsFriendshipOperationTask.Arguments, user: ParcelableUser) {
|
||||
val nameFirst = kPreferences[nameFirstKey]
|
||||
val nameFirst = preferences[nameFirstKey]
|
||||
val message = context.getString(R.string.muted_user, manager.getDisplayName(user,
|
||||
nameFirst))
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.mariotaku.twidere.task
|
|||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.widget.Toast
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.microblog.library.MicroBlog
|
||||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.mastodon.Mastodon
|
||||
|
@ -53,7 +54,7 @@ class DestroyUserMuteTask(context: Context) : AbsFriendshipOperationTask(context
|
|||
}
|
||||
|
||||
override fun showSucceededMessage(params: AbsFriendshipOperationTask.Arguments, user: ParcelableUser) {
|
||||
val nameFirst = kPreferences[nameFirstKey]
|
||||
val nameFirst = preferences[nameFirstKey]
|
||||
val message = context.getString(R.string.unmuted_user, manager.getDisplayName(user, nameFirst))
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ import android.content.SharedPreferences
|
|||
import okhttp3.Cache
|
||||
import okhttp3.ConnectionPool
|
||||
import okhttp3.Dns
|
||||
import org.mariotaku.kpreferences.KPreferences
|
||||
import org.mariotaku.restfu.http.RestHttpClient
|
||||
import org.mariotaku.twidere.model.DefaultFeatures
|
||||
import org.mariotaku.twidere.util.*
|
||||
|
@ -72,9 +71,6 @@ class DependencyHolder internal constructor(context: Context) {
|
|||
lateinit var userColorNameManager: UserColorNameManager
|
||||
internal set
|
||||
@Inject
|
||||
lateinit var kPreferences: KPreferences
|
||||
internal set
|
||||
@Inject
|
||||
lateinit var thumbor: ThumborWrapper
|
||||
internal set
|
||||
@Inject
|
||||
|
|
|
@ -1,150 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Mark Platvoet<mplatvoet@gmail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
@file:JvmName("KovenantTwidere")
|
||||
|
||||
package org.mariotaku.twidere.util.kovenant
|
||||
|
||||
import android.os.AsyncTask
|
||||
import android.os.Process
|
||||
import nl.komponents.kovenant.Dispatcher
|
||||
import nl.komponents.kovenant.Kovenant
|
||||
import nl.komponents.kovenant.android.Disposable
|
||||
import nl.komponents.kovenant.android.androidUiDispatcher
|
||||
import nl.komponents.kovenant.buildJvmDispatcher
|
||||
import nl.komponents.kovenant.ui.KovenantUi
|
||||
import java.util.concurrent.Executor
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
private val initCount = AtomicInteger(0)
|
||||
private val disposable = AtomicReference<Disposable>(null)
|
||||
|
||||
fun startKovenant() {
|
||||
initCount.onlyFirst {
|
||||
disposable.set(configureKovenant())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@JvmOverloads fun stopKovenant(force: Boolean = false) {
|
||||
val dispose = disposable.get()
|
||||
if (dispose != null && disposable.compareAndSet(dispose, null)) {
|
||||
dispose.close(force)
|
||||
initCount.set(0)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures Kovenant for common Android scenarios.
|
||||
*
|
||||
* @return `Disposable` to properly shutdown Kovenant
|
||||
*/
|
||||
fun configureKovenant(): Disposable {
|
||||
KovenantUi.uiContext {
|
||||
dispatcher = androidUiDispatcher()
|
||||
}
|
||||
|
||||
val callbackDispatcher = buildJvmDispatcher {
|
||||
name = "kovenant-callback"
|
||||
concurrentTasks = 1
|
||||
|
||||
pollStrategy {
|
||||
yielding(numberOfPolls = 100)
|
||||
blocking()
|
||||
}
|
||||
|
||||
threadFactory = createThreadFactory(Process.THREAD_PRIORITY_BACKGROUND)
|
||||
}
|
||||
val workerDispatcher = AsyncTaskDispatcher(AsyncTask.SERIAL_EXECUTOR)
|
||||
|
||||
Kovenant.context {
|
||||
callbackContext {
|
||||
dispatcher = callbackDispatcher
|
||||
}
|
||||
workerContext {
|
||||
dispatcher = workerDispatcher
|
||||
}
|
||||
}
|
||||
return DispatchersDisposable(workerDispatcher, callbackDispatcher)
|
||||
}
|
||||
|
||||
private fun createThreadFactory(priority: Int): (Runnable, String, Int) -> Thread = {
|
||||
target, dispatcherName, id ->
|
||||
val wrapper = Runnable {
|
||||
Process.setThreadPriority(priority)
|
||||
target.run()
|
||||
}
|
||||
Thread(wrapper, "$dispatcherName-$id")
|
||||
}
|
||||
|
||||
private inline fun AtomicInteger.onlyFirst(body: () -> Unit) {
|
||||
val threadNumber = incrementAndGet()
|
||||
if (threadNumber == 1) {
|
||||
body()
|
||||
} else {
|
||||
decrementAndGet()
|
||||
}
|
||||
}
|
||||
|
||||
private class DispatchersDisposable(private vararg val dispatcher: Dispatcher) : Disposable {
|
||||
override fun close(force: Boolean) {
|
||||
dispatcher.forEach {
|
||||
close(force, it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun close(force: Boolean, dispatcher: Dispatcher) {
|
||||
try {
|
||||
if (force) {
|
||||
dispatcher.stop(force = true)
|
||||
} else {
|
||||
dispatcher.stop(block = true)
|
||||
}
|
||||
} catch(e: Exception) {
|
||||
//ignore, nothing we can do
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class AsyncTaskDispatcher(val executor: Executor) : Dispatcher {
|
||||
override fun offer(task: () -> Unit): Boolean {
|
||||
if (stopped || terminated) return false
|
||||
executor.execute(task)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun tryCancel(task: () -> Unit): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun stop(force: Boolean, timeOutMs: Long, block: Boolean): List<() -> Unit> {
|
||||
stopped = true
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
override var stopped: Boolean = false
|
||||
private set
|
||||
|
||||
override var terminated: Boolean = false
|
||||
private set
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.util.preference
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import org.mariotaku.commons.collection.MultiMap
|
||||
|
||||
class PreferenceChangeNotifier(private val preferences: SharedPreferences) {
|
||||
|
||||
private val listenersMap = MultiMap<String, (String) -> Unit>()
|
||||
|
||||
fun register(key: String, callback: (String) -> Unit) {
|
||||
listenersMap.add(key, callback)
|
||||
}
|
||||
|
||||
fun register(vararg keys: String, callback: (String) -> Unit) {
|
||||
keys.forEach { key -> listenersMap.add(key, callback) }
|
||||
}
|
||||
|
||||
}
|
|
@ -1,16 +1,13 @@
|
|||
package org.mariotaku.twidere.util.refresh
|
||||
|
||||
import android.content.Context
|
||||
import org.mariotaku.kpreferences.KPreferences
|
||||
import android.content.SharedPreferences
|
||||
import org.mariotaku.twidere.annotation.AutoRefreshType
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2016/12/17.
|
||||
*/
|
||||
|
||||
abstract class AutoRefreshController(
|
||||
val context: Context,
|
||||
val kPreferences: KPreferences
|
||||
val preferences: SharedPreferences
|
||||
) {
|
||||
|
||||
abstract fun appStarted()
|
||||
|
|
|
@ -5,8 +5,9 @@ import android.app.job.JobInfo
|
|||
import android.app.job.JobScheduler
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Build
|
||||
import org.mariotaku.kpreferences.KPreferences
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.twidere.annotation.AutoRefreshType
|
||||
import org.mariotaku.twidere.constant.refreshIntervalKey
|
||||
import org.mariotaku.twidere.service.JobTaskService
|
||||
|
@ -15,15 +16,11 @@ import org.mariotaku.twidere.service.JobTaskService.Companion.JOB_ID_REFRESH_LAU
|
|||
import java.util.concurrent.TimeUnit
|
||||
import android.Manifest.permission as AndroidPermissions
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2016/12/17.
|
||||
*/
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
class JobSchedulerAutoRefreshController(
|
||||
context: Context,
|
||||
kPreferences: KPreferences
|
||||
) : AutoRefreshController(context, kPreferences) {
|
||||
preferences: SharedPreferences
|
||||
) : AutoRefreshController(context, preferences) {
|
||||
private val scheduler = context.getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler
|
||||
|
||||
override fun appStarted() {
|
||||
|
@ -54,7 +51,7 @@ class JobSchedulerAutoRefreshController(
|
|||
scheduler.cancel(jobId)
|
||||
}
|
||||
|
||||
fun scheduleJob(jobId: Int, periodMillis: Long = TimeUnit.MINUTES.toMillis(kPreferences[refreshIntervalKey]), persisted: Boolean = true) {
|
||||
fun scheduleJob(jobId: Int, periodMillis: Long = TimeUnit.MINUTES.toMillis(preferences[refreshIntervalKey]), persisted: Boolean = true) {
|
||||
val builder = JobInfo.Builder(jobId, ComponentName(context, JobTaskService::class.java))
|
||||
builder.setPeriodic(periodMillis)
|
||||
builder.setPersisted(persisted)
|
||||
|
|
|
@ -6,10 +6,11 @@ import android.app.PendingIntent
|
|||
import android.app.job.JobScheduler
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Build
|
||||
import android.os.SystemClock
|
||||
import android.support.v4.util.ArrayMap
|
||||
import org.mariotaku.kpreferences.KPreferences
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.twidere.annotation.AutoRefreshType
|
||||
import org.mariotaku.twidere.constant.refreshIntervalKey
|
||||
import org.mariotaku.twidere.service.JobTaskService.Companion.JOB_IDS_REFRESH
|
||||
|
@ -20,8 +21,8 @@ import java.util.concurrent.TimeUnit
|
|||
|
||||
class LegacyAutoRefreshController(
|
||||
context: Context,
|
||||
kPreferences: KPreferences
|
||||
) : AutoRefreshController(context, kPreferences) {
|
||||
preferences: SharedPreferences
|
||||
) : AutoRefreshController(context, preferences) {
|
||||
|
||||
private val alarmManager: AlarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
private val pendingIntents: ArrayMap<String, PendingIntent> = ArrayMap()
|
||||
|
@ -55,7 +56,7 @@ class LegacyAutoRefreshController(
|
|||
|
||||
override fun schedule(type: String) {
|
||||
val pendingIntent = pendingIntents[type] ?: return
|
||||
val interval = TimeUnit.MINUTES.toMillis(kPreferences[refreshIntervalKey])
|
||||
val interval = TimeUnit.MINUTES.toMillis(preferences[refreshIntervalKey])
|
||||
if (interval > 0) {
|
||||
val triggerAt = SystemClock.elapsedRealtime() + interval
|
||||
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAt, interval, pendingIntent)
|
||||
|
|
Loading…
Reference in New Issue