Twidere-App-Android-Twitter.../twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseFragment.kt

111 lines
3.6 KiB
Kotlin
Raw Normal View History

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
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-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.*
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper
2017-01-09 06:16:23 +01:00
import org.mariotaku.twidere.util.premium.ExtraFeaturesService
2017-03-26 16:38:07 +02:00
import org.mariotaku.twidere.util.schedule.StatusScheduleController
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 asyncTaskManager: AsyncTaskManager
@Inject
lateinit var multiSelectManager: MultiSelectManager
@Inject
lateinit var userColorNameManager: UserColorNameManager
@Inject
lateinit var preferences: SharedPreferencesWrapper
@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
lateinit var statusScheduleControllerFactory: StatusScheduleController.Factory
@Inject
lateinit var restHttpClient: RestHttpClient
protected val statusScheduleController: StatusScheduleController?
get() = statusScheduleControllerFactory.newInstance(context)
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)
GeneralComponentHelper.build(context!!).inject(this)
}
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)
}
}