-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LightCycleActivity base class for use without AppCompat (#57)
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
lightcycle-lib/src/main/java/com/soundcloud/lightcycle/LightCycleActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ActivityType extends LightCycleActivity> | ||
extends Activity | ||
implements LightCycleDispatcher<ActivityLightCycle<ActivityType>> { | ||
|
||
private final ActivityLightCycleDispatcher<ActivityType> lightCycleDispatcher; | ||
|
||
public LightCycleActivity() { | ||
lightCycleDispatcher = new ActivityLightCycleDispatcher<>(); | ||
} | ||
|
||
@Override | ||
public void bind(ActivityLightCycle<ActivityType> 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; | ||
} | ||
} |