导航菜单

页面标题

页面副标题

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

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

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


package com.mcb.stjohnsemschool.activity;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.exoplayer2.extractor.ts.TsExtractor;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.mcb.stjohnsemschool.fragment.FileUploadFragmentDialog;
import com.mcb.stjohnsemschool.interfaces.OnImageCapturedInterface;
import com.mcb.stjohnsemschool.model.GroupsConversationModel;
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 java.util.Iterator;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class NewConversationActivity extends AppCompatActivity implements OnImageCapturedInterface {
    private static final String TAG = "com.mcb.stjohnsemschool.activity.NewConversationActivity";
    private Activity activity;
    private ApiInterface apiService;
    private Context context;
    private ArrayList<GroupsConversationModel> groupsList;
    private TextView mAlertText;
    private LinearLayout mAttachmentsLL;
    private EditText mDescriptionEt;
    private Dialog mDialogAlert;
    private TextView mDialogAlertYes;
    private TransparentProgressDialog mProgressbar;
    private ScrollView mScrl;
    private EditText mTopicEt;
    private Spinner mVisibleToSp;
    private OnImageCapturedInterface onImageCaptured;
    private String organisationID;
    private String schoolChatGroupID;
    private String userID;
    private int mSelectedGroupId = 0;
    private boolean isFromBrowse = false;
    private ArrayList<String> pathList = new ArrayList<>();

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_new_conversation);
        this.onImageCaptured = this;
        this.activity = this;
        this.context = getApplicationContext();
        setTitle("New Conversation");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        setUpIds();
    }

    private void setUpIds() {
        Dialog dialog = new Dialog(this, R.style.Theme_Dialog);
        this.mDialogAlert = dialog;
        WindowManager.LayoutParams attributes = dialog.getWindow().getAttributes();
        attributes.dimAmount = 5.0f;
        this.mDialogAlert.getWindow().setAttributes(attributes);
        this.mDialogAlert.getWindow().addFlags(2);
        this.mDialogAlert.setContentView(R.layout.alert_dialog_layout);
        this.mDialogAlert.setCanceledOnTouchOutside(true);
        this.mAlertText = (TextView) this.mDialogAlert.findViewById(R.id.alert_text);
        TextView textView = (TextView) this.mDialogAlert.findViewById(R.id.ok_alert_dialog);
        this.mDialogAlertYes = textView;
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (NewConversationActivity.this.mDialogAlert != null && NewConversationActivity.this.mDialogAlert.isShowing()) {
                    NewConversationActivity.this.mDialogAlert.dismiss();
                }
                NewConversationActivity.this.finish();
            }
        });
        SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences("", 0);
        this.apiService = (ApiInterface) ApiClient.getClient1(this.context).create(ApiInterface.class);
        this.mProgressbar = new TransparentProgressDialog(this, R.drawable.spinner_loading_imag);
        Intent intent = getIntent();
        this.groupsList = intent.getParcelableArrayListExtra("groups");
        this.mSelectedGroupId = intent.getIntExtra(FirebaseAnalytics.Param.GROUP_ID, 0);
        this.mScrl = (ScrollView) findViewById(R.id.scrl);
        this.mVisibleToSp = (Spinner) findViewById(R.id.spn_visible_to);
        this.mTopicEt = (EditText) findViewById(R.id.edt_topic);
        this.mDescriptionEt = (EditText) findViewById(R.id.edt_description);
        this.mAttachmentsLL = (LinearLayout) findViewById(R.id.ll_attached_files);
        this.userID = sharedPreferences.getString("UseridKey", "0");
        this.organisationID = sharedPreferences.getString("orgnizationIdKey", "0");
        this.mVisibleToSp.setAdapter((SpinnerAdapter) new ArrayAdapter(getApplicationContext(), R.layout.custom_textview, this.groupsList));
        this.mVisibleToSp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
            }

            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long j) {
                NewConversationActivity.this.schoolChatGroupID = "" + ((GroupsConversationModel) NewConversationActivity.this.groupsList.get(i)).getGroupId();
            }
        });
        this.mVisibleToSp.setSelection(getSelectedGroupPosition());
        this.mVisibleToSp.setEnabled(false);
    }

    private int getSelectedGroupPosition() {
        for (int i = 0; i < this.groupsList.size(); i++) {
            if (this.groupsList.get(i).getGroupId() == this.mSelectedGroupId) {
                return i;
            }
        }
        return 0;
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_attach, menu);
        return true;
    }

    public void onBackPressed() {
        super.onBackPressed();
        finish();
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        int itemId = menuItem.getItemId();
        if (itemId == 16908332) {
            finish();
            return true;
        }
        if (itemId == 2131361854) {
            this.isFromBrowse = false;
            FileUploadFragmentDialog fileUploadFragmentDialog = new FileUploadFragmentDialog(this.pathList, true, this.onImageCaptured);
            fileUploadFragmentDialog.show(getSupportFragmentManager(), fileUploadFragmentDialog.getTag());
        } else if (itemId == 2131361885) {
            if (this.mTopicEt.getText().toString().trim().length() > 0) {
                if (this.mDescriptionEt.getText().toString().trim().length() > 0) {
                    saveConversation();
                } else {
                    Toast.makeText(getApplicationContext(), "Enter Description", 0).show();
                }
            } else {
                Toast.makeText(getApplicationContext(), "Enter Topic Name", 0).show();
            }
        }
        return super.onOptionsItemSelected(menuItem);
    }

    private void saveConversation() {
        try {
            RequestBody create = RequestBody.create(MediaType.parse("text/plain"), this.mTopicEt.getText().toString());
            RequestBody create2 = RequestBody.create(MediaType.parse("text/plain"), this.mDescriptionEt.getText().toString());
            RequestBody create3 = RequestBody.create(MediaType.parse("text/plain"), String.valueOf(this.userID));
            RequestBody create4 = RequestBody.create(MediaType.parse("text/plain"), String.valueOf(this.organisationID));
            RequestBody create5 = RequestBody.create(MediaType.parse("text/plain"), String.valueOf(this.schoolChatGroupID));
            RequestBody create6 = RequestBody.create(MediaType.parse("text/plain"), Utility.getSchoolApiKey(this.context));
            TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
            if (transparentProgressDialog != null) {
                transparentProgressDialog.show();
            }
            ArrayList arrayList = new ArrayList();
            Iterator<String> it = this.pathList.iterator();
            while (it.hasNext()) {
                File file = new File(it.next());
                arrayList.add(MultipartBody.Part.createFormData("file1", file.getName(), RequestBody.create(MediaType.parse("*/*"), file)));
            }
            this.apiService.saveSchoolConversationTopic(arrayList, create3, create4, create5, create, create2, create6).enqueue(new Callback<String>() {
                public void onResponse(Call<String> call, Response<String> response) {
                    if (NewConversationActivity.this.mProgressbar != null && NewConversationActivity.this.mProgressbar.isShowing()) {
                        NewConversationActivity.this.mProgressbar.dismiss();
                    }
                    try {
                        if (response.code() == 200) {
                            Iterator it2 = NewConversationActivity.this.pathList.iterator();
                            while (it2.hasNext()) {
                                String str = (String) it2.next();
                                if (NewConversationActivity.this.isFromBrowse && str != null && str.length() > 0) {
                                    FileUtils.deleteFile(NewConversationActivity.this.getApplicationContext(), str);
                                }
                            }
                            NewConversationActivity.this.mAlertText.setText((CharSequence) response.body());
                            NewConversationActivity.this.mDialogAlert.show();
                            return;
                        }
                        Toast.makeText(NewConversationActivity.this.getApplicationContext(), response.message(), 0).show();
                    } catch (Exception e) {
                        Toast.makeText(NewConversationActivity.this.getApplicationContext(), "Unable to get Server Response,Retry!", 0).show();
                        e.printStackTrace();
                    }
                }

                public void onFailure(Call<String> call, Throwable th) {
                    if (NewConversationActivity.this.mProgressbar != null && NewConversationActivity.this.mProgressbar.isShowing()) {
                        NewConversationActivity.this.mProgressbar.dismiss();
                    }
                    NewConversationActivity.this.mAlertText.setText(th.toString());
                    NewConversationActivity.this.mDialogAlert.show();
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
            TransparentProgressDialog transparentProgressDialog2 = this.mProgressbar;
            if (transparentProgressDialog2 == null || !transparentProgressDialog2.isShowing()) {
                return;
            }
            this.mProgressbar.dismiss();
        }
    }

    protected void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i2 != 100 || intent == null) {
            return;
        }
        this.pathList.clear();
        this.pathList = intent.getStringArrayListExtra("FilePaths");
        if (intent.hasExtra("IsFromBrowse")) {
            this.isFromBrowse = intent.getBooleanExtra("IsFromBrowse", false);
        }
        showAttachedFiles();
    }

    public void onFileCaptured(ArrayList<String> arrayList) {
        this.pathList = arrayList;
        showAttachedFiles();
    }

    public void showAttachedFiles() {
        this.mAttachmentsLL.removeAllViews();
        if (this.pathList.size() > 0) {
            this.mAttachmentsLL.setVisibility(0);
            for (int i = 0; i < this.pathList.size(); i++) {
                View inflate = LayoutInflater.from(getApplicationContext()).inflate(R.layout.file_attachment_view, (ViewGroup) null);
                TextView textView = (TextView) inflate.findViewById(R.id.txv_filename);
                ImageView imageView = (ImageView) inflate.findViewById(R.id.img_cancel_file);
                imageView.setTag(Integer.valueOf(i));
                imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        NewConversationActivity.this.pathList.remove(Integer.parseInt(view.getTag().toString()));
                        NewConversationActivity.this.showAttachedFiles();
                    }
                });
                String str = this.pathList.get(i);
                textView.setText(str.substring(str.lastIndexOf("/") + 1));
                this.mAttachmentsLL.addView(inflate);
            }
        } else {
            this.mAttachmentsLL.setVisibility(8);
        }
        this.mScrl.postDelayed(new Runnable() {
            @Override
            public void run() {
                NewConversationActivity.this.mScrl.fullScroll(TsExtractor.TS_STREAM_TYPE_HDMV_DTS);
            }
        }, 100L);
    }

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