Skip to content

Commit

Permalink
JR| Loading Spinner When Syncing
Browse files Browse the repository at this point in the history
Add a loading spinner when syncing in the ChildSmartRegisterFragment

Part of fix for issue #474

Signed-off-by: Jason Rogena <jasonrogena@gmail.com>
  • Loading branch information
jasonrogena committed May 16, 2017
1 parent 665689c commit 4e4b802
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 40 deletions.
15 changes: 1 addition & 14 deletions opensrp-path/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ repositories {
maven { url 'https://maven.fabric.io/public' }
}

/*dependencies {
compile project(':opensrp-app')
compile 'com.android.support:design:22.2.1'
compile 'com.android.support:support-v4:22.1.1'
compile 'com.android.support:cardview-v7:22.2.1'
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
transitive = true;
}
compile 'id.zelory:compressor:1.0.4'
}*/

android {
compileSdkVersion 22
buildToolsVersion "23.0.2"
Expand Down Expand Up @@ -101,5 +88,5 @@ dependencies {
}
compile 'id.zelory:compressor:1.0.4'
compile 'com.twotoasters.SectionCursorAdapter:library:1.0.+'
//compile 'com.github.vijayrawatsan:android-json-form-wizard:1.1.1-SNAPSHOT'
compile 'com.github.ybq:Android-SpinKit:1.1.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private void refreshSyncStatusViews(FetchStatus fetchStatus) {
ViewGroup rootView = (ViewGroup) ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0);
if (syncStatusSnackbar != null) syncStatusSnackbar.dismiss();
syncStatusSnackbar = Snackbar.make(rootView, R.string.syncing,
Snackbar.LENGTH_INDEFINITE);
Snackbar.LENGTH_LONG);
syncStatusSnackbar.show();
} else {
if (fetchStatus != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private void refreshSyncStatusViews(FetchStatus fetchStatus) {
ViewGroup rootView = (ViewGroup) ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0);
if (syncStatusSnackbar != null) syncStatusSnackbar.dismiss();
syncStatusSnackbar = Snackbar.make(rootView, R.string.syncing,
Snackbar.LENGTH_INDEFINITE);
Snackbar.LENGTH_LONG);
syncStatusSnackbar.show();
syncMenuItem.setTitle(R.string.syncing);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.github.ybq.android.spinkit.style.ChasingDots;
import com.github.ybq.android.spinkit.style.Circle;
import com.github.ybq.android.spinkit.style.DoubleBounce;
import com.github.ybq.android.spinkit.style.RotatingCircle;
import com.github.ybq.android.spinkit.style.WanderingCubes;

import org.ei.opensrp.Context;
import org.ei.opensrp.commonregistry.CommonPersonObjectClient;
import org.ei.opensrp.commonregistry.CommonRepository;
Expand All @@ -23,6 +30,7 @@
import org.ei.opensrp.cursoradapter.CursorSortOption;
import org.ei.opensrp.cursoradapter.SmartRegisterPaginatedCursorAdapter;
import org.ei.opensrp.cursoradapter.SmartRegisterQueryBuilder;
import org.ei.opensrp.domain.FetchStatus;
import org.ei.opensrp.path.R;
import org.ei.opensrp.path.activity.ChildImmunizationActivity;
import org.ei.opensrp.path.activity.ChildSmartRegisterActivity;
Expand All @@ -34,6 +42,7 @@
import org.ei.opensrp.path.option.DateSort;
import org.ei.opensrp.path.option.StatusSort;
import org.ei.opensrp.path.provider.ChildSmartClientsProvider;
import org.ei.opensrp.path.receiver.SyncStatusBroadcastReceiver;
import org.ei.opensrp.path.servicemode.VaccinationServiceModeOption;
import org.ei.opensrp.path.view.LocationPickerView;
import org.ei.opensrp.provider.SmartRegisterClientsProvider;
Expand All @@ -51,7 +60,7 @@

import static android.view.View.INVISIBLE;

public class ChildSmartRegisterFragment extends BaseSmartRegisterFragment {
public class ChildSmartRegisterFragment extends BaseSmartRegisterFragment implements SyncStatusBroadcastReceiver.SyncStatusListener {
private final ClientActionHandler clientActionHandler = new ClientActionHandler();
private LocationPickerView clinicSelection;
private static final long NO_RESULT_SHOW_DIALOG_DELAY = 1000l;
Expand All @@ -61,6 +70,8 @@ public class ChildSmartRegisterFragment extends BaseSmartRegisterFragment {
private View filterSection;
private ImageView backButton;
private TextView nameInitials;
private LinearLayout btnBackToHome;
private ProgressBar syncProgressBar;
private int dueOverdueCount = 0;

@Override
Expand Down Expand Up @@ -166,6 +177,13 @@ protected void onResumption() {
if (filterMode()) {
toggleFilterSelection();
}
SyncStatusBroadcastReceiver.getInstance().addSyncStatusListener(this);
}

@Override
public void onPause() {
super.onPause();
SyncStatusBroadcastReceiver.getInstance().removeSyncStatusListener(this);
}

@Override
Expand Down Expand Up @@ -215,6 +233,10 @@ public void onClick(View view) {

backButton = (ImageView) view.findViewById(R.id.back_button);
nameInitials = (TextView) view.findViewById(R.id.name_inits);
btnBackToHome = (LinearLayout) view.findViewById(R.id.btn_back_to_home);
syncProgressBar = (ProgressBar) view.findViewById(R.id.sync_progress_bar);
Circle circle = new Circle();
syncProgressBar.setIndeterminateDrawable(circle);

AllSharedPreferences allSharedPreferences = Context.getInstance().allSharedPreferences();
String preferredName = allSharedPreferences.getANMPreferredName(allSharedPreferences.fetchRegisteredANM());
Expand All @@ -231,7 +253,7 @@ public void onClick(View view) {

View globalSearchButton = mView.findViewById(R.id.global_search);
globalSearchButton.setOnClickListener(clientActionHandler);

refreshSyncStatusViews();
}

@Override
Expand Down Expand Up @@ -317,6 +339,26 @@ public void initializeQueries() {
refresh();
}

private void refreshSyncStatusViews() {
if (SyncStatusBroadcastReceiver.getInstance().isSyncing()) {
syncProgressBar.setVisibility(View.VISIBLE);
btnBackToHome.setVisibility(View.GONE);
} else {
syncProgressBar.setVisibility(View.GONE);
btnBackToHome.setVisibility(View.VISIBLE);
}
}

@Override
public void onSyncStart() {
refreshSyncStatusViews();
}

@Override
public void onSyncComplete(FetchStatus fetchStatus) {
refreshSyncStatusViews();
}

private class ClientActionHandler implements View.OnClickListener {
@Override
public void onClick(View view) {
Expand Down
58 changes: 36 additions & 22 deletions opensrp-path/src/main/res/layout/tool_bar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,52 @@
android:focusableInTouchMode="true"
tools:showIn="@layout/smart_register_nav_bar_customized">

<LinearLayout
android:id="@+id/btn_back_to_home"
android:layout_width="wrap_content"
<RelativeLayout
android:id="@+id/back_btn_layout"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true">

<TextView
android:id="@+id/name_inits"
android:layout_width="47dp"
android:layout_height="47dp"
android:layout_margin="1dp"
android:background="@drawable/name_inits_bg"
android:gravity="center"
android:text="RW"
android:textAllCaps="true"
android:textColor="@color/actionbar"
android:textSize="25sp" />

<ImageView
android:id="@+id/back_button"
<LinearLayout
android:id="@+id/btn_back_to_home"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:src="@drawable/abc_ic_ab_back_mtrl_am_alpha"
android:visibility="gone" />
</LinearLayout>
android:layout_centerInParent="true">

<TextView
android:id="@+id/name_inits"
android:layout_width="47dp"
android:layout_height="47dp"
android:layout_margin="1dp"
android:background="@drawable/name_inits_bg"
android:gravity="center"
android:text="RW"
android:textAllCaps="true"
android:textColor="@color/actionbar"
android:textSize="25sp" />

<ImageView
android:id="@+id/back_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:src="@drawable/abc_ic_ab_back_mtrl_am_alpha"
android:visibility="gone" />
</LinearLayout>

<ProgressBar
android:id="@+id/sync_progress_bar"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_centerInParent="true"
android:indeterminate="true" />
</RelativeLayout>

<LinearLayout
android:id="@+id/title_layout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_toRightOf="@id/btn_back_to_home"
android:layout_toRightOf="@id/back_btn_layout"
android:background="@android:color/transparent"
android:orientation="horizontal"
android:paddingLeft="2.5dp"
Expand Down

0 comments on commit 4e4b802

Please sign in to comment.