导航菜单

页面标题

页面副标题

St.John's v1.0.9 - FillDynamicFormActivity.java 源代码

正在查看: St.John's v1.0.9 应用的 FillDynamicFormActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.mcb.stjohnsemschool.activity;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Base64;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.mcb.stjohnsemschool.model.DynamicFormQuestionsModel;
import com.mcb.stjohnsemschool.model.DynamicFormQuestionsModelClass;
import com.mcb.stjohnsemschool.model.PickListModelClass;
import com.mcb.stjohnsemschool.model.RadioButtonModelClass;
import com.mcb.stjohnsemschool.services.ApiClient;
import com.mcb.stjohnsemschool.services.ApiInterface;
import com.mcb.stjohnsemschool.utils.Constants;
import com.mcb.stjohnsemschool.utils.NonScrollListView;
import com.mcb.stjohnsemschool.utils.TransparentProgressDialog;
import com.mcb.stjohnsemschool.utils.Utility;
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class FillDynamicFormActivity extends BaseActivity implements DatePickerDialog.OnDateSetListener {
    private static final String TAG = "com.mcb.stjohnsemschool.activity.FillDynamicFormActivity";
    private Activity activity;
    Dialog alertDialog;
    private Context context;
    private DatePickerDialog dateDialog;
    TextView done;
    private Typeface font;
    int formId;
    LayoutInflater inflater;
    boolean isSel;
    NonScrollListView listview;
    TextView mDisclaimer;
    LinearLayout mMainLL;
    TextView mNoData;
    private TransparentProgressDialog mProgressbar;
    MenuItem menuItem;
    SimpleDateFormat sdf;
    DynamicFormQuestionsModelClass selModel;
    TextView titleTxv;
    String formName = "";
    String disclaimer = "";
    String userId = "0";
    String studentEnrolmentId = "0";
    String orgId = "0";
    String academicYearId = "0";
    ArrayList<DynamicFormQuestionsModelClass> formQuestionList = new ArrayList<>();
    Calendar myCalendar = Calendar.getInstance();
    int RESULT_LOAD_IMAGE = 6;

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_fill_dynamic_form);
        this.activity = this;
        this.context = getApplicationContext();
        this.mProgressbar = new TransparentProgressDialog(this.activity, R.drawable.spinner_loading_imag);
        this.font = Typeface.createFromAsset(this.context.getAssets(), "Roboto-Regular.ttf");
        this.inflater = (LayoutInflater) getSystemService("layout_inflater");
        Bundle extras = getIntent().getExtras();
        this.formName = extras.getString("FormName", this.formName);
        this.disclaimer = extras.getString("Disclaimer", this.disclaimer);
        this.formId = extras.getInt("FormId", this.formId);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle(this.formName);
        this.sdf = new SimpleDateFormat("dd MMM yyyy", Locale.US);
        SharedPreferences sharedPreferences = this.context.getSharedPreferences("", 0);
        this.userId = sharedPreferences.getString("UseridKey", this.userId);
        this.studentEnrolmentId = sharedPreferences.getString("studentEnrollmentIdKey", this.studentEnrolmentId);
        this.orgId = sharedPreferences.getString("orgnizationIdKey", this.orgId);
        this.academicYearId = sharedPreferences.getString("academicyearIdKey", this.academicYearId);
        initializations();
        if (Build.VERSION.SDK_INT >= 23) {
            getMultiplePermissions();
        }
    }

    private void initializations() {
        this.mMainLL = (LinearLayout) findViewById(R.id.ll_main);
        this.mNoData = (TextView) findViewById(R.id.txv_no_data);
        this.mDisclaimer = (TextView) findViewById(R.id.txv_disclaimer);
        this.mNoData.setTypeface(this.font);
        this.mDisclaimer.setTypeface(this.font);
        String str = this.disclaimer;
        if (str != null && str.length() > 0 && !this.disclaimer.equalsIgnoreCase("null")) {
            this.mDisclaimer.setText(this.disclaimer);
            this.mDisclaimer.setVisibility(0);
        } else {
            this.mDisclaimer.setVisibility(8);
        }
        this.mMainLL.setVisibility(8);
        this.mNoData.setVisibility(8);
        Dialog dialog = new Dialog(this);
        this.alertDialog = dialog;
        dialog.requestWindowFeature(1);
        this.alertDialog.setContentView(R.layout.popup_data);
        this.alertDialog.setCancelable(false);
        this.alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(-1));
        this.titleTxv = (TextView) this.alertDialog.findViewById(R.id.item_tittle);
        this.done = (TextView) this.alertDialog.findViewById(R.id.item_done);
        this.listview = this.alertDialog.findViewById(R.id.listview);
        ((ImageView) this.alertDialog.findViewById(R.id.close)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FillDynamicFormActivity.this.alertDialog.dismiss();
            }
        });
        getFormQuestions();
    }

    private void getFormQuestions() {
        ConnectivityManager connectivityManager = (ConnectivityManager) this.context.getSystemService("connectivity");
        if (connectivityManager.getActiveNetworkInfo() != null && connectivityManager.getActiveNetworkInfo().isAvailable() && connectivityManager.getActiveNetworkInfo().isConnected()) {
            getDynamicFormColumnsData();
        } else {
            Toast.makeText(this.context, "Check your Network Connection", 0).show();
        }
    }

    private void getDynamicFormColumnsData() {
        TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
        if (transparentProgressDialog != null && !transparentProgressDialog.isShowing()) {
            this.mProgressbar.show();
        }
        ((ApiInterface) ApiClient.getClient1(this.context).create(ApiInterface.class)).GetDynamicFormColumnsData(Integer.parseInt(this.studentEnrolmentId), this.formId, Utility.getSchoolApiKey(this.context)).enqueue(new Callback<ArrayList<DynamicFormQuestionsModel>>() {
            public void onResponse(Call<ArrayList<DynamicFormQuestionsModel>> call, Response<ArrayList<DynamicFormQuestionsModel>> response) {
                if (FillDynamicFormActivity.this.mProgressbar != null && FillDynamicFormActivity.this.mProgressbar.isShowing()) {
                    FillDynamicFormActivity.this.mProgressbar.dismiss();
                }
                if (response == null || response.body() == null) {
                    Utility.showAlertDialog(FillDynamicFormActivity.this.activity);
                    return;
                }
                FillDynamicFormActivity.this.formQuestionList.clear();
                ArrayList arrayList = (ArrayList) response.body();
                if (arrayList != null && arrayList.size() > 0) {
                    Iterator it = arrayList.iterator();
                    while (it.hasNext()) {
                        DynamicFormQuestionsModel dynamicFormQuestionsModel = (DynamicFormQuestionsModel) it.next();
                        DynamicFormQuestionsModelClass dynamicFormQuestionsModelClass = new DynamicFormQuestionsModelClass();
                        dynamicFormQuestionsModelClass.setDynamicFormColumnId(dynamicFormQuestionsModel.getDynamicFormColumnId());
                        dynamicFormQuestionsModelClass.setDynamicFormId(dynamicFormQuestionsModel.getDynamicFormId());
                        dynamicFormQuestionsModelClass.setColumnName(dynamicFormQuestionsModel.getColumnName());
                        dynamicFormQuestionsModelClass.setDataType(dynamicFormQuestionsModel.getDataType());
                        dynamicFormQuestionsModelClass.setMandatory(dynamicFormQuestionsModel.isMandatory());
                        dynamicFormQuestionsModelClass.setDefaultValue(dynamicFormQuestionsModel.getDefaultValue());
                        dynamicFormQuestionsModelClass.setColumnDetails(dynamicFormQuestionsModel.getColumnDetails());
                        dynamicFormQuestionsModelClass.setPickList(dynamicFormQuestionsModel.getPickList());
                        dynamicFormQuestionsModelClass.setRadioButtonList(dynamicFormQuestionsModel.getRadioButtonList());
                        FillDynamicFormActivity.this.formQuestionList.add(dynamicFormQuestionsModelClass);
                    }
                }
                if (FillDynamicFormActivity.this.formQuestionList.size() > 0) {
                    FillDynamicFormActivity.this.generateUI();
                    FillDynamicFormActivity.this.menuItem.setVisible(true);
                    FillDynamicFormActivity.this.mMainLL.setVisibility(0);
                    FillDynamicFormActivity.this.mNoData.setVisibility(8);
                    return;
                }
                FillDynamicFormActivity.this.menuItem.setVisible(false);
                FillDynamicFormActivity.this.mMainLL.setVisibility(8);
                FillDynamicFormActivity.this.mNoData.setVisibility(0);
            }

            public void onFailure(Call<ArrayList<DynamicFormQuestionsModel>> call, Throwable th) {
                if (FillDynamicFormActivity.this.mProgressbar != null && FillDynamicFormActivity.this.mProgressbar.isShowing()) {
                    FillDynamicFormActivity.this.mProgressbar.dismiss();
                }
                Utility.showAlertDialog(FillDynamicFormActivity.this.activity);
            }
        });
    }

    protected void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i == this.RESULT_LOAD_IMAGE && i2 == -1 && intent != null) {
            String[] strArr = {"_data"};
            Cursor query = getContentResolver().query(intent.getData(), strArr, null, null, null);
            query.moveToFirst();
            String string = query.getString(query.getColumnIndex(strArr[0]));
            query.close();
            String name = new File(string).getName();
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inPreferredConfig = Bitmap.Config.RGB_565;
            options.inSampleSize = 5;
            Bitmap decodeFile = BitmapFactory.decodeFile(string, options);
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            decodeFile.compress(Bitmap.CompressFormat.PNG, 90, byteArrayOutputStream);
            String encodeToString = Base64.encodeToString(byteArrayOutputStream.toByteArray(), 0);
            this.selModel.setFileName(name);
            this.selModel.setImageBase64Str(encodeToString);
            if (this.selModel.getImageView() == null || encodeToString.length() <= 0 || encodeToString.equalsIgnoreCase("null")) {
                return;
            }
            this.isSel = true;
            byte[] decode = Base64.decode(encodeToString, 0);
            this.selModel.getImageView().setImageBitmap(BitmapFactory.decodeByteArray(decode, 0, decode.length));
        }
    }

    RadioButton getElementRadioButton(RadioButtonModelClass radioButtonModelClass) {
        RadioButton radioButton = (RadioButton) this.inflater.inflate(R.layout.radio_button, (ViewGroup) null);
        radioButton.setLayoutParams(new LinearLayout.LayoutParams(-1, -2));
        radioButton.setText(radioButtonModelClass.getRadioButtonName());
        radioButton.setTypeface(this.font);
        radioButton.setTextColor(ContextCompat.getColor(this.context, R.color.dark_gray));
        radioButton.setTextSize(12.0f);
        radioButton.setTag(radioButtonModelClass.getRadioButtonName());
        return radioButton;
    }

    CheckBox getElementCheckBox(PickListModelClass pickListModelClass) {
        final CheckBox checkBox = (CheckBox) this.inflater.inflate(R.layout.my_check_box, (ViewGroup) null);
        checkBox.setLayoutParams(new LinearLayout.LayoutParams(-1, -2));
        checkBox.setText(pickListModelClass.getPickListName());
        checkBox.setTag(pickListModelClass);
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
                ((PickListModelClass) checkBox.getTag()).setIschecked(z);
            }
        });
        return checkBox;
    }

    public void showPickListDialog(DynamicFormQuestionsModelClass dynamicFormQuestionsModelClass, final EditText editText) {
        final ArrayList pickList = dynamicFormQuestionsModelClass.getPickList();
        if (pickList.size() > 0) {
            this.titleTxv.setText("Select");
            this.listview.setAdapter(new ArrayAdapter(getApplicationContext(), R.layout.multi_select_list_item, pickList));
            this.listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
                    if (((PickListModelClass) pickList.get(i)).isIschecked()) {
                        ((PickListModelClass) pickList.get(i)).setIschecked(false);
                    } else {
                        ((PickListModelClass) pickList.get(i)).setIschecked(true);
                    }
                }
            });
            this.done.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    editText.setText(FillDynamicFormActivity.this.getSelectedValues(pickList));
                    if (FillDynamicFormActivity.this.alertDialog == null || !FillDynamicFormActivity.this.alertDialog.isShowing()) {
                        return;
                    }
                    FillDynamicFormActivity.this.alertDialog.dismiss();
                }
            });
            for (int i = 0; i < pickList.size(); i++) {
                if (((PickListModelClass) pickList.get(i)).isIschecked()) {
                    this.listview.setItemChecked(i, true);
                }
            }
            Dialog dialog = this.alertDialog;
            if (dialog == null || dialog.isShowing()) {
                return;
            }
            this.alertDialog.show();
            return;
        }
        Toast.makeText(this.context, "Values not added", 0).show();
    }

    public String getSelectedValues(ArrayList<PickListModelClass> arrayList) {
        Iterator<PickListModelClass> it = arrayList.iterator();
        String str = "";
        while (it.hasNext()) {
            PickListModelClass next = it.next();
            if (next.isIschecked()) {
                str = str + next.getPickListName() + ", ";
            }
        }
        String trim = str.trim();
        return (trim.length() <= 0 || !trim.substring(trim.length() + (-1)).equalsIgnoreCase(",")) ? trim : trim.substring(0, trim.length() - 1);
    }

    public void generateUI() {
        this.mMainLL.removeAllViews();
        Iterator<DynamicFormQuestionsModelClass> it = this.formQuestionList.iterator();
        while (it.hasNext()) {
            DynamicFormQuestionsModelClass next = it.next();
            String columnName = next.getColumnName();
            String dataType = next.getDataType();
            String defaultValue = next.getDefaultValue();
            int i = 0;
            if (dataType.equalsIgnoreCase("Radio Button")) {
                LinearLayout linearLayout = (LinearLayout) this.inflater.inflate(R.layout.ll_rbtn, (ViewGroup) null);
                TextView textView = (TextView) linearLayout.findViewById(R.id.txv_title);
                textView.setTypeface(this.font, 1);
                textView.setText(columnName);
                RadioGroup radioGroup = (RadioGroup) linearLayout.findViewById(R.id.rgp_options);
                ArrayList radioButtonList = next.getRadioButtonList();
                while (i < radioButtonList.size()) {
                    RadioButtonModelClass radioButtonModelClass = (RadioButtonModelClass) radioButtonList.get(i);
                    RadioButton elementRadioButton = getElementRadioButton(radioButtonModelClass);
                    radioGroup.addView(elementRadioButton);
                    if (radioButtonModelClass.isDefaultValue()) {
                        elementRadioButton.setChecked(true);
                    }
                    i++;
                }
                this.mMainLL.addView(linearLayout);
                next.setRgp(radioGroup);
            } else if (dataType.equalsIgnoreCase("Checkbox")) {
                LinearLayout linearLayout2 = (LinearLayout) this.inflater.inflate(R.layout.ll_chk, (ViewGroup) null);
                TextView textView2 = (TextView) linearLayout2.findViewById(R.id.txv_title);
                textView2.setTypeface(this.font, 1);
                textView2.setText(columnName);
                LinearLayout linearLayout3 = (LinearLayout) linearLayout2.findViewById(R.id.main_check_box_tl);
                ArrayList pickList = next.getPickList();
                while (i < pickList.size()) {
                    PickListModelClass pickListModelClass = (PickListModelClass) pickList.get(i);
                    CheckBox elementCheckBox = getElementCheckBox(pickListModelClass);
                    linearLayout3.addView(elementCheckBox);
                    if (pickListModelClass.isIschecked()) {
                        elementCheckBox.setChecked(true);
                    }
                    i++;
                }
                this.mMainLL.addView(linearLayout2);
            } else if (dataType.equalsIgnoreCase("Label") || dataType.equalsIgnoreCase("System Generated Number")) {
                LinearLayout linearLayout4 = (LinearLayout) this.inflater.inflate(R.layout.ll_textview, (ViewGroup) null);
                TextView textView3 = (TextView) linearLayout4.findViewById(R.id.txv_title);
                textView3.setTypeface(this.font, 1);
                textView3.setText(columnName);
                TextView textView4 = (TextView) linearLayout4.findViewById(R.id.txv_value);
                textView4.setTypeface(this.font);
                textView4.setText(defaultValue);
                this.mMainLL.addView(linearLayout4);
            } else if (dataType.equalsIgnoreCase("DateTime")) {
                LinearLayout linearLayout5 = (LinearLayout) this.inflater.inflate(R.layout.ll_date_edittext, (ViewGroup) null);
                final EditText editText = (EditText) linearLayout5.findViewById(R.id.edt_date);
                editText.setTypeface(this.font);
                TextView textView5 = (TextView) linearLayout5.findViewById(R.id.txv_title);
                textView5.setTypeface(this.font, 1);
                textView5.setText(columnName);
                editText.setTag(next);
                editText.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        FillDynamicFormActivity.this.selModel = (DynamicFormQuestionsModelClass) view.getTag();
                        FillDynamicFormActivity.this.showDateDialog(editText.getText().toString().trim());
                    }
                });
                if (defaultValue != null && defaultValue.length() > 0 && !defaultValue.equalsIgnoreCase("null")) {
                    try {
                        try {
                            try {
                                try {
                                    editText.setText(this.sdf.format(new SimpleDateFormat("MMM dd yyyy hh:mma", Locale.US).parse(defaultValue)));
                                } catch (ParseException unused) {
                                    editText.setText(this.sdf.format(new SimpleDateFormat("MMM dd yyyy", Locale.US).parse(defaultValue)));
                                }
                            } catch (ParseException unused2) {
                                editText.setText(this.sdf.format(new SimpleDateFormat("dd MMM yyyy", Locale.US).parse(defaultValue)));
                            }
                        } catch (ParseException unused3) {
                            editText.setText(this.sdf.format(new SimpleDateFormat("MM/dd/yyyy", Locale.US).parse(defaultValue)));
                        }
                    } catch (ParseException unused4) {
                        editText.setText(defaultValue);
                    }
                } else {
                    editText.setText("");
                }
                this.mMainLL.addView(linearLayout5);
                next.setEdt(editText);
            } else if (dataType.equalsIgnoreCase("Pick List")) {
                LinearLayout linearLayout6 = (LinearLayout) this.inflater.inflate(R.layout.ll_spinner, (ViewGroup) null);
                TextView textView6 = (TextView) linearLayout6.findViewById(R.id.txv_title);
                textView6.setTypeface(this.font, 1);
                textView6.setText(columnName);
                Spinner spinner = (Spinner) linearLayout6.findViewById(R.id.spn_val);
                new ArrayList();
                ArrayList pickList2 = next.getPickList();
                spinner.setAdapter((SpinnerAdapter) new ArrayAdapter(this.context, R.layout.custom_textview, pickList2));
                if (defaultValue != null && defaultValue.length() > 0 && !defaultValue.equalsIgnoreCase("null")) {
                    int i2 = 0;
                    while (true) {
                        if (i2 >= pickList2.size()) {
                            break;
                        }
                        if (String.valueOf(((PickListModelClass) pickList2.get(i2)).getPickListName()).equalsIgnoreCase(defaultValue)) {
                            i = i2;
                            break;
                        }
                        i2++;
                    }
                    spinner.setSelection(i);
                } else {
                    spinner.setSelection(0);
                }
                this.mMainLL.addView(linearLayout6);
                next.setSpn(spinner);
            } else if (dataType.equalsIgnoreCase("Image")) {
                LinearLayout linearLayout7 = (LinearLayout) this.inflater.inflate(R.layout.ll_img, (ViewGroup) null);
                RelativeLayout relativeLayout = (RelativeLayout) linearLayout7.findViewById(R.id.rl_img);
                TextView textView7 = (TextView) linearLayout7.findViewById(R.id.txv_title);
                textView7.setTypeface(this.font, 1);
                textView7.setText(columnName);
                final ImageView imageView = (ImageView) linearLayout7.findViewById(R.id.profile_image_view);
                relativeLayout.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        FillDynamicFormActivity.this.selModel = (DynamicFormQuestionsModelClass) view.getTag();
                        Intent intent = new Intent("android.intent.action.PICK", MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                        FillDynamicFormActivity fillDynamicFormActivity = FillDynamicFormActivity.this;
                        fillDynamicFormActivity.startActivityForResult(intent, fillDynamicFormActivity.RESULT_LOAD_IMAGE);
                    }
                });
                if (defaultValue != null && defaultValue.length() > 0 && !defaultValue.equalsIgnoreCase("null")) {
                    if (defaultValue.contains("~")) {
                        String replace = defaultValue.replace("~", "").replace("\\", "//");
                        this.context.getSharedPreferences("", 0);
                        Glide.with(this).load(getResources().getString(R.string.payonline_url) + replace).listener(new RequestListener<Drawable>() {
                            public boolean onResourceReady(Drawable drawable, Object obj, Target<Drawable> target, DataSource dataSource, boolean z) {
                                return false;
                            }

                            public boolean onResourceReady(Object obj, Object obj2, Target target, DataSource dataSource, boolean z) {
                                return onResourceReady((Drawable) obj, obj2, (Target<Drawable>) target, dataSource, z);
                            }

                            public boolean onLoadFailed(GlideException glideException, Object obj, Target<Drawable> target, boolean z) {
                                imageView.setBackgroundColor(ContextCompat.getColor(FillDynamicFormActivity.this.context, R.color.gray));
                                imageView.setImageResource(R.drawable.default_image);
                                return true;
                            }
                        }).into(imageView);
                    } else {
                        String replace2 = defaultValue.replace("\\", "//");
                        if (replace2 != null && !replace2.equalsIgnoreCase("null")) {
                            Glide.with(this).load(replace2).listener(new RequestListener<Drawable>() {
                                public boolean onResourceReady(Drawable drawable, Object obj, Target<Drawable> target, DataSource dataSource, boolean z) {
                                    return false;
                                }

                                public boolean onResourceReady(Object obj, Object obj2, Target target, DataSource dataSource, boolean z) {
                                    return onResourceReady((Drawable) obj, obj2, (Target<Drawable>) target, dataSource, z);
                                }

                                public boolean onLoadFailed(GlideException glideException, Object obj, Target<Drawable> target, boolean z) {
                                    imageView.setBackgroundColor(ContextCompat.getColor(FillDynamicFormActivity.this.context, R.color.gray));
                                    imageView.setImageResource(R.drawable.default_image);
                                    return true;
                                }
                            }).into(imageView);
                        } else {
                            imageView.setImageResource(R.drawable.default_image);
                        }
                    }
                }
                relativeLayout.setTag(next);
                this.mMainLL.addView(linearLayout7);
                next.setImageView(imageView);
            } else {
                LinearLayout linearLayout8 = (LinearLayout) this.inflater.inflate(R.layout.ll_edittext, (ViewGroup) null);
                EditText editText2 = (EditText) linearLayout8.findViewById(R.id.edt_text);
                editText2.setTypeface(this.font);
                TextView textView8 = (TextView) linearLayout8.findViewById(R.id.txv_title);
                textView8.setTypeface(this.font, 1);
                textView8.setText(columnName);
                if (dataType.equalsIgnoreCase("Integer")) {
                    editText2.setInputType(2);
                } else if (dataType.equalsIgnoreCase("Percent") || dataType.equalsIgnoreCase("Decimal") || dataType.equalsIgnoreCase("Currency")) {
                    editText2.setInputType(12290);
                } else if (dataType.equalsIgnoreCase("TextArea")) {
                    editText2.setSingleLine(false);
                    editText2.setImeOptions(1073741824);
                    editText2.setInputType(131073);
                } else if (dataType.equalsIgnoreCase("Email")) {
                    editText2.setInputType(524321);
                } else if (dataType.equalsIgnoreCase("Phone")) {
                    editText2.setInputType(3);
                } else if (dataType.equalsIgnoreCase("Multiselect Pick List")) {
                    editText2.setInputType(0);
                    editText2.setFocusable(false);
                    editText2.setFocusableInTouchMode(false);
                    editText2.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            FillDynamicFormActivity.this.selModel = (DynamicFormQuestionsModelClass) view.getTag();
                            FillDynamicFormActivity fillDynamicFormActivity = FillDynamicFormActivity.this;
                            fillDynamicFormActivity.showPickListDialog(fillDynamicFormActivity.selModel, (EditText) view);
                        }
                    });
                } else {
                    editText2.setInputType(1);
                }
                if (defaultValue != null && defaultValue.length() > 0 && !defaultValue.equalsIgnoreCase("null")) {
                    editText2.setText(defaultValue);
                } else {
                    editText2.setText("");
                }
                editText2.setTag(next);
                this.mMainLL.addView(linearLayout8);
                next.setEdt(editText2);
            }
        }
    }

    public void showDateDialog(String str) {
        if (str != null && str.length() > 0 && !str.equalsIgnoreCase("null")) {
            try {
                this.myCalendar.setTimeInMillis(this.sdf.parse(str).getTime());
            } catch (ParseException unused) {
                this.myCalendar = Calendar.getInstance();
            }
        } else {
            this.myCalendar = Calendar.getInstance();
        }
        this.dateDialog = DatePickerDialog.newInstance(this, this.myCalendar.get(1), this.myCalendar.get(2), this.myCalendar.get(5));
        this.dateDialog.setMaxDate(Calendar.getInstance());
        this.dateDialog.setThemeDark(false);
        this.dateDialog.setAccentColor(ContextCompat.getColor(this.context, R.color.ColorPrimary));
        this.dateDialog.show(getFragmentManager(), "Datepickerdialog");
    }

    public void onDateSet(DatePickerDialog datePickerDialog, int i, int i2, int i3) {
        if (datePickerDialog == this.dateDialog) {
            this.myCalendar.set(1, i);
            this.myCalendar.set(2, i2);
            this.myCalendar.set(5, i3);
            this.selModel.getEdt().setText(this.sdf.format(this.myCalendar.getTime()));
        }
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.save_icon_menu, menu);
        this.menuItem = menu.findItem(R.id.action_save);
        if (this.formQuestionList.size() > 0) {
            this.menuItem.setVisible(true);
        } else {
            this.menuItem.setVisible(false);
        }
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        int itemId = menuItem.getItemId();
        if (itemId == 16908332) {
            finish();
        } else if (itemId == 2131361885) {
            generateRequest();
        }
        return super.onOptionsItemSelected(menuItem);
    }

    private void generateRequest() {
        boolean z;
        String str;
        Iterator<DynamicFormQuestionsModelClass> it = this.formQuestionList.iterator();
        String str2 = "";
        String str3 = "";
        while (it.hasNext()) {
            DynamicFormQuestionsModelClass next = it.next();
            EditText edt = next.getEdt();
            Spinner spn = next.getSpn();
            RadioGroup rgp = next.getRgp();
            String dataType = next.getDataType();
            if (dataType.equalsIgnoreCase("Image")) {
                str = next.getImageBase64Str();
            } else if (dataType.equalsIgnoreCase("Checkbox")) {
                str = getSelectedValues(next.getPickList());
            } else if (edt != null) {
                str = edt.getText().toString().trim();
                if (dataType.equalsIgnoreCase("DateTime")) {
                    try {
                        str = new SimpleDateFormat("MM/dd/yyyy", Locale.US).format(this.sdf.parse(str));
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
            } else if (spn != null) {
                str = ((PickListModelClass) spn.getSelectedItem()).getPickListName();
            } else if (rgp != null) {
                RadioButton radioButton = (RadioButton) rgp.findViewById(rgp.getCheckedRadioButtonId());
                str = radioButton != null ? radioButton.getTag().toString().trim() : null;
            } else {
                str = "";
            }
            if ((str == null || str.length() == 0) && next.isMandatory()) {
                str2 = "Please fill " + next.getColumnName();
            } else if (dataType.equalsIgnoreCase("Email") && str != null && str.length() > 0 && !Constants.isValidEmail(str)) {
                str2 = "Please enter valid email for " + next.getColumnName();
            } else if (dataType.equalsIgnoreCase("Phone") && str != null && str.length() > 0 && !Constants.isValidPhoneNum(str)) {
                str2 = "Please enter valid phone number for " + next.getColumnName();
            } else {
                str3 = str3 + (next.getDynamicFormId() + "-" + next.getDynamicFormColumnId() + "-" + next.getColumnDetails()) + "?" + str + ";";
            }
            z = false;
        }
        z = true;
        if (z) {
            if (str3.length() > 0 && String.valueOf(str3.charAt(str3.length() - 1)).equalsIgnoreCase(";")) {
                str3 = str3.substring(0, str3.length() - 1);
            }
            saveEditedFields(str3);
            return;
        }
        Toast.makeText(this.context, str2, 0).show();
    }

    private void saveEditedFields(String str) {
        ConnectivityManager connectivityManager = (ConnectivityManager) this.context.getSystemService("connectivity");
        if (connectivityManager.getActiveNetworkInfo() != null && connectivityManager.getActiveNetworkInfo().isAvailable() && connectivityManager.getActiveNetworkInfo().isConnected()) {
            saveStudentDynamicFormData(str);
        } else {
            Toast.makeText(this.context, "Check your Network Connection", 0).show();
        }
    }

    private void saveStudentDynamicFormData(String str) {
        TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
        if (transparentProgressDialog != null && !transparentProgressDialog.isShowing()) {
            this.mProgressbar.show();
        }
        HashMap hashMap = new HashMap();
        hashMap.put("StudentEnrollmentID", this.studentEnrolmentId);
        hashMap.put("OrganisationID", this.orgId);
        hashMap.put("AcademicYearID", this.academicYearId);
        hashMap.put("UserID", this.userId);
        hashMap.put("Values", str);
        hashMap.put("apikey", Utility.getSchoolApiKey(this.context));
        ((ApiInterface) ApiClient.getClient1(getApplicationContext()).create(ApiInterface.class)).SaveStudentDynamicFormData(hashMap).enqueue(new Callback<String>() {
            public void onResponse(Call<String> call, Response<String> response) {
                if (FillDynamicFormActivity.this.mProgressbar != null && FillDynamicFormActivity.this.mProgressbar.isShowing()) {
                    FillDynamicFormActivity.this.mProgressbar.dismiss();
                }
                if (response == null || response.body() == null) {
                    Utility.showAlertDialog(FillDynamicFormActivity.this.activity);
                    return;
                }
                String str2 = (String) response.body();
                AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper((Context) FillDynamicFormActivity.this, R.style.MyDialogTheme));
                builder.setMessage(str2).setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        FillDynamicFormActivity.this.finish();
                    }
                }).setCancelable(false);
                builder.create().show();
            }

            public void onFailure(Call<String> call, Throwable th) {
                if (FillDynamicFormActivity.this.mProgressbar != null && FillDynamicFormActivity.this.mProgressbar.isShowing()) {
                    FillDynamicFormActivity.this.mProgressbar.dismiss();
                }
                Utility.showAlertDialog(FillDynamicFormActivity.this.activity);
            }
        });
    }

    protected void onResume() {
        super.onResume();
        String string = getSharedPreferences("", 0).getString("usernamekey", "");
        Bundle bundle = new Bundle();
        bundle.putString("user_name", string);
        FirebaseAnalytics.getInstance(this).logEvent("PAGE_FILL_DYNAMIC_FORMS", bundle);
    }

    protected void onStop() {
        TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
        if (transparentProgressDialog != null && transparentProgressDialog.isShowing()) {
            this.mProgressbar.dismiss();
        }
        super.onStop();
    }
}