• 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

0.0
opensrp-child/src/main/java/org/smartregister/child/fragment/StatusEditDialogFragment.java
1
package org.smartregister.child.fragment;
2

3
import android.annotation.SuppressLint;
4
import android.app.Activity;
5
import android.app.AlertDialog;
6
import android.app.DialogFragment;
7
import android.app.ProgressDialog;
8
import android.os.AsyncTask;
9
import android.os.Bundle;
10
import android.os.Handler;
11
import android.view.LayoutInflater;
12
import android.view.View;
13
import android.view.ViewGroup;
14
import android.view.Window;
15
import android.widget.FrameLayout;
16
import android.widget.ImageView;
17
import android.widget.LinearLayout;
18

19
import androidx.annotation.NonNull;
20

21
import org.smartregister.child.R;
22
import org.smartregister.child.event.ClientStatusUpdateEvent;
23
import org.smartregister.child.listener.StatusChangeListener;
24
import org.smartregister.child.task.ArchiveRecordTask;
25
import org.smartregister.child.util.Constants;
26
import org.smartregister.util.Utils;
27

28
import java.util.Map;
29

30
@SuppressLint("ValidFragment")
31
public class StatusEditDialogFragment extends DialogFragment {
32
    private static final String inactive = Constants.CHILD_STATUS.INACTIVE;
33
    private static final String lostToFollowUp = Constants.CHILD_STATUS.LOST_TO_FOLLOW_UP;
34
    private static Map<String, String> details;
35
    private StatusChangeListener listener;
36

37
    private StatusEditDialogFragment(Map<String, String> details) {
×
38
        StatusEditDialogFragment.details = details;
×
39
    }
×
40

41
    public static StatusEditDialogFragment newInstance(Map<String, String> details) {
42
        return new StatusEditDialogFragment(details);
×
43
    }
44

45
    @Override
46
    public void onCreate(Bundle savedInstanceState) {
47
        super.onCreate(savedInstanceState);
×
48
        setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog);
×
49
    }
×
50

51
    @Override
52
    public void onStart() {
53
        super.onStart();
×
54
        // without a handler, the window sizes itself correctly
55
        // but the keyboard does not show up
56
        new Handler().post(new Runnable() {
×
57
            @Override
58
            public void run() {
59
                Window window = null;
×
60
                if (getDialog() != null) {
×
61
                    window = getDialog().getWindow();
×
62
                }
63

64
                if (window == null) {
×
65
                    return;
×
66
                }
67

68
                window.setLayout(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
×
69

70
            }
×
71
        });
72

73
    }
×
74

75
    @Override
76
    public void onAttach(Activity activity) {
77
        super.onAttach(activity);
×
78
        // Verify that the host activity implements the callback interface
79
        try {
80
            // Instantiate the NoticeDialogListener so we can send events to the host
81
            listener = (StatusChangeListener) activity;
×
82
        } catch (ClassCastException e) {
×
83
            // The activity doesn't implement the interface, throw exception
84
            throw new ClassCastException(activity.toString() + " must implement StatusChangeListener");
×
85
        }
×
86
    }
×
87

88
    @Override
89
    public View onCreateView(final LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
90

91
        ViewGroup dialogView = (ViewGroup) inflater.inflate(R.layout.status_edit_dialog_view, container, false);
×
92
        LinearLayout activeLayout = dialogView.findViewById(R.id.activelayout);
×
93
        LinearLayout inactiveLayout = dialogView.findViewById(R.id.inactivelayout);
×
94
        LinearLayout lostToFollowUpLayout = dialogView.findViewById(R.id.losttofollowuplayout);
×
95
        LinearLayout childArchiveRecordLayout = dialogView.findViewById(R.id.child_archive_record_layout);
×
96
        final ImageView activeImageView = dialogView.findViewById(R.id.active_check);
×
97
        final ImageView inactiveImageView = dialogView.findViewById(R.id.inactive_check);
×
98
        final ImageView lostToFollowUpImageView = dialogView.findViewById(R.id.lost_to_followup_check);
×
99

100
        activeImageView.setVisibility(View.INVISIBLE);
×
101
        inactiveImageView.setVisibility(View.INVISIBLE);
×
102
        lostToFollowUpImageView.setVisibility(View.INVISIBLE);
×
103

104
        if (details.containsKey(inactive) && details.get(inactive) != null &&
×
105
                details.get(inactive).equalsIgnoreCase(Boolean.TRUE.toString())) {
×
106
            inactiveImageView.setVisibility(View.VISIBLE);
×
107
            activeImageView.setVisibility(View.INVISIBLE);
×
108
            lostToFollowUpImageView.setVisibility(View.INVISIBLE);
×
109

110
        } else if (details.containsKey(lostToFollowUp) && details.get(lostToFollowUp) != null &&
×
111
                details.get(lostToFollowUp).equalsIgnoreCase(Boolean.TRUE.toString())) {
×
112
            lostToFollowUpImageView.setVisibility(View.VISIBLE);
×
113
            inactiveImageView.setVisibility(View.INVISIBLE);
×
114
            activeImageView.setVisibility(View.INVISIBLE);
×
115

116
        } else {
117
            activeImageView.setVisibility(View.VISIBLE);
×
118
            inactiveImageView.setVisibility(View.INVISIBLE);
×
119
            lostToFollowUpImageView.setVisibility(View.INVISIBLE);
×
120
        }
121

122
        activeLayout.setOnClickListener(v -> {
×
123
            UpdateView updateView = new UpdateView(STATUS.ACTIVE, listener, details);
×
124
            updateView.setImageView(activeImageView, inactiveImageView, lostToFollowUpImageView);
×
125

126
            Utils.startAsyncTask(updateView, null);
×
127

128
        });
×
129

130
        inactiveLayout.setOnClickListener(v -> {
×
131
            UpdateView updateView = new UpdateView(STATUS.IN_ACTIVE, listener, details);
×
132
            updateView.setImageView(activeImageView, inactiveImageView, lostToFollowUpImageView);
×
133

134
            Utils.startAsyncTask(updateView, null);
×
135
        });
×
136

137
        lostToFollowUpLayout.setOnClickListener(v -> {
×
138
            UpdateView updateView = new UpdateView(STATUS.LOST_TO_FOLLOW_UP, listener, details);
×
139
            updateView.setImageView(activeImageView, inactiveImageView, lostToFollowUpImageView);
×
140

141
            Utils.startAsyncTask(updateView, null);
×
142
        });
×
143

144
        childArchiveRecordLayout.setOnClickListener(v -> {
×
145
            AlertDialog dialog = new AlertDialog.Builder(getActivity(), R.style.AppThemeAlertDialog)
×
146
                    .setTitle(R.string.child_archive_record_text)
×
147
                    .setCancelable(true)
×
148
                    .setMessage(R.string.child_archive_dialog_title)
×
149
                    .setNegativeButton(R.string.yes, (dialog1, which) -> archiveChildRecord(details))
×
150
                    .setPositiveButton(R.string.no, (dialog12, which) -> dialog12.dismiss()).create();
×
151

152
            dialog.show();
×
153
        });
×
154

155

156
        return dialogView;
×
157
    }
158

159
    protected void archiveChildRecord(@NonNull Map<String, String> details) {
160
        new ArchiveRecordTask(getActivity(), details).execute();
×
161
    }
×
162

163
    private enum STATUS {
×
164
        ACTIVE, IN_ACTIVE, LOST_TO_FOLLOW_UP
×
165
    }
166

167
    ////////////////////////////////////////////////////////////////
168
    // Inner classes
169
    ////////////////////////////////////////////////////////////////
170
    private class UpdateView extends AsyncTask<Void, Void, Boolean> {
171
        private StatusChangeListener listener;
172
        private STATUS status;
173
        private Map<String, String> details;
174
        private ImageView activeImageView;
175
        private ImageView inactiveImageView;
176
        private ImageView lostToFollowUpImageView;
177
        private ProgressDialog progressDialog;
178

179
        private UpdateView(STATUS status, StatusChangeListener listener, Map<String, String> details) {
×
180
            this.status = status;
×
181
            this.listener = listener;
×
182
            this.details = details;
×
183

184
            this.progressDialog = new ProgressDialog(getActivity());
×
185
            this.progressDialog.setCancelable(false);
×
186
            this.progressDialog.setTitle(getString(R.string.updating_dialog_title));
×
187
            this.progressDialog.setMessage(getString(R.string.please_wait_message));
×
188
        }
×
189

190
        private void setImageView(ImageView activeImageView, ImageView inactiveImageView,
191
                                  ImageView lostToFollowUpImageView) {
192
            this.activeImageView = activeImageView;
×
193
            this.inactiveImageView = inactiveImageView;
×
194
            this.lostToFollowUpImageView = lostToFollowUpImageView;
×
195
        }
×
196

197
        @Override
198
        protected Boolean doInBackground(Void... params) {
199
            boolean updateViews = false;
×
200
            switch (status) {
×
201
                case ACTIVE:
202
                    if (details.containsKey(inactive) && details.get(inactive) != null &&
×
203
                            details.get(inactive).equalsIgnoreCase(Boolean.TRUE.toString())) {
×
204
                        listener.updateClientAttribute(inactive, false);
×
205
                        updateViews = true;
×
206
                        details.put(inactive, "false");
×
207
                    }
208

209
                    if (details.containsKey(lostToFollowUp) && details.get(lostToFollowUp) != null &&
×
210
                            details.get(lostToFollowUp).equalsIgnoreCase(Boolean.TRUE.toString())) {
×
211
                        listener.updateClientAttribute(lostToFollowUp, false);
×
212
                        details.put(lostToFollowUp, "false");
×
213
                        updateViews = true;
×
214
                    }
215
                    break;
216

217
                case IN_ACTIVE:
218
                    if (!details.containsKey(inactive) || !(details.containsKey(inactive) && details.get(inactive) != null &&
×
219
                            details.get(inactive).equalsIgnoreCase(Boolean.TRUE.toString()))) {
×
220
                        listener.updateClientAttribute(inactive, true);
×
221
                        details.put(inactive, "true");
×
222
                        if (details.containsKey(lostToFollowUp) && details.get(lostToFollowUp) != null &&
×
223
                                details.get(lostToFollowUp).equalsIgnoreCase(Boolean.TRUE.toString())) {
×
224
                            listener.updateClientAttribute(lostToFollowUp, false);
×
225
                            details.put(lostToFollowUp, "false");
×
226
                        }
227
                        updateViews = true;
×
228
                    }
229
                    break;
230
                case LOST_TO_FOLLOW_UP:
231
                    if (!details.containsKey(lostToFollowUp) ||
×
232
                            !(details.containsKey(lostToFollowUp) && details.get(lostToFollowUp) != null &&
×
233
                                    details.get(lostToFollowUp).equalsIgnoreCase(Boolean.TRUE.toString()))) {
×
234
                        listener.updateClientAttribute(lostToFollowUp, true);
×
235
                        details.put(lostToFollowUp, "true");
×
236
                        if (details.containsKey(inactive) && details.get(inactive) != null &&
×
237
                                details.get(inactive).equalsIgnoreCase(Boolean.TRUE.toString())) {
×
238
                            listener.updateClientAttribute(inactive, false);
×
239
                            details.put(inactive, "false");
×
240
                        }
241
                        updateViews = true;
×
242
                    }
243
                    break;
244
                default:
245
                    break;
246

247
            }
248

249
            return updateViews;
×
250
        }
251

252
        @Override
253
        protected void onPreExecute() {
254
            this.progressDialog.show();
×
255
        }
×
256

257
        @Override
258
        protected void onPostExecute(Boolean updateViews) {
259
            this.progressDialog.dismiss();
×
260
            if (updateViews) {
×
261
                switch (status) {
×
262
                    case ACTIVE:
263
                        activeImageView.setVisibility(View.VISIBLE);
×
264
                        inactiveImageView.setVisibility(View.INVISIBLE);
×
265
                        lostToFollowUpImageView.setVisibility(View.INVISIBLE);
×
266
                        break;
×
267
                    case IN_ACTIVE:
268
                        activeImageView.setVisibility(View.INVISIBLE);
×
269
                        inactiveImageView.setVisibility(View.VISIBLE);
×
270
                        lostToFollowUpImageView.setVisibility(View.INVISIBLE);
×
271
                        break;
×
272
                    case LOST_TO_FOLLOW_UP:
273
                        activeImageView.setVisibility(View.INVISIBLE);
×
274
                        inactiveImageView.setVisibility(View.INVISIBLE);
×
275
                        lostToFollowUpImageView.setVisibility(View.VISIBLE);
×
276
                        break;
×
277
                    default:
278
                        break;
279
                }
280

281
                if (status != null) {
×
282
                    org.smartregister.child.util.Utils.postEvent(new ClientStatusUpdateEvent(status.toString()));
×
283
                }
284
            }
285
            listener.updateStatus(details);
×
286
            dismiss();
×
287

288
        }
×
289
    }
290

291
}
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