diff --git a/lightcycle-lib/src/main/java/com/soundcloud/lightcycle/LightCycleActivity.java b/lightcycle-lib/src/main/java/com/soundcloud/lightcycle/LightCycleActivity.java new file mode 100644 index 0000000..1976245 --- /dev/null +++ b/lightcycle-lib/src/main/java/com/soundcloud/lightcycle/LightCycleActivity.java @@ -0,0 +1,90 @@ +package com.soundcloud.lightcycle; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.MenuItem; + +public abstract class LightCycleActivity + extends Activity + implements LightCycleDispatcher> { + + private final ActivityLightCycleDispatcher lightCycleDispatcher; + + public LightCycleActivity() { + lightCycleDispatcher = new ActivityLightCycleDispatcher<>(); + } + + @Override + public void bind(ActivityLightCycle lightCycle) { + lightCycleDispatcher.bind(lightCycle); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setActivityContentView(); + LightCycles.bind(this); + lightCycleDispatcher.onCreate(activity(), savedInstanceState); + } + + protected abstract void setActivityContentView(); + + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + lightCycleDispatcher.onNewIntent(activity(), intent); + } + + @Override + protected void onStart() { + super.onStart(); + lightCycleDispatcher.onStart(activity()); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + return lightCycleDispatcher.onOptionsItemSelected(activity(), item); + } + + @Override + protected void onStop() { + lightCycleDispatcher.onStop(activity()); + super.onStop(); + } + + @Override + protected void onResume() { + super.onResume(); + lightCycleDispatcher.onResume(activity()); + } + + @Override + protected void onPause() { + lightCycleDispatcher.onPause(activity()); + super.onPause(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + lightCycleDispatcher.onSaveInstanceState(activity(), outState); + } + + @Override + protected void onRestoreInstanceState(Bundle savedInstanceState) { + super.onRestoreInstanceState(savedInstanceState); + lightCycleDispatcher.onRestoreInstanceState(activity(), savedInstanceState); + } + + @Override + protected void onDestroy() { + lightCycleDispatcher.onDestroy(activity()); + super.onDestroy(); + } + + @SuppressWarnings("unchecked") + private ActivityType activity() { + return (ActivityType) this; + } +}