Skip to content

Commit

Permalink
Adds a no connection listener to Sync Dialog to show snackbar to users
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdyrod committed Feb 12, 2024
1 parent 23d412c commit 6d4eab4
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ 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 @@ -172,6 +173,18 @@ 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()
}
},
)
.show(DATAVALUE_SYNC)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;

import com.google.android.material.snackbar.Snackbar;

import org.dhis2.App;
import org.dhis2.R;
import org.dhis2.bindings.ExtensionsKt;
Expand All @@ -26,6 +28,7 @@
import org.dhis2.commons.filters.FiltersAdapter;
import org.dhis2.commons.orgunitselector.OUTreeFragment;
import org.dhis2.commons.sync.ConflictType;
import org.dhis2.commons.sync.OnNoConnectionListener;
import org.dhis2.databinding.ActivityDatasetDetailBinding;
import org.dhis2.ui.ThemeManager;
import org.dhis2.usescases.datasets.datasetDetail.datasetList.DataSetListFragment;
Expand Down Expand Up @@ -240,10 +243,18 @@ public void setProgress(boolean active) {
@Override
public void showGranularSync() {
presenter.trackDataSetGranularSync();
View contextView = findViewById(R.id.navigationBar);
new SyncStatusDialog.Builder()
.withContext(this, null)
.withSyncContext(new SyncContext.DataSet(dataSetUid))
.onDismissListener(hasChanged -> presenter.refreshList())
.onNoConnectionListener(() ->
Snackbar.make(
contextView,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT
).show()
)
.show("DATASET_SYNC");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.viewModels
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 @@ -132,7 +134,20 @@ class DataSetListFragment : FragmentGlobalAbstract() {
viewModel.updateData()
}
}
}).show(FRAGMENT_TAG)
})
.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(FRAGMENT_TAG)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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 @@ -444,6 +445,18 @@ 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()
}
},
)
.show("EVENT_SYNC")
}

Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/org/dhis2/usescases/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.core.view.ViewCompat
import androidx.databinding.DataBindingUtil
import androidx.drawerlayout.widget.DrawerLayout
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import org.dhis2.BuildConfig
import org.dhis2.R
import org.dhis2.bindings.app
Expand All @@ -30,6 +31,7 @@ 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 @@ -304,6 +306,18 @@ 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()
}
},
)
.show("ALL_SYNC")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.core.view.ViewCompat
import androidx.databinding.DataBindingUtil
import com.google.android.material.snackbar.Snackbar
import org.dhis2.App
import org.dhis2.R
import org.dhis2.android.rtsm.commons.Constants.INTENT_EXTRA_APP_CONFIG
Expand All @@ -27,6 +28,7 @@ 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 @@ -220,7 +222,20 @@ class ProgramFragment : FragmentGlobalAbstract(), ProgramView {
}
}
},
).show(FRAGMENT_TAG)
)
.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(FRAGMENT_TAG)
}

fun sharedView() = binding.drawerLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.activity.viewModels
import androidx.constraintlayout.widget.ConstraintSet
import androidx.databinding.DataBindingUtil
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import dhis2.org.analytics.charts.ui.GroupAnalyticsFragment
import org.dhis2.R
import org.dhis2.bindings.app
Expand All @@ -27,6 +28,7 @@ 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 @@ -195,7 +197,20 @@ class ProgramEventDetailActivity :
override fun onDismiss(hasChanged: Boolean) {
if (hasChanged) FilterManager.getInstance().publishData()
}
}).show("EVENT_SYNC")
})
.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("EVENT_SYNC")
}

public override fun onPause() {
Expand Down Expand Up @@ -376,7 +391,20 @@ class ProgramEventDetailActivity :
override fun onDismiss(hasChanged: Boolean) {
if (hasChanged) FilterManager.getInstance().publishData()
}
}).show(FRAGMENT_TAG)
})
.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()
}
},
)
.show(FRAGMENT_TAG)
}

private fun showList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,23 @@ protected void onSaveInstanceState(@NonNull Bundle outState) {
}

private void openSyncDialog() {
View contextView = findViewById(R.id.navigationBar);
new SyncStatusDialog.Builder()
.withContext(this, null)
.withSyncContext(
new SyncContext.TrackerProgram(initialProgram)
)
.onDismissListener(hasChanged -> {
if (hasChanged) viewModel.refreshData();
}).show("PROGRAM_SYNC");
})
.onNoConnectionListener(() ->
Snackbar.make(
contextView,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT
).show()
)
.show("PROGRAM_SYNC");
}

@Override
Expand Down Expand Up @@ -582,14 +591,22 @@ public void setPrograms(List<ProgramSpinnerModel> programs) {

@Override
public void showSyncDialog(String enrollmentUid) {
View contextView = findViewById(R.id.navigationBar);
new SyncStatusDialog.Builder()
.withContext(this, null)
.withSyncContext(
new SyncContext.TrackerProgramTei(enrollmentUid)
)
.onDismissListener(hasChanged -> {
if (hasChanged) viewModel.refreshData();
}).show("TEI_SYNC");
})
.onNoConnectionListener(() ->
Snackbar.make(
contextView,
R.string.sync_offline_check_connection,
Snackbar.LENGTH_SHORT
).show()
).show("TEI_SYNC");
}

private void setInitialProgram(List<ProgramSpinnerModel> programs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModelProvider
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.snackbar.Snackbar
import org.dhis2.App
import org.dhis2.R
import org.dhis2.commons.Constants
Expand All @@ -30,6 +31,7 @@ import org.dhis2.commons.filters.Filters
import org.dhis2.commons.network.NetworkUtils
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.ActivityDashboardMobileBinding
import org.dhis2.ui.ThemeManager
Expand Down Expand Up @@ -292,7 +294,19 @@ class TeiDashboardMobileActivity :
finish()
}
}
}).show(TEI_SYNC)
})
.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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.recyclerview.widget.DividerItemDecoration
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.google.android.material.snackbar.Snackbar
import io.reactivex.Flowable
import io.reactivex.Single
import io.reactivex.functions.Consumer
Expand All @@ -40,6 +41,7 @@ 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 @@ -619,7 +621,19 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View {
override fun onDismiss(hasChanged: Boolean) {
if (hasChanged) FilterManager.getInstance().publishData()
}
}).show(enrollmentUid)
})
.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)
}

override fun displayCatComboOptionSelectorForEvents(data: List<EventViewModel>) {
Expand Down
Loading

0 comments on commit 6d4eab4

Please sign in to comment.