Minor refactoring duplicated code.

This commit is contained in:
Dima-1 2019-10-29 20:16:59 +03:00
parent 05af6974fe
commit fa0dae54c5

View file

@ -232,7 +232,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
private boolean stopped = true; private boolean stopped = true;
private ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); private ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
private LockHelper lockHelper; private LockHelper lockHelper;
@Override @Override
@ -254,7 +254,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
trackDetailsMenu.setMapActivity(this); trackDetailsMenu.setMapActivity(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (Version.isHuawei(getMyApplication())) { if (Version.isHuawei(getMyApplication())) {
HuaweiDrmHelper.check(this); HuaweiDrmHelper.check(this);
} }
@ -353,7 +353,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
registerReceiver(screenOffReceiver, filter); registerReceiver(screenOffReceiver, filter);
app.getAidlApi().onCreateMapActivity(this); app.getAidlApi().onCreateMapActivity(this);
lockHelper.setLockUIAdapter(this); lockHelper.setLockUIAdapter(this);
mIsDestroyed = false; mIsDestroyed = false;
@ -687,7 +687,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return; return;
} }
QuickActionListFragment quickActionListFragment = getQuickActionListFragment(); QuickActionListFragment quickActionListFragment = getQuickActionListFragment();
if ( quickActionListFragment!=null && quickActionListFragment.isVisible()) { if ( quickActionListFragment != null && quickActionListFragment.isVisible()) {
this.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_SCREEN, null); this.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_SCREEN, null);
} }
@ -1401,7 +1401,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
atlasMapRendererView.handleOnDestroy(); atlasMapRendererView.handleOnDestroy();
} }
lockHelper.setLockUIAdapter(null); lockHelper.setLockUIAdapter(null);
mIsDestroyed = true; mIsDestroyed = true;
} }
@ -2263,33 +2263,32 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
} }
public QuickSearchDialogFragment getQuickSearchDialogFragment() { public QuickSearchDialogFragment getQuickSearchDialogFragment() {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(QuickSearchDialogFragment.TAG); return getFragment(QuickSearchDialogFragment.TAG);
return fragment != null && !fragment.isDetached() && !fragment.isRemoving() ? (QuickSearchDialogFragment) fragment : null;
} }
public PlanRouteFragment getPlanRouteFragment() { public PlanRouteFragment getPlanRouteFragment() {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(PlanRouteFragment.TAG); return getFragment(PlanRouteFragment.TAG);
return fragment != null && !fragment.isDetached() && !fragment.isRemoving() ? (PlanRouteFragment) fragment : null;
} }
public MeasurementToolFragment getMeasurementToolFragment() { public MeasurementToolFragment getMeasurementToolFragment() {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(MeasurementToolFragment.TAG); return getFragment(MeasurementToolFragment.TAG);
return fragment != null && !fragment.isDetached() && !fragment.isRemoving() ? (MeasurementToolFragment) fragment : null;
} }
public ChooseRouteFragment getChooseRouteFragment() { public ChooseRouteFragment getChooseRouteFragment() {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(ChooseRouteFragment.TAG); return getFragment(ChooseRouteFragment.TAG);
return fragment != null && !fragment.isDetached() && !fragment.isRemoving() ? (ChooseRouteFragment) fragment : null;
} }
public EditProfileFragment getEditProfileFragment() { public EditProfileFragment getEditProfileFragment() {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(EditProfileFragment.TAG); return getFragment(EditProfileFragment.TAG);
return fragment != null && !fragment.isDetached() && !fragment.isRemoving() ? (EditProfileFragment) fragment : null;
} }
public QuickActionListFragment getQuickActionListFragment() { public QuickActionListFragment getQuickActionListFragment() {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(QuickActionListFragment.TAG); return getFragment(QuickActionListFragment.TAG);
return fragment != null && !fragment.isDetached() && !fragment.isRemoving() ? (QuickActionListFragment) fragment : null; }
<T> T getFragment(String fragmentTag){
Fragment fragment = getSupportFragmentManager().findFragmentByTag(fragmentTag);
return fragment != null && !fragment.isDetached() && !fragment.isRemoving() ? (T) fragment : null;
} }
public boolean isTopToolbarActive() { public boolean isTopToolbarActive() {