mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-12 23:30:59 +00:00
Implements use of message sending service for pings.
Replaced network helper with message sending service in PingHelper class. Added message service start and destroy in regatta activity.
This commit is contained in:
1 parent
9f50ef2514
commit
498ae8e898
3 files changed
+56
-28
No files matched your search
+50
-1
@@ -1,8 +1,11 @@
|
||||
package com.sap.sailing.android.buoy.positioning.app.ui.activities;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.os.IBinder;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
@@ -17,6 +20,7 @@ import com.sap.sailing.android.buoy.positioning.app.valueobjects.CheckinData;
|
||||
import com.sap.sailing.android.buoy.positioning.app.valueobjects.MarkInfo;
|
||||
import com.sap.sailing.android.shared.data.AbstractCheckinData;
|
||||
import com.sap.sailing.android.shared.logging.ExLog;
|
||||
import com.sap.sailing.android.shared.services.sending.MessageSendingService;
|
||||
import com.sap.sailing.android.shared.ui.activities.AbstractRegattaActivity;
|
||||
import com.sap.sailing.android.shared.ui.customviews.OpenSansToolbar;
|
||||
|
||||
@@ -32,6 +36,8 @@ public class RegattaActivity extends AbstractRegattaActivity {
|
||||
private String checkinUrl;
|
||||
|
||||
private AppPreferences prefs;
|
||||
private MessageSendingService messageSendingService;
|
||||
private boolean messageSendingServiceBound;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -76,6 +82,28 @@ public class RegattaActivity extends AbstractRegattaActivity {
|
||||
setTitle(leaderboardName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
Intent messageSendingServiceIntent = new Intent(this, MessageSendingService.class);
|
||||
bindService(messageSendingServiceIntent, messageSendingServiceConnection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
if (messageSendingServiceBound) {
|
||||
messageSendingService.unregisterAPIConnectivityListener();
|
||||
unbindService(messageSendingServiceConnection);
|
||||
|
||||
messageSendingServiceBound = false;
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
ExLog.i(this, TAG, "Unbound transmitting Service");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
@@ -138,4 +166,25 @@ public class RegattaActivity extends AbstractRegattaActivity {
|
||||
this.marks = marks;
|
||||
}
|
||||
|
||||
/** Defines callbacks for service binding, passed to bindService() */
|
||||
private ServiceConnection messageSendingServiceConnection = new ServiceConnection() {
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
||||
// We've bound to LocalService, cast the IBinder and get
|
||||
// LocalService instance
|
||||
MessageSendingService.MessageSendingBinder binder = (MessageSendingService.MessageSendingBinder) service;
|
||||
messageSendingService = binder.getService();
|
||||
messageSendingServiceBound = true;
|
||||
if (BuildConfig.DEBUG) {
|
||||
ExLog.i(RegattaActivity.this, TAG, "connected to message sending service");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName arg0) {
|
||||
messageSendingServiceBound = false;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
+1
-3
@@ -145,8 +145,6 @@ public class DatabaseHelper {
|
||||
* When checking in, store info on the event, the competitor and the leaderboard in the database.
|
||||
*
|
||||
* @param context
|
||||
* @param event
|
||||
* @param competitor
|
||||
* @param leaderboard
|
||||
* @return success or failure
|
||||
* @throws GeneralDatabaseHelperException
|
||||
@@ -209,7 +207,7 @@ public class DatabaseHelper {
|
||||
|
||||
public void storeMarkPing(Context context, MarkPingInfo markPing) throws GeneralDatabaseHelperException{
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
|
||||
deletePingsFromDataBase(context, markPing.getMarkId());
|
||||
ArrayList<ContentProviderOperation> opList = new ArrayList<ContentProviderOperation>();
|
||||
ContentValues mpcv = new ContentValues();
|
||||
mpcv.put(MarkPing.MARK_ID, markPing.getMarkId());
|
||||
|
||||
+5
-24
@@ -10,6 +10,7 @@ import com.sap.sailing.android.buoy.positioning.app.valueobjects.MarkPingInfo;
|
||||
import com.sap.sailing.android.shared.data.LeaderboardInfo;
|
||||
import com.sap.sailing.android.shared.data.http.HttpJsonPostRequest;
|
||||
import com.sap.sailing.android.shared.logging.ExLog;
|
||||
import com.sap.sailing.android.shared.services.sending.MessageSendingService;
|
||||
import com.sap.sailing.android.shared.util.NetworkHelper;
|
||||
import com.sap.sailing.android.shared.util.NetworkHelper.NetworkHelperError;
|
||||
import com.sap.sailing.android.shared.util.NetworkHelper.NetworkHelperSuccessListener;
|
||||
@@ -19,6 +20,7 @@ import org.json.JSONObject;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PingHelper {
|
||||
private static String TAG = PingHelper.class.getName();
|
||||
@@ -36,37 +38,16 @@ public class PingHelper {
|
||||
|
||||
String postUrlStr = leaderBoard.serverUrl
|
||||
+ prefs.getServerMarkPingPath(leaderBoard.name, mark.getId());
|
||||
|
||||
HttpJsonPostRequest request = new HttpJsonPostRequest(new URL(postUrlStr),
|
||||
fixJson.toString(), context);
|
||||
NetworkHelper.getInstance(context)
|
||||
.executeHttpJsonRequestAsnchronously(request, new NetworkHelperSuccessListener() {
|
||||
|
||||
@Override
|
||||
public void performAction(JSONObject arg0) {
|
||||
Toast.makeText(context, "DATA SEND TO SERVER", Toast.LENGTH_LONG).show();
|
||||
|
||||
}
|
||||
}, new NetworkHelper.NetworkHelperFailureListener() {
|
||||
|
||||
@Override
|
||||
public void performAction(NetworkHelperError arg0) {
|
||||
Toast.makeText(context, "FAILURE SERVER WAS NOT NOTIFIED", Toast.LENGTH_LONG).show();
|
||||
|
||||
}
|
||||
});;
|
||||
|
||||
//context.startService(MessageSendingService.createMessageIntent(context,
|
||||
// postUrlStr, null, UUID.randomUUID(), fixJson.toString(), null));
|
||||
context.startService(MessageSendingService.createMessageIntent(context, postUrlStr,
|
||||
null, UUID.randomUUID(), fixJson.toString(), null));
|
||||
|
||||
|
||||
} catch (JSONException ex) {
|
||||
ExLog.i(context, TAG,
|
||||
"Error while building ping json " + ex.getMessage());
|
||||
} catch (GeneralDatabaseHelperException e) {
|
||||
e.printStackTrace();
|
||||
} catch (MalformedURLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user