From 4911fe0165d1e2060bfc10205725cb5e9e349a60 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 23 Jan 2021 22:45:14 +0100 Subject: [PATCH] MaintenanceFragment -> jetpack --- .../maintenance/MaintenanceFragment.kt | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.kt index 921cf19327..d6cbf22770 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.kt @@ -8,13 +8,13 @@ import android.view.ViewGroup import dagger.android.support.DaggerFragment import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R +import info.nightscout.androidaps.databinding.MaintenanceFragmentBinding import info.nightscout.androidaps.interfaces.ImportExportPrefsInterface import info.nightscout.androidaps.plugins.general.food.FoodPlugin import info.nightscout.androidaps.plugins.general.maintenance.activities.LogSettingActivity import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.resources.ResourceHelper -import kotlinx.android.synthetic.main.maintenance_fragment.* import javax.inject.Inject class MaintenanceFragment : DaggerFragment() { @@ -26,15 +26,22 @@ class MaintenanceFragment : DaggerFragment() { @Inject lateinit var foodPlugin: FoodPlugin @Inject lateinit var importExportPrefs: ImportExportPrefsInterface - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - return inflater.inflate(R.layout.maintenance_fragment, container, false) + private var _binding: MaintenanceFragmentBinding? = null + + // This property is only valid between onCreateView and + // onDestroyView. + private val binding get() = _binding!! + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { + _binding = MaintenanceFragmentBinding.inflate(inflater, container, false) + return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - log_send.setOnClickListener { maintenancePlugin.sendLogs() } - log_delete.setOnClickListener { maintenancePlugin.deleteLogs() } - nav_resetdb.setOnClickListener { + binding.logSend.setOnClickListener { maintenancePlugin.sendLogs() } + binding.logDelete.setOnClickListener { maintenancePlugin.deleteLogs() } + binding.navResetdb.setOnClickListener { activity?.let { activity -> OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.maintenance), resourceHelper.gs(R.string.reset_db_confirm), Runnable { MainApp.getDbHelper().resetDatabases() @@ -45,18 +52,24 @@ class MaintenanceFragment : DaggerFragment() { }) } } - nav_export.setOnClickListener { + binding.navExport.setOnClickListener { // start activity for checking permissions... importExportPrefs.verifyStoragePermissions(this) { importExportPrefs.exportSharedPreferences(this) } } - nav_import.setOnClickListener { + binding.navImport.setOnClickListener { // start activity for checking permissions... importExportPrefs.verifyStoragePermissions(this) { importExportPrefs.importSharedPreferences(this) } } - nav_logsettings.setOnClickListener { startActivity(Intent(activity, LogSettingActivity::class.java)) } + binding.navLogsettings.setOnClickListener { startActivity(Intent(activity, LogSettingActivity::class.java)) } + } + + @Synchronized + override fun onDestroyView() { + super.onDestroyView() + _binding = null } } \ No newline at end of file