Check track is not null after getting a track from track id.

This commit is contained in:
Jimmy Shih
2012-05-16 15:11:18 -07:00
parent 0b08e53de2
commit af35d45ba7
8 changed files with 35 additions and 31 deletions
@@ -64,7 +64,7 @@ public class TrackEditActivity extends AbstractMyTracksActivity {
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this); myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this);
track = myTracksProviderUtils.getTrack(trackId); track = myTracksProviderUtils.getTrack(trackId);
if (track == null) { if (track == null) {
Log.e(TAG, "no track"); Log.e(TAG, "No track for " + trackId);
finish(); finish();
return; return;
} }
@@ -119,7 +119,7 @@ public class SendDocsAsyncTask extends AbstractSendAsyncTask {
Track track = myTracksProviderUtils.getTrack(trackId); Track track = myTracksProviderUtils.getTrack(trackId);
if (track == null) { if (track == null) {
Log.d(TAG, "Track is null"); Log.d(TAG, "No track for " + trackId);
return false; return false;
} }
@@ -118,7 +118,7 @@ public class TrackWriterFactory {
long trackId, TrackFileFormat format) { long trackId, TrackFileFormat format) {
Track track = providerUtils.getTrack(trackId); Track track = providerUtils.getTrack(trackId);
if (track == null) { if (track == null) {
Log.w(TAG, "Trying to create a writer for an invalid track, id=" + trackId); Log.d(TAG, "No track for " + trackId);
return null; return null;
} }
@@ -105,12 +105,12 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
@Override @Override
protected void saveResult() { protected void saveResult() {
Track track = myTracksProviderUtils.getTrack(trackId); Track track = myTracksProviderUtils.getTrack(trackId);
if (track != null) { if (track == null) {
track.setTableId(tableId); Log.d(TAG, "No track for " + trackId);
myTracksProviderUtils.updateTrack(track); return;
} else {
Log.d(TAG, "No track");
} }
track.setTableId(tableId);
myTracksProviderUtils.updateTrack(track);
} }
@Override @Override
@@ -136,7 +136,7 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
Track track = myTracksProviderUtils.getTrack(trackId); Track track = myTracksProviderUtils.getTrack(trackId);
if (track == null) { if (track == null) {
Log.d(TAG, "Track is null"); Log.d(TAG, "No track for " + trackId);
return false; return false;
} }
@@ -131,14 +131,14 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
@Override @Override
protected void saveResult() { protected void saveResult() {
Track track = myTracksProviderUtils.getTrack(trackId); Track track = myTracksProviderUtils.getTrack(trackId);
if (track != null) { if (track == null) {
track.setMapId(mapId); Log.d(TAG, "No track for " + trackId);
myTracksProviderUtils.updateTrack(track); return;
} else {
Log.d(TAG, "No track");
} }
track.setMapId(mapId);
myTracksProviderUtils.updateTrack(track);
} }
@Override @Override
protected boolean performTask() { protected boolean performTask() {
// Reset the per upload states // Reset the per upload states
@@ -173,7 +173,7 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
// Get the track // Get the track
Track track = myTracksProviderUtils.getTrack(trackId); Track track = myTracksProviderUtils.getTrack(trackId);
if (track == null) { if (track == null) {
Log.d(TAG, "Track is null"); Log.d(TAG, "No track for " + trackId);
return false; return false;
} }
@@ -30,6 +30,7 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@@ -42,10 +43,10 @@ import android.widget.TextView;
*/ */
public class UploadResultActivity extends FragmentActivity { public class UploadResultActivity extends FragmentActivity {
private static final String TAG = UploadResultActivity.class.getSimpleName();
private static final int DIALOG_RESULT_ID = 0; private static final int DIALOG_RESULT_ID = 0;
private SendRequest sendRequest; private SendRequest sendRequest;
private Track track;
private String shareUrl; private String shareUrl;
private Dialog resultDialog; private Dialog resultDialog;
@@ -53,11 +54,17 @@ public class UploadResultActivity extends FragmentActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
sendRequest = getIntent().getParcelableExtra(SendRequest.SEND_REQUEST_KEY); sendRequest = getIntent().getParcelableExtra(SendRequest.SEND_REQUEST_KEY);
track = null;
shareUrl = null; shareUrl = null;
Track track = MyTracksProviderUtils.Factory.get(this).getTrack(sendRequest.getTrackId());
if (track == null) {
Log.d(TAG, "No track for " + sendRequest.getTrackId());
finish();
return;
}
if (sendRequest.isSendMaps() && sendRequest.isMapsSuccess()) { if (sendRequest.isSendMaps() && sendRequest.isMapsSuccess()) {
shareUrl = SendMapsUtils.getMapUrl(getTrack()); shareUrl = SendMapsUtils.getMapUrl(track);
if (sendRequest.getSharingAppPackageName() != null) { if (sendRequest.getSharingAppPackageName() != null) {
Intent intent = IntentUtils.newShareUrlIntent(this, sendRequest.getTrackId(), shareUrl, Intent intent = IntentUtils.newShareUrlIntent(this, sendRequest.getTrackId(), shareUrl,
sendRequest.getSharingAppPackageName(), sendRequest.getSharingAppClassName()); sendRequest.getSharingAppPackageName(), sendRequest.getSharingAppClassName());
@@ -68,18 +75,11 @@ public class UploadResultActivity extends FragmentActivity {
} }
if (shareUrl == null && sendRequest.isSendFusionTables() if (shareUrl == null && sendRequest.isSendFusionTables()
&& sendRequest.isFusionTablesSuccess()) { && sendRequest.isFusionTablesSuccess()) {
shareUrl = SendFusionTablesUtils.getMapUrl(getTrack()); shareUrl = SendFusionTablesUtils.getMapUrl(track);
} }
showDialog(DIALOG_RESULT_ID); showDialog(DIALOG_RESULT_ID);
} }
private Track getTrack() {
if (track == null) {
track = MyTracksProviderUtils.Factory.get(this).getTrack(sendRequest.getTrackId());
}
return track;
}
@Override @Override
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
if (id != DIALOG_RESULT_ID) { if (id != DIALOG_RESULT_ID) {
@@ -93,6 +93,10 @@ public class DynamicSpeedTrackPathDescriptor implements TrackPathDescriptor,
return false; return false;
} }
Track track = MyTracksProviderUtils.Factory.get(context).getTrack(selectedTrackId); Track track = MyTracksProviderUtils.Factory.get(context).getTrack(selectedTrackId);
if (track == null) {
Log.d(TAG, "No track for " + selectedTrackId);
return false;
}
TripStatistics stats = track.getStatistics(); TripStatistics stats = track.getStatistics();
double newAverageMovingSpeed = (int) Math.floor( double newAverageMovingSpeed = (int) Math.floor(
stats.getAverageMovingSpeed() * UnitConversions.MS_TO_KMH); stats.getAverageMovingSpeed() * UnitConversions.MS_TO_KMH);
@@ -65,8 +65,8 @@ public class IntentUtils {
public static final Intent newShareUrlIntent( public static final Intent newShareUrlIntent(
Context context, long trackId, String trackUrl, String packageName, String className) { Context context, long trackId, String trackUrl, String packageName, String className) {
Track track = MyTracksProviderUtils.Factory.get(context).getTrack(trackId); Track track = MyTracksProviderUtils.Factory.get(context).getTrack(trackId);
String trackDescription = new DescriptionGeneratorImpl(context).generateTrackDescription( String trackDescription = track == null ? ""
track, null, null, false); : new DescriptionGeneratorImpl(context).generateTrackDescription(track, null, null, false);
return new Intent(Intent.ACTION_SEND) return new Intent(Intent.ACTION_SEND)
.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP) .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP)
@@ -89,8 +89,8 @@ public class IntentUtils {
public static final Intent newShareFileIntent( public static final Intent newShareFileIntent(
Context context, long trackId, String filePath, TrackFileFormat trackFileFormat) { Context context, long trackId, String filePath, TrackFileFormat trackFileFormat) {
Track track = MyTracksProviderUtils.Factory.get(context).getTrack(trackId); Track track = MyTracksProviderUtils.Factory.get(context).getTrack(trackId);
String trackDescription = new DescriptionGeneratorImpl(context).generateTrackDescription( String trackDescription = track == null ? ""
track, null, null, false); : new DescriptionGeneratorImpl(context).generateTrackDescription(track, null, null, false);
return new Intent(Intent.ACTION_SEND) return new Intent(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filePath))) .putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filePath)))