diff --git a/app/src/main/java/ua/samosfator/moduleok/App.java b/app/src/main/java/ua/samosfator/moduleok/App.java index 62e424d..91543b3 100644 --- a/app/src/main/java/ua/samosfator/moduleok/App.java +++ b/app/src/main/java/ua/samosfator/moduleok/App.java @@ -1,6 +1,8 @@ package ua.samosfator.moduleok; +import android.app.ActivityManager; import android.app.Application; +import android.app.Service; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; @@ -77,4 +79,14 @@ public static String getFormattedUpdateTime() { public static void setUpdateTime(Date updateTime) { App.updateTime = updateTime; } + + public static boolean isServiceRunning(Class serviceClass) { + ActivityManager manager = (ActivityManager) App.getContext().getSystemService(Context.ACTIVITY_SERVICE); + for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { + if (serviceClass.getName().equals(service.service.getClassName())) { + return true; + } + } + return false; + } } \ No newline at end of file diff --git a/app/src/main/java/ua/samosfator/moduleok/MainActivity.java b/app/src/main/java/ua/samosfator/moduleok/MainActivity.java index a38f162..e23ba3e 100644 --- a/app/src/main/java/ua/samosfator/moduleok/MainActivity.java +++ b/app/src/main/java/ua/samosfator/moduleok/MainActivity.java @@ -21,8 +21,6 @@ import ua.samosfator.moduleok.event.LogoutEvent; import ua.samosfator.moduleok.event.RefreshEndEvent; import ua.samosfator.moduleok.event.RefreshEvent; -import ua.samosfator.moduleok.fragment.last_total_fragment.LastTotalFragment; -import ua.samosfator.moduleok.fragment.modules_fragment.ModulesFragment; import ua.samosfator.moduleok.fragment.navigation_drawer_fragment.NavigationDrawerFragment; import ua.samosfator.moduleok.notification.ScoreCheckerService; @@ -44,7 +42,7 @@ protected void onCreate(Bundle savedInstanceState) { initToolbar(); initNavigationDrawer(); - if (Auth.isLoggedIn() && App.hasInternetConnection()) { + if (Auth.isLoggedIn() && App.hasInternetConnection() && !App.isServiceRunning(ScoreCheckerService.class)) { startService(new Intent(this, ScoreCheckerService.class)); } } diff --git a/app/src/main/java/ua/samosfator/moduleok/notification/NearbyModules.java b/app/src/main/java/ua/samosfator/moduleok/notification/NearbyModules.java index 6d77f90..86749bc 100644 --- a/app/src/main/java/ua/samosfator/moduleok/notification/NearbyModules.java +++ b/app/src/main/java/ua/samosfator/moduleok/notification/NearbyModules.java @@ -27,6 +27,7 @@ public static int getCount() { private static void initModulesDatesList() { modulesDates.clear(); List subjects = getCurrentSemesterSubjects(); + System.setProperty("java8.util.Spliterators.assume.oracle.collections.impl", "false"); StreamSupport.stream(subjects) .map(Subject::getModules) .map(StreamSupport::stream) diff --git a/app/src/main/java/ua/samosfator/moduleok/notification/ScoreCheckerService.java b/app/src/main/java/ua/samosfator/moduleok/notification/ScoreCheckerService.java index 66d8c5a..a9adf62 100644 --- a/app/src/main/java/ua/samosfator/moduleok/notification/ScoreCheckerService.java +++ b/app/src/main/java/ua/samosfator/moduleok/notification/ScoreCheckerService.java @@ -38,6 +38,7 @@ public IBinder onBind(Intent intent) { @Override public void onCreate() { App.registerClassForEventBus(this); + System.setProperty("java8.util.Spliterators.assume.oracle.collections.impl", "false"); Toast.makeText(this, "Congrats! ScoreCheckerService Created", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); }