Permalink
Browse files

''Back'' should point back to host info page after going from

there to map location. Closes #31.
  • Loading branch information...
1 parent def214b commit e15d214b8fab011937a0a467487575cb77da2cde @jstaffans committed Apr 5, 2012
@@ -85,12 +85,17 @@ protected void onCreate(Bundle savedInstanceState) {
host = (Host) i.getParcelableExtra("host");
id = i.getIntExtra("id", NO_ID);
starred = starredHostDao.isHostStarred(id, host.getName());
- if (starred) {
- host = starredHostDao.get(id, host.getName());
- forceUpdate = i.getBooleanExtra("update", false);
- shouldDownloadHostInfo = forceUpdate;
+
+ if (intentProvidesFullHostInfo(i)) {
+ shouldDownloadHostInfo = false;
} else {
- shouldDownloadHostInfo = true;
+ if (starred) {
+ host = starredHostDao.get(id, host.getName());
+ forceUpdate = i.getBooleanExtra("update", false);
+ shouldDownloadHostInfo = forceUpdate;
+ } else {
+ shouldDownloadHostInfo = true;
+ }
}
}
@@ -106,6 +111,10 @@ protected void onCreate(Bundle savedInstanceState) {
starredHostDao.close();
}
+ private boolean intentProvidesFullHostInfo(Intent i) {
+ return i.getBooleanExtra("full_info", false);
+ }
+
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putParcelable("host", host);
@@ -154,6 +163,7 @@ public void contactHost(View view) {
public void showHostOnMap(View view) {
// We need to finish the host info dialog, switch to the map tab and
// zoom/scroll to the location of the host
+
Intent resultIntent = new Intent();
if (!Strings.isEmpty(host.getLatitude()) && !Strings.isEmpty(host.getLongitude())) {
@@ -163,6 +173,10 @@ public void showHostOnMap(View view) {
resultIntent.putExtra("lon", lon);
}
+ // #31: when going back from the map, we should end up on the host info page
+ resultIntent.putExtra("host", host);
+ resultIntent.putExtra("id", id);
+
setResult(RESULT_SHOW_HOST_ON_MAP, resultIntent);
finish();
}
@@ -114,6 +114,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == HostInformationActivity.RESULT_SHOW_HOST_ON_MAP) {
MainActivity parent = (MainActivity) this.getParent();
+ parent.stashHost(data, 1);
mapAnimator.prepareToAnimateToHost(data);
parent.switchTab(2);
}
@@ -5,6 +5,7 @@
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
+import android.os.Parcelable;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -17,6 +18,9 @@
public class MainActivity extends RoboTabActivity {
private Dialog splashDialog;
+ private Parcelable savedHost;
+ private int savedHostId;
+ private int stashedFromTab;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -146,4 +150,27 @@ protected void onSaveInstanceState(Bundle outState) {
public void switchTab(int tab) {
getTabHost().setCurrentTab(tab);
}
+
+ public void stashHost(Intent data, int stashedFrom) {
+ savedHost = data.getParcelableExtra("host");
+ savedHostId = data.getIntExtra("id", 0);
+ stashedFromTab = stashedFrom;
+ }
+
+ public boolean hasStashedHost() {
+ return savedHost != null;
+ }
+
+ public Intent popStashedHost(Intent i) {
+ i.putExtra("host", savedHost);
+ i.putExtra("id", savedHostId);
+ i.putExtra("full_info", true);
+ savedHost = null;
+ savedHostId = 0;
+ return i;
+ }
+
+ public int getStashedFromTab() {
+ return stashedFromTab;
+ }
}
@@ -110,6 +110,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == HostInformationActivity.RESULT_SHOW_HOST_ON_MAP) {
MainActivity parent = (MainActivity) this.getParent();
+ parent.stashHost(data, 0);
mapAnimator.prepareToAnimateToHost(data);
parent.switchTab(2);
}

0 comments on commit e15d214

Please sign in to comment.