Skip to content

Commit

Permalink
Make 'serviceRunning' static, to better keep track of service status in
Browse files Browse the repository at this point in the history
receivers
  • Loading branch information
edeleastar committed May 6, 2014
1 parent ee36cb4 commit 0a3dc09
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/com/marakana/yambax/BaseActivity.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.Menu
import android.view.MenuItem
import android.widget.Toast


interface Command
{
def void doCommand()
Expand All @@ -20,11 +21,11 @@ class BaseActivity extends Activity
.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)) ] as Command

val toggleService = [ | intent = new Intent(this, typeof(UpdaterService))
if (app.isServiceRunning)
if (YambaApplication.serviceRunning)
stopService(intent)
else
startService(intent)
app.serviceRunning = !app.serviceRunning] as Command
YambaApplication.serviceRunning = !YambaApplication.serviceRunning] as Command

val purge = [ | app.clearTimeline
Toast.makeText(this, R.string.msgAllDataPurged, Toast.LENGTH_LONG).show() ] as Command
Expand Down Expand Up @@ -64,8 +65,8 @@ class BaseActivity extends Activity
override onMenuOpened(int featureId, Menu menu)
{
val toggleItem = menu.findItem(R.id.itemToggleService)
toggleItem.title = if (app.isServiceRunning) R.string.titleServiceStop else R.string.titleServiceStart
toggleItem.icon = if (app.isServiceRunning) android.R.drawable.ic_media_pause else android.R.drawable.ic_media_play
toggleItem.title = if (YambaApplication.serviceRunning) R.string.titleServiceStop else R.string.titleServiceStart
toggleItem.icon = if (YambaApplication.serviceRunning) android.R.drawable.ic_media_pause else android.R.drawable.ic_media_play
true
}
}
4 changes: 2 additions & 2 deletions src/com/marakana/yambax/UpdaterService.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class UpdaterService extends BackgroundService
{
super.onStartCommand(intent, flags, startId)
startBackgroundTask
app.serviceRunning = true
YambaApplication.serviceRunning = true
START_STICKY;
}

override onDestroy()
{
super.onDestroy
stopBackgroundTask
app.serviceRunning = false
YambaApplication.serviceRunning = false
}

override def void doBackgroundTask()
Expand Down
16 changes: 11 additions & 5 deletions src/com/marakana/yambax/YambaApplication.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ class NetworkReceiver extends BroadcastReceiver

if (isNetworkDown)
{
Log.d("YAMBA", "onReceive: NOT connected, stopping UpdaterService");
context.stopService(new Intent(context, typeof(UpdaterService)))
if (YambaApplication.serviceRunning)
{
Log.d("YAMBA", "onReceive: NOT connected, stopping UpdaterService");
context.stopService(new Intent(context, typeof(UpdaterService)))
}
}
else
{
Log.d("YAMBA", "onReceive: connected, starting UpdaterService");
context.startService(new Intent(context, typeof(UpdaterService)))
if (!YambaApplication.serviceRunning)
{
Log.d("YAMBA", "onReceive: connected, starting UpdaterService");
context.startService(new Intent(context, typeof(UpdaterService)))
}
}
}
}
Expand All @@ -44,8 +50,8 @@ class BootReceiver extends BroadcastReceiver

class YambaApplication extends Application
{
public static boolean serviceRunning = false
@Property TwitterAPI twitter = new TwitterAPI("student", "password", "http://yamba.marakana.com/api")
@Property boolean serviceRunning = false
@Property List<Twitter.Status> timeline = new LinkedList<Status>

var prefsChanged = [ SharedPreferences prefs, String s |
Expand Down

0 comments on commit 0a3dc09

Please sign in to comment.