Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2018-04-17 17:58:42 +02:00
commit 6391ce3c9c
15 changed files with 456 additions and 61 deletions

View file

@ -46,6 +46,14 @@
</LinearLayout>
<View
android:id="@+id/divider"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginLeft="@dimen/map_button_shadow_width"
android:layout_marginStart="@dimen/map_button_shadow_width"
tools:background="?attr/dashboard_divider"/>
<include
android:id="@+id/bottom_shadow"
layout="@layout/card_bottom_divider"

View file

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<ImageView
android:id="@+id/top_divider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:visibility="visible"
tools:visibility="visible" />
<LinearLayout
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/map_button_shadow_width"
android:background="?attr/selectableItemBackground">
<ImageView
android:id="@+id/icon_left"
android:layout_width="@dimen/map_button_shadow_width"
android:layout_height="@dimen/map_button_shadow_width"
android:visibility="invisible" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:textColor="@color/dashboard_blue"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="Van Gogh Museum" />
</LinearLayout>
<ImageView
android:id="@+id/icon_right"
android:layout_width="wrap_content"
android:layout_height="@dimen/map_button_shadow_width"
android:paddingEnd="@dimen/list_content_padding"
android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
android:paddingStart="@dimen/list_content_padding"
tools:src="@drawable/ic_action_filter" />
</LinearLayout>
<View
android:id="@+id/divider"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:background="?attr/dashboard_divider" />
</LinearLayout>
</LinearLayout>

View file

@ -29,6 +29,7 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;
import net.osmand.plus.R;
import net.osmand.plus.download.DownloadActivity;
import java.io.BufferedReader;
import java.io.File;
@ -128,6 +129,20 @@ public class AndroidUtils {
return DateFormat.getTimeFormat(ctx).format(new Date(time));
}
public static String formatSize(long sizeBytes) {
int sizeKb = (int) ((sizeBytes + 512) >> 10);
if (sizeKb > 0) {
if (sizeKb > 1 << 20) {
return DownloadActivity.formatGb.format(new Object[]{(float) sizeKb / (1 << 20)});
} else if (sizeBytes > (100 * (1 << 10))) {
return DownloadActivity.formatMb.format(new Object[]{(float) sizeBytes / (1 << 20)});
} else {
return DownloadActivity.formatKb.format(new Object[]{(float) sizeBytes / (1 << 10)});
}
}
return "";
}
public static View findParentViewById(View view, int id) {
ViewParent viewParent = view.getParent();

View file

@ -59,6 +59,10 @@ public class PicassoUtils {
}
}
public static long getDiskCacheSizeBytes() throws IOException {
return diskCache.size();
}
private static File createDefaultCacheDir(Context context) {
File cache = new File(context.getApplicationContext().getCacheDir(), PICASSO_CACHE);
if (!cache.exists()) {

View file

@ -418,7 +418,7 @@ public class MapMarkersHelper {
if (mapMarkersGroup.getId() == null || mapMarkersGroup.getName() == null) {
return;
}
createHeaderInGroup(mapMarkersGroup);
createHeadersInGroup(mapMarkersGroup);
int historyMarkersCount = mapMarkersGroup.getHistoryMarkers().size();
ShowHideHistoryButton showHideHistoryButton = mapMarkersGroup.getShowHideHistoryButton();
if (showHideHistoryButton != null) {
@ -460,15 +460,22 @@ public class MapMarkersHelper {
}
}
private void createHeaderInGroup(@NonNull MapMarkersGroup group) {
private void createHeadersInGroup(@NonNull MapMarkersGroup group) {
GroupHeader header = new GroupHeader();
CategoriesSubHeader categoriesSubHeader = new CategoriesSubHeader();
WikivoyageArticleSubHeader wikivoyageArticleSubHeader = new WikivoyageArticleSubHeader();
int type = group.getType();
if (type != -1) {
header.iconRes = type == MapMarkersGroup.FAVORITES_TYPE
? R.drawable.ic_action_fav_dark : R.drawable.ic_action_polygom_dark;
categoriesSubHeader.iconRes = R.drawable.ic_action_filter;
}
header.group = group;
categoriesSubHeader.group = group;
wikivoyageArticleSubHeader.group = group;
group.header = header;
group.categoriesSubHeader = categoriesSubHeader;
group.wikivoyageArticleSubHeader = wikivoyageArticleSubHeader;
}
private void removeMarkerFromGroup(MapMarker marker) {
@ -534,7 +541,7 @@ public class MapMarkersHelper {
if (search == null && selected.getGpxFile() != null && selected.getGpxFile().path != null) {
MapMarkersGroup group = createGPXMarkerGroup(new File(selected.getGpxFile().path));
group.disabled = true;
createHeaderInGroup(group);
createHeadersInGroup(group);
res.add(group);
}
}
@ -555,7 +562,7 @@ public class MapMarkersHelper {
if (search == null) {
MapMarkersGroup group = createGPXMarkerGroup(path);
group.disabled = true;
createHeaderInGroup(group);
createHeadersInGroup(group);
res.add(group);
}
}
@ -1212,10 +1219,14 @@ public class MapMarkersHelper {
private long creationDate;
private boolean disabled;
private boolean visible = true;
private boolean wasShown = false;
private boolean visibleUntilRestart;
private List<MapMarker> markers = new ArrayList<>();
private TravelArticle wikivoyageArticle;
// TODO should be removed from this class:
private GroupHeader header;
private CategoriesSubHeader categoriesSubHeader;
private WikivoyageArticleSubHeader wikivoyageArticleSubHeader;
private ShowHideHistoryButton showHideHistoryButton;
public MapMarkersGroup() {
@ -1236,6 +1247,14 @@ public class MapMarkersHelper {
return id;
}
public TravelArticle getWikivoyageArticle() {
return wikivoyageArticle;
}
public void setWikivoyageArticle(TravelArticle wikivoyageArticle) {
this.wikivoyageArticle = wikivoyageArticle;
}
public String getName() {
return name;
}
@ -1248,6 +1267,10 @@ public class MapMarkersHelper {
this.wptCategories = wptCategories;
}
public Set<String> getWptCategories() {
return wptCategories;
}
public boolean isDisabled() {
return disabled;
}
@ -1260,6 +1283,14 @@ public class MapMarkersHelper {
return visible;
}
public boolean wasShown() {
return wasShown;
}
public void setWasShown(boolean wasShown) {
this.wasShown = wasShown;
}
public void setVisibleUntilRestart(boolean visibleUntilRestart) {
this.visibleUntilRestart = visibleUntilRestart;
}
@ -1272,6 +1303,14 @@ public class MapMarkersHelper {
return header;
}
public CategoriesSubHeader getCategoriesSubHeader() {
return categoriesSubHeader;
}
public WikivoyageArticleSubHeader getWikivoyageArticleSubHeader() {
return wikivoyageArticleSubHeader;
}
public ShowHideHistoryButton getShowHideHistoryButton() {
return showHideHistoryButton;
}
@ -1323,6 +1362,32 @@ public class MapMarkersHelper {
}
}
public static class CategoriesSubHeader {
private int iconRes;
private MapMarkersGroup group;
public int getIconRes() {
return iconRes;
}
public MapMarkersGroup getGroup() {
return group;
}
}
public static class WikivoyageArticleSubHeader {
private int iconRes;
private MapMarkersGroup group;
public int getIconRes() {
return iconRes;
}
public MapMarkersGroup getGroup() {
return group;
}
}
public static class MapMarker implements LocationPoint {
private static int[] colors;

View file

@ -467,24 +467,12 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
public String getExtendedDescription(Context ctx) {
DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(ctx);
String date = dateFormat.format(file.lastModified());
int size = (int) ((file.length() + 512) >> 10);
String sz = "";
if (size > 0) {
if (size > 1 << 20) {
sz = DownloadActivity.formatGb.format(new Object[]{(float) size / (1 << 20)});
} else {
if (file.length() > (100 * (1 << 10))) {
sz = DownloadActivity.formatMb.format(new Object[]{(float) file.length() / (1 << 20)});
} else {
sz = DownloadActivity.formatKb.format(new Object[]{(float) file.length() / (1 << 10)});
}
}
}
String size = AndroidUtils.formatSize(file.length());
if (isPhoto()) {
return date + "" + sz;
return date + "" + size;
}
updateInternalDescription();
return date + "" + sz + "" + getDuration(ctx, false);
return date + "" + size + "" + getDuration(ctx, false);
}
public String getTypeWithDuration(Context ctx) {

View file

@ -32,19 +32,22 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee
public static final String TAG = "SelectWptCategoriesBottomSheetDialogFragment";
public static final String GPX_FILE_PATH_KEY = "gpx_file_path";
public static final String UPDATE_CATEGORIES_KEY = "update_categories";
private GPXFile gpxFile;
private Set<String> selectedCategories = new HashSet<>();
private List<BottomSheetItemWithCompoundButton> categoryItems = new ArrayList<>();
private boolean isUpdateMode =false;
@Override
public void createMenuItems(Bundle savedInstanceState) {
gpxFile = getGpxFile();
if (gpxFile == null) {
return;
}
isUpdateMode = getArguments().getBoolean(UPDATE_CATEGORIES_KEY);
items.add(new TitleItem(getGpxName(gpxFile)));
items.add(new DescriptionItem(getString(R.string.select_waypoints_category_description)));
@ -108,11 +111,35 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee
@Override
protected int getRightBottomButtonTextId() {
return R.string.shared_string_import;
if (isUpdateMode) {
return super.getRightBottomButtonTextId();
} else {
return R.string.shared_string_add;
}
}
@Override
protected int getDismissButtonTextId() {
if (isUpdateMode) {
return R.string.shared_string_update;
} else {
return super.getDismissButtonTextId();
}
}
protected void onDismissButtonClickAction() {
if (isUpdateMode) {
updateAddOrEnableGroupWptCategories();
}
}
@Override
protected void onRightBottomButtonClick() {
updateAddOrEnableGroupWptCategories();
dismiss();
}
private void updateAddOrEnableGroupWptCategories() {
OsmandApplication app = getMyApplication();
GpxSelectionHelper gpxSelectionHelper = app.getSelectedGpxHelper();
MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
@ -122,12 +149,11 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee
gpxSelectionHelper.selectGpxFile(gpxFile, true, false);
}
MapMarkersGroup group = mapMarkersHelper.getMarkersGroup(gpxFile);
if(group == null) {
if (group == null) {
group = mapMarkersHelper.addOrEnableGroup(gpxFile);
}
mapMarkersHelper.updateGroupWptCategories(group, selectedCategories);
dismiss();
mapMarkersHelper.runSynchronization(group);
}
private boolean isAllChecked() {

View file

@ -0,0 +1,25 @@
package net.osmand.plus.mapmarkers.adapters;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SwitchCompat;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.plus.R;
public class MapMarkerCategoriesViewHolder extends RecyclerView.ViewHolder {
final ImageView icon;
final TextView title;
final View divider;
public MapMarkerCategoriesViewHolder(View itemView) {
super(itemView);
icon = (ImageView) itemView.findViewById(R.id.icon_right);
title = (TextView) itemView.findViewById(R.id.title);
divider = itemView.findViewById(R.id.divider);
}
}

View file

@ -16,6 +16,7 @@ public class MapMarkerHeaderViewHolder extends RecyclerView.ViewHolder {
final TextView title;
final SwitchCompat disableGroupSwitch;
final View bottomShadow;
final View divider;
public MapMarkerHeaderViewHolder(View itemView) {
super(itemView);
@ -24,5 +25,6 @@ public class MapMarkerHeaderViewHolder extends RecyclerView.ViewHolder {
title = (TextView) itemView.findViewById(R.id.title);
disableGroupSwitch = (SwitchCompat) itemView.findViewById(R.id.disable_group_switch);
bottomShadow = itemView.findViewById(R.id.bottom_shadow);
divider = itemView.findViewById(R.id.divider);
}
}

View file

@ -0,0 +1,23 @@
package net.osmand.plus.mapmarkers.adapters;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.plus.R;
public class MapMarkerOpenWikivoyageArticleViewHolder extends RecyclerView.ViewHolder {
final ImageView icon;
final TextView title;
final View divider;
public MapMarkerOpenWikivoyageArticleViewHolder(View itemView) {
super(itemView);
icon = (ImageView) itemView.findViewById(R.id.icon_right);
title = (TextView) itemView.findViewById(R.id.title);
divider = itemView.findViewById(R.id.divider);
}
}

View file

@ -1,5 +1,6 @@
package net.osmand.plus.mapmarkers.adapters;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
@ -9,7 +10,9 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.ImageView;
import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.data.LatLon;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GpxSelectionHelper;
@ -25,6 +28,10 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.mapmarkers.SelectWptCategoriesBottomSheetDialogFragment;
import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
import net.osmand.plus.wikivoyage.data.TravelArticle;
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
import java.io.File;
import java.text.SimpleDateFormat;
@ -39,6 +46,8 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
private static final int HEADER_TYPE = 1;
private static final int MARKER_TYPE = 2;
private static final int SHOW_HIDE_HISTORY_TYPE = 3;
private static final int CATEGORIES_TYPE = 4;
private static final int WIKIVOYAGE_ARTICLE_TYPE = 5;
private static final int TODAY_HEADER = 56;
private static final int YESTERDAY_HEADER = 57;
@ -145,11 +154,45 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
} else {
GroupHeader header = group.getGroupHeader();
items.add(header);
if (!group.isDisabled()) {
if (group.getWptCategories() != null && !group.getWptCategories().isEmpty()) {
MapMarkersHelper.CategoriesSubHeader categoriesSubHeader = group.getCategoriesSubHeader();
items.add(categoriesSubHeader);
}
TravelDbHelper travelDbHelper = mapActivity.getMyApplication().getTravelDbHelper();
if (travelDbHelper.getSelectedTravelBook() != null) {
List<TravelArticle> savedArticles = travelDbHelper.getLocalDataHelper().getSavedArticles();
for (TravelArticle art : savedArticles) {
String gpxName = travelDbHelper.getGPXName(art);
File path = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_TRAVEL_DIR + gpxName);
if (path.getAbsolutePath().equals(group.getGpxPath())) {
MapMarkersHelper.WikivoyageArticleSubHeader wikivoyageArticleSubHeader = group.getWikivoyageArticleSubHeader();
items.add(wikivoyageArticleSubHeader);
group.setWikivoyageArticle(art);
}
}
}
}
if (group.getWptCategories() == null || group.getWptCategories().isEmpty()) {
helper.updateGroupWptCategories(group, getGpxFile(group.getGpxPath()).getPointsByCategories().keySet());
}
populateAdapterWithGroupMarkers(group, getItemCount());
}
}
}
private GPXFile getGpxFile(String filePath) {
if (filePath != null) {
OsmandApplication app = mapActivity.getMyApplication();
SelectedGpxFile selectedGpx = app.getSelectedGpxHelper().getSelectedFileByPath(filePath);
if (selectedGpx != null && selectedGpx.getGpxFile() != null) {
return selectedGpx.getGpxFile();
}
return GPXUtilities.loadGPXFile(app, new File(filePath));
}
return null;
}
private void populateAdapterWithGroupMarkers(MapMarkersGroup group, int position) {
if (position != RecyclerView.NO_POSITION) {
ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton();
@ -221,6 +264,12 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
} else if (viewType == SHOW_HIDE_HISTORY_TYPE) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_show_hide_history, viewGroup, false);
return new MapMarkersShowHideHistoryViewHolder(view);
} else if (viewType == CATEGORIES_TYPE) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_subheader, viewGroup, false);
return new MapMarkerCategoriesViewHolder(view);
}else if (viewType == WIKIVOYAGE_ARTICLE_TYPE) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_subheader, viewGroup, false);
return new MapMarkerOpenWikivoyageArticleViewHolder(view);
} else {
throw new IllegalArgumentException("Unsupported view type");
}
@ -391,8 +440,9 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
headerViewHolder.icon.setVisibility(View.VISIBLE);
headerViewHolder.iconSpace.setVisibility(View.GONE);
headerViewHolder.icon.setImageDrawable(iconsCache.getIcon(groupHeader.getIconRes(), R.color.divider_color));
boolean groupIsDisabled = group.isDisabled();
final boolean groupIsDisabled = group.isDisabled();
headerViewHolder.disableGroupSwitch.setVisibility(View.VISIBLE);
headerViewHolder.divider.setVisibility(group.getWptCategories().isEmpty() ? View.GONE : View.VISIBLE);
CompoundButton.OnCheckedChangeListener checkedChangeListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean enabled) {
@ -400,6 +450,17 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
final GPXFile[] gpxFile = new GPXFile[1];
boolean disabled = !enabled;
if (groupIsDisabled && !group.wasShown() && !group.getWptCategories().isEmpty()) {
group.setWasShown(true);
Bundle args = new Bundle();
args.putString(SelectWptCategoriesBottomSheetDialogFragment.GPX_FILE_PATH_KEY, group.getGpxPath());
args.putBoolean(SelectWptCategoriesBottomSheetDialogFragment.UPDATE_CATEGORIES_KEY, true);
SelectWptCategoriesBottomSheetDialogFragment fragment = new SelectWptCategoriesBottomSheetDialogFragment();
fragment.setArguments(args);
fragment.setUsedOnMap(false);
fragment.show(mapActivity.getSupportFragmentManager(), SelectWptCategoriesBottomSheetDialogFragment.TAG);
}
mapMarkersHelper.updateGroupDisabled(group, disabled);
if (group.getType() == MapMarkersGroup.GPX_TYPE) {
group.setVisibleUntilRestart(disabled);
@ -467,6 +528,49 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
notifyDataSetChanged();
}
});
} else if (holder instanceof MapMarkerCategoriesViewHolder) {
final MapMarkerCategoriesViewHolder categoriesViewHolder = (MapMarkerCategoriesViewHolder) holder;
final Object header = getItem(position);
if (header instanceof MapMarkersHelper.CategoriesSubHeader) {
final MapMarkersHelper.CategoriesSubHeader categoriesSubHeader = (MapMarkersHelper.CategoriesSubHeader) header;
final MapMarkersGroup group = categoriesSubHeader.getGroup();
categoriesViewHolder.icon.setImageDrawable(iconsCache.getIcon(categoriesSubHeader.getIconRes(), R.color.divider_color));
categoriesViewHolder.title.setText(group.getWptCategoriesString());
categoriesViewHolder.divider.setVisibility(View.VISIBLE);
categoriesViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!group.getWptCategories().isEmpty()) {
Bundle args = new Bundle();
args.putString(SelectWptCategoriesBottomSheetDialogFragment.GPX_FILE_PATH_KEY, group.getGpxPath());
args.putBoolean(SelectWptCategoriesBottomSheetDialogFragment.UPDATE_CATEGORIES_KEY, true);
SelectWptCategoriesBottomSheetDialogFragment fragment = new SelectWptCategoriesBottomSheetDialogFragment();
fragment.setArguments(args);
fragment.setUsedOnMap(false);
fragment.show(mapActivity.getSupportFragmentManager(), SelectWptCategoriesBottomSheetDialogFragment.TAG);
} else {
mapActivity.getMyApplication().getMapMarkersHelper().addOrEnableGpxGroup(new File(group.getGpxPath()));
}
}
});
}
} else if (holder instanceof MapMarkerOpenWikivoyageArticleViewHolder) {
final MapMarkerOpenWikivoyageArticleViewHolder wikivoyageArticleViewHolder = (MapMarkerOpenWikivoyageArticleViewHolder) holder;
final Object header = getItem(position);
final MapMarkersHelper.WikivoyageArticleSubHeader wikivoyageArticleSubHeader = (MapMarkersHelper.WikivoyageArticleSubHeader) header;
final MapMarkersGroup group = wikivoyageArticleSubHeader.getGroup();
wikivoyageArticleViewHolder.title.setText(R.string.context_menu_read_article);
wikivoyageArticleViewHolder.icon.setVisibility(View.INVISIBLE);
wikivoyageArticleViewHolder.divider.setVisibility(View.VISIBLE);
wikivoyageArticleViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
TravelArticle article = group.getWikivoyageArticle();
if (mapActivity.getSupportFragmentManager() != null && article != null) {
WikivoyageArticleDialogFragment.showInstance(app, mapActivity.getSupportFragmentManager(), article.getCityId(), article.getLang());
}
}
});
}
}
@ -490,6 +594,10 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
return HEADER_TYPE;
} else if (item instanceof ShowHideHistoryButton) {
return SHOW_HIDE_HISTORY_TYPE;
}else if (item instanceof MapMarkersHelper.CategoriesSubHeader) {
return CATEGORIES_TYPE;
}else if (item instanceof MapMarkersHelper.WikivoyageArticleSubHeader) {
return WIKIVOYAGE_ARTICLE_TYPE;
} else {
throw new IllegalArgumentException("Unsupported view type");
}

View file

@ -222,6 +222,14 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
} else if (requestCode == WikivoyageShowPicturesDialogFragment.SHOW_PICTURES_CHANGED_REQUEST_CODE) {
updateWebSettings();
populateArticle();
} else if (requestCode == WikivoyageArticleNavigationFragment.OPEN_ARTICLE_REQUEST_CODE) {
long cityId = data.getLongExtra(WikivoyageArticleNavigationFragment.CITY_ID_KEY, -1);
String selectedLang = data.getStringExtra(WikivoyageArticleNavigationFragment.SELECTED_LANG_KEY);
if (cityId != -1 && !TextUtils.isEmpty(selectedLang)) {
this.cityId = cityId;
this.selectedLang = selectedLang;
populateArticle();
}
}
}
@ -365,7 +373,10 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
sb.append(navBarString);
}
if (!TextUtils.isEmpty(current)) {
sb.append(" • <span class=\"nav-bar-current\">").append(current).append("</span>");
if (aggregatedPartOfArrayOrig.length > 1) {
sb.append("");
}
sb.append("<span class=\"nav-bar-current\">").append(current).append("</span>");
}
sb.append("</div>");
}
@ -440,10 +451,11 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
@JavascriptInterface
public void showNavigation() {
FragmentManager fm = getFragmentManager();
if (article == null || fm == null) {
if (article == null || fm == null || selectedLang == null) {
return;
}
WikivoyageArticleNavigationFragment.showInstance(fm, cityId, selectedLang);
WikivoyageArticleNavigationFragment.showInstance(fm,
WikivoyageArticleDialogFragment.this, cityId, selectedLang);
}
}
}

View file

@ -1,10 +1,12 @@
package net.osmand.plus.wikivoyage.article;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
@ -33,8 +35,8 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr
public static final String TAG = WikivoyageArticleNavigationFragment.class.getSimpleName();
private static final String CITY_ID_KEY = "city_id_key";
private static final String SELECTED_LANG_KEY = "selected_lang_key";
public static final String CITY_ID_KEY = "city_id_key";
public static final String SELECTED_LANG_KEY = "selected_lang_key";
public static final int OPEN_ARTICLE_REQUEST_CODE = 2;
@ -42,12 +44,18 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr
private long cityId = UNDEFINED;
private String selectedLang;
private TravelArticle article;
private List<String> parentsList;
private ExpandableListView expListView;
@Override
public void createMenuItems(Bundle savedInstanceState) {
Context ctx = getContext();
if (ctx == null) {
return;
}
if (savedInstanceState != null) {
selectedLang = savedInstanceState.getString(SELECTED_LANG_KEY);
cityId = savedInstanceState.getLong(CITY_ID_KEY);
@ -63,7 +71,7 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr
return;
}
TravelArticle article = getMyApplication().getTravelDbHelper().getArticle(cityId, selectedLang);
article = getMyApplication().getTravelDbHelper().getArticle(cityId, selectedLang);
if (article == null) {
return;
}
@ -73,11 +81,11 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr
items.add(new TitleItem(getString(R.string.shared_string_navigation)));
expListView = new ExpandableListView(getContext());
ExpandableListAdapter listAdapter = new ExpandableListAdapter(getContext(), navigationMap);
expListView = new ExpandableListView(ctx);
final ExpandableListAdapter listAdapter = new ExpandableListAdapter(ctx, navigationMap);
expListView.setAdapter(listAdapter);
Drawable transparent = ContextCompat.getDrawable(getContext(), R.color.color_transparent);
Drawable transparent = ContextCompat.getDrawable(ctx, R.color.color_transparent);
expListView.setDivider(transparent);
expListView.setGroupIndicator(transparent);
expListView.setSelector(transparent);
@ -90,6 +98,8 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
WikivoyageSearchResult articleItem = listAdapter.getArticleItem(groupPosition, childPosition);
sendResults(articleItem.getCityId());
dismiss();
return true;
}
@ -97,12 +107,16 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr
expListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
dismiss();
if (!expListView.isGroupExpanded(groupPosition)) {
expListView.expandGroup(groupPosition);
} else {
expListView.collapseGroup(groupPosition);
}
return true;
}
});
LinearLayout container = new LinearLayout(getContext());
LinearLayout container = new LinearLayout(ctx);
container.addView(expListView);
items.add(new SimpleBottomSheetItem.Builder().setCustomView(container).create());
@ -124,14 +138,28 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr
return false;
}
private void sendResults(long cityId) {
Fragment fragment = getTargetFragment();
if (fragment != null) {
Intent intent = new Intent();
intent.putExtra(CITY_ID_KEY, cityId);
intent.putExtra(SELECTED_LANG_KEY, selectedLang);
fragment.onActivityResult(getTargetRequestCode(), OPEN_ARTICLE_REQUEST_CODE, intent);
}
}
public static boolean showInstance(@NonNull FragmentManager fm,
@Nullable Fragment targetFragment,
long cityId,
@Nullable String selectedLang) {
@NonNull String selectedLang) {
try {
Bundle args = new Bundle();
args.putLong(CITY_ID_KEY, cityId);
args.putString(SELECTED_LANG_KEY, selectedLang);
WikivoyageArticleNavigationFragment fragment = new WikivoyageArticleNavigationFragment();
if (targetFragment != null) {
fragment.setTargetFragment(targetFragment, OPEN_ARTICLE_REQUEST_CODE);
}
fragment.setArguments(args);
fragment.show(fm, TAG);
return true;
@ -166,7 +194,7 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr
return navigationMap.get(headers.get(groupPosition));
}
private WikivoyageSearchResult getArticleItem(int groupPosition, int childPosititon) {
public WikivoyageSearchResult getArticleItem(int groupPosition, int childPosititon) {
return navigationMap.get(headers.get(groupPosition)).get(childPosititon);
}
@ -204,14 +232,15 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
WikivoyageSearchResult articleItem = getArticleItem(groupPosition, childPosition);
String childText = articleItem.getArticleTitles().get(0);
boolean selected = cityId == articleItem.getCityId() || parentsList.contains(childText);
String childTitle = articleItem.getArticleTitles().get(0);
boolean selected = cityId == articleItem.getCityId() || parentsList.contains(childTitle);
if (convertView == null) {
convertView = LayoutInflater.from(context)
.inflate(R.layout.wikivoyage_contents_list_item, parent, false);
}
TextView txtListChild = (TextView) convertView.findViewById(R.id.item_label);
txtListChild.setText(childText);
txtListChild.setText(childTitle);
if (selected) {
txtListChild.setTextColor(ContextCompat.getColor(context, nightMode
? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light));
@ -230,14 +259,14 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr
@Override
public View getGroupView(final int groupPosition, final boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
boolean selected = parentsList.contains(headerTitle);
String groupTitle = (String) getGroup(groupPosition);
boolean selected = parentsList.contains(groupTitle) || article.getTitle().equals(groupTitle);
if (convertView == null) {
convertView = LayoutInflater.from(context)
.inflate(R.layout.wikivoyage_contents_list_item, parent, false);
}
TextView lblListHeader = (TextView) convertView.findViewById(R.id.item_label);
lblListHeader.setText(headerTitle);
lblListHeader.setText(groupTitle);
if (selected) {
lblListHeader.setTextColor(ContextCompat.getColor(context, nightMode
? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light));

View file

@ -24,6 +24,7 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
@ -298,23 +299,23 @@ public class TravelDbHelper {
cursor.close();
}
LinkedHashMap<String, List<WikivoyageSearchResult>> res = new LinkedHashMap<>();
if (navMap.keySet().size() > 1 && parts != null && parts.length > 0) {
for (String part : parts) {
List<WikivoyageSearchResult> partsList = navMap.get(part);
if (partsList != null) {
Collections.sort(partsList, new Comparator<WikivoyageSearchResult>() {
@Override
public int compare(WikivoyageSearchResult o1, WikivoyageSearchResult o2) {
return collator.compare(o1.articleTitles.get(0), o2.articleTitles.get(0));
}
});
res.put(part, partsList);
}
}
} else {
res.putAll(navMap);
List<String> partsList = new ArrayList<>();
if (parts != null) {
partsList.addAll(Arrays.asList(parts));
}
partsList.add(title);
for (String part : partsList) {
List<WikivoyageSearchResult> results = navMap.get(part);
if (results != null) {
Collections.sort(results, new Comparator<WikivoyageSearchResult>() {
@Override
public int compare(WikivoyageSearchResult o1, WikivoyageSearchResult o2) {
return collator.compare(o1.articleTitles.get(0), o2.articleTitles.get(0));
}
});
res.put(part, results);
}
}
return res;
}

View file

@ -12,6 +12,7 @@ import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import net.osmand.AndroidUtils;
import net.osmand.PicassoUtils;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
@ -27,6 +28,7 @@ import net.osmand.plus.wikivoyage.data.TravelDbHelper;
import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
@ -93,7 +95,7 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
BaseBottomSheetItem clearCacheItem = new BottomSheetItemWithDescription.Builder()
.setDescription(getString(R.string.shared_string_clear))
.setDescriptionColorId(nightMode ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light)
.setTitle(getString(R.string.images_cache) + ": ???") // TODO : show images cache size
.setTitle(getString(R.string.images_cache) + getCacheSize())
.setLayoutId(R.layout.bottom_sheet_item_with_right_descr)
.setOnClickListener(new View.OnClickListener() {
@Override
@ -156,4 +158,14 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
.setNegativeButton(R.string.shared_string_dismiss, null)
.show();
}
private String getCacheSize() {
long cacheBytes = 0;
try {
cacheBytes += PicassoUtils.getDiskCacheSizeBytes();
} catch (IOException e) {
e.printStackTrace();
}
return ": " + AndroidUtils.formatSize(cacheBytes);
}
}