Download map from context menu in progress

This commit is contained in:
Alexey Kulish 2016-07-29 21:54:14 +03:00
parent 6c29a3c865
commit cab8ac2d90
5 changed files with 158 additions and 19 deletions

View file

@ -213,6 +213,59 @@
</LinearLayout>
<LinearLayout
android:id="@+id/download_buttons_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/context_menu_buttons_top_margin"
android:clickable="true"
android:orientation="vertical"
android:paddingBottom="@dimen/context_menu_buttons_padding_bottom"
android:paddingLeft="62dp"
android:paddingRight="2dp"
android:visibility="gone"
tools:visibility="visible">
<View
android:id="@+id/download_buttons_top_border"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:background="?attr/dashboard_divider"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/download_button_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="left|center_vertical"
android:paddingLeft="@dimen/context_menu_button_padding_x"
android:paddingRight="@dimen/context_menu_button_padding_x"
android:text="@string/shared_string_download"
android:textColor="?attr/contextMenuButtonColor"
android:textSize="@dimen/default_desc_text_size"/>
<Button
android:id="@+id/download_button_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:paddingLeft="@dimen/context_menu_button_padding_x"
android:paddingRight="@dimen/context_menu_button_padding_x"
android:text="@string/shared_string_delete"
android:textColor="?attr/contextMenuButtonColor"
android:textSize="@dimen/default_desc_text_size"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/title_progress_container"
android:layout_width="fill_parent"

View file

@ -785,6 +785,22 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
}
}
public TitleButtonController getLeftDownloadButtonController() {
if (menuController != null) {
return menuController.getLeftDownloadButtonController();
} else {
return null;
}
}
public TitleButtonController getRightDownloadButtonController() {
if (menuController != null) {
return menuController.getRightDownloadButtonController();
} else {
return null;
}
}
public TitleProgressController getTitleProgressController() {
if (menuController != null) {
return menuController.getTitleProgressController();

View file

@ -68,6 +68,8 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
private TitleButtonController leftTitleButtonController;
private TitleButtonController rightTitleButtonController;
private TitleButtonController topRightTitleButtonController;
private TitleButtonController leftDownloadButtonController;
private TitleButtonController rightDownloadButtonController;
private TitleProgressController titleProgressController;
private int menuTopViewHeight;
@ -128,6 +130,9 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
leftTitleButtonController = menu.getLeftTitleButtonController();
rightTitleButtonController = menu.getRightTitleButtonController();
topRightTitleButtonController = menu.getTopRightTitleButtonController();
leftDownloadButtonController = menu.getLeftDownloadButtonController();
rightDownloadButtonController = menu.getRightDownloadButtonController();
titleProgressController = menu.getTitleProgressController();
map = getMapActivity().getMapView();
@ -170,6 +175,28 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
});
}
// Left download button
final Button leftDownloadButton = (Button) view.findViewById(R.id.download_button_left);
if (leftDownloadButtonController != null) {
leftDownloadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
leftDownloadButtonController.buttonPressed();
}
});
}
// Right download button
final Button rightDownloadButton = (Button) view.findViewById(R.id.download_button_right);
if (rightDownloadButtonController != null) {
rightDownloadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rightDownloadButtonController.buttonPressed();
}
});
}
// Top Right title button
final Button topRightTitleButton = (Button) view.findViewById(R.id.title_button_top_right);
if (topRightTitleButtonController != null) {
@ -564,10 +591,9 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
private void updateButtonsAndProgress() {
// Title buttons
boolean showButtonsContainer = (leftTitleButtonController != null || rightTitleButtonController != null)
&& (titleProgressController == null || !titleProgressController.visible);
boolean showTitleButtonsContainer = (leftTitleButtonController != null || rightTitleButtonController != null);
final View titleButtonsContainer = view.findViewById(R.id.title_button_container);
titleButtonsContainer.setVisibility(showButtonsContainer ? View.VISIBLE : View.GONE);
titleButtonsContainer.setVisibility(showTitleButtonsContainer ? View.VISIBLE : View.GONE);
// Left title button
final Button leftTitleButton = (Button) view.findViewById(R.id.title_button);
@ -619,6 +645,40 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
topRightTitleButton.setVisibility(View.GONE);
}
// Download buttons
boolean showDownloadButtonsContainer = (leftDownloadButtonController != null || rightDownloadButtonController != null)
&& (titleProgressController == null || !titleProgressController.visible);
final View downloadButtonsContainer = view.findViewById(R.id.download_buttons_container);
downloadButtonsContainer.setVisibility(showDownloadButtonsContainer ? View.VISIBLE : View.GONE);
// Left download button
final Button leftDownloadButton = (Button) view.findViewById(R.id.download_button_left);
if (leftDownloadButtonController != null) {
leftDownloadButton.setText(leftDownloadButtonController.caption);
leftDownloadButton.setVisibility(leftDownloadButtonController.visible ? View.VISIBLE : View.GONE);
Drawable leftIcon = leftDownloadButtonController.getLeftIcon();
if (leftIcon != null) {
leftDownloadButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
leftDownloadButton.setCompoundDrawablePadding(dpToPx(4f));
}
} else {
leftDownloadButton.setVisibility(View.GONE);
}
// Right download button
final Button rightDownloadButton = (Button) view.findViewById(R.id.download_button_right);
if (rightDownloadButtonController != null) {
rightDownloadButton.setText(rightDownloadButtonController.caption);
rightDownloadButton.setVisibility(rightDownloadButtonController.visible ? View.VISIBLE : View.GONE);
Drawable leftIcon = rightDownloadButtonController.getLeftIcon();
rightDownloadButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
rightDownloadButton.setCompoundDrawablePadding(dpToPx(4f));
} else {
rightDownloadButton.setVisibility(View.GONE);
}
// Progress bar
final View titleProgressContainer = view.findViewById(R.id.title_progress_container);
if (titleProgressController != null) {

View file

@ -66,6 +66,8 @@ public abstract class MenuController extends BaseMenuController {
protected TitleButtonController rightTitleButtonController;
protected TitleButtonController topRightTitleButtonController;
protected TitleButtonController leftDownloadButtonController;
protected TitleButtonController rightDownloadButtonController;
protected TitleProgressController titleProgressController;
public MenuController(MenuBuilder builder, PointDescription pointDescription, MapActivity mapActivity) {
@ -235,6 +237,14 @@ public abstract class MenuController extends BaseMenuController {
return topRightTitleButtonController;
}
public TitleButtonController getLeftDownloadButtonController() {
return leftDownloadButtonController;
}
public TitleButtonController getRightDownloadButtonController() {
return rightDownloadButtonController;
}
public TitleProgressController getTitleProgressController() {
return titleProgressController;
}

View file

@ -83,7 +83,7 @@ public class MapDataMenuController extends MenuController {
OsmandPlugin srtmPlugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
srtmNeedsInstallation = srtmPlugin == null || srtmPlugin.needsInstallation();
leftTitleButtonController = new TitleButtonController() {
leftDownloadButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
if (backuped) {
@ -112,10 +112,10 @@ public class MapDataMenuController extends MenuController {
}
}
};
leftTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_download);
leftTitleButtonController.leftIconId = R.drawable.ic_action_import;
leftDownloadButtonController.caption = getMapActivity().getString(R.string.shared_string_download);
leftDownloadButtonController.leftIconId = R.drawable.ic_action_import;
rightTitleButtonController = new TitleButtonController() {
rightDownloadButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
if (indexItem != null) {
@ -129,8 +129,8 @@ public class MapDataMenuController extends MenuController {
}
}
};
rightTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_delete);
rightTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark;
rightDownloadButtonController.caption = getMapActivity().getString(R.string.shared_string_delete);
rightDownloadButtonController.leftIconId = R.drawable.ic_action_delete_dark;
topRightTitleButtonController = new TitleButtonController() {
@Override
@ -317,28 +317,28 @@ public class MapDataMenuController extends MenuController {
}
}
leftTitleButtonController.visible = true;
leftTitleButtonController.leftIconId = R.drawable.ic_action_import;
leftDownloadButtonController.visible = true;
leftDownloadButtonController.leftIconId = R.drawable.ic_action_import;
if (backuped) {
leftTitleButtonController.caption = getMapActivity().getString(R.string.local_index_mi_restore);
leftDownloadButtonController.caption = getMapActivity().getString(R.string.local_index_mi_restore);
} else if (indexItem != null) {
if ((indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE
|| indexItem.getType() == DownloadActivityType.HILLSHADE_FILE)
&& srtmDisabled) {
leftTitleButtonController.caption = getMapActivity().getString(R.string.get_plugin);
leftTitleButtonController.leftIconId = 0;
leftDownloadButtonController.caption = getMapActivity().getString(R.string.get_plugin);
leftDownloadButtonController.leftIconId = 0;
} else if (indexItem.isOutdated()) {
leftTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_update);
leftDownloadButtonController.caption = getMapActivity().getString(R.string.shared_string_update);
} else if (!downloaded) {
leftTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_download);
leftDownloadButtonController.caption = getMapActivity().getString(R.string.shared_string_download);
} else {
leftTitleButtonController.visible = false;
leftDownloadButtonController.visible = false;
}
} else {
leftTitleButtonController.visible = false;
leftDownloadButtonController.visible = false;
}
rightTitleButtonController.visible = downloaded;
rightDownloadButtonController.visible = downloaded;
topRightTitleButtonController.visible = (otherIndexItems != null && otherIndexItems.size() > 0)
|| (otherLocalIndexInfos != null && otherLocalIndexInfos.size() > 0);