Welcome to mirror list, hosted at ThFree Co, Russian Federation.

RoutingResultCodesProcessor.java « routing « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fa5947fc398c8992fc9c4e5ce3d3ee72cec7bd4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package com.mapswithme.maps.routing;

import android.content.res.Resources;
import android.util.Pair;

import com.mapswithme.maps.LocationState;
import com.mapswithme.maps.MWMApplication;
import com.mapswithme.maps.MapStorage;
import com.mapswithme.maps.R;

import java.util.ArrayList;
import java.util.List;

public class RoutingResultCodesProcessor
{
  // Codes correspond to native routing::IRouter::ResultCode
  public static final int NO_ERROR = 0;
  public static final int CANCELLED = 1;
  public static final int NO_POSITION = 2;
  public static final int INCONSISTENT_MWM_ROUTE = 3;
  public static final int ROUTING_FILE_NOT_EXIST = 4;
  public static final int START_POINT_NOT_FOUND = 5;
  public static final int END_POINT_NOT_FOUND = 6;
  public static final int DIFFERENT_MWM = 7;
  public static final int ROUTE_NOT_FOUND = 8;
  public static final int NEED_MORE_MAPS = 9;
  public static final int INTERNAL_ERROR = 10;
  public static final int FILE_TOO_OLD = 11;

  public static Pair<String, String> getDialogTitleSubtitle(int errorCode, MapStorage.Index[] missingCountries)
  {
    int missingCount = 0;
    if (missingCountries != null)
      missingCount = missingCountries.length;

    Resources resources = MWMApplication.get().getResources();
    int titleRes = 0;
    List<String> messages = new ArrayList<>();
    switch (errorCode)
    {
    case NO_POSITION:
      if (LocationState.INSTANCE.getLocationStateMode() == LocationState.UNKNOWN_POSITION)
      {
        titleRes = R.string.dialog_routing_location_turn_on;
        messages.add(resources.getString(R.string.dialog_routing_location_unknown_turn_on));
      }
      else
      {
        titleRes = R.string.dialog_routing_check_gps;
        messages.add(resources.getString(R.string.dialog_routing_error_location_not_found));
        messages.add(resources.getString(R.string.dialog_routing_location_turn_wifi));
      }
      break;
    case INCONSISTENT_MWM_ROUTE:
    case ROUTING_FILE_NOT_EXIST:
      titleRes = R.string.routing_download_maps_along;
      messages.add(resources.getString(R.string.routing_requires_all_map));
      break;
    case START_POINT_NOT_FOUND:
      titleRes = R.string.dialog_routing_change_start;
      messages.add(resources.getString(R.string.dialog_routing_start_not_determined));
      messages.add(resources.getString(R.string.dialog_routing_select_closer_start));
      break;
    case END_POINT_NOT_FOUND:
      titleRes = R.string.dialog_routing_change_end;
      messages.add(resources.getString(R.string.dialog_routing_end_not_determined));
      messages.add(resources.getString(R.string.dialog_routing_select_closer_end));
      break;
    case DIFFERENT_MWM:
      messages.add(resources.getString(R.string.routing_failed_cross_mwm_building));
      break;
    //TODO (@yunitski @marchuk) Add proper dialog for this case.
    case FILE_TOO_OLD:
    case ROUTE_NOT_FOUND:
      if (missingCount == 0)
      {
        titleRes = R.string.dialog_routing_unable_locate_route;
        messages.add(resources.getString(R.string.dialog_routing_cant_build_route));
        messages.add(resources.getString(R.string.dialog_routing_change_start_or_end));
      }
      else
      {
        titleRes = R.string.routing_download_maps_along;
        messages.add(resources.getString(R.string.routing_requires_all_map));
      }
      break;
    case INTERNAL_ERROR:
      titleRes = R.string.dialog_routing_system_error;
      messages.add(resources.getString(R.string.dialog_routing_application_error));
      messages.add(resources.getString(R.string.dialog_routing_try_again));
      break;
    case NEED_MORE_MAPS:
      titleRes = R.string.dialog_routing_download_and_build_cross_route;
      messages.add(resources.getString(R.string.dialog_routing_download_cross_route));
      break;
    }

    StringBuilder builder = new StringBuilder();
    for (String messagePart : messages)
      builder.append(messagePart).append("\n\n");

    return new Pair<>(titleRes == 0 ? "" : resources.getString(titleRes), builder.toString());
  }

  public static boolean isDownloadable(int resultCode)
  {
    return resultCode == INCONSISTENT_MWM_ROUTE || resultCode == ROUTING_FILE_NOT_EXIST;
  }
}