X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=src%2Fro%2Fieval%2Ffonbot%2FFonBotMainService.java;h=dd13affe715aef6f403d1fba71fc6c87e00bf8ac;hb=828b60f224e51edfb1840d03f7a6d745b44e01b7;hp=e0bc6c0cf5452b7a76868843a167be08a9d372b6;hpb=ca40a5cc0f95f37d2ac3008d5fa3f0adaf47d736;p=fonbot.git diff --git a/src/ro/ieval/fonbot/FonBotMainService.java b/src/ro/ieval/fonbot/FonBotMainService.java index e0bc6c0..dd13aff 100644 --- a/src/ro/ieval/fonbot/FonBotMainService.java +++ b/src/ro/ieval/fonbot/FonBotMainService.java @@ -3,6 +3,7 @@ package ro.ieval.fonbot; import static ro.ieval.fonbot.R.string.*; import static ro.ieval.fonbot.Utils.toNonNull; +import java.net.SocketTimeoutException; import java.util.Collections; import java.util.EnumSet; import java.util.Set; @@ -77,9 +78,12 @@ public final class FonBotMainService extends Service { Log.d("LongPollRunnable", "Long polling started"); while(man.getActiveNetworkInfo() != null && man.getActiveNetworkInfo().isConnected()) try { - runnable.run(); + runnable.doRun(); + } catch (final SocketTimeoutException e){ + Log.d("LongPollRunnable", "Socket timeout, refreshing connection"); } catch (final Exception ex){ ex.printStackTrace(); + break; } Log.d("LongPollRunnable", "Long polling stopped"); } @@ -93,8 +97,7 @@ public final class FonBotMainService extends Service { * Broadcast action: remove an ongoing event */ public static final String ACTION_DELETE_ONGOING="ro.ieval.fonbot.FonBotMainService.ACTION_DELETE_ONGOING"; - /** Broadcast action: trigger a server poll */ - public static final String ACTION_TRIGGER_POLL="ro.ieval.fonbot.FonBotMainService.ACTION_TRIGGER_POLL"; + /** * Extra: ongoing event id * @@ -160,13 +163,14 @@ public final class FonBotMainService extends Service { @Override public int onStartCommand(final @Nullable Intent intent, final int flags, final int startId) { + final boolean showOngoing=PreferenceManager.getDefaultSharedPreferences(this).getBoolean("ongoing", false); boolean updateNotification = false; - if(intent!=null && intent.getAction()==ACTION_PUT_ONGOING && intent.hasExtra(EXTRA_ONGOING_ID)){ + if(intent!=null && intent.getAction()==ACTION_PUT_ONGOING && intent.hasExtra(EXTRA_ONGOING_ID) && showOngoing){ ongoing.add(OngoingEvent.values()[intent.getIntExtra(EXTRA_ONGOING_ID, 0)]); LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(ACTION_ONGOING_UPDATE)); updateNotification=true; } - if(intent!=null && intent.getAction()==ACTION_DELETE_ONGOING && intent.hasExtra(EXTRA_ONGOING_ID)){ + if(intent!=null && intent.getAction()==ACTION_DELETE_ONGOING && intent.hasExtra(EXTRA_ONGOING_ID) && showOngoing){ ongoing.remove(OngoingEvent.values()[intent.getIntExtra(EXTRA_ONGOING_ID, 0)]); LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(ACTION_ONGOING_UPDATE)); updateNotification=true; @@ -177,6 +181,8 @@ public final class FonBotMainService extends Service { longPollThread.start(); } + ExecutableRunnable.retryTasks(); + final boolean runForeground=PreferenceManager.getDefaultSharedPreferences(this).getBoolean("foreground", false); if(!runForeground) stopForeground(true); @@ -194,7 +200,7 @@ public final class FonBotMainService extends Service { setContentIntent(PendingIntent.getActivity(this, 0, mainIntent, 0)). setOngoing(true); - if(!ongoing.isEmpty()) { + if(showOngoing && !ongoing.isEmpty()) { final NotificationCompat.InboxStyle inboxBuilder=new NotificationCompat.InboxStyle(builder); for(final OngoingEvent event : ongoing)