APK反编译源代码展示 - 南明离火平台提供

应用版本信息
应用名称:Unit Converter
版本号:2.0
包名称:com.apochstudios.unitconverter2

MD5 校验值:5ead1ed7f35383ec0e7e763a064d5934

反编译源代码说明

RateThisApp.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。


package com.apochstudios.unitconverter2;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import androidx.appcompat.app.AlertDialog;
import java.lang.ref.WeakReference;
import java.util.Date;

public class RateThisApp {
    public static final boolean DEBUG = false;
    private static final String KEY_ASK_LATER_DATE = "rta_ask_later_date";
    private static final String KEY_INSTALL_DATE = "rta_install_date";
    private static final String KEY_LAUNCH_TIMES = "rta_launch_times";
    private static final String KEY_OPT_OUT = "rta_opt_out";
    private static final String PREF_NAME = "com.apochstudios.unitconverter2";
    private static final String TAG = "RateThisApp";
    private static Date mInstallDate = new Date();
    private static int mLaunchTimes = 0;
    private static boolean mOptOut = false;
    private static Date mAskLaterDate = new Date();
    private static Config sConfig = new Config();
    private static Callback sCallback = null;
    private static WeakReference<AlertDialog> sDialogRef = null;

    public interface Callback {
        void onCancelClicked();

        void onNoClicked();

        void onYesClicked();
    }

    private static void log(String str) {
    }

    public static void init(Config config) {
        sConfig = config;
    }

    public static void setCallback(Callback callback) {
        sCallback = callback;
    }

    public static void onStart(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("com.apochstudios.unitconverter2", 0);
        SharedPreferences.Editor edit = sharedPreferences.edit();
        if (sharedPreferences.getLong(KEY_INSTALL_DATE, 0L) == 0) {
            storeInstallDate(context, edit);
        }
        int i = sharedPreferences.getInt(KEY_LAUNCH_TIMES, 0) + 1;
        edit.putInt(KEY_LAUNCH_TIMES, i);
        log("Launch times; " + i);
        edit.commit();
        mInstallDate = new Date(sharedPreferences.getLong(KEY_INSTALL_DATE, 0L));
        mLaunchTimes = sharedPreferences.getInt(KEY_LAUNCH_TIMES, 0);
        mOptOut = sharedPreferences.getBoolean(KEY_OPT_OUT, false);
        mAskLaterDate = new Date(sharedPreferences.getLong(KEY_ASK_LATER_DATE, 0L));
        printStatus(context);
    }

    public static boolean showRateDialogIfNeeded(Context context) {
        if (!shouldShowRateDialog()) {
            return false;
        }
        showRateDialog(context);
        return true;
    }

    public static boolean showRateDialogIfNeeded(Context context, int i) {
        if (!shouldShowRateDialog()) {
            return false;
        }
        showRateDialog(context, i);
        return true;
    }

    public static boolean shouldShowRateDialog() {
        if (mOptOut) {
            return false;
        }
        if (mLaunchTimes >= sConfig.mCriteriaLaunchTimes) {
            return true;
        }
        long j = sConfig.mCriteriaInstallDays * 24 * 60 * 60 * 1000;
        return new Date().getTime() - mInstallDate.getTime() >= j && new Date().getTime() - mAskLaterDate.getTime() >= j;
    }

    public static void showRateDialog(Context context) {
        showRateDialog(context, new AlertDialog.Builder(context));
    }

    public static void showRateDialog(Context context, int i) {
        showRateDialog(context, new AlertDialog.Builder(context, i));
    }

    public static void stopRateDialog(Context context) {
        setOptOut(context, true);
    }

    private static void showRateDialog(final Context context, AlertDialog.Builder builder) {
        WeakReference<AlertDialog> weakReference = sDialogRef;
        if (weakReference == null || weakReference.get() == null) {
            int i = sConfig.mTitleId != 0 ? sConfig.mTitleId : R.string.rta_dialog_title;
            int i2 = sConfig.mMessageId != 0 ? sConfig.mMessageId : R.string.rta_dialog_message;
            int i3 = sConfig.mCancelButton != 0 ? sConfig.mCancelButton : R.string.rta_dialog_cancel;
            int i4 = sConfig.mNoButtonId != 0 ? sConfig.mNoButtonId : R.string.rta_dialog_no;
            int i5 = sConfig.mYesButtonId != 0 ? sConfig.mYesButtonId : R.string.rta_dialog_ok;
            builder.setTitle(i);
            builder.setMessage(i2);
            builder.setPositiveButton(i5, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i6) {
                    if (RateThisApp.sCallback != null) {
                        RateThisApp.sCallback.onYesClicked();
                    }
                    context.startActivity(new Intent("android.intent.action.VIEW", Uri.parse("https://play.google.com/store/apps/details?id=" + context.getPackageName())));
                    RateThisApp.setOptOut(context, true);
                }
            });
            builder.setNeutralButton(i3, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i6) {
                    if (RateThisApp.sCallback != null) {
                        RateThisApp.sCallback.onCancelClicked();
                    }
                    RateThisApp.clearSharedPreferences(context);
                    RateThisApp.storeAskLaterDate(context);
                }
            });
            builder.setNegativeButton(i4, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i6) {
                    if (RateThisApp.sCallback != null) {
                        RateThisApp.sCallback.onNoClicked();
                    }
                    RateThisApp.setOptOut(context, true);
                }
            });
            builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialogInterface) {
                    if (RateThisApp.sCallback != null) {
                        RateThisApp.sCallback.onCancelClicked();
                    }
                    RateThisApp.clearSharedPreferences(context);
                    RateThisApp.storeAskLaterDate(context);
                }
            });
            builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialogInterface) {
                    RateThisApp.sDialogRef.clear();
                }
            });
            sDialogRef = new WeakReference<>(builder.show());
        }
    }

    public static void clearSharedPreferences(Context context) {
        SharedPreferences.Editor edit = context.getSharedPreferences("com.apochstudios.unitconverter2", 0).edit();
        edit.remove(KEY_INSTALL_DATE);
        edit.remove(KEY_LAUNCH_TIMES);
        edit.commit();
    }

    public static void setOptOut(Context context, boolean z) {
        SharedPreferences.Editor edit = context.getSharedPreferences("com.apochstudios.unitconverter2", 0).edit();
        edit.putBoolean(KEY_OPT_OUT, z);
        edit.commit();
        mOptOut = z;
    }

    private static void storeInstallDate(Context context, SharedPreferences.Editor editor) {
        Date date = new Date();
        if (Build.VERSION.SDK_INT >= 9) {
            try {
                date = new Date(context.getPackageManager().getPackageInfo(context.getPackageName(), 0).firstInstallTime);
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
        }
        editor.putLong(KEY_INSTALL_DATE, date.getTime());
        log("First install: " + date.toString());
    }

    public static void storeAskLaterDate(Context context) {
        SharedPreferences.Editor edit = context.getSharedPreferences("com.apochstudios.unitconverter2", 0).edit();
        edit.putLong(KEY_ASK_LATER_DATE, System.currentTimeMillis());
        edit.commit();
    }

    private static void printStatus(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("com.apochstudios.unitconverter2", 0);
        log("*** RateThisApp Status ***");
        log("Install Date: " + new Date(sharedPreferences.getLong(KEY_INSTALL_DATE, 0L)));
        log("Launch Times: " + sharedPreferences.getInt(KEY_LAUNCH_TIMES, 0));
        log("Opt out: " + sharedPreferences.getBoolean(KEY_OPT_OUT, false));
    }

    public static class Config {
        private int mCancelButton;
        private int mCriteriaInstallDays;
        private int mCriteriaLaunchTimes;
        private int mMessageId;
        private int mNoButtonId;
        private int mTitleId;
        private int mYesButtonId;

        public Config() {
            this(7, 10);
        }

        public Config(int i, int i2) {
            this.mTitleId = 0;
            this.mMessageId = 0;
            this.mYesButtonId = 0;
            this.mNoButtonId = 0;
            this.mCancelButton = 0;
            this.mCriteriaInstallDays = i;
            this.mCriteriaLaunchTimes = i2;
        }

        public void setTitle(int i) {
            this.mTitleId = i;
        }

        public void setMessage(int i) {
            this.mMessageId = i;
        }

        public void setYesButtonText(int i) {
            this.mYesButtonId = i;
        }

        public void setNoButtonText(int i) {
            this.mNoButtonId = i;
        }

        public void setCancelButtonText(int i) {
            this.mCancelButton = i;
        }
    }
}