正在查看: bbinstant v6.24.0 应用的 KapchatScreenActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: bbinstant v6.24.0 应用的 KapchatScreenActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.adjetter.kapchatsdk.activity;
import android.app.Activity;
import android.app.NotificationManager;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentUris;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.IBinder;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
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.app.c;
import androidx.appcompat.view.ActionMode;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.NotificationCompat;
import androidx.core.app.b;
import androidx.core.content.FileProvider;
import androidx.exifinterface.media.a;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.adjetter.kapchatsdk.KapchatConnection;
import com.adjetter.kapchatsdk.KapchatHelper;
import com.adjetter.kapchatsdk.KapchatListAdapter;
import com.adjetter.kapchatsdk.KapchatMessageInsertion;
import com.adjetter.kapchatsdk.KapchatMessageList;
import com.adjetter.kapchatsdk.KapchatMultipleDelete;
import com.adjetter.kapchatsdk.KapchatPaginationFromServer;
import com.adjetter.kapchatsdk.KapchatReadMessages;
import com.adjetter.kapchatsdk.KapchatSendMessageStructure;
import com.adjetter.kapchatsdk.KapchatService;
import com.adjetter.kapchatsdk.KapchatUploadService;
import com.adjetter.kapchatsdk.R;
import com.adjetter.kapchatsdk.animation.KapchatImageUtils;
import com.adjetter.kapchatsdk.attachments.KapchatAttachmentStructure;
import com.adjetter.kapchatsdk.helper.KapchatMessageListItemClickListener;
import com.adjetter.kapchatsdk.helper.KapchatUpdateConversationId;
import com.adjetter.kapchatsdk.interfaces.IkapchatMessages;
import com.adjetter.kapchatsdk.interfaces.MessageListItemClickListner;
import com.adjetter.kapchatsdk.service.Kapchatdownloadservice;
import com.adjetter.kapchatsdk.structure.KapchatQANotification;
import com.adjetter.kapchatsdk.structure.KapchatUpdateAttachments;
import com.adjetter.kapchatsdk.structure.MarkableElement;
import com.adjetter.kapchatsdk.structure.NoCarbon;
import com.adjetter.kapchatsdk.structure.NoCopy;
import com.adjetter.kapchatsdk.structure.NoPermanantStoreElement;
import com.adjetter.kapchatsdk.timer.IKapchatTimer;
import com.adjetter.kapchatsdk.timer.ISingletonTimer;
import com.adjetter.kapchatsdk.timer.KapchatTimer;
import com.amazonaws.mobileconnectors.s3.transferutility.TransferTable;
import com.google.android.material.snackbar.Snackbar;
import com.google.gson.Gson;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import org.jivesoftware.smack.chat.Chat;
import org.jivesoftware.smack.chat.ChatManager;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smackx.chatstates.ChatState;
import org.jivesoftware.smackx.chatstates.ChatStateListener;
import org.jxmpp.jid.impl.JidCreate;
public class KapchatScreenActivity extends AppCompatActivity implements IkapchatMessages, IKapchatTimer, ISingletonTimer {
private static String[] PERMISSIONS_LIST = {"android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE", "android.permission-group.STORAGE"};
public static boolean chatScreenExited = false;
public static String savedImage = "";
private String[] PERMISSIONS_CAMERA;
private String[] PERMISSIONS_STORAGE;
private LinearLayout answerLayout;
private TextView clearPopup;
public String downloadConversationId;
private ServiceConnection downloadServiceConnection;
boolean hasCheckedItems;
private LinearLayout interactionLayout;
Boolean isDownloadBind;
boolean isPaginationFromServer;
private boolean isRefresh;
private boolean isSendTemplateMessage;
Boolean isUploadBind;
private KapchatTimer kapchatTimer;
private ActionMode mActionMode;
NotificationReceiver notificationReceiver;
private TextView notificationTimerText;
OnlineStatusReceiver onlineStatusReceiver;
private TextView popupMessage;
private RelativeLayout primaryView;
ProgressDialog progressDialog;
ArrayList<String> selectedMessageList;
TextView showOfflineText;
private String templateMessageGiven;
private TextView timerTextView;
private Toolbar toolbar;
private ServiceConnection uploadServiceConnection;
private ActionBar actionBar = null;
private RecyclerView messageListView = null;
private LinearLayoutManager layoutManager = null;
private TextView timeLayout = null;
private ArrayList<KapchatMessageList> messageLists = new ArrayList<>();
private KapchatListAdapter messageAdapter = null;
private EditText typeMessage = null;
IkapchatMessages ikapchatMessages = null;
private Chat newChat = null;
private ImageView sendButton = null;
private Boolean isPagination = Boolean.TRUE;
private int nPageLimit = 0;
BroadcastReceiver updateReceiver = null;
private RelativeLayout popupNotification = null;
ArrayList<KapchatAttachmentStructure> attachmentList = new ArrayList<>();
KapchatUploadService.Localbinder mBind = null;
Kapchatdownloadservice.DownloadGroupbinder mDownloadBind = null;
public class NotificationReceiver extends BroadcastReceiver {
public NotificationReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null && intent.getExtras() != null && intent.getExtras().getString("isShowNotification") != null && intent.getExtras().getString("isShowNotification").equalsIgnoreCase("yes")) {
if (intent.getExtras() == null || intent.getExtras().getString(NotificationCompat.CATEGORY_MESSAGE) == null || intent.getExtras().getString(NotificationCompat.CATEGORY_MESSAGE).equalsIgnoreCase("")) {
return;
}
KapchatScreenActivity.this.showActivityPopUpNotification("" + intent.getExtras().getString(NotificationCompat.CATEGORY_MESSAGE));
return;
}
if (intent != null && intent.getExtras() != null && intent.getExtras().getString("isTriggerNotification") != null && intent.getExtras().getString("isTriggerNotification").equalsIgnoreCase("yes")) {
KapchatScreenActivity.this.showTimerNotificatication();
return;
}
if (intent == null || intent.getExtras() == null || intent.getExtras().getString("isTriggerNotification") == null || !intent.getExtras().getString("isTriggerNotification").equalsIgnoreCase("no")) {
KapchatScreenActivity.this.popupNotification.setVisibility(8);
} else {
KapchatScreenActivity.this.kapchatTimer.cancel();
KapchatScreenActivity.this.interactionLayout.setVisibility(8);
}
}
}
public class OnlineStatusReceiver extends BroadcastReceiver {
public OnlineStatusReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
String string = KapchatScreenActivity.this.getSharedPreferences("kapchatpreference", 0).getString("screenPresent", "");
if (string == null || !string.equalsIgnoreCase("yes")) {
return;
}
KapchatScreenActivity.this.restartService(context);
}
}
public class UpdateChatListener extends BroadcastReceiver {
public UpdateChatListener() {
}
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null && intent.getExtras() != null && intent.getExtras().getString("chatlistener") != null && intent.getExtras().getString("chatlistener").equalsIgnoreCase("yes")) {
KapchatScreenActivity.this.chatlistener();
return;
}
if (intent != null && intent.getExtras() != null && intent.getExtras().getString("updateStatus") != null && intent.getExtras().getString("updateStatus").equalsIgnoreCase("yes")) {
ArrayList arrayList = (ArrayList) intent.getSerializableExtra("updateList");
if (arrayList == null || arrayList.size() <= 0 || KapchatScreenActivity.this.messageLists == null || KapchatScreenActivity.this.messageLists.size() <= 0) {
return;
}
for (int i = 0; i < arrayList.size(); i++) {
for (int i2 = 0; i2 < KapchatScreenActivity.this.messageLists.size(); i2++) {
if (((KapchatMessageList) arrayList.get(i)).getConversationId().equalsIgnoreCase(((KapchatMessageList) KapchatScreenActivity.this.messageLists.get(i2)).getConversationId())) {
((KapchatMessageList) KapchatScreenActivity.this.messageLists.get(i2)).setMessageStatus(((KapchatMessageList) arrayList.get(i)).getMessageStatus());
}
}
}
KapchatScreenActivity.this.messageAdapter.notifyDataSetChanged();
return;
}
if (intent != null && intent.getExtras() != null && intent.getExtras().getString("downloadStatus") != null && intent.getExtras().getString("downloadStatus").equalsIgnoreCase("yes")) {
ArrayList arrayList2 = (ArrayList) intent.getSerializableExtra("downloadList");
if (arrayList2 == null || arrayList2.size() <= 0 || KapchatScreenActivity.this.messageLists == null || KapchatScreenActivity.this.messageLists.size() <= 0) {
return;
}
for (int i3 = 0; i3 < arrayList2.size(); i3++) {
for (int i4 = 0; i4 < KapchatScreenActivity.this.messageLists.size(); i4++) {
if (((KapchatMessageList) arrayList2.get(i3)).getConversationId().equalsIgnoreCase(((KapchatMessageList) KapchatScreenActivity.this.messageLists.get(i4)).getConversationId())) {
((KapchatMessageList) KapchatScreenActivity.this.messageLists.get(i4)).setMessageStatus(((KapchatMessageList) arrayList2.get(i3)).getMessageStatus());
((KapchatMessageList) KapchatScreenActivity.this.messageLists.get(i4)).setMessageStatus(((KapchatMessageList) arrayList2.get(i3)).getMessageStatus());
((KapchatMessageList) KapchatScreenActivity.this.messageLists.get(i4)).setMimeurl(((KapchatMessageList) arrayList2.get(i3)).getMimeurl());
((KapchatMessageList) KapchatScreenActivity.this.messageLists.get(i4)).setDownload(((KapchatMessageList) arrayList2.get(i3)).getDownload());
((KapchatMessageList) KapchatScreenActivity.this.messageLists.get(i4)).setDownloadPath(((KapchatMessageList) arrayList2.get(i3)).getDownloadPath());
((KapchatMessageList) KapchatScreenActivity.this.messageLists.get(i4)).setBlob(((KapchatMessageList) arrayList2.get(i3)).getBlob());
}
}
}
KapchatScreenActivity.this.messageAdapter.notifyDataSetChanged();
return;
}
if (intent == null || intent.getExtras() == null || intent.getExtras().getString("uploadStatus") == null || !intent.getExtras().getString("uploadStatus").equalsIgnoreCase("yes")) {
KapchatScreenActivity.this.checkTimerVisibility();
KapchatScreenActivity kapchatScreenActivity = KapchatScreenActivity.this;
if (kapchatScreenActivity.hasCheckedItems) {
return;
}
kapchatScreenActivity.nPageLimit = 0;
KapchatScreenActivity.this.isPagination = Boolean.TRUE;
KapchatScreenActivity.this.readMessageList(0);
return;
}
ArrayList arrayList3 = (ArrayList) intent.getSerializableExtra("uploadList");
if (arrayList3 == null || arrayList3.size() <= 0 || KapchatScreenActivity.this.messageLists == null || KapchatScreenActivity.this.messageLists.size() <= 0) {
return;
}
for (int i5 = 0; i5 < arrayList3.size(); i5++) {
for (int i6 = 0; i6 < KapchatScreenActivity.this.messageLists.size(); i6++) {
if (((KapchatUpdateAttachments) arrayList3.get(i5)).getConversationid().equalsIgnoreCase(((KapchatMessageList) KapchatScreenActivity.this.messageLists.get(i6)).getConversationId())) {
((KapchatMessageList) KapchatScreenActivity.this.messageLists.get(i6)).setMimeurl(((KapchatUpdateAttachments) arrayList3.get(i5)).getMimeurl());
((KapchatMessageList) KapchatScreenActivity.this.messageLists.get(i6)).setMessageStatus(((KapchatUpdateAttachments) arrayList3.get(i5)).getMessagestatus());
}
}
}
KapchatScreenActivity.this.messageAdapter.notifyDataSetChanged();
}
}
public KapchatScreenActivity() {
Boolean bool = Boolean.FALSE;
this.isUploadBind = bool;
this.isDownloadBind = bool;
this.showOfflineText = null;
this.onlineStatusReceiver = null;
this.notificationReceiver = null;
this.toolbar = null;
this.selectedMessageList = new ArrayList<>();
this.hasCheckedItems = false;
this.isPaginationFromServer = false;
this.progressDialog = null;
this.PERMISSIONS_STORAGE = new String[]{"android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE", "android.permission-group.STORAGE"};
this.PERMISSIONS_CAMERA = new String[]{"android.permission.CAMERA"};
this.primaryView = null;
this.isRefresh = true;
this.isSendTemplateMessage = false;
this.templateMessageGiven = "";
this.popupMessage = null;
this.clearPopup = null;
this.interactionLayout = null;
this.notificationTimerText = null;
this.kapchatTimer = null;
this.timerTextView = null;
this.answerLayout = null;
this.uploadServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
KapchatUploadService.Localbinder localbinder = (KapchatUploadService.Localbinder) iBinder;
KapchatScreenActivity.this.mBind = localbinder;
if (localbinder != null) {
localbinder.getService().readAllMessages();
}
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
}
};
this.downloadServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
Kapchatdownloadservice.DownloadGroupbinder downloadGroupbinder = (Kapchatdownloadservice.DownloadGroupbinder) iBinder;
KapchatScreenActivity.this.mDownloadBind = downloadGroupbinder;
if (downloadGroupbinder != null) {
downloadGroupbinder.getService().downloadata(KapchatScreenActivity.this.downloadConversationId);
}
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
}
};
this.downloadConversationId = "0";
}
private void answerTimerNotification(String str) {
KapchatTimer kapchatTimer = this.kapchatTimer;
if (kapchatTimer != null) {
kapchatTimer.cancel();
}
this.interactionLayout.setVisibility(8);
KapchatQANotification kapchatQANotification = (KapchatQANotification) new Gson().fromJson(getSharedPreferences("kapchatpreference", 0).getString(KapchatHelper.QUESTION_ANSWER_JSON, "").toString(), KapchatQANotification.class);
if (kapchatQANotification != null) {
ArrayList arrayList = new ArrayList();
arrayList.clear();
KapchatMessageList kapchatMessageList = new KapchatMessageList();
kapchatMessageList.setSendDate("" + new Date().getTime());
kapchatMessageList.setFromJid("" + kapchatQANotification.getFromJid());
kapchatMessageList.setToJid(kapchatQANotification.getToJid());
kapchatMessageList.setMessageType(a.GPS_MEASUREMENT_2D);
kapchatMessageList.setMessage(str);
kapchatMessageList.setDownload("0");
kapchatMessageList.setDownloadPath("0");
kapchatMessageList.setMime("0");
kapchatMessageList.setMimeurl("0");
kapchatQANotification.setFromJid(kapchatMessageList.getFromJid());
kapchatQANotification.setToJid(kapchatMessageList.getToJid());
kapchatQANotification.setSenderName("" + getSharedPreferences("kapchatpreference", 0).getString("contactName", ""));
kapchatMessageList.setBlob(new byte[]{0});
XMPPTCPConnection xMPPTCPConnection = KapchatConnection.mConnection;
if (xMPPTCPConnection == null || !xMPPTCPConnection.isAuthenticated()) {
kapchatMessageList.setMessageStatus(a.GPS_MEASUREMENT_2D);
} else {
kapchatMessageList.setMessageStatus("1");
}
try {
Message message = new Message();
KapchatSendMessageStructure kapchatSendMessageStructure = new KapchatSendMessageStructure();
kapchatSendMessageStructure.enquiryId = "0";
kapchatSendMessageStructure.fromJid = "" + getSharedPreferences("kapchatpreference", 0).getString("userName", "");
kapchatSendMessageStructure.leadId = Integer.parseInt(getSharedPreferences("kapchatpreference", 0).getString("leadId", "0"));
kapchatSendMessageStructure.message = "" + str;
kapchatSendMessageStructure.messageId = null;
kapchatSendMessageStructure.receiverName = null;
kapchatSendMessageStructure.sentDate = System.currentTimeMillis();
kapchatSendMessageStructure.senderName = "" + getSharedPreferences("kapchatpreference", 0).getString("contactName", "");
kapchatSendMessageStructure.supportId = "" + getSharedPreferences("kapchatpreference", 0).getString("supportId", "");
kapchatSendMessageStructure.toJid = null;
kapchatSendMessageStructure.fromResource = getSharedPreferences("kapchatpreference", 0).getString("kapchatresource", "");
if (getSharedPreferences("kapchatpreference", 0).getString("guestsession", "").equalsIgnoreCase("true")) {
kapchatSendMessageStructure.taskId = Integer.parseInt(getSharedPreferences("kapchatpreference", 0).getString("taskId", ""));
kapchatSendMessageStructure.ticketId = getSharedPreferences("kapchatpreference", 0).getString("ticketId", "");
}
kapchatQANotification.setAnswer(str);
kapchatQANotification.isAnswer = true;
String str2 = "{\"key\":\"" + KapchatHelper.supportmessagekey + "\",\"supportChatTrigger\":" + new Gson().toJson(kapchatQANotification) + ",\"supportChatMessage\":" + new Gson().toJson(kapchatSendMessageStructure) + ",\"type\":\"" + KapchatHelper.TRIGGER_TYPE + "\"}";
StringBuilder sb = new StringBuilder();
sb.append("");
sb.append(str2);
message.setBody("" + str2);
message.setType(Message.Type.chat);
String str3 = message.getStanzaId() + (new Random().nextInt(900000) + 100000);
message.setStanzaId(str3);
MarkableElement markableElement = new MarkableElement();
markableElement.setId(str3);
message.addExtension(markableElement);
kapchatMessageList.setStanzaId(message.getStanzaId());
XMPPTCPConnection xMPPTCPConnection2 = KapchatConnection.mConnection;
if (xMPPTCPConnection2 != null && xMPPTCPConnection2.isConnected() && KapchatConnection.mConnection.isAuthenticated()) {
this.newChat.sendMessage(message);
SharedPreferences.Editor edit = getSharedPreferences("kapchatpreference", 0).edit();
edit.putString("lastLogout", "" + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()));
edit.apply();
} else {
kapchatMessageList.setMessageStatus(a.GPS_MEASUREMENT_2D);
}
} catch (Exception e) {
kapchatMessageList.setMessageStatus(a.GPS_MEASUREMENT_2D);
e.printStackTrace();
}
arrayList.add(kapchatMessageList);
new KapchatMessageInsertion(getApplicationContext(), null, Boolean.FALSE).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, arrayList);
SharedPreferences.Editor edit2 = getSharedPreferences("kapchatpreference", 0).edit();
edit2.putString(KapchatHelper.QUESTION_ANSWER_JSON, "");
edit2.apply();
}
}
private void checkPendingTimerNotification() {
String string = getSharedPreferences("kapchatpreference", 0).getString(KapchatHelper.QUESTION_ANSWER_JSON, "");
if (string.equalsIgnoreCase("")) {
this.interactionLayout.setVisibility(8);
return;
}
KapchatQANotification kapchatQANotification = (KapchatQANotification) new Gson().fromJson(string, KapchatQANotification.class);
StringBuilder sb = new StringBuilder();
sb.append("time 1: ");
sb.append(System.currentTimeMillis() - kapchatQANotification.getSentDate().longValue());
StringBuilder sb2 = new StringBuilder();
sb2.append("time 2: ");
sb2.append(kapchatQANotification.getExpiration().longValue() - 5000);
if (System.currentTimeMillis() - kapchatQANotification.getSentDate().longValue() < kapchatQANotification.getExpiration().longValue() - 5000) {
this.interactionLayout.setVisibility(0);
showTimerNotificatication();
} else {
this.interactionLayout.setVisibility(8);
insertQuestion(string, false, "");
}
}
public static String getDataColumn(Context context, Uri uri, String str, String[] strArr) {
Cursor cursor = null;
try {
Cursor query = context.getContentResolver().query(uri, new String[]{"_data"}, str, strArr, null);
if (query != null) {
try {
if (query.moveToFirst()) {
String string = query.getString(query.getColumnIndexOrThrow("_data"));
query.close();
return string;
}
} catch (Throwable th) {
th = th;
cursor = query;
if (cursor != null) {
cursor.close();
}
throw th;
}
}
if (query != null) {
query.close();
}
return null;
} catch (Throwable th2) {
th = th2;
}
}
public static String getRealPathFromURI(Context context, Uri uri) {
Uri uri2 = null;
if (DocumentsContract.isDocumentUri(context, uri)) {
if (isExternalStorageDocument(uri)) {
String[] split = DocumentsContract.getDocumentId(uri).split(":");
if ("primary".equalsIgnoreCase(split[0])) {
return Environment.getExternalStorageDirectory() + "/" + split[1];
}
} else {
if (isDownloadsDocument(uri)) {
return getDataColumn(context, ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(DocumentsContract.getDocumentId(uri)).longValue()), null, null);
}
if (isMediaDocument(uri)) {
String[] split2 = DocumentsContract.getDocumentId(uri).split(":");
String str = split2[0];
if ("image".equals(str)) {
uri2 = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(str)) {
uri2 = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if ("audio".equals(str)) {
uri2 = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
return getDataColumn(context, uri2, "_id=?", new String[]{split2[1]});
}
}
} else {
if ("content".equalsIgnoreCase(uri.getScheme())) {
return isGooglePhotosUri(uri) ? uri.getLastPathSegment() : getDataColumn(context, uri, null, null);
}
if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}
}
return null;
}
private boolean hideKeyboard() {
((InputMethodManager) getSystemService("input_method")).hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 2);
return true;
}
public static boolean isDownloadsDocument(Uri uri) {
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}
public static boolean isExternalStorageDocument(Uri uri) {
return "com.android.externalstorage.documents".equals(uri.getAuthority());
}
public static boolean isGooglePhotosUri(Uri uri) {
return "com.google.android.apps.photos.content".equals(uri.getAuthority());
}
public static boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri.getAuthority());
}
public void onListItemSelect(int i) {
ActionMode actionMode;
updateSelected(i);
boolean z = this.selectedMessageList.size() > 0;
this.hasCheckedItems = z;
if (z && this.mActionMode == null) {
if (this.toolbar != null) {
this.mActionMode = startSupportActionMode(new ActionMode.a() {
@Override
public boolean onActionItemClicked(ActionMode actionMode2, MenuItem menuItem) {
if (menuItem.getItemId() != R.id.delete) {
return true;
}
KapchatScreenActivity.this.deleteRows();
return true;
}
@Override
public boolean onCreateActionMode(ActionMode actionMode2, Menu menu) {
KapchatScreenActivity.this.typeMessage.setEnabled(false);
KapchatScreenActivity.this.typeMessage.setClickable(false);
actionMode2.getMenuInflater().inflate(R.menu.kapchatactionmode, menu);
return true;
}
@Override
public void onDestroyActionMode(ActionMode actionMode2) {
KapchatScreenActivity.this.unselectAllmessages();
KapchatScreenActivity.this.setNullToActionMode();
}
@Override
public boolean onPrepareActionMode(ActionMode actionMode2, Menu menu) {
menu.findItem(R.id.delete).setShowAsAction(2);
return true;
}
});
}
} else if (!z && (actionMode = this.mActionMode) != null) {
actionMode.finish();
}
ActionMode actionMode2 = this.mActionMode;
if (actionMode2 != null) {
actionMode2.setTitle(this.selectedMessageList.size() + " selected");
}
}
public void showTimerNotificatication() {
View inflate;
KapchatTimer kapchatTimer = this.kapchatTimer;
if (kapchatTimer != null) {
kapchatTimer.cancel();
this.interactionLayout.setVisibility(8);
}
String string = getSharedPreferences("kapchatpreference", 0).getString(KapchatHelper.QUESTION_ANSWER_JSON, "");
if (string.equalsIgnoreCase("")) {
return;
}
KapchatQANotification kapchatQANotification = (KapchatQANotification) new Gson().fromJson(string, KapchatQANotification.class);
this.timerTextView.setText(kapchatQANotification.getQuestion());
this.answerLayout.removeAllViews();
if (kapchatQANotification.getAnswerList() != null && kapchatQANotification.getAnswerList().length > 0) {
for (final String str : kapchatQANotification.getAnswerList()) {
if (str.toLowerCase().trim().equalsIgnoreCase("yes") || str.toLowerCase().trim().equalsIgnoreCase("ok") || str.toLowerCase().trim().equalsIgnoreCase("done")) {
inflate = LayoutInflater.from(this).inflate(R.layout.kapchat_item_answer_layout_positive, (ViewGroup) null, false);
TextView textView = (TextView) inflate.findViewById(R.id.positive);
textView.setText(str);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
KapchatScreenActivity kapchatScreenActivity = KapchatScreenActivity.this;
kapchatScreenActivity.insertQuestion(kapchatScreenActivity.getSharedPreferences("kapchatpreference", 0).getString(KapchatHelper.QUESTION_ANSWER_JSON, ""), true, str);
}
});
} else {
inflate = LayoutInflater.from(this).inflate(R.layout.kapchat_itme_answer_layout_negative, (ViewGroup) null, false);
TextView textView2 = (TextView) inflate.findViewById(R.id.negative);
textView2.setText(str);
textView2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
KapchatScreenActivity kapchatScreenActivity = KapchatScreenActivity.this;
kapchatScreenActivity.insertQuestion(kapchatScreenActivity.getSharedPreferences("kapchatpreference", 0).getString(KapchatHelper.QUESTION_ANSWER_JSON, ""), true, str);
}
});
}
this.answerLayout.addView(inflate);
}
}
if (System.currentTimeMillis() - kapchatQANotification.getSentDate().longValue() >= kapchatQANotification.getExpiration().longValue() - 5000) {
this.interactionLayout.setVisibility(8);
insertQuestion(string, false, "");
} else {
KapchatTimer kapchatTimer2 = new KapchatTimer(kapchatQANotification.getExpiration().longValue() - (System.currentTimeMillis() - kapchatQANotification.getSentDate().longValue()), 1000L, this);
this.kapchatTimer = kapchatTimer2;
kapchatTimer2.start();
this.interactionLayout.setVisibility(0);
}
}
public void callpagination(String str) {
new KapchatReadMessages(this, this, this.nPageLimit).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
}
public void chatlistener() {
XMPPTCPConnection xMPPTCPConnection = KapchatConnection.mConnection;
if (xMPPTCPConnection != null && xMPPTCPConnection.isConnected()) {
try {
this.newChat = ChatManager.getInstanceFor(KapchatConnection.mConnection).createChat(JidCreate.entityBareFrom(getSharedPreferences("kapchatpreference", 0).getString("supportId", "")), new ChatStateListener() {
public void processMessage(Chat chat, Message message) {
try {
KapchatScreenActivity.this.newChat.sendMessage(message);
} catch (Exception e) {
System.out.println("######### crzsh here2 : " + e.getMessage());
}
}
public void stateChanged(Chat chat, ChatState chatState, Message message) {
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
if (this.isSendTemplateMessage) {
sendTemplateMessage(this.templateMessageGiven);
}
}
public void checkCameraPermission() {
if (getSharedPreferences("kapchatpreference", 0).getString("supportId", "").equalsIgnoreCase("")) {
Toast.makeText(this, "Chat Initialise Failed", 0).show();
} else if (verifyCameraPermission(this, 1) && verifyStoragePermissions(this, 1)) {
startCameraActivity();
}
}
public void checkGalleryPermission() {
if (getSharedPreferences("kapchatpreference", 0).getString("supportId", "").equalsIgnoreCase("")) {
Toast.makeText(this, "Chat Initialise Failed", 0).show();
} else if (verifyStoragePermissions(this, 2)) {
startGalleryActivity();
}
}
public void checkTimerVisibility() {
KapchatTimer kapchatTimer = this.kapchatTimer;
if (kapchatTimer != null) {
kapchatTimer.cancel();
this.interactionLayout.setVisibility(8);
insertQuestion(getSharedPreferences("kapchatpreference", 0).getString(KapchatHelper.QUESTION_ANSWER_JSON, ""), false, "");
}
}
@Override
public void clearMessages(Boolean bool) {
if (bool.booleanValue()) {
this.isPagination = Boolean.FALSE;
this.nPageLimit = 0;
this.messageLists.clear();
this.messageListView.setAdapter(this.messageAdapter);
}
}
@Override
public void clearMultiple(Boolean bool, ArrayList<String> arrayList) {
ArrayList<KapchatMessageList> arrayList2;
if (!bool.booleanValue() || (arrayList2 = this.messageLists) == null || arrayList2.size() <= 0) {
return;
}
int i = 0;
for (int size = this.messageLists.size() - 1; size >= 0; size--) {
int i2 = 0;
while (true) {
if (i2 >= arrayList.size()) {
break;
}
if (this.messageLists.get(size).getConversationId().equalsIgnoreCase(arrayList.get(i2))) {
this.messageLists.remove(size);
i = size;
break;
}
i2++;
}
}
this.messageListView.setAdapter(this.messageAdapter);
if (i <= this.messageLists.size()) {
this.messageListView.scrollToPosition(i - 1);
} else {
this.messageListView.scrollToPosition(this.layoutManager.findFirstVisibleItemPosition());
}
}
public void deleteRows() {
new KapchatMultipleDelete(this, this, this.selectedMessageList).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
this.selectedMessageList.clear();
this.mActionMode.finish();
}
public void doEndChat() {
if (getSharedPreferences("kapchatpreference", 0).getString("supportId", "").equalsIgnoreCase("")) {
Toast.makeText(this, "Chat Initialise Failed", 0).show();
return;
}
ArrayList arrayList = new ArrayList();
arrayList.clear();
KapchatMessageList kapchatMessageList = new KapchatMessageList();
kapchatMessageList.setSendDate("" + new Date().getTime());
kapchatMessageList.setFromJid(getSharedPreferences("kapchatpreference", 0).getString("userName", "") + KapchatHelper.serviceName);
kapchatMessageList.setToJid("" + getSharedPreferences("kapchatpreference", 0).getString("supportId", ""));
kapchatMessageList.setMessage("you have terminated the chat session.");
kapchatMessageList.setMessageType(a.GPS_MEASUREMENT_3D);
kapchatMessageList.setMime("0");
kapchatMessageList.setMimeurl("0");
kapchatMessageList.setDownload("0");
kapchatMessageList.setDownloadPath("0");
kapchatMessageList.setBlob(new byte[]{0});
XMPPTCPConnection xMPPTCPConnection = KapchatConnection.mConnection;
if (xMPPTCPConnection == null || !xMPPTCPConnection.isAuthenticated()) {
kapchatMessageList.setMessageStatus(a.GPS_MEASUREMENT_2D);
} else {
kapchatMessageList.setMessageStatus("1");
}
try {
Message message = new Message();
KapchatSendMessageStructure kapchatSendMessageStructure = new KapchatSendMessageStructure();
kapchatSendMessageStructure.enquiryId = "0";
kapchatSendMessageStructure.fromJid = "" + getSharedPreferences("kapchatpreference", 0).getString("userName", "");
kapchatSendMessageStructure.leadId = Integer.parseInt(getSharedPreferences("kapchatpreference", 0).getString("leadId", "0"));
kapchatSendMessageStructure.message = "" + getSharedPreferences("kapchatpreference", 0).getString("contactName", "") + " has terminated the chat session. Please do the needful and close the chat session.";
kapchatSendMessageStructure.messageId = null;
kapchatSendMessageStructure.receiverName = null;
kapchatSendMessageStructure.sentDate = System.currentTimeMillis();
kapchatSendMessageStructure.senderName = "" + getSharedPreferences("kapchatpreference", 0).getString("contactName", "");
kapchatSendMessageStructure.supportId = "" + getSharedPreferences("kapchatpreference", 0).getString("supportId", "");
kapchatSendMessageStructure.toJid = null;
kapchatSendMessageStructure.fromResource = getSharedPreferences("kapchatpreference", 0).getString("kapchatresource", "");
if (getSharedPreferences("kapchatpreference", 0).getString("guestsession", "").equalsIgnoreCase("true")) {
kapchatSendMessageStructure.taskId = Integer.parseInt(getSharedPreferences("kapchatpreference", 0).getString("taskId", ""));
kapchatSendMessageStructure.ticketId = getSharedPreferences("kapchatpreference", 0).getString("ticketId", "");
}
message.setBody("" + ("{\"key\":\"" + KapchatHelper.supportmessagekey + "\",\"supportChatMessage\":" + new Gson().toJson(kapchatSendMessageStructure) + ",\"type\":\"" + KapchatHelper.supporttype + "\"}"));
message.setType(Message.Type.chat);
String str = message.getStanzaId() + (new Random().nextInt(900000) + 100000);
message.setStanzaId(str);
MarkableElement markableElement = new MarkableElement();
markableElement.setId(str);
message.addExtension(markableElement);
kapchatMessageList.setStanzaId(message.getStanzaId());
message.addExtension(new NoPermanantStoreElement());
message.addExtension(new NoCopy());
message.addExtension(new NoCarbon());
XMPPTCPConnection xMPPTCPConnection2 = KapchatConnection.mConnection;
if (xMPPTCPConnection2 != null && xMPPTCPConnection2.isConnected() && KapchatConnection.mConnection.isAuthenticated()) {
this.newChat.sendMessage(message);
SharedPreferences.Editor edit = getSharedPreferences("kapchatpreference", 0).edit();
edit.putString("lastLogout", "" + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()));
edit.apply();
} else {
kapchatMessageList.setMessageStatus(a.GPS_MEASUREMENT_2D);
}
} catch (Exception e) {
kapchatMessageList.setMessageStatus(a.GPS_MEASUREMENT_2D);
e.printStackTrace();
}
arrayList.add(kapchatMessageList);
new KapchatMessageInsertion(this, null, Boolean.FALSE).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, arrayList);
}
public void downloadAttach(final String str, String str2) {
ArrayList arrayList = new ArrayList();
KapchatMessageList kapchatMessageList = new KapchatMessageList();
kapchatMessageList.setConversationId(str);
kapchatMessageList.setMessageStatus("11");
kapchatMessageList.setMimeurl(str2);
arrayList.add(kapchatMessageList);
new KapchatUpdateConversationId(this, null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, arrayList);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
KapchatScreenActivity kapchatScreenActivity = KapchatScreenActivity.this;
kapchatScreenActivity.downloadConversationId = str;
if (kapchatScreenActivity.mDownloadBind == null || !kapchatScreenActivity.isDownloadBind.booleanValue()) {
Intent intent = new Intent(KapchatScreenActivity.this, (Class<?>) Kapchatdownloadservice.class);
KapchatScreenActivity kapchatScreenActivity2 = KapchatScreenActivity.this;
kapchatScreenActivity2.isDownloadBind = Boolean.valueOf(kapchatScreenActivity2.getApplicationContext().bindService(intent, KapchatScreenActivity.this.downloadServiceConnection, 1));
} else {
try {
KapchatScreenActivity.this.mDownloadBind.getService().downloadata(str);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}, 20L);
}
@Override
public void getMessageList(ArrayList<KapchatMessageList> arrayList) {
if (arrayList == null || arrayList.size() <= 0) {
return;
}
this.messageLists.clear();
this.nPageLimit = 0;
this.isPagination = Boolean.TRUE;
this.messageLists.addAll(arrayList);
Collections.reverse(this.messageLists);
this.messageListView.setAdapter(this.messageAdapter);
this.messageListView.scrollToPosition(this.messageLists.size() - 1);
}
public void getPaginationFromServer() {
this.isPaginationFromServer = false;
new KapchatPaginationFromServer(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
}
@Override
public void getPaginationList(ArrayList<KapchatMessageList> arrayList) {
if (arrayList == null || arrayList.size() <= 0) {
this.isPagination = Boolean.FALSE;
getPaginationFromServer();
} else {
this.isPagination = Boolean.TRUE;
this.messageLists.addAll(0, arrayList);
this.messageListView.setAdapter(this.messageAdapter);
this.messageListView.scrollToPosition(arrayList.size());
}
}
public String htmlToStringFilter(String str) {
return Html.fromHtml(str).toString().trim();
}
public void insertBulkPaginationMessage(java.util.ArrayList<org.jivesoftware.smack.packet.Message> r16, java.util.ArrayList<org.jivesoftware.smackx.delay.packet.DelayInformation> r17, java.lang.Boolean r18) {
throw new UnsupportedOperationException("Method not decompiled: com.adjetter.kapchatsdk.activity.KapchatScreenActivity.insertBulkPaginationMessage(java.util.ArrayList, java.util.ArrayList, java.lang.Boolean):void");
}
public void insertQuestion(String str, boolean z, String str2) {
if (str.equalsIgnoreCase("")) {
return;
}
KapchatQANotification kapchatQANotification = (KapchatQANotification) new Gson().fromJson(str, KapchatQANotification.class);
if (kapchatQANotification != null) {
ArrayList arrayList = new ArrayList();
arrayList.clear();
KapchatMessageList kapchatMessageList = new KapchatMessageList();
kapchatMessageList.setSendDate("" + kapchatQANotification.getSentDate());
kapchatMessageList.setFromJid("" + kapchatQANotification.getFromJid());
kapchatMessageList.setToJid(kapchatQANotification.getToJid());
kapchatMessageList.setMessageType("1");
kapchatMessageList.setMessage(kapchatQANotification.getQuestion());
kapchatMessageList.setDownload("0");
kapchatMessageList.setDownloadPath("0");
kapchatMessageList.setMessageStatus("1");
kapchatMessageList.setMime("0");
kapchatMessageList.setMimeurl("0");
kapchatMessageList.setBlob(new byte[]{0});
kapchatMessageList.setStanzaId(kapchatQANotification.getStanzaId());
arrayList.add(kapchatMessageList);
new KapchatMessageInsertion(getApplicationContext(), null, Boolean.FALSE).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, arrayList);
if (!z) {
SharedPreferences.Editor edit = getSharedPreferences("kapchatpreference", 0).edit();
edit.putString(KapchatHelper.QUESTION_ANSWER_JSON, "");
edit.apply();
this.interactionLayout.setVisibility(8);
}
}
if (z) {
answerTimerNotification(str2);
}
}
public boolean isOnline(Context context) {
NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
@Override
protected void onActivityResult(int i, int i2, Intent intent) {
String str;
Boolean bool;
String replace;
Boolean bool2;
super.onActivityResult(i, i2, intent);
if (i == 10 && i2 == -1) {
String replace2 = Build.VERSION.SDK_INT >= 24 ? getSharedPreferences("kapchatpreference", 0).getString("savedimage", "").replace("/external_files", Environment.getExternalStorageDirectory().toString()) : getSharedPreferences("kapchatpreference", 0).getString("savedimage", "");
File file = new File(replace2);
StringBuilder sb = new StringBuilder();
sb.append("file name ");
sb.append(replace2);
if (!file.exists() || file.length() <= 0) {
Toast.makeText(this, "Image not available try another !! ", 0).show();
return;
}
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(replace2, file3).booleanValue()) {
replace2 = file3.getAbsolutePath();
}
File file4 = new File(replace2);
if (!file4.exists() || file4.length() >= 5000000) {
Toast.makeText(this, "File Size Should be less than 5MB", 0).show();
return;
}
KapchatAttachmentStructure kapchatAttachmentStructure = new KapchatAttachmentStructure();
kapchatAttachmentStructure.setFilepath(replace2);
this.attachmentList.add(kapchatAttachmentStructure);
StringBuilder sb2 = new StringBuilder();
sb2.append("picture path is ");
sb2.append(replace2);
Intent intent2 = new Intent(this, (Class<?>) KapchatAttachmentActivity.class);
Bundle bundle = new Bundle();
bundle.putString("uri", replace2);
bundle.putString("tojid", getSharedPreferences("kapchatpreference", 0).getString("supportId", ""));
bundle.putString("from", "camera");
bundle.putString(TransferTable.COLUMN_TYPE, "chat");
intent2.putExtras(bundle);
startActivityForResult(intent2, 13);
return;
}
if (i == 11 && intent != null) {
Uri data = intent.getData();
if (data == null || data.getPath() == null || data.getPath().equalsIgnoreCase("")) {
return;
}
String[] strArr = {"_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://", "");
}
if (replace == null || replace.equalsIgnoreCase("")) {
showPopUpNotification("The photo is currently not available in the device.");
return;
}
File file5 = new File(replace);
File file6 = new File(Environment.getExternalStorageDirectory(), "Kaphatsend");
if (!file6.isFile()) {
file6.mkdirs();
}
File file7 = new File(file6, "kapchatsend_3_" + Calendar.getInstance().getTimeInMillis() + ".jpg");
try {
bool2 = KapchatImageUtils.compressImage(file5.getAbsolutePath(), file7);
} catch (Exception e) {
e.printStackTrace();
bool2 = Boolean.FALSE;
}
if (!bool2.booleanValue()) {
Intent intent3 = new Intent(this, (Class<?>) KapchatAttachmentActivity.class);
Bundle bundle2 = new Bundle();
bundle2.putString("uri", file5.getAbsolutePath());
bundle2.putString("tojid", getSharedPreferences("kapchatpreference", 0).getString("supportId", ""));
bundle2.putString("from", "gallery");
bundle2.putString(TransferTable.COLUMN_TYPE, "chat");
intent3.putExtras(bundle2);
startActivityForResult(intent3, 13);
return;
}
if (!file7.exists() || file7.length() >= 5000000) {
Toast.makeText(this, "File Size Should be less than 5MB", 0).show();
return;
}
Intent intent4 = new Intent(this, (Class<?>) KapchatAttachmentActivity.class);
Bundle bundle3 = new Bundle();
bundle3.putString("uri", file7.getAbsolutePath());
bundle3.putString("tojid", getSharedPreferences("kapchatpreference", 0).getString("supportId", ""));
bundle3.putString("from", "gallery");
bundle3.putString(TransferTable.COLUMN_TYPE, "chat");
intent4.putExtras(bundle3);
startActivityForResult(intent4, 13);
return;
}
if (i == 13) {
str = TransferTable.COLUMN_TYPE;
if (i2 == -1) {
if (intent == null || intent.getExtras() == null || intent.getExtras().getString("result") == null) {
if (this.mBind == null || !this.isUploadBind.booleanValue()) {
this.isUploadBind = Boolean.valueOf(getApplicationContext().bindService(new Intent(this, (Class<?>) KapchatUploadService.class), this.uploadServiceConnection, 1));
return;
}
try {
this.mBind.getService().readAllMessages();
return;
} catch (Exception e2) {
e2.printStackTrace();
return;
}
}
if (intent.getExtras().getString("result").equalsIgnoreCase("Permission Failed")) {
c.a aVar = new c.a(this);
aVar.setCancelable(false);
aVar.setMessage("" + getResources().getString(R.string.app_name) + " need permission to attach images , Please enable permission and then try attaching attachments");
aVar.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i3) {
KapchatScreenActivity.this.checkGalleryPermission();
}
});
aVar.create().show();
return;
}
return;
}
} else {
str = TransferTable.COLUMN_TYPE;
}
if (i == 14) {
this.isRefresh = false;
return;
}
if (i != 15 || intent == null || intent.getData() == null) {
return;
}
String str2 = "" + getRealPathFromURI(getApplicationContext(), intent.getData());
if (str2 == null || str2.equalsIgnoreCase("")) {
showPopUpNotification("Not able to access the selected file. please try with some other");
return;
}
File file8 = new File(str2);
File file9 = new File(Environment.getExternalStorageDirectory(), "Kaphatsend");
if (!file9.isFile()) {
file9.mkdirs();
}
File file10 = new File(file9, "kapchatsend_3_" + Calendar.getInstance().getTimeInMillis() + ".jpg");
try {
bool = KapchatImageUtils.compressImage(file8.getAbsolutePath(), file10);
} catch (Exception e3) {
e3.printStackTrace();
bool = Boolean.FALSE;
}
if (!bool.booleanValue()) {
Intent intent5 = new Intent(this, (Class<?>) KapchatAttachmentActivity.class);
Bundle bundle4 = new Bundle();
bundle4.putString("uri", file8.getAbsolutePath());
bundle4.putString("tojid", getSharedPreferences("kapchatpreference", 0).getString("supportId", ""));
bundle4.putString("from", "gallery");
bundle4.putString(str, "chat");
intent5.putExtras(bundle4);
startActivityForResult(intent5, 13);
return;
}
if (!file10.exists() || file10.length() >= 5000000) {
Toast.makeText(this, "File Size Should be less than 5MB", 0).show();
return;
}
Intent intent6 = new Intent(this, (Class<?>) KapchatAttachmentActivity.class);
Bundle bundle5 = new Bundle();
bundle5.putString("uri", file10.getAbsolutePath());
bundle5.putString("tojid", getSharedPreferences("kapchatpreference", 0).getString("supportId", ""));
bundle5.putString("from", "gallery");
bundle5.putString(str, "chat");
intent6.putExtras(bundle5);
startActivityForResult(intent6, 13);
}
@Override
public void onBackPressed() {
super.onBackPressed();
try {
if (this.typeMessage.hasFocus()) {
((InputMethodManager) getSystemService("input_method")).hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 2);
}
} catch (Exception unused) {
}
setResult(-1, new Intent());
System.out.println("#### value is RESULT_OK new : -1");
finish();
}
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_kapchatscreenactivity);
setupactionbar();
this.ikapchatMessages = this;
SharedPreferences.Editor edit = getSharedPreferences("kapchatpreference", 0).edit();
edit.putString("screenPresent", "yes");
edit.putString("kapchatNotificationList", "");
edit.putString("popupPresent", "no");
edit.apply();
SharedPreferences.Editor edit2 = getSharedPreferences("kapchatnewRef", 0).edit();
edit2.putInt("unreadCount", 0);
edit2.apply();
ProgressDialog progressDialog = new ProgressDialog(this);
this.progressDialog = progressDialog;
progressDialog.requestWindowFeature(1);
this.progressDialog.setTitle("Loading");
this.progressDialog.setMessage("Please wait...");
this.progressDialog.setCancelable(false);
BroadcastReceiver updateChatListener = new UpdateChatListener();
this.updateReceiver = updateChatListener;
registerReceiver(updateChatListener, new IntentFilter("com.adjetter.kapchatupdate"));
OnlineStatusReceiver onlineStatusReceiver = new OnlineStatusReceiver();
this.onlineStatusReceiver = onlineStatusReceiver;
registerReceiver(onlineStatusReceiver, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));
NotificationReceiver notificationReceiver = new NotificationReceiver();
this.notificationReceiver = notificationReceiver;
registerReceiver(notificationReceiver, new IntentFilter("com.adjetter.NOTIFICATION_RECEIVED"));
try {
XMPPTCPConnection xMPPTCPConnection = KapchatConnection.mConnection;
if ((xMPPTCPConnection == null || (xMPPTCPConnection != null && !xMPPTCPConnection.isConnected())) && !KapchatService.isConnecting.booleanValue()) {
Intent intent = new Intent(this, (Class<?>) KapchatService.class);
if (Build.VERSION.SDK_INT >= 26) {
getApplicationContext().startService(intent);
} else {
getApplicationContext().startService(intent);
}
}
} catch (Exception unused) {
}
this.timeLayout = (TextView) findViewById(R.id.timelayout);
this.typeMessage = (EditText) findViewById(R.id.typemessage);
this.sendButton = (ImageView) findViewById(R.id.sendbutton);
this.showOfflineText = (TextView) findViewById(R.id.kapchatonlinestatus);
this.primaryView = (RelativeLayout) findViewById(R.id.primaryView);
this.popupNotification = (RelativeLayout) findViewById(R.id.popupNotification);
this.popupMessage = (TextView) findViewById(R.id.popupMessage);
this.clearPopup = (TextView) findViewById(R.id.clearpopup);
this.popupNotification.setVisibility(8);
this.interactionLayout = (LinearLayout) findViewById(R.id.interaction_layout);
this.notificationTimerText = (TextView) findViewById(R.id.notification_timer);
this.timerTextView = (TextView) findViewById(R.id.timer_question);
this.answerLayout = (LinearLayout) findViewById(R.id.answer_layout);
this.interactionLayout.setVisibility(8);
this.messageListView = (RecyclerView) findViewById(R.id.chatListView);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
this.layoutManager = linearLayoutManager;
linearLayoutManager.setStackFromEnd(true);
this.messageListView.setLayoutManager(this.layoutManager);
KapchatListAdapter kapchatListAdapter = new KapchatListAdapter(this, this.messageLists, this);
this.messageAdapter = kapchatListAdapter;
this.messageListView.setAdapter(kapchatListAdapter);
this.messageListView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int i) {
super.onScrollStateChanged(recyclerView, i);
if (i == 0 && KapchatScreenActivity.this.timeLayout.getVisibility() == 0) {
Animation loadAnimation = AnimationUtils.loadAnimation(KapchatScreenActivity.this, R.anim.kapchatanimatetop);
KapchatScreenActivity.this.timeLayout.startAnimation(loadAnimation);
loadAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
KapchatScreenActivity.this.timeLayout.setVisibility(8);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationStart(Animation animation) {
}
});
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int i, int i2) {
super.onScrolled(recyclerView, i, i2);
int findFirstVisibleItemPosition = KapchatScreenActivity.this.layoutManager.findFirstVisibleItemPosition();
if (findFirstVisibleItemPosition != 0) {
if (findFirstVisibleItemPosition > 0) {
try {
KapchatScreenActivity.this.timeLayout.setVisibility(0);
KapchatScreenActivity.this.timeLayout.setText(KapchatHelper.getFormattedDate(KapchatScreenActivity.this, Long.parseLong(((KapchatMessageList) KapchatScreenActivity.this.messageLists.get(findFirstVisibleItemPosition)).getSendDate())));
return;
} catch (Exception e) {
e.printStackTrace();
return;
}
}
return;
}
if (KapchatScreenActivity.this.isPagination.booleanValue()) {
KapchatScreenActivity.this.isPagination = Boolean.FALSE;
KapchatScreenActivity.this.nPageLimit += 20;
KapchatScreenActivity.this.callpagination("" + KapchatScreenActivity.this.nPageLimit);
} else {
KapchatScreenActivity kapchatScreenActivity = KapchatScreenActivity.this;
if (kapchatScreenActivity.isPaginationFromServer) {
kapchatScreenActivity.getPaginationFromServer();
}
}
KapchatScreenActivity.this.timeLayout.setVisibility(8);
}
});
RecyclerView recyclerView = this.messageListView;
recyclerView.addOnItemTouchListener(new KapchatMessageListItemClickListener(this, recyclerView, new MessageListItemClickListner() {
@Override
public void onClick(View view, int i) {
if (KapchatScreenActivity.this.mActionMode != null) {
KapchatScreenActivity.this.onListItemSelect(i);
}
}
@Override
public void onLongClick(View view, int i) {
KapchatScreenActivity.this.onListItemSelect(i);
}
}));
this.sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
KapchatScreenActivity.this.sendButtonClick();
}
});
if (isOnline(getApplicationContext())) {
this.showOfflineText.setVisibility(8);
} else {
this.showOfflineText.setVisibility(0);
}
if (getIntent() != null && getIntent().getExtras() != null && getIntent().getExtras().getString("templateMessage") != null) {
this.isSendTemplateMessage = true;
this.templateMessageGiven = getIntent().getExtras().getString("templateMessage");
}
this.clearPopup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
KapchatScreenActivity.this.popupNotification.setVisibility(8);
}
});
this.typeMessage.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable editable) {
}
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
if (charSequence.length() >= 2000) {
KapchatScreenActivity.this.showSnackbar("You have reached maximum of 2000 character");
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.kapchatmenu, menu);
return true;
}
@Override
protected void onDestroy() {
try {
unregisterReceiver(this.updateReceiver);
unregisterReceiver(this.onlineStatusReceiver);
unregisterReceiver(this.notificationReceiver);
if (this.isUploadBind.booleanValue()) {
getApplicationContext().unbindService(this.uploadServiceConnection);
}
if (this.isDownloadBind.booleanValue()) {
getApplicationContext().unbindService(this.downloadServiceConnection);
}
} catch (Exception e) {
e.printStackTrace();
}
super.onDestroy();
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
int itemId = menuItem.getItemId();
if (itemId == 16908332) {
if (!getSharedPreferences("kapchatpreference", 0).getString("guestsession", "").equalsIgnoreCase("true")) {
onBackPressed();
return true;
}
c.a aVar = new c.a(this);
aVar.setMessage("Are you sure to close this session ?");
aVar.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
KapchatHelper.logoutKapchat(KapchatScreenActivity.this);
KapchatScreenActivity.this.finish();
}
});
aVar.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
aVar.create().show();
return true;
}
if (itemId == R.id.clearchat) {
c.a aVar2 = new c.a(this);
aVar2.setMessage("Are you sure to clear the chat history ?");
aVar2.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
SharedPreferences.Editor edit = KapchatScreenActivity.this.getSharedPreferences("kapchatpreference", 0).edit();
edit.putString("firstIndex", "-1");
edit.apply();
}
});
aVar2.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
aVar2.create().show();
return true;
}
if (itemId == R.id.kapchat_camera) {
checkCameraPermission();
return true;
}
if (itemId == R.id.kapchat_gallery) {
checkGalleryPermission();
return true;
}
if (itemId != R.id.endchat) {
return true;
}
doEndChat();
return true;
}
@Override
protected void onPause() {
super.onPause();
}
@Override
public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
super.onRequestPermissionsResult(i, strArr, iArr);
this.isRefresh = false;
if (i == 1) {
if (iArr[0] == 0) {
if (verifyStoragePermissions(this, 1)) {
startCameraActivity();
return;
}
return;
}
if (shouldShowRequestPermissionRationale(strArr[0])) {
Snackbar make = Snackbar.make(this.primaryView, getResources().getString(R.string.app_name) + " need permission to start camera", -1);
make.setActionTextColor(getResources().getColor(R.color.colorPrimary));
make.setAction("Ok", new View.OnClickListener() {
@Override
public void onClick(View view) {
KapchatScreenActivity.this.checkCameraPermission();
}
});
make.getView();
return;
}
Snackbar make2 = Snackbar.make(this.primaryView, getResources().getString(R.string.app_name) + " need permission to start camera", -1);
make2.setActionTextColor(getResources().getColor(R.color.colorPrimary));
make2.setAction("Settings", new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
intent.setData(Uri.fromParts("package", KapchatScreenActivity.this.getPackageName(), null));
KapchatScreenActivity.this.startActivity(intent);
}
});
make2.getView();
return;
}
if (i == 2) {
if (iArr[0] == 0) {
startGalleryActivity();
return;
}
if (shouldShowRequestPermissionRationale(strArr[0])) {
Snackbar make3 = Snackbar.make(this.primaryView, getResources().getString(R.string.app_name) + " need permission to attach images", -1);
make3.setActionTextColor(getResources().getColor(R.color.colorPrimary));
make3.setAction("Ok", new View.OnClickListener() {
@Override
public void onClick(View view) {
KapchatScreenActivity.this.checkGalleryPermission();
}
});
make3.getView();
return;
}
Snackbar make4 = Snackbar.make(this.primaryView, getResources().getString(R.string.app_name) + " need permission to attach images", -1);
make4.setActionTextColor(getResources().getColor(R.color.colorPrimary));
make4.setAction("Settings", new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
intent.setData(Uri.fromParts("package", KapchatScreenActivity.this.getPackageName(), null));
KapchatScreenActivity.this.startActivity(intent);
}
});
make4.getView();
return;
}
if (i != 3) {
return;
}
if (iArr[0] == 0) {
Toast.makeText(this, "Please click download button now, to download attachments", 0).show();
return;
}
if (shouldShowRequestPermissionRationale(strArr[0])) {
Snackbar make5 = Snackbar.make(this.primaryView, getResources().getString(R.string.app_name) + " need permission to save downloaded image", -1);
make5.setActionTextColor(getResources().getColor(R.color.colorPrimary));
make5.setAction("Ok", new View.OnClickListener() {
@Override
public void onClick(View view) {
KapchatScreenActivity.this.requestPermission();
}
});
make5.getView();
return;
}
Snackbar make6 = Snackbar.make(this.primaryView, getResources().getString(R.string.app_name) + " need permission to save downloaded image", -1);
make6.setActionTextColor(getResources().getColor(R.color.colorPrimary));
make6.setAction("Settings", new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
intent.setData(Uri.fromParts("package", KapchatScreenActivity.this.getPackageName(), null));
KapchatScreenActivity.this.startActivity(intent);
}
});
make6.getView();
}
@Override
protected void onResume() {
super.onResume();
SharedPreferences.Editor edit = getSharedPreferences("kapchatpreference", 0).edit();
edit.putString("screenPresent", "yes");
edit.putString("kapchatNotificationList", "");
edit.apply();
SharedPreferences.Editor edit2 = getSharedPreferences("kapchatnewRef", 0).edit();
edit2.putInt("unreadCount", 0);
edit2.apply();
((NotificationManager) getSystemService("notification")).cancelAll();
if (this.isSendTemplateMessage) {
chatlistener();
} else {
if (this.isRefresh) {
readMessageList(0);
} else {
this.isRefresh = true;
ArrayList<KapchatMessageList> arrayList = this.messageLists;
if (arrayList != null && arrayList.size() < 1) {
readMessageList(0);
}
}
chatlistener();
}
if (this.showOfflineText.getVisibility() == 0) {
restartService(this);
}
checkPendingTimerNotification();
chatScreenExited = false;
}
@Override
protected void onStop() {
SharedPreferences.Editor edit = getSharedPreferences("kapchatpreference", 0).edit();
edit.putString("screenPresent", "no");
edit.apply();
KapchatTimer kapchatTimer = this.kapchatTimer;
if (kapchatTimer != null) {
kapchatTimer.cancel();
}
super.onStop();
}
@Override
public void onTimerEnd() {
this.interactionLayout.setVisibility(8);
insertQuestion(getSharedPreferences("kapchatpreference", 0).getString(KapchatHelper.QUESTION_ANSWER_JSON, ""), false, "");
}
@Override
public void onTimerTick(long j2) {
this.interactionLayout.setVisibility(0);
this.notificationTimerText.setText("" + (j2 / 1000) + " s");
}
@Override
public void readMessageList(int i) {
new KapchatReadMessages(this, this, i).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
}
public void requestPermission() {
b.requestPermissions(this, PERMISSIONS_LIST, 3);
}
public void restartService(Context context) {
if (!isOnline(context)) {
this.showOfflineText.setVisibility(0);
return;
}
this.showOfflineText.setVisibility(8);
if (context.getSharedPreferences("kapchatpreference", 0).getString("supportId", "").equalsIgnoreCase("")) {
return;
}
Bundle bundle = new Bundle();
bundle.putString("reconnect", "yes");
Intent intent = new Intent(context, (Class<?>) KapchatService.class);
intent.putExtras(bundle);
if (KapchatConnection.mConnection == null) {
if (Build.VERSION.SDK_INT >= 26) {
getApplicationContext().startService(intent);
} else {
getApplicationContext().startService(intent);
}
}
}
public void retry(String str, String str2) {
ArrayList arrayList = new ArrayList();
KapchatMessageList kapchatMessageList = new KapchatMessageList();
kapchatMessageList.setConversationId(str);
kapchatMessageList.setMimeurl(str2);
kapchatMessageList.setMessageStatus("5");
arrayList.add(kapchatMessageList);
new KapchatUpdateConversationId(getApplicationContext(), null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, arrayList);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
KapchatUploadService.Localbinder localbinder = KapchatScreenActivity.this.mBind;
if (localbinder != null) {
localbinder.getService().readAllMessages();
return;
}
Intent intent = new Intent(KapchatScreenActivity.this, (Class<?>) KapchatUploadService.class);
KapchatScreenActivity kapchatScreenActivity = KapchatScreenActivity.this;
kapchatScreenActivity.isUploadBind = Boolean.valueOf(kapchatScreenActivity.getApplicationContext().bindService(intent, KapchatScreenActivity.this.uploadServiceConnection, 1));
}
}, 20L);
}
public void sendButtonClick() {
if (getSharedPreferences("kapchatpreference", 0).getString("supportId", "").equalsIgnoreCase("")) {
Toast.makeText(this, "Chat Initialise Failed", 0).show();
return;
}
if (this.typeMessage.getText().toString().trim().equalsIgnoreCase("")) {
return;
}
KapchatTimer kapchatTimer = this.kapchatTimer;
if (kapchatTimer != null) {
kapchatTimer.cancel();
this.interactionLayout.setVisibility(8);
insertQuestion(getSharedPreferences("kapchatpreference", 0).getString(KapchatHelper.QUESTION_ANSWER_JSON, ""), false, "");
}
ArrayList arrayList = new ArrayList();
arrayList.clear();
KapchatMessageList kapchatMessageList = new KapchatMessageList();
kapchatMessageList.setSendDate("" + System.currentTimeMillis());
kapchatMessageList.setFromJid(getSharedPreferences("kapchatpreference", 0).getString("userName", "") + KapchatHelper.serviceName);
kapchatMessageList.setToJid("" + getSharedPreferences("kapchatpreference", 0).getString("supportId", ""));
kapchatMessageList.setMessage(htmlToStringFilter(this.typeMessage.getText().toString()));
kapchatMessageList.setMessageType(a.GPS_MEASUREMENT_2D);
kapchatMessageList.setMime("0");
kapchatMessageList.setMimeurl("0");
kapchatMessageList.setDownload("0");
kapchatMessageList.setDownloadPath("0");
kapchatMessageList.setBlob(new byte[]{0});
XMPPTCPConnection xMPPTCPConnection = KapchatConnection.mConnection;
if (xMPPTCPConnection == null || !xMPPTCPConnection.isAuthenticated()) {
kapchatMessageList.setMessageStatus(a.GPS_MEASUREMENT_2D);
} else {
kapchatMessageList.setMessageStatus("1");
}
try {
Message message = new Message();
KapchatSendMessageStructure kapchatSendMessageStructure = new KapchatSendMessageStructure();
kapchatSendMessageStructure.enquiryId = "0";
kapchatSendMessageStructure.fromJid = "" + getSharedPreferences("kapchatpreference", 0).getString("userName", "");
kapchatSendMessageStructure.leadId = Integer.parseInt(getSharedPreferences("kapchatpreference", 0).getString("leadId", "0"));
kapchatSendMessageStructure.message = "" + htmlToStringFilter(this.typeMessage.getText().toString());
kapchatSendMessageStructure.messageId = null;
kapchatSendMessageStructure.receiverName = null;
kapchatSendMessageStructure.sentDate = System.currentTimeMillis();
kapchatSendMessageStructure.senderName = "" + getSharedPreferences("kapchatpreference", 0).getString("contactName", "");
kapchatSendMessageStructure.supportId = "" + getSharedPreferences("kapchatpreference", 0).getString("supportId", "");
kapchatSendMessageStructure.toJid = null;
kapchatSendMessageStructure.fromResource = getSharedPreferences("kapchatpreference", 0).getString("kapchatresource", "");
if (getSharedPreferences("kapchatpreference", 0).getString("guestsession", "").equalsIgnoreCase("true")) {
kapchatSendMessageStructure.taskId = Integer.parseInt(getSharedPreferences("kapchatpreference", 0).getString("taskId", ""));
kapchatSendMessageStructure.ticketId = getSharedPreferences("kapchatpreference", 0).getString("ticketId", "");
}
String str = "{\"key\":\"" + KapchatHelper.supportmessagekey + "\",\"supportChatMessage\":" + new Gson().toJson(kapchatSendMessageStructure) + ",\"type\":\"" + KapchatHelper.supporttype + "\"}";
StringBuilder sb = new StringBuilder();
sb.append("");
sb.append(str);
message.setBody("" + str);
message.setType(Message.Type.chat);
String str2 = message.getStanzaId() + (new Random().nextInt(900000) + 100000);
message.setStanzaId(str2);
MarkableElement markableElement = new MarkableElement();
markableElement.setId(str2);
message.addExtension(markableElement);
kapchatMessageList.setStanzaId(message.getStanzaId());
XMPPTCPConnection xMPPTCPConnection2 = KapchatConnection.mConnection;
if (xMPPTCPConnection2 != null && xMPPTCPConnection2.isConnected() && KapchatConnection.mConnection.isAuthenticated()) {
this.newChat.sendMessage(message);
SharedPreferences.Editor edit = getSharedPreferences("kapchatpreference", 0).edit();
edit.putString("lastLogout", "" + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()));
edit.apply();
} else {
kapchatMessageList.setMessageStatus(a.GPS_MEASUREMENT_2D);
}
} catch (Exception e) {
kapchatMessageList.setMessageStatus(a.GPS_MEASUREMENT_2D);
e.printStackTrace();
}
arrayList.add(kapchatMessageList);
new KapchatMessageInsertion(this, null, Boolean.FALSE).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, arrayList);
this.typeMessage.setText("");
}
public void sendTemplateMessage(String str) {
if (getSharedPreferences("kapchatpreference", 0).getString("supportId", "").equalsIgnoreCase("")) {
Toast.makeText(this, "Chat Initialise Failed", 0).show();
return;
}
if (str.equalsIgnoreCase("")) {
return;
}
ArrayList arrayList = new ArrayList();
arrayList.clear();
KapchatMessageList kapchatMessageList = new KapchatMessageList();
kapchatMessageList.setSendDate("" + new Date().getTime());
kapchatMessageList.setFromJid(getSharedPreferences("kapchatpreference", 0).getString("userName", "") + KapchatHelper.serviceName);
kapchatMessageList.setToJid("" + getSharedPreferences("kapchatpreference", 0).getString("supportId", ""));
kapchatMessageList.setMessage(str);
kapchatMessageList.setMessageType(a.GPS_MEASUREMENT_2D);
kapchatMessageList.setMime("0");
kapchatMessageList.setMimeurl("0");
kapchatMessageList.setDownload("0");
kapchatMessageList.setDownloadPath("0");
kapchatMessageList.setBlob(new byte[]{0});
XMPPTCPConnection xMPPTCPConnection = KapchatConnection.mConnection;
if (xMPPTCPConnection == null || !xMPPTCPConnection.isAuthenticated()) {
kapchatMessageList.setMessageStatus(a.GPS_MEASUREMENT_2D);
} else {
kapchatMessageList.setMessageStatus("1");
}
try {
Message message = new Message();
KapchatSendMessageStructure kapchatSendMessageStructure = new KapchatSendMessageStructure();
kapchatSendMessageStructure.enquiryId = "0";
kapchatSendMessageStructure.fromJid = "" + getSharedPreferences("kapchatpreference", 0).getString("userName", "");
kapchatSendMessageStructure.leadId = Integer.parseInt(getSharedPreferences("kapchatpreference", 0).getString("leadId", "0"));
kapchatSendMessageStructure.message = "" + str;
kapchatSendMessageStructure.messageId = null;
kapchatSendMessageStructure.receiverName = null;
kapchatSendMessageStructure.sentDate = System.currentTimeMillis();
kapchatSendMessageStructure.senderName = "" + getSharedPreferences("kapchatpreference", 0).getString("contactName", "");
kapchatSendMessageStructure.supportId = "" + getSharedPreferences("kapchatpreference", 0).getString("supportId", "");
kapchatSendMessageStructure.toJid = null;
kapchatSendMessageStructure.fromResource = getSharedPreferences("kapchatpreference", 0).getString("kapchatresource", "");
if (getSharedPreferences("kapchatpreference", 0).getString("guestsession", "").equalsIgnoreCase("true")) {
kapchatSendMessageStructure.taskId = Integer.parseInt(getSharedPreferences("kapchatpreference", 0).getString("taskId", ""));
kapchatSendMessageStructure.ticketId = getSharedPreferences("kapchatpreference", 0).getString("ticketId", "");
}
message.setBody("" + ("{\"key\":\"" + KapchatHelper.supportmessagekey + "\",\"supportChatMessage\":" + new Gson().toJson(kapchatSendMessageStructure) + ",\"type\":\"" + KapchatHelper.supporttype + "\"}"));
message.setType(Message.Type.chat);
kapchatMessageList.setStanzaId(message.getStanzaId());
XMPPTCPConnection xMPPTCPConnection2 = KapchatConnection.mConnection;
if (xMPPTCPConnection2 != null && xMPPTCPConnection2.isConnected() && KapchatConnection.mConnection.isAuthenticated()) {
this.newChat.sendMessage(message);
SharedPreferences.Editor edit = getSharedPreferences("kapchatpreference", 0).edit();
edit.putString("lastLogout", "" + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()));
edit.apply();
} else {
kapchatMessageList.setMessageStatus(a.GPS_MEASUREMENT_2D);
}
} catch (Exception e) {
kapchatMessageList.setMessageStatus(a.GPS_MEASUREMENT_2D);
e.printStackTrace();
}
arrayList.add(kapchatMessageList);
new KapchatMessageInsertion(this, null, Boolean.FALSE).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, arrayList);
this.typeMessage.setText("");
this.isSendTemplateMessage = false;
}
public void setNullToActionMode() {
this.mActionMode = null;
this.hasCheckedItems = false;
this.typeMessage.setEnabled(true);
this.typeMessage.setClickable(true);
}
public void setupactionbar() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
this.toolbar = toolbar;
setSupportActionBar(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 showActivityPopUpNotification(String str) {
SharedPreferences.Editor edit = getSharedPreferences("kapchatpreference", 0).edit();
edit.putString("popupPresent", "yes");
edit.apply();
this.popupNotification.setVisibility(0);
this.popupMessage.setText(str);
}
public void showPopUpNotification(String str) {
final Snackbar make = Snackbar.make(this.primaryView, str, -2);
make.setActionTextColor(getResources().getColor(R.color.colorPrimary));
make.setAction("Ok", new View.OnClickListener() {
@Override
public void onClick(View view) {
make.dismiss();
}
});
make.getView();
}
public void showSnackbar(String str) {
Snackbar.make(this.messageListView, str, -1).getView();
}
public void startCameraActivity() {
Uri fromFile;
File file = new File(Environment.getExternalStorageDirectory(), "Kaphatcapture");
if (!file.isFile()) {
file.mkdirs();
}
File file2 = new File(file, "kapchatimage_2_" + Calendar.getInstance().getTimeInMillis() + ".jpg");
Uri.parse("");
if (Build.VERSION.SDK_INT >= 24) {
fromFile = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", file2);
} else {
fromFile = Uri.fromFile(file2);
}
savedImage = fromFile.getPath();
SharedPreferences.Editor edit = getSharedPreferences("kapchatpreference", 0).edit();
edit.putString("savedimage", savedImage);
edit.apply();
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra("output", fromFile);
startActivityForResult(intent, 10);
}
public void startGalleryActivity() {
Intent intent = new Intent("android.intent.action.PICK");
intent.setType("image/*");
startActivityForResult(intent, 15);
}
@Override
public void stopKapChatServiceTimer() {
KapchatHelper.stopKapService(getApplicationContext());
}
public void unselectAllmessages() {
ArrayList<String> arrayList;
ArrayList<KapchatMessageList> arrayList2 = this.messageLists;
if (arrayList2 != null && arrayList2.size() > 0 && (arrayList = this.selectedMessageList) != null && arrayList.size() > 0) {
for (int i = 0; i < this.messageLists.size(); i++) {
int size = this.selectedMessageList.size() - 1;
while (true) {
if (size < 0) {
break;
}
if (this.selectedMessageList.get(size).equalsIgnoreCase(this.messageLists.get(i).getConversationId())) {
this.selectedMessageList.remove(size);
this.messageLists.get(i).setSelected(false);
break;
}
size--;
}
}
this.messageAdapter.notifyDataSetChanged();
}
this.selectedMessageList.clear();
}
@Override
public void updateMessageList(Boolean bool, ArrayList<KapchatMessageList> arrayList) {
this.messageLists.addAll(arrayList);
Collections.sort(this.messageLists, new Comparator<KapchatMessageList>() {
@Override
public int compare(KapchatMessageList kapchatMessageList, KapchatMessageList kapchatMessageList2) {
try {
long parseLong = Long.parseLong(kapchatMessageList.getSendDate());
long parseLong2 = Long.parseLong(kapchatMessageList2.getSendDate());
if (parseLong < parseLong2) {
return -1;
}
return parseLong > parseLong2 ? 1 : 0;
} catch (Exception e) {
e.printStackTrace();
StringBuilder sb = new StringBuilder();
sb.append("exception on comparison ");
sb.append(kapchatMessageList.getSendDate());
sb.append(" o2 senddate ");
sb.append(kapchatMessageList2.getSendDate());
return 0;
}
}
});
this.messageListView.setAdapter(this.messageAdapter);
this.messageListView.scrollToPosition(arrayList.size());
ProgressDialog progressDialog = this.progressDialog;
if (progressDialog != null && progressDialog.isShowing()) {
this.progressDialog.dismiss();
}
this.isPaginationFromServer = true;
}
public void updateSelected(int i) {
ArrayList<KapchatMessageList> arrayList = this.messageLists;
if (arrayList == null || arrayList.size() <= 0) {
return;
}
if (this.messageLists.get(i).isSelected) {
this.messageLists.get(i).setSelected(false);
int size = this.selectedMessageList.size() - 1;
while (true) {
if (size < 0) {
break;
}
if (this.selectedMessageList.get(size).equalsIgnoreCase(this.messageLists.get(i).getConversationId())) {
this.selectedMessageList.remove(size);
break;
}
size--;
}
} else {
this.messageLists.get(i).setSelected(true);
this.selectedMessageList.add(this.messageLists.get(i).getConversationId());
}
this.messageAdapter.notifyDataSetChanged();
}
public boolean verifyCameraPermission(Activity activity, int i) {
if (androidx.core.content.a.checkSelfPermission(activity, "android.permission.CAMERA") == 0) {
return true;
}
b.requestPermissions(activity, this.PERMISSIONS_CAMERA, i);
return false;
}
public boolean verifyStoragePermissions(Activity activity, int i) {
if (androidx.core.content.a.checkSelfPermission(activity, "android.permission.WRITE_EXTERNAL_STORAGE") == 0) {
return true;
}
b.requestPermissions(activity, this.PERMISSIONS_STORAGE, i);
return false;
}
}