浏览代码

NewBaseController: Inject kotlin fields without @JvmField and nullable type

These do not need to be nullable as they will be injected immediately.
This will make child controllers code much cleaner.

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Álvaro Brey 2 年之前
父节点
当前提交
e176b38d8b
共有 1 个文件被更改,包括 4 次插入5 次删除
  1. 4 5
      app/src/main/java/com/nextcloud/talk/controllers/base/NewBaseController.kt

+ 4 - 5
app/src/main/java/com/nextcloud/talk/controllers/base/NewBaseController.kt

@@ -68,12 +68,10 @@ abstract class NewBaseController(@LayoutRes var layoutRes: Int, args: Bundle? =
     }
     }
 
 
     @Inject
     @Inject
-    @JvmField
-    var appPreferences: AppPreferences? = null
+    lateinit var appPreferences: AppPreferences
 
 
     @Inject
     @Inject
-    @JvmField
-    var context: Context? = null
+    lateinit var context: Context
 
 
     protected open val title: String?
     protected open val title: String?
         get() = null
         get() = null
@@ -93,6 +91,8 @@ abstract class NewBaseController(@LayoutRes var layoutRes: Int, args: Bundle? =
         }
         }
 
 
     init {
     init {
+        @Suppress("LeakingThis")
+        sharedApplication!!.componentApplication.inject(this)
         addLifecycleListener(object : LifecycleListener() {
         addLifecycleListener(object : LifecycleListener() {
             override fun postCreateView(controller: Controller, view: View) {
             override fun postCreateView(controller: Controller, view: View) {
                 onViewBound(view)
                 onViewBound(view)
@@ -271,7 +271,6 @@ abstract class NewBaseController(@LayoutRes var layoutRes: Int, args: Bundle? =
     }
     }
 
 
     private fun cleanTempCertPreference() {
     private fun cleanTempCertPreference() {
-        sharedApplication!!.componentApplication.inject(this)
         val temporaryClassNames: MutableList<String> = ArrayList()
         val temporaryClassNames: MutableList<String> = ArrayList()
         temporaryClassNames.add(ServerSelectionController::class.java.name)
         temporaryClassNames.add(ServerSelectionController::class.java.name)
         temporaryClassNames.add(AccountVerificationController::class.java.name)
         temporaryClassNames.add(AccountVerificationController::class.java.name)