[android] Changed dialog btn text

This commit is contained in:
Dmitry Donskoy 2020-01-17 09:56:26 +03:00 committed by Daria Volvenkova
parent a1e660fa70
commit 331736d7da
2 changed files with 38 additions and 5 deletions

View file

@ -3,10 +3,10 @@ package com.mapswithme.maps.routing;
import android.content.res.Resources;
import android.util.Pair;
import androidx.annotation.NonNull;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.location.LocationState;
import java.util.ArrayList;
import java.util.List;
@ -32,11 +32,13 @@ class ResultCodesHelper
private static final int ROUTE_NOT_FOUND_REDRESS_ROUTE_ERROR = 15;
static final int HAS_WARNINGS = 16;
static Pair<String, String> getDialogTitleSubtitle(int errorCode, int missingCount)
@NonNull
static ResourcesHolder getDialogTitleSubtitle(int errorCode, int missingCount)
{
Resources resources = MwmApplication.get().getResources();
int titleRes = 0;
List<String> messages = new ArrayList<>();
int cancelBtnResId = android.R.string.cancel;
switch (errorCode)
{
case NO_POSITION:
@ -84,6 +86,7 @@ class ResultCodesHelper
case TRANSIT_ROUTE_NOT_FOUND_TOO_LONG_PEDESTRIAN:
titleRes = R.string.dialog_pedestrian_route_is_long_header;
messages.add(resources.getString(R.string.dialog_pedestrian_route_is_long_message));
cancelBtnResId = R.string.ok;
break;
case ROUTE_NOT_FOUND:
case ROUTE_NOT_FOUND_REDRESS_ROUTE_ERROR:
@ -119,7 +122,9 @@ class ResultCodesHelper
builder.append(messagePart);
}
return new Pair<>(titleRes == 0 ? "" : resources.getString(titleRes), builder.toString());
return new ResourcesHolder(
new Pair<>(titleRes == 0 ? "" : resources.getString(titleRes), builder.toString()),
cancelBtnResId);
}
static boolean isDownloadable(int resultCode, int missingCount)
@ -144,4 +149,29 @@ class ResultCodesHelper
{
return resultCode == NEED_MORE_MAPS;
}
public static class ResourcesHolder
{
@NonNull
private final Pair<String, String> mTitleMessage;
private final int mCancelBtnResId;
private ResourcesHolder(@NonNull Pair<String, String> titleMessage, int cancelBtnResId)
{
mTitleMessage = titleMessage;
mCancelBtnResId = cancelBtnResId;
}
@NonNull
public Pair<String, String> getTitleMessage()
{
return mTitleMessage;
}
public int getCancelBtnResId()
{
return mCancelBtnResId;
}
}
}

View file

@ -29,10 +29,13 @@ public class RoutingErrorDialogFragment extends BaseRoutingErrorDialogFragment
{
super.beforeDialogCreated(builder);
Pair<String, String> titleMessage = ResultCodesHelper.getDialogTitleSubtitle(mResultCode, mMissingMaps.size());
ResultCodesHelper.ResourcesHolder resHolder =
ResultCodesHelper.getDialogTitleSubtitle(mResultCode, mMissingMaps.size());
Pair<String, String> titleMessage = resHolder.getTitleMessage();
builder.setTitle(titleMessage.first);
mMessage = titleMessage.second;
builder.setNegativeButton(resHolder.getCancelBtnResId(), null);
if (ResultCodesHelper.isDownloadable(mResultCode, mMissingMaps.size()))
builder.setPositiveButton(R.string.download, null);