导航菜单

页面标题

页面副标题

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

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

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


package com.mcb.stjohnsemschool.activity;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.mcb.stjohnsemschool.fragment.FileUploadFragmentDialog;
import com.mcb.stjohnsemschool.interfaces.OnImageCapturedInterface;
import com.mcb.stjohnsemschool.model.ParentConcernCategoriesModelClass;
import com.mcb.stjohnsemschool.model.SavingResponseModel;
import com.mcb.stjohnsemschool.services.ApiClient;
import com.mcb.stjohnsemschool.services.ApiInterface;
import com.mcb.stjohnsemschool.utils.FileUtils;
import com.mcb.stjohnsemschool.utils.TransparentProgressDialog;
import com.mcb.stjohnsemschool.utils.Utility;
import java.io.File;
import java.util.ArrayList;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class SubmitParentConcernFormActivity extends AppCompatActivity implements View.OnClickListener, OnImageCapturedInterface {
    private Activity activity;
    private String branchId;
    private ConnectivityManager conMgr;
    private int concernCategoryId;
    private String concernTypeCategory;
    private int concernTypeCategoryId;
    private String detailsOfConcern;
    private TextView mAttachFile;
    private TextView mAttachedFileName;
    private Spinner mConcernCategories;
    private TextView mConcernCategoriesHeading;
    private EditText mDetailsOfConcern;
    private TextView mDetailsOfConcernHeading;
    private Typeface mLatoFont;
    private CheckBox mNotifyUser;
    private TransparentProgressDialog mProgressbar;
    private SharedPreferences mSharedPref;
    private Button mSubmit;
    private int notifyUser;
    private OnImageCapturedInterface onImageCaptured;
    private String organisationId;
    private String studentEnrollmentId;
    private String userId;
    private String filePath = "";
    private String concernCategory = "";
    private ArrayList<ParentConcernCategoriesModelClass> concernCategories = new ArrayList<>();
    private boolean isFromBrowse = false;

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_submit_parent_concern_form);
        this.activity = this;
        this.onImageCaptured = this;
        this.mLatoFont = Typeface.createFromAsset(getAssets(), "Roboto-Regular.ttf");
        SharedPreferences sharedPreferences = getSharedPreferences("", 0);
        this.mSharedPref = sharedPreferences;
        this.userId = sharedPreferences.getString("UseridKey", this.userId);
        this.studentEnrollmentId = this.mSharedPref.getString("studentEnrollmentIdKey", this.studentEnrollmentId);
        this.organisationId = this.mSharedPref.getString("orgnizationIdKey", this.organisationId);
        this.branchId = this.mSharedPref.getString("BranchIdKey", this.branchId);
        this.mProgressbar = new TransparentProgressDialog(this, R.drawable.spinner_loading_imag);
        Bundle extras = getIntent().getExtras();
        this.concernTypeCategoryId = extras.getInt("ServiceRequestId");
        this.concernTypeCategory = extras.getString("ServiceName");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowTitleEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setTitle(this.concernTypeCategory);
        initializations();
    }

    private void initializations() {
        this.mConcernCategoriesHeading = (TextView) findViewById(R.id.txv_concern_categories);
        this.mDetailsOfConcernHeading = (TextView) findViewById(R.id.txv_details_of_concern);
        this.mAttachFile = (TextView) findViewById(R.id.txv_attach_file);
        this.mAttachedFileName = (TextView) findViewById(R.id.txv_attached_file_name);
        this.mNotifyUser = (CheckBox) findViewById(R.id.chk_notify_user);
        this.mDetailsOfConcern = (EditText) findViewById(R.id.edt_details_of_concern);
        this.mSubmit = (Button) findViewById(R.id.btn_submit);
        this.mConcernCategories = (Spinner) findViewById(R.id.spn_concern_categories);
        this.mConcernCategoriesHeading.setTypeface(this.mLatoFont);
        this.mDetailsOfConcernHeading.setTypeface(this.mLatoFont);
        this.mAttachFile.setTypeface(this.mLatoFont, 1);
        this.mAttachedFileName.setTypeface(this.mLatoFont);
        this.mNotifyUser.setTypeface(this.mLatoFont);
        this.mDetailsOfConcern.setTypeface(this.mLatoFont);
        this.mSubmit.setTypeface(this.mLatoFont);
        this.mAttachFile.setOnClickListener(this);
        this.mSubmit.setOnClickListener(this);
        this.mAttachedFileName.setVisibility(8);
        this.mNotifyUser.setVisibility(8);
        this.mConcernCategories.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
            }

            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long j) {
                SubmitParentConcernFormActivity submitParentConcernFormActivity = SubmitParentConcernFormActivity.this;
                submitParentConcernFormActivity.concernCategoryId = ((ParentConcernCategoriesModelClass) submitParentConcernFormActivity.concernCategories.get(i)).getServiceRequestId();
                SubmitParentConcernFormActivity submitParentConcernFormActivity2 = SubmitParentConcernFormActivity.this;
                submitParentConcernFormActivity2.concernCategory = ((ParentConcernCategoriesModelClass) submitParentConcernFormActivity2.concernCategories.get(i)).getServiceName();
            }
        });
        getServiceCategories();
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() == 16908332) {
            super.onBackPressed();
            return true;
        }
        return super.onOptionsItemSelected(menuItem);
    }

    @Override
    public void onClick(View view) {
        if (view == this.mAttachFile) {
            ArrayList arrayList = new ArrayList();
            this.isFromBrowse = false;
            FileUploadFragmentDialog fileUploadFragmentDialog = new FileUploadFragmentDialog(arrayList, false, this.onImageCaptured);
            fileUploadFragmentDialog.show(getSupportFragmentManager(), fileUploadFragmentDialog.getTag());
            return;
        }
        if (view == this.mSubmit) {
            String trim = this.mDetailsOfConcern.getText().toString().trim();
            this.detailsOfConcern = trim;
            this.notifyUser = 1;
            if (this.concernCategoryId > 0) {
                if (trim.length() > 0) {
                    saveServiceTicket();
                    return;
                } else {
                    Toast.makeText(getApplicationContext(), "Please enter details of concern", 0).show();
                    return;
                }
            }
            Toast.makeText(getApplicationContext(), "Please select concern type", 0).show();
        }
    }

    protected void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i2 != 100 || intent == null) {
            return;
        }
        ArrayList<String> stringArrayListExtra = intent.getStringArrayListExtra("FilePaths");
        if (intent.hasExtra("IsFromBrowse")) {
            this.isFromBrowse = intent.getBooleanExtra("IsFromBrowse", false);
        }
        if (stringArrayListExtra.size() > 0) {
            this.filePath = stringArrayListExtra.get(0);
        }
        String str = this.filePath;
        if (str == null || str.length() <= 0) {
            return;
        }
        getFileNameByPath();
    }

    public void onFileCaptured(ArrayList<String> arrayList) {
        if (arrayList == null || arrayList.size() <= 0) {
            return;
        }
        String str = arrayList.get(0);
        this.filePath = str;
        if (str == null || str.length() <= 0) {
            return;
        }
        getFileNameByPath();
    }

    public void getFileNameByPath() {
        String str;
        String str2;
        String str3;
        try {
            String str4 = this.filePath;
            String substring = str4.substring(str4.lastIndexOf("/") + 1);
            String str5 = this.filePath;
            String substring2 = str5.substring(str5.lastIndexOf(".") + 1);
            this.mAttachedFileName.setText(substring);
            if (!substring2.contains("doc") && !substring2.contains("docx") && !substring2.contains("pdf") && !substring2.contains("png") && !substring2.contains("jpg") && !substring2.contains("jpeg") && !substring2.equalsIgnoreCase("heic") && !substring2.equalsIgnoreCase("heif")) {
                if (this.isFromBrowse && (str3 = this.filePath) != null && str3.length() > 0) {
                    FileUtils.deleteFile(getApplicationContext(), this.filePath);
                }
                this.filePath = "";
                Toast.makeText(getApplicationContext(), "Only files with extension .doc.docx,.pdf,.jpg,.png, .heic, .heif are allowed", 0).show();
                this.mAttachedFileName.setVisibility(8);
                return;
            }
            int parseInt = Integer.parseInt(String.valueOf(new File(this.filePath).length() / 1024));
            if (substring == null) {
                if (this.isFromBrowse && (str = this.filePath) != null && str.length() > 0) {
                    FileUtils.deleteFile(getApplicationContext(), this.filePath);
                }
                this.filePath = "";
                this.mAttachedFileName.setVisibility(8);
                return;
            }
            if (parseInt > 10240) {
                if (this.isFromBrowse && (str2 = this.filePath) != null && str2.length() > 0) {
                    FileUtils.deleteFile(getApplicationContext(), this.filePath);
                }
                this.mAttachedFileName.setVisibility(8);
                this.filePath = "";
                Toast.makeText(getApplicationContext(), "File size exceeds allowed limit of 10MB", 0).show();
                return;
            }
            this.mAttachedFileName.setVisibility(0);
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(getApplicationContext(), "File not supported!!", 0).show();
        }
    }

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

    private void submitServiceTicket() {
        MultipartBody.Part part;
        TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
        if (transparentProgressDialog != null && !transparentProgressDialog.isShowing()) {
            this.mProgressbar.show();
        }
        RequestBody create = RequestBody.create(MediaType.parse("text/plain"), String.valueOf(this.userId));
        RequestBody create2 = RequestBody.create(MediaType.parse("text/plain"), String.valueOf(this.studentEnrollmentId));
        RequestBody create3 = RequestBody.create(MediaType.parse("text/plain"), String.valueOf(this.organisationId));
        RequestBody create4 = RequestBody.create(MediaType.parse("text/plain"), String.valueOf(this.branchId));
        RequestBody create5 = RequestBody.create(MediaType.parse("text/plain"), String.valueOf(this.concernCategoryId));
        RequestBody create6 = RequestBody.create(MediaType.parse("text/plain"), this.concernCategory);
        RequestBody create7 = RequestBody.create(MediaType.parse("text/plain"), this.detailsOfConcern);
        RequestBody create8 = RequestBody.create(MediaType.parse("text/plain"), String.valueOf(this.notifyUser));
        RequestBody create9 = RequestBody.create(MediaType.parse("text/plain"), Utility.getSchoolApiKey(getApplicationContext()));
        String str = this.filePath;
        if (str == null || str.length() <= 0) {
            part = null;
        } else {
            File file = new File(this.filePath);
            part = MultipartBody.Part.createFormData("file1", file.getName(), RequestBody.create(MediaType.parse("*/*"), file));
        }
        ((ApiInterface) ApiClient.getClient1(getApplicationContext()).create(ApiInterface.class)).SaveServiceTicket(part, create, create2, create3, create4, create5, create6, create7, create8, create9).enqueue(new Callback<SavingResponseModel>() {
            public void onResponse(Call<SavingResponseModel> call, Response<SavingResponseModel> response) {
                if (SubmitParentConcernFormActivity.this.mProgressbar != null && SubmitParentConcernFormActivity.this.mProgressbar.isShowing()) {
                    SubmitParentConcernFormActivity.this.mProgressbar.dismiss();
                }
                if (response == null || response.body() == null) {
                    Utility.showAlertDialog(SubmitParentConcernFormActivity.this.activity);
                    return;
                }
                SavingResponseModel savingResponseModel = (SavingResponseModel) response.body();
                final int intValue = savingResponseModel.getStatus().intValue();
                String message = savingResponseModel.getMessage();
                AlertDialog.Builder builder = new AlertDialog.Builder(SubmitParentConcernFormActivity.this);
                builder.setMessage(message).setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                        if (intValue == 1) {
                            if (SubmitParentConcernFormActivity.this.isFromBrowse && SubmitParentConcernFormActivity.this.filePath != null && SubmitParentConcernFormActivity.this.filePath.length() > 0) {
                                FileUtils.deleteFile(SubmitParentConcernFormActivity.this.getApplicationContext(), SubmitParentConcernFormActivity.this.filePath);
                            }
                            SubmitParentConcernFormActivity.this.finish();
                        }
                    }
                }).setCancelable(false);
                builder.create().show();
            }

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

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

    private void serviceCategories() {
        TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
        if (transparentProgressDialog != null && !transparentProgressDialog.isShowing()) {
            this.mProgressbar.show();
        }
        ((ApiInterface) ApiClient.getClient1(getApplicationContext()).create(ApiInterface.class)).GetServiceCategories(Integer.parseInt(this.organisationId), this.concernTypeCategoryId, Utility.getSchoolApiKey(this)).enqueue(new Callback<ArrayList<ParentConcernCategoriesModelClass>>() {
            public void onResponse(Call<ArrayList<ParentConcernCategoriesModelClass>> call, Response<ArrayList<ParentConcernCategoriesModelClass>> response) {
                if (SubmitParentConcernFormActivity.this.mProgressbar != null && SubmitParentConcernFormActivity.this.mProgressbar.isShowing()) {
                    SubmitParentConcernFormActivity.this.mProgressbar.dismiss();
                }
                if (response == null || response.body() == null) {
                    Utility.showAlertDialog(SubmitParentConcernFormActivity.this.activity);
                    return;
                }
                SubmitParentConcernFormActivity.this.concernCategories.clear();
                SubmitParentConcernFormActivity.this.concernCategories = (ArrayList) response.body();
                ParentConcernCategoriesModelClass parentConcernCategoriesModelClass = new ParentConcernCategoriesModelClass();
                parentConcernCategoriesModelClass.setServiceName("-Select-");
                parentConcernCategoriesModelClass.setServiceRequestId(0);
                SubmitParentConcernFormActivity.this.concernCategories.add(0, parentConcernCategoriesModelClass);
                SubmitParentConcernFormActivity.this.mConcernCategories.setAdapter((SpinnerAdapter) new ArrayAdapter(SubmitParentConcernFormActivity.this.getApplicationContext(), R.layout.customlayout, SubmitParentConcernFormActivity.this.concernCategories));
            }

            public void onFailure(Call<ArrayList<ParentConcernCategoriesModelClass>> call, Throwable th) {
                if (SubmitParentConcernFormActivity.this.mProgressbar != null && SubmitParentConcernFormActivity.this.mProgressbar.isShowing()) {
                    SubmitParentConcernFormActivity.this.mProgressbar.dismiss();
                }
                Utility.showAlertDialog(SubmitParentConcernFormActivity.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_SUBMIT_PARENT_CONCERN_FORM", bundle);
    }
}