blob: 28bddb3cd369a3682c202a7b8a0f91efb86b67ea (
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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
package com.mapswithme.maps.routing;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.view.ViewGroup;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
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.maps.widget.WheelProgressView;
import com.mapswithme.util.UiUtils;
public class RoutingMapsDownloadFragment extends BaseRoutingErrorDialogFragment
{
private ViewGroup mItemsFrame;
private final Set<String> mMaps = new HashSet<>();
private int mSubscribeSlot;
@Override
void beforeDialogCreated(AlertDialog.Builder builder)
{
super.beforeDialogCreated(builder);
builder.setTitle(R.string.downloading);
mMapsArray = new String[mMissingMaps.size()];
for (int i = 0; i < mMissingMaps.size(); i++)
{
CountryItem item = mMissingMaps.get(i);
mMaps.add(item.id);
mMapsArray[i] = item.id;
}
for (String map : mMaps)
MapManager.nativeDownload(map);
}
private View setupFrame(View frame)
{
UiUtils.hide(frame.findViewById(R.id.tv__message));
mItemsFrame = (ViewGroup) frame.findViewById(R.id.items_frame);
return frame;
}
@Override
View buildSingleMapView(CountryItem map)
{
View res = setupFrame(super.buildSingleMapView(map));
bindGroup(res);
return res;
}
@Override
View buildMultipleMapView()
{
return setupFrame(super.buildMultipleMapView());
}
private WheelProgressView getWheel()
{
if (mItemsFrame == null)
return null;
View frame = mItemsFrame.getChildAt(0);
if (frame == null)
return null;
WheelProgressView res = (WheelProgressView) frame.findViewById(R.id.wheel_progress);
return ((res != null && UiUtils.isVisible(res)) ? res : null);
}
private void updateWheel(WheelProgressView wheel)
{
int progress = MapManager.nativeGetOverallProgress(mMapsArray);
if (progress == 0)
wheel.setPending(true);
else
{
wheel.setPending(false);
wheel.setProgress(progress);
}
}
@Override
void bindGroup(View view)
{
WheelProgressView wheel = (WheelProgressView) view.findViewById(R.id.wheel_progress);
UiUtils.show(wheel);
updateWheel(wheel);
}
@Override
public void onDismiss(DialogInterface dialog)
{
if (mCancelled)
for (String item : mMaps)
MapManager.nativeCancel(item);
super.onDismiss(dialog);
}
@Override
public void onStart()
{
super.onStart();
setCancelable(false);
mSubscribeSlot = MapManager.nativeSubscribe(new MapManager.StorageCallback()
{
{
update();
}
private void update()
{
WheelProgressView wheel = getWheel();
if (wheel != null)
updateWheel(wheel);
}
@Override
public void onStatusChanged(List<MapManager.StorageCallbackData> data)
{
for (MapManager.StorageCallbackData item : data)
if (mMaps.contains(item.countryId))
{
if (item.newStatus == CountryItem.STATUS_DONE)
{
mMaps.remove(item.countryId);
if (mMaps.isEmpty())
{
mCancelled = false;
RoutingController.get().checkAndBuildRoute();
dismissAllowingStateLoss();
return;
}
}
update();
return;
}
}
@Override
public void onProgress(String countryId, long localSize, long remoteSize)
{
if (mMaps.contains(countryId))
update();
}
});
}
@Override
public void onStop()
{
super.onStop();
if (mSubscribeSlot != 0)
{
MapManager.nativeUnsubscribe(mSubscribeSlot);
mSubscribeSlot = 0;
}
}
public static RoutingMapsDownloadFragment create(String[] missingMaps)
{
Bundle args = new Bundle();
args.putStringArray(EXTRA_MISSING_MAPS, missingMaps);
RoutingMapsDownloadFragment res = (RoutingMapsDownloadFragment) Fragment.instantiate(MwmApplication.get(), RoutingMapsDownloadFragment.class.getName());
res.setArguments(args);
return res;
}
}
|