Skip to content

Commit

Permalink
Merge pull request #1245 from OpenSRP/issue-1231
Browse files Browse the repository at this point in the history
Use toast instead of Snackbar for sync messages
  • Loading branch information
faidvd authored Apr 19, 2021
2 parents 1dfd67e + bd2fc66 commit c255537
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 47 deletions.
8 changes: 4 additions & 4 deletions opensrp-reveal/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ android {
applicationId "org.smartregister.reveal"
minSdkVersion 18
targetSdkVersion 28
versionCode 32
versionName "5.3.24"
versionCode 33
versionName "5.3.25"
multiDexEnabled true
buildConfigField "long", "MAX_SERVER_TIME_DIFFERENCE", "1800000l"
buildConfigField "boolean", "TIME_CHECK", "false"
Expand Down Expand Up @@ -133,7 +133,7 @@ android {
buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '250'
buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '100'
buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '2'
buildConfigField "long", "SYNC_INTERVAL_IN_MINUTES", '15'
buildConfigField "long", "SYNC_INTERVAL_IN_MINUTES", '480'
buildConfigField "org.smartregister.reveal.util.Country", "BUILD_COUNTRY", "org.smartregister.reveal.util.Country.ZAMBIA"
buildConfigField "long", "PULL_UNIQUE_IDS_MINUTES", '15'
buildConfigField "String", "ADMIN_PASSWORD_NOT_NEAR_STRUCTURES", '"AdminPass1"'
Expand All @@ -152,7 +152,7 @@ android {
buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '250'
buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '100'
buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '2'
buildConfigField "long", "SYNC_INTERVAL_IN_MINUTES", '15'
buildConfigField "long", "SYNC_INTERVAL_IN_MINUTES", '480'
buildConfigField "org.smartregister.reveal.util.Country", "BUILD_COUNTRY", "org.smartregister.reveal.util.Country.THAILAND_EN"
buildConfigField "long", "PULL_UNIQUE_IDS_MINUTES", '15'
buildConfigField "String", "ADMIN_PASSWORD_NOT_NEAR_STRUCTURES", '"AdminPass1"'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ public LoginInteractor(BaseLoginContract.Presenter loginPresenter) {
@Override
protected void scheduleJobsPeriodically() {
LocationTaskServiceJob.scheduleJob(LocationTaskServiceJob.TAG,
BuildConfig.SYNC_INTERVAL_IN_MINUTES, getFlexValue((int) BuildConfig.SYNC_INTERVAL_IN_MINUTES));
Utils.getSyncInterval(), getFlexValue((int) Utils.getSyncInterval()));

PullUniqueIdsServiceJob.scheduleJob(SyncServiceJob.TAG,
BuildConfig.PULL_UNIQUE_IDS_MINUTES, getFlexValue((int) BuildConfig.PULL_UNIQUE_IDS_MINUTES));

DocumentConfigurationServiceJob
.scheduleJob(DocumentConfigurationServiceJob.TAG, BuildConfig.SYNC_INTERVAL_IN_MINUTES,
getFlexValue((int) BuildConfig.SYNC_INTERVAL_IN_MINUTES));
.scheduleJob(DocumentConfigurationServiceJob.TAG, Utils.getSyncInterval(), getFlexValue((int) Utils.getSyncInterval()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public interface Constants {
List<String> MACEPA_PROVINCES = Arrays.asList("Western", "Southern", "Lusaka");

String ACTIONS = "actions";
String THAILAND_SYNC_INTERVAL = "720";

int SYNC_BACK_OFF_DELAY = 5000;

interface CONFIGURATION {
String LOGIN = "login";
Expand Down Expand Up @@ -106,6 +109,7 @@ interface CONFIGURATION {
String COMMUNITY_HEALTH_WORKERS = "community_health_workers";
String CODE = "code";
String NAME = "name";
String SYNC_INTERVAL_IN_MINUTES = "sync_interval_in_minutes";


String MDA_CORDINATORS = "mda_coordinators";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,18 @@ public static Float getLocationBuffer() {
return Float.valueOf(getGlobalConfig(CONFIGURATION.LOCATION_BUFFER_RADIUS_IN_METRES, BuildConfig.MY_LOCATION_BUFFER + ""));
}

public static long getSyncInterval() {
return Long.parseLong(getGlobalConfig(CONFIGURATION.SYNC_INTERVAL_IN_MINUTES, getDefaultSyncInterval()));
}

private static String getDefaultSyncInterval() {
if (BuildConfig.BUILD_COUNTRY == Country.THAILAND || BuildConfig.BUILD_COUNTRY == Country.THAILAND_EN) {
return Constants.THAILAND_SYNC_INTERVAL;
} else {
return BuildConfig.SYNC_INTERVAL_IN_MINUTES + "";
}
}


public static Float getPixelsPerDPI(Resources resources) {
return TypedValue.applyDimension(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.graphics.Color;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
Expand All @@ -30,7 +31,6 @@
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.mapbox.android.core.permissions.PermissionsManager;
import com.mapbox.geojson.Feature;
import com.mapbox.geojson.FeatureCollection;
Expand Down Expand Up @@ -83,6 +83,7 @@
import org.smartregister.reveal.util.Country;
import org.smartregister.reveal.util.RevealJsonFormUtils;
import org.smartregister.reveal.util.RevealMapHelper;
import org.smartregister.util.NetworkUtils;

import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -115,6 +116,7 @@
import static org.smartregister.reveal.util.Constants.RequestCode.REQUEST_CODE_FILTER_TASKS;
import static org.smartregister.reveal.util.Constants.RequestCode.REQUEST_CODE_GET_JSON;
import static org.smartregister.reveal.util.Constants.RequestCode.REQUEST_CODE_TASK_LISTS;
import static org.smartregister.reveal.util.Constants.SYNC_BACK_OFF_DELAY;
import static org.smartregister.reveal.util.Constants.VERTICAL_OFFSET;
import static org.smartregister.reveal.util.FamilyConstants.Intent.START_REGISTRATION;
import static org.smartregister.reveal.util.Utils.displayDistanceScale;
Expand Down Expand Up @@ -158,7 +160,9 @@ public class ListTasksActivity extends BaseMapActivity implements ListTaskContra

private boolean hasRequestedLocation;

private Snackbar syncProgressSnackbar;
private boolean startedToastShown;

private boolean completedToastShown;

private BaseDrawerContract.View drawerView;

Expand Down Expand Up @@ -216,8 +220,6 @@ protected void onCreate(Bundle savedInstanceState) {
initializeCardViews();

initializeToolbar();

syncProgressSnackbar = Snackbar.make(rootView, getString(org.smartregister.R.string.syncing), Snackbar.LENGTH_INDEFINITE);
}

private void initializeCardViews() {
Expand Down Expand Up @@ -844,26 +846,33 @@ public void onDestroy() {

@Override
public void onSyncStart() {
if (SyncStatusBroadcastReceiver.getInstance().isSyncing()) {
syncProgressSnackbar.show();
if (SyncStatusBroadcastReceiver.getInstance().isSyncing() && !startedToastShown) {
displayToast(R.string.sync_started);
startedToastShown = true;
completedToastShown = false;
}
toggleProgressBarView(true);
}

@Override
public void onSyncInProgress(FetchStatus fetchStatus) {
if (FetchStatus.fetched.equals(fetchStatus)) {
syncProgressSnackbar.show();
return;
}
syncProgressSnackbar.dismiss();
if (fetchStatus.equals(FetchStatus.fetchedFailed)) {
Snackbar.make(rootView, org.smartregister.R.string.sync_failed, Snackbar.LENGTH_SHORT).show();
if (completedToastShown) return;
//To cover against consecutive sync starts firing, turn the flag off with delay
new Handler().postDelayed(() -> startedToastShown = false, SYNC_BACK_OFF_DELAY);
boolean isNetworkAvailable = NetworkUtils.isNetworkAvailable();
if (fetchStatus.equals(FetchStatus.fetchedFailed) && isNetworkAvailable) {
displayToast(org.smartregister.R.string.sync_failed);
} else if (fetchStatus.equals(FetchStatus.nothingFetched)) {
Snackbar.make(rootView, org.smartregister.R.string.sync_complete, Snackbar.LENGTH_SHORT).show();
displayToast(org.smartregister.R.string.sync_complete);
} else if (fetchStatus.equals(FetchStatus.noConnection)) {
Snackbar.make(rootView, org.smartregister.R.string.sync_failed_no_internet, Snackbar.LENGTH_SHORT).show();
displayToast(org.smartregister.R.string.sync_failed_no_internet);
} else if (fetchStatus.equals(FetchStatus.fetchedFailed) && !isNetworkAvailable) {
displayToast(org.smartregister.R.string.sync_failed_no_internet);
}
completedToastShown = true;
}

@Override
Expand All @@ -889,7 +898,6 @@ public void onResume() {
listTaskPresenter.onResume();

if (SyncStatusBroadcastReceiver.getInstance().isSyncing()) {
syncProgressSnackbar.show();
toggleProgressBarView(true);
}
}
Expand Down
1 change: 1 addition & 0 deletions opensrp-reveal/src/main/res/values-th/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,6 @@
<string name="view_paot_details">เปลี่ยนคำเป็น “แก้ไข”</string>
<string name="downloading">กำลังดาวน์โหลด</string>
<string name="map_download_progress">กำลังดาวน์โหลด: %,.2f %%</string>
<string name="sync_started">เริ่มการซิงค์แล้ว</string>

</resources>
1 change: 1 addition & 0 deletions opensrp-reveal/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@
<string name="start_p2p_syc">Start P2P Sync</string>

<string name="events">Events</string>
<string name="sync_started">Sync Started</string>
<string name="ok">Done</string>
<string name="locations">Locations</string>
<string name="plans">Plans</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import org.smartregister.domain.Obs;
import org.smartregister.reveal.BuildConfig;
import org.smartregister.reveal.R;
Expand Down Expand Up @@ -279,6 +280,35 @@ public void testGetCoordsFromGeometryReturnsCorrectValuesFromMultiPolygon() {

}

@Test
public void testGetSyncIntervalDefaultForThailand() throws Exception {
RevealApplication revealApplication = initRevealApplicationMock();

when(revealApplication.getServerConfigs()).thenReturn(new HashMap<>());
Whitebox.setInternalState(BuildConfig.class, BuildConfig.BUILD_COUNTRY, Country.THAILAND);
assertEquals(Utils.getSyncInterval(), 720);

Whitebox.setInternalState(BuildConfig.class, BuildConfig.BUILD_COUNTRY, Country.THAILAND_EN);
assertEquals(Utils.getSyncInterval(), 720);
}

@Test
public void testGetSyncIntervalDefaultForOthers() throws Exception {
RevealApplication revealApplication = initRevealApplicationMock();
when(revealApplication.getServerConfigs()).thenReturn(new HashMap<>());
Whitebox.setInternalState(BuildConfig.class, BuildConfig.BUILD_COUNTRY, Country.ZAMBIA);
assertEquals(Utils.getSyncInterval(), 480);
}

@Test
public void testGetSyncIntervalFromGlobalConfig() throws Exception {
RevealApplication revealApplication = initRevealApplicationMock();
Map<String, Object> globalConfigs= new HashMap<>();
globalConfigs.put(Constants.CONFIGURATION.SYNC_INTERVAL_IN_MINUTES, "80");
when(revealApplication.getServerConfigs()).thenReturn(globalConfigs);
assertEquals(Utils.getSyncInterval(), 80);
}

@Test
public void testShowWhenTrueCheckVisible() {
View view = mock(View.class);
Expand Down
Loading

0 comments on commit c255537

Please sign in to comment.