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

opensrp / opensrp-client-native-form / #57

12 Sep 2023 07:43AM UTC coverage: 66.18% (+0.2%) from 66.013%
#57

push

github-actions

web-flow
Merge pull request #667 from opensrp/fix_tech_debt_660

Add tests for setUpOptiBpActivityResultListener

8432 of 12741 relevant lines covered (66.18%)

0.66 hits per line

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

71.07
android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/NativeRadioButtonFactory.java
1

2
package com.vijay.jsonwizard.widgets;
3

4
import static com.vijay.jsonwizard.widgets.DatePickerFactory.DATE_FORMAT;
5

6
import android.app.Activity;
7
import android.app.Fragment;
8
import android.app.FragmentTransaction;
9
import android.content.Context;
10
import android.content.Intent;
11
import android.graphics.Color;
12
import android.os.Build;
13
import android.text.TextUtils;
14
import android.util.TypedValue;
15
import android.view.LayoutInflater;
16
import android.view.View;
17
import android.view.ViewGroup;
18
import android.widget.DatePicker;
19
import android.widget.ImageView;
20
import android.widget.LinearLayout;
21
import android.widget.RadioButton;
22
import android.widget.RadioGroup;
23
import android.widget.RelativeLayout;
24
import android.widget.TextView;
25

26
import androidx.annotation.NonNull;
27
import androidx.annotation.Nullable;
28
import androidx.constraintlayout.widget.ConstraintLayout;
29

30
import com.rey.material.util.ViewUtil;
31
import com.vijay.jsonwizard.R;
32
import com.vijay.jsonwizard.activities.JsonFormActivity;
33
import com.vijay.jsonwizard.constants.JsonFormConstants;
34
import com.vijay.jsonwizard.customviews.DatePickerDialog;
35
import com.vijay.jsonwizard.fragments.JsonFormFragment;
36
import com.vijay.jsonwizard.interfaces.CommonListener;
37
import com.vijay.jsonwizard.interfaces.FormWidgetFactory;
38
import com.vijay.jsonwizard.interfaces.JsonApi;
39
import com.vijay.jsonwizard.utils.FormUtils;
40
import com.vijay.jsonwizard.utils.Utils;
41
import com.vijay.jsonwizard.utils.ValidationStatus;
42
import com.vijay.jsonwizard.views.CustomTextView;
43
import com.vijay.jsonwizard.views.JsonFormFragmentView;
44

45
import org.apache.commons.lang3.StringUtils;
46
import org.jetbrains.annotations.NotNull;
47
import org.json.JSONArray;
48
import org.json.JSONException;
49
import org.json.JSONObject;
50

51
import java.util.ArrayList;
52
import java.util.Calendar;
53
import java.util.HashMap;
54
import java.util.HashSet;
55
import java.util.List;
56
import java.util.Map;
57
import java.util.Set;
58

59
import timber.log.Timber;
60

61

62
/**
63
 * Created by samuelgithengi on 8/16/18.
64
 */
65
public class NativeRadioButtonFactory implements FormWidgetFactory {
1✔
66

67
    private static final String TAG = NativeRadioButtonFactory.class.getCanonicalName();
1✔
68
    private final FormUtils formUtils = new FormUtils();
1✔
69
    private final CustomTextViewClickListener customTextViewClickListener = new CustomTextViewClickListener();
1✔
70
    private RadioButton radioButton;
71
    private CustomTextView extraInfoTextView;
72
    private CustomTextView specifyTextView;
73
    private CustomTextView reasonsTextView;
74
    private Context context;
75
    private JsonFormFragment formFragment;
76
    private String stepName;
77
    private JSONArray canvasIds;
78

79
    public static void showDateDialog(View view) {
80
        Context context = (Context) view.getTag(R.id.specify_context);
1✔
81
        CustomTextView customTextView = (CustomTextView) view.getTag(R.id.specify_textview);
1✔
82
        RadioButton radioButton = (RadioButton) view.getTag(R.id.native_radio_button);
1✔
83
        DatePickerDialog datePickerDialog = new DatePickerDialog();
1✔
84
        JSONObject jsonObject = (JSONObject) ((radioButton).getTag(R.id.option_json_object));
1✔
85

86
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
1✔
87
            datePickerDialog.setCalendarViewShown(false);
1✔
88

89
            try {
90
                if (jsonObject != null) {
1✔
91

92
                    if (jsonObject.has(JsonFormConstants.MIN_DATE)) {
1✔
93
                        Calendar minDate = FormUtils.getDate(jsonObject.getString(JsonFormConstants.MIN_DATE));
1✔
94
                        minDate.set(Calendar.HOUR_OF_DAY, 0);
1✔
95
                        minDate.set(Calendar.MINUTE, 0);
1✔
96
                        minDate.set(Calendar.SECOND, 0);
1✔
97
                        minDate.set(Calendar.MILLISECOND, 0);
1✔
98
                        datePickerDialog.setMinDate(minDate.getTimeInMillis());
1✔
99
                    }
100

101
                    if (jsonObject.has(JsonFormConstants.MAX_DATE)) {
1✔
102
                        Calendar maxDate = FormUtils.getDate(jsonObject.getString(JsonFormConstants.MAX_DATE));
1✔
103
                        maxDate.set(Calendar.HOUR_OF_DAY, 23);
1✔
104
                        maxDate.set(Calendar.MINUTE, 59);
1✔
105
                        maxDate.set(Calendar.SECOND, 59);
1✔
106
                        maxDate.set(Calendar.MILLISECOND, 999);
1✔
107
                        datePickerDialog.setMaxDate(maxDate.getTimeInMillis());
1✔
108

109
                    }
110
                }
111

112
            } catch (JSONException e) {
×
113
                Timber.e(e);
×
114
            }
1✔
115

116
        }
117

118
        datePickerDialog.setContext(context);
1✔
119
        setDate(datePickerDialog, radioButton, customTextView, context);
1✔
120
        showDatePickerDialog((Activity) context, datePickerDialog, radioButton);
1✔
121
    }
1✔
122

123
    private static void setDate(DatePickerDialog datePickerDialog, final RadioButton radioButton,
124
                                final CustomTextView customTextView, final Context context) {
125
        final String[] arrayString = radioButton.getText().toString().split(":");
1✔
126
        datePickerDialog.setOnDateSetListener(new android.app.DatePickerDialog.OnDateSetListener() {
1✔
127
            @Override
128
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
129
                Calendar calendarDate = Calendar.getInstance();
×
130
                calendarDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
×
131
                calendarDate.set(Calendar.MONTH, monthOfYear);
×
132
                calendarDate.set(Calendar.YEAR, year);
×
133
                if (calendarDate.getTimeInMillis() >= view.getMinDate() &&
×
134
                        calendarDate.getTimeInMillis() <= view.getMaxDate()) {
×
135
                    radioButton.setText(arrayString[0] + ": " + DATE_FORMAT.format(calendarDate.getTime()));
×
136
                    customTextView.setText(
×
137
                            createSpecifyText(context.getResources().getString(R.string.radio_button_tap_to_change)));
×
138

139
                    if (context instanceof JsonFormActivity) {
×
140
                        HashMap<String, String> map = new HashMap<>();
×
141
                        map.put(customTextView.getTag(R.id.key).toString(),
×
142
                                customTextView.getTag(R.id.childKey) + ":" + DATE_FORMAT.format(calendarDate.getTime()));
×
143

144
                        Intent intent = new Intent(JsonFormConstants.INTENT_ACTION.JSON_FORM_ACTIVITY);
×
145
                        intent.putExtra(JsonFormConstants.INTENT_KEY.MESSAGE, map);
×
146
                        intent.putExtra(JsonFormConstants.STEPNAME, ((String) customTextView.getTag(R.id.specify_step_name)));
×
147

148
                        intent.putExtra(JsonFormConstants.INTENT_KEY.MESSAGE_TYPE,
×
149
                                JsonFormConstants.MESSAGE_TYPE.GLOBAL_VALUES);
150

151
                        ((JsonFormActivity) context).getLocalBroadcastManager().sendBroadcast(intent);
×
152
                    }
153
                    String key = (String) customTextView.getTag(R.id.key);
×
154
                    String childKey = (String) customTextView.getTag(R.id.childKey);
×
155
                    String stepName = (String) customTextView.getTag(R.id.specify_step_name);
×
156
                    Context context = (Context) customTextView.getTag(R.id.specify_context);
×
157

158
                    JSONArray fields = new FormUtils().getFormFields(stepName, context);
×
159
                    if (fields.length() > 0) {
×
160
                        for (int i = 0; i < fields.length(); i++) {
×
161
                            try {
162
                                JSONObject widget = fields.getJSONObject(i);
×
163
                                if (widget != null && widget.getString(JsonFormConstants.KEY).equals(key)) {
×
164
                                    radioButtonOptionAssignSecondaryValue(widget, childKey, calendarDate);
×
165
                                }
166
                                if (widget != null && widget.getString(JsonFormConstants.KEY)
×
167
                                        .equals(key + JsonFormConstants.SPECIFY_DATE_HIDDEN_FIELD_SUFFIX)) {
×
168
                                    assignHiddenDateValue(widget, calendarDate);
×
169
                                }
170
                            } catch (JSONException e) {
×
171
                                Timber.e(e);
×
172
                            }
×
173
                        }
174
                    }
175

176
                } else {
×
177
                    radioButton.setText(arrayString[0]);
×
178
                }
179
            }
×
180
        });
181
    }
1✔
182

183
    private static void showDatePickerDialog(Activity context, DatePickerDialog datePickerDialog, RadioButton radioButton) {
184
        FragmentTransaction ft = context.getFragmentManager().beginTransaction();
1✔
185
        Fragment prev = context.getFragmentManager().findFragmentByTag(TAG);
1✔
186
        if (prev != null) {
1✔
187
            ft.remove(prev);
×
188
        }
189

190
        ft.addToBackStack(null);
1✔
191

192
        datePickerDialog.show(ft, TAG);
1✔
193
        Calendar calendar = getDate(radioButton);
1✔
194
        datePickerDialog.setDate(calendar.getTime());
1✔
195
    }
1✔
196

197
    private static String createSpecifyText(String text) {
198
        return text == null || text.isEmpty() ? "" : "(" + text + ")";
1✔
199
    }
200

201
    /**
202
     * This assign the secondary value to the radio button options
203
     *
204
     * @param jsonObject
205
     * @param childKey
206
     * @param calendarDate
207
     * @throws JSONException
208
     */
209
    private static void radioButtonOptionAssignSecondaryValue(JSONObject jsonObject, String childKey, Calendar calendarDate)
210
            throws JSONException {
211
        if (jsonObject.has(JsonFormConstants.OPTIONS_FIELD_NAME)) {
×
212
            JSONArray jsonArray = jsonObject.getJSONArray(JsonFormConstants.OPTIONS_FIELD_NAME);
×
213
            for (int i = 0; i < jsonArray.length(); i++) {
×
214
                JSONObject option = jsonArray.getJSONObject(i);
×
215
                if (option.has(JsonFormConstants.KEY) && option.getString(JsonFormConstants.KEY).equals(childKey)) {
×
216
                    addSecondaryValue(option, calendarDate);
×
217
                }
218
            }
219
        }
220
    }
×
221

222
    private static void assignHiddenDateValue(JSONObject widget, Calendar calendarDate) {
223
        try {
224
            widget.put(JsonFormConstants.VALUE, DATE_FORMAT.format(calendarDate.getTime()));
×
225
        } catch (Exception e) {
×
226
            Timber.e(e);
×
227
        }
×
228
    }
×
229

230
    private static Calendar getDate(RadioButton radioButton) {
231
        String[] arrayString = radioButton.getText().toString().split(":");
1✔
232
        String dateString = "";
1✔
233
        if (arrayString.length > 1) {
1✔
234
            dateString = arrayString[1];
1✔
235
        }
236
        return FormUtils.getDate(dateString);
1✔
237
    }
238

239
    /**
240
     * Add the secondary value object
241
     *
242
     * @param item
243
     * @param calendarDate
244
     * @throws JSONException
245
     */
246
    private static void addSecondaryValue(JSONObject item, Calendar calendarDate) throws JSONException {
247
        JSONObject valueObject = new JSONObject();
×
248
        JSONArray jsonArray = new JSONArray();
×
249
        valueObject.put(JsonFormConstants.KEY, item.getString(JsonFormConstants.KEY));
×
250
        valueObject.put(JsonFormConstants.TYPE, JsonFormConstants.DATE_PICKER);
×
251
        valueObject.put(JsonFormConstants.VALUES, jsonArray.put(DATE_FORMAT.format(calendarDate.getTime())));
×
252

253
        try {
254
            item.put(JsonFormConstants.SECONDARY_VALUE, new JSONArray().put(valueObject));
×
255
        } catch (Exception e) {
×
256
            Timber.e(e, "--> addSecondaryValue");
×
257
        }
×
258
    }
×
259

260
    public static boolean isValid(final RadioGroup radioGroup) {
261
        String error = (String) radioGroup.getTag(R.id.error);
×
262
        return (error == null || !radioGroup.isEnabled()
×
263
                || radioGroup.isEnabled() && performValidation(radioGroup));
×
264
    }
265

266
    public static ValidationStatus validate(final JsonFormFragmentView formFragmentView, RadioGroup radioGroup) {
267
        final String error = (String) radioGroup.getTag(R.id.error);
×
268
        if (radioGroup.isEnabled() && error != null) {
×
269
            final LinearLayout linearLayout = (LinearLayout) radioGroup.getParent();
×
270
            if (linearLayout != null && linearLayout.isShown()) {
×
271
                boolean isValid = performValidation(radioGroup);
×
272
                final TextView errorTextView = linearLayout.findViewById(R.id.error_textView);
×
273
                if (!isValid) {
×
274
                    updateRadioButtonGroupWithError(formFragmentView, error, linearLayout);
×
275
                    return new ValidationStatus(false, error, formFragmentView, radioGroup);
×
276
                } else if (errorTextView != null) {
×
277
                    ((JsonFormActivity) formFragmentView.getContext()).runOnUiThread(new Runnable() {
×
278
                        @Override
279
                        public void run() {
280
                            errorTextView.setVisibility(View.GONE);
×
281
                        }
×
282
                    });
283
                }
284
            }
285
        }
286
        return new ValidationStatus(true, null, formFragmentView, radioGroup);
×
287
    }
288

289
    private static void updateRadioButtonGroupWithError(final JsonFormFragmentView formFragmentView, final String error, final LinearLayout linearLayout) {
290
        ((JsonFormActivity) formFragmentView.getContext()).runOnUiThread(new Runnable() {
×
291
            @Override
292
            public void run() {
293
                if (linearLayout.getChildAt(0) instanceof ConstraintLayout) {
×
294
                    ConstraintLayout constraintLayout = (ConstraintLayout) linearLayout.getChildAt(0);
×
295
                    TextView errorTextView = linearLayout.findViewById(R.id.error_textView);
×
296
                    if (errorTextView == null) {
×
297
                        errorTextView = new TextView(formFragmentView.getContext());
×
298
                        errorTextView.setId(R.id.error_textView);
×
299
                        errorTextView.setTextColor(formFragmentView.getContext().getResources().getColor(R.color.toaster_note_red_icon));
×
300
                        errorTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
×
301
                        ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(constraintLayout.getLayoutParams());
×
302
                        layoutParams.topToBottom = R.id.label_text;
×
303
                        layoutParams.leftMargin = FormUtils.dpToPixels(formFragmentView.getContext(), 8);
×
304
                        constraintLayout.addView(errorTextView, new ConstraintLayout.LayoutParams(layoutParams));
×
305
                    }
306
                    errorTextView.setVisibility(View.VISIBLE);
×
307
                    errorTextView.setText(error);
×
308

309
                }
310
            }
×
311
        });
312

313
    }
×
314

315
    private static boolean performValidation(RadioGroup radioGroup) {
316
        boolean isChecked = false;
×
317
        for (int i = 0; i < radioGroup.getChildCount(); i++) {
×
318
            isChecked = getCheckedRadio(radioGroup.getChildAt(i));
×
319
            if (isChecked) {
×
320
                break;
×
321
            }
322
        }
323
        return isChecked;
×
324
    }
325

326
    /**
327
     * @param item radiogroup nested layout
328
     * @return true if any of the radio buttons is selected.
329
     */
330
    private static boolean getCheckedRadio(View item) {
331
        if (item instanceof ViewGroup) {
×
332
            ViewGroup outerRelativeLayout = (ViewGroup) item;
×
333
            //Get radio button on the fourth hierarchy of the nested radio group layout
334
            ViewGroup mainRadioLayout = (ViewGroup) outerRelativeLayout.getChildAt(0);
×
335
            ViewGroup radioContentLinearLayout = (ViewGroup) mainRadioLayout.getChildAt(0);
×
336
            RadioButton radioButton = (RadioButton) radioContentLinearLayout.getChildAt(0);
×
337

338
            return radioButton.isChecked();
×
339
        }
340
        return false;
×
341
    }
342

343
    @Override
344
    public List<View> getViewsFromJson(String stepName, Context context, JsonFormFragment formFragment,
345
                                       JSONObject jsonObject, CommonListener listener, boolean popup) throws Exception {
346
        return attachJson(stepName, context, formFragment, jsonObject, listener, popup);
×
347
    }
348

349
    @Override
350
    public List<View> getViewsFromJson(String stepName, Context context, JsonFormFragment formFragment,
351
                                       JSONObject jsonObject, CommonListener listener) throws Exception {
352
        return attachJson(stepName, context, formFragment, jsonObject, listener, false);
1✔
353
    }
354

355
    protected List<View> attachJson(String stepName, Context context, JsonFormFragment formFragment, JSONObject jsonObject,
356
                                    CommonListener listener, boolean popup) throws JSONException {
357

358
        JSONArray canvasIds = new JSONArray();
1✔
359
        this.stepName = stepName;
1✔
360
        this.formFragment = formFragment;
1✔
361
        this.context = context;
1✔
362
        this.canvasIds = canvasIds;
1✔
363

364
        boolean readOnly = false;
1✔
365
        boolean editable = false;
1✔
366
        if (jsonObject.has(JsonFormConstants.READ_ONLY)) {
1✔
367
            readOnly = jsonObject.getBoolean(JsonFormConstants.READ_ONLY);
1✔
368
        }
369
        if (jsonObject.has(JsonFormConstants.EDITABLE)) {
1✔
370
            editable = jsonObject.getBoolean(JsonFormConstants.EDITABLE);
1✔
371
        }
372
        List<View> views = new ArrayList<>(1);
1✔
373
        ImageView editButton;
374

375
        LinearLayout rootLayout = getLinearRootLayout(context);
1✔
376

377
        Map<String, View> labelViews = new HashMap<>();
1✔
378
        String label = jsonObject.optString(JsonFormConstants.LABEL, "");
1✔
379
        if (StringUtils.isNotBlank(label)) {
1✔
380
            labelViews = formUtils.createRadioButtonAndCheckBoxLabel(stepName, rootLayout, jsonObject, context, canvasIds, readOnly, listener, popup);
1✔
381
        }
382

383
        View radioGroup = addRadioButtonOptionsElements(jsonObject, context, stepName, rootLayout, listener, popup);
1✔
384
        radioGroup.setTag(R.id.json_object, jsonObject);
1✔
385

386
        if (labelViews != null && labelViews.size() > 0) {
1✔
387
            editButton = (ImageView) labelViews.get(JsonFormConstants.EDIT_BUTTON);
1✔
388
            if (editButton != null) {
1✔
389
                FormUtils.setEditButtonAttributes(jsonObject, radioGroup, editButton, listener);
1✔
390
                if (editable) {
1✔
391
                    editButton.setVisibility(View.VISIBLE);
1✔
392
                }
393
            }
394
        }
395

396
        populateTags(rootLayout, stepName, popup, "", "", "", jsonObject);
1✔
397

398
        String relevance = jsonObject.optString(JsonFormConstants.RELEVANCE);
1✔
399
        attachRelevance(rootLayout, context, relevance);
1✔
400

401
        rootLayout.setTag(R.id.extraPopup, popup);
1✔
402
        views.add(rootLayout);
1✔
403
        return views;
1✔
404
    }
405

406
    private void attachRelevance(@NonNull View view, @NonNull Context context, @Nullable String relevance) {
407
        if (!TextUtils.isEmpty(relevance) && context instanceof JsonApi) {
1✔
408
            view.setTag(R.id.relevance, relevance);
1✔
409
            ((JsonApi) context).addSkipLogicView(view);
1✔
410
        }
411
    }
1✔
412

413
    private void populateTags(@NonNull View view, @NonNull String stepName,
414
                              boolean popUp,
415
                              String openmrsEntity, String openmrsEntityParent,
416
                              String openmrsEntityId, JSONObject jsonObject) {
417
        JSONArray canvasIds = new JSONArray();
1✔
418
        view.setId(ViewUtil.generateViewId());
1✔
419
        canvasIds.put(view.getId());
1✔
420
        view.setTag(R.id.canvas_ids, canvasIds.toString());
1✔
421
        view.setTag(R.id.key, jsonObject.optString(JsonFormConstants.KEY));
1✔
422
        view.setTag(R.id.openmrs_entity_parent, openmrsEntityParent);
1✔
423
        view.setTag(R.id.openmrs_entity, openmrsEntity);
1✔
424
        view.setTag(R.id.openmrs_entity_id, openmrsEntityId);
1✔
425
        view.setTag(R.id.type, jsonObject.optString(JsonFormConstants.TYPE));
1✔
426
        view.setTag(R.id.extraPopup, popUp);
1✔
427
        view.setTag(R.id.address, stepName + ":" + jsonObject.optString(JsonFormConstants.KEY));
1✔
428
    }
1✔
429

430
    public LinearLayout getLinearRootLayout(Context context) {
431
        return (LinearLayout) LayoutInflater.from(context).inflate(R.layout.native_form_compound_button_parent, null);
1✔
432
    }
433

434
    /**
435
     * Creates the Radio Button options from the JSON definitions
436
     *
437
     * @param jsonObject   {@link JSONObject}
438
     * @param context      {@link Context}
439
     * @param stepName     {@link String}
440
     * @param linearLayout {@link LinearLayout}
441
     * @param listener     {@link CommonListener}
442
     * @throws JSONException {@link JSONException}
443
     * @author dubdabasoduba
444
     */
445
    protected View addRadioButtonOptionsElements(JSONObject jsonObject, Context context, String stepName,
446
                                                 LinearLayout linearLayout,
447
                                                 CommonListener listener, boolean popup)
448
            throws JSONException {
449
        String openMrsEntityParent = jsonObject.getString(JsonFormConstants.OPENMRS_ENTITY_PARENT);
1✔
450
        String openMrsEntity = jsonObject.getString(JsonFormConstants.OPENMRS_ENTITY);
1✔
451
        String openMrsEntityId = jsonObject.getString(JsonFormConstants.OPENMRS_ENTITY_ID);
1✔
452
        String relevance = jsonObject.optString(JsonFormConstants.RELEVANCE);
1✔
453
        String constraints = jsonObject.optString(JsonFormConstants.CONSTRAINTS);
1✔
454
        String calculation = jsonObject.optString(JsonFormConstants.CALCULATION);
1✔
455
        JSONArray options = jsonObject.getJSONArray(JsonFormConstants.OPTIONS_FIELD_NAME);
1✔
456
        Boolean extraRelCheck = jsonObject.optBoolean(JsonFormConstants.EXTRA_REL, false);
1✔
457
        String extraRelArray = null;
1✔
458
        if (extraRelCheck) {
1✔
459
            extraRelArray = jsonObject.optString(JsonFormConstants.HAS_EXTRA_REL, null);
1✔
460
        }
461

462
        RadioGroup radioGroup = getRadioGroup(jsonObject, context, stepName, popup, openMrsEntityParent, openMrsEntity, openMrsEntityId, extraRelCheck, extraRelArray);
1✔
463
        canvasIds.put(radioGroup.getId());
1✔
464
        addRequiredValidator(radioGroup, jsonObject);
1✔
465
        for (int i = 0; i < options.length(); i++) {
1✔
466
            JSONObject item = options.getJSONObject(i);
1✔
467

468
            RelativeLayout radioGroupLayout = getRadioGroupLayout(jsonObject, context, stepName, popup, openMrsEntityParent, openMrsEntity, openMrsEntityId, item);
1✔
469

470
            //Showing optional info alert dialog on individual radio buttons
471
            ImageView imageView = radioGroupLayout.findViewById(R.id.info_icon);
1✔
472
            formUtils.showInfoIcon(stepName, jsonObject, listener, FormUtils.getInfoDialogAttributes(item), imageView, canvasIds);
1✔
473

474
            createRadioButton(radioGroupLayout, jsonObject, item, listener, popup);
1✔
475

476
            radioGroup.addView(radioGroupLayout);
1✔
477
            ((JsonApi) context).addFormDataView(radioGroup);
1✔
478
        }
479

480
        prepareViewChecks(context, relevance, constraints, calculation, radioGroup);
1✔
481

482
        FormUtils.setRadioExclusiveClick(radioGroup);
1✔
483
        radioGroup.setLayoutParams(FormUtils.getLinearLayoutParams(FormUtils.MATCH_PARENT, FormUtils.WRAP_CONTENT, 0, 0, 0,
1✔
484
                (int) context.getResources().getDimension(R.dimen.extra_bottom_margin)));
1✔
485
        radioGroup.setTag(R.id.canvas_ids, canvasIds.toString());
1✔
486

487
        linearLayout.addView(radioGroup);
1✔
488
        return radioGroup;
1✔
489
    }
490

491
    @NotNull
492
    public RadioGroup getRadioGroup(JSONObject jsonObject, Context context, String stepName, boolean popup, String openMrsEntityParent, String openMrsEntity, String openMrsEntityId, Boolean extraRelCheck, String extraRelArray) throws JSONException {
493
        RadioGroup radioGroup = new RadioGroup(context);
1✔
494
        radioGroup.setTag(R.id.key, jsonObject.getString(JsonFormConstants.KEY));
1✔
495
        radioGroup.setTag(R.id.openmrs_entity_parent, openMrsEntityParent);
1✔
496
        radioGroup.setTag(R.id.openmrs_entity, openMrsEntity);
1✔
497
        radioGroup.setTag(R.id.openmrs_entity_id, openMrsEntityId);
1✔
498
        radioGroup.setTag(R.id.type, jsonObject.getString(JsonFormConstants.TYPE));
1✔
499
        radioGroup.setTag(R.id.address, stepName + ":" + jsonObject.getString(JsonFormConstants.KEY));
1✔
500
        radioGroup.setTag(R.id.extraRelCheck, extraRelCheck);
1✔
501
        radioGroup.setTag(R.id.extraRelArray, extraRelArray);
1✔
502
        radioGroup.setTag(R.id.extraPopup, popup);
1✔
503
        radioGroup.setId(ViewUtil.generateViewId());
1✔
504
        return radioGroup;
1✔
505
    }
506

507
    @NotNull
508
    public RelativeLayout getRadioGroupLayout(JSONObject jsonObject, Context context, String stepName, boolean popup, String openMrsEntityParent, String openMrsEntity, String openMrsEntityId, JSONObject item) throws JSONException {
509
        RelativeLayout radioGroupLayout = getRadioGroupLayout(context);
1✔
510
        radioGroupLayout.setId(ViewUtil.generateViewId());
1✔
511
        radioGroupLayout.setTag(R.id.key, jsonObject.getString(JsonFormConstants.KEY));
1✔
512
        radioGroupLayout.setTag(R.id.type, jsonObject.getString(JsonFormConstants.TYPE));
1✔
513
        radioGroupLayout.setTag(R.id.openmrs_entity_parent, openMrsEntityParent);
1✔
514
        radioGroupLayout.setTag(R.id.openmrs_entity, openMrsEntity);
1✔
515
        radioGroupLayout.setTag(R.id.openmrs_entity_id, openMrsEntityId);
1✔
516
        radioGroupLayout.setTag(R.id.childKey, item.getString(JsonFormConstants.KEY));
1✔
517
        radioGroupLayout.setTag(R.id.address, stepName + ":" + jsonObject.getString(JsonFormConstants.KEY));
1✔
518
        radioGroupLayout.setTag(R.id.extraPopup, popup);
1✔
519
        radioGroupLayout.setTag(R.id.native_radio_button_layout_view_id, radioGroupLayout.getId());
1✔
520
        return radioGroupLayout;
1✔
521
    }
522

523
    public RelativeLayout getRadioGroupLayout(Context context) {
524
        return (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.native_item_radio_button, null);
1✔
525
    }
526

527
    private void prepareViewChecks(Context context, String relevance, String constraints, String calculation, RadioGroup radioGroup) {
528

529
        attachRelevance(radioGroup, context, relevance);
1✔
530

531
        if (!TextUtils.isEmpty(constraints) && context instanceof JsonApi) {
1✔
532
            radioGroup.setTag(R.id.constraints, constraints);
1✔
533
            ((JsonApi) context).addConstrainedView(radioGroup);
1✔
534
        }
535

536
        if (!TextUtils.isEmpty(calculation) && context instanceof JsonApi) {
1✔
537
            radioGroup.setTag(R.id.calculation, calculation);
1✔
538
            ((JsonApi) context).addCalculationLogicView(radioGroup);
1✔
539
        }
540
    }
1✔
541

542
    private void addRequiredValidator(RadioGroup radioGroup, JSONObject jsonObject) throws JSONException {
543
        JSONObject requiredObject = jsonObject.optJSONObject(JsonFormConstants.V_REQUIRED);
1✔
544
        if (requiredObject != null) {
1✔
545
            boolean requiredValue = requiredObject.getBoolean(JsonFormConstants.VALUE);
1✔
546
            if (Boolean.TRUE.equals(requiredValue)) {
1✔
547
                radioGroup.setTag(R.id.error, requiredObject.optString(JsonFormConstants.ERR, null));
1✔
548
            }
549
        }
550
    }
1✔
551

552
    private void createRadioButton(RelativeLayout rootLayout, JSONObject jsonObject, JSONObject item,
553
                                   final CommonListener listener, boolean popup) throws JSONException {
554
        boolean readOnly = false;
1✔
555
        if (jsonObject.has(JsonFormConstants.READ_ONLY)) {
1✔
556
            readOnly = jsonObject.getBoolean(JsonFormConstants.READ_ONLY);
1✔
557
        }
558

559
        String specifyInfo = item.optString(JsonFormConstants.CONTENT_INFO, null);
1✔
560
        String extraInfo = item.optString(JsonFormConstants.NATIVE_RADIO_EXTRA_INFO, null);
1✔
561
        String text_color = item.optString(JsonFormConstants.CONTENT_INFO_COLOR, JsonFormConstants.DEFAULT_HINT_TEXT_COLOR);
1✔
562

563
        if (extraInfo != null) {
1✔
564
            createExtraInfoDisplayTextView(rootLayout, jsonObject, readOnly, item, this.stepName, this.context, text_color);
1✔
565
        }
566

567

568
        final RadioButton radioButton = rootLayout.findViewById(R.id.mainRadioButton);
1✔
569
        if (radioButton != null) {
1✔
570
            setRadioButtonTags(rootLayout, jsonObject, item, extraInfo, radioButton);
1✔
571

572
            String valueString  = jsonObject.optString(JsonFormConstants.VALUE);
1✔
573
            if(valueString != null && valueString.startsWith("{"))
1✔
574
            {
575
                JSONObject translationObject  =  new JSONObject(valueString);
×
576
                valueString  = translationObject.optString(JsonFormConstants.VALUE);
×
577
            }
578

579
            if (!TextUtils.isEmpty(valueString) &&
1✔
580
                    valueString.equals(item.getString(JsonFormConstants.KEY))) {
1✔
581
                ((Activity) context).runOnUiThread(() -> radioButton.setChecked(true));
1✔
582
            }
583
            String optionTextColor = JsonFormConstants.DEFAULT_TEXT_COLOR;
1✔
584
            if (item.has(JsonFormConstants.TEXT_COLOR)) {
1✔
585
                optionTextColor = item.getString(JsonFormConstants.TEXT_COLOR);
×
586
            }
587
            String optionTextSize = String.valueOf(this.context.getResources().getDimension(R.dimen.options_default_text_size));
1✔
588
            if (item.has(JsonFormConstants.TEXT_SIZE)) {
1✔
589
                optionTextSize = item.getString(JsonFormConstants.TEXT_SIZE);
×
590
            }
591

592
            String optionText = item.getString(JsonFormConstants.TEXT);
1✔
593

594
            if (item.has(JsonFormConstants.SECONDARY_VALUE)) {
1✔
595
                optionText = getOptionTextWithSecondaryValue(item, jsonObject);
1✔
596
            }
597

598
            setRadioButton(radioButton);
1✔
599
            if (specifyInfo != null) {
1✔
600
                createSpecifyReasonsDisplayTextView(rootLayout, jsonObject, item, this.stepName, text_color);
1✔
601
                createSpecifyTextView(rootLayout, listener, jsonObject, this.context, readOnly, item, popup, this.formFragment,
1✔
602
                        this.stepName
603
                );
604
            }
605

606
            addPopupRelevantTags(radioButton, jsonObject, popup, item, this.context, this.formFragment, this.stepName, listener);
1✔
607
            radioButton.setTextColor(Color.parseColor(optionTextColor));
1✔
608
            radioButton.setTextSize(FormUtils.getValueFromSpOrDpOrPx(optionTextSize, this.context));
1✔
609
            radioButton.setText(optionText);
1✔
610
            radioButton.setEnabled(!readOnly);
1✔
611

612
            // Make sure to register listener after setting the value to avoid unnecessary onCheckedChange call
613
            checkSelectedRadioButton(listener, radioButton, Utils.returnValue(jsonObject), item);
1✔
614
        }
615
    }
1✔
616

617
    private void checkSelectedRadioButton(final CommonListener listener, final RadioButton radioButton, String value, JSONObject item) throws JSONException {
618
        if (StringUtils.isNotBlank(value)) {
1✔
619
            JSONObject jsonObject = null;
1✔
620
            if (StringUtils.isNotBlank(value) && value.startsWith("{")) {
1✔
621
                jsonObject = new JSONObject(value);
1✔
622
            }
623
            if (value.equals(item.getString(JsonFormConstants.KEY)) || (jsonObject != null && jsonObject.has(JsonFormConstants.VALUE) && jsonObject.optString(JsonFormConstants.VALUE).equals(item.getString(JsonFormConstants.KEY)))) {
1✔
624
                ((Activity) context).runOnUiThread(() -> {
1✔
625
                    radioButton.setChecked(true);
1✔
626
                });
1✔
627
            }
628
            radioButton.setOnCheckedChangeListener(listener);
1✔
629
        } else {
1✔
630
            radioButton.setOnCheckedChangeListener(listener);
1✔
631
        }
632

633
    }
1✔
634

635

636
    private void setRadioButtonTags(RelativeLayout rootLayout, JSONObject jsonObject, JSONObject item, String extraInfo,
637
                                    RadioButton radioButton) throws JSONException {
638
        String openMrsEntityParent = jsonObject.getString(JsonFormConstants.OPENMRS_ENTITY_PARENT);
1✔
639
        String openMrsEntity = jsonObject.getString(JsonFormConstants.OPENMRS_ENTITY);
1✔
640
        String openMrsEntityId = jsonObject.getString(JsonFormConstants.OPENMRS_ENTITY_ID);
1✔
641
        String relevance = jsonObject.optString(JsonFormConstants.RELEVANCE);
1✔
642

643
        int generatedViewId = ViewUtil.generateViewId();
1✔
644
        if (radioButton != null) {
1✔
645
            radioButton.setId(generatedViewId);
1✔
646
            radioButton.setTag(R.id.key, jsonObject.getString(JsonFormConstants.KEY));
1✔
647
            radioButton.setTag(R.id.openmrs_entity_parent, openMrsEntityParent);
1✔
648
            radioButton.setTag(R.id.openmrs_entity, openMrsEntity);
1✔
649
            radioButton.setTag(R.id.openmrs_entity_id, openMrsEntityId);
1✔
650
            radioButton.setTag(R.id.type, jsonObject.getString(JsonFormConstants.TYPE));
1✔
651
            radioButton.setTag(R.id.childKey, item.getString(JsonFormConstants.KEY));
1✔
652
            radioButton.setTag(R.id.address, this.stepName + ":" + jsonObject.getString(JsonFormConstants.KEY));
1✔
653
            radioButton.setTag(R.id.relevance, relevance);
1✔
654
            rootLayout.setTag(R.id.native_radio_button_view_id, generatedViewId);
1✔
655
            if (extraInfo != null) {
1✔
656
                radioButton.setTag(R.id.native_radio_button_extra_info, true);
1✔
657
            } else {
658
                radioButton.setTag(R.id.native_radio_button_extra_info, false);
1✔
659

660
            }
661
            radioButton.setTag(jsonObject.getString(JsonFormConstants.TYPE));
1✔
662
        }
663
    }
1✔
664

665
    /**
666
     * Creates the specify the text view and adds in the radio on checked change listener
667
     *
668
     * @param rootLayout   {@link RelativeLayout}
669
     * @param listener     {@link CommonListener}
670
     * @param jsonObject   {@link JSONObject}
671
     * @param context      {@link Context}
672
     * @param readOnly     {@link Boolean}
673
     * @param item         {@link JSONObject}
674
     * @param popup        {@link Boolean}
675
     * @param formFragment {@link JsonFormFragment}
676
     * @param stepName     {@link String}
677
     * @throws JSONException {@link JSONException}
678
     * @author dubdabasoduba
679
     */
680
    private void createSpecifyTextView(RelativeLayout rootLayout, final CommonListener listener, JSONObject jsonObject,
681
                                       Context context, Boolean readOnly, JSONObject item, Boolean popup,
682
                                       JsonFormFragment formFragment, String stepName)
683
            throws JSONException {
684
        String optionKey = item.optString(JsonFormConstants.KEY, "");
1✔
685
        String widgetValue = Utils.returnValue(jsonObject);
1✔
686

687
        String specifyText;
688
        if (item.has(JsonFormConstants.SECONDARY_VALUE) && widgetValue.equals(optionKey))
1✔
689
            specifyText = context.getResources().getString(R.string.radio_button_tap_to_change);
×
690
        else specifyText = item.getString(JsonFormConstants.CONTENT_INFO);
1✔
691
        String relevance = jsonObject.optString(JsonFormConstants.RELEVANCE);
1✔
692

693
        CustomTextView specifyTextView = rootLayout.findViewById(R.id.specifyTextView);
1✔
694
        addTextViewAttributes(jsonObject, item, specifyTextView, stepName, "");
1✔
695
        specifyTextView.setText(createSpecifyText(specifyText));
1✔
696
        specifyTextView.setTextSize(context.getResources().getDimension(R.dimen.specify_date_default_text_size));
1✔
697
        specifyTextView.setId(ViewUtil.generateViewId());
1✔
698
        specifyTextView.setEnabled(!readOnly);
1✔
699
        specifyTextView.setTag(R.id.relevance, relevance);
1✔
700
        specifyTextView.setVisibility(View.VISIBLE);
1✔
701
        addPopupRelevantTags(specifyTextView, jsonObject, popup, item, context, formFragment, stepName, listener);
1✔
702
        specifyTextView.setOnClickListener(customTextViewClickListener);
1✔
703
        setSpecifyTextView(specifyTextView);
1✔
704
    }
1✔
705

706
    /**
707
     * Returns the radio button option text after concatenating with the secondary value in the case of a date picker popup.
708
     *
709
     * @param item {@link JSONObject}
710
     * @return optionText {@link String}
711
     * @throws JSONException {@link JSONException}
712
     * @author dubdabasoduba
713
     */
714
    private String getOptionTextWithSecondaryValue(JSONObject item, JSONObject jsonObject) throws JSONException {
715
        String optionText = item.getString(JsonFormConstants.TEXT);
1✔
716
        String optionKey = item.getString(JsonFormConstants.KEY);
1✔
717
        String widgetValue = Utils.returnValue(jsonObject);
1✔
718

719
        if (optionKey.equals(widgetValue) && item.has(JsonFormConstants.SECONDARY_VALUE)) {
1✔
720
            JSONArray secondaryValueArray = item.getJSONArray(JsonFormConstants.SECONDARY_VALUE);
1✔
721
            if (secondaryValueArray != null && secondaryValueArray.length() > 0) {
1✔
722
                JSONObject secondaryValue = secondaryValueArray.getJSONObject(0);
1✔
723
                String secondValueKey = secondaryValue.getString(JsonFormConstants.KEY);
1✔
724
                String secondValueType = secondaryValue.getString(JsonFormConstants.TYPE);
1✔
725
                if (item.getString(JsonFormConstants.KEY).equals(secondValueKey) &&
1✔
726
                        secondValueType.equals(JsonFormConstants.DATE_PICKER)) {
1✔
727
                    String secondaryValueDate = getSecondaryDateValue(secondaryValue.getJSONArray(JsonFormConstants.VALUES));
1✔
728
                    optionText = item.getString(JsonFormConstants.TEXT) + ":" + secondaryValueDate;
1✔
729
                }
730
            }
731
        }
732

733
        return optionText;
1✔
734
    }
735

736
    private void addPopupRelevantTags(View view, JSONObject jsonObject, boolean popup, JSONObject item, Context context,
737
                                      JsonFormFragment formFragment, String stepName, CommonListener listener)
738
            throws JSONException {
739
        String specifyWidget = item.optString(JsonFormConstants.CONTENT_WIDGET, "");
1✔
740
        String specifyContent = item.optString(JsonFormConstants.CONTENT_FORM, null);
1✔
741
        String specifyContentForm = item.optString(JsonFormConstants.CONTENT_FORM_LOCATION, null);
1✔
742

743
        if (view != null) {
1✔
744
            view.setTag(R.id.extraPopup, popup);
1✔
745
            view.setTag(R.id.json_object, jsonObject);
1✔
746
            view.setTag(R.id.option_json_object, item);
1✔
747
            view.setTag(R.id.specify_textview, getSpecifyTextView());
1✔
748
            view.setTag(R.id.native_radio_button, getRadioButton());
1✔
749
            view.setTag(R.id.specify_reasons_textview, getReasonsTextView());
1✔
750
            view.setTag(R.id.specify_extra_info_textview, getExtraInfoTextView());
1✔
751
            view.setTag(R.id.specify_type, JsonFormConstants.CONTENT_INFO);
1✔
752
            view.setTag(R.id.specify_context, context);
1✔
753
            view.setTag(R.id.specify_widget, specifyWidget);
1✔
754
            view.setTag(R.id.specify_content, specifyContent);
1✔
755
            view.setTag(R.id.specify_content_form, specifyContentForm);
1✔
756
            view.setTag(R.id.specify_listener, listener);
1✔
757
            view.setTag(R.id.specify_step_name, stepName);
1✔
758
            view.setTag(R.id.specify_fragment, formFragment);
1✔
759
            view.setTag(R.id.secondaryValues, formUtils.getSecondaryValues(item, jsonObject.getString(JsonFormConstants.TYPE)));
1✔
760
        }
761
    }
1✔
762

763
    private void createExtraInfoDisplayTextView(RelativeLayout rootLayout, JSONObject jsonObject, Boolean readOnly,
764
                                                JSONObject item, String stepName, Context context, String text_color)
765
            throws JSONException {
766
        String relevance = jsonObject.optString(JsonFormConstants.RELEVANCE);
1✔
767
        String text = item.getString(JsonFormConstants.NATIVE_RADIO_EXTRA_INFO);
1✔
768

769
        CustomTextView extraInfoTextView = rootLayout.findViewById(R.id.extraInfoTextView);
1✔
770
        extraInfoTextView.setTextSize(context.getResources().getDimension(R.dimen.extra_info_default_text_size));
1✔
771
        extraInfoTextView.setVisibility(View.VISIBLE);
1✔
772
        addTextViewAttributes(jsonObject, item, extraInfoTextView, stepName, text_color);
1✔
773
        extraInfoTextView.setText(text);
1✔
774
        extraInfoTextView.setEnabled(!readOnly);
1✔
775
        setExtraInfoTextView(extraInfoTextView);
1✔
776
        extraInfoTextView.setTag(R.id.relevance, relevance);
1✔
777
    }
1✔
778

779
    /**
780
     * Displays the selected items from the popup
781
     *
782
     * @param rootLayout
783
     * @param jsonObject
784
     * @param item
785
     * @param stepName
786
     * @param text_color
787
     * @throws JSONException
788
     * @author kitoto
789
     */
790
    private void createSpecifyReasonsDisplayTextView(RelativeLayout rootLayout, JSONObject jsonObject, JSONObject item,
791
                                                     String stepName, String text_color) throws JSONException {
792
        String relevance = jsonObject.optString(JsonFormConstants.RELEVANCE);
1✔
793
        String popupReasonsText = "";
1✔
794
        CustomTextView reasonsTextView = rootLayout.findViewById(R.id.reasonsTextView);
1✔
795
        String optionKey = item.optString(JsonFormConstants.KEY, "");
1✔
796
        String widgetValue = Utils.returnValue(jsonObject);
1✔
797
        if (widgetValue.equals(optionKey)) {
1✔
798
            if (item.has(JsonFormConstants.SECONDARY_VALUE)) {
×
799
                popupReasonsText = formUtils.getSpecifyText(item.getJSONArray(JsonFormConstants.SECONDARY_VALUE));
×
800
                if (item.has(JsonFormConstants.CONTENT_WIDGET) &&
×
801
                        !item.getString(JsonFormConstants.CONTENT_WIDGET).equals(JsonFormConstants.DATE_PICKER)) {
×
802
                    reasonsTextView.setVisibility(View.VISIBLE);
×
803
                }
804
            }
805

806
            if (item.has(JsonFormConstants.SECONDARY_SUFFIX)) {
×
807
                String suffix = item.getString(JsonFormConstants.SECONDARY_SUFFIX);
×
808
                if (!TextUtils.isEmpty(popupReasonsText)) {
×
809
                    popupReasonsText = popupReasonsText + " " + suffix;
×
810
                }
811
            }
812

813
            addTextViewAttributes(jsonObject, item, reasonsTextView, stepName, text_color);
×
814
            reasonsTextView.setTag(R.id.relevance, relevance);
×
815
            reasonsTextView.setText(JsonFormConstants.SECONDARY_PREFIX + popupReasonsText);
×
816
        }
817
        setReasonsTextView(reasonsTextView);
1✔
818
    }
1✔
819

820
    /**
821
     * Returns the date from the secondary values in-case of a date picker pop up
822
     *
823
     * @param values {@link JSONArray}
824
     * @return date {@link String}
825
     * @throws JSONException {@link JSONException}
826
     * @author dubdabasoduba
827
     */
828
    private String getSecondaryDateValue(JSONArray values) throws JSONException {
829
        String date = "";
1✔
830
        if (values != null && values.length() > 0) {
1✔
831
            date = values.getString(0);
1✔
832
        }
833
        return date;
1✔
834
    }
835

836
    private void addTextViewAttributes(JSONObject jsonObject, JSONObject item, CustomTextView customTextView,
837
                                       String stepName, String text_color) throws JSONException {
838
        String openMrsEntityParent = jsonObject.getString(JsonFormConstants.OPENMRS_ENTITY_PARENT);
1✔
839
        String openMrsEntity = jsonObject.getString(JsonFormConstants.OPENMRS_ENTITY);
1✔
840
        String openMrsEntityId = jsonObject.getString(JsonFormConstants.OPENMRS_ENTITY_ID);
1✔
841

842
        if (!TextUtils.isEmpty(text_color)) {
1✔
843
            customTextView.setTextColor(Color.parseColor(text_color));
1✔
844
        }
845
        customTextView.setTag(R.id.key, jsonObject.getString(JsonFormConstants.KEY));
1✔
846
        customTextView.setTag(R.id.openmrs_entity_parent, openMrsEntityParent);
1✔
847
        customTextView.setTag(R.id.openmrs_entity, openMrsEntity);
1✔
848
        customTextView.setTag(R.id.openmrs_entity_id, openMrsEntityId);
1✔
849
        customTextView.setTag(R.id.type, jsonObject.getString(JsonFormConstants.TYPE));
1✔
850
        customTextView.setTag(R.id.childKey, item.getString(JsonFormConstants.KEY));
1✔
851
        customTextView.setTag(R.id.address, stepName + ":" + jsonObject.getString(JsonFormConstants.KEY));
1✔
852
    }
1✔
853

854
    public CustomTextView getExtraInfoTextView() {
855
        return extraInfoTextView;
1✔
856
    }
857

858
    private void setExtraInfoTextView(CustomTextView customTextView) {
859
        extraInfoTextView = customTextView;
1✔
860
    }
1✔
861

862
    public CustomTextView getSpecifyTextView() {
863
        return specifyTextView;
1✔
864
    }
865

866
    public void setSpecifyTextView(CustomTextView specifyTextView) {
867
        this.specifyTextView = specifyTextView;
1✔
868
    }
1✔
869

870
    public CustomTextView getReasonsTextView() {
871
        return reasonsTextView;
1✔
872
    }
873

874
    public void setReasonsTextView(CustomTextView reasonsTextView) {
875
        this.reasonsTextView = reasonsTextView;
1✔
876
    }
1✔
877

878
    private RadioButton getRadioButton() {
879
        return radioButton;
1✔
880
    }
881

882
    private void setRadioButton(RadioButton radioButton) {
883
        this.radioButton = radioButton;
1✔
884
    }
1✔
885

886
    @Override
887
    @NonNull
888
    public Set<String> getCustomTranslatableWidgetFields() {
889
        Set<String> customTranslatableWidgetFields = new HashSet<>();
1✔
890
        customTranslatableWidgetFields.add(JsonFormConstants.OPTIONS_FIELD_NAME + "." + JsonFormConstants.TEXT);
1✔
891
        customTranslatableWidgetFields.add(JsonFormConstants.OPTIONS_FIELD_NAME + "." + JsonFormConstants.CONTENT_INFO);
1✔
892
        customTranslatableWidgetFields.add(JsonFormConstants.LABEL_INFO_TEXT);
1✔
893
        customTranslatableWidgetFields.add(JsonFormConstants.LABEL_INFO_TITLE);
1✔
894
        return customTranslatableWidgetFields;
1✔
895
    }
896

897
    public void cleanUp() {
898
        this.context = null;
×
899
        this.formFragment = null;
×
900
        this.radioButton = null;
×
901
        this.extraInfoTextView = null;
×
902
        this.specifyTextView = null;
×
903
        this.reasonsTextView = null;
×
904
    }
×
905

906

907
    private class CustomTextViewClickListener implements View.OnClickListener {
1✔
908
        @Override
909
        public void onClick(View view) {
910
            RadioButton radioButton = (RadioButton) view.getTag(R.id.native_radio_button);
×
911
            radioButton.setChecked(false);
×
912
            radioButton.performClick();
×
913
        }
×
914
    }
915
}
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