public static void loadTranslationData(Context context) {
    loadTranslationData(context, false);
} public static final String DB_KEY_KCMAINTNC = "key_kcmaintnc"; public static final String DB_KEY_STARTDATA = "key_startdata"; public static final String ERROR_TYPE_MAIN = "AM"; public static final int KCANOTIFY_DB_VERSION = 5; public static final String NOTICE_CHK_CODE = "chk002"; public static final List<String> PREFS_LIST = Arrays.asList(PREF_ARRAY); public static final String PREF_ALLOW_EXTFILTER = "allow_external_filter"; public static final String PREF_APK_DOWNLOAD_SITE = "apk_download_site"; public static final String PREF_CHECK_UPDATE_START = "check_update_start"; public static final String PREF_DATALOAD_ERROR_FLAG = "dataload_error_flag"; public static final String PREF_DEFAULT_APIVER = "default_apiver"; public static final String PREF_FAIRY_ICON = "fairy_icon"; public static final String PREF_KCA_DATA_VERSION = "kca_data_version"; public static final String PREF_KCA_LANGUAGE = "kca_language"; public static final String PREF_KCA_VERSION = "kca_version"; public static final String PREF_NOTICE_CHK_FLAG = "kr_notice_chk"; public static final String PREF_LAST_UPDATE_CHECK = "last_update_check"; public final static boolean FAIRY_SPECIAL_FLAG = false; public final static int FAIRY_SPECIAL_PREFIX = 900; public final static String START_APP = "StartApp"; public static boolean compareVersion(String version_current, String version_default) {
    if (version_current != null && version_current.length() == 0) return false;
    if (version_current.equals(version_default)) return true;
    String[] current_split = version_current.replace("r", ".0.").split("\\.");
    String[] default_split = version_default.replace("r", ".0.").split("\\.");
    int min_length = Math.min(current_split.length, default_split.length);
    for (int i = 0; i < min_length; i++) {
        if (current_split[i].trim().length() > 0 && default_split[i].trim().length() > 0) {
            if (Integer.parseInt(current_split[i]) > Integer.parseInt(default_split[i])) {
                return true;
            } else if (Integer.parseInt(current_split[i]) < Integer.parseInt(default_split[i])) {
                return false;
            }
        }
    }
    return current_split.length > default_split.length;
} public static Boolean getBooleanPreferences(Context ctx, String key) {
    SharedPreferences pref = ctx.getSharedPreferences("pref", Context.MODE_PRIVATE);
    return pref.getBoolean(key, false);
} public static int getId(String resourceName, Class<?> c) {
    try {
        Field idField = c.getDeclaredField(resourceName);
        return idField.getInt(idField);
    } catch (Exception e) {
        throw new RuntimeException("No resource ID found for: "
                + resourceName + " / " + c, e);
    }
} public static String getStringFromException(Exception ex) {
    StringWriter errors = new StringWriter();
    ex.printStackTrace(new PrintWriter(errors));
    return errors.toString().replaceAll("\n", " / ").replaceAll("\t", "");
} public static String getStringPreferences(Context ctx, String key) {
    SharedPreferences pref = ctx.getSharedPreferences("pref", Context.MODE_PRIVATE);
    try {
        return String.valueOf(pref.getInt(key, 0));
    } catch (Exception e) {
        // Nothing to do
    }
    return pref.getString(key, "");
} public static byte[] gzipdecompress(byte[] contentBytes) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        ByteStreams.copy(new GZIPInputStream(new ByteArrayInputStream(contentBytes)), out);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return out.toByteArray();
} public static void sendUserAnalytics(Context context, String event, JsonObject value) {
    Bundle params = new Bundle();
    FirebaseAnalytics mFirebaseAnalytics = FirebaseAnalytics.getInstance(context);
    if (value != null) {
        for (String key: value.keySet()) {
            params.putString(key, value.get(key).getAsString());
        }
    }
    mFirebaseAnalytics.logEvent(event, params);
} public static void setPreferences(Context ctx, String key, Object value) {
    SharedPreferences pref = ctx.getSharedPreferences("pref", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = pref.edit();
    if (value instanceof String) {
        editor.putString(key, (String) value);
    } else if (value instanceof Boolean) {
        editor.putBoolean(key, (Boolean) value);
    } else if (value instanceof Integer) {
        editor.putString(key, String.valueOf(value));
    } else {
        editor.putString(key, value.toString());
    }
    editor.commit();
}
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.AssetManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.common.io.ByteStreams;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
import static com.antest1.kcanotify.KcaApiData.loadTranslationData;
import static com.antest1.kcanotify.KcaConstants.DB_KEY_KCMAINTNC;
import static com.antest1.kcanotify.KcaConstants.DB_KEY_STARTDATA;
import static com.antest1.kcanotify.KcaConstants.ERROR_TYPE_MAIN;
import static com.antest1.kcanotify.KcaConstants.KCANOTIFY_DB_VERSION;
import static com.antest1.kcanotify.KcaConstants.NOTICE_CHK_CODE;
import static com.antest1.kcanotify.KcaConstants.PREFS_LIST;
import static com.antest1.kcanotify.KcaConstants.PREF_ALLOW_EXTFILTER;
import static com.antest1.kcanotify.KcaConstants.PREF_APK_DOWNLOAD_SITE;
import static com.antest1.kcanotify.KcaConstants.PREF_CHECK_UPDATE_START;
import static com.antest1.kcanotify.KcaConstants.PREF_DATALOAD_ERROR_FLAG;
import static com.antest1.kcanotify.KcaConstants.PREF_DEFAULT_APIVER;
import static com.antest1.kcanotify.KcaConstants.PREF_FAIRY_ICON;
import static com.antest1.kcanotify.KcaConstants.PREF_KCA_DATA_VERSION;
import static com.antest1.kcanotify.KcaConstants.PREF_KCA_LANGUAGE;
import static com.antest1.kcanotify.KcaConstants.PREF_KCA_VERSION;
import static com.antest1.kcanotify.KcaConstants.PREF_NOTICE_CHK_FLAG;
import static com.antest1.kcanotify.KcaConstants.PREF_LAST_UPDATE_CHECK;
import static com.antest1.kcanotify.KcaFairySelectActivity.FAIRY_SPECIAL_FLAG;
import static com.antest1.kcanotify.KcaFairySelectActivity.FAIRY_SPECIAL_PREFIX;
import static com.antest1.kcanotify.KcaUseStatConstant.START_APP;
import static com.antest1.kcanotify.KcaUtils.compareVersion;
import static com.antest1.kcanotify.KcaUtils.getBooleanPreferences;
import static com.antest1.kcanotify.KcaUtils.getId;
import static com.antest1.kcanotify.KcaUtils.getStringFromException;
import static com.antest1.kcanotify.KcaUtils.getStringPreferences;
import static com.antest1.kcanotify.KcaUtils.gzipdecompress;
import static com.antest1.kcanotify.KcaUtils.sendUserAnalytics;
import static com.antest1.kcanotify.KcaUtils.setPreferences;
package com.antest1.kcanotify;






public class InitStartActivity extends Activity {
    public static final String ACTION_RESET = "ACTION_RESET";

    boolean download_finished = false;
    Handler handler = new Handler();

    KcaDBHelper dbHelper;
    KcaDownloader downloader;
    TextView appname, appversion, appmessage;
    ImageView appfront;

    boolean is_destroyed = false;
    int fairy_flag, new_resversion;
    boolean reset_flag = false;
    boolean validated_flag = false;
    boolean is_skipped = false;

    static Gson gson = new Gson();
    Type listType = new TypeToken<ArrayList<JsonObject>>(){}.getType();

    public String getStringWithLocale(int id) {
        return KcaUtils.getStringWithLocale(getApplicationContext(), getBaseContext(), id);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_init_download);
        Log.e("KCA-DA", "created");

        sendUserAnalytics(getApplicationContext(), START_APP, null);

        Intent mainIntent = getIntent();
        reset_flag = mainIntent.getBooleanExtra(ACTION_RESET, false);
        is_destroyed = false;

        PreferenceManager.setDefaultValues(this, R.xml.pref_settings, false);
        setDefaultPreferences();

        dbHelper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION);
        downloader = KcaUtils.getInfoDownloader(getApplicationContext());

        KcaApiData.setDBHelper(dbHelper);

        appname = findViewById(R.id.app_title);
        appname.setText(getStringWithLocale(R.string.app_name));

        appversion = findViewById(R.id.app_version);
        appversion.setText(getString(R.string.app_version));

        appmessage = findViewById(R.id.app_message);
        appmessage.setText("");

        appfront = findViewById(R.id.app_icon);
        int img_id = (int) (Math.random() * 4);
        appfront.setImageResource(R.mipmap.main_image);

        int fairy_id = Integer.parseInt(getStringPreferences(getApplicationContext(), PREF_FAIRY_ICON));
        if (!FAIRY_SPECIAL_FLAG && fairy_id >= FAIRY_SPECIAL_PREFIX) {
            setPreferences(getApplicationContext(), PREF_FAIRY_ICON, 0);
        }

        // Initialize resources
        setPreferences(getApplicationContext(), PREF_DATALOAD_ERROR_FLAG, false);