导航菜单

页面标题

页面副标题

Rilo v2.0.21 - CouponCodeActivity.java 源代码

正在查看: Rilo v2.0.21 应用的 CouponCodeActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package app.callpe.ui.payment;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import androidx.activity.ComponentActivity;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LifecycleOwnerKt;
import androidx.lifecycle.ViewModelLazy;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStore;
import androidx.lifecycle.viewmodel.CreationExtras;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import app.callpe.adapters.CouponAdapter;
import app.callpe.common.utils.custom.CustomLinearLayoutManager;
import app.callpe.common.utils.extensions.ActivityExtKt;
import app.callpe.data.model.CouponCodeModel;
import app.callpe.data.model.TopUpModel;
import app.callpe.databinding.ActivityCouponCodeBinding;
import app.callpe.ui.dialog.CouponRechargeListDialog;
import app.callpe.ui.home.AccountViewModel;
import app.callpe.ui.home.BaseActivity;
import com.google.gson.Gson;
import dagger.hilt.android.AndroidEntryPoint;
import j$.util.DesugarTimeZone;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import kotlin.Lazy;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.collections.CollectionsKt;
import kotlin.coroutines.CoroutineContext;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.Reflection;
import kotlinx.coroutines.BuildersKt;
import kotlinx.coroutines.CoroutineStart;
import kotlinx.coroutines.Job;
import timber.log.Timber;

@Metadata(d1 = {"\u0000\\\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u0007\u0018\u00002\b\u0012\u0004\u0012\u00020\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0003J\u0010\u0010\u000e\u001a\u00020\u00022\u0006\u0010\u000f\u001a\u00020\u0010H\u0016J\b\u0010\u0011\u001a\u00020\u0012H\u0002J\b\u0010\u0013\u001a\u00020\u0014H\u0002J\u0012\u0010\u0015\u001a\u00020\u00122\b\u0010\u0016\u001a\u0004\u0018\u00010\u0017H\u0014J\u0010\u0010\u0018\u001a\u00020\u00192\u0006\u0010\u001a\u001a\u00020\u001bH\u0016J\b\u0010\u001c\u001a\u00020\u0012H\u0002J\b\u0010\u001d\u001a\u00020\u0012H\u0002J\b\u0010\u001e\u001a\u00020\u0012H\u0002J \u0010\u001f\u001a\u00020\u00122\u0016\u0010 \u001a\u0012\u0012\u0004\u0012\u00020\"0!j\b\u0012\u0004\u0012\u00020\"`#H\u0002J\b\u0010$\u001a\u00020\u0012H\u0002R\u0010\u0010\u0004\u001a\u0004\u0018\u00010\u0005X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0006\u001a\u00020\u0007X\u0082.¢\u0006\u0002\n\u0000R\u001b\u0010\b\u001a\u00020\t8BX\u0082\u0084\u0002¢\u0006\f\n\u0004\b\f\u0010\r\u001a\u0004\b\n\u0010\u000b¨\u0006%"}, d2 = {"Lapp/callpe/ui/payment/CouponCodeActivity;", "Lapp/callpe/ui/home/BaseActivity;", "Lapp/callpe/databinding/ActivityCouponCodeBinding;", "()V", "adapter", "Lapp/callpe/adapters/CouponAdapter;", "toolbar", "Landroidx/appcompat/widget/Toolbar;", "viewModel", "Lapp/callpe/ui/home/AccountViewModel;", "getViewModel", "()Lapp/callpe/ui/home/AccountViewModel;", "viewModel$delegate", "Lkotlin/Lazy;", "inflateLayout", "layoutInflater", "Landroid/view/LayoutInflater;", "initViews", "", "observeEvent", "Lkotlinx/coroutines/Job;", "onCreate", "savedInstanceState", "Landroid/os/Bundle;", "onOptionsItemSelected", "", "item", "Landroid/view/MenuItem;", "refresh", "setUpToolbar", "setupRv", "sortAndAddItems", "coupons", "Ljava/util/ArrayList;", "Lapp/callpe/data/model/CouponCodeModel;", "Lkotlin/collections/ArrayList;", "swipeRefresh", "app_riloRelease"}, k = 1, mv = {1, 8, 0}, xi = 48)
@AndroidEntryPoint
public final class CouponCodeActivity extends BaseActivity<ActivityCouponCodeBinding> {
    private CouponAdapter adapter;
    private Toolbar toolbar;

    private final Lazy viewModel;

    public CouponCodeActivity() {
        final ComponentActivity componentActivity = (ComponentActivity) this;
        final Function0 function0 = null;
        this.viewModel = new ViewModelLazy(Reflection.getOrCreateKotlinClass(AccountViewModel.class), new Function0<ViewModelStore>() {
            {
                super(0);
            }

            public final ViewModelStore m2140invoke() {
                return componentActivity.getViewModelStore();
            }
        }, new Function0<ViewModelProvider.Factory>() {
            {
                super(0);
            }

            public final ViewModelProvider.Factory m2139invoke() {
                return componentActivity.getDefaultViewModelProviderFactory();
            }
        }, new Function0<CreationExtras>() {
            {
                super(0);
            }

            public final CreationExtras m2141invoke() {
                CreationExtras creationExtras;
                Function0 function02 = function0;
                return (function02 == null || (creationExtras = (CreationExtras) function02.invoke()) == null) ? componentActivity.getDefaultViewModelCreationExtras() : creationExtras;
            }
        });
    }

    @Override
    public ActivityCouponCodeBinding inflateLayout(LayoutInflater layoutInflater) {
        Intrinsics.checkNotNullParameter(layoutInflater, "layoutInflater");
        ActivityCouponCodeBinding inflate = ActivityCouponCodeBinding.inflate(layoutInflater);
        Intrinsics.checkNotNullExpressionValue(inflate, "inflate(layoutInflater)");
        return inflate;
    }

    public final AccountViewModel getViewModel() {
        return (AccountViewModel) this.viewModel.getValue();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setStatusBarColor(ContextCompat.getColor((Context) this, 2131100053));
        swipeRefresh();
        refresh();
        setupRv();
        initViews();
        setUpToolbar();
        observeEvent();
    }

    private final void setupRv() {
        int intExtra = getIntent().getIntExtra("topupAmount", 0);
        long longExtra = getIntent().getLongExtra("upiPgId", -1L);
        if (longExtra != -1) {
            getViewModel().setUpiPgId(Long.valueOf(longExtra));
        }
        CouponAdapter.INSTANCE.setTopUpAmount(intExtra);
        ((ActivityCouponCodeBinding) getBinding()).couponRv.setLayoutManager(new CustomLinearLayoutManager((Context) this));
        this.adapter = new CouponAdapter(null, new CouponAdapter.ItemClickListener() {
            @Override
            public void onApplyButtonClick(final CouponCodeModel coupon) {
                Intrinsics.checkNotNullParameter(coupon, "coupon");
                if (CouponAdapter.INSTANCE.getTopUpAmount() < coupon.getMinRechargeAmount()) {
                    try {
                        int minRechargeAmount = coupon.getMinRechargeAmount();
                        final CouponCodeActivity couponCodeActivity = CouponCodeActivity.this;
                        CouponRechargeListDialog couponRechargeListDialog = new CouponRechargeListDialog(minRechargeAmount, new Function1<TopUpModel, Unit>() {
                            {
                                super(1);
                            }

                            public Object invoke(Object obj) {
                                invoke((TopUpModel) obj);
                                return Unit.INSTANCE;
                            }

                            public final void invoke(TopUpModel topUpModel) {
                                Intrinsics.checkNotNullParameter(topUpModel, "newTopUpModel");
                                Intent intent = new Intent((Context) CouponCodeActivity.this, (Class<?>) PaymentDetailsActivity.class);
                                CouponCodeModel couponCodeModel = coupon;
                                intent.putExtra("couponCodeId", couponCodeModel.getId());
                                intent.putExtra("bonusPercentage", couponCodeModel.getBonusPercentage());
                                intent.putExtra("topUpId", topUpModel.getId());
                                intent.putExtra("plan", new Gson().toJson(topUpModel));
                                CouponCodeActivity.this.setResult(-1, intent);
                                CouponCodeActivity.this.finish();
                            }
                        });
                        couponRechargeListDialog.setCancelable(true);
                        if (!couponRechargeListDialog.isAdded() && !couponRechargeListDialog.isVisible()) {
                            couponRechargeListDialog.show(CouponCodeActivity.this.getSupportFragmentManager(), "RechargeDialog");
                            return;
                        }
                        return;
                    } catch (Exception unused) {
                        CouponCodeActivity couponCodeActivity2 = CouponCodeActivity.this;
                        Activity activity = (Activity) couponCodeActivity2;
                        String string = couponCodeActivity2.getString(2131951993);
                        Intrinsics.checkNotNullExpressionValue(string, "getString(R.string.error_unknown)");
                        ActivityExtKt.toast(activity, string);
                        return;
                    }
                }
                Intent intent = new Intent((Context) CouponCodeActivity.this, (Class<?>) PaymentDetailsActivity.class);
                intent.putExtra("couponCodeId", coupon.getId());
                intent.putExtra("bonusPercentage", coupon.getBonusPercentage());
                CouponCodeActivity.this.setResult(-1, intent);
                CouponCodeActivity.this.finish();
            }
        }, 1, null);
        ((ActivityCouponCodeBinding) getBinding()).couponRv.setAdapter(this.adapter);
    }

    private final void setUpToolbar() {
        try {
            Toolbar toolbar = this.toolbar;
            if (toolbar == null) {
                Intrinsics.throwUninitializedPropertyAccessException("toolbar");
                toolbar = null;
            }
            setSupportActionBar(toolbar);
            ActionBar supportActionBar = getSupportActionBar();
            if (supportActionBar != null) {
                supportActionBar.setDisplayHomeAsUpEnabled(true);
            }
        } catch (Exception e) {
            Timber.e(e, "setUpToolbar: Error ", new Object[0]);
        }
    }

    private final void initViews() {
        Toolbar toolbar = getBinding().toolbar;
        Intrinsics.checkNotNullExpressionValue(toolbar, "binding.toolbar");
        this.toolbar = toolbar;
    }

    private final Job observeEvent() {
        return BuildersKt.launch$default(LifecycleOwnerKt.getLifecycleScope((LifecycleOwner) this), (CoroutineContext) null, (CoroutineStart) null, new CouponCodeActivity$observeEvent$1(this, null), 3, (Object) null);
    }

    public final void sortAndAddItems(ArrayList<CouponCodeModel> coupons) {
        final int topUpAmount = CouponAdapter.INSTANCE.getTopUpAmount();
        TimeZone timeZone = DesugarTimeZone.getTimeZone("Asia/Kolkata");
        final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
        simpleDateFormat.setTimeZone(timeZone);
        CollectionsKt.sortWith(coupons, new Comparator() {
            @Override
            public final int compare(Object obj, Object obj2) {
                int sortAndAddItems$lambda$0;
                sortAndAddItems$lambda$0 = CouponCodeActivity.sortAndAddItems$lambda$0(topUpAmount, simpleDateFormat, (CouponCodeModel) obj, (CouponCodeModel) obj2);
                return sortAndAddItems$lambda$0;
            }
        });
        CouponAdapter couponAdapter = this.adapter;
        if (couponAdapter != null) {
            couponAdapter.addItems(coupons);
        }
    }

    public static final int sortAndAddItems$lambda$0(int i, SimpleDateFormat simpleDateFormat, CouponCodeModel couponCodeModel, CouponCodeModel couponCodeModel2) {
        Intrinsics.checkNotNullParameter(simpleDateFormat, "$sdf");
        if (i >= couponCodeModel.getMinRechargeAmount() && i >= couponCodeModel2.getMinRechargeAmount()) {
            Date parse = simpleDateFormat.parse(couponCodeModel.getExpiry());
            Date parse2 = simpleDateFormat.parse(couponCodeModel2.getExpiry());
            if (parse != null && parse2 != null) {
                return parse.compareTo(parse2);
            }
            if (parse != null) {
                return -1;
            }
            return parse2 != null ? 1 : 0;
        }
        if (i >= couponCodeModel.getMinRechargeAmount()) {
            return -1;
        }
        return i >= couponCodeModel2.getMinRechargeAmount() ? 1 : 0;
    }

    private final void swipeRefresh() {
        getBinding().swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            public final void onRefresh() {
                CouponCodeActivity.swipeRefresh$lambda$1(CouponCodeActivity.this);
            }
        });
    }

    public static final void swipeRefresh$lambda$1(CouponCodeActivity couponCodeActivity) {
        Intrinsics.checkNotNullParameter(couponCodeActivity, "this$0");
        couponCodeActivity.getBinding().swipeRefresh.setRefreshing(false);
        couponCodeActivity.refresh();
    }

    private final void refresh() {
        CouponAdapter couponAdapter = this.adapter;
        if (couponAdapter != null) {
            couponAdapter.clear();
        }
        getViewModel().getAllowedPaymentMethodV3(getViewModel().getUpiPgId());
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        Intrinsics.checkNotNullParameter(item, "item");
        if (item.getItemId() != 16908332) {
            return true;
        }
        finish();
        return true;
    }
}