Fix possible npe
This commit is contained in:
parent
53d30621cd
commit
d0758f4146
2 changed files with 31 additions and 14 deletions
|
@ -1,7 +1,11 @@
|
|||
package net.osmand.plus.profiles;
|
||||
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.profiles.ConfigureProfileMenuAdapter.ProfileSelectedListener;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
@ -9,8 +13,8 @@ import java.util.LinkedHashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ConfigureAppModesBottomSheetDialogFragment extends AppModesBottomSheetDialogFragment<ConfigureProfileMenuAdapter>
|
||||
implements ConfigureProfileMenuAdapter.ProfileSelectedListener {
|
||||
public class ConfigureAppModesBottomSheetDialogFragment extends AppModesBottomSheetDialogFragment<ConfigureProfileMenuAdapter>
|
||||
implements ProfileSelectedListener {
|
||||
|
||||
public static final String TAG = "ConfigureAppModesBottomSheetDialogFragment";
|
||||
|
||||
|
@ -56,4 +60,15 @@ public class ConfigureAppModesBottomSheetDialogFragment extends AppModesBottomSh
|
|||
}
|
||||
ApplicationMode.changeProfileAvailability(item, isChecked, getMyApplication());
|
||||
}
|
||||
|
||||
public static void showInstance(@NonNull FragmentManager fragmentManager, boolean usedOnMap, UpdateMapRouteMenuListener listener) {
|
||||
if (fragmentManager.findFragmentByTag(TAG) == null) {
|
||||
ConfigureAppModesBottomSheetDialogFragment fragment = new ConfigureAppModesBottomSheetDialogFragment();
|
||||
fragment.setUsedOnMap(usedOnMap);
|
||||
fragment.setUpdateMapRouteMenuListener(listener);
|
||||
fragmentManager.beginTransaction()
|
||||
.add(fragment, TAG)
|
||||
.commitAllowingStateLoss();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,6 +29,8 @@ import androidx.appcompat.content.res.AppCompatResources;
|
|||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.transition.AutoTransition;
|
||||
import androidx.transition.Scene;
|
||||
import androidx.transition.Transition;
|
||||
|
@ -71,7 +73,7 @@ import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenuFragment;
|
|||
import net.osmand.plus.mapmarkers.MapMarker;
|
||||
import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment;
|
||||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
import net.osmand.plus.profiles.AppModesBottomSheetDialogFragment;
|
||||
import net.osmand.plus.profiles.AppModesBottomSheetDialogFragment.UpdateMapRouteMenuListener;
|
||||
import net.osmand.plus.profiles.ConfigureAppModesBottomSheetDialogFragment;
|
||||
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidPTTypesRoutingParameter;
|
||||
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsRoutingParameter;
|
||||
|
@ -870,16 +872,16 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
}
|
||||
|
||||
private void showProfileBottomSheetDialog() {
|
||||
final AppModesBottomSheetDialogFragment fragment = new ConfigureAppModesBottomSheetDialogFragment();
|
||||
fragment.setUsedOnMap(true);
|
||||
fragment.setUpdateMapRouteMenuListener(new AppModesBottomSheetDialogFragment.UpdateMapRouteMenuListener() {
|
||||
@Override
|
||||
public void updateAppModeMenu() {
|
||||
updateApplicationModes();
|
||||
}
|
||||
});
|
||||
getMapActivity().getSupportFragmentManager().beginTransaction()
|
||||
.add(fragment, ConfigureAppModesBottomSheetDialogFragment.TAG).commitAllowingStateLoss();
|
||||
FragmentActivity activity = getMapActivity();
|
||||
if (activity != null) {
|
||||
FragmentManager manager = activity.getSupportFragmentManager();
|
||||
ConfigureAppModesBottomSheetDialogFragment.showInstance(manager, true, new UpdateMapRouteMenuListener() {
|
||||
@Override
|
||||
public void updateAppModeMenu() {
|
||||
updateApplicationModes();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void updateApplicationMode(ApplicationMode mode, ApplicationMode next) {
|
||||
|
|
Loading…
Reference in a new issue