• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OpenSRP / opensrp-client-child / #798

pending completion
#798

Pull #302

github-actions

web-flow
Merge 67ae6b5c4 into c099d4f8b
Pull Request #302: Migrate core to 6 - Memory Leak Fixes

4929 of 9038 relevant lines covered (54.54%)

0.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

16.28
opensrp-child/src/main/java/org/smartregister/child/activity/BaseActivity.java
1
package org.smartregister.child.activity;
2

3
import android.app.Activity;
4
import android.app.ProgressDialog;
5
import android.content.Intent;
6
import android.graphics.drawable.ColorDrawable;
7
import android.graphics.drawable.Drawable;
8
import android.os.Build;
9
import android.os.Bundle;
10
import android.os.Looper;
11
import android.util.Log;
12
import android.view.Gravity;
13
import android.view.Menu;
14
import android.view.MenuItem;
15
import android.view.View;
16
import android.view.ViewGroup;
17
import android.view.animation.Animation;
18
import android.view.animation.AnimationUtils;
19
import android.widget.Button;
20
import android.widget.ImageView;
21
import android.widget.LinearLayout;
22
import android.widget.TextView;
23

24
import androidx.annotation.StringRes;
25
import androidx.appcompat.app.ActionBarDrawerToggle;
26
import androidx.appcompat.widget.Toolbar;
27
import androidx.core.view.GravityCompat;
28
import androidx.drawerlayout.widget.DrawerLayout;
29

30
import com.google.android.material.navigation.NavigationView;
31
import com.google.android.material.snackbar.Snackbar;
32
import com.vijay.jsonwizard.constants.JsonFormConstants;
33

34
import org.apache.commons.lang3.StringUtils;
35
import org.joda.time.DateTime;
36
import org.joda.time.Days;
37
import org.joda.time.Hours;
38
import org.joda.time.Minutes;
39
import org.joda.time.Seconds;
40
import org.opensrp.api.constants.Gender;
41
import org.smartregister.AllConstants;
42
import org.smartregister.Context;
43
import org.smartregister.CoreLibrary;
44
import org.smartregister.child.R;
45
import org.smartregister.child.contract.ChildRegisterContract;
46
import org.smartregister.child.domain.ChildEventClient;
47
import org.smartregister.child.domain.UpdateRegisterParams;
48
import org.smartregister.child.interactor.ChildRegisterInteractor;
49
import org.smartregister.child.model.BaseChildRegisterModel;
50
import org.smartregister.child.toolbar.BaseToolbar;
51
import org.smartregister.child.util.ChildJsonFormUtils;
52
import org.smartregister.child.util.Utils;
53
import org.smartregister.commonregistry.CommonPersonObjectClient;
54
import org.smartregister.domain.FetchStatus;
55
import org.smartregister.job.SyncServiceJob;
56
import org.smartregister.receiver.SyncStatusBroadcastReceiver;
57
import org.smartregister.sync.helper.ECSyncHelper;
58
import org.smartregister.view.activity.MultiLanguageActivity;
59

60
import java.util.ArrayList;
61
import java.util.Calendar;
62
import java.util.List;
63
import java.util.Map;
64

65
import timber.log.Timber;
66

67
/**
68
 * Base activity class for all other PATH activity classes. Implements: - A uniform navigation bar that is launched by
69
 * swiping from the left - Support for specifying which {@link BaseToolbar} to use
70
 * <p/>
71
 * This activity requires that the base view for any child activity be {@link DrawerLayout} Make sure include the navigation
72
 * view as the last element in the activity's root DrawerLayout like this:
73
 * <p/>
74
 * <include layout="@layout/nav_view_base"/>
75
 * <p/>
76
 * Created by Jason Rogena - jrogena@ona.io on 16/02/2017.
77
 */
78
public abstract class BaseActivity extends MultiLanguageActivity
1✔
79
        implements NavigationView.OnNavigationItemSelectedListener, SyncStatusBroadcastReceiver.SyncStatusListener,
80
        ChildRegisterContract.InteractorCallBack {
81

82
    public static final int REQUEST_CODE_GET_JSON = 3432;
83
    public static final String INACTIVE = "inactive";
84
    public static final String LOST_TO_FOLLOW_UP = "lost_to_follow_up";
85
    private static final String TAG = "BaseActivity";
86
    private BaseToolbar toolbar;
87
    private Menu menu;
88
    private Snackbar syncStatusSnackbar;
89
    private ProgressDialog progressDialog;
90
    //  private NavigationItemListener navigationItemListener;
91
    // private CustomNavigationBarListener customNavigationBarListener;
92
    private ArrayList<Notification> notifications;
93
    private BaseActivityToggle toggle;
94
    private ChildRegisterContract.Interactor interactor;
95
    private BaseChildRegisterModel model;
96

97
    @Override
98
    protected void onCreate(Bundle savedInstanceState) {
99
        super.onCreate(savedInstanceState);
1✔
100
        setContentView(getContentView());
1✔
101
        toolbar = findViewById(getToolbarId());
1✔
102
        setSupportActionBar(toolbar);
1✔
103

104
     /*   DrawerLayout drawer = (DrawerLayout) findViewById(getDrawerLayoutId());
105
        toggle = new BaseActivityToggle(
106
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
107
        drawer.setDrawerListener(toggle);
108
toggle.syncState();
109
       */
110

111
        interactor = new ChildRegisterInteractor();
1✔
112
        model = new BaseChildRegisterModel();
1✔
113

114
        //NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
115
        //avigationView.setNavigationItemSelectedListener(this);
116

117
        notifications = new ArrayList<>();
1✔
118

119
        initializeProgressDialog();
1✔
120

121

122
        //  navigationItemListener = new NavigationItemListener(this, toolbar);
123
        //customNavigationBarListener = new CustomNavigationBarListener(this, toolbar);
124
    }
1✔
125

126
    /**
127
     * The layout resource file to user for this activity
128
     *
129
     * @return The resource id for the layout file to use
130
     */
131
    protected abstract int getContentView();
132

133
    /**
134
     * The id for the toolbar used in this activity
135
     *
136
     * @return The id for the toolbar used
137
     */
138
    protected abstract int getToolbarId();
139

140
    private void initializeProgressDialog() {
141
        progressDialog = new ProgressDialog(this);
1✔
142
        progressDialog.setCancelable(false);
1✔
143
        progressDialog.setTitle(getString(R.string.saving_dialog_title));
1✔
144
        progressDialog.setMessage(getString(R.string.please_wait_message));
1✔
145
    }
1✔
146

147
    @Override
148
    public void onSyncStart() {
149
        refreshSyncStatusViews(null);
×
150
    }
×
151

152
    @Override
153
    public void onSyncInProgress(FetchStatus fetchStatus) {
154
        refreshSyncStatusViews(fetchStatus);
×
155
    }
×
156

157
    @Override
158
    public void onSyncComplete(FetchStatus fetchStatus) {
159
        refreshSyncStatusViews(fetchStatus);
×
160
    }
×
161

162
    /////////////////////////for custom navigation //////////////////////////////////////////////////////
163
    private void refreshSyncStatusViews(FetchStatus fetchStatus) {/*
164
        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
165
        if (navigationView != null && navigationView.getMenu() != null) {
166
            LinearLayout syncMenuItem = (LinearLayout) navigationView.findViewById(R.id.nav_sync);
167
            if (syncMenuItem != null) {
168
                if (SyncStatusBroadcastReceiver.getInstance().isSyncing()) {
169
                    ViewGroup rootView = (ViewGroup) ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0);
170
                    if (syncStatusSnackbar != null) syncStatusSnackbar.dismiss();
171
                    syncStatusSnackbar = Snackbar.make(rootView, R.string.syncing,
172
                            Snackbar.LENGTH_LONG);
173
                    syncStatusSnackbar.show();
174
                    ((TextView) syncMenuItem.findViewById(R.id.nav_synctextview)).setText(R.string.syncing);
175
                } else {
176
                    if (fetchStatus != null) {
177
                        if (syncStatusSnackbar != null) syncStatusSnackbar.dismiss();
178
                        ViewGroup rootView = (ViewGroup) ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0);
179
                        if (fetchStatus.equals(FetchStatus.fetchedFailed)) {
180
                            syncStatusSnackbar = Snackbar.make(rootView, R.string.sync_failed, Snackbar.LENGTH_INDEFINITE);
181
                            syncStatusSnackbar.setActionTextColor(getResources().getColor(R.color.snackbar_action_color));
182
                            syncStatusSnackbar.setAction(R.string.retry, new View.OnClickListener() {
183
                                @Override
184
                                public void onClick(View v) {
185
                                    startSync();
186
                                }
187
                            });
188
                        } else if (fetchStatus.equals(FetchStatus.fetched)
189
                                || fetchStatus.equals(FetchStatus.nothingFetched)) {
190
                            syncStatusSnackbar = Snackbar.make(rootView, R.string.sync_complete, Snackbar.LENGTH_LONG);
191
                        } else if (fetchStatus.equals(FetchStatus.noConnection)) {
192
                            syncStatusSnackbar = Snackbar.make(rootView, R.string.sync_failed_no_internet, Snackbar
193
                            .LENGTH_LONG);
194
                        }
195
                        syncStatusSnackbar.show();
196
                    }
197

198
                    updateLastSyncText();
199
                }
200
            }
201
        }*/
202
    }
×
203

204
    public BaseToolbar getBaseToolbar() {
205
        return toolbar;
×
206
    }
207

208
    protected ActionBarDrawerToggle getDrawerToggle() {
209
        return toggle;
×
210
    }
211

212
    protected void openDrawer() {
213
        DrawerLayout drawer = findViewById(getDrawerLayoutId());
×
214
        drawer.openDrawer(Gravity.LEFT);
×
215
    }
×
216

217
    /**
218
     * The id for the base {@link DrawerLayout} for the activity
219
     *
220
     * @return
221
     */
222
    protected abstract int getDrawerLayoutId();
223

224
    private void updateLastSyncText() {/*
225
        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
226
        if (navigationView != null && navigationView.getMenu() != null) {
227
            TextView syncMenuItem = ((TextView) navigationView.findViewById(R.id.nav_synctextview));
228
            if (syncMenuItem != null) {
229
                String lastSync = getLastSyncTime();
230

231
                if (!TextUtils.isEmpty(lastSync)) {
232
                    lastSync = " " + String.format(getString(R.string.last_sync), lastSync);
233
                }
234
                syncMenuItem.setText(String.format(getString(R.string.sync_), lastSync));
235
            }
236
        }*/
237
    }
×
238

239
    private void initializeCustomNavbarLIsteners() {
240

241
/*
242
        final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
243
        LinearLayout syncMenuItem = (LinearLayout) drawer.findViewById(R.id.nav_sync);
244
        syncMenuItem.setOnClickListener(customNavigationBarListener);
245

246
        LinearLayout addchild = (LinearLayout) drawer.findViewById(R.id.nav_register);
247
        addchild.setOnClickListener(customNavigationBarListener);
248

249
        LinearLayout outofcatchment = (LinearLayout) drawer.findViewById(R.id.nav_record_vaccination_out_catchment);
250
        outofcatchment.setOnClickListener(customNavigationBarListener);
251

252
        LinearLayout stockregister = (LinearLayout) drawer.findViewById(R.id.stock_control);
253
        stockregister.setOnClickListener(customNavigationBarListener);
254

255
        LinearLayout childregister = (LinearLayout) drawer.findViewById(R.id.child_register);
256
        childregister.setOnClickListener(customNavigationBarListener);
257

258
        LinearLayout hia2 = (LinearLayout) drawer.findViewById(R.id.hia2_reports);
259
        hia2.setOnClickListener(customNavigationBarListener);
260

261
        LinearLayout coverage = (LinearLayout) drawer.findViewById(R.id.coverage_reports);
262
        coverage.setOnClickListener(customNavigationBarListener);
263

264
        LinearLayout dropout = (LinearLayout) drawer.findViewById(R.id.dropout_reports);
265
        dropout.setOnClickListener(customNavigationBarListener);
266
*/
267
    }
×
268

269
    private String getLastSyncTime() {
270
        String lastSync = "";
×
271
        long milliseconds = ECSyncHelper.getInstance(this).getLastCheckTimeStamp();
×
272
        if (milliseconds > 0) {
×
273
            DateTime lastSyncTime = new DateTime(milliseconds);
×
274
            DateTime now = new DateTime(Calendar.getInstance());
×
275
            Minutes minutes = Minutes.minutesBetween(lastSyncTime, now);
×
276
            if (minutes.getMinutes() < 1) {
×
277
                Seconds seconds = Seconds.secondsBetween(lastSyncTime, now);
×
278
                lastSync = seconds.getSeconds() + "s";
×
279
            } else if (minutes.getMinutes() >= 1 && minutes.getMinutes() < 60) {
×
280
                lastSync = minutes.getMinutes() + "m";
×
281
            } else if (minutes.getMinutes() >= 60 && minutes.getMinutes() < 1440) {
×
282
                Hours hours = Hours.hoursBetween(lastSyncTime, now);
×
283
                lastSync = hours.getHours() + "h";
×
284
            } else {
×
285
                Days days = Days.daysBetween(lastSyncTime, now);
×
286
                lastSync = days.getDays() + "d";
×
287
            }
288
        }
289
        return lastSync;
×
290
    }
291

292
    @Override
293
    public boolean onCreateOptionsMenu(Menu menu) {
294
        if (toolbar.getSupportedMenu() != 0) {
×
295
            this.menu = menu;
×
296
            getMenuInflater().inflate(toolbar.getSupportedMenu(), menu);
×
297
            toolbar.prepareMenu();
×
298
            return super.onCreateOptionsMenu(menu);
×
299
        } else {
300
            toolbar.prepareMenu();
×
301
        }
302

303
        return false;
×
304
    }
305

306
    @Override
307
    public boolean onOptionsItemSelected(MenuItem item) {
308
        return super.onOptionsItemSelected(toolbar.onMenuItemSelected(item));
×
309
    }
310

311
    public boolean onNavigationItemSelected(MenuItem item) {
312
        //  return navigationItemListener.onNavigationItemSelected(item);
313
        return false;
×
314
    }
315

316
    private void startSync() {
317
        SyncServiceJob.scheduleJobImmediately(SyncServiceJob.TAG);
×
318
    }
×
319

320
    /**
321
     * Updates all gender affected views
322
     *
323
     * @param gender The gender to update the
324
     */
325
    protected int[] updateGenderViews(Gender gender) {
326
        int darkShade = R.color.gender_neutral_dark_green;
×
327
        int normalShade = R.color.gender_neutral_green;
×
328
        int lightSade = R.color.gender_neutral_light_green;
×
329

330
        if (gender.equals(Gender.FEMALE)) {
×
331
            darkShade = R.color.female_dark_pink;
×
332
            normalShade = R.color.female_pink;
×
333
            lightSade = R.color.female_light_pink;
×
334
        } else if (gender.equals(Gender.MALE)) {
×
335
            darkShade = R.color.male_dark_blue;
×
336
            normalShade = R.color.male_blue;
×
337
            lightSade = R.color.male_light_blue;
×
338
        }
339

340
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
×
341
            getWindow().setStatusBarColor(getResources().getColor(darkShade));
×
342
        }
343
        toolbar.setBackground(new ColorDrawable(getResources().getColor(normalShade)));
×
344
        final ViewGroup viewGroup = (ViewGroup) ((ViewGroup) this.findViewById(android.R.id.content)).getChildAt(0);
×
345
        viewGroup.setBackground(new ColorDrawable(getResources().getColor(lightSade)));
×
346

347
        return new int[]{darkShade, normalShade, lightSade};
×
348
    }
349

350
    protected void startJsonForm(String formName, String entityId) {
351
        try {
352

353
            String locationId = Utils.context().allSharedPreferences().getPreference(AllConstants.CURRENT_LOCATION_ID);
×
354
            startJsonForm(formName, entityId, locationId);
×
355

356
        } catch (Exception e) {
×
357
            Log.e(TAG, e.getMessage(), e);
×
358
        }
×
359
    }
×
360

361
    protected void startJsonForm(String formName, String entityId, String locationId) throws Exception {
362
        ChildJsonFormUtils.startForm(this, REQUEST_CODE_GET_JSON, formName, entityId, locationId);
×
363
    }
×
364

365
    protected void showNotification(int message, int notificationIcon, int positiveButtonText,
366
                                    View.OnClickListener positiveButtonClick, int negativeButtonText,
367
                                    View.OnClickListener negativeButtonClick, Object tag) {
368
        String posBtnText = null;
×
369
        if (positiveButtonText != 0 && positiveButtonClick != null) {
×
370
            posBtnText = getString(positiveButtonText);
×
371
        }
372

373
        String negBtnText = null;
×
374
        if (negativeButtonText != 0 && negativeButtonClick != null) {
×
375
            negBtnText = getString(negativeButtonText);
×
376
        }
377

378
        showNotification(getString(message), getResources().getDrawable(notificationIcon), posBtnText, positiveButtonClick,
×
379
                negBtnText, negativeButtonClick, tag);
380
    }
×
381

382
    private void showNotification(String message, Drawable notificationIcon, String positiveButtonText,
383
                                  View.OnClickListener positiveButtonOnClick, String negativeButtonText,
384
                                  View.OnClickListener negativeButtonOnClick, Object tag) {
385
        Notification notification =
×
386
                new Notification(message, notificationIcon, positiveButtonText, positiveButtonOnClick, negativeButtonText,
387
                        negativeButtonOnClick, tag);
388

389
        // Add the notification as the last element in the notification list
390
        String notificationMessage = notification.message;
×
391
        if (notificationMessage == null) notificationMessage = "";
×
392
        for (Notification curNotification : notifications) {
×
393
            if (notificationMessage.equals(curNotification.message)) {
×
394
                notifications.remove(curNotification);
×
395
            }
396
        }
×
397
        notifications.add(notification);
×
398

399
        updateNotificationViews(notification);
×
400
    }
×
401

402
    private void updateNotificationViews(final Notification notification) {
403
        TextView notiMessage = findViewById(R.id.noti_message);
×
404
        notiMessage.setText(notification.message);
×
405
        Button notiPositiveButton = findViewById(R.id.noti_positive_button);
×
406
        notiPositiveButton.setTag(notification.tag);
×
407
        if (notification.positiveButtonText != null) {
×
408
            notiPositiveButton.setVisibility(View.VISIBLE);
×
409
            notiPositiveButton.setText(notification.positiveButtonText);
×
410
            notiPositiveButton.setOnClickListener(new View.OnClickListener() {
×
411
                @Override
412
                public void onClick(View v) {
413
                    if (notifications.size() > 0) {
×
414
                        notifications.remove(notifications.size() - 1);
×
415
                    }
416

417
                    if (notification.positiveButtonOnClick != null) {
×
418
                        notification.positiveButtonOnClick.onClick(v);
×
419
                    }
420

421
                    // Show the second last notification
422
                    if (notifications.size() > 0) {
×
423
                        updateNotificationViews(notifications.get(notifications.size() - 1));
×
424
                    }
425
                }
×
426
            });
427
        } else {
428
            notiPositiveButton.setVisibility(View.GONE);
×
429
        }
430

431
        Button notiNegativeButton = findViewById(R.id.noti_negative_button);
×
432
        notiNegativeButton.setTag(notification.tag);
×
433
        if (notification.negativeButtonText != null) {
×
434
            notiNegativeButton.setVisibility(View.VISIBLE);
×
435
            notiNegativeButton.setText(notification.negativeButtonText);
×
436
            notiNegativeButton.setOnClickListener(new View.OnClickListener() {
×
437
                @Override
438
                public void onClick(View v) {
439
                    if (notifications.size() > 0) {
×
440
                        notifications.remove(notifications.size() - 1);
×
441
                    }
442

443
                    if (notification.negativeButtonOnClick != null) {
×
444
                        notification.negativeButtonOnClick.onClick(v);
×
445
                    }
446

447
                    // Show the second last notification
448
                    if (notifications.size() > 0) {
×
449
                        updateNotificationViews(notifications.get(notifications.size() - 1));
×
450
                    }
451
                }
×
452
            });
453
        } else {
454
            notiNegativeButton.setVisibility(View.GONE);
×
455
        }
456

457
        ImageView notiIcon = findViewById(R.id.noti_icon);
×
458
        if (notification.notificationIcon != null) {
×
459
            notiIcon.setVisibility(View.VISIBLE);
×
460
            notiIcon.setImageDrawable(notification.notificationIcon);
×
461
        } else {
462
            notiIcon.setVisibility(View.GONE);
×
463
        }
464

465
        final LinearLayout notificationLL = findViewById(R.id.notification);
×
466

467
        Animation slideDownAnimation = AnimationUtils.loadAnimation(this, R.anim.slide_down);
×
468
        slideDownAnimation.setAnimationListener(new Animation.AnimationListener() {
×
469
            @Override
470
            public void onAnimationStart(Animation animation) {
471
                notificationLL.setVisibility(View.VISIBLE);
×
472
            }
×
473

474
            @Override
475
            public void onAnimationEnd(Animation animation) {
476

477
            }
×
478

479
            @Override
480
            public void onAnimationRepeat(Animation animation) {
481

482
            }
×
483
        });
484
        notificationLL.clearAnimation();
×
485
        notificationLL.startAnimation(slideDownAnimation);
×
486
    }
×
487

488
    protected void hideNotification() {
489
        final LinearLayout notification = findViewById(R.id.notification);
×
490
        if (notification.getVisibility() == View.VISIBLE) {
×
491
            Animation slideUpAnimation = AnimationUtils.loadAnimation(this, R.anim.slide_up);
×
492
            slideUpAnimation.setAnimationListener(new Animation.AnimationListener() {
×
493
                @Override
494
                public void onAnimationStart(Animation animation) {
495

496
                }
×
497

498
                @Override
499
                public void onAnimationEnd(Animation animation) {
500
                    notification.setVisibility(View.GONE);
×
501
                }
×
502

503
                @Override
504
                public void onAnimationRepeat(Animation animation) {
505

506
                }
×
507
            });
508
            notification.startAnimation(slideUpAnimation);
×
509
        }
510
    }
×
511

512
    public Context getOpenSRPContext() {
513
        return CoreLibrary.getInstance().context();
1✔
514
    }
515

516
    protected boolean isActiveStatus(CommonPersonObjectClient child) {
517
        String humanFriendlyStatus = getHumanFriendlyChildsStatus(child);
1✔
518
        return isActiveStatus(humanFriendlyStatus);
1✔
519
    }
520

521
    protected String getHumanFriendlyChildsStatus(CommonPersonObjectClient child) {
522
        Map<String, String> detailsMap = child.getColumnmaps();
1✔
523
        return getHumanFriendlyChildsStatus(detailsMap);
1✔
524
    }
525

526
    protected boolean isActiveStatus(String humanFriendlyStatus) {
527
        return getString(R.string.active).equalsIgnoreCase(humanFriendlyStatus);
1✔
528
    }
529

530
    protected String getHumanFriendlyChildsStatus(Map<String, String> detailsColumnMap) {
531
        String status = getString(R.string.active);
1✔
532
        if (detailsColumnMap.containsKey(INACTIVE) && detailsColumnMap.get(INACTIVE) != null &&
1✔
533
                detailsColumnMap.get(INACTIVE).equalsIgnoreCase(Boolean.TRUE.toString())) {
1✔
534
            status = getString(R.string.inactive);
1✔
535
        } else if (detailsColumnMap.containsKey(LOST_TO_FOLLOW_UP) && detailsColumnMap.get(LOST_TO_FOLLOW_UP) != null &&
1✔
536
                detailsColumnMap.get(LOST_TO_FOLLOW_UP).equalsIgnoreCase(Boolean.TRUE.toString())) {
×
537
            status = getString(R.string.lost_to_follow_up);
×
538
        }
539

540
        return status;
1✔
541
    }
542

543
    protected void showChildsStatus(String status) {
544
        LinearLayout linearLayout = findViewById(R.id.ll_inactive_status_bar_layout);
1✔
545
        boolean isStatusActive = getString(R.string.active).equals(status);
1✔
546

547
        if (linearLayout != null) {
1✔
548
            linearLayout.setVisibility((isStatusActive) ? View.GONE : View.VISIBLE);
1✔
549

550
            if (!isStatusActive) {
1✔
551
                TextView textView = findViewById(R.id.tv_inactive_status_bar_status_text);
1✔
552

553
                if (textView != null) {
1✔
554
                    textView.setText(String.format(getString(R.string.status_text), status));
1✔
555
                }
556
            }
557
        }
558
    }
1✔
559

560
    @Override
561
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
562
        if (requestCode == REQUEST_CODE_GET_JSON && resultCode == RESULT_OK) {
×
563
            String jsonString = data.getStringExtra(JsonFormConstants.JSON_FORM_KEY.JSON);
×
564
            if (jsonString != null) {
×
565
                UpdateRegisterParams updateRegisterParams = new UpdateRegisterParams();
×
566
                updateRegisterParams.setEditMode(false);
×
567

568
                saveForm(jsonString, updateRegisterParams);
×
569
            }
570
        }
571

572
        super.onActivityResult(requestCode, resultCode, data);
×
573
    }
×
574

575
    @Override
576
    public void onBackPressed() {
577
        DrawerLayout drawer = findViewById(getDrawerLayoutId());
×
578
        if (drawer != null && drawer.isDrawerOpen(GravityCompat.START)) {
×
579
            drawer.closeDrawer(GravityCompat.START);
×
580
        } else {
581
            super.onBackPressed();
×
582
        }
583
    }
×
584

585
    @Override
586
    protected void onPause() {
587
        super.onPause();
×
588
        unregisterSyncStatusBroadcastReceiver();
×
589
        if (progressDialog != null) progressDialog.dismiss();
×
590
    }
×
591

592
    private void unregisterSyncStatusBroadcastReceiver() {
593
        SyncStatusBroadcastReceiver.getInstance().removeSyncStatusListener(this);
×
594
    }
×
595

596
    @Override
597
    protected void onResume() {
598
        super.onResume();
×
599
        registerSyncStatusBroadcastReceiver();
×
600
    }
×
601

602
    private void registerSyncStatusBroadcastReceiver() {
603
        SyncStatusBroadcastReceiver.getInstance().addSyncStatusListener(this);
×
604
    }
×
605

606
    public void saveForm(String jsonString, UpdateRegisterParams updateRegisterParams) {
607
        try {
608
            if (updateRegisterParams.getFormTag() == null) {
×
609
                updateRegisterParams.setFormTag(ChildJsonFormUtils.formTag(Utils.getAllSharedPreferences()));
×
610
            }
611

612
            List<ChildEventClient> childEventClientList = model.processRegistration(
×
613
                    jsonString,
614
                    updateRegisterParams.getFormTag(),
×
615
                    updateRegisterParams.isEditMode()
×
616
            );
617

618
            if (childEventClientList == null || childEventClientList.isEmpty()) {
×
619
                return;
×
620
            }
621

622
            interactor.saveRegistration(childEventClientList, jsonString, updateRegisterParams, this);
×
623
        } catch (Exception e) {
×
624
            Timber.e(Log.getStackTraceString(e));
×
625
        }
×
626
    }
×
627

628
    protected BaseToolbar getToolbar() {
629
        return toolbar;
1✔
630
    }
631

632
    public Menu getMenu() {
633
        return menu;
×
634
    }
635

636
    /**
637
     * The activity to go back to
638
     *
639
     * @return
640
     */
641
    protected abstract Class onBackActivity();
642

643
    public void processInThread(Runnable runnable) {
644
        if (Looper.myLooper() == Looper.getMainLooper()) {
×
645
            new Thread(runnable).start();
×
646
        }
647
    }
×
648

649
    public void showProgressDialog() {
650
        showProgressDialog(getString(R.string.saving_dialog_title), getString(R.string.please_wait_message));
×
651
    }
×
652

653
    public void showProgressDialog(String title, String message) {
654
        if (progressDialog != null) {
1✔
655
            if (StringUtils.isNotBlank(title)) progressDialog.setTitle(title);
1✔
656

657
            if (StringUtils.isNotBlank(message)) progressDialog.setMessage(message);
1✔
658

659
            if (!isFinishing()) progressDialog.show();
1✔
660
        }
661
    }
1✔
662

663
    public void hideProgressDialog() {
664
        if (progressDialog != null && !isFinishing()) progressDialog.dismiss();
×
665
    }
×
666

667
    ////////////////////////////////////////////////////////////////
668
    // Inner classes
669
    ////////////////////////////////////////////////////////////////
670

671
    private class BaseActivityToggle extends ActionBarDrawerToggle {
672

673
        private BaseActivityToggle(Activity activity, DrawerLayout drawerLayout, Toolbar toolbar,
674
                                   @StringRes int openDrawerContentDescRes, @StringRes int closeDrawerContentDescRes) {
×
675
            super(activity, drawerLayout, toolbar, openDrawerContentDescRes, closeDrawerContentDescRes);
×
676
        }
×
677

678
        @Override
679
        public void onDrawerOpened(View drawerView) {
680
            super.onDrawerOpened(drawerView);
×
681
            if (!SyncStatusBroadcastReceiver.getInstance().isSyncing()) {
×
682
                updateLastSyncText();
×
683
            }
684
        }
×
685

686
        @Override
687
        public void onDrawerClosed(View drawerView) {
688
            super.onDrawerClosed(drawerView);
×
689
        }
×
690
    }
691

692
    private class Notification {
693
        public final String message;
694
        public final Drawable notificationIcon;
695
        public final String positiveButtonText;
696
        public final View.OnClickListener positiveButtonOnClick;
697
        public final String negativeButtonText;
698
        public final View.OnClickListener negativeButtonOnClick;
699
        public final Object tag;
700

701
        private Notification(String message, Drawable notificationIcon, String positiveButtonText,
702
                             View.OnClickListener positiveButtonOnClick, String negativeButtonText,
703
                             View.OnClickListener negativeButtonOnClick, Object tag) {
×
704
            this.message = message;
×
705
            this.notificationIcon = notificationIcon;
×
706
            this.positiveButtonText = positiveButtonText;
×
707
            this.positiveButtonOnClick = positiveButtonOnClick;
×
708
            this.negativeButtonText = negativeButtonText;
×
709
            this.negativeButtonOnClick = negativeButtonOnClick;
×
710
            this.tag = tag;
×
711
        }
×
712

713
        @Override
714
        public boolean equals(Object o) {
715
            if (o instanceof Notification) {
×
716
                Notification notification = (Notification) o;
×
717
                String message = this.message;
×
718
                if (message == null) message = "";
×
719
                String positiveButtonText = this.positiveButtonText;
×
720
                if (positiveButtonText == null) positiveButtonText = "";
×
721
                String negativeButtonText = this.negativeButtonText;
×
722
                if (negativeButtonText == null) negativeButtonText = "";
×
723

724
                return message.equals(notification.message) && positiveButtonText.equals(notification.positiveButtonText) &&
×
725
                        negativeButtonText.equals(notification.negativeButtonText);
×
726
            }
727
            return false;
×
728
        }
729
    }
730
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc