Fix wikivoyage navigation
This commit is contained in:
parent
14b027d2a6
commit
43c6a37ae5
3 changed files with 77 additions and 35 deletions
|
@ -222,6 +222,14 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
|
||||||
} else if (requestCode == WikivoyageShowPicturesDialogFragment.SHOW_PICTURES_CHANGED_REQUEST_CODE) {
|
} else if (requestCode == WikivoyageShowPicturesDialogFragment.SHOW_PICTURES_CHANGED_REQUEST_CODE) {
|
||||||
updateWebSettings();
|
updateWebSettings();
|
||||||
populateArticle();
|
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);
|
sb.append(navBarString);
|
||||||
}
|
}
|
||||||
if (!TextUtils.isEmpty(current)) {
|
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>");
|
sb.append("</div>");
|
||||||
}
|
}
|
||||||
|
@ -440,10 +451,11 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public void showNavigation() {
|
public void showNavigation() {
|
||||||
FragmentManager fm = getFragmentManager();
|
FragmentManager fm = getFragmentManager();
|
||||||
if (article == null || fm == null) {
|
if (article == null || fm == null || selectedLang == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
WikivoyageArticleNavigationFragment.showInstance(fm, cityId, selectedLang);
|
WikivoyageArticleNavigationFragment.showInstance(fm,
|
||||||
|
WikivoyageArticleDialogFragment.this, cityId, selectedLang);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package net.osmand.plus.wikivoyage.article;
|
package net.osmand.plus.wikivoyage.article;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
@ -33,8 +35,8 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr
|
||||||
|
|
||||||
public static final String TAG = WikivoyageArticleNavigationFragment.class.getSimpleName();
|
public static final String TAG = WikivoyageArticleNavigationFragment.class.getSimpleName();
|
||||||
|
|
||||||
private static final String CITY_ID_KEY = "city_id_key";
|
public static final String CITY_ID_KEY = "city_id_key";
|
||||||
private static final String SELECTED_LANG_KEY = "selected_lang_key";
|
public static final String SELECTED_LANG_KEY = "selected_lang_key";
|
||||||
|
|
||||||
public static final int OPEN_ARTICLE_REQUEST_CODE = 2;
|
public static final int OPEN_ARTICLE_REQUEST_CODE = 2;
|
||||||
|
|
||||||
|
@ -42,12 +44,18 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr
|
||||||
|
|
||||||
private long cityId = UNDEFINED;
|
private long cityId = UNDEFINED;
|
||||||
private String selectedLang;
|
private String selectedLang;
|
||||||
|
private TravelArticle article;
|
||||||
private List<String> parentsList;
|
private List<String> parentsList;
|
||||||
|
|
||||||
private ExpandableListView expListView;
|
private ExpandableListView expListView;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createMenuItems(Bundle savedInstanceState) {
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
|
Context ctx = getContext();
|
||||||
|
if (ctx == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
selectedLang = savedInstanceState.getString(SELECTED_LANG_KEY);
|
selectedLang = savedInstanceState.getString(SELECTED_LANG_KEY);
|
||||||
cityId = savedInstanceState.getLong(CITY_ID_KEY);
|
cityId = savedInstanceState.getLong(CITY_ID_KEY);
|
||||||
|
@ -63,7 +71,7 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TravelArticle article = getMyApplication().getTravelDbHelper().getArticle(cityId, selectedLang);
|
article = getMyApplication().getTravelDbHelper().getArticle(cityId, selectedLang);
|
||||||
if (article == null) {
|
if (article == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -73,11 +81,11 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr
|
||||||
|
|
||||||
items.add(new TitleItem(getString(R.string.shared_string_navigation)));
|
items.add(new TitleItem(getString(R.string.shared_string_navigation)));
|
||||||
|
|
||||||
expListView = new ExpandableListView(getContext());
|
expListView = new ExpandableListView(ctx);
|
||||||
ExpandableListAdapter listAdapter = new ExpandableListAdapter(getContext(), navigationMap);
|
final ExpandableListAdapter listAdapter = new ExpandableListAdapter(ctx, navigationMap);
|
||||||
|
|
||||||
expListView.setAdapter(listAdapter);
|
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.setDivider(transparent);
|
||||||
expListView.setGroupIndicator(transparent);
|
expListView.setGroupIndicator(transparent);
|
||||||
expListView.setSelector(transparent);
|
expListView.setSelector(transparent);
|
||||||
|
@ -90,6 +98,8 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr
|
||||||
@Override
|
@Override
|
||||||
public boolean onChildClick(ExpandableListView parent, View v,
|
public boolean onChildClick(ExpandableListView parent, View v,
|
||||||
int groupPosition, int childPosition, long id) {
|
int groupPosition, int childPosition, long id) {
|
||||||
|
WikivoyageSearchResult articleItem = listAdapter.getArticleItem(groupPosition, childPosition);
|
||||||
|
sendResults(articleItem.getCityId());
|
||||||
dismiss();
|
dismiss();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -97,12 +107,16 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr
|
||||||
expListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
|
expListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
LinearLayout container = new LinearLayout(getContext());
|
LinearLayout container = new LinearLayout(ctx);
|
||||||
container.addView(expListView);
|
container.addView(expListView);
|
||||||
|
|
||||||
items.add(new SimpleBottomSheetItem.Builder().setCustomView(container).create());
|
items.add(new SimpleBottomSheetItem.Builder().setCustomView(container).create());
|
||||||
|
@ -124,14 +138,28 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr
|
||||||
return false;
|
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,
|
public static boolean showInstance(@NonNull FragmentManager fm,
|
||||||
|
@Nullable Fragment targetFragment,
|
||||||
long cityId,
|
long cityId,
|
||||||
@Nullable String selectedLang) {
|
@NonNull String selectedLang) {
|
||||||
try {
|
try {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putLong(CITY_ID_KEY, cityId);
|
args.putLong(CITY_ID_KEY, cityId);
|
||||||
args.putString(SELECTED_LANG_KEY, selectedLang);
|
args.putString(SELECTED_LANG_KEY, selectedLang);
|
||||||
WikivoyageArticleNavigationFragment fragment = new WikivoyageArticleNavigationFragment();
|
WikivoyageArticleNavigationFragment fragment = new WikivoyageArticleNavigationFragment();
|
||||||
|
if (targetFragment != null) {
|
||||||
|
fragment.setTargetFragment(targetFragment, OPEN_ARTICLE_REQUEST_CODE);
|
||||||
|
}
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
fragment.show(fm, TAG);
|
fragment.show(fm, TAG);
|
||||||
return true;
|
return true;
|
||||||
|
@ -166,7 +194,7 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr
|
||||||
return navigationMap.get(headers.get(groupPosition));
|
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);
|
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,
|
public View getChildView(int groupPosition, final int childPosition,
|
||||||
boolean isLastChild, View convertView, ViewGroup parent) {
|
boolean isLastChild, View convertView, ViewGroup parent) {
|
||||||
WikivoyageSearchResult articleItem = getArticleItem(groupPosition, childPosition);
|
WikivoyageSearchResult articleItem = getArticleItem(groupPosition, childPosition);
|
||||||
String childText = articleItem.getArticleTitles().get(0);
|
String childTitle = articleItem.getArticleTitles().get(0);
|
||||||
boolean selected = cityId == articleItem.getCityId() || parentsList.contains(childText);
|
boolean selected = cityId == articleItem.getCityId() || parentsList.contains(childTitle);
|
||||||
|
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
convertView = LayoutInflater.from(context)
|
convertView = LayoutInflater.from(context)
|
||||||
.inflate(R.layout.wikivoyage_contents_list_item, parent, false);
|
.inflate(R.layout.wikivoyage_contents_list_item, parent, false);
|
||||||
}
|
}
|
||||||
TextView txtListChild = (TextView) convertView.findViewById(R.id.item_label);
|
TextView txtListChild = (TextView) convertView.findViewById(R.id.item_label);
|
||||||
txtListChild.setText(childText);
|
txtListChild.setText(childTitle);
|
||||||
if (selected) {
|
if (selected) {
|
||||||
txtListChild.setTextColor(ContextCompat.getColor(context, nightMode
|
txtListChild.setTextColor(ContextCompat.getColor(context, nightMode
|
||||||
? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light));
|
? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light));
|
||||||
|
@ -230,14 +259,14 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr
|
||||||
@Override
|
@Override
|
||||||
public View getGroupView(final int groupPosition, final boolean isExpanded,
|
public View getGroupView(final int groupPosition, final boolean isExpanded,
|
||||||
View convertView, ViewGroup parent) {
|
View convertView, ViewGroup parent) {
|
||||||
String headerTitle = (String) getGroup(groupPosition);
|
String groupTitle = (String) getGroup(groupPosition);
|
||||||
boolean selected = parentsList.contains(headerTitle);
|
boolean selected = parentsList.contains(groupTitle) || article.getTitle().equals(groupTitle);
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
convertView = LayoutInflater.from(context)
|
convertView = LayoutInflater.from(context)
|
||||||
.inflate(R.layout.wikivoyage_contents_list_item, parent, false);
|
.inflate(R.layout.wikivoyage_contents_list_item, parent, false);
|
||||||
}
|
}
|
||||||
TextView lblListHeader = (TextView) convertView.findViewById(R.id.item_label);
|
TextView lblListHeader = (TextView) convertView.findViewById(R.id.item_label);
|
||||||
lblListHeader.setText(headerTitle);
|
lblListHeader.setText(groupTitle);
|
||||||
if (selected) {
|
if (selected) {
|
||||||
lblListHeader.setTextColor(ContextCompat.getColor(context, nightMode
|
lblListHeader.setTextColor(ContextCompat.getColor(context, nightMode
|
||||||
? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light));
|
? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light));
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -298,23 +299,23 @@ public class TravelDbHelper {
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
LinkedHashMap<String, List<WikivoyageSearchResult>> res = new LinkedHashMap<>();
|
LinkedHashMap<String, List<WikivoyageSearchResult>> res = new LinkedHashMap<>();
|
||||||
if (navMap.keySet().size() > 1 && parts != null && parts.length > 0) {
|
List<String> partsList = new ArrayList<>();
|
||||||
for (String part : parts) {
|
if (parts != null) {
|
||||||
List<WikivoyageSearchResult> partsList = navMap.get(part);
|
partsList.addAll(Arrays.asList(parts));
|
||||||
if (partsList != null) {
|
}
|
||||||
Collections.sort(partsList, new Comparator<WikivoyageSearchResult>() {
|
partsList.add(title);
|
||||||
@Override
|
for (String part : partsList) {
|
||||||
public int compare(WikivoyageSearchResult o1, WikivoyageSearchResult o2) {
|
List<WikivoyageSearchResult> results = navMap.get(part);
|
||||||
return collator.compare(o1.articleTitles.get(0), o2.articleTitles.get(0));
|
if (results != null) {
|
||||||
}
|
Collections.sort(results, new Comparator<WikivoyageSearchResult>() {
|
||||||
});
|
@Override
|
||||||
res.put(part, partsList);
|
public int compare(WikivoyageSearchResult o1, WikivoyageSearchResult o2) {
|
||||||
}
|
return collator.compare(o1.articleTitles.get(0), o2.articleTitles.get(0));
|
||||||
}
|
}
|
||||||
} else {
|
});
|
||||||
res.putAll(navMap);
|
res.put(part, results);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue