forked from organicmaps/organicmaps
[android] Added base activity delegate to SplashActivity to make it themized and loggable
This commit is contained in:
parent
c856580fe3
commit
d297549180
4 changed files with 57 additions and 10 deletions
|
@ -7,12 +7,15 @@ import android.content.Intent;
|
|||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StyleRes;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapswithme.maps.base.BaseActivity;
|
||||
import com.mapswithme.maps.base.BaseActivityDelegate;
|
||||
import com.mapswithme.maps.downloader.UpdaterDialogFragment;
|
||||
import com.mapswithme.maps.editor.ViralFragment;
|
||||
import com.mapswithme.maps.news.BaseNewsFragment;
|
||||
|
@ -23,13 +26,14 @@ import com.mapswithme.maps.permissions.StoragePermissionsDialogFragment;
|
|||
import com.mapswithme.util.Config;
|
||||
import com.mapswithme.util.Counters;
|
||||
import com.mapswithme.util.PermissionsUtils;
|
||||
import com.mapswithme.util.ThemeUtils;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.concurrency.UiThread;
|
||||
import com.mapswithme.util.statistics.PushwooshHelper;
|
||||
import com.my.tracker.MyTracker;
|
||||
|
||||
public class SplashActivity extends AppCompatActivity
|
||||
implements BaseNewsFragment.NewsDialogListener
|
||||
implements BaseNewsFragment.NewsDialogListener, BaseActivity
|
||||
{
|
||||
public static final String EXTRA_INTENT = "extra_intent";
|
||||
private static final String EXTRA_ACTIVITY_TO_START = "extra_activity_to_start";
|
||||
|
@ -82,6 +86,9 @@ public class SplashActivity extends AppCompatActivity
|
|||
}
|
||||
};
|
||||
|
||||
@NonNull
|
||||
private final BaseActivityDelegate mBaseDelegate = new BaseActivityDelegate(this);
|
||||
|
||||
public static void start(@NonNull Context context,
|
||||
@Nullable Class<? extends Activity> activityToStart,
|
||||
@Nullable Intent initialIntent)
|
||||
|
@ -105,6 +112,7 @@ public class SplashActivity extends AppCompatActivity
|
|||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
mBaseDelegate.onCreate();
|
||||
handleUpdateMapsFragmentCorrectly(savedInstanceState);
|
||||
UiThread.cancelDelayedTasks(mPermissionsDelayedTask);
|
||||
UiThread.cancelDelayedTasks(mInitCoreDelayedTask);
|
||||
|
@ -113,6 +121,13 @@ public class SplashActivity extends AppCompatActivity
|
|||
initView();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent)
|
||||
{
|
||||
super.onNewIntent(intent);
|
||||
mBaseDelegate.onNewIntent(intent);
|
||||
}
|
||||
|
||||
private void handleUpdateMapsFragmentCorrectly(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
if (savedInstanceState == null)
|
||||
|
@ -150,6 +165,7 @@ public class SplashActivity extends AppCompatActivity
|
|||
protected void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
mBaseDelegate.onStart();
|
||||
MyTracker.onStartActivity(this);
|
||||
}
|
||||
|
||||
|
@ -157,6 +173,7 @@ public class SplashActivity extends AppCompatActivity
|
|||
protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
mBaseDelegate.onResume();
|
||||
mCanceled = false;
|
||||
mPermissionsGranted = PermissionsUtils.isExternalStorageGranted();
|
||||
DialogFragment storagePermissionsDialog = StoragePermissionsDialogFragment.find(this);
|
||||
|
@ -190,20 +207,29 @@ public class SplashActivity extends AppCompatActivity
|
|||
@Override
|
||||
protected void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
mBaseDelegate.onPause();
|
||||
mCanceled = true;
|
||||
UiThread.cancelDelayedTasks(mPermissionsDelayedTask);
|
||||
UiThread.cancelDelayedTasks(mInitCoreDelayedTask);
|
||||
UiThread.cancelDelayedTasks(mFinalDelayedTask);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
super.onStop();
|
||||
mBaseDelegate.onStop();
|
||||
MyTracker.onStopActivity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy()
|
||||
{
|
||||
super.onDestroy();
|
||||
mBaseDelegate.onDestroy();
|
||||
}
|
||||
|
||||
private void resumeDialogs()
|
||||
{
|
||||
if (mCanceled)
|
||||
|
@ -328,4 +354,23 @@ public class SplashActivity extends AppCompatActivity
|
|||
startActivity(result);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Activity get()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getThemeResourceId(@NonNull String theme)
|
||||
{
|
||||
if (ThemeUtils.isDefaultTheme(theme))
|
||||
return R.style.MwmTheme;
|
||||
|
||||
if (ThemeUtils.isNightTheme(theme))
|
||||
return R.style.MwmTheme_Night;
|
||||
|
||||
throw new IllegalArgumentException("Attempt to apply unsupported theme: " + theme);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.support.annotation.StyleRes;
|
|||
|
||||
public interface BaseActivity
|
||||
{
|
||||
@NonNull
|
||||
Activity get();
|
||||
@StyleRes
|
||||
int getThemeResourceId(@NonNull String theme);
|
||||
|
|
|
@ -14,7 +14,7 @@ import com.mapswithme.util.concurrency.UiThread;
|
|||
import com.mapswithme.util.statistics.Statistics;
|
||||
import com.my.tracker.MyTracker;
|
||||
|
||||
class BaseActivityDelegate
|
||||
public class BaseActivityDelegate
|
||||
{
|
||||
private static final String TAG = BaseActivityDelegate.class.getSimpleName();
|
||||
@NonNull
|
||||
|
@ -22,12 +22,12 @@ class BaseActivityDelegate
|
|||
@Nullable
|
||||
private String mThemeName;
|
||||
|
||||
BaseActivityDelegate(@NonNull BaseActivity activity)
|
||||
public BaseActivityDelegate(@NonNull BaseActivity activity)
|
||||
{
|
||||
mActivity = activity;
|
||||
}
|
||||
|
||||
void onNewIntent(@NonNull Intent intent)
|
||||
public void onNewIntent(@NonNull Intent intent)
|
||||
{
|
||||
logLifecycleMethod("onNewIntent(" + intent + ")");
|
||||
}
|
||||
|
@ -40,26 +40,26 @@ class BaseActivityDelegate
|
|||
mActivity.get().setTheme(mActivity.getThemeResourceId(mThemeName));
|
||||
}
|
||||
|
||||
void onDestroy()
|
||||
public void onDestroy()
|
||||
{
|
||||
logLifecycleMethod("onDestroy()");
|
||||
ViewServer.get(mActivity.get()).removeWindow(mActivity.get());
|
||||
}
|
||||
|
||||
void onPostCreate()
|
||||
public void onPostCreate()
|
||||
{
|
||||
logLifecycleMethod("onPostCreate()");
|
||||
ViewServer.get(mActivity.get()).addWindow(mActivity.get());
|
||||
}
|
||||
|
||||
void onStart()
|
||||
public void onStart()
|
||||
{
|
||||
logLifecycleMethod("onStart()");
|
||||
Statistics.INSTANCE.startActivity(mActivity.get());
|
||||
MyTracker.onStartActivity(mActivity.get());
|
||||
}
|
||||
|
||||
void onStop()
|
||||
public void onStop()
|
||||
{
|
||||
logLifecycleMethod("onStop()");
|
||||
Statistics.INSTANCE.stopActivity(mActivity.get());
|
||||
|
@ -80,7 +80,7 @@ class BaseActivityDelegate
|
|||
org.alohalytics.Statistics.logEvent("$onPause", mActivity.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
void onPostResume()
|
||||
public void onPostResume()
|
||||
{
|
||||
logLifecycleMethod("onPostResume()");
|
||||
if (!TextUtils.isEmpty(mThemeName) && mThemeName.equals(Config.getCurrentUiTheme()))
|
||||
|
|
|
@ -31,6 +31,7 @@ public abstract class BaseMwmFragmentActivity extends AppCompatActivity
|
|||
private boolean mInitializationCompleted = false;
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Activity get()
|
||||
{
|
||||
return this;
|
||||
|
|
Loading…
Add table
Reference in a new issue