package com.xingin.matrix.followfeed.shop; import android.content.DialogInterface; import android.net.Uri; import android.os.Bundle; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import androidx.collection.SimpleArrayMap; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.uber.autodispose.a0; import com.uber.autodispose.y; import com.xingin.android.xhscomm.event.Event; import com.xingin.android.xhscomm.router.Routers; import com.xingin.matrix.base.R$id; import com.xingin.matrix.base.R$layout; import com.xingin.matrix.base.R$string; import com.xingin.matrix.followfeed.model.FollowNoteModel; import com.xingin.matrix.followfeed.shop.GoodsSkuAdapter; import com.xingin.utils.core.z; import com.xingin.widgets.XYImageView; import dw2.r; import ja.b1; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; import kotlin.Unit; import ne1.g; import ne1.h; import ne1.h0; import ne1.i; import ne1.i0; import ne1.j; import ne1.j0; import ne1.k; import ne1.l; import ne1.m; import ne1.n; import ne1.o; import ne1.p; import ne1.q; import ne1.s; import ne1.t; import ne1.u; import ne1.v; import oe1.b; import oe1.c; import oe1.d; import oe1.e; /* compiled from: GoodsMainPage */ public class a implements j0, GoodsSkuAdapter.d { public c.b.a A = null; public Boolean B = Boolean.FALSE; /* renamed from: a reason: collision with root package name */ public final h0 f57780a; /* renamed from: b reason: collision with root package name */ public View f57781b = null; /* renamed from: c reason: collision with root package name */ public String f57782c; /* renamed from: d reason: collision with root package name */ public double f57783d; /* renamed from: e reason: collision with root package name */ public b f57784e = null; /* renamed from: f reason: collision with root package name */ public ImageView f57785f; /* renamed from: g reason: collision with root package name */ public XYImageView f57786g; /* renamed from: h reason: collision with root package name */ public TextView f57787h; /* renamed from: i reason: collision with root package name */ public TextView f57788i; /* renamed from: j reason: collision with root package name */ public TextView f57789j; /* renamed from: k reason: collision with root package name */ public TextView f57790k; /* renamed from: l reason: collision with root package name */ public TextView f57791l; /* renamed from: m reason: collision with root package name */ public TextView f57792m; /* renamed from: n reason: collision with root package name */ public ImageView f57793n; /* renamed from: o reason: collision with root package name */ public TextView f57794o; /* renamed from: p reason: collision with root package name */ public LinearLayout f57795p; /* renamed from: q reason: collision with root package name */ public RecyclerView f57796q; /* renamed from: r reason: collision with root package name */ public LinearLayout f57797r; /* renamed from: s reason: collision with root package name */ public TextView f57798s; /* renamed from: t reason: collision with root package name */ public TextView f57799t; /* renamed from: u reason: collision with root package name */ public TextView f57800u; /* renamed from: v reason: collision with root package name */ public GoodsSkuAdapter f57801v; /* renamed from: w reason: collision with root package name */ public String f57802w; /* renamed from: x reason: collision with root package name */ public HashMap<String, String> f57803x = new LinkedHashMap(); /* renamed from: y reason: collision with root package name */ public SimpleArrayMap<String, Set<String>> f57804y = new SimpleArrayMap<>(); /* renamed from: z reason: collision with root package name */ public int f57805z = 1; public a(h0 h0Var) { this.f57780a = h0Var; } public static String C(String str) { if (TextUtils.isEmpty(str)) { return ""; } if (str.startsWith("https:") || str.startsWith("http:")) { return str; } return "https:" + str; } public static /* synthetic */ void F(View.OnClickListener onClickListener, View view, Unit unit) throws Exception { if (onClickListener != null) { onClickListener.onClick(view); } } /* access modifiers changed from: private */ public /* synthetic */ void G(View view) { this.f57780a.dismiss(); } /* access modifiers changed from: private */ public /* synthetic */ b H(d dVar, c cVar) throws Exception { b bVar = null; if (!(dVar == null || cVar == null)) { List<d.b> items = dVar.getItems(); List<c.b> items2 = cVar.getItems(); z zVar = z.f63665a; if (!zVar.a(items) && !zVar.a(items2)) { bVar = new b(); HashMap<String, b.a> goodsMap = bVar.getGoodsMap(); W(goodsMap, items); V(goodsMap, items2); D(goodsMap); bVar.getSkuOptionsList().addAll(dVar.getSku_options()); c.a cart = cVar.getCart(); if (cart != null) { bVar.mCartCount = cart.getCount(); bVar.syncCartCount = cart.isSync(); bVar.mCartCountLink = cart.getUrl(); } } } return bVar; } /* access modifiers changed from: private */ public /* synthetic */ Unit I() { if (!B()) { return null; } Routers.build(this.f57780a.e().b("xhsdiscover://rn/lancer/group_order/instant_buy?type=2&item_id=" + this.f57782c + "¬e_id=" + this.f57780a.a() + "&quantity=" + this.f57805z + "&xhs_g_s=0123", this.f57780a.d())).open(this.f57780a.getContext()); f0(this.f57780a.d(), this.f57782c, this.f57805z); this.f57780a.e().e("NoteFeedGoodsBuyNow", this.f57782c); this.f57780a.e().a(ActionType.BUY_NOW, this.f57782c, i()); this.f57780a.f().a(); this.f57780a.dismiss(); return null; } /* access modifiers changed from: private */ public /* synthetic */ void J(View view) { ka.a.f97735a.g(new m(this)).i(new ka.b(view.getContext(), 13)).e(); } /* access modifiers changed from: private */ public /* synthetic */ void K(e eVar) throws Exception { int i10; try { i10 = Integer.parseInt(this.f57794o.getText().toString()); } catch (Exception unused) { i10 = 0; } a0(String.valueOf(i10 + this.f57805z)); e0(this.f57780a.d(), this.f57782c, this.f57805z); } public static /* synthetic */ void L(Throwable th3) throws Exception { ne1.b.b(th3.getMessage()); } /* access modifiers changed from: private */ public /* synthetic */ Unit M() { if (!B()) { return null; } this.f57780a.e().e("NoteFeedGoodsAddToCart", this.f57782c); this.f57780a.e().a(ActionType.ADD_CART, this.f57782c, i()); this.f57780a.f().e(); ((y) FollowNoteModel.g(this.f57782c, String.valueOf(this.f57805z), (int) (this.f57783d * 100.0d)).n(com.uber.autodispose.d.b(a0.D))).a(new u(this), h.f109735a); return null; } /* access modifiers changed from: private */ public /* synthetic */ void N(View view) { ka.a.f97735a.g(new k(this)).i(new ka.b(view.getContext(), 10)).e(); } /* access modifiers changed from: private */ public /* synthetic */ void O(String str, b bVar) throws Exception { this.f57784e = bVar; ArrayList arrayList = new ArrayList(bVar.getSkuOptionsList()); arrayList.add(new GoodsSkuAdapter.a()); c0(str, true); if (this.f57781b.isAttachedToWindow()) { this.f57780a.e().a(ActionType.IMPRESSION, this.f57782c, i()); } d0(); Y(); this.f57801v.n(arrayList); b0(str); Z(); A(this.f57792m, new q(this)); A(this.f57791l, new p(this)); } /* access modifiers changed from: private */ public /* synthetic */ void Q(oe1.a aVar) throws Exception { if (aVar.isSuccess()) { a0(aVar.getCount()); } } /* access modifiers changed from: private */ public /* synthetic */ Unit R() { Routers.build(this.f57780a.e().b("xhsdiscover://rn/lancer/user/shopping_cart", this.f57780a.d())).open(this.f57780a.getContext()); this.f57780a.e().e("NoteFeedGoodsShoppingCart", this.f57782c); this.f57780a.e().a(ActionType.CART_CLICK, this.f57782c, i()); this.f57780a.f().b(); this.f57780a.dismiss(); return null; } /* access modifiers changed from: private */ public /* synthetic */ void S(View view) { ka.a.f97735a.g(new l(this)).i(new ka.b(view.getContext(), 11)).e(); } /* access modifiers changed from: private */ public /* synthetic */ void T() { this.f57796q.invalidateItemDecorations(); } /* access modifiers changed from: private */ public /* synthetic */ void U(View view) { i0 e14 = this.f57780a.e(); Routers.build(e14.b("https://pages.xiaohongshu.com/goods/" + this.f57782c, this.f57780a.d())).open(this.f57780a.getContext()); this.f57780a.e().e("NoteFeedGoodsJumpDetail", this.f57782c); this.f57780a.e().a(ActionType.DETAIL_CLICK, this.f57782c, i()); this.f57780a.f().c(); this.f57780a.dismiss(); g0(this.f57782c, this.f57780a.d()); } public final void A(View view, View.OnClickListener onClickListener) { ((y) u7.a.b(view).F1(500, TimeUnit.MILLISECONDS, cx2.a.a()).W0(gw2.a.a()).n(com.uber.autodispose.d.b(a0.D))).a(new s(onClickListener, view), ib1.c.f89433a); } public final boolean B() { Set<String> keySet = this.f57803x.keySet(); boolean z14 = true; if (keySet.isEmpty()) { if (keySet.size() != this.f57804y.size()) { z14 = false; } if (!z14) { ne1.b.a(R$string.cy_); } return z14; } for (String str : keySet) { if (TextUtils.isEmpty(this.f57803x.get(str))) { ne1.b.b("请选择" + str); return false; } } return true; } public final void D(HashMap<String, b.a> hashMap) { for (String str : hashMap.keySet()) { if (hashMap.get(str).mFilter) { hashMap.remove(str); } } } public final int E(b.a aVar) { try { String str = aVar.mSellerId; boolean z14 = aVar.isOfficial; if (TextUtils.equals(this.f57802w, str)) { return 2; } if (z14) { return 1; } return 0; } catch (Exception unused) { } } public final void V(HashMap<String, b.a> hashMap, List<c.b> list) { c.b.C1722b.a sale_price; for (c.b bVar : list) { if (bVar != null) { String id3 = bVar.getId(); if (hashMap.containsKey(id3)) { b.a aVar = hashMap.get(id3); aVar.mStockStatus = bVar.getStock_status(); c.b.C1722b price = bVar.getPrice(); if (!(price == null || (sale_price = price.getSale_price()) == null)) { aVar.mSalePrice = sale_price.getPrice(); aVar.mMemberPrice = price.getMember_price(); aVar.mOriginPrice = price.getOrigin_price(); } aVar.mCoupon = bVar.getCoupon(); aVar.mFilter = false; } } } } public final void W(HashMap<String, b.a> hashMap, List<d.b> list) { for (d.b bVar : list) { if (bVar != null) { b.a aVar = new b.a(); aVar.mFilter = true; aVar.mGoodsId = bVar.getId(); aVar.mGoodsName = bVar.getName(); aVar.variants = bVar.getVariants(); aVar.mImageList = bVar.getImages(); aVar.mPolicyList = bVar.getPolicyList(); d.b.C1725d seller = bVar.getSeller(); if (seller != null) { aVar.mSellerId = seller.getId(); aVar.isOfficial = seller.isOfficial(); } hashMap.put(aVar.mGoodsId, aVar); } } } public final void X(String str) { ((y) r.V1(FollowNoteModel.e(str), FollowNoteModel.d(str, this.f57780a.d(), this.f57780a.a(), !b1.f94179a.c1()), new ne1.r(this)).W0(gw2.a.a()).n(com.uber.autodispose.d.b(a0.D))).a(new v(this, str), i.f109736a); } public final void Y() { if (this.f57784e != null) { this.f57804y.clear(); List<d.a> skuOptionsList = this.f57784e.getSkuOptionsList(); ArrayList<b.a> arrayList = new ArrayList(this.f57784e.getGoodsMap().values()); for (d.a aVar : skuOptionsList) { String name = aVar.getName(); HashSet hashSet = new HashSet(); this.f57804y.put(name, hashSet); for (b.a aVar2 : arrayList) { List<d.b.e> list = aVar2.variants; if (list != null && !list.isEmpty()) { boolean z14 = false; String str = null; for (d.b.e eVar : list) { String name2 = eVar.getName(); String value = eVar.getValue(); if (TextUtils.equals(name, name2)) { str = value; } else { String str2 = this.f57803x.get(name2); if (!TextUtils.isEmpty(str2) && !TextUtils.equals(value, str2)) { z14 = true; } } } if (!z14 && aVar2.mStockStatus == 1) { hashSet.add(str); } } } } } } public final void Z() { b bVar = this.f57784e; if (bVar != null) { a0(bVar.mCartCount); if (!this.f57784e.syncCartCount) { ((y) FollowNoteModel.c().n(com.uber.autodispose.d.b(a0.D))).a(new t(this), ib1.c.f89433a); } A(this.f57793n, new o(this)); } } @Override // ne1.j0 public View a(ViewGroup viewGroup, int i10) { if (this.f57781b == null) { View inflate = LayoutInflater.from(viewGroup.getContext()).inflate(R$layout.arc, viewGroup, false); this.f57781b = inflate; ImageView imageView = (ImageView) inflate.findViewById(R$id.cey); this.f57785f = imageView; imageView.setOnClickListener(new n(this)); this.f57786g = (XYImageView) this.f57781b.findViewById(R$id.cfe); this.f57787h = (TextView) this.f57781b.findViewById(R$id.tv_title); this.f57788i = (TextView) this.f57781b.findViewById(R$id.g4e); this.f57789j = (TextView) this.f57781b.findViewById(R$id.g4f); this.f57790k = (TextView) this.f57781b.findViewById(R$id.g63); this.f57791l = (TextView) this.f57781b.findViewById(R$id.g28); this.f57792m = (TextView) this.f57781b.findViewById(R$id.g2j); this.f57793n = (ImageView) this.f57781b.findViewById(R$id.cez); this.f57794o = (TextView) this.f57781b.findViewById(R$id.g2l); this.f57795p = (LinearLayout) this.f57781b.findViewById(R$id.ct9); this.f57797r = (LinearLayout) this.f57781b.findViewById(R$id.cku); this.f57798s = (TextView) this.f57781b.findViewById(R$id.g64); this.f57799t = (TextView) this.f57781b.findViewById(R$id.g3z); this.f57800u = (TextView) this.f57781b.findViewById(R$id.g5e); RecyclerView recyclerView = (RecyclerView) this.f57781b.findViewById(R$id.ety); this.f57796q = recyclerView; recyclerView.setLayoutManager(new LinearLayoutManager(viewGroup.getContext())); this.f57796q.setNestedScrollingEnabled(false); GoodsSkuAdapter goodsSkuAdapter = new GoodsSkuAdapter(null, this.f57780a); this.f57801v = goodsSkuAdapter; goodsSkuAdapter.o(this); this.f57796q.setAdapter(this.f57801v); } X(this.f57780a.b()); this.f57780a.f().f(); return this.f57781b; } public final void a0(String str) { if (TextUtils.isEmpty(str) || TextUtils.equals(str, "0")) { this.f57794o.setVisibility(8); return; } this.f57794o.setVisibility(0); this.f57794o.setText(str); } @Override // com.xingin.matrix.followfeed.shop.GoodsSkuAdapter.d public String b() { return this.f57782c; } public final void b0(String str) { b.a aVar; b bVar = this.f57784e; if (bVar != null && (aVar = bVar.getGoodsMap().get(str)) != null) { c.b.a aVar2 = aVar.mCoupon; List data = this.f57801v.getData(); if (aVar2 == null || aVar2.getDiscount() <= 0) { c.b.a aVar3 = this.A; if (aVar3 != null) { data.remove(aVar3); this.f57801v.notifyItemRemoved(0); this.f57796q.post(new j(this)); this.A = null; } } else { if (this.A == null) { data.add(0, aVar2); this.f57801v.notifyItemInserted(0); } else { data.set(0, aVar2); this.f57801v.notifyItemChanged(0, aVar2); } this.A = aVar2; } if (this.A != null) { this.f57780a.f().d(this.A); } } } @Override // com.xingin.matrix.followfeed.shop.GoodsSkuAdapter.d public void c(String str, String str2, boolean z14) { double d14; HashMap<String, String> hashMap = this.f57803x; b.a aVar = null; if (!z14) { str2 = null; } hashMap.put(str, str2); d0(); Y(); this.f57801v.notifyDataSetChanged(); this.f57780a.f().i(); if (this.f57784e != null) { ArrayList<b.a> arrayList = new ArrayList(this.f57784e.getGoodsMap().values()); HashSet hashSet = new HashSet(); for (b.a aVar2 : arrayList) { List<d.b.e> list = aVar2.variants; if (list != null && !list.isEmpty()) { boolean z15 = true; for (d.b.e eVar : list) { String name = eVar.getName(); String value = eVar.getValue(); String str3 = this.f57803x.get(name); if (!TextUtils.isEmpty(str3) && !TextUtils.equals(value, str3)) { z15 = false; } } if (z15 && aVar2.mStockStatus == 1) { hashSet.add(aVar2); } } } if (!hashSet.isEmpty()) { try { Iterator it3 = hashSet.iterator(); int i10 = 0; while (true) { if (!it3.hasNext()) { break; } b.a aVar3 = (b.a) it3.next(); if (TextUtils.equals(this.f57780a.b(), aVar3.mGoodsId)) { aVar = aVar3; break; } double parseDouble = Double.parseDouble(aVar3.mSalePrice); if (aVar == null) { d14 = Double.MAX_VALUE; } else { d14 = Double.parseDouble(aVar.mSalePrice); } int i14 = (parseDouble > d14 ? 1 : (parseDouble == d14 ? 0 : -1)); if (i14 <= 0) { if (i14 == 0) { int E = E(aVar3); if (E > i10) { aVar = aVar3; i10 = E; } } else { i10 = E(aVar3); aVar = aVar3; } } } if (aVar != null) { c0(aVar.mGoodsId, false); b0(this.f57782c); } } catch (Exception e14) { z41.l.e(e14); } } } } public final void c0(String str, boolean z14) { List<d.b.e> list; b bVar = this.f57784e; if (bVar != null) { this.f57782c = str; b.a aVar = bVar.getGoodsMap().get(str); if (aVar != null) { this.f57787h.setText(aVar.mGoodsName); List<d.b.C1724b> list2 = aVar.mImageList; if (list2 != null && !list2.isEmpty()) { this.f57786g.setImageURI(Uri.parse(C(list2.get(0).getThumbnail()))); } pe1.b.a(aVar.mSalePrice, aVar.mMemberPrice, aVar.mOriginPrice, this.f57788i, this.f57789j); try { this.f57783d = Double.parseDouble(aVar.mSalePrice); } catch (Exception unused) { } this.f57780a.f().h(); A(this.f57795p, new g(this)); if (z14 && (list = aVar.variants) != null && !list.isEmpty()) { for (d.b.e eVar : list) { this.f57803x.put(eVar.getName(), eVar.getValue()); } } this.f57802w = aVar.mSellerId; List<d.b.c> list3 = aVar.mPolicyList; if (list3 == null || list3.isEmpty()) { this.f57797r.setVisibility(8); return; } boolean z15 = false; boolean z16 = false; boolean z17 = false; for (d.b.c cVar : list3) { if (cVar.getSequence() == 0) { this.f57800u.setVisibility(0); this.f57800u.setText(cVar.getTitle()); z15 = true; } else if (cVar.getSequence() == 1) { this.f57799t.setVisibility(0); this.f57799t.setText(cVar.getTitle()); z16 = true; } else if (cVar.getSequence() == 2) { this.f57798s.setVisibility(0); this.f57798s.setText(cVar.getTitle()); z17 = true; } } if (z15 || z16 || z17) { this.f57797r.setVisibility(0); if (!z15) { this.f57800u.setVisibility(8); } if (!z16) { this.f57799t.setVisibility(8); } if (!z17) { this.f57798s.setVisibility(8); return; } return; } this.f57797r.setVisibility(8); } } } @Override // com.xingin.matrix.followfeed.shop.GoodsSkuAdapter.d public void d() { HashMap<String, b.a> goodsMap; b.a aVar; c.b.a aVar2; b bVar = this.f57784e; if (!(bVar == null || (aVar = (goodsMap = bVar.getGoodsMap()).get(this.f57782c)) == null)) { String str = aVar.mSellerId; for (b.a aVar3 : goodsMap.values()) { if (TextUtils.equals(str, aVar3.mSellerId) && (aVar2 = aVar3.mCoupon) != null) { aVar2.setHasClaimedAll(true); } } } } public final void d0() { StringBuilder sb3 = new StringBuilder("已选:"); Set<String> keySet = this.f57803x.keySet(); if (keySet.isEmpty()) { this.f57790k.setText(""); return; } for (String str : keySet) { String str2 = this.f57803x.get(str); if (!TextUtils.isEmpty(str2)) { sb3.append(str2); sb3.append(" "); } } this.f57790k.setText(sb3.toString()); } @Override // com.xingin.matrix.followfeed.shop.GoodsSkuAdapter.d public Set<String> e(String str) { return this.f57804y.get(str); } public final void e0(String str, String str2, int i10) { if (this.B.booleanValue()) { Bundle bundle = new Bundle(); bundle.putString("CONTRACT_ID", str); bundle.putString("GOODS_ID", str2); bundle.putInt("GOODS_COUNT", i10); e30.c.e(new Event("com.xingin.xhs.goods.add.cart", bundle)); } } @Override // com.xingin.matrix.followfeed.shop.GoodsSkuAdapter.d public String f(String str) { return this.f57803x.get(str); } public final void f0(String str, String str2, int i10) { if (this.B.booleanValue()) { Bundle bundle = new Bundle(); bundle.putString("CONTRACT_ID", str); bundle.putString("GOODS_ID", str2); bundle.putInt("GOODS_COUNT", i10); e30.c.e(new Event("com.xingin.xhs.goods.buy", bundle)); } } @Override // com.xingin.matrix.followfeed.shop.GoodsSkuAdapter.d public int g() { return this.f57805z; } public final void g0(String str, String str2) { if (this.B.booleanValue()) { Bundle bundle = new Bundle(); bundle.putString("CONTRACT_ID", str); bundle.putString("GOODS_ID", str2); e30.c.e(new Event("com.xingin.xhs.goods.detail", bundle)); } } @Override // ne1.j0 public void h(DialogInterface dialogInterface) { } @Override // com.xingin.matrix.followfeed.shop.GoodsSkuAdapter.d public int i() { b.a aVar; b bVar = this.f57784e; if (bVar == null || (aVar = bVar.getGoodsMap().get(this.f57782c)) == null) { return -1; } return aVar.mStockStatus; } @Override // com.xingin.matrix.followfeed.shop.GoodsSkuAdapter.d public void j(int i10) { this.f57805z = i10; b0(this.f57782c); } }