导航菜单

页面标题

页面副标题

bbinstant v6.24.0 - KapchatAttachmentActivity.java 源代码

正在查看: bbinstant v6.24.0 应用的 KapchatAttachmentActivity.java JAVA 源代码文件

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


package com.adjetter.kapchatsdk.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.MimeTypeMap;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.exifinterface.media.a;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.adjetter.kapchatsdk.KapchatGallerylistpager;
import com.adjetter.kapchatsdk.KapchatHelper;
import com.adjetter.kapchatsdk.KapchatMessageInsertion;
import com.adjetter.kapchatsdk.KapchatMessageList;
import com.adjetter.kapchatsdk.R;
import com.adjetter.kapchatsdk.animation.KapchatImageUtils;
import com.adjetter.kapchatsdk.animation.TransparentProgressDialog;
import com.adjetter.kapchatsdk.attachments.KapchatAttachmentStructure;
import com.adjetter.kapchatsdk.interfaces.IUpdatenotify;
import com.adjetter.kapchatsdk.structure.KapchatAttachmentPreservedList;
import com.amazonaws.mobileconnectors.s3.transferutility.TransferTable;
import com.google.android.material.snackbar.Snackbar;
import com.squareup.picasso.u;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

public class KapchatAttachmentActivity extends AppCompatActivity implements IUpdatenotify {
    ActionBar actionBar;
    LinearLayout attachmentLayoutBottom;
    LinearLayout attachmentLayoutTop;
    TextView cancelAttachment;
    RecyclerView galleryPager;
    LinearLayoutManager layoutManager;
    public KapchatGallerylistpager mAapter;
    String messageType;
    TransparentProgressDialog progressDialog;
    TextView sendAttachment;
    String toJid = "";
    String attachmentType = "";
    ArrayList<KapchatAttachmentStructure> attachmentList = new ArrayList<>();
    IUpdatenotify iUpdatenotify = null;
    RelativeLayout attachmentPrimaryView = null;
    private String[] PERMISSIONS_STORAGE = {"android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE", "android.permission-group.STORAGE"};
    String saveSelectedImageUrl = "";

    public static String getMimeType(String str) {
        StringBuilder sb = new StringBuilder();
        sb.append("url ");
        sb.append(str);
        String fileExtensionFromUrl = MimeTypeMap.getFileExtensionFromUrl(str.replace(" ", "%20"));
        if (fileExtensionFromUrl != null) {
            return MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtensionFromUrl);
        }
        return null;
    }

    @Override
    protected void onActivityResult(int i, int i2, Intent intent) {
        String replace;
        super.onActivityResult(i, i2, intent);
        if (i != 11 || intent == null) {
            if (i != 15 || intent == null || intent.getData() == null) {
                return;
            }
            String str = "" + KapchatScreenActivity.getRealPathFromURI(getApplicationContext(), intent.getData());
            if (str == null || str.equalsIgnoreCase("")) {
                Toast.makeText(this, "Not able to access the selected file. please try with some other", 0).show();
                return;
            }
            File file = new File(str);
            if (!file.exists() || file.length() >= 5000000) {
                Toast.makeText(this, "File Size Should be less than 5MB", 0).show();
                return;
            }
            for (int i3 = 0; i3 < this.attachmentLayoutTop.getChildCount(); i3++) {
                if (this.attachmentLayoutTop.getChildAt(i3).getTag() != null) {
                    if ("1".equalsIgnoreCase("" + this.attachmentLayoutTop.getChildAt(i3).getTag())) {
                        this.attachmentLayoutTop.removeViewAt(i3);
                    }
                }
            }
            for (int i4 = 0; i4 < this.attachmentLayoutBottom.getChildCount(); i4++) {
                if (this.attachmentLayoutBottom.getChildAt(i4).getTag() != null) {
                    if ("1".equalsIgnoreCase("" + this.attachmentLayoutBottom.getChildAt(i4).getTag())) {
                        this.attachmentLayoutBottom.removeViewAt(i4);
                    }
                }
            }
            if (this.attachmentLayoutTop.getChildCount() < 5) {
                ImageView imageView = new ImageView(this);
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(150, 150);
                layoutParams.weight = 1.0f;
                layoutParams.gravity = 3;
                imageView.setLayoutParams(layoutParams);
                try {
                    u.get().load(new File(str)).fit().placeholder(R.drawable.kapchat_nopreview).into(imageView);
                    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                } catch (Exception e) {
                    e.printStackTrace();
                    u.get().load(new File(str)).fit().placeholder(R.drawable.kapchat_nopreview).into(imageView);
                }
                imageView.setPadding(0, 0, 80, 0);
                imageView.setId(this.attachmentLayoutTop.getChildCount());
                imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        KapchatAttachmentActivity kapchatAttachmentActivity = KapchatAttachmentActivity.this;
                        if (kapchatAttachmentActivity.galleryPager == null || kapchatAttachmentActivity.attachmentList.size() <= view.getId()) {
                            return;
                        }
                        KapchatAttachmentActivity.this.galleryPager.scrollToPosition(view.getId());
                    }
                });
                this.attachmentLayoutTop.addView(imageView);
                KapchatAttachmentStructure kapchatAttachmentStructure = new KapchatAttachmentStructure();
                kapchatAttachmentStructure.setMime(getMimeType(str));
                kapchatAttachmentStructure.setDownload(str);
                kapchatAttachmentStructure.setFilepath(str);
                this.attachmentList.add(kapchatAttachmentStructure);
                this.mAapter.notifyDataSetChanged();
            } else {
                ImageView imageView2 = new ImageView(this);
                LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(150, 150);
                layoutParams2.weight = 1.0f;
                layoutParams2.gravity = 3;
                imageView2.setLayoutParams(layoutParams2);
                try {
                    u.get().load(new File(str)).fit().placeholder(R.drawable.kapchat_nopreview).into(imageView2);
                    imageView2.setScaleType(ImageView.ScaleType.CENTER_CROP);
                } catch (Exception e2) {
                    e2.printStackTrace();
                    u.get().load(new File(str)).fit().placeholder(R.drawable.kapchat_nopreview).into(imageView2);
                }
                imageView2.setLeft(10);
                imageView2.setPadding(10, 0, 0, 0);
                imageView2.setId(this.attachmentLayoutTop.getChildCount() + this.attachmentLayoutBottom.getChildCount());
                imageView2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        KapchatAttachmentActivity kapchatAttachmentActivity = KapchatAttachmentActivity.this;
                        if (kapchatAttachmentActivity.galleryPager == null || kapchatAttachmentActivity.attachmentList.size() <= view.getId()) {
                            return;
                        }
                        KapchatAttachmentActivity.this.galleryPager.scrollToPosition(view.getId());
                    }
                });
                this.attachmentLayoutBottom.addView(imageView2);
                KapchatAttachmentStructure kapchatAttachmentStructure2 = new KapchatAttachmentStructure();
                kapchatAttachmentStructure2.setMime(getMimeType(str));
                kapchatAttachmentStructure2.setDownload(str);
                kapchatAttachmentStructure2.setFilepath(str);
                this.attachmentList.add(kapchatAttachmentStructure2);
                this.mAapter.notifyDataSetChanged();
            }
            if (this.attachmentLayoutTop.getChildCount() < 5) {
                ImageView imageView3 = new ImageView(this);
                LinearLayout.LayoutParams layoutParams3 = new LinearLayout.LayoutParams(150, 150);
                imageView3.setLayoutParams(layoutParams3);
                imageView3.setTag("1");
                layoutParams3.weight = 1.0f;
                layoutParams3.gravity = 3;
                imageView3.setPadding(10, 50, 50, 50);
                imageView3.setImageResource(R.drawable.kapchatplus);
                imageView3.setScaleType(ImageView.ScaleType.FIT_CENTER);
                imageView3.setLeft(10);
                this.attachmentLayoutTop.addView(imageView3);
            } else if (this.attachmentLayoutBottom.getChildCount() < 5) {
                ImageView imageView4 = new ImageView(this);
                LinearLayout.LayoutParams layoutParams4 = new LinearLayout.LayoutParams(150, 150);
                imageView4.setLayoutParams(layoutParams4);
                imageView4.setTag("1");
                layoutParams4.weight = 1.0f;
                layoutParams4.gravity = 3;
                imageView4.setPadding(10, 50, 50, 50);
                imageView4.setImageResource(R.drawable.kapchatplus);
                imageView4.setScaleType(ImageView.ScaleType.FIT_CENTER);
                imageView4.setLeft(10);
                this.attachmentLayoutBottom.addView(imageView4);
            }
            setclicklistener();
            return;
        }
        Uri data = intent.getData();
        String[] strArr = {"_data"};
        StringBuilder sb = new StringBuilder();
        sb.append("selected image uri ");
        sb.append(data);
        Cursor query = getContentResolver().query(data, strArr, null, null, null);
        if (query != null) {
            query.moveToFirst();
            replace = query.getString(query.getColumnIndex(strArr[0]));
        } else {
            replace = data.getPath().replace("file://", "");
        }
        File file2 = new File(Environment.getExternalStorageDirectory(), "Kaphatsend");
        if (!file2.isFile()) {
            file2.mkdirs();
        }
        File file3 = new File(file2, "kapchatsend_3_" + Calendar.getInstance().getTimeInMillis() + ".jpg");
        if (KapchatImageUtils.compressImage(replace, file3).booleanValue()) {
            replace = file3.getAbsolutePath();
        }
        String str2 = replace;
        StringBuilder sb2 = new StringBuilder();
        sb2.append("file path is ");
        sb2.append(str2);
        if (query != null) {
            query.close();
        }
        File file4 = new File(str2);
        if (!file4.exists() || file4.length() >= 5000000) {
            Toast.makeText(this, "File Size Should be less than 5MB", 0).show();
            return;
        }
        for (int i5 = 0; i5 < this.attachmentLayoutTop.getChildCount(); i5++) {
            if (this.attachmentLayoutTop.getChildAt(i5).getTag() != null) {
                if ("1".equalsIgnoreCase("" + this.attachmentLayoutTop.getChildAt(i5).getTag())) {
                    this.attachmentLayoutTop.removeViewAt(i5);
                }
            }
        }
        for (int i6 = 0; i6 < this.attachmentLayoutBottom.getChildCount(); i6++) {
            if (this.attachmentLayoutBottom.getChildAt(i6).getTag() != null) {
                if ("1".equalsIgnoreCase("" + this.attachmentLayoutBottom.getChildAt(i6).getTag())) {
                    this.attachmentLayoutBottom.removeViewAt(i6);
                }
            }
        }
        if (this.attachmentLayoutTop.getChildCount() < 5) {
            ImageView imageView5 = new ImageView(this);
            LinearLayout.LayoutParams layoutParams5 = new LinearLayout.LayoutParams(150, 150);
            layoutParams5.weight = 1.0f;
            layoutParams5.gravity = 3;
            imageView5.setLayoutParams(layoutParams5);
            try {
                u.get().load(new File(str2)).fit().placeholder(R.drawable.kapchat_nopreview).into(imageView5);
                imageView5.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            } catch (Exception e3) {
                e3.printStackTrace();
                u.get().load(new File(str2)).fit().placeholder(R.drawable.kapchat_nopreview).into(imageView5);
            }
            imageView5.setPadding(10, 0, 0, 0);
            imageView5.setId(this.attachmentLayoutTop.getChildCount());
            imageView5.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    KapchatAttachmentActivity kapchatAttachmentActivity = KapchatAttachmentActivity.this;
                    if (kapchatAttachmentActivity.galleryPager == null || kapchatAttachmentActivity.attachmentList.size() <= view.getId()) {
                        return;
                    }
                    KapchatAttachmentActivity.this.galleryPager.scrollToPosition(view.getId());
                }
            });
            this.attachmentLayoutTop.addView(imageView5);
            KapchatAttachmentStructure kapchatAttachmentStructure3 = new KapchatAttachmentStructure();
            kapchatAttachmentStructure3.setMime(getMimeType(str2));
            kapchatAttachmentStructure3.setDownload(str2);
            kapchatAttachmentStructure3.setFilepath(str2);
            this.attachmentList.add(kapchatAttachmentStructure3);
            this.mAapter.notifyDataSetChanged();
        } else {
            ImageView imageView6 = new ImageView(this);
            LinearLayout.LayoutParams layoutParams6 = new LinearLayout.LayoutParams(150, 150);
            layoutParams6.weight = 1.0f;
            layoutParams6.gravity = 3;
            imageView6.setLayoutParams(layoutParams6);
            try {
                u.get().load(new File(str2)).fit().placeholder(R.drawable.kapchat_nopreview).into(imageView6);
                imageView6.setScaleType(ImageView.ScaleType.CENTER_CROP);
            } catch (Exception e4) {
                e4.printStackTrace();
                u.get().load(new File(str2)).fit().placeholder(R.drawable.kapchat_nopreview).into(imageView6);
            }
            imageView6.setLeft(10);
            imageView6.setPadding(10, 0, 0, 0);
            imageView6.setId(this.attachmentLayoutTop.getChildCount() + this.attachmentLayoutBottom.getChildCount());
            imageView6.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    KapchatAttachmentActivity kapchatAttachmentActivity = KapchatAttachmentActivity.this;
                    if (kapchatAttachmentActivity.galleryPager == null || kapchatAttachmentActivity.attachmentList.size() <= view.getId()) {
                        return;
                    }
                    KapchatAttachmentActivity.this.galleryPager.scrollToPosition(view.getId());
                }
            });
            this.attachmentLayoutBottom.addView(imageView6);
            KapchatAttachmentStructure kapchatAttachmentStructure4 = new KapchatAttachmentStructure();
            kapchatAttachmentStructure4.setMime(getMimeType(str2));
            kapchatAttachmentStructure4.setDownload(str2);
            kapchatAttachmentStructure4.setFilepath(str2);
            this.attachmentList.add(kapchatAttachmentStructure4);
            this.mAapter.notifyDataSetChanged();
        }
        if (this.attachmentLayoutTop.getChildCount() < 5) {
            ImageView imageView7 = new ImageView(this);
            LinearLayout.LayoutParams layoutParams7 = new LinearLayout.LayoutParams(150, 150);
            imageView7.setLayoutParams(layoutParams7);
            imageView7.setTag("1");
            layoutParams7.weight = 1.0f;
            layoutParams7.gravity = 3;
            imageView7.setPadding(10, 50, 50, 50);
            imageView7.setImageResource(R.drawable.kapchatplus);
            imageView7.setScaleType(ImageView.ScaleType.FIT_CENTER);
            imageView7.setLeft(10);
            this.attachmentLayoutTop.addView(imageView7);
        } else if (this.attachmentLayoutBottom.getChildCount() < 5) {
            ImageView imageView8 = new ImageView(this);
            LinearLayout.LayoutParams layoutParams8 = new LinearLayout.LayoutParams(150, 150);
            imageView8.setLayoutParams(layoutParams8);
            imageView8.setTag("1");
            layoutParams8.weight = 1.0f;
            layoutParams8.gravity = 3;
            imageView8.setPadding(10, 50, 50, 50);
            imageView8.setImageResource(R.drawable.kapchatplus);
            imageView8.setScaleType(ImageView.ScaleType.FIT_CENTER);
            imageView8.setLeft(10);
            this.attachmentLayoutBottom.addView(imageView8);
        }
        setclicklistener();
    }

    @Override
    public void onBackPressed() {
        if (this.attachmentList.size() > 0) {
            setResult(-1);
        } else {
            setResult(0);
        }
        super.onBackPressed();
    }

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_kapchatattachment);
        PrintStream printStream = System.out;
        printStream.println("### value came here 456");
        this.progressDialog = new TransparentProgressDialog(this);
        setupactionbar();
        this.iUpdatenotify = this;
        this.galleryPager = (RecyclerView) findViewById(R.id.galleryviewlist);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, 0, false);
        this.layoutManager = linearLayoutManager;
        this.galleryPager.setLayoutManager(linearLayoutManager);
        this.galleryPager.setLayoutParams(new RelativeLayout.LayoutParams(-1, -1));
        this.attachmentLayoutTop = (LinearLayout) findViewById(R.id.attachmentlayout);
        this.attachmentLayoutBottom = (LinearLayout) findViewById(R.id.attachmentlayout2);
        this.cancelAttachment = (TextView) findViewById(R.id.cancelattach);
        this.sendAttachment = (TextView) findViewById(R.id.sendattacch);
        this.attachmentPrimaryView = (RelativeLayout) findViewById(R.id.attachmentPrimaryView);
        if (bundle != null) {
            KapchatAttachmentPreservedList kapchatAttachmentPreservedList = (KapchatAttachmentPreservedList) bundle.getSerializable("createdList");
            this.saveSelectedImageUrl = kapchatAttachmentPreservedList.getSelectedImage();
            this.toJid = kapchatAttachmentPreservedList.getToJid();
            this.attachmentType = kapchatAttachmentPreservedList.getAttachmentType();
            this.messageType = kapchatAttachmentPreservedList.getMessageType();
            this.attachmentList.clear();
            this.attachmentList.addAll(kapchatAttachmentPreservedList.getAttachmentList());
            reloadSelectedList();
        } else {
            this.saveSelectedImageUrl = getIntent().getExtras().getString("uri");
            Uri parse = Uri.parse(getIntent().getExtras().getString("uri"));
            this.toJid = getIntent().getExtras().getString("tojid");
            this.attachmentType = getIntent().getExtras().getString("from");
            this.messageType = getIntent().getExtras().getString(TransferTable.COLUMN_TYPE);
            if (this.attachmentType.equalsIgnoreCase("gallery")) {
                StringBuilder sb = new StringBuilder();
                sb.append("selected image uri ");
                sb.append(Uri.parse(this.saveSelectedImageUrl));
                ImageView imageView = new ImageView(this);
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(150, 150);
                layoutParams.weight = 1.0f;
                layoutParams.gravity = 3;
                imageView.setLayoutParams(layoutParams);
                try {
                    printStream.println("### value came here 123 : " + getIntent().getExtras().getString("uri"));
                    u.get().load(new File(getIntent().getExtras().getString("uri"))).fit().placeholder(R.drawable.kapchat_nopreview).into(imageView);
                    imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
                } catch (Exception e) {
                    e.printStackTrace();
                    u.get().load(new File(getIntent().getExtras().getString("uri"))).fit().placeholder(R.drawable.kapchat_nopreview).into(imageView);
                }
                imageView.setId(0);
                imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    @SuppressLint({"ResourceType"})
                    public void onClick(View view) {
                        KapchatAttachmentActivity kapchatAttachmentActivity = KapchatAttachmentActivity.this;
                        if (kapchatAttachmentActivity.galleryPager == null || kapchatAttachmentActivity.attachmentList.size() <= view.getId()) {
                            return;
                        }
                        KapchatAttachmentActivity.this.galleryPager.scrollToPosition(view.getId());
                    }
                });
                KapchatAttachmentStructure kapchatAttachmentStructure = new KapchatAttachmentStructure();
                kapchatAttachmentStructure.setMime(getMimeType(getIntent().getExtras().getString("uri")));
                kapchatAttachmentStructure.setDownload(getIntent().getExtras().getString("uri"));
                kapchatAttachmentStructure.setFilepath(getIntent().getExtras().getString("uri"));
                this.attachmentList.add(kapchatAttachmentStructure);
                this.attachmentLayoutTop.addView(imageView);
                ImageView imageView2 = new ImageView(this);
                LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(150, 150);
                imageView2.setLayoutParams(layoutParams2);
                imageView2.setLeft(10);
                imageView2.setTag("1");
                layoutParams2.weight = 1.0f;
                layoutParams2.gravity = 3;
                imageView2.setScaleType(ImageView.ScaleType.FIT_CENTER);
                imageView2.setPadding(10, 50, 50, 50);
                imageView2.setImageResource(R.drawable.kapchatplus);
                this.attachmentLayoutTop.addView(imageView2);
            } else if (this.attachmentType.equalsIgnoreCase("camera")) {
                String uri = parse.toString();
                StringBuilder sb2 = new StringBuilder();
                sb2.append("file path is ");
                sb2.append(uri);
                KapchatAttachmentStructure kapchatAttachmentStructure2 = new KapchatAttachmentStructure();
                kapchatAttachmentStructure2.setMime(getMimeType(uri));
                kapchatAttachmentStructure2.setDownload(uri);
                kapchatAttachmentStructure2.setFilepath(uri);
                this.attachmentList.add(kapchatAttachmentStructure2);
            } else if (this.attachmentType.equalsIgnoreCase("other")) {
                String uri2 = parse.toString();
                KapchatAttachmentStructure kapchatAttachmentStructure3 = new KapchatAttachmentStructure();
                kapchatAttachmentStructure3.setMime(getMimeType(uri2));
                kapchatAttachmentStructure3.setDownload(uri2);
                kapchatAttachmentStructure3.setFilepath(uri2);
                this.attachmentList.add(kapchatAttachmentStructure3);
            }
        }
        setadapter();
        this.cancelAttachment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                KapchatAttachmentActivity.this.finish();
            }
        });
        this.sendAttachment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                KapchatAttachmentActivity.this.progressDialog.show();
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(new Date());
                for (int i = 0; i < KapchatAttachmentActivity.this.attachmentList.size(); i++) {
                    ArrayList arrayList = new ArrayList();
                    arrayList.clear();
                    KapchatMessageList kapchatMessageList = new KapchatMessageList();
                    calendar.add(13, 1);
                    kapchatMessageList.setSendDate("" + calendar.getTime().getTime());
                    kapchatMessageList.setFromJid(KapchatAttachmentActivity.this.getSharedPreferences("kapchatpreference", 0).getString("userName", "") + KapchatHelper.serviceName);
                    kapchatMessageList.setToJid("" + KapchatAttachmentActivity.this.toJid);
                    if (KapchatAttachmentActivity.this.attachmentList.get(i).getBody() == null || KapchatAttachmentActivity.this.attachmentList.get(i).getBody().equalsIgnoreCase("")) {
                        kapchatMessageList.setMessage("");
                    } else {
                        kapchatMessageList.setMessage("" + KapchatAttachmentActivity.this.attachmentList.get(i).getBody());
                    }
                    kapchatMessageList.setMessageType(a.GPS_MEASUREMENT_2D);
                    kapchatMessageList.setMime(KapchatAttachmentActivity.this.attachmentList.get(i).getMime());
                    kapchatMessageList.setMimeurl("0");
                    if (KapchatAttachmentActivity.this.attachmentList.get(i).getMimeurl() != null) {
                        kapchatMessageList.setMimeurl(KapchatAttachmentActivity.this.attachmentList.get(i).getMimeurl());
                    }
                    kapchatMessageList.setDownload("yes");
                    kapchatMessageList.setDownloadPath(KapchatAttachmentActivity.this.attachmentList.get(i).getFilepath().toString());
                    if (KapchatAttachmentActivity.getMimeType(KapchatAttachmentActivity.this.attachmentList.get(i).getFilepath().toString()).split("/")[0].equalsIgnoreCase("image")) {
                        File file = new File("" + KapchatAttachmentActivity.this.attachmentList.get(i).getFilepath().toString());
                        StringBuilder sb3 = new StringBuilder();
                        sb3.append("file path  ");
                        sb3.append(KapchatAttachmentActivity.this.attachmentList.get(i).getFilepath().toString());
                        try {
                            Bitmap extractThumbnail = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(file.getPath()), 500, 500);
                            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                            extractThumbnail.compress(Bitmap.CompressFormat.JPEG, 20, byteArrayOutputStream);
                            kapchatMessageList.setBlob(byteArrayOutputStream.toByteArray());
                        } catch (Exception e2) {
                            kapchatMessageList.setBlob(new byte[]{0});
                            e2.printStackTrace();
                        }
                    } else {
                        kapchatMessageList.setBlob(new byte[]{0});
                    }
                    kapchatMessageList.setMessageStatus("5");
                    kapchatMessageList.setStanzaId("0");
                    arrayList.add(kapchatMessageList);
                    KapchatAttachmentActivity kapchatAttachmentActivity = KapchatAttachmentActivity.this;
                    new KapchatMessageInsertion(kapchatAttachmentActivity, kapchatAttachmentActivity.iUpdatenotify, Boolean.FALSE).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, arrayList);
                }
            }
        });
    }

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

    @Override
    protected void onDestroy() {
        for (int i = 0; i < 10; i++) {
            SharedPreferences.Editor edit = getSharedPreferences("kapchatpreference", 0).edit();
            edit.putString("image" + i, "");
            edit.apply();
        }
        super.onDestroy();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem menuItem) {
        int itemId = menuItem.getItemId();
        if (itemId == 16908332) {
            onBackPressed();
        }
        if (itemId == R.id.delete) {
            this.attachmentList.remove(this.layoutManager.findFirstVisibleItemPosition());
            this.mAapter.notifyDataSetChanged();
            selectedpicture(this.attachmentList);
            if (this.attachmentList.size() == 0) {
                onBackPressed();
            }
        }
        return super.onOptionsItemSelected(menuItem);
    }

    @Override
    protected void onResume() {
        super.onResume();
        verifyStoragePermissions(this, 1);
    }

    @Override
    protected void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        ArrayList<KapchatAttachmentStructure> arrayList = this.attachmentList;
        if (arrayList == null || arrayList.size() <= 0) {
            return;
        }
        bundle.putSerializable("createdList", new KapchatAttachmentPreservedList(this.attachmentList, this.saveSelectedImageUrl, this.toJid, this.attachmentType, this.messageType));
    }

    public void reloadSelectedList() {
        for (int i = 0; i < this.attachmentList.size(); i++) {
            if (i <= 4) {
                ImageView imageView = new ImageView(this);
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(150, 150);
                layoutParams.weight = 1.0f;
                layoutParams.gravity = 3;
                imageView.setLayoutParams(layoutParams);
                try {
                    u.get().load(this.attachmentList.get(i).getFilepath()).fit().placeholder(R.drawable.kapchat_nopreview).into(imageView);
                    imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
                } catch (Exception e) {
                    e.printStackTrace();
                    u.get().load(this.attachmentList.get(i).getFilepath()).placeholder(R.drawable.kapchat_nopreview).fit().into(imageView);
                }
                imageView.setId(i);
                imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        KapchatAttachmentActivity kapchatAttachmentActivity = KapchatAttachmentActivity.this;
                        if (kapchatAttachmentActivity.galleryPager == null || kapchatAttachmentActivity.attachmentList.size() <= view.getId()) {
                            return;
                        }
                        KapchatAttachmentActivity.this.galleryPager.scrollToPosition(view.getId());
                    }
                });
                this.attachmentLayoutTop.addView(imageView);
            } else {
                ImageView imageView2 = new ImageView(this);
                LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(150, 150);
                layoutParams2.weight = 1.0f;
                layoutParams2.gravity = 3;
                imageView2.setLayoutParams(layoutParams2);
                try {
                    u.get().load(this.attachmentList.get(i).getFilepath()).fit().placeholder(R.drawable.kapchat_nopreview).into(imageView2);
                    imageView2.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
                } catch (Exception e2) {
                    e2.printStackTrace();
                    u.get().load(this.attachmentList.get(i).getFilepath()).fit().placeholder(R.drawable.kapchat_nopreview).into(imageView2);
                }
                imageView2.setLeft(10);
                imageView2.setPadding(10, 0, 0, 0);
                imageView2.setId(this.attachmentLayoutTop.getChildCount() + this.attachmentLayoutBottom.getChildCount());
                imageView2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        KapchatAttachmentActivity kapchatAttachmentActivity = KapchatAttachmentActivity.this;
                        if (kapchatAttachmentActivity.galleryPager == null || kapchatAttachmentActivity.attachmentList.size() <= view.getId()) {
                            return;
                        }
                        KapchatAttachmentActivity.this.galleryPager.scrollToPosition(view.getId());
                    }
                });
                this.attachmentLayoutBottom.addView(imageView2);
            }
        }
        if (this.attachmentLayoutTop.getChildCount() < 5) {
            ImageView imageView3 = new ImageView(this);
            LinearLayout.LayoutParams layoutParams3 = new LinearLayout.LayoutParams(150, 150);
            imageView3.setLayoutParams(layoutParams3);
            imageView3.setTag("1");
            layoutParams3.weight = 1.0f;
            layoutParams3.gravity = 3;
            imageView3.setPadding(10, 50, 50, 50);
            imageView3.setImageResource(R.drawable.kapchatplus);
            imageView3.setScaleType(ImageView.ScaleType.FIT_CENTER);
            imageView3.setLeft(10);
            this.attachmentLayoutTop.addView(imageView3);
        } else if (this.attachmentLayoutBottom.getChildCount() < 5) {
            ImageView imageView4 = new ImageView(this);
            LinearLayout.LayoutParams layoutParams4 = new LinearLayout.LayoutParams(150, 150);
            imageView4.setLayoutParams(layoutParams4);
            imageView4.setTag("1");
            layoutParams4.weight = 1.0f;
            layoutParams4.gravity = 3;
            imageView4.setPadding(10, 50, 50, 50);
            imageView4.setImageResource(R.drawable.kapchatplus);
            imageView4.setScaleType(ImageView.ScaleType.FIT_CENTER);
            imageView4.setLeft(10);
            this.attachmentLayoutBottom.addView(imageView4);
        }
        setclicklistener();
    }

    public void selectedpicture(ArrayList<KapchatAttachmentStructure> arrayList) {
        for (int i = 0; i < this.attachmentLayoutTop.getChildCount(); i++) {
            if (this.attachmentLayoutTop.getChildAt(i).getTag() != null) {
                if ("1".equalsIgnoreCase("" + this.attachmentLayoutTop.getChildAt(i).getTag())) {
                    this.attachmentLayoutTop.removeViewAt(i);
                }
            }
        }
        for (int i2 = 0; i2 < this.attachmentLayoutBottom.getChildCount(); i2++) {
            if (this.attachmentLayoutBottom.getChildAt(i2).getTag() != null) {
                if ("1".equalsIgnoreCase("" + this.attachmentLayoutBottom.getChildAt(i2).getTag())) {
                    this.attachmentLayoutBottom.removeViewAt(i2);
                }
            }
        }
        this.attachmentLayoutTop.removeAllViews();
        this.attachmentLayoutBottom.removeAllViews();
        for (int i3 = 0; i3 < arrayList.size(); i3++) {
            String filepath = arrayList.get(i3).getFilepath();
            if (this.attachmentLayoutTop.getChildCount() < 5) {
                ImageView imageView = new ImageView(this);
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(150, 150);
                layoutParams.weight = 1.0f;
                layoutParams.gravity = 3;
                imageView.setLayoutParams(layoutParams);
                try {
                    u.get().load(new File(filepath)).fit().placeholder(R.drawable.kapchat_nopreview).into(imageView);
                    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                } catch (Exception e) {
                    e.printStackTrace();
                    u.get().load(new File(filepath)).fit().placeholder(R.drawable.kapchat_nopreview).into(imageView);
                }
                imageView.setPadding(10, 0, 0, 0);
                imageView.setId(this.attachmentLayoutTop.getChildCount());
                imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        KapchatAttachmentActivity kapchatAttachmentActivity = KapchatAttachmentActivity.this;
                        if (kapchatAttachmentActivity.galleryPager == null || kapchatAttachmentActivity.attachmentList.size() <= view.getId()) {
                            return;
                        }
                        KapchatAttachmentActivity.this.galleryPager.scrollToPosition(view.getId());
                    }
                });
                this.attachmentLayoutTop.addView(imageView);
            } else {
                ImageView imageView2 = new ImageView(this);
                LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(150, 150);
                layoutParams2.weight = 1.0f;
                layoutParams2.gravity = 3;
                imageView2.setLayoutParams(layoutParams2);
                try {
                    u.get().load(new File(filepath)).fit().placeholder(R.drawable.kapchat_nopreview).into(imageView2);
                    imageView2.setScaleType(ImageView.ScaleType.CENTER_CROP);
                } catch (Exception e2) {
                    e2.printStackTrace();
                    u.get().load(new File(filepath)).placeholder(R.drawable.kapchat_nopreview).into(imageView2);
                }
                imageView2.setPadding(10, 0, 0, 0);
                imageView2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        KapchatAttachmentActivity kapchatAttachmentActivity = KapchatAttachmentActivity.this;
                        if (kapchatAttachmentActivity.galleryPager == null || kapchatAttachmentActivity.attachmentList.size() <= view.getId()) {
                            return;
                        }
                        KapchatAttachmentActivity.this.galleryPager.scrollToPosition(view.getId());
                    }
                });
                imageView2.setId(this.attachmentLayoutTop.getChildCount() + this.attachmentLayoutBottom.getChildCount());
                this.attachmentLayoutBottom.addView(imageView2);
            }
        }
        if (this.attachmentLayoutTop.getChildCount() < 5) {
            ImageView imageView3 = new ImageView(this);
            LinearLayout.LayoutParams layoutParams3 = new LinearLayout.LayoutParams(150, 150);
            imageView3.setLayoutParams(layoutParams3);
            imageView3.setTag("1");
            layoutParams3.weight = 1.0f;
            layoutParams3.gravity = 3;
            imageView3.setPadding(10, 50, 50, 50);
            imageView3.setImageResource(R.drawable.kapchatplus);
            imageView3.setScaleType(ImageView.ScaleType.FIT_CENTER);
            this.attachmentLayoutTop.addView(imageView3);
        } else if (this.attachmentLayoutBottom.getChildCount() < 5) {
            ImageView imageView4 = new ImageView(this);
            LinearLayout.LayoutParams layoutParams4 = new LinearLayout.LayoutParams(150, 150);
            imageView4.setLayoutParams(layoutParams4);
            imageView4.setTag("1");
            layoutParams4.weight = 1.0f;
            layoutParams4.gravity = 3;
            imageView4.setImageResource(R.drawable.kapchatplus);
            imageView4.setPadding(10, 50, 50, 50);
            imageView4.setScaleType(ImageView.ScaleType.FIT_CENTER);
            this.attachmentLayoutBottom.addView(imageView4);
        }
        for (int i4 = 0; i4 < arrayList.size(); i4++) {
            SharedPreferences.Editor edit = getSharedPreferences("kapchatpreference", 0).edit();
            edit.putString("image" + i4, arrayList.get(i4).getBody());
            edit.apply();
        }
        setclicklistener();
    }

    public void setadapter() {
        KapchatGallerylistpager kapchatGallerylistpager = new KapchatGallerylistpager(this, this.attachmentList);
        this.mAapter = kapchatGallerylistpager;
        this.galleryPager.setAdapter(kapchatGallerylistpager);
        setclicklistener();
    }

    public void setclicklistener() {
        for (int i = 0; i < this.attachmentLayoutTop.getChildCount(); i++) {
            if (this.attachmentLayoutTop.getChildAt(i).getTag() != null) {
                if ("1".equalsIgnoreCase("" + this.attachmentLayoutTop.getChildAt(i).getTag())) {
                    this.attachmentLayoutTop.getChildAt(i).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            KapchatAttachmentActivity kapchatAttachmentActivity = KapchatAttachmentActivity.this;
                            if (kapchatAttachmentActivity.verifyStoragePermissions(kapchatAttachmentActivity, 1)) {
                                Intent intent = new Intent("android.intent.action.PICK");
                                intent.setType("image/*");
                                KapchatAttachmentActivity.this.startActivityForResult(intent, 15);
                            }
                        }
                    });
                }
            }
        }
        for (int i2 = 0; i2 < this.attachmentLayoutBottom.getChildCount(); i2++) {
            if (this.attachmentLayoutBottom.getChildAt(i2).getTag() != null) {
                if ("1".equalsIgnoreCase("" + this.attachmentLayoutBottom.getChildAt(i2).getTag())) {
                    this.attachmentLayoutBottom.getChildAt(i2).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            KapchatAttachmentActivity kapchatAttachmentActivity = KapchatAttachmentActivity.this;
                            if (kapchatAttachmentActivity.verifyStoragePermissions(kapchatAttachmentActivity, 2)) {
                                Intent intent = new Intent("android.intent.action.PICK");
                                intent.setType("image/*");
                                KapchatAttachmentActivity.this.startActivityForResult(intent, 15);
                            }
                        }
                    });
                }
            }
        }
    }

    public void setupactionbar() {
        setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
        ActionBar supportActionBar = getSupportActionBar();
        this.actionBar = supportActionBar;
        supportActionBar.setElevation(0.0f);
        this.actionBar.setDisplayHomeAsUpEnabled(true);
        this.actionBar.setDisplayShowHomeEnabled(true);
        this.actionBar.setDisplayUseLogoEnabled(true);
    }

    public void showSnackbar(String str) {
        Snackbar.make(this.attachmentPrimaryView, str, -1).getView();
    }

    public void textcaption(int i, String str) {
        for (int i2 = 0; i2 < this.attachmentList.size(); i2++) {
            if (i == i2) {
                this.attachmentList.get(i2).setBody(str);
                SharedPreferences.Editor edit = getSharedPreferences("kapchatpreference", 0).edit();
                edit.putString("image" + i2, str);
                edit.apply();
                return;
            }
        }
    }

    @Override
    public void update(Boolean bool) {
        if (this.progressDialog.isShowing()) {
            this.progressDialog.dismiss();
        }
        if (this.attachmentList.size() > 0) {
            setResult(-1);
        } else {
            setResult(0);
        }
        finish();
    }

    public boolean verifyStoragePermissions(Activity activity, int i) {
        if (androidx.core.content.a.checkSelfPermission(activity, "android.permission.WRITE_EXTERNAL_STORAGE") == 0) {
            return true;
        }
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        bundle.putString("result", "Permission Failed");
        intent.putExtras(bundle);
        setResult(-1, intent);
        finish();
        return false;
    }
}