Просмотр исходного кода

修复表情包没有显示完的bug;
表情包的内容在需要显示的时候转换

zengjiebin лет назад: 7
Родитель
Сommit
5289bb2880

+ 13 - 1
app/src/main/java/com/lqr/emoji/EmotionLayout.java

@@ -91,7 +91,7 @@ public class EmotionLayout extends LinearLayout implements View.OnClickListener
             //组装图片数据
             List<String> pngList = new ArrayList<>(perPageCount);
             for (int j = 0; j < perPageCount; j++) {
-                int index = i * EMOJI_COLUMNS + j;
+                int index = i * ( perPageCount - 1) + j;
                 if (index + 1 >= totalCount) {
                     break;
                 }
@@ -188,6 +188,18 @@ public class EmotionLayout extends LinearLayout implements View.OnClickListener
             String replaceContent = String.format(Locale.CHINA, "<img src=\"%s\" />", tagToNameMap.get(pngTag));
             content = content.replaceAll(String.format(Locale.CHINA, "\\[%s\\]", pngTag), replaceContent);
         }
+        content = content.replaceAll("\n", "<br>");//替换换行
         return content;
     }
+    //转换内容
+    public static boolean hasExp(String content) {
+        if(content != null && content.contains("[")) {
+            for (String pngTag : PNG_TAGS) {
+                if (content.contains(String.format(Locale.CHINA, "[%s]", pngTag))) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
 }

+ 9 - 0
app/src/main/java/com/sheep/gamegroup/model/entity/ShowAll.java

@@ -13,10 +13,19 @@ public class ShowAll {
     }
 
     private boolean yes;
+    private boolean hasExp;//是否包含表情
     private int canShowAllState;//0 初始状态, 1, false, 2 true
     private String content;
     private String showAllText = "显示全部";
 
+    public boolean isHasExp() {
+        return hasExp;
+    }
+
+    public void setHasExp(boolean hasExp) {
+        this.hasExp = hasExp;
+    }
+
     public boolean isYes() {
         return yes;
     }

+ 7 - 2
app/src/main/java/com/sheep/gamegroup/model/entity/UserCommentReply.java

@@ -1,6 +1,8 @@
 package com.sheep.gamegroup.model.entity;
 
 
+import com.lqr.emoji.EmotionLayout;
+
 /**
  * Created by realicing on 2018/11/2.
  * realicing@sina.com
@@ -123,8 +125,11 @@ public class UserCommentReply {
 
     private ShowAll showAll;
     public ShowAll getShowAll() {
-        if(showAll == null)
-            showAll = new ShowAll(content);
+        if(showAll == null) {
+            boolean hasExp = EmotionLayout.hasExp(content);
+            showAll = new ShowAll(hasExp ? EmotionLayout.changeContent(content) : content);
+            showAll.setHasExp(hasExp);
+        }
         return showAll;
     }
 }

+ 4 - 2
app/src/main/java/com/sheep/gamegroup/util/TextViewUtil.java

@@ -44,13 +44,15 @@ public class TextViewUtil {
 
     //初始化文本介绍,必须有 intro_content 和 intro_show_all
     public static void initIntroView(View itemView, final ShowAll showAll) {
-        String text = showAll.getContent();
         final TextView intro_content = itemView.findViewById(showAll.getIntroContentId());
         final TextView intro_show_all = itemView.findViewById(showAll.getIntroShowAllId());
         final View intro_show_all_no = itemView.findViewById(showAll.getIntroShowAllNoId());
         boolean isFirst = showAll.isFirst();
 
-        ViewUtil.setH5ImgText(intro_content, text);
+        if(showAll.isHasExp())
+            ViewUtil.setH5ImgText(intro_content, showAll.getContent());
+        else
+            ViewUtil.setText(intro_content, showAll.getContent());
         if (isFirst) {
             intro_content.setMaxLines(showAll.getMaxLine());
             TextViewUtil.listenEllipsizeChange(intro_content, new Action1<Integer>() {

+ 0 - 1
app/src/main/java/com/sheep/gamegroup/util/ViewUtil.java

@@ -920,7 +920,6 @@ public class ViewUtil {
                 textView.setText("");
                 return;
             }
-            content = content.replaceAll("\n", "<br>");//替换换行
             textView.setText(Html.fromHtml(content, new ResImageGetter(textView), null));
         }
     }

+ 1 - 2
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtUserCommentDetail.java

@@ -112,8 +112,7 @@ public class FgtUserCommentDetail extends BaseListFragment3<UserCommentReply> {
             @Override
             public void onClick(View view) {
                 String content = input_comment_input.getText().toString();
-                String changeContent = EmotionLayout.changeContent(content);
-                commitContent(changeContent, !TextUtils.equals(content, changeContent));
+                commitContent(content, EmotionLayout.hasExp(content));
             }
         });
         //初始化 表情键盘协调工具