2016-06-29 15:47:52 +02:00
|
|
|
/*
|
|
|
|
* Twidere - Twitter client for Android
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012-2014 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.fragment
|
|
|
|
|
|
|
|
import android.content.Context
|
2017-04-17 15:10:14 +02:00
|
|
|
import android.content.SharedPreferences
|
2016-06-29 15:47:52 +02:00
|
|
|
import android.os.Bundle
|
|
|
|
import android.support.v4.app.Fragment
|
|
|
|
import android.support.v4.text.BidiFormatter
|
|
|
|
import com.squareup.otto.Bus
|
2017-02-28 08:34:00 +01:00
|
|
|
import com.twitter.Validator
|
2017-03-22 13:00:29 +01:00
|
|
|
import nl.komponents.kovenant.Promise
|
2017-04-17 15:10:14 +02:00
|
|
|
import okhttp3.Dns
|
2017-03-26 16:38:07 +02:00
|
|
|
import org.mariotaku.restfu.http.RestHttpClient
|
2016-06-29 15:47:52 +02:00
|
|
|
import org.mariotaku.twidere.fragment.iface.IBaseFragment
|
2017-02-15 06:32:45 +01:00
|
|
|
import org.mariotaku.twidere.model.DefaultFeatures
|
2016-06-29 15:47:52 +02:00
|
|
|
import org.mariotaku.twidere.util.*
|
2017-04-16 15:09:56 +02:00
|
|
|
import org.mariotaku.twidere.util.dagger.GeneralComponent
|
2017-01-09 06:16:23 +01:00
|
|
|
import org.mariotaku.twidere.util.premium.ExtraFeaturesService
|
2017-03-29 09:04:55 +02:00
|
|
|
import org.mariotaku.twidere.util.schedule.StatusScheduleProvider
|
2017-04-13 18:57:14 +02:00
|
|
|
import org.mariotaku.twidere.util.sync.TimelineSyncManager
|
2016-06-29 15:47:52 +02:00
|
|
|
import javax.inject.Inject
|
|
|
|
|
2017-01-12 17:26:44 +01:00
|
|
|
open class BaseFragment : Fragment(), IBaseFragment<BaseFragment> {
|
2016-06-29 15:47:52 +02:00
|
|
|
|
|
|
|
// Utility classes
|
|
|
|
@Inject
|
|
|
|
lateinit var twitterWrapper: AsyncTwitterWrapper
|
|
|
|
@Inject
|
|
|
|
lateinit var readStateManager: ReadStateManager
|
|
|
|
@Inject
|
|
|
|
lateinit var bus: Bus
|
|
|
|
@Inject
|
|
|
|
lateinit var multiSelectManager: MultiSelectManager
|
|
|
|
@Inject
|
|
|
|
lateinit var userColorNameManager: UserColorNameManager
|
|
|
|
@Inject
|
2017-04-17 15:10:14 +02:00
|
|
|
lateinit var preferences: SharedPreferences
|
2016-06-29 15:47:52 +02:00
|
|
|
@Inject
|
|
|
|
lateinit var notificationManager: NotificationManagerWrapper
|
|
|
|
@Inject
|
|
|
|
lateinit var bidiFormatter: BidiFormatter
|
|
|
|
@Inject
|
|
|
|
lateinit var errorInfoStore: ErrorInfoStore
|
|
|
|
@Inject
|
2017-02-28 08:34:00 +01:00
|
|
|
lateinit var validator: Validator
|
2017-01-09 06:16:23 +01:00
|
|
|
@Inject
|
|
|
|
lateinit var extraFeaturesService: ExtraFeaturesService
|
2017-02-14 08:52:29 +01:00
|
|
|
@Inject
|
|
|
|
lateinit var permissionsManager: PermissionsManager
|
2017-02-15 06:32:45 +01:00
|
|
|
@Inject
|
|
|
|
lateinit var defaultFeatures: DefaultFeatures
|
2017-03-26 16:38:07 +02:00
|
|
|
@Inject
|
2017-03-29 09:04:55 +02:00
|
|
|
lateinit var statusScheduleProviderFactory: StatusScheduleProvider.Factory
|
2017-03-26 16:38:07 +02:00
|
|
|
@Inject
|
2017-04-13 18:57:14 +02:00
|
|
|
lateinit var timelineSyncManagerFactory: TimelineSyncManager.Factory
|
|
|
|
@Inject
|
2017-03-26 16:38:07 +02:00
|
|
|
lateinit var restHttpClient: RestHttpClient
|
2017-04-17 15:10:14 +02:00
|
|
|
@Inject
|
|
|
|
lateinit var dns: Dns
|
2017-03-26 16:38:07 +02:00
|
|
|
|
2017-03-29 09:04:55 +02:00
|
|
|
protected val statusScheduleProvider: StatusScheduleProvider?
|
|
|
|
get() = statusScheduleProviderFactory.newInstance(context)
|
2016-06-29 15:47:52 +02:00
|
|
|
|
2017-04-13 18:57:14 +02:00
|
|
|
protected val timelineSyncManager: TimelineSyncManager?
|
|
|
|
get() = timelineSyncManagerFactory.get()
|
|
|
|
|
2016-06-29 15:47:52 +02:00
|
|
|
private val actionHelper = IBaseFragment.ActionHelper(this)
|
|
|
|
|
|
|
|
override fun onViewStateRestored(savedInstanceState: Bundle?) {
|
|
|
|
super.onViewStateRestored(savedInstanceState)
|
|
|
|
requestFitSystemWindows()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onAttach(context: Context?) {
|
|
|
|
super.onAttach(context)
|
2017-04-16 15:09:56 +02:00
|
|
|
GeneralComponent.get(context!!).inject(this)
|
2016-06-29 15:47:52 +02:00
|
|
|
}
|
|
|
|
|
2017-03-22 13:00:29 +01:00
|
|
|
override fun executeAfterFragmentResumed(useHandler: Boolean, action: (BaseFragment) -> Unit)
|
|
|
|
: Promise<Unit, Exception> {
|
|
|
|
return actionHelper.executeAfterFragmentResumed(useHandler, action)
|
2016-06-29 15:47:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
|
|
|
actionHelper.dispatchOnResumeFragments()
|
|
|
|
}
|
|
|
|
|
2016-07-06 15:21:34 +02:00
|
|
|
override fun onPause() {
|
|
|
|
actionHelper.dispatchOnPause()
|
|
|
|
super.onPause()
|
|
|
|
}
|
|
|
|
|
2016-06-29 15:47:52 +02:00
|
|
|
override fun onDestroy() {
|
2017-01-09 06:16:23 +01:00
|
|
|
extraFeaturesService.release()
|
2016-06-29 15:47:52 +02:00
|
|
|
super.onDestroy()
|
|
|
|
DebugModeUtils.watchReferenceLeak(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|