package com.tencent.mm.plugin.sns.ui;

import android.text.Editable;
import android.text.TextWatcher;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.plugin.sns.c.a;
import com.tencent.mm.plugin.sns.ui.widget.d;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.ytcommon.BuildConfig;
import java.util.List;

class SnsCommentFooter$5 implements TextWatcher {
    final /* synthetic */ SnsCommentFooter rrD;
    int rrF = 0;
    final /* synthetic */ List rrG;

    SnsCommentFooter$5(SnsCommentFooter snsCommentFooter, List list) {
        this.rrD = snsCommentFooter;
        this.rrG = list;
    }

    public final void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        AppMethodBeat.i(38881);
        if (charSequence == null || charSequence.length() < a.qFE) {
            this.rrD.DW(16);
            ab.d("MicroMsg.SnsCommentFooter", "clean SNS_COMMENT_FLAG_FOLD");
            AppMethodBeat.o(38881);
            return;
        }
        if (charSequence.length() - this.rrF > a.qFE) {
            this.rrD.setCommentFlag(16);
            ab.d("MicroMsg.SnsCommentFooter", "add SNS_COMMENT_FLAG_FOLD");
        }
        AppMethodBeat.o(38881);
    }

    public final void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        AppMethodBeat.i(38882);
        this.rrF = charSequence == null ? 0 : charSequence.length();
        AppMethodBeat.o(38882);
    }

    public final void afterTextChanged(Editable editable) {
        AppMethodBeat.i(38883);
        if (SnsCommentFooter.b(this.rrD).getText() == null) {
            AppMethodBeat.o(38883);
            return;
        }
        if (!(!d.fF(SnsCommentFooter.c(this.rrD), 8) || bo.isNullOrNil(SnsCommentFooter.d(this.rrD)) || bo.isNullOrNil(SnsCommentFooter.b(this.rrD).getText().toString()) || SnsCommentFooter.b(this.rrD).getText().toString().startsWith(SnsCommentFooter.d(this.rrD)))) {
            ab.i("MicroMsg.SnsCommentFooter", "commentAtPrefix [%s], curTxt [%s]", new Object[]{SnsCommentFooter.d(this.rrD), SnsCommentFooter.b(this.rrD).getText()});
            SnsCommentFooter.a(this.rrD, BuildConfig.FLAVOR);
            SnsCommentFooter.e(this.rrD);
            this.rrD.DW(8);
            SnsCommentFooter.a(this.rrD, 0);
        }
        ab.d("MicroMsg.SnsCommentFooter", "update commentkey:" + SnsCommentFooter.f(this.rrD));
        if (!bo.isNullOrNil(SnsCommentFooter.f(this.rrD))) {
            k kVar;
            int i;
            for (k kVar2 : this.rrG) {
                if (SnsCommentFooter.f(this.rrD).equals(kVar2.key)) {
                    ab.d("MicroMsg.SnsCommentFooter", "afterTextChanged update");
                    kVar2.text = SnsCommentFooter.b(this.rrD).getText().toString();
                    kVar2.bJt = SnsCommentFooter.c(this.rrD);
                    i = 1;
                    break;
                }
            }
            i = 0;
            if (i == 0) {
                ab.d("MicroMsg.SnsCommentFooter", "afterTextChanged add");
                kVar2 = new k();
                kVar2.key = SnsCommentFooter.f(this.rrD);
                kVar2.text = SnsCommentFooter.b(this.rrD).getText().toString();
                kVar2.bJt = SnsCommentFooter.c(this.rrD);
                if (kVar2.text != null && kVar2.text.length() > 0) {
                    this.rrG.add(kVar2);
                }
            }
        }
        if (this.rrG.size() > 5) {
            ab.d("MicroMsg.SnsCommentFooter", "comments remove");
            this.rrG.remove(0);
        }
        SnsCommentFooter.b(this.rrD).requestFocus();
        boolean z = SnsCommentFooter.b(this.rrD).getText().toString().trim().length() > 0;
        if (z && this.rrD.oio) {
            SnsCommentFooter.a(this.rrD, z);
            this.rrD.oio = false;
        }
        if (!z) {
            SnsCommentFooter.a(this.rrD, z);
            this.rrD.oio = true;
        }
        AppMethodBeat.o(38883);
    }
}
