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

import android.content.Context;
import android.content.Intent;
import android.util.SparseArray;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.model.r;
import com.tencent.mm.model.v;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXVideoObject;
import com.tencent.mm.plugin.fav.a.am.a;
import com.tencent.mm.plugin.fav.a.b;
import com.tencent.mm.plugin.fav.a.g;
import com.tencent.mm.plugin.fav.a.h;
import com.tencent.mm.protocal.protobuf.aar;
import com.tencent.mm.protocal.protobuf.aau;
import com.tencent.mm.protocal.protobuf.cfh;
import com.tencent.mm.sdk.g.d;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.al;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.vfs.e;
import com.tencent.mm.vfs.j;
import com.tencent.ytcommon.BuildConfig;
import java.util.LinkedList;
import java.util.List;

public final class i {

    /* renamed from: com.tencent.mm.plugin.fav.ui.i$2 */
    public static class AnonymousClass2 implements a {
        final /* synthetic */ Runnable cfC;
        final /* synthetic */ g meE;
        final /* synthetic */ Context val$context;

        public AnonymousClass2(g gVar, Context context, Runnable runnable) {
            this.meE = gVar;
            this.val$context = context;
            this.cfC = runnable;
        }

        public final void d(SparseArray<String> sparseArray) {
            AppMethodBeat.i(74119);
            String str = (String) sparseArray.get(this.meE.field_id);
            ab.d("MicroMsg.FavSendLogic", "on finish, favid %d, url %s", new Object[]{Integer.valueOf(this.meE.field_id), str});
            if (!bo.isNullOrNil(str)) {
                if (4 == this.meE.field_type) {
                    aar c = b.c(this.meE);
                    String bc = bo.bc(c.title, this.val$context.getString(2131299761));
                    Intent intent = new Intent();
                    intent.putExtra("Ksnsupload_link", str);
                    intent.putExtra("Ksnsupload_title", bc);
                    intent.putExtra("Ksnsupload_imgbuf", e.e(b.c(c), 0, -1));
                    b.v(intent, this.val$context);
                    str = "fav_" + r.Yz() + "_" + this.meE.field_id;
                    String nW = v.nW(str);
                    v.Zp().y(nW, true).j("prePublishId", str);
                    intent.putExtra("reportSessionId", nW);
                    h.j(this.meE.field_localId, 0, 0);
                } else {
                    ab.w("MicroMsg.FavSendLogic", "unknown type %d, fav id %d", new Object[]{Integer.valueOf(this.meE.field_type), Integer.valueOf(this.meE.field_id)});
                }
            }
            if (this.cfC != null) {
                al.d(this.cfC);
            }
            AppMethodBeat.o(74119);
        }
    }

    public static void a(Context context, String str, String str2, g gVar, Runnable runnable) {
        AppMethodBeat.i(74129);
        List linkedList = new LinkedList();
        linkedList.add(gVar);
        a(context, str, str2, linkedList, runnable);
        AppMethodBeat.o(74129);
    }

    public static void a(Context context, String str, String str2, List<g> list, Runnable runnable) {
        AppMethodBeat.i(74130);
        if (context == null) {
            ab.w("MicroMsg.FavSendLogic", "want to send fav msg, but context is null");
            al.d(runnable);
            AppMethodBeat.o(74130);
        } else if (bo.isNullOrNil(str)) {
            ab.w("MicroMsg.FavSendLogic", "want to send fav msg, but to user is null");
            al.d(runnable);
            AppMethodBeat.o(74130);
        } else if (list.isEmpty()) {
            ab.w("MicroMsg.FavSendLogic", "want to send fav msg, but info is null");
            al.d(runnable);
            AppMethodBeat.o(74130);
        } else {
            d.xDH.ak(new 1(str, list, context, str2, runnable));
            AppMethodBeat.o(74130);
        }
    }

    public static void a(Context context, String str, aar aar, Runnable runnable) {
        AppMethodBeat.i(74131);
        if (context == null) {
            ab.w("MicroMsg.FavSendLogic", "want to send fav video, but context is null");
            AppMethodBeat.o(74131);
        } else if (bo.isNullOrNil(str)) {
            ab.w("MicroMsg.FavSendLogic", "want to send fav video, but to user is null");
            AppMethodBeat.o(74131);
        } else if (aar == null) {
            ab.w("MicroMsg.FavSendLogic", "want to send fav video, but dataItem is null");
            AppMethodBeat.o(74131);
        } else {
            com.tencent.mm.kernel.g.RS().aa(new 3(aar, context, str, runnable));
            AppMethodBeat.o(74131);
        }
    }

    public static void a(Context context, String str, g gVar, aar aar, Runnable runnable) {
        AppMethodBeat.i(74132);
        if (context == null) {
            ab.w("MicroMsg.FavSendLogic", "want to send fav file, but context is null");
            AppMethodBeat.o(74132);
        } else if (bo.isNullOrNil(str)) {
            ab.w("MicroMsg.FavSendLogic", "want to send fav file, but to user is null");
            AppMethodBeat.o(74132);
        } else {
            if (gVar == null) {
                ab.w("MicroMsg.FavSendLogic", "want to send fav file, but info is null");
            }
            if (aar == null) {
                ab.w("MicroMsg.FavSendLogic", "want to send fav file, but dataItem is null");
                AppMethodBeat.o(74132);
                return;
            }
            com.tencent.mm.kernel.g.RS().aa(new 4(str, gVar, aar, runnable));
            AppMethodBeat.o(74132);
        }
    }

    public static String i(aar aar) {
        String w;
        AppMethodBeat.i(74133);
        com.tencent.mm.vfs.b bVar = new com.tencent.mm.vfs.b(b.c(aar));
        if (bVar.exists()) {
            w = j.w(bVar.dMD());
        } else {
            w = b.bue() + com.tencent.mm.a.g.x(bo.bc(aar.cvq, BuildConfig.FLAVOR).getBytes());
        }
        AppMethodBeat.o(74133);
        return w;
    }

    static /* synthetic */ void b(Context context, String str, aar aar) {
        AppMethodBeat.i(74135);
        com.tencent.mm.vfs.b bVar = new com.tencent.mm.vfs.b(b.b(aar));
        aau aau;
        if (bVar.exists()) {
            String w;
            com.tencent.mm.vfs.b bVar2 = new com.tencent.mm.vfs.b(b.c(aar));
            if (bVar2.exists()) {
                w = j.w(bVar2.dMD());
            } else {
                w = b.bue() + com.tencent.mm.a.g.x(bo.bc(aar.cvq, BuildConfig.FLAVOR).getBytes());
            }
            ab.d("MicroMsg.FavSendLogic", "sendVideo::data path[%s] thumb path[%s]", new Object[]{j.w(bVar.dMD()), w});
            cfh cfh = null;
            aau = aar.wgZ;
            if (aau != null) {
                cfh = new cfh();
                cfh.fiL = aau.fiL;
                cfh.fiI = aau.fiI;
                cfh.wid = aau.wid;
                cfh.fiG = aau.fiG;
                cfh.fiJ = aau.fiJ;
                cfh.fiM = aau.fiM;
                cfh.fiN = aau.fiN;
            }
            if (cfh != null) {
                com.tencent.mm.plugin.messenger.a.g.bOk().a(context, str, j.w(bVar.dMD()), w, 1, aar.duration, cfh, aar.cMn);
                AppMethodBeat.o(74135);
                return;
            }
            com.tencent.mm.plugin.messenger.a.g.bOk().a(context, str, j.w(bVar.dMD()), w, 1, aar.duration, aar.cMn);
            AppMethodBeat.o(74135);
            return;
        }
        String str2 = aar.wgg;
        if (!bo.isNullOrNil(str2)) {
            WXVideoObject wXVideoObject = new WXVideoObject();
            wXVideoObject.videoUrl = str2;
            WXMediaMessage wXMediaMessage = new WXMediaMessage(wXVideoObject);
            str2 = bo.bc(aar.title, context.getResources().getString(2131299761));
            wXMediaMessage.mediaObject = wXVideoObject;
            wXMediaMessage.title = str2;
            wXMediaMessage.description = aar.desc;
            wXMediaMessage.thumbData = bo.readFromFile(b.c(aar));
            if (wXMediaMessage.thumbData == null) {
                wXMediaMessage.thumbData = bo.readFromFile(b.bue() + com.tencent.mm.a.g.x(bo.bc(aar.cvq, BuildConfig.FLAVOR).getBytes()));
            }
            com.tencent.mm.af.j.b bVar3 = new com.tencent.mm.af.j.b();
            bVar3.fgr = 3;
            aau = aar.wgZ;
            if (aau != null) {
                bVar3.fiL = aau.fiL;
                bVar3.fiI = aau.fiI;
                bVar3.fiH = aau.wid;
                bVar3.fiG = aau.fiG;
                bVar3.fiJ = aau.fiJ;
                bVar3.fiM = aau.fiM;
                bVar3.fiN = aau.fiN;
            }
            ((com.tencent.mm.plugin.fav.a.ab) com.tencent.mm.kernel.g.K(com.tencent.mm.plugin.fav.a.ab.class)).a(bVar3, wXMediaMessage, str);
        }
        AppMethodBeat.o(74135);
    }
}
