Context menu: download from map in progress
This commit is contained in:
parent
68d5106b4c
commit
036790784c
10 changed files with 280 additions and 134 deletions
|
@ -162,6 +162,8 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingLeft="54dp"
|
android:paddingLeft="54dp"
|
||||||
android:paddingRight="2dp"
|
android:paddingRight="2dp"
|
||||||
|
android:minHeight="52dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
android:layout_marginTop="-16dp"
|
android:layout_marginTop="-16dp"
|
||||||
android:paddingBottom="4dp"
|
android:paddingBottom="4dp"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
|
@ -182,30 +184,14 @@
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_marginRight="12dp">
|
android:layout_marginRight="12dp">
|
||||||
|
|
||||||
<LinearLayout
|
<TextView
|
||||||
|
android:id="@+id/progressTitle"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal">
|
android:layout_gravity="center_vertical"
|
||||||
|
android:visibility="visible"
|
||||||
|
tools:text="@string/shared_string_downloading"/>
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/progressTitle"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:visibility="visible"
|
|
||||||
tools:text="@string/shared_string_downloading"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/progressPercent"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:layout_marginLeft="12dp"
|
|
||||||
android:visibility="visible"
|
|
||||||
tools:text="12%"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/progressBar"
|
android:id="@+id/progressBar"
|
||||||
style="?android:attr/progressBarStyleHorizontal"
|
style="?android:attr/progressBarStyleHorizontal"
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||||
-->
|
-->
|
||||||
|
<string name="shared_string_update">Update</string>
|
||||||
<string name="rec_photo_description">Photo %1$s</string>
|
<string name="rec_photo_description">Photo %1$s</string>
|
||||||
<string name="rec_audio_description">Audio %1$s</string>
|
<string name="rec_audio_description">Audio %1$s</string>
|
||||||
<string name="rec_video_description">Video %1$s</string>
|
<string name="rec_video_description">Video %1$s</string>
|
||||||
|
|
|
@ -224,7 +224,7 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
getMyApplication().getAppCustomization().pauseActivity(DownloadActivity.class);
|
getMyApplication().getAppCustomization().pauseActivity(DownloadActivity.class);
|
||||||
downloadThread.setUiActivity(null);
|
downloadThread.resetUiActivity(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -89,6 +89,12 @@ public class DownloadIndexesThread {
|
||||||
this.uiActivity = uiActivity;
|
this.uiActivity = uiActivity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resetUiActivity(DownloadEvents uiActivity) {
|
||||||
|
if (this.uiActivity == uiActivity) {
|
||||||
|
this.uiActivity = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
protected void downloadInProgress() {
|
protected void downloadInProgress() {
|
||||||
if (uiActivity != null) {
|
if (uiActivity != null) {
|
||||||
|
|
|
@ -55,6 +55,9 @@ public class DownloadResources extends DownloadResourceGroup {
|
||||||
|
|
||||||
public IndexItem getIndexItem(String fileName) {
|
public IndexItem getIndexItem(String fileName) {
|
||||||
IndexItem res = null;
|
IndexItem res = null;
|
||||||
|
if (rawResources == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
for (IndexItem item : rawResources) {
|
for (IndexItem item : rawResources) {
|
||||||
if (fileName.equals(item.getFileName())) {
|
if (fileName.equals(item.getFileName())) {
|
||||||
res = item;
|
res = item;
|
||||||
|
@ -64,6 +67,19 @@ public class DownloadResources extends DownloadResourceGroup {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<IndexItem> getIndexItems(String fileNamePrefix) {
|
||||||
|
List<IndexItem> res = new LinkedList<>();
|
||||||
|
if (rawResources == null) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
for (IndexItem item : rawResources) {
|
||||||
|
if (item.getFileName().toLowerCase().startsWith(fileNamePrefix)) {
|
||||||
|
res.add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
public void updateLoadedFiles() {
|
public void updateLoadedFiles() {
|
||||||
initAlreadyLoadedFiles();
|
initAlreadyLoadedFiles();
|
||||||
prepareFilesToUpdate();
|
prepareFilesToUpdate();
|
||||||
|
|
|
@ -398,4 +398,10 @@ public class MapContextMenu extends MenuTitleController {
|
||||||
public boolean buttonsVisible() {
|
public boolean buttonsVisible() {
|
||||||
return menuController == null || menuController.buttonsVisible();
|
return menuController == null || menuController.buttonsVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateData() {
|
||||||
|
if (menuController != null) {
|
||||||
|
menuController.updateData();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -156,89 +156,41 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
||||||
view = inflater.inflate(R.layout.map_context_menu_fragment, container, false);
|
view = inflater.inflate(R.layout.map_context_menu_fragment, container, false);
|
||||||
mainView = view.findViewById(R.id.context_menu_main);
|
mainView = view.findViewById(R.id.context_menu_main);
|
||||||
|
|
||||||
// Title buttons
|
|
||||||
boolean showButtonsContainer = (leftTitleButtonController != null || rightTitleButtonController != null)
|
|
||||||
&& (titleProgressController == null || !titleProgressController.visible);
|
|
||||||
final View titleButtonsContainer = view.findViewById(R.id.title_button_container);
|
|
||||||
titleButtonsContainer.setVisibility(showButtonsContainer ? View.VISIBLE : View.GONE);
|
|
||||||
|
|
||||||
// Left title button
|
// Left title button
|
||||||
final Button leftTitleButton = (Button) view.findViewById(R.id.title_button);
|
final Button leftTitleButton = (Button) view.findViewById(R.id.title_button);
|
||||||
final TextView titleButtonRightText = (TextView) view.findViewById(R.id.title_button_right_text);
|
|
||||||
if (leftTitleButtonController != null) {
|
if (leftTitleButtonController != null) {
|
||||||
leftTitleButton.setText(leftTitleButtonController.caption);
|
|
||||||
leftTitleButton.setVisibility(leftTitleButtonController.visible ? View.VISIBLE : View.INVISIBLE);
|
|
||||||
|
|
||||||
Drawable leftIcon = leftTitleButtonController.getLeftIcon();
|
|
||||||
if (leftIcon != null) {
|
|
||||||
leftTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
|
|
||||||
leftTitleButton.setCompoundDrawablePadding(dpToPx(4f));
|
|
||||||
}
|
|
||||||
leftTitleButton.setOnClickListener(new View.OnClickListener() {
|
leftTitleButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
leftTitleButtonController.buttonPressed();
|
leftTitleButtonController.buttonPressed();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (leftTitleButtonController.needRightText) {
|
|
||||||
titleButtonRightText.setText(leftTitleButtonController.rightTextCaption);
|
|
||||||
} else {
|
|
||||||
titleButtonRightText.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
leftTitleButton.setVisibility(View.GONE);
|
|
||||||
titleButtonRightText.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Right title button
|
// Right title button
|
||||||
final Button rightTitleButton = (Button) view.findViewById(R.id.title_button_right);
|
final Button rightTitleButton = (Button) view.findViewById(R.id.title_button_right);
|
||||||
if (rightTitleButtonController != null) {
|
if (rightTitleButtonController != null) {
|
||||||
rightTitleButton.setText(rightTitleButtonController.caption);
|
|
||||||
rightTitleButton.setVisibility(rightTitleButtonController.visible ? View.VISIBLE : View.INVISIBLE);
|
|
||||||
|
|
||||||
Drawable leftIcon = rightTitleButtonController.getLeftIcon();
|
|
||||||
if (leftIcon != null) {
|
|
||||||
rightTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
|
|
||||||
rightTitleButton.setCompoundDrawablePadding(dpToPx(4f));
|
|
||||||
}
|
|
||||||
rightTitleButton.setOnClickListener(new View.OnClickListener() {
|
rightTitleButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
rightTitleButtonController.buttonPressed();
|
rightTitleButtonController.buttonPressed();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
rightTitleButton.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Top Right title button
|
// Top Right title button
|
||||||
final Button topRightTitleButton = (Button) view.findViewById(R.id.title_button_top_right);
|
final Button topRightTitleButton = (Button) view.findViewById(R.id.title_button_top_right);
|
||||||
if (topRightTitleButtonController != null) {
|
if (topRightTitleButtonController != null) {
|
||||||
topRightTitleButton.setText(topRightTitleButtonController.caption);
|
|
||||||
topRightTitleButton.setVisibility(topRightTitleButtonController.visible ? View.VISIBLE : View.INVISIBLE);
|
|
||||||
|
|
||||||
Drawable leftIcon = topRightTitleButtonController.getLeftIcon();
|
|
||||||
if (leftIcon != null) {
|
|
||||||
topRightTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
|
|
||||||
topRightTitleButton.setCompoundDrawablePadding(dpToPx(4f));
|
|
||||||
}
|
|
||||||
topRightTitleButton.setOnClickListener(new View.OnClickListener() {
|
topRightTitleButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
topRightTitleButtonController.buttonPressed();
|
topRightTitleButtonController.buttonPressed();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
topRightTitleButton.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Progress bar
|
// Progress bar
|
||||||
final View titleProgressContainer = view.findViewById(R.id.title_progress_container);
|
|
||||||
if (titleProgressController != null) {
|
if (titleProgressController != null) {
|
||||||
|
|
||||||
updateProgress();
|
|
||||||
|
|
||||||
final ImageView progressButton = (ImageView) view.findViewById(R.id.progressButton);
|
final ImageView progressButton = (ImageView) view.findViewById(R.id.progressButton);
|
||||||
progressButton.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_remove_dark,
|
progressButton.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_remove_dark,
|
||||||
light ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
|
light ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
|
||||||
|
@ -248,10 +200,10 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
||||||
titleProgressController.buttonPressed();
|
titleProgressController.buttonPressed();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
titleProgressContainer.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateButtonsAndProgress();
|
||||||
|
|
||||||
if (menu.isLandscapeLayout()) {
|
if (menu.isLandscapeLayout()) {
|
||||||
mainView.setLayoutParams(new FrameLayout.LayoutParams(dpToPx(menu.getLandscapeWidthDp()),
|
mainView.setLayoutParams(new FrameLayout.LayoutParams(dpToPx(menu.getLandscapeWidthDp()),
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT));
|
ViewGroup.LayoutParams.MATCH_PARENT));
|
||||||
|
@ -486,29 +438,82 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void recalculateFullHeightMax() {
|
private void updateButtonsAndProgress() {
|
||||||
menuFullHeightMax = menuTitleHeight + (menuBottomViewHeight > 0 ? menuBottomViewHeight : -dpToPx(SHADOW_HEIGHT_BOTTOM_DP));
|
// Title buttons
|
||||||
}
|
boolean showButtonsContainer = (leftTitleButtonController != null || rightTitleButtonController != null)
|
||||||
|
&& (titleProgressController == null || !titleProgressController.visible);
|
||||||
|
final View titleButtonsContainer = view.findViewById(R.id.title_button_container);
|
||||||
|
titleButtonsContainer.setVisibility(showButtonsContainer ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
private void updateProgress() {
|
// Left title button
|
||||||
final View titleProgressContainer = view.findViewById(R.id.title_progress_container);
|
final Button leftTitleButton = (Button) view.findViewById(R.id.title_button);
|
||||||
titleProgressContainer.setVisibility(titleProgressController.visible ? View.VISIBLE : View.GONE);
|
final TextView titleButtonRightText = (TextView) view.findViewById(R.id.title_button_right_text);
|
||||||
|
if (leftTitleButtonController != null) {
|
||||||
|
leftTitleButton.setText(leftTitleButtonController.caption);
|
||||||
|
leftTitleButton.setVisibility(leftTitleButtonController.visible ? View.VISIBLE : View.INVISIBLE);
|
||||||
|
|
||||||
final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
|
Drawable leftIcon = leftTitleButtonController.getLeftIcon();
|
||||||
final TextView progressTitle = (TextView) view.findViewById(R.id.progressTitle);
|
if (leftIcon != null) {
|
||||||
final TextView progressPercent = (TextView) view.findViewById(R.id.progressPercent);
|
leftTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
|
||||||
progressTitle.setText(titleProgressController.caption);
|
leftTitleButton.setCompoundDrawablePadding(dpToPx(4f));
|
||||||
if (titleProgressController.indeterminate) {
|
}
|
||||||
progressPercent.setVisibility(View.GONE);
|
|
||||||
|
if (leftTitleButtonController.needRightText) {
|
||||||
|
titleButtonRightText.setText(leftTitleButtonController.rightTextCaption);
|
||||||
|
} else {
|
||||||
|
titleButtonRightText.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
progressPercent.setVisibility(View.VISIBLE);
|
leftTitleButton.setVisibility(View.GONE);
|
||||||
progressPercent.setText(titleProgressController.progress + "%");
|
titleButtonRightText.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
progressBar.setIndeterminate(titleProgressController.indeterminate);
|
|
||||||
progressBar.setProgress(titleProgressController.progress);
|
|
||||||
|
|
||||||
final ImageView progressButton = (ImageView) view.findViewById(R.id.progressButton);
|
// Right title button
|
||||||
progressButton.setVisibility(titleProgressController.buttonVisible ? View.VISIBLE : View.GONE);
|
final Button rightTitleButton = (Button) view.findViewById(R.id.title_button_right);
|
||||||
|
if (rightTitleButtonController != null) {
|
||||||
|
rightTitleButton.setText(rightTitleButtonController.caption);
|
||||||
|
rightTitleButton.setVisibility(rightTitleButtonController.visible ? View.VISIBLE : View.INVISIBLE);
|
||||||
|
|
||||||
|
Drawable leftIcon = rightTitleButtonController.getLeftIcon();
|
||||||
|
if (leftIcon != null) {
|
||||||
|
rightTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
|
||||||
|
rightTitleButton.setCompoundDrawablePadding(dpToPx(4f));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rightTitleButton.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Top Right title button
|
||||||
|
final Button topRightTitleButton = (Button) view.findViewById(R.id.title_button_top_right);
|
||||||
|
if (topRightTitleButtonController != null) {
|
||||||
|
topRightTitleButton.setText(topRightTitleButtonController.caption);
|
||||||
|
topRightTitleButton.setVisibility(topRightTitleButtonController.visible ? View.VISIBLE : View.INVISIBLE);
|
||||||
|
|
||||||
|
Drawable leftIcon = topRightTitleButtonController.getLeftIcon();
|
||||||
|
if (leftIcon != null) {
|
||||||
|
topRightTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
|
||||||
|
topRightTitleButton.setCompoundDrawablePadding(dpToPx(4f));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
topRightTitleButton.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Progress bar
|
||||||
|
final View titleProgressContainer = view.findViewById(R.id.title_progress_container);
|
||||||
|
if (titleProgressController != null) {
|
||||||
|
titleProgressContainer.setVisibility(titleProgressController.visible ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
|
final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
|
||||||
|
final TextView progressTitle = (TextView) view.findViewById(R.id.progressTitle);
|
||||||
|
progressTitle.setText(titleProgressController.caption);
|
||||||
|
progressBar.setIndeterminate(titleProgressController.indeterminate);
|
||||||
|
progressBar.setProgress(titleProgressController.progress);
|
||||||
|
|
||||||
|
final ImageView progressButton = (ImageView) view.findViewById(R.id.progressButton);
|
||||||
|
progressButton.setVisibility(titleProgressController.buttonVisible ? View.VISIBLE : View.GONE);
|
||||||
|
} else {
|
||||||
|
titleProgressContainer.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildHeader() {
|
private void buildHeader() {
|
||||||
|
@ -545,6 +550,18 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
getMyApplication().getDownloadThread().setUiActivity(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
getMyApplication().getDownloadThread().resetUiActivity(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
|
@ -583,7 +600,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
||||||
menuTitleHeight = menuTopShadowHeight + menuTopShadowAllHeight + dy;
|
menuTitleHeight = menuTopShadowHeight + menuTopShadowAllHeight + dy;
|
||||||
menuBottomViewHeight = view.findViewById(R.id.context_menu_bottom_view).getHeight();
|
menuBottomViewHeight = view.findViewById(R.id.context_menu_bottom_view).getHeight();
|
||||||
|
|
||||||
recalculateFullHeightMax();
|
menuFullHeightMax = menuTitleHeight + (menuBottomViewHeight > 0 ? menuBottomViewHeight : -dpToPx(SHADOW_HEIGHT_BOTTOM_DP));
|
||||||
|
|
||||||
ViewTreeObserver obs = view.getViewTreeObserver();
|
ViewTreeObserver obs = view.getViewTreeObserver();
|
||||||
|
|
||||||
|
@ -824,17 +841,27 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
||||||
//DownloadEvents
|
//DownloadEvents
|
||||||
@Override
|
@Override
|
||||||
public void newDownloadIndexes() {
|
public void newDownloadIndexes() {
|
||||||
|
updateOnDownload();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void downloadInProgress() {
|
public void downloadInProgress() {
|
||||||
|
updateOnDownload();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void downloadHasFinished() {
|
public void downloadHasFinished() {
|
||||||
|
updateOnDownload();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateOnDownload() {
|
||||||
|
boolean wasProgressVisible = menu.getTitleProgressController() != null && menu.getTitleProgressController().visible;
|
||||||
|
menu.updateData();
|
||||||
|
boolean progressVisible = menu.getTitleProgressController() != null && menu.getTitleProgressController().visible;
|
||||||
|
updateButtonsAndProgress();
|
||||||
|
if (wasProgressVisible != progressVisible) {
|
||||||
|
runLayoutListener();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private MapActivity getMapActivity() {
|
private MapActivity getMapActivity() {
|
||||||
|
|
|
@ -240,6 +240,8 @@ public abstract class MenuController extends BaseMenuController {
|
||||||
ShareMenu.show(latLon, title, getMapActivity());
|
ShareMenu.show(latLon, title, getMapActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateData() {
|
||||||
|
}
|
||||||
|
|
||||||
public abstract class TitleButtonController {
|
public abstract class TitleButtonController {
|
||||||
public String caption = "";
|
public String caption = "";
|
||||||
|
@ -261,13 +263,12 @@ public abstract class MenuController extends BaseMenuController {
|
||||||
|
|
||||||
public abstract class TitleProgressController {
|
public abstract class TitleProgressController {
|
||||||
public String caption = "";
|
public String caption = "";
|
||||||
public int progress;
|
public int progress = 0;
|
||||||
public boolean indeterminate;
|
public boolean indeterminate;
|
||||||
public boolean visible;
|
public boolean visible;
|
||||||
public boolean buttonVisible;
|
public boolean buttonVisible;
|
||||||
|
|
||||||
public void setIndexesDownloadMode() {
|
public void setIndexesDownloadMode() {
|
||||||
progress = 0;
|
|
||||||
caption = getMapActivity().getString(R.string.downloading_list_indexes);
|
caption = getMapActivity().getString(R.string.downloading_list_indexes);
|
||||||
indeterminate = true;
|
indeterminate = true;
|
||||||
buttonVisible = false;
|
buttonVisible = false;
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package net.osmand.plus.mapcontextmenu.controllers;
|
package net.osmand.plus.mapcontextmenu.controllers;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
import net.osmand.binary.BinaryMapDataObject;
|
import net.osmand.binary.BinaryMapDataObject;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
@ -11,41 +13,43 @@ import net.osmand.map.WorldRegion;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.download.DownloadActivity;
|
import net.osmand.plus.download.DownloadActivityType;
|
||||||
import net.osmand.plus.download.DownloadIndexesThread;
|
import net.osmand.plus.download.DownloadIndexesThread;
|
||||||
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
|
import net.osmand.plus.download.DownloadValidationManager;
|
||||||
|
import net.osmand.plus.download.IndexItem;
|
||||||
|
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||||
import net.osmand.plus.mapcontextmenu.MenuController;
|
import net.osmand.plus.mapcontextmenu.MenuController;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class MapDataMenuController extends MenuController {
|
public class MapDataMenuController extends MenuController {
|
||||||
private WorldRegion region;
|
private WorldRegion region;
|
||||||
private String regionName;
|
private IndexItem indexItem;
|
||||||
|
private List<IndexItem> otherIndexItems;
|
||||||
|
private String name;
|
||||||
|
|
||||||
public MapDataMenuController(OsmandApplication app, MapActivity mapActivity, PointDescription pointDescription, final BinaryMapDataObject dataObject) {
|
private DownloadValidationManager downloadValidationManager;
|
||||||
|
private DownloadIndexesThread downloadThread;
|
||||||
|
|
||||||
|
public MapDataMenuController(final OsmandApplication app, final MapActivity mapActivity, PointDescription pointDescription, final BinaryMapDataObject dataObject) {
|
||||||
super(new MenuBuilder(app), pointDescription, mapActivity);
|
super(new MenuBuilder(app), pointDescription, mapActivity);
|
||||||
OsmandRegions osmandRegions = app.getRegions();
|
OsmandRegions osmandRegions = app.getRegions();
|
||||||
String fullName = osmandRegions.getFullName(dataObject);
|
String fullName = osmandRegions.getFullName(dataObject);
|
||||||
final WorldRegion region = osmandRegions.getRegionData(fullName);
|
this.region = osmandRegions.getRegionData(fullName);
|
||||||
this.region = region;
|
name = getPointDescription().getName();
|
||||||
if (region != null) {
|
downloadValidationManager = new DownloadValidationManager(app);
|
||||||
regionName = region.getLocaleName();
|
downloadThread = app.getDownloadThread();
|
||||||
} else {
|
|
||||||
regionName = dataObject.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean hasIndexes = app.getDownloadThread().getIndexes().isDownloadedFromInternet;
|
|
||||||
boolean isDownloading = false; //todo
|
|
||||||
|
|
||||||
|
mapActivity.getSupportFragmentManager();
|
||||||
leftTitleButtonController = new TitleButtonController() {
|
leftTitleButtonController = new TitleButtonController() {
|
||||||
@Override
|
@Override
|
||||||
public void buttonPressed() {
|
public void buttonPressed() {
|
||||||
getMapActivity().getContextMenu().close();
|
if (indexItem != null) {
|
||||||
|
downloadValidationManager.startDownload(mapActivity, indexItem);
|
||||||
final Intent intent = new Intent(getMapActivity(), getMapActivity().getMyApplication()
|
}
|
||||||
.getAppCustomization().getDownloadIndexActivity());
|
|
||||||
intent.putExtra(DownloadActivity.FILTER_KEY, regionName);
|
|
||||||
intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB);
|
|
||||||
getMapActivity().startActivity(intent);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
leftTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_download);
|
leftTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_download);
|
||||||
|
@ -54,8 +58,9 @@ public class MapDataMenuController extends MenuController {
|
||||||
rightTitleButtonController = new TitleButtonController() {
|
rightTitleButtonController = new TitleButtonController() {
|
||||||
@Override
|
@Override
|
||||||
public void buttonPressed() {
|
public void buttonPressed() {
|
||||||
// todo delete
|
if (indexItem != null) {
|
||||||
//getMapActivity().getContextMenu().close();
|
deleteItem();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
rightTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_delete);
|
rightTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_delete);
|
||||||
|
@ -68,25 +73,21 @@ public class MapDataMenuController extends MenuController {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
topRightTitleButtonController.caption = getMapActivity().getString(R.string.download_select_map_types);
|
topRightTitleButtonController.caption = getMapActivity().getString(R.string.download_select_map_types);
|
||||||
topRightTitleButtonController.visible = hasIndexes && !isDownloading;
|
|
||||||
|
|
||||||
titleProgressController = new TitleProgressController() {
|
titleProgressController = new TitleProgressController() {
|
||||||
@Override
|
@Override
|
||||||
public void buttonPressed() {
|
public void buttonPressed() {
|
||||||
// todo cancel download
|
if (indexItem != null) {
|
||||||
|
downloadThread.cancelDownload(indexItem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (!hasIndexes) {
|
|
||||||
titleProgressController.setIndexesDownloadMode();
|
if (!downloadThread.getIndexes().isDownloadedFromInternet) {
|
||||||
titleProgressController.visible = true;
|
downloadThread.runReloadIndexFiles();
|
||||||
getMapActivity().getMyApplication().getDownloadThread().runReloadIndexFiles();
|
|
||||||
} else if (isDownloading) {
|
|
||||||
titleProgressController.setMapDownloadMode();
|
|
||||||
titleProgressController.caption = "Downloading..."; // todo
|
|
||||||
titleProgressController.visible = true;
|
|
||||||
} else {
|
|
||||||
titleProgressController.visible = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -106,7 +107,7 @@ public class MapDataMenuController extends MenuController {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNameStr() {
|
public String getNameStr() {
|
||||||
return regionName;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -141,4 +142,95 @@ public class MapDataMenuController extends MenuController {
|
||||||
public boolean buttonsVisible() {
|
public boolean buttonsVisible() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateData() {
|
||||||
|
if (indexItem == null) {
|
||||||
|
otherIndexItems = downloadThread.getIndexes().getIndexItems(region.getRegionDownloadNameLC());
|
||||||
|
for (IndexItem i : otherIndexItems) {
|
||||||
|
if (i.getType() == DownloadActivityType.NORMAL_FILE) {
|
||||||
|
indexItem = i;
|
||||||
|
otherIndexItems.remove(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
topRightTitleButtonController.visible = otherIndexItems.size() > 0;
|
||||||
|
if (indexItem != null) {
|
||||||
|
if (indexItem.isOutdated()) {
|
||||||
|
leftTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_update)
|
||||||
|
+ " (" + indexItem.getSizeDescription(getMapActivity()) + ")";
|
||||||
|
} else {
|
||||||
|
leftTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_download)
|
||||||
|
+ " (" + indexItem.getSizeDescription(getMapActivity()) + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rightTitleButtonController.visible = indexItem != null && indexItem.isDownloaded();
|
||||||
|
|
||||||
|
boolean hasIndexes = downloadThread.getIndexes().isDownloadedFromInternet;
|
||||||
|
boolean isDownloading = indexItem != null && downloadThread.getCurrentDownloadingItem() == indexItem;
|
||||||
|
if (!hasIndexes) {
|
||||||
|
titleProgressController.setIndexesDownloadMode();
|
||||||
|
titleProgressController.visible = true;
|
||||||
|
} else if (isDownloading) {
|
||||||
|
titleProgressController.setMapDownloadMode();
|
||||||
|
titleProgressController.progress = downloadThread.getCurrentDownloadingItemProgress();
|
||||||
|
double mb = indexItem.getArchiveSizeMB();
|
||||||
|
String v ;
|
||||||
|
if (titleProgressController.progress != -1) {
|
||||||
|
v = getMapActivity().getString(R.string.value_downloaded_from_max, mb * titleProgressController.progress / 100, mb);
|
||||||
|
} else {
|
||||||
|
v = getMapActivity().getString(R.string.file_size_in_mb, mb);
|
||||||
|
}
|
||||||
|
if(indexItem.getType() == DownloadActivityType.ROADS_FILE) {
|
||||||
|
titleProgressController.caption = indexItem.getType().getString(getMapActivity()) + " • " + v;
|
||||||
|
} else {
|
||||||
|
titleProgressController.caption = v;
|
||||||
|
}
|
||||||
|
titleProgressController.visible = true;
|
||||||
|
} else {
|
||||||
|
titleProgressController.visible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteItem() {
|
||||||
|
final OsmandApplication app = getMapActivity().getMyApplication();
|
||||||
|
final File fl = indexItem.getTargetFile(app);
|
||||||
|
if (fl.exists()) {
|
||||||
|
AlertDialog.Builder confirm = new AlertDialog.Builder(getMapActivity());
|
||||||
|
confirm.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
new AsyncTask<Void, Void, Void>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
getMapActivity().getContextMenu().close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... params) {
|
||||||
|
boolean successfull = Algorithms.removeAllFiles(fl.getAbsoluteFile());
|
||||||
|
if (successfull) {
|
||||||
|
app.getResourceManager().closeFile(fl.getName());
|
||||||
|
}
|
||||||
|
app.getDownloadThread().updateLoadedFiles();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onPostExecute(Void result) {
|
||||||
|
getMapActivity().refreshMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
}.execute((Void) null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
confirm.setNegativeButton(R.string.shared_string_no, null);
|
||||||
|
String fn = FileNameTranslationHelper.getFileName(getMapActivity(), app.getRegions(),
|
||||||
|
indexItem.getVisibleName(getMapActivity(), app.getRegions()));
|
||||||
|
confirm.setMessage(getMapActivity().getString(R.string.delete_confirmation_msg, fn));
|
||||||
|
confirm.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -356,6 +356,17 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PointDescription getObjectName(Object o) {
|
public PointDescription getObjectName(Object o) {
|
||||||
|
if (o instanceof BinaryMapDataObject) {
|
||||||
|
String fullName = osmandRegions.getFullName((BinaryMapDataObject) o);
|
||||||
|
final WorldRegion region = osmandRegions.getRegionData(fullName);
|
||||||
|
if (region != null) {
|
||||||
|
return new PointDescription(PointDescription.POINT_TYPE_WORLD_REGION,
|
||||||
|
view.getContext().getString(R.string.shared_string_map), region.getLocaleName());
|
||||||
|
} else {
|
||||||
|
return new PointDescription(PointDescription.POINT_TYPE_WORLD_REGION,
|
||||||
|
view.getContext().getString(R.string.shared_string_map), ((BinaryMapDataObject) o).getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
return new PointDescription(PointDescription.POINT_TYPE_WORLD_REGION,
|
return new PointDescription(PointDescription.POINT_TYPE_WORLD_REGION,
|
||||||
view.getContext().getString(R.string.shared_string_map), "");
|
view.getContext().getString(R.string.shared_string_map), "");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue