// Path: app/src/main/java/com/chickenkiller/upods2/controllers/app/UpodsApplication.java
// public class UpodsApplication extends Application {
// 
//     private static final int CHECK_NEW_EPISODS_INTENT_CODE = 2302;
// 
//     private static final String TAG = "UpodsApplication";
//     private static Context applicationContext;
//     private static SQLdatabaseManager databaseManager;
//     private static boolean isLoaded;
// 
//     @Override
//     public void onCreate() {
//         isLoaded = false;
//         applicationContext = getApplicationContext();
//         YandexMetrica.activate(getApplicationContext(), Config.YANDEX_METRICS_API_KEY);
//         YandexMetrica.enableActivityAutoTracking(this);
//         FacebookSdk.sdkInitialize(applicationContext);
//         LoginMaster.getInstance().init();
//         new Prefs.Builder()
//                 .setContext(this)
//                 .setMode(ContextWrapper.MODE_PRIVATE)
//                 .setPrefsName(getPackageName())
//                 .setUseDefaultSharedPreference(true).build();
// 
//         super.onCreate();
//     }
// 
//     /**
//      * All resources which can be loaded not in onCreate(), should be load here,
//      * this function called while splash screen is active
//      */
//     public static void initAllResources() {
//         if (!isLoaded) {
//             databaseManager = new SQLdatabaseManager(applicationContext);
//             SettingsManager.getInstace().init();
//             Category.initPodcastsCatrgories();
//             SimpleCacheManager.getInstance().removeExpiredCache();
//             runMainService();
//             setAlarmManagerTasks();
//             isLoaded = true;
//         }
//     }
// 
//     private static void runMainService() {
//         applicationContext.startService(new Intent(applicationContext, MainService.class));
//     }
// 
//     public static void setAlarmManagerTasks() {
//         setAlarmManagerTasks(applicationContext);
//     }
// 
//     public static void setAlarmManagerTasks(Context context) {
//         try {
//             if (ProfileManager.getInstance().getSubscribedPodcasts().size() == 0) {
//                 return;
//             }
//             AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
//             Intent intent = new Intent(context, NetworkTasksService.class);
//             intent.setAction(NetworkTasksService.ACTION_CHECK_FOR_NEW_EPISODS);
//             PendingIntent alarmIntent = PendingIntent.getService(context, CHECK_NEW_EPISODS_INTENT_CODE, intent,
//                     PendingIntent.FLAG_UPDATE_CURRENT);
// 
//             if (SettingsManager.getInstace().getBooleanSettingsValue(SettingsManager.JS_NOTIFY_EPISODES)) {
//                 long interval = SettingsManager.getInstace().getIntSettingsValue(SettingsManager.JS_PODCASTS_UPDATE_TIME);
//                 //interval = TimeUnit.MINUTES.toMillis(60);
//                 alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
//                         SystemClock.elapsedRealtime(),
//                         interval, alarmIntent);
//                 Logger.printInfo(TAG, "Alarm managers - Episods check for updates task added");
//             } else {
//                 alarmIntent.cancel();
//                 alarmMgr.cancel(alarmIntent);
//                 Logger.printInfo(TAG, "Alarm managers - Episods check for updates task canceled");
//             }
//         } catch (Exception e) {
//             Logger.printInfo(TAG, "Alarm managers - can't set alarm manager");
//             e.printStackTrace();
//         }
//     }
// 
//     @Override
//     public void onTerminate() {
//         super.onTerminate();
//     }
// 
//     public static Context getContext() {
//         return applicationContext;
//     }
// 
//     public static SQLdatabaseManager getDatabaseManager() {
//         return databaseManager;
//     }
// }


import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.Uri;
import com.chickenkiller.upods2.controllers.app.UpodsApplication;
import java.io.File;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

    public static boolean isUrlReachable(String urlToCheck) {
        try {
            URL url = new URL(urlToCheck);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setConnectTimeout(1000);
            int code = connection.getResponseCode();
            if (code == 200) {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    public static void rateApp(Context context) {
        Uri uri = Uri.parse("market://details?id=" + context.getPackageName());
        Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);

        goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
        try {
            context.startActivity(goToMarket);
        } catch (ActivityNotFoundException e) {
            context.startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://play.google.com/store/apps/details?id=" + context.getPackageName())));
        }
    }

    public static boolean isPackageInstalled(String packagename) {
// Path: app/src/main/java/com/chickenkiller/upods2/controllers/app/UpodsApplication.java
// public class UpodsApplication extends Application {
// 
//     private static final int CHECK_NEW_EPISODS_INTENT_CODE = 2302;
// 
//     private static final String TAG = "UpodsApplication";
//     private static Context applicationContext;
//     private static SQLdatabaseManager databaseManager;
//     private static boolean isLoaded;
// 
//     @Override
//     public void onCreate() {
//         isLoaded = false;
//         applicationContext = getApplicationContext();
//         YandexMetrica.activate(getApplicationContext(), Config.YANDEX_METRICS_API_KEY);
//         YandexMetrica.enableActivityAutoTracking(this);
//         FacebookSdk.sdkInitialize(applicationContext);
//         LoginMaster.getInstance().init();
//         new Prefs.Builder()
//                 .setContext(this)
//                 .setMode(ContextWrapper.MODE_PRIVATE)
//                 .setPrefsName(getPackageName())
//                 .setUseDefaultSharedPreference(true).build();
// 
//         super.onCreate();
//     }
// 
//     /**
//      * All resources which can be loaded not in onCreate(), should be load here,
//      * this function called while splash screen is active
//      */
//     public static void initAllResources() {
//         if (!isLoaded) {
//             databaseManager = new SQLdatabaseManager(applicationContext);
//             SettingsManager.getInstace().init();
//             Category.initPodcastsCatrgories();
//             SimpleCacheManager.getInstance().removeExpiredCache();
//             runMainService();
//             setAlarmManagerTasks();
//             isLoaded = true;
//         }
//     }
// 
//     private static void runMainService() {
//         applicationContext.startService(new Intent(applicationContext, MainService.class));
//     }
// 
//     public static void setAlarmManagerTasks() {
//         setAlarmManagerTasks(applicationContext);
//     }
// 
//     public static void setAlarmManagerTasks(Context context) {
//         try {
//             if (ProfileManager.getInstance().getSubscribedPodcasts().size() == 0) {
//                 return;
//             }
//             AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
//             Intent intent = new Intent(context, NetworkTasksService.class);
//             intent.setAction(NetworkTasksService.ACTION_CHECK_FOR_NEW_EPISODS);
//             PendingIntent alarmIntent = PendingIntent.getService(context, CHECK_NEW_EPISODS_INTENT_CODE, intent,
//                     PendingIntent.FLAG_UPDATE_CURRENT);
// 
//             if (SettingsManager.getInstace().getBooleanSettingsValue(SettingsManager.JS_NOTIFY_EPISODES)) {
//                 long interval = SettingsManager.getInstace().getIntSettingsValue(SettingsManager.JS_PODCASTS_UPDATE_TIME);
//                 //interval = TimeUnit.MINUTES.toMillis(60);
//                 alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
//                         SystemClock.elapsedRealtime(),
//                         interval, alarmIntent);
//                 Logger.printInfo(TAG, "Alarm managers - Episods check for updates task added");
//             } else {
//                 alarmIntent.cancel();
//                 alarmMgr.cancel(alarmIntent);
//                 Logger.printInfo(TAG, "Alarm managers - Episods check for updates task canceled");
//             }
//         } catch (Exception e) {
//             Logger.printInfo(TAG, "Alarm managers - can't set alarm manager");
//             e.printStackTrace();
//         }
//     }
// 
//     @Override
//     public void onTerminate() {
//         super.onTerminate();
//     }
// 
//     public static Context getContext() {
//         return applicationContext;
//     }
// 
//     public static SQLdatabaseManager getDatabaseManager() {
//         return databaseManager;
//     }
// }


// Path: app/src/main/java/com/chickenkiller/upods2/utils/GlobalUtils.java
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.Uri;
import com.chickenkiller.upods2.controllers.app.UpodsApplication;
import java.io.File;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


    public static boolean isUrlReachable(String urlToCheck) {
        try {
            URL url = new URL(urlToCheck);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setConnectTimeout(1000);
            int code = connection.getResponseCode();
            if (code == 200) {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    public static void rateApp(Context context) {
        Uri uri = Uri.parse("market://details?id=" + context.getPackageName());
        Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);

        goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
        try {
            context.startActivity(goToMarket);
        } catch (ActivityNotFoundException e) {
            context.startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://play.google.com/store/apps/details?id=" + context.getPackageName())));
        }
    }

    public static boolean isPackageInstalled(String packagename) {
        PackageManager pm = UpodsApplication.getContext().getPackageManager();