Kate Mobile v109.1版本的 MD5 值为:fcd76ded5f363ecbfac46035a4ed2a23
以下内容为反编译后的 CommentsActivity.java 源代码,内容仅作参考
package com.perm.kate;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.Editable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import com.perm.kate.CommentsActivity;
import com.perm.kate.api.Comment;
import com.perm.kate.api.CommentList;
import com.perm.kate.api.Group;
import com.perm.kate.api.KException;
import com.perm.kate.api.User;
import com.perm.kate.data.NotifyObject;
import com.perm.kate.data.PageCommentList;
import com.perm.kate.session.Callback;
import com.perm.kate.smile.SmileKeyboard;
import com.perm.kate.smile.SmilePagerAdapter;
import com.perm.kate.smile.StickerAdapter;
import com.perm.utils.AnswerParser;
import com.perm.utils.AnswerType;
import com.perm.utils.RepostHelper;
import com.perm.utils.SimpleListener;
import com.perm.utils.SmileHelper;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
public class CommentsActivity extends BaseActivity {
boolean can_post;
private CommentListAdapter comment_list_adapter;
private int comment_type;
private long content_id;
private long content_owner_id;
EditText editText;
public boolean is_new;
private boolean last_page;
PageCommentList list;
private ListView lv_comment_list;
private long parent_comment_id;
MiniPlayer player;
String reply_to_cid;
String reply_to_user_name;
ImageButton sendButton;
private Long start_comment_id;
private StickerAdapter stickerHintsAdapter;
private View stickerHintsView;
private PopupWindow stickerHintsWindow;
private final long account_id = Long.parseLong(KApplication.session.getMid());
final ArrayList replyCids = new ArrayList();
final ArrayList replyUsers = new ArrayList();
boolean is_grouped = isGrouped();
boolean is_sorted = false;
boolean is_sorted_by_date = false;
private final NotifyObject.EventsListener listChangeListener = new NotifyObject.EventsListener() {
@Override
public void onChange() {
CommentsActivity.this.requeryOnUiThread();
}
};
private final Callback callback_reload = new Callback(this) {
@Override
public void error(Throwable th) {
super.error(th);
CommentsActivity.this.showProgressBar(false);
}
@Override
public void ready(Object obj) {
CommentList commentList = (CommentList) obj;
if (!CommentsActivity.this.is_new) {
long currentTimeMillis = System.currentTimeMillis();
long nanoTime = System.nanoTime();
KApplication.db.recreateComments(commentList.comments, CommentsActivity.this.content_id, CommentsActivity.this.comment_type, CommentsActivity.this.content_owner_id, CommentsActivity.this.account_id);
Helper.reportDbWriteDuration(nanoTime, "ca_recreateComments");
long currentTimeMillis2 = System.currentTimeMillis();
Log.i("Kate.CommentsActivity", "Recreate comments duration " + (currentTimeMillis2 - currentTimeMillis) + " ms");
}
Helper.getMissingUsers(commentList.comments);
CommentsActivity.this.list.reset(commentList, 35, false);
CommentsActivity.this.requeryOnUiThread();
CommentsActivity.this.showProgressBar(false);
}
};
private final Callback callback_refresh = new Callback(this) {
@Override
public void error(Throwable th) {
super.error(th);
CommentsActivity.this.showProgressBar(false);
}
@Override
public void ready(Object obj) {
CommentList commentList = (CommentList) obj;
CommentsActivity.this.showProgressBar(false);
if (commentList.comments.size() == 0) {
return;
}
Helper.getMissingUsers(commentList.comments);
CommentsActivity.this.list.addPage(commentList);
CommentsActivity.this.requeryOnUiThread(true);
}
};
ArrayList commentDatas = new ArrayList();
int removed_posts = 0;
private final AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView adapterView, View view, int i, long j) {
PageCommentList.CommentData commentData = (PageCommentList.CommentData) CommentsActivity.this.commentDatas.get(i);
PageCommentList.CommentData.ItemType itemType = commentData.type;
if (itemType == PageCommentList.CommentData.ItemType.COMMENT) {
CommentsActivity.this.displayContextMenu((CommentTag) view.getTag());
} else if (itemType == PageCommentList.CommentData.ItemType.EMPTY_PAGE) {
CommentsActivity commentsActivity = CommentsActivity.this;
commentsActivity.list.loadPage(commentData.page_number, commentsActivity);
} else if (itemType == PageCommentList.CommentData.ItemType.SHOW_ALL_REPLIES) {
CommentsActivity.this.showAllReplies(commentData.parent_comment_id);
}
}
};
final int page_size = 35;
private final Callback callback_get_comment = new Callback(this) {
@Override
public void error(Throwable th) {
super.error(th);
CommentsActivity.this.showProgressBar(false);
}
@Override
public void ready(Object obj) {
Comment comment = (Comment) obj;
if (comment == null) {
CommentsActivity.this.showProgressBar(false);
} else if (comment.parent_stack > 0) {
CommentsActivity.this.downloadParentCommentById(comment);
} else {
Helper.getMissingUsers(comment.thread_comments);
CommentList commentList = new CommentList();
commentList.count = 1;
commentList.comments.add(comment);
CommentsActivity.this.list.reset(commentList, 35, true);
CommentsActivity.this.requeryOnUiThread(false);
CommentsActivity.this.showProgressBar(false);
}
}
};
private final Callback callback_last_page = new Callback(this) {
@Override
public void error(Throwable th) {
super.error(th);
CommentsActivity.this.showProgressBar(false);
}
@Override
public void ready(Object obj) {
CommentList commentList = (CommentList) obj;
Helper.getMissingUsers(commentList.comments);
Collections.reverse(commentList.comments);
CommentsActivity.this.list.reset(commentList, 35, true);
CommentsActivity.this.requeryOnUiThread(true);
CommentsActivity.this.showProgressBar(false);
}
};
private final View.OnClickListener sendClick = new AnonymousClass24();
private final View.OnClickListener addAttachmentClick = new View.OnClickListener() {
@Override
public void onClick(View view) {
CommentsActivity commentsActivity = CommentsActivity.this;
String str = commentsActivity.reply_to_cid;
if (str == null) {
str = commentsActivity.parent_comment_id > 0 ? Long.toString(CommentsActivity.this.parent_comment_id) : null;
}
CommentsActivity commentsActivity2 = CommentsActivity.this;
commentsActivity2.showNewCommentActivity(str, commentsActivity2.reply_to_user_name);
}
};
private final Callback callback_save = new Callback(this) {
@Override
public void error(Throwable th) {
super.error(th);
CommentsActivity.this.showProgressBar(false);
CommentsActivity.this.enableFieldAndButtonsInUI(true);
}
@Override
public void ready(Object obj) {
ArrayList arrayList = new ArrayList();
if (obj instanceof ArrayList) {
arrayList.addAll((ArrayList) obj);
} else {
arrayList.add((Long) obj);
}
if (arrayList.size() > 0) {
if (arrayList.size() == 2 && CommentsActivity.this.parent_comment_id == 0) {
CommentsActivity.this.refreshReplyInThread(((Long) arrayList.get(0)).longValue(), ((Long) arrayList.get(1)).longValue());
} else {
CommentsActivity.this.refreshInThread();
}
}
CommentsActivity.this.showProgressBar(false);
CommentsActivity.this.enableFieldAndButtonsInUI(true);
CommentsActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
CommentsActivity.this.editText.setText("");
}
});
CommentsActivity commentsActivity = CommentsActivity.this;
commentsActivity.reply_to_cid = null;
commentsActivity.reply_to_user_name = null;
commentsActivity.replyCids.clear();
CommentsActivity.this.replyUsers.clear();
}
};
final SmilePagerAdapter.SmileSelectedListener listener = new SmilePagerAdapter.SmileSelectedListener() {
@Override
public void backspace() {
SmileHelper.sendBackspace(CommentsActivity.this.editText);
}
@Override
public void selected(String str) {
CommentsActivity.this.addSmile(str);
}
@Override
public void stickerSelected(Integer num) {
CommentsActivity.this.send(num);
}
@Override
public void stickersConfigure() {
CommentsActivity.this.showMyStickersActivity();
}
};
SmilePagerAdapter.SmileSelectedListener stickerHintListener = new SmilePagerAdapter.SmileSelectedListener() {
@Override
public void stickerSelected(Integer num) {
CommentsActivity.this.send(num);
CommentsActivity.this.hideStickerHints();
}
};
public class AnonymousClass24 implements View.OnClickListener {
AnonymousClass24() {
}
public void lambda$onClick$0() {
CommentsActivity.this.send(null);
}
@Override
public void onClick(View view) {
ArrayList arrayList;
String obj = CommentsActivity.this.editText.getText().toString();
if (TextUtils.isEmpty(obj)) {
Toast.makeText(CommentsActivity.this.getApplicationContext(), (int) R.string.message_empty, 1).show();
return;
}
try {
if (CommentsActivity.this.getCorrectOwnerId() == -26062647) {
CommentsActivity commentsActivity = CommentsActivity.this;
if (commentsActivity.reply_to_cid == null && ((arrayList = commentsActivity.replyCids) == null || arrayList.size() == 0)) {
NewCommentActivity.reportEvent("ask");
AnswerType parse = AnswerParser.parse(obj);
if (parse != AnswerType.UNKNOWN) {
NewCommentActivity.reportEvent("answer_found");
NewCommentActivity.showAnswer(parse, new SimpleListener() {
@Override
public final void call() {
CommentsActivity.AnonymousClass24.this.lambda$onClick$0();
}
}, CommentsActivity.this);
return;
}
}
}
} catch (Throwable th) {
th.printStackTrace();
Helper.reportError(th);
}
CommentsActivity.this.send(null);
}
}
public void addSmile(String str) {
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(str);
SmileHelper.insertSmiles(this, str, spannableStringBuilder, false);
this.editText.getText().insert(this.editText.getSelectionEnd(), spannableStringBuilder);
}
private void checkLastPageSupport() {
int i = this.comment_type;
if (i != 4 && i != 1 && this.last_page) {
throw new RuntimeException("Last page not supported for this comment type yet. See downloadLastPage() method.");
}
}
public void checkStickerHints(String str) {
try {
if (StickerHints.getShowStickerHints()) {
if (KApplication.isTablet || getResources().getConfiguration().orientation != 2) {
int[] iArr = StickerHints.get(str.toLowerCase().trim(), this.account_id);
if (iArr == null || iArr.length == 0) {
hideStickerHints();
} else {
showStickerHints(iArr);
}
}
}
} catch (Throwable th) {
th.printStackTrace();
Helper.reportError(th);
}
}
private void clearEditText() {
EditText editText = this.editText;
if (editText != null) {
editText.setText("");
}
}
private void confirmRemoveRecentComments(final long j) {
if (!(j == Long.parseLong(KApplication.session.getMid())) && getCorrectOwnerId() <= 0) {
if (KApplication.db.isModerInGroup(Long.valueOf(Long.parseLong(KApplication.session.getMid())), -getCorrectOwnerId())) {
View inflate = LayoutInflater.from(this).inflate(R.layout.comment_moderation, (ViewGroup) null);
inflate.findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CommentsActivity.this.removeRecentComments(j);
}
});
inflate.findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Helper.showGroupBlockActivity(CommentsActivity.this.content_owner_id, j, CommentsActivity.this);
}
});
AlertDialog create = new AlertDialog.Builder(this).setTitle(R.string.label_my_groups).setView(inflate).setPositiveButton(R.string.close, (DialogInterface.OnClickListener) null).create();
create.setCanceledOnTouchOutside(true);
create.show();
}
}
}
public void copyLink(long j) {
Helper.copyText(getLink(j), this);
}
private void createStickerHintsPopup() {
View inflate = getLayoutInflater().inflate(R.layout.stickers_grid, (ViewGroup) null);
this.stickerHintsView = inflate;
StickerAdapter stickerAdapter = new StickerAdapter(new WeakReference(this.stickerHintListener), new WeakReference(this), new int[0]);
this.stickerHintsAdapter = stickerAdapter;
((GridView) inflate.findViewById(R.id.emoticons_grid)).setAdapter((ListAdapter) stickerAdapter);
this.stickerHintsWindow = new PopupWindow(this.stickerHintsView, -1, Helper.getDIP(75.0d), false);
}
public void displayContextMenu(final CommentTag commentTag) {
boolean z;
Comment comment;
final ArrayList arrayList;
final ArrayList arrayList2;
int i;
int i2;
if (commentTag == null) {
return;
}
try {
Long valueOf = Long.valueOf(Long.parseLong(KApplication.session.getMid()));
boolean z2 = false;
if (!valueOf.equals(Long.valueOf(commentTag.user_id))) {
long longValue = valueOf.longValue();
long j = this.content_owner_id;
if (longValue != j && j >= 0 && this.comment_type != 4) {
long j2 = commentTag.user_id;
if (j2 >= 0 || !KApplication.db.isAdminOrEditorInGroup(valueOf, -j2)) {
z = false;
comment = commentTag.comment;
if (comment != null && comment.deleted) {
z2 = true;
}
ArrayList extractUrl = Helper.extractUrl(commentTag.message, true);
arrayList = new ArrayList();
if (this.can_post && ((i2 = this.comment_type) == 1 || i2 == 4 || i2 == 0 || i2 == 2 || i2 == 5)) {
arrayList.add(new MenuItemDetails((int) R.string.label_replay, 4));
}
if (z2) {
int i3 = this.comment_type;
if (i3 == 1 || i3 == 4 || i3 == 0 || i3 == 2 || i3 == 5) {
if (commentTag.like) {
arrayList.add(new MenuItemDetails((int) R.string.i_dont_like, 6));
} else {
arrayList.add(new MenuItemDetails((int) R.string.i_like, 5));
}
}
arrayList.add(new MenuItemDetails((int) R.string.who_likes, 7));
arrayList.add(new MenuItemDetails((int) R.string.label_menu_send_to_friend, 17));
if (this.comment_type == 1) {
arrayList.add(new MenuItemDetails((int) R.string.publish_desc, 18));
}
if (commentTag.comment.reply_to_cid > 0) {
arrayList.add(new MenuItemDetails((int) R.string.reply_to_who, 15));
}
if (extractUrl.size() > 0) {
arrayList.add(new MenuItemDetails((int) R.string.links, 2));
}
arrayList.add(new MenuItemDetails((int) R.string.copy_text, 3));
if (Helper.isNotEmpty(commentTag.message)) {
arrayList.add(new MenuItemDetails((int) R.string.label_copy_part_text, 19));
}
arrayList.add(new MenuItemDetails((int) R.string.label_copy_video_link, 16));
if (valueOf.equals(Long.valueOf(commentTag.user_id)) || (this.comment_type == 4 && KApplication.db.isAdminOrEditorInGroup(valueOf, -getCorrectOwnerId()))) {
arrayList2 = extractUrl;
} else {
long j3 = this.content_owner_id;
arrayList2 = extractUrl;
if (j3 >= 0 || j3 != commentTag.user_id || !KApplication.db.isAdminOrEditorInGroup(valueOf, -getCorrectOwnerId())) {
long j4 = commentTag.user_id;
if (j4 < 0 && KApplication.db.isAdminOrEditorInGroup(valueOf, -j4)) {
}
if ((this.comment_type != 4 || this.content_owner_id < 0) && !valueOf.equals(Long.valueOf(commentTag.user_id)) && KApplication.db.isModerInGroup(valueOf, -getCorrectOwnerId())) {
arrayList.add(new MenuItemDetails((int) R.string.label_user_to_ban, 9));
}
if (z) {
arrayList.add(new MenuItemDetails((int) R.string.delete, 1));
}
i = this.comment_type;
if ((i != 1 || i == 0 || i == 2 || i == 5) && this.account_id != commentTag.user_id) {
arrayList.add(new MenuItemDetails((int) R.string.label_complain_report, 13));
}
}
}
arrayList.add(new MenuItemDetails((int) R.string.label_edit, 8));
if (this.comment_type != 4) {
}
arrayList.add(new MenuItemDetails((int) R.string.label_user_to_ban, 9));
if (z) {
}
i = this.comment_type;
if (i != 1) {
}
arrayList.add(new MenuItemDetails((int) R.string.label_complain_report, 13));
} else {
arrayList.add(new MenuItemDetails((int) R.string.label_copy_video_link, 16));
arrayList2 = extractUrl;
}
if (arrayList.size() != 0) {
return;
}
AlertDialog create = new AlertDialog.Builder(this).setItems(MenuItemDetails.toArray(arrayList), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i4) {
switch (((MenuItemDetails) arrayList.get(i4)).code) {
case 1:
CommentsActivity.this.confirmRemoveComment(Long.valueOf(commentTag.comment_id), commentTag.user_id);
return;
case 2:
Helper.displayLinksMenu(arrayList2, CommentsActivity.this);
return;
case 3:
Helper.copyText(commentTag.message, CommentsActivity.this);
return;
case 4:
CommentsActivity.this.reply(commentTag);
return;
case 5:
CommentsActivity.this.setLike(Long.valueOf(commentTag.comment_id), commentTag.comment, true);
return;
case 6:
CommentsActivity.this.setLike(Long.valueOf(commentTag.comment_id), commentTag.comment, false);
return;
case 7:
CommentsActivity.this.showLikes(commentTag.comment_id);
return;
case 8:
CommentsActivity commentsActivity = CommentsActivity.this;
CommentTag commentTag2 = commentTag;
commentsActivity.editComment(commentTag2.comment_id, commentTag2.comment);
return;
case 9:
Helper.showGroupBlockActivity(CommentsActivity.this.content_owner_id, commentTag.user_id, CommentsActivity.this);
return;
case 10:
case 11:
case 12:
case 14:
default:
return;
case 13:
if (CommentsActivity.this.comment_type == 0) {
new ReportHelper(CommentsActivity.this).showReportPhotoCommentDialog(commentTag.comment_id, CommentsActivity.this.content_owner_id);
return;
} else if (CommentsActivity.this.comment_type == 2) {
new ReportHelper(CommentsActivity.this).showReportVideoCommentDialog(commentTag.comment_id, CommentsActivity.this.content_owner_id);
return;
} else if (CommentsActivity.this.comment_type == 5) {
new ReportHelper(CommentsActivity.this).showReportMarketCommentDialog(commentTag.comment_id, CommentsActivity.this.content_owner_id);
return;
} else {
new ReportHelper(CommentsActivity.this).showReportPostCommentDialog(commentTag.comment_id, CommentsActivity.this.content_owner_id);
return;
}
case 15:
CommentsActivity commentsActivity2 = CommentsActivity.this;
Comment comment2 = commentTag.comment;
commentsActivity2.replyToWho(comment2.reply_to_cid, comment2.parent_stack);
return;
case 16:
CommentsActivity.this.copyLink(commentTag.comment.cid);
return;
case 17:
CommentsActivity.this.sendToFriend(commentTag.comment.cid);
return;
case 18:
new RepostHelper(CommentsActivity.this, null).createRepostDialog(commentTag.comment.cid, CommentsActivity.this.content_owner_id, 0L, false);
return;
case 19:
Helper.showTextDialogForCopy(commentTag.message, CommentsActivity.this);
return;
}
}
}).create();
create.setCanceledOnTouchOutside(true);
create.show();
return;
}
}
}
z = true;
comment = commentTag.comment;
if (comment != null) {
z2 = true;
}
ArrayList extractUrl2 = Helper.extractUrl(commentTag.message, true);
arrayList = new ArrayList();
if (this.can_post) {
arrayList.add(new MenuItemDetails((int) R.string.label_replay, 4));
}
if (z2) {
}
if (arrayList.size() != 0) {
}
} catch (Throwable th) {
Helper.reportError(th);
th.printStackTrace();
}
}
private void displayData() {
try {
CommentListAdapter commentListAdapter = new CommentListAdapter(this.commentDatas, this);
this.comment_list_adapter = commentListAdapter;
this.lv_comment_list.setAdapter((ListAdapter) commentListAdapter);
} catch (Exception e) {
Helper.reportError(e);
displayToast(e.getMessage());
e.printStackTrace();
}
}
private void displayFromCache() {
long nanoTime = System.nanoTime();
ArrayList fetchCommentList = KApplication.db.fetchCommentList(this.content_id, this.comment_type, this.content_owner_id, this.account_id);
Helper.reportDbReadDuration(nanoTime, "ca_fetchCommentList", null);
this.list.initFromCache(fetchCommentList);
requeryOnUiThread();
}
public void downloadCommentById() {
if (this.comment_type == 1) {
KApplication.session.getWallComment(this.content_owner_id, this.start_comment_id.longValue(), this.callback_get_comment, this);
}
}
public void downloadComments(int i, long j, Callback callback) {
int i2 = this.comment_type;
if (i2 == 1) {
KApplication.session.getWallComments(Long.valueOf(this.content_owner_id), Long.valueOf(this.content_id), i, 35, false, null, j, callback, this);
} else if (i2 == 0) {
KApplication.session.getPhotoComments(Long.valueOf(this.content_id), Long.valueOf(this.content_owner_id), i, 35, null, callback, this);
} else if (i2 == 3) {
KApplication.session.getNoteComments(Long.valueOf(this.content_id), Long.valueOf(this.content_owner_id), i, 35, callback, this);
} else if (i2 == 2) {
KApplication.session.getVideoComments(this.content_id, Long.valueOf(this.content_owner_id), i, 35, null, callback, this);
} else if (i2 == 4) {
KApplication.session.getGroupTopicComments(this.content_owner_id, this.content_id, 0, 0, 35, i, false, null, callback, this);
} else if (i2 == 5) {
KApplication.session.getMarketComments(Long.valueOf(this.content_owner_id), Long.valueOf(this.content_id), i, 35, null, callback, this);
}
}
public void downloadLastPage() {
if (this.comment_type == 4) {
KApplication.session.getGroupTopicComments(this.content_owner_id, this.content_id, 0, 0, 35, 0, true, null, this.callback_last_page, this);
}
if (this.comment_type == 1) {
KApplication.session.getWallComments(Long.valueOf(this.content_owner_id), Long.valueOf(this.content_id), 0, 35, true, null, 0L, this.callback_last_page, this);
}
}
public void downloadParentCommentById(final Comment comment) {
KApplication.session.getWallComment(this.content_owner_id, comment.parent_stack, new Callback(this) {
@Override
public void error(Throwable th) {
super.error(th);
CommentsActivity.this.showProgressBar(false);
}
@Override
public void ready(Object obj) {
boolean z;
Comment comment2 = (Comment) obj;
if (comment2 != null) {
Iterator<Comment> it = comment2.thread_comments.iterator();
while (true) {
if (!it.hasNext()) {
z = false;
break;
} else if (it.next().cid == comment.cid) {
z = true;
break;
}
}
if (!z) {
comment2.thread_comments.add(comment);
}
ArrayList arrayList = new ArrayList();
arrayList.add(comment2);
Helper.getMissingUsers(arrayList);
CommentList commentList = new CommentList();
commentList.count = 1;
commentList.comments = arrayList;
CommentsActivity.this.list.reset(commentList, 35, true);
CommentsActivity.this.requeryOnUiThread(true);
CommentsActivity.this.showProgressBar(false);
}
CommentsActivity.this.showProgressBar(false);
}
}, this);
}
public void editComment(long j, Comment comment) {
Intent intent = new Intent(this, NewCommentActivity.class);
intent.putExtra("com.perm.kate.edit", true);
intent.putExtra("com.perm.kate.cid", j);
intent.putExtra("com.perm.kate.pid", String.valueOf(this.content_id));
intent.putExtra("com.perm.kate.owner_id", String.valueOf(getCorrectOwnerId()));
intent.putExtra("com.perm.kate.comment_type", this.comment_type);
intent.putExtra("com.perm.kate.comment", comment);
startActivityForResult(intent, 2);
}
public void enableFieldAndButtonsInUI(final boolean z) {
runOnUiThread(new Runnable() {
@Override
public void run() {
CommentsActivity.this.sendButton.setEnabled(z);
}
});
}
public long getCorrectOwnerId() {
return this.comment_type == 4 ? -this.content_owner_id : this.content_owner_id;
}
private String getLink(long j) {
int i = this.comment_type;
String str = i == 4 ? "topic" : i == 0 ? "photo" : i == 2 ? "video" : i == 5 ? "product" : i == 1 ? "wall" : "";
String str2 = i == 4 ? "post" : "reply";
return "http://vk.com/" + str + getCorrectOwnerId() + "_" + this.content_id + "?" + str2 + "=" + j;
}
public void hideStickerHints() {
PopupWindow popupWindow = this.stickerHintsWindow;
if (popupWindow == null || !popupWindow.isShowing()) {
return;
}
this.stickerHintsWindow.dismiss();
}
public static boolean isGrouped() {
return PreferenceManager.getDefaultSharedPreferences(KApplication.current).getBoolean("comments_grouped", true);
}
public void refreshInThread() {
new Thread() {
@Override
public void run() {
CommentsActivity.this.showProgressBar(true);
CommentsActivity commentsActivity = CommentsActivity.this;
commentsActivity.downloadComments(commentsActivity.list.count, commentsActivity.parent_comment_id, CommentsActivity.this.callback_refresh);
}
}.start();
}
public void refreshReplyInThread(final long j, final long j2) {
if (this.comment_type != 1) {
return;
}
final Callback callback = new Callback(this) {
@Override
public void error(Throwable th) {
super.error(th);
CommentsActivity.this.showProgressBar(false);
}
@Override
public void ready(Object obj) {
CommentList commentList = (CommentList) obj;
CommentsActivity.this.showProgressBar(false);
if (commentList.comments.size() == 0) {
return;
}
Helper.getMissingUsers(commentList.comments);
CommentsActivity.this.list.addRepliesToComment(j2, commentList);
CommentsActivity.this.requeryOnUiThread();
}
};
new Thread() {
@Override
public void run() {
CommentsActivity.this.showProgressBar(true);
KApplication.session.getWallComments(Long.valueOf(CommentsActivity.this.content_owner_id), Long.valueOf(CommentsActivity.this.content_id), 0, 35, false, Long.valueOf(j), j2, callback, CommentsActivity.this);
}
}.start();
}
private void reloadInThread() {
new Thread() {
@Override
public void run() {
CommentsActivity.this.showProgressBar(true);
if (!CommentsActivity.this.last_page) {
CommentsActivity commentsActivity = CommentsActivity.this;
commentsActivity.downloadComments(0, commentsActivity.parent_comment_id, CommentsActivity.this.callback_reload);
} else if (CommentsActivity.this.start_comment_id.longValue() > 0) {
CommentsActivity.this.downloadCommentById();
} else {
CommentsActivity.this.downloadLastPage();
}
}
}.start();
}
public void removeRecentComments(final long j) {
new Thread() {
@Override
public void run() {
CommentsActivity commentsActivity = CommentsActivity.this;
commentsActivity.removed_posts = 0;
KApplication.session.deleteRecentWallComments(commentsActivity.getCorrectOwnerId(), j, new Callback(CommentsActivity.this) {
@Override
public void ready(Object obj) {
CommentsActivity commentsActivity2 = CommentsActivity.this;
commentsActivity2.removed_posts = (int) (commentsActivity2.removed_posts + ((Long) obj).longValue());
}
}, CommentsActivity.this);
KApplication.session.deleteRecentTopicComments(-CommentsActivity.this.getCorrectOwnerId(), j, new Callback(CommentsActivity.this) {
@Override
public void error(Throwable th) {
}
@Override
public void ready(Object obj) {
CommentsActivity commentsActivity2 = CommentsActivity.this;
commentsActivity2.removed_posts = (int) (commentsActivity2.removed_posts + ((Long) obj).longValue());
}
}, CommentsActivity.this);
CommentsActivity commentsActivity2 = CommentsActivity.this;
commentsActivity2.displayToast(CommentsActivity.this.getString(R.string.items_removed) + ": " + CommentsActivity.this.removed_posts);
}
}.start();
}
public void reply(CommentTag commentTag) {
String str;
try {
if (this.comment_type == 4 && this.reply_to_user_name != null && (str = this.reply_to_cid) != null) {
this.replyCids.add(str);
this.replyUsers.add(this.reply_to_user_name);
}
this.reply_to_cid = String.valueOf(commentTag.comment_id);
String str2 = commentTag.user_name;
if (str2 == null || str2.length() <= 0) {
Comment comment = commentTag.comment;
if (comment != null) {
long j = comment.from_id;
if (j > 0) {
User fetchUser = KApplication.db.fetchUser(j);
if (fetchUser != null) {
this.reply_to_user_name = fetchUser.first_name;
}
} else {
Group fetchGroup = KApplication.db.fetchGroup(j * (-1));
if (fetchGroup != null) {
this.reply_to_user_name = fetchGroup.name;
}
}
}
} else {
this.reply_to_user_name = commentTag.user_name;
}
String str3 = "";
if (this.reply_to_user_name != null) {
Iterator it = this.replyUsers.iterator();
while (it.hasNext()) {
String str4 = (String) it.next();
if (str4 != null && str4.length() > 0) {
str3 = str3 + str4 + ", ";
}
}
this.editText.setText(str3 + this.reply_to_user_name + ", ");
EditText editText = this.editText;
editText.setSelection(editText.getText().length());
} else {
this.editText.setText("");
}
this.editText.requestFocus();
this.editText.postDelayed(new Runnable() {
@Override
public void run() {
((InputMethodManager) CommentsActivity.this.getSystemService("input_method")).showSoftInput(CommentsActivity.this.editText, 0);
}
}, 200L);
} catch (Throwable th) {
th.printStackTrace();
Helper.reportError(th);
}
}
public void replyToWho(long j, long j2) {
Intent intent = new Intent();
intent.setClass(this, CommentRepliesActivity.class);
intent.putExtra("comment_id", j);
intent.putExtra("content_id", this.content_id);
intent.putExtra("content_owner_id", this.content_owner_id);
intent.putExtra("content_type", this.comment_type);
intent.putExtra("parent_comment_id", j2);
startActivity(intent);
}
public void requeryOnUiThread() {
requeryOnUiThread(false);
}
public void requeryOnUiThread(final boolean z) {
runOnUiThread(new Runnable() {
@Override
public void run() {
CommentsActivity commentsActivity = CommentsActivity.this;
commentsActivity.commentDatas = commentsActivity.list.getComments();
CommentListAdapter commentListAdapter = CommentsActivity.this.comment_list_adapter;
CommentsActivity commentsActivity2 = CommentsActivity.this;
commentListAdapter.list = commentsActivity2.commentDatas;
commentsActivity2.comment_list_adapter.notifyDataSetChanged();
if (z) {
CommentsActivity.this.scrollToEnd();
}
}
});
}
public void scrollToEnd() {
this.lv_comment_list.setSelection(this.commentDatas.size() - 1);
}
public void send(final Integer num) {
String str;
final String obj = this.editText.getText().toString();
if (this.comment_type == 4 && this.reply_to_cid != null && (str = this.reply_to_user_name) != null && str.length() > 0) {
for (int i = 0; i < this.replyUsers.size(); i++) {
String str2 = (String) this.replyUsers.get(i);
obj = obj.replace(str2 + ",", "[post" + ((String) this.replyCids.get(i)) + "|" + str2 + "],");
}
obj = obj.replace(this.reply_to_user_name + ",", "[post" + this.reply_to_cid + "|" + this.reply_to_user_name + "],");
}
enableFieldAndButtonsInUI(false);
showProgressBar(true);
new Thread() {
@Override
public void run() {
CommentsActivity commentsActivity = CommentsActivity.this;
String str3 = commentsActivity.reply_to_cid;
NewCommentActivity.createComment(CommentsActivity.this.comment_type, Long.valueOf(CommentsActivity.this.getCorrectOwnerId()), Long.valueOf(CommentsActivity.this.content_id), obj, str3 != null ? Long.valueOf(Long.parseLong(str3)) : commentsActivity.parent_comment_id > 0 ? Long.valueOf(CommentsActivity.this.parent_comment_id) : null, null, num, CommentsActivity.this.callback_save, CommentsActivity.this);
}
}.start();
}
public void sendToFriend(long j) {
String link = getLink(j);
Intent intent = new Intent();
intent.setClass(this, MembersActivity.class);
intent.putExtra("com.perm.kate.only_members", false);
intent.putExtra("com.perm.kate.new_message", true);
intent.putExtra("shared_text", link);
startActivity(intent);
}
private static void setGrouped(boolean z) {
PreferenceManager.getDefaultSharedPreferences(KApplication.current).edit().putBoolean("comments_grouped", z).apply();
}
public void showAllReplies(long j) {
Intent intent = new Intent();
intent.setClass(this, CommentsActivity.class);
intent.putExtra("com.perm.kate.current_owner_id", this.content_owner_id);
intent.putExtra("com.perm.kate.current_photo_pid", this.content_id);
intent.putExtra("com.perm.kate.comment_type", this.comment_type);
intent.putExtra("parent_comment_id", j);
startActivity(intent);
}
public void showLikes(long j) {
Intent intent = new Intent();
intent.setClass(this, LikesActivity.class);
intent.putExtra("com.perm.kate.item_id", j);
intent.putExtra("com.perm.kate.owner_id", getCorrectOwnerId());
int i = this.comment_type;
intent.putExtra("com.perm.kate.item_type", i == 4 ? "topic_comment" : i == 0 ? "photo_comment" : i == 2 ? "video_comment" : i == 5 ? "market_comment" : "comment");
startActivity(intent);
}
public void showMyStickersActivity() {
Intent intent = new Intent();
intent.setClass(this, MyStickersActivity.class);
startActivityForResult(intent, 3);
}
public void showNewCommentActivity(String str, String str2) {
Intent intent = new Intent();
intent.setClass(this, NewCommentActivity.class);
intent.putExtra("com.perm.kate.pid", String.valueOf(this.content_id));
intent.putExtra("com.perm.kate.owner_id", String.valueOf(getCorrectOwnerId()));
intent.putExtra("com.perm.kate.comment_type", this.comment_type);
intent.putExtra("com.perm.kate.reply_to_cid", str);
intent.putExtra("com.perm.kate.reply_to_user_name", str2);
String obj = this.editText.getText().toString();
if (!TextUtils.isEmpty(str2)) {
Iterator it = this.replyUsers.iterator();
while (it.hasNext()) {
obj = obj.replace(((String) it.next()) + ", ", "");
}
obj = obj.replace(str2 + ", ", "");
}
intent.putExtra("text", obj);
if (this.comment_type == 4) {
intent.putStringArrayListExtra("com.perm.kate.replyCids", this.replyCids);
intent.putStringArrayListExtra("com.perm.kate.replyUsers", this.replyUsers);
}
startActivityForResult(intent, 0);
}
private void showStickerHints(int[] iArr) {
if (this.editText.getWindowToken() == null || PreferenceManager.getDefaultSharedPreferences(this).getBoolean("key_fullscreen", false)) {
return;
}
if (this.stickerHintsWindow == null) {
createStickerHintsPopup();
}
if (!this.stickerHintsWindow.isShowing()) {
this.stickerHintsWindow.showAsDropDown(this.editText, 0, -Helper.getDIP(110.0d));
}
StickerAdapter stickerAdapter = this.stickerHintsAdapter;
stickerAdapter.ids = iArr;
stickerAdapter.notifyDataSetChanged();
}
void confirmRemoveComment(final Long l, final long j) {
AlertDialog create = new AlertDialog.Builder(this).setMessage(R.string.label_confirm_delete).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
CommentsActivity.this.removeComment(l, j);
}
}).setNegativeButton(R.string.no, (DialogInterface.OnClickListener) null).create();
create.setCanceledOnTouchOutside(true);
create.show();
}
@Override
protected boolean fillMenuItems(Menu menu) {
menu.add(0, 23, 500, R.string.refresh);
menu.add(0, 56, 1000, R.string.label_down_to_end);
if (this.is_new) {
MenuItem add = menu.add(0, 3, 1000, R.string.sort_by_date);
add.setCheckable(true);
add.setChecked(this.is_sorted_by_date);
add.setEnabled(!this.is_sorted);
} else {
MenuItem add2 = menu.add(0, 1, 1000, R.string.group_replies);
add2.setCheckable(true);
add2.setChecked(this.is_grouped);
add2.setEnabled(!this.is_sorted);
}
MenuItem add3 = menu.add(0, 2, 1000, R.string.sort_by_likes);
add3.setCheckable(true);
add3.setChecked(this.is_sorted);
return true;
}
@Override
public void onActivityResult(int i, int i2, Intent intent) {
long j;
long j2;
super.onActivityResult(i, i2, intent);
if (i == 0 && i2 == -1) {
this.replyCids.clear();
this.replyUsers.clear();
clearEditText();
if (intent != null) {
j = intent.getLongExtra("comment_id", 0L);
j2 = intent.getLongExtra("parent_comment_id", 0L);
} else {
j = 0;
j2 = 0;
}
if (j == 0 || j2 == 0 || this.parent_comment_id != 0) {
refreshInThread();
} else {
refreshReplyInThread(j, j2);
}
}
if (i == 2 && i2 == -1) {
reloadInThread();
}
if (i == 3) {
this.smileKeyboard.updatePages(intent != null ? intent.getIntExtra("index", -1) : -1);
}
}
@Override
public void onConfigurationChanged(Configuration configuration) {
super.onConfigurationChanged(configuration);
hideStickerHints();
}
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.comments_list);
setHeaderTitle(R.string.label_menu_comments);
setupMenuButton();
setupRefreshButton();
setupSearchButton();
ListView listView = (ListView) findViewById(R.id.lv_comment_list);
this.lv_comment_list = listView;
listView.setOnItemClickListener(this.onItemClickListener);
this.content_owner_id = getIntent().getLongExtra("com.perm.kate.current_owner_id", 0L);
this.content_id = getIntent().getLongExtra("com.perm.kate.current_photo_pid", 0L);
this.comment_type = getIntent().getIntExtra("com.perm.kate.comment_type", 0);
this.last_page = getIntent().getBooleanExtra("last_page", false);
this.can_post = getIntent().getBooleanExtra("can_post", true);
long longExtra = getIntent().getLongExtra("parent_comment_id", 0L);
this.parent_comment_id = longExtra;
this.is_new = this.comment_type == 1 && longExtra == 0;
this.start_comment_id = Long.valueOf(getIntent().getLongExtra("start_comment_id", 0L));
if (!this.can_post) {
findViewById(R.id.add_comment_view).setVisibility(8);
}
checkLastPageSupport();
PageCommentList pageCommentList = new PageCommentList() {
@Override
public void downloadComments(int i, Callback callback) {
CommentsActivity commentsActivity = CommentsActivity.this;
commentsActivity.downloadComments(i, commentsActivity.parent_comment_id, callback);
}
};
this.list = pageCommentList;
pageCommentList.addEventsListener(this.listChangeListener);
PageCommentList pageCommentList2 = this.list;
pageCommentList2.is_grouped = this.is_grouped;
pageCommentList2.is_new = this.is_new;
displayData();
try {
if (!this.last_page && !this.is_new) {
displayFromCache();
}
reloadInThread();
} catch (Exception e) {
Helper.reportError(e);
Toast.makeText(getApplicationContext(), e.getMessage(), 1).show();
e.printStackTrace();
}
ImageButton imageButton = (ImageButton) findViewById(R.id.btn_new_message);
this.sendButton = imageButton;
imageButton.setOnClickListener(this.sendClick);
findViewById(R.id.btn_add_attachment).setOnClickListener(this.addAttachmentClick);
EditText editText = (EditText) findViewById(R.id.et_new_message);
this.editText = editText;
if (BaseActivity.Theme == R.style.KateTransparent) {
editText.setBackgroundResource(R.drawable.d_empty);
}
this.editText.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable editable) {
CommentsActivity.this.checkStickerHints(editable.toString());
}
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
});
SmileKeyboard smileKeyboard = new SmileKeyboard();
this.smileKeyboard = smileKeyboard;
smileKeyboard.init(this, findViewById(R.id.smile_button), this.listener, this.comment_type != 3);
this.smileKeyboard.registerEditText(this.editText);
StickerHints.initIfRequired(this.account_id, this);
MiniPlayer miniPlayer = (MiniPlayer) findViewById(R.id.mini_player);
this.player = miniPlayer;
if (miniPlayer != null) {
miniPlayer.setActive(false);
}
}
@Override
public void onDestroy() {
CommentListAdapter commentListAdapter = this.comment_list_adapter;
if (commentListAdapter != null) {
commentListAdapter.Destroy();
}
PopupWindow popupWindow = this.stickerHintsWindow;
if (popupWindow != null) {
popupWindow.dismiss();
}
this.stickerHintsWindow = null;
this.stickerHintsView = null;
this.stickerHintListener = null;
this.stickerHintsAdapter = null;
MiniPlayer miniPlayer = this.player;
if (miniPlayer != null) {
miniPlayer.destroy();
}
this.player = null;
super.onDestroy();
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
int itemId = menuItem.getItemId();
if (itemId == 1) {
boolean z = !this.is_grouped;
this.is_grouped = z;
setGrouped(z);
this.list.is_grouped = this.is_grouped;
requeryOnUiThread();
return true;
} else if (itemId == 2) {
boolean z2 = !this.is_sorted;
this.is_sorted = z2;
this.list.is_sorted = z2;
requeryOnUiThread();
return true;
} else if (itemId == 3) {
boolean z3 = !this.is_sorted_by_date;
this.is_sorted_by_date = z3;
this.list.is_sorted_by_date = z3;
requeryOnUiThread();
return true;
} else if (itemId == 23) {
reloadInThread();
return true;
} else if (itemId != 56) {
return super.onOptionsItemSelected(menuItem);
} else {
scrollToEnd();
return true;
}
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
menu.clear();
fillMenuItems(menu);
return super.onPrepareOptionsMenu(menu);
}
@Override
protected void onRefreshButton() {
refreshInThread();
}
@Override
protected void onSearchButton() {
Intent intent = new Intent();
intent.setClass(this, CommentsSearchActivity.class);
intent.putExtra("com.perm.kate.current_owner_id", this.content_owner_id);
intent.putExtra("com.perm.kate.current_photo_pid", this.content_id);
intent.putExtra("com.perm.kate.comment_type", this.comment_type);
startActivity(intent);
}
protected void removeComment(final Long l, long j) {
showProgressBar(true);
final Callback callback = new Callback(this) {
@Override
public void error(Throwable th) {
super.error(th);
CommentsActivity.this.showProgressBar(false);
}
@Override
public void ready(Object obj) {
CommentsActivity.this.showProgressBar(false);
if (((Boolean) obj).booleanValue()) {
KApplication.db.deleteComment(CommentsActivity.this.content_id, CommentsActivity.this.comment_type, CommentsActivity.this.content_owner_id, l.longValue());
Comment comment = CommentsActivity.this.list.getComment(l);
if (comment != null) {
CommentsActivity commentsActivity = CommentsActivity.this;
if (!commentsActivity.is_new || comment.thread_count <= 0) {
commentsActivity.list.deleteComment(l);
} else {
comment.deleted = true;
comment.from_id = 0L;
comment.message = "";
comment.attachments.clear();
comment.like_count = 0;
}
} else {
CommentsActivity.this.list.deleteComment(l);
}
CommentsActivity.this.requeryOnUiThread();
}
}
};
new Thread() {
@Override
public void run() {
if (CommentsActivity.this.comment_type == 1) {
KApplication.session.deleteWallComment(Long.valueOf(CommentsActivity.this.content_owner_id), l.longValue(), callback, CommentsActivity.this);
} else if (CommentsActivity.this.comment_type == 0) {
KApplication.session.deletePhotoComment(CommentsActivity.this.content_id, Long.valueOf(CommentsActivity.this.content_owner_id), l.longValue(), callback, CommentsActivity.this);
} else if (CommentsActivity.this.comment_type == 3) {
KApplication.session.deleteNoteComment(Long.valueOf(CommentsActivity.this.content_owner_id), l.longValue(), callback, CommentsActivity.this);
} else if (CommentsActivity.this.comment_type == 2) {
KApplication.session.deleteVideoComment(Long.valueOf(CommentsActivity.this.content_owner_id), l.longValue(), callback, CommentsActivity.this);
} else if (CommentsActivity.this.comment_type == 4) {
KApplication.session.deleteGroupTopicComment(CommentsActivity.this.content_owner_id, CommentsActivity.this.content_id, l.longValue(), callback, CommentsActivity.this);
}
if (CommentsActivity.this.comment_type == 5) {
KApplication.session.deleteMarketComment(Long.valueOf(CommentsActivity.this.content_owner_id), l.longValue(), callback, CommentsActivity.this);
}
}
}.start();
confirmRemoveRecentComments(j);
}
void setLike(final Long l, final Comment comment, final boolean z) {
final Callback callback = new Callback(this) {
@Override
public void error(Throwable th) {
super.error(th);
if (th instanceof KException) {
int i = ((KException) th).error_code;
if (i == 230 || i == 231) {
KApplication.db.updateCommentLikes(l.longValue(), CommentsActivity.this.content_id, CommentsActivity.this.content_owner_id, CommentsActivity.this.comment_type, null, z, CommentsActivity.this.account_id);
CommentsActivity.this.requeryOnUiThread();
}
}
}
@Override
public void ready(Object obj) {
KApplication.db.updateCommentLikes(l.longValue(), CommentsActivity.this.content_id, CommentsActivity.this.content_owner_id, CommentsActivity.this.comment_type, (Long) obj, z, CommentsActivity.this.account_id);
Comment comment2 = comment;
boolean z2 = z;
comment2.user_like = z2;
if (z2) {
comment2.like_count++;
} else {
comment2.like_count--;
}
CommentsActivity.this.requeryOnUiThread();
}
};
new Thread() {
@Override
public void run() {
Long valueOf = Long.valueOf(CommentsActivity.this.getCorrectOwnerId());
int i = CommentsActivity.this.comment_type;
String str = i != 0 ? i != 2 ? i != 4 ? i != 5 ? "comment" : "market_comment" : "topic_comment" : "video_comment" : "photo_comment";
if (z) {
KApplication.session.addLike(valueOf, l, str, null, callback, CommentsActivity.this);
} else {
KApplication.session.deleteLike(valueOf, str, l, callback, CommentsActivity.this);
}
}
}.start();
}
}