package X; import android.content.Context; import android.graphics.Paint; import android.graphics.Rect; import android.widget.EditText; import com.bytedance.covode.number.Covode; import com.ss.android.ugc.aweme.editSticker.text.bean.InteractTextStructWrap; import com.ss.android.ugc.aweme.editSticker.text.bean.TextStickerString; import com.ss.android.ugc.aweme.editSticker.text.bean.TextStickerTextPair; import com.ss.android.ugc.aweme.editSticker.text.bean.TextStickerTextUnderlineIndexRange; import com.ss.android.ugc.aweme.editSticker.text.bean.TextStickerTextWrap; import com.ss.android.ugc.aweme.sticker.data.CreateAnchorInfo; import com.ss.android.ugc.aweme.sticker.data.InteractStickerStruct; import com.ss.android.ugc.aweme.sticker.data.TextStruct; import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Objects; import kotlin.g.b.m; import org.json.JSONObject; /* renamed from: X.5DW reason: invalid class name */ public final class AnonymousClass5DW { public static int LIZ; static { Covode.recordClassIndex(64773); } public static final float LIZ(Context context) { C21090sc.LIZ(context); return C132265Hz.LIZ(context, 4.0f); } public static final int LIZ(Paint paint, String str, int i2, int i3) { C21090sc.LIZ(paint); if (str == null || str.length() == 0 || i2 < 0 || i3 > str.length() || i2 >= i3) { return 0; } Objects.requireNonNull(str, "null cannot be cast to non-null type java.lang.String"); String substring = str.substring(i2, i3); m.LIZIZ(substring, ""); int length = substring.length(); float[] fArr = new float[length]; paint.getTextWidths(substring, fArr); int i4 = 0; for (int i5 = 0; i5 < length; i5++) { i4 += (int) Math.ceil((double) fArr[i5]); } return i4; } public static final TextStickerTextWrap LIZ(EditText editText, List<InteractTextStructWrap> list) { if (editText == null) { return new TextStickerTextWrap(null, null, 0, false, false, 31, null); } String obj = editText.getText().toString(); LinkedHashMap linkedHashMap = new LinkedHashMap(); int lineCount = editText.getLineCount(); int i2 = 0; int i3 = 0; while (i2 < lineCount) { int lineEnd = editText.getLayout().getLineEnd(i2); Objects.requireNonNull(obj, "null cannot be cast to non-null type java.lang.String"); String substring = obj.substring(i3, lineEnd); m.LIZIZ(substring, ""); TextStickerString textStickerString = new TextStickerString(substring); ArrayList arrayList = new ArrayList(); if (list != null) { for (T t : list) { if (t.getRange().getStart() < lineEnd && t.getRange().getEnd() > i3) { if (i3 >= t.getRange().getStart() && lineEnd <= t.getRange().getEnd()) { arrayList.add(new InteractTextStructWrap(new TextStickerTextUnderlineIndexRange(i3 - i3, lineEnd - i3), CreateAnchorInfo.copy$default(t.getStruct(), 0, null, null, null, null, null, null, null, null, null, null, null, 4095, null))); } else if (i3 >= t.getRange().getStart() && lineEnd > t.getRange().getEnd()) { arrayList.add(new InteractTextStructWrap(new TextStickerTextUnderlineIndexRange(i3 - i3, t.getRange().getEnd() - i3), CreateAnchorInfo.copy$default(t.getStruct(), 0, null, null, null, null, null, null, null, null, null, null, null, 4095, null))); } else if (i3 < t.getRange().getStart() && lineEnd <= t.getRange().getEnd()) { arrayList.add(new InteractTextStructWrap(new TextStickerTextUnderlineIndexRange(t.getRange().getStart() - i3, lineEnd - i3), CreateAnchorInfo.copy$default(t.getStruct(), 0, null, null, null, null, null, null, null, null, null, null, null, 4095, null))); } else if (i3 < t.getRange().getStart() && lineEnd > t.getRange().getEnd()) { arrayList.add(new InteractTextStructWrap(new TextStickerTextUnderlineIndexRange(t.getRange().getStart() - i3, t.getRange().getEnd() - i3), CreateAnchorInfo.copy$default(t.getStruct(), 0, null, null, null, null, null, null, null, null, null, null, null, 4095, null))); } } } } if (arrayList.size() > 1) { AnonymousClass1ZP.LIZ((List) arrayList, (Comparator) new C130815Ck()); } linkedHashMap.put(textStickerString, arrayList); editText.getLayout().getLineBounds(i2, new Rect()); i2++; i3 = lineEnd; } ArrayList arrayList2 = new ArrayList(); if (list != null) { Iterator<T> it = list.iterator(); while (it.hasNext()) { arrayList2.add(InteractTextStructWrap.copy$default(it.next(), null, null, 3, null)); } } return new TextStickerTextWrap(linkedHashMap, new TextStickerTextPair(obj, arrayList2), editText.getSelectionStart(), editText.hasFocus(), false, 16, null); } public static final TextStickerTextWrap LIZ(String str, boolean z) { if (str == null || str.length() == 0) { return new TextStickerTextWrap(null, null, 0, false, false, 31, null); } LinkedHashMap linkedHashMap = new LinkedHashMap(); linkedHashMap.put(new TextStickerString(str), new ArrayList()); return new TextStickerTextWrap(linkedHashMap, new TextStickerTextPair(str, new ArrayList()), 0, false, z, 12, null); } public static final TextStickerTextWrap LIZ(String[] strArr) { if (strArr == null || strArr.length == 0) { return new TextStickerTextWrap(null, null, 0, false, false, 31, null); } LinkedHashMap linkedHashMap = new LinkedHashMap(); StringBuilder sb = new StringBuilder(); for (String str : strArr) { sb.append(str); linkedHashMap.put(new TextStickerString(str), new ArrayList()); } String sb2 = sb.toString(); m.LIZIZ(sb2, ""); return new TextStickerTextWrap(linkedHashMap, new TextStickerTextPair(sb2, new ArrayList()), 0, false, false, 28, null); } public static final List<TextStickerTextWrap> LIZ(String str) { return AnonymousClass1ZP.LIZLLL(LIZ(str, false)); } public static final void LIZ(List<InteractTextStructWrap> list, int i2, int i3) { if (list != null) { for (T t : list) { if (t.getRange().getStart() >= i2 && i3 != 0) { TextStickerTextUnderlineIndexRange range = t.getRange(); range.setStart(range.getStart() + i3); TextStickerTextUnderlineIndexRange range2 = t.getRange(); range2.setEnd(range2.getEnd() + i3); } } } } public static final void LIZ(List<InteractTextStructWrap> list, InteractTextStructWrap interactTextStructWrap) { if (list.remove(interactTextStructWrap)) { int end = interactTextStructWrap.getRange().getEnd() - interactTextStructWrap.getRange().getStart(); for (T t : list) { if (t.getRange().getStart() >= interactTextStructWrap.getRange().getEnd()) { TextStickerTextUnderlineIndexRange range = t.getRange(); range.setStart(range.getStart() - end); TextStickerTextUnderlineIndexRange range2 = t.getRange(); range2.setEnd(range2.getEnd() - end); } } } } public static final boolean LIZ(List<TextStickerTextWrap> list) { if (list == null || list.isEmpty()) { return false; } Iterator<T> it = list.iterator(); while (true) { if (!it.hasNext()) { break; } T next = it.next(); if (!next.isReplaceString()) { if (next != null) { return false; } } } return true; } public static final boolean LIZ(List<InteractTextStructWrap> list, int i2) { if (list == null || list.isEmpty()) { return false; } Iterator<T> it = list.iterator(); while (true) { if (!it.hasNext()) { break; } T next = it.next(); if (next.isValid(i2)) { if (next != null) { return true; } } } return false; } public static final TextStickerString[] LIZIZ(List<TextStickerTextWrap> list) { if (list == null || list.isEmpty()) { return new TextStickerString[0]; } if (list.size() == 1) { Object[] array = list.get(0).getStrMap().keySet().toArray(new TextStickerString[0]); Objects.requireNonNull(array, "null cannot be cast to non-null type kotlin.Array<T>"); return (TextStickerString[]) array; } Iterator<T> it = list.iterator(); while (true) { if (!it.hasNext()) { break; } T next = it.next(); T t = next; if (!t.isReplaceString()) { String text = t.getText(); Objects.requireNonNull(text, "null cannot be cast to non-null type kotlin.CharSequence"); if (AnonymousClass1ZS.LIZIZ((CharSequence) text).toString().length() > 0) { if (next != null) { ArrayList arrayList = new ArrayList(); ArrayList<TextStickerTextWrap> arrayList2 = new ArrayList(); for (T t2 : list) { T t3 = t2; if (!t3.isReplaceString()) { String text2 = t3.getText(); Objects.requireNonNull(text2, "null cannot be cast to non-null type kotlin.CharSequence"); if (AnonymousClass1ZS.LIZIZ((CharSequence) text2).toString().length() > 0) { arrayList2.add(t2); } } } for (TextStickerTextWrap textStickerTextWrap : arrayList2) { arrayList.addAll(textStickerTextWrap.getStrMap().keySet()); } Object[] array2 = arrayList.toArray(new TextStickerString[0]); Objects.requireNonNull(array2, "null cannot be cast to non-null type kotlin.Array<T>"); return (TextStickerString[]) array2; } } } } Object[] array3 = list.get(0).getStrMap().keySet().toArray(new TextStickerString[0]); Objects.requireNonNull(array3, "null cannot be cast to non-null type kotlin.Array<T>"); return (TextStickerString[]) array3; } public static final String LIZJ(List<TextStickerTextWrap> list) { int i2 = 0; if (list == null || list.isEmpty()) { return ""; } ArrayList arrayList = new ArrayList(); for (T t : list) { if (t.isValid()) { arrayList.add(t); } } ArrayList arrayList2 = arrayList; if (!(!arrayList2.isEmpty()) || arrayList2 == null) { return ""; } StringBuilder sb = new StringBuilder(""); if (arrayList2.size() > 1) { int size = arrayList2.size() - 2; if (size >= 0) { while (true) { sb.append(((TextStickerTextWrap) arrayList2.get(i2)).safeStrPair().LIZ); sb.append("\n"); if (i2 == size) { break; } i2++; } } sb.append(((TextStickerTextWrap) arrayList2.get(arrayList2.size() - 1)).safeStrPair().LIZ); } else { sb.append(((TextStickerTextWrap) arrayList2.get(0)).safeStrPair().LIZ); } String sb2 = sb.toString(); m.LIZIZ(sb2, ""); return sb2; } public static final List<InteractTextStructWrap> LIZLLL(List<TextStickerTextWrap> list) { if (list == null || list.isEmpty()) { return new ArrayList(); } ArrayList arrayList = new ArrayList(); for (T t : list) { if (t.isValid()) { arrayList.add(t); } } ArrayList arrayList2 = arrayList; if (!(!arrayList2.isEmpty()) || arrayList2 == null) { return new ArrayList(); } if (arrayList2.size() == 1) { return ((TextStickerTextWrap) arrayList2.get(0)).safeStrPair().LIZIZ; } int size = arrayList2.size(); for (int i2 = 1; i2 < size; i2++) { for (T t2 : ((TextStickerTextWrap) arrayList2.get(i2)).safeStrPair().LIZIZ) { t2.getRange().getStart(); t2.getRange().getEnd(); } } ArrayList arrayList3 = new ArrayList(); Iterator<T> it = list.iterator(); while (it.hasNext()) { AnonymousClass1ZP.LIZ((Collection) arrayList3, (Iterable) it.next().safeStrPair().LIZIZ); } return arrayList3; } public static final boolean LJ(List<TextStickerTextWrap> list) { if (list == null) { return false; } Iterator<T> it = list.iterator(); while (true) { if (!it.hasNext()) { break; } T next = it.next(); if (next.isValid()) { if (next != null) { return true; } } } return false; } public static final List<CreateAnchorInfo> LJFF(List<TextStickerTextWrap> list) { ArrayList arrayList = new ArrayList(); if (list == null) { return new ArrayList(); } Iterator<T> it = list.iterator(); while (it.hasNext()) { arrayList.addAll(it.next().getAnchorInfoList()); } return arrayList; } public static final boolean LJI(List<TextStickerTextWrap> list) { if (list == null) { return false; } Iterator<T> it = list.iterator(); while (true) { if (!it.hasNext()) { break; } T next = it.next(); if (!next.safeStrPair().LIZIZ.isEmpty()) { if (next != null) { return true; } } } return false; } public static final boolean LJII(List<TextStickerTextWrap> list) { C21090sc.LIZ(list); Iterator<T> it = list.iterator(); while (true) { if (!it.hasNext()) { break; } T next = it.next(); String str = next.safeStrPair().LIZ; Objects.requireNonNull(str, "null cannot be cast to non-null type kotlin.CharSequence"); if (AnonymousClass1ZS.LIZIZ((CharSequence) str).toString().length() > 0) { if (next != null) { return true; } } } return false; } public static final String LJIIIIZZ(List<TextStickerTextWrap> list) { if (list == null) { return ""; } StringBuilder sb = new StringBuilder(""); Iterator<T> it = list.iterator(); while (it.hasNext()) { sb.append(it.next().getText()); } String sb2 = sb.toString(); m.LIZIZ(sb2, ""); return sb2; } public static final List<CreateAnchorInfo> LJIIIZ(List<? extends InteractStickerStruct> list) { TextStruct textStruct; List<CreateAnchorInfo> list2; ArrayList<CreateAnchorInfo> arrayList = new ArrayList(); if (list == null) { return arrayList; } ArrayList<InteractStickerStruct> arrayList2 = new ArrayList(); Iterator<T> it = list.iterator(); while (true) { boolean z = true; if (!it.hasNext()) { break; } T next = it.next(); if (next.getType() != 5) { z = false; } if (z) { arrayList2.add(next); } } ArrayList arrayList3 = new ArrayList(); for (InteractStickerStruct interactStickerStruct : arrayList2) { try { textStruct = (TextStruct) AnonymousClass5EI.LIZIZ().fromJson(interactStickerStruct.getTextStruct(), TextStruct.class); } catch (Exception unused) { textStruct = null; } if (textStruct == null || (list2 = textStruct.getAnchors()) == null) { list2 = new ArrayList<>(); } AnonymousClass1ZP.LIZ((Collection) arrayList3, (Iterable) list2); } arrayList.addAll(arrayList3); for (CreateAnchorInfo createAnchorInfo : arrayList) { String iconUrl = createAnchorInfo.getIconUrl(); if (iconUrl == null || iconUrl.length() == 0) { createAnchorInfo.setIconUrl("https://p16.tiktokcdn.com/obj/tiktok-obj/wiki_anchor_new.png"); createAnchorInfo.setAddTime(0L); } } return arrayList; } public static final List<CreateAnchorInfo> LJIIJ(List<? extends InteractStickerStruct> list) { Exception e; String str; String str2; long j; ArrayList arrayList = new ArrayList(); if (list == null) { return arrayList; } JSONObject jSONObject = new JSONObject(); jSONObject.put("add_from", 1); String jSONObject2 = jSONObject.toString(); m.LIZIZ(jSONObject2, ""); ArrayList<InteractStickerStruct> arrayList2 = new ArrayList(); Iterator<T> it = list.iterator(); while (true) { boolean z = false; if (!it.hasNext()) { break; } T next = it.next(); if (next.getType() == 6) { z = true; } if (z) { arrayList2.add(next); } } for (InteractStickerStruct interactStickerStruct : arrayList2) { try { Object fromJson = AnonymousClass5EI.LIZIZ().fromJson(interactStickerStruct.getAttr(), new C131095Dm().type); m.LIZIZ(fromJson, ""); HashMap hashMap = (HashMap) fromJson; if (hashMap.get("donation_name") instanceof String) { Object obj = hashMap.get("donation_name"); if (obj != null) { str = (String) obj; } else { throw new NullPointerException("null cannot be cast to non-null type kotlin.String"); } } else { str = ""; } if (hashMap.get("donation_url") instanceof String) { Object obj2 = hashMap.get("donation_url"); if (obj2 != null) { str2 = (String) obj2; } else { throw new NullPointerException("null cannot be cast to non-null type kotlin.String"); } } else { str2 = ""; } if (hashMap.get("add_anchor_time") instanceof String) { Object obj3 = hashMap.get("add_anchor_time"); if (obj3 == null) { throw new NullPointerException("null cannot be cast to non-null type kotlin.String"); } else if (((String) obj3).length() > 0) { Object obj4 = hashMap.get("add_anchor_time"); if (obj4 != null) { j = Long.parseLong((String) obj4); arrayList.add(new CreateAnchorInfo(19, str, str2, "", jSONObject2, "https://p16.tiktokcdn.com/obj/tiktok-obj/who3x.png", Long.valueOf(j), null, null, null, null, null, 3968, null)); } else { throw new NullPointerException("null cannot be cast to non-null type kotlin.String"); } } } j = 0; try { arrayList.add(new CreateAnchorInfo(19, str, str2, "", jSONObject2, "https://p16.tiktokcdn.com/obj/tiktok-obj/who3x.png", Long.valueOf(j), null, null, null, null, null, 3968, null)); } catch (Exception e2) { e = e2; } } catch (Exception e3) { e = e3; AbstractC131155Ds LIZLLL = AnonymousClass5EI.LIZLLL(); if (LIZLLL != null) { LIZLLL.LIZIZ(e.getMessage()); } } } return arrayList; } }