Change the way 'K9ActivityCommon' is initialized
This commit is contained in:
parent
2c17c25938
commit
8910fdf8c1
3 changed files with 11 additions and 47 deletions
|
@ -26,24 +26,24 @@ public abstract class K9Activity extends AppCompatActivity implements K9Activity
|
|||
private static final String FRAGMENT_TAG_RATIONALE = "rationale";
|
||||
|
||||
|
||||
private K9ActivityCommon mBase;
|
||||
private final K9ActivityCommon base = new K9ActivityCommon(this);
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
mBase = K9ActivityCommon.newInstance(this);
|
||||
base.preOnCreate();
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent event) {
|
||||
mBase.preDispatchTouchEvent(event);
|
||||
base.preDispatchTouchEvent(event);
|
||||
return super.dispatchTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupGestureDetector(OnSwipeGestureListener listener) {
|
||||
mBase.setupGestureDetector(listener);
|
||||
base.setupGestureDetector(listener);
|
||||
}
|
||||
|
||||
protected void setLayout(@LayoutRes int layoutResId) {
|
||||
|
|
|
@ -22,10 +22,13 @@ import com.fsck.k9.ui.R
|
|||
* @see K9Activity
|
||||
* @see K9ListActivity
|
||||
*/
|
||||
class K9ActivityCommon private constructor(private val activity: Activity) {
|
||||
class K9ActivityCommon(private val activity: Activity) {
|
||||
private var gestureDetector: GestureDetector? = null
|
||||
|
||||
init {
|
||||
/**
|
||||
* Call this before calling `super.onCreate(Bundle)`.
|
||||
*/
|
||||
fun preOnCreate() {
|
||||
setLanguage(activity, K9.k9Language)
|
||||
activity.setTheme(k9ThemeResourceId)
|
||||
}
|
||||
|
@ -48,18 +51,6 @@ class K9ActivityCommon private constructor(private val activity: Activity) {
|
|||
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Creates a new instance of [K9ActivityCommon] bound to the specified activity.
|
||||
*
|
||||
* @param activity The [Activity] the returned `K9ActivityCommon` instance will be bound to.
|
||||
*
|
||||
* @return The [K9ActivityCommon] instance that will provide the base functionality of the "K9" activities.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun newInstance(activity: Activity): K9ActivityCommon {
|
||||
return K9ActivityCommon(activity)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setLanguage(context: Context, language: String) {
|
||||
val locale = if (TextUtils.isEmpty(language)) {
|
||||
|
|
|
@ -1,46 +1,19 @@
|
|||
package com.fsck.k9.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.activity.K9ActivityCommon.K9ActivityMagic;
|
||||
import com.fsck.k9.activity.misc.SwipeGestureDetector.OnSwipeGestureListener;
|
||||
|
||||
|
||||
public abstract class K9ListActivity extends K9Activity implements K9ActivityMagic {
|
||||
|
||||
private K9ActivityCommon base;
|
||||
public abstract class K9ListActivity extends K9Activity {
|
||||
protected ListAdapter adapter;
|
||||
protected ListView list;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
base = K9ActivityCommon.newInstance(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent event) {
|
||||
base.preDispatchTouchEvent(event);
|
||||
return super.dispatchTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupGestureDetector(OnSwipeGestureListener listener) {
|
||||
base.setupGestureDetector(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
// Shortcuts that work no matter what is selected
|
||||
|
|
Loading…
Reference in a new issue