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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
package com.mapswithme.maps.routing;
import android.content.DialogInterface;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.appcompat.app.AlertDialog;
import android.util.Pair;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
import com.mapswithme.maps.downloader.CountryItem;
import com.mapswithme.maps.downloader.MapManager;
import com.mapswithme.util.UiUtils;
public class RoutingErrorDialogFragment extends BaseRoutingErrorDialogFragment
{
private static final String EXTRA_RESULT_CODE = "RouterResultCode";
private int mResultCode;
private String mMessage;
private boolean mNeedMoreMaps;
@Override
void beforeDialogCreated(AlertDialog.Builder builder)
{
super.beforeDialogCreated(builder);
Pair<String, String> titleMessage = ResultCodesHelper.getDialogTitleSubtitle(mResultCode, mMissingMaps.size());
builder.setTitle(titleMessage.first);
mMessage = titleMessage.second;
if (ResultCodesHelper.isDownloadable(mResultCode, mMissingMaps.size()))
builder.setPositiveButton(R.string.download, null);
mNeedMoreMaps = ResultCodesHelper.isMoreMapsNeeded(mResultCode);
if (mNeedMoreMaps)
builder.setNegativeButton(R.string.later, null);
}
private View addMessage(View frame)
{
UiUtils.setTextAndHideIfEmpty((TextView)frame.findViewById(R.id.tv__message), mMessage);
return frame;
}
@Override
public void onDismiss(DialogInterface dialog)
{
if (mNeedMoreMaps && mCancelled)
mCancelled = false;
super.onDismiss(dialog);
}
@Override
View buildSingleMapView(CountryItem map)
{
return addMessage(super.buildSingleMapView(map));
}
@Override
View buildMultipleMapView()
{
return addMessage(super.buildMultipleMapView());
}
private void startDownload()
{
if (mMissingMaps.isEmpty())
{
dismiss();
return;
}
long size = 0;
for (CountryItem country : mMissingMaps)
{
if (country.status != CountryItem.STATUS_PROGRESS &&
country.status != CountryItem.STATUS_APPLYING)
{
size += country.totalSize;
}
}
MapManager.warnOn3g(getActivity(), size, new Runnable()
{
@Override
public void run()
{
RoutingMapsDownloadFragment downloader = RoutingMapsDownloadFragment.create(mMapsArray);
downloader.show(getActivity().getSupportFragmentManager(), downloader.getClass().getSimpleName());
mCancelled = false;
dismiss();
}
});
}
@Override
public void onStart()
{
super.onStart();
final AlertDialog dlg = (AlertDialog) getDialog();
Button button = dlg.getButton(AlertDialog.BUTTON_POSITIVE);
if (button == null)
return;
button.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
startDownload();
}
});
}
@Override
public void onCancel(DialogInterface dialog)
{
mCancelled = true;
super.onCancel(dialog);
}
@Override
void parseArguments()
{
super.parseArguments();
mResultCode = getArguments().getInt(EXTRA_RESULT_CODE);
}
public static RoutingErrorDialogFragment create(int resultCode, @Nullable String[] missingMaps)
{
Bundle args = new Bundle();
args.putInt(EXTRA_RESULT_CODE, resultCode);
args.putStringArray(EXTRA_MISSING_MAPS, missingMaps);
RoutingErrorDialogFragment res = (RoutingErrorDialogFragment)Fragment.instantiate(MwmApplication.get(), RoutingErrorDialogFragment.class.getName());
res.setArguments(args);
return res;
}
}
|