From 5dca594ba19661b0a909a282a6b22e4b854ec39e Mon Sep 17 00:00:00 2001 From: FerdyRod Date: Tue, 13 Feb 2024 16:42:54 +0100 Subject: [PATCH] resolve code smell. now dialog uses SAM interface for the NoConnectionListener --- .../dataSetTable/DataSetTableActivity.kt | 21 ++++------ .../datasetList/DataSetListFragment.kt | 21 ++++------ .../eventCapture/EventCaptureActivity.kt | 21 ++++------ .../org/dhis2/usescases/main/MainActivity.kt | 21 ++++------ .../usescases/main/program/ProgramFragment.kt | 21 ++++------ .../ProgramEventDetailActivity.kt | 41 ++++++++----------- .../TeiDashboardMobileActivity.kt | 21 ++++------ .../teidata/TEIDataFragment.kt | 21 ++++------ .../commons/sync/OnNoConnectionListener.kt | 2 +- 9 files changed, 73 insertions(+), 117 deletions(-) diff --git a/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/DataSetTableActivity.kt b/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/DataSetTableActivity.kt index 27a71a94af..c0f162192b 100644 --- a/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/DataSetTableActivity.kt +++ b/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/DataSetTableActivity.kt @@ -38,7 +38,6 @@ import org.dhis2.commons.extensions.closeKeyboard import org.dhis2.commons.matomo.Labels.Companion.CLICK import org.dhis2.commons.popupmenu.AppMenuHelper import org.dhis2.commons.sync.OnDismissListener -import org.dhis2.commons.sync.OnNoConnectionListener import org.dhis2.commons.sync.SyncContext import org.dhis2.databinding.ActivityDatasetTableBinding import org.dhis2.usescases.datasets.dataSetTable.dataSetDetail.DataSetDetailFragment.Companion.create @@ -173,18 +172,14 @@ class DataSetTableActivity : ActivityGlobalAbstract(), DataSetTableContract.View if (hasChanged) presenter.updateData() } }) - .onNoConnectionListener( - object : OnNoConnectionListener { - override fun onNoConnection() { - val contextView = findViewById(R.id.navigationBar) - Snackbar.make( - contextView, - R.string.sync_offline_check_connection, - Snackbar.LENGTH_SHORT, - ).show() - } - }, - ) + .onNoConnectionListener { + val contextView = findViewById(R.id.navigationBar) + Snackbar.make( + contextView, + R.string.sync_offline_check_connection, + Snackbar.LENGTH_SHORT, + ).show() + } .show(DATAVALUE_SYNC) } diff --git a/app/src/main/java/org/dhis2/usescases/datasets/datasetDetail/datasetList/DataSetListFragment.kt b/app/src/main/java/org/dhis2/usescases/datasets/datasetDetail/datasetList/DataSetListFragment.kt index f983002ab4..476e90bae2 100644 --- a/app/src/main/java/org/dhis2/usescases/datasets/datasetDetail/datasetList/DataSetListFragment.kt +++ b/app/src/main/java/org/dhis2/usescases/datasets/datasetDetail/datasetList/DataSetListFragment.kt @@ -9,7 +9,6 @@ import com.google.android.material.snackbar.Snackbar import org.dhis2.R import org.dhis2.commons.Constants import org.dhis2.commons.sync.OnDismissListener -import org.dhis2.commons.sync.OnNoConnectionListener import org.dhis2.commons.sync.SyncContext import org.dhis2.databinding.FragmentDataSetListBinding import org.dhis2.usescases.datasets.dataSetTable.DataSetTableActivity @@ -135,18 +134,14 @@ class DataSetListFragment : FragmentGlobalAbstract() { } } }) - .onNoConnectionListener( - object : OnNoConnectionListener { - override fun onNoConnection() { - val contextView = activity.findViewById(R.id.navigationBar) - Snackbar.make( - contextView, - R.string.sync_offline_check_connection, - Snackbar.LENGTH_SHORT, - ).show() - } - }, - ) + .onNoConnectionListener { + val contextView = activity.findViewById(R.id.navigationBar) + Snackbar.make( + contextView, + R.string.sync_offline_check_connection, + Snackbar.LENGTH_SHORT, + ).show() + } .show(FRAGMENT_TAG) } diff --git a/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventCapture/EventCaptureActivity.kt b/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventCapture/EventCaptureActivity.kt index 3adb553017..ec0907f55d 100644 --- a/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventCapture/EventCaptureActivity.kt +++ b/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventCapture/EventCaptureActivity.kt @@ -22,7 +22,6 @@ import org.dhis2.commons.dialogs.AlertBottomDialog import org.dhis2.commons.dialogs.CustomDialog import org.dhis2.commons.dialogs.DialogClickListener import org.dhis2.commons.popupmenu.AppMenuHelper -import org.dhis2.commons.sync.OnNoConnectionListener import org.dhis2.commons.sync.SyncContext import org.dhis2.databinding.ActivityEventCaptureBinding import org.dhis2.ui.ErrorFieldList @@ -445,18 +444,14 @@ class EventCaptureActivity : SyncStatusDialog.Builder() .withContext(this) .withSyncContext(SyncContext.Event(eventUid!!)) - .onNoConnectionListener( - object : OnNoConnectionListener { - override fun onNoConnection() { - val contextView = findViewById(R.id.navigationBar) - Snackbar.make( - contextView, - R.string.sync_offline_check_connection, - Snackbar.LENGTH_SHORT, - ).show() - } - }, - ) + .onNoConnectionListener { + val contextView = findViewById(R.id.navigationBar) + Snackbar.make( + contextView, + R.string.sync_offline_check_connection, + Snackbar.LENGTH_SHORT, + ).show() + } .show("EVENT_SYNC") } diff --git a/app/src/main/java/org/dhis2/usescases/main/MainActivity.kt b/app/src/main/java/org/dhis2/usescases/main/MainActivity.kt index 26f4a3c4dd..a66a3bf8b2 100644 --- a/app/src/main/java/org/dhis2/usescases/main/MainActivity.kt +++ b/app/src/main/java/org/dhis2/usescases/main/MainActivity.kt @@ -31,7 +31,6 @@ import org.dhis2.commons.filters.FilterItem import org.dhis2.commons.filters.FilterManager import org.dhis2.commons.filters.FiltersAdapter import org.dhis2.commons.sync.OnDismissListener -import org.dhis2.commons.sync.OnNoConnectionListener import org.dhis2.commons.sync.SyncContext import org.dhis2.databinding.ActivityMainBinding import org.dhis2.ui.dialogs.alert.AlertDialog @@ -306,18 +305,14 @@ class MainActivity : } }, ) - .onNoConnectionListener( - object : OnNoConnectionListener { - override fun onNoConnection() { - val contextView = findViewById(R.id.navigationBar) - Snackbar.make( - contextView, - R.string.sync_offline_check_connection, - Snackbar.LENGTH_SHORT, - ).show() - } - }, - ) + .onNoConnectionListener { + val contextView = findViewById(R.id.navigationBar) + Snackbar.make( + contextView, + R.string.sync_offline_check_connection, + Snackbar.LENGTH_SHORT, + ).show() + } .show("ALL_SYNC") } diff --git a/app/src/main/java/org/dhis2/usescases/main/program/ProgramFragment.kt b/app/src/main/java/org/dhis2/usescases/main/program/ProgramFragment.kt index 53294c5e57..4e0d1653d3 100644 --- a/app/src/main/java/org/dhis2/usescases/main/program/ProgramFragment.kt +++ b/app/src/main/java/org/dhis2/usescases/main/program/ProgramFragment.kt @@ -28,7 +28,6 @@ import org.dhis2.bindings.dp import org.dhis2.commons.filters.FilterManager import org.dhis2.commons.orgunitselector.OUTreeFragment import org.dhis2.commons.sync.OnDismissListener -import org.dhis2.commons.sync.OnNoConnectionListener import org.dhis2.commons.sync.SyncContext import org.dhis2.databinding.FragmentProgramBinding import org.dhis2.usescases.general.FragmentGlobalAbstract @@ -223,18 +222,14 @@ class ProgramFragment : FragmentGlobalAbstract(), ProgramView { } }, ) - .onNoConnectionListener( - object : OnNoConnectionListener { - override fun onNoConnection() { - val contextView = activity?.findViewById(R.id.navigationBar) - Snackbar.make( - contextView!!, - R.string.sync_offline_check_connection, - Snackbar.LENGTH_SHORT, - ).show() - } - }, - ) + .onNoConnectionListener { + val contextView = activity?.findViewById(R.id.navigationBar) + Snackbar.make( + contextView!!, + R.string.sync_offline_check_connection, + Snackbar.LENGTH_SHORT, + ).show() + } .show(FRAGMENT_TAG) } diff --git a/app/src/main/java/org/dhis2/usescases/programEventDetail/ProgramEventDetailActivity.kt b/app/src/main/java/org/dhis2/usescases/programEventDetail/ProgramEventDetailActivity.kt index dd81e4506f..d7a7887e1c 100644 --- a/app/src/main/java/org/dhis2/usescases/programEventDetail/ProgramEventDetailActivity.kt +++ b/app/src/main/java/org/dhis2/usescases/programEventDetail/ProgramEventDetailActivity.kt @@ -28,7 +28,6 @@ import org.dhis2.commons.matomo.Actions.Companion.CREATE_EVENT import org.dhis2.commons.network.NetworkUtils import org.dhis2.commons.orgunitselector.OUTreeFragment import org.dhis2.commons.sync.OnDismissListener -import org.dhis2.commons.sync.OnNoConnectionListener import org.dhis2.commons.sync.SyncContext import org.dhis2.databinding.ActivityProgramEventDetailBinding import org.dhis2.ui.ThemeManager @@ -198,18 +197,14 @@ class ProgramEventDetailActivity : if (hasChanged) FilterManager.getInstance().publishData() } }) - .onNoConnectionListener( - object : OnNoConnectionListener { - override fun onNoConnection() { - val contextView = findViewById(R.id.navigationBar) - Snackbar.make( - contextView, - R.string.sync_offline_check_connection, - Snackbar.LENGTH_SHORT, - ).show() - } - }, - ) + .onNoConnectionListener { + val contextView = findViewById(R.id.navigationBar) + Snackbar.make( + contextView, + R.string.sync_offline_check_connection, + Snackbar.LENGTH_SHORT, + ).show() + } .show("EVENT_SYNC") } @@ -392,18 +387,14 @@ class ProgramEventDetailActivity : if (hasChanged) FilterManager.getInstance().publishData() } }) - .onNoConnectionListener( - object : OnNoConnectionListener { - override fun onNoConnection() { - val contextView = findViewById(R.id.rootView) - Snackbar.make( - contextView, - R.string.sync_offline_check_connection, - Snackbar.LENGTH_SHORT, - ).show() - } - }, - ) + .onNoConnectionListener { + val contextView = findViewById(R.id.rootView) + Snackbar.make( + contextView, + R.string.sync_offline_check_connection, + Snackbar.LENGTH_SHORT, + ).show() + } .show(FRAGMENT_TAG) } diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt index b64e048489..dde3387b99 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt @@ -32,7 +32,6 @@ import org.dhis2.commons.network.NetworkUtils import org.dhis2.commons.popupmenu.AppMenuHelper import org.dhis2.commons.resources.ResourceManager import org.dhis2.commons.sync.OnDismissListener -import org.dhis2.commons.sync.OnNoConnectionListener import org.dhis2.commons.sync.SyncContext import org.dhis2.databinding.ActivityDashboardMobileBinding import org.dhis2.ui.ThemeManager @@ -305,18 +304,14 @@ class TeiDashboardMobileActivity : } } }) - .onNoConnectionListener( - object : OnNoConnectionListener { - override fun onNoConnection() { - val contextView = findViewById(R.id.navigationBar) - Snackbar.make( - contextView, - R.string.sync_offline_check_connection, - Snackbar.LENGTH_SHORT, - ).show() - } - }, - ).show(TEI_SYNC) + .onNoConnectionListener { + val contextView = findViewById(R.id.navigationBar) + Snackbar.make( + contextView, + R.string.sync_offline_check_connection, + Snackbar.LENGTH_SHORT, + ).show() + }.show(TEI_SYNC) } } diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt index 87591930ac..985d3fcb08 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt @@ -41,7 +41,6 @@ import org.dhis2.commons.orgunitselector.OUTreeFragment import org.dhis2.commons.resources.ColorUtils import org.dhis2.commons.resources.ObjectStyleUtils.getIconResource import org.dhis2.commons.sync.OnDismissListener -import org.dhis2.commons.sync.OnNoConnectionListener import org.dhis2.commons.sync.SyncContext.EnrollmentEvent import org.dhis2.databinding.FragmentTeiDataBinding import org.dhis2.usescases.eventsWithoutRegistration.eventInitial.EventInitialActivity @@ -622,18 +621,14 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View { if (hasChanged) FilterManager.getInstance().publishData() } }) - .onNoConnectionListener( - object : OnNoConnectionListener { - override fun onNoConnection() { - val contextView = activity?.findViewById(R.id.navigationBar) - Snackbar.make( - contextView!!, - R.string.sync_offline_check_connection, - Snackbar.LENGTH_SHORT, - ).show() - } - }, - ).show(enrollmentUid) + .onNoConnectionListener { + val contextView = activity?.findViewById(R.id.navigationBar) + Snackbar.make( + contextView!!, + R.string.sync_offline_check_connection, + Snackbar.LENGTH_SHORT, + ).show() + }.show(enrollmentUid) } override fun displayCatComboOptionSelectorForEvents(data: List) { diff --git a/commons/src/main/java/org/dhis2/commons/sync/OnNoConnectionListener.kt b/commons/src/main/java/org/dhis2/commons/sync/OnNoConnectionListener.kt index 5817f18355..5d75bdbd3f 100644 --- a/commons/src/main/java/org/dhis2/commons/sync/OnNoConnectionListener.kt +++ b/commons/src/main/java/org/dhis2/commons/sync/OnNoConnectionListener.kt @@ -1,5 +1,5 @@ package org.dhis2.commons.sync -interface OnNoConnectionListener { +fun interface OnNoConnectionListener { fun onNoConnection() }