[android] Fixed review notes

This commit is contained in:
Dmitry Donskoy 2020-06-11 19:58:03 +03:00 committed by Vladimir Byko-Ianko
parent 528c0cb866
commit 13f699e424
7 changed files with 79 additions and 13 deletions

View file

@ -136,6 +136,7 @@ import com.mapswithme.maps.widget.menu.MenuController;
import com.mapswithme.maps.widget.menu.MenuControllerFactory;
import com.mapswithme.maps.widget.menu.MenuStateObserver;
import com.mapswithme.maps.widget.menu.MyPositionButton;
import com.mapswithme.maps.base.NoConnectionListener;
import com.mapswithme.maps.widget.placepage.PlacePageController;
import com.mapswithme.maps.widget.placepage.PlacePageData;
import com.mapswithme.maps.widget.placepage.PlacePageFactory;
@ -192,7 +193,8 @@ public class MwmActivity extends BaseMwmFragmentActivity
WelcomeDialogFragment.OnboardingStepPassedListener,
OnIsolinesLayerToggleListener,
OnGuidesLayerToggleListener,
GuidesGalleryListener
GuidesGalleryListener,
NoConnectionListener
{
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
private static final String TAG = MwmActivity.class.getSimpleName();
@ -553,7 +555,8 @@ public class MwmActivity extends BaseMwmFragmentActivity
mPlacePageController.onActivityCreated(this, savedInstanceState);
mMainMenuController = MenuControllerFactory.createMainMenuController(new MainMenuStateObserver(),
new MainMenuOptionSelectedListener());
new MainMenuOptionSelectedListener(),
this);
mMainMenuController.initialize(findViewById(R.id.coordinator));
boolean isLaunchByDeepLink = getIntent().getBooleanExtra(EXTRA_LAUNCH_BY_DEEP_LINK, false);
@ -587,6 +590,15 @@ public class MwmActivity extends BaseMwmFragmentActivity
tryToShowAdditionalViewOnTop();
}
@Override
public void onNoConnectionError()
{
DialogInterface.OnClickListener listener = (dialog, which) -> {};
DialogUtils.showAlertDialog(this, R.string.common_check_internet_connection_dialog_title,
R.string.common_check_internet_connection_dialog,
R.string.ok, listener);
}
private void initControllersAndValidatePurchases(@Nullable Bundle savedInstanceState)
{
mAdsRemovalPurchaseController = PurchaseFactory.createAdsRemovalPurchaseController(this);
@ -1495,7 +1507,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
private void onGuidesFatalError()
{
Mode.GUIDES.setEnabled(getApplicationContext(), false);
mToggleMapLayerController.turnOff();
RecyclerView bottomSheetRecycler = findViewById(R.id.layers_recycler);
Objects.requireNonNull(bottomSheetRecycler.getAdapter()).notifyDataSetChanged();

View file

@ -0,0 +1,6 @@
package com.mapswithme.maps.base;
public interface NoConnectionListener
{
void onNoConnectionError();
}

View file

@ -17,7 +17,7 @@ public abstract class DefaultClickListener implements OnItemClickListener<Bottom
}
@Override
public final void onItemClick(@NonNull View v, @NonNull BottomSheetItem item)
public void onItemClick(@NonNull View v, @NonNull BottomSheetItem item)
{
Mode mode = item.getMode();
SharedPropertiesUtils.setLayerMarkerShownForLayerMode(v.getContext(), mode);

View file

@ -19,6 +19,8 @@ import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.mapswithme.maps.R;
import com.mapswithme.maps.maplayer.subway.OnSubwayLayerToggleListener;
import com.mapswithme.maps.maplayer.traffic.OnTrafficLayerToggleListener;
import com.mapswithme.maps.maplayer.guides.AbstractGuidesClickListener;
import com.mapswithme.maps.base.NoConnectionListener;
import com.mapswithme.maps.widget.recycler.SpanningLinearLayoutManager;
import java.util.Objects;
@ -154,11 +156,11 @@ public class ToggleMapLayerDialog extends DialogFragment
}
}
private class GuidesItemClickListener extends DefaultClickListener
private class GuidesItemClickListener extends AbstractGuidesClickListener
{
private GuidesItemClickListener()
{
super(mAdapter);
super(mAdapter, (NoConnectionListener) requireActivity());
}
@Override

View file

@ -0,0 +1,38 @@
package com.mapswithme.maps.maplayer.guides;
import android.view.View;
import androidx.annotation.NonNull;
import com.mapswithme.maps.base.NoConnectionListener;
import com.mapswithme.maps.maplayer.BottomSheetItem;
import com.mapswithme.maps.maplayer.DefaultClickListener;
import com.mapswithme.maps.maplayer.LayersAdapter;
import com.mapswithme.maps.maplayer.Mode;
import com.mapswithme.util.ConnectionState;
public abstract class AbstractGuidesClickListener extends DefaultClickListener
{
@NonNull
private final NoConnectionListener mNoConnectionListener;
public AbstractGuidesClickListener(@NonNull LayersAdapter adapter,
@NonNull NoConnectionListener noConnectionListener)
{
super(adapter);
mNoConnectionListener = noConnectionListener;
}
@Override
public void onItemClick(@NonNull View v, @NonNull BottomSheetItem item)
{
Mode mode = item.getMode();
if (!mode.isEnabled(v.getContext()) && !ConnectionState.isConnected())
{
mNoConnectionListener.onNoConnectionError();
return;
}
super.onItemClick(v, item);
}
}

View file

@ -9,6 +9,7 @@ import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.mapswithme.maps.R;
import com.mapswithme.maps.base.NoConnectionListener;
import com.mapswithme.maps.downloader.MapManager;
import com.mapswithme.maps.downloader.UpdateInfo;
import com.mapswithme.maps.maplayer.AbstractIsoLinesClickListener;
@ -16,6 +17,7 @@ import com.mapswithme.maps.maplayer.BottomSheetItem;
import com.mapswithme.maps.maplayer.DefaultClickListener;
import com.mapswithme.maps.maplayer.LayersAdapter;
import com.mapswithme.maps.maplayer.LayersUtils;
import com.mapswithme.maps.maplayer.guides.AbstractGuidesClickListener;
import com.mapswithme.maps.widget.recycler.SpanningLinearLayoutManager;
import com.mapswithme.util.Graphics;
import com.mapswithme.util.UiUtils;
@ -35,10 +37,14 @@ public class MainMenuRenderer implements MenuRenderer
@SuppressWarnings("NullableProblems")
@NonNull
private NestedScrollView mScrollView;
@NonNull
private final NoConnectionListener mNoConnectionListener;
MainMenuRenderer(@NonNull MainMenuOptionListener listener)
MainMenuRenderer(@NonNull MainMenuOptionListener listener,
@NonNull NoConnectionListener noConnectionListener)
{
mListener = listener;
mNoConnectionListener = noConnectionListener;
}
@Override
@ -94,7 +100,7 @@ public class MainMenuRenderer implements MenuRenderer
new SubwayItemClickListener(),
new TrafficItemClickListener(),
new IsolinesItemClickListener(),
new GuidesItemClickListener()));
new GuidesItemClickListener(mNoConnectionListener)));
layersRecycler.setAdapter(mLayersAdapter);
}
@ -153,11 +159,11 @@ public class MainMenuRenderer implements MenuRenderer
}
}
private class GuidesItemClickListener extends DefaultClickListener
private class GuidesItemClickListener extends AbstractGuidesClickListener
{
GuidesItemClickListener()
GuidesItemClickListener(@NonNull NoConnectionListener connectionListener)
{
super(mLayersAdapter);
super(mLayersAdapter, connectionListener);
}
@Override

View file

@ -3,14 +3,17 @@ package com.mapswithme.maps.widget.menu;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mapswithme.maps.R;
import com.mapswithme.maps.base.NoConnectionListener;
public class MenuControllerFactory
{
@NonNull
public static MenuController createMainMenuController(@Nullable MenuStateObserver stateObserver,
@NonNull MainMenuOptionListener listener)
@NonNull MainMenuOptionListener listener,
@NonNull NoConnectionListener noConnectionListener)
{
return new BottomSheetMenuController(R.id.main_menu_sheet, new MainMenuRenderer(listener),
return new BottomSheetMenuController(R.id.main_menu_sheet, new MainMenuRenderer(listener,
noConnectionListener),
stateObserver);
}
}