Skip to content

Commit

Permalink
Added instance saving on screen rotation for the detail activity.
Browse files Browse the repository at this point in the history
  • Loading branch information
marius-m committed Jul 27, 2015
1 parent c2ce1c3 commit d142113
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions app/src/main/java/lt/mm/moviedb/DetailActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

public class DetailActivity extends Activity {
public static final String BUNDLE_ID = "BUNDLE_ID";
public static final String INSTANCE_DETAIL_MODEL = "INSTANCE_DETAIL_MODEL";

private ImageLoader imageLoader;

Expand All @@ -51,7 +52,8 @@ protected void onCreate(Bundle savedInstanceState) {
imageLoader = ImageLoader.getInstance();
NetworkDetail networkDetail = new NetworkDetail(Volley.newRequestQueue(this));
networkDetail.setLoadListener(loadListener);
networkDetail.load(getIntent().getExtras().getInt(BUNDLE_ID));
if (savedInstanceState == null)
networkDetail.load(getIntent().getExtras().getInt(BUNDLE_ID));

// Views
progressBar = (ProgressBar) findViewById(R.id.progress);
Expand Down Expand Up @@ -94,10 +96,28 @@ public void onLoadSuccess(DetailItem response) {

@Override
public void onLoadFail(String error) {

// todo : inform user that the id does not exist !
finish();
}
};

//endregion

//region Instance saving

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable(INSTANCE_DETAIL_MODEL, detailItem);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
detailItem = (DetailItem) savedInstanceState.getSerializable(INSTANCE_DETAIL_MODEL);
updateViews();
}

//endregion

}

0 comments on commit d142113

Please sign in to comment.