Skip to content

Commit

Permalink
resolve code smell. now dialog uses SAM interface for the NoConnectio…
Browse files Browse the repository at this point in the history
…nListener
  • Loading branch information
ferdyrod committed Feb 14, 2024
1 parent f7b988b commit 5dca594
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -173,18 +172,14 @@ class DataSetTableActivity : ActivityGlobalAbstract(), DataSetTableContract.View
if (hasChanged) presenter.updateData()
}
})
.onNoConnectionListener(
object : OnNoConnectionListener {
override fun onNoConnection() {
val contextView = findViewById<View>(R.id.navigationBar)
Snackbar.make(
contextView,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT,
).show()
}
},
)
.onNoConnectionListener {
val contextView = findViewById<View>(R.id.navigationBar)
Snackbar.make(
contextView,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT,
).show()
}
.show(DATAVALUE_SYNC)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -135,18 +134,14 @@ class DataSetListFragment : FragmentGlobalAbstract() {
}
}
})
.onNoConnectionListener(
object : OnNoConnectionListener {
override fun onNoConnection() {
val contextView = activity.findViewById<View>(R.id.navigationBar)
Snackbar.make(
contextView,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT,
).show()
}
},
)
.onNoConnectionListener {
val contextView = activity.findViewById<View>(R.id.navigationBar)
Snackbar.make(
contextView,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT,
).show()
}
.show(FRAGMENT_TAG)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -445,18 +444,14 @@ class EventCaptureActivity :
SyncStatusDialog.Builder()
.withContext(this)
.withSyncContext(SyncContext.Event(eventUid!!))
.onNoConnectionListener(
object : OnNoConnectionListener {
override fun onNoConnection() {
val contextView = findViewById<View>(R.id.navigationBar)
Snackbar.make(
contextView,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT,
).show()
}
},
)
.onNoConnectionListener {
val contextView = findViewById<View>(R.id.navigationBar)
Snackbar.make(
contextView,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT,
).show()
}
.show("EVENT_SYNC")
}

Expand Down
21 changes: 8 additions & 13 deletions app/src/main/java/org/dhis2/usescases/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -306,18 +305,14 @@ class MainActivity :
}
},
)
.onNoConnectionListener(
object : OnNoConnectionListener {
override fun onNoConnection() {
val contextView = findViewById<View>(R.id.navigationBar)
Snackbar.make(
contextView,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT,
).show()
}
},
)
.onNoConnectionListener {
val contextView = findViewById<View>(R.id.navigationBar)
Snackbar.make(
contextView,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT,
).show()
}
.show("ALL_SYNC")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -223,18 +222,14 @@ class ProgramFragment : FragmentGlobalAbstract(), ProgramView {
}
},
)
.onNoConnectionListener(
object : OnNoConnectionListener {
override fun onNoConnection() {
val contextView = activity?.findViewById<View>(R.id.navigationBar)
Snackbar.make(
contextView!!,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT,
).show()
}
},
)
.onNoConnectionListener {
val contextView = activity?.findViewById<View>(R.id.navigationBar)
Snackbar.make(
contextView!!,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT,
).show()
}
.show(FRAGMENT_TAG)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -198,18 +197,14 @@ class ProgramEventDetailActivity :
if (hasChanged) FilterManager.getInstance().publishData()
}
})
.onNoConnectionListener(
object : OnNoConnectionListener {
override fun onNoConnection() {
val contextView = findViewById<View>(R.id.navigationBar)
Snackbar.make(
contextView,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT,
).show()
}
},
)
.onNoConnectionListener {
val contextView = findViewById<View>(R.id.navigationBar)
Snackbar.make(
contextView,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT,
).show()
}
.show("EVENT_SYNC")
}

Expand Down Expand Up @@ -392,18 +387,14 @@ class ProgramEventDetailActivity :
if (hasChanged) FilterManager.getInstance().publishData()
}
})
.onNoConnectionListener(
object : OnNoConnectionListener {
override fun onNoConnection() {
val contextView = findViewById<View>(R.id.rootView)
Snackbar.make(
contextView,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT,
).show()
}
},
)
.onNoConnectionListener {
val contextView = findViewById<View>(R.id.rootView)
Snackbar.make(
contextView,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT,
).show()
}
.show(FRAGMENT_TAG)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -305,18 +304,14 @@ class TeiDashboardMobileActivity :
}
}
})
.onNoConnectionListener(
object : OnNoConnectionListener {
override fun onNoConnection() {
val contextView = findViewById<View>(R.id.navigationBar)
Snackbar.make(
contextView,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT,
).show()
}
},
).show(TEI_SYNC)
.onNoConnectionListener {
val contextView = findViewById<View>(R.id.navigationBar)
Snackbar.make(
contextView,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT,
).show()
}.show(TEI_SYNC)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -622,18 +621,14 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View {
if (hasChanged) FilterManager.getInstance().publishData()
}
})
.onNoConnectionListener(
object : OnNoConnectionListener {
override fun onNoConnection() {
val contextView = activity?.findViewById<View>(R.id.navigationBar)
Snackbar.make(
contextView!!,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT,
).show()
}
},
).show(enrollmentUid)
.onNoConnectionListener {
val contextView = activity?.findViewById<View>(R.id.navigationBar)
Snackbar.make(
contextView!!,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT,
).show()
}.show(enrollmentUid)
}

override fun displayCatComboOptionSelectorForEvents(data: List<EventViewModel>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.dhis2.commons.sync

interface OnNoConnectionListener {
fun interface OnNoConnectionListener {
fun onNoConnection()
}

0 comments on commit 5dca594

Please sign in to comment.