Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-10-06 16:15:11 +02:00
commit d562346d3b
5 changed files with 396 additions and 14 deletions

View file

@ -137,7 +137,7 @@ public class ItemsListBuilder {
case TTS: case TTS:
return app.getResources().getString(R.string.index_name_tts_voice); return app.getResources().getString(R.string.index_name_tts_voice);
default: default:
return null; return "";
} }
} }
@ -148,7 +148,7 @@ public class ItemsListBuilder {
case TTS: case TTS:
return voiceTTSItems; return voiceTTSItems;
default: default:
return null; return new LinkedList<>();
} }
} }

View file

@ -156,15 +156,13 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
private class RegionsItemsAdapter extends OsmandBaseExpandableListAdapter { private class RegionsItemsAdapter extends OsmandBaseExpandableListAdapter {
private Map<String, List> data = new LinkedHashMap<>(); private Map<String, List<Object>> data = new LinkedHashMap<>();
private List<String> sections = new LinkedList<>(); private List<String> sections = new LinkedList<>();
private Context ctx;
private boolean srtmDisabled; private boolean srtmDisabled;
private boolean nauticalPluginDisabled; private boolean nauticalPluginDisabled;
private boolean freeVersion; private boolean freeVersion;
public RegionsItemsAdapter(Context ctx) { public RegionsItemsAdapter(Context ctx) {
this.ctx = ctx;
srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null; srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null;
nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null; nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null;
freeVersion = Version.isFreeVersion(getMyApplication()); freeVersion = Version.isFreeVersion(getMyApplication());
@ -183,7 +181,7 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
sections.add(section); sections.add(section);
} }
if (!data.containsKey(section)) { if (!data.containsKey(section)) {
data.put(section, new ArrayList()); data.put(section, new ArrayList<>());
} }
data.get(section).addAll(list); data.get(section).addAll(list);
} }

View file

@ -1,6 +1,134 @@
package net.osmand.plus.download.items; package net.osmand.plus.download.items;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class VoiceDialogFragment { import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.items.ItemsListBuilder.VoicePromptsType;
import net.osmand.plus.download.newimplementation.DownloadsUiHelper;
import org.apache.commons.logging.Log;
public class VoiceDialogFragment extends DialogFragment {
private static final Log LOG = PlatformUtil.getLog(VoiceDialogFragment.class);
public static final String TAG = "VoiceDialogFragment";
private static final String VOICE_PROMPT_TYPE_DLG_KEY = "voice_prompt_type_dlg_key";
private VoicePromptsType voicePromptsType = VoicePromptsType.NONE;
private DownloadsUiHelper.MapDownloadListener mProgressListener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean isLightTheme = ((OsmandApplication) getActivity().getApplication())
.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme;
setStyle(STYLE_NO_FRAME, themeId);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.maps_in_category_fragment, container, false);
String value = null;
try {
if (savedInstanceState != null) {
value = savedInstanceState.getString(VOICE_PROMPT_TYPE_DLG_KEY);
if (value != null) {
voicePromptsType = VoicePromptsType.valueOf(value);
}
}
if (voicePromptsType == VoicePromptsType.NONE) {
value = getArguments().getString(VOICE_PROMPT_TYPE_DLG_KEY);
if (value != null) {
voicePromptsType = VoicePromptsType.valueOf(value);
}
}
} catch (IllegalArgumentException e) {
LOG.warn("VOICE_PROMPT_TYPE_DLG_KEY=" + value);
}
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
if (voicePromptsType != VoicePromptsType.NONE) {
Fragment fragment = getChildFragmentManager().findFragmentById(R.id.fragmentContainer);
if (fragment == null) {
getChildFragmentManager().beginTransaction().add(R.id.fragmentContainer,
VoiceItemsFragment.createInstance(voicePromptsType)).commit();
}
ItemsListBuilder builder = getDownloadActivity().getItemsBuilder();
toolbar.setTitle(builder.getVoicePromtName(voicePromptsType));
}
DownloadsUiHelper.initFreeVersionBanner(view, getMyApplication(),
getResources());
mProgressListener = new DownloadsUiHelper.MapDownloadListener(view, getResources()){
@Override
public void onProgressUpdate(int progressPercentage, int activeTasks) {
super.onProgressUpdate(progressPercentage, activeTasks);
}
@Override
public void onFinished() {
super.onFinished();
DownloadsUiHelper.initFreeVersionBanner(view,
getMyApplication(), getResources());
}
};
return view;
}
@Override
public void onResume() {
super.onResume();
getDownloadActivity().setOnProgressUpdateListener(mProgressListener);
}
@Override
public void onPause() {
super.onPause();
getDownloadActivity().setOnProgressUpdateListener(null);
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putString(VOICE_PROMPT_TYPE_DLG_KEY, voicePromptsType.name());
super.onSaveInstanceState(outState);
}
private OsmandApplication getMyApplication() {
return (OsmandApplication) getActivity().getApplication();
}
private DownloadActivity getDownloadActivity() {
return (DownloadActivity) getActivity();
}
public static VoiceDialogFragment createInstance(VoicePromptsType voicePromptsType) {
Bundle bundle = new Bundle();
bundle.putString(VOICE_PROMPT_TYPE_DLG_KEY, voicePromptsType.name());
VoiceDialogFragment fragment = new VoiceDialogFragment();
fragment.setArguments(bundle);
return fragment;
}
} }

View file

@ -0,0 +1,249 @@
package net.osmand.plus.download.items;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;
import android.widget.TextView;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.WorldRegion;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.download.BaseDownloadActivity;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.download.items.ItemsListBuilder.VoicePromptsType;
import org.apache.commons.logging.Log;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class VoiceItemsFragment extends OsmandExpandableListFragment {
public static final String TAG = "VoiceItemsFragment";
private static final Log LOG = PlatformUtil.getLog(VoiceItemsFragment.class);
private static final String VOICE_PROMPT_TYPE_KEY = "voice_prompt_type_key";
private VoicePromptsType voicePromptsType = VoicePromptsType.NONE;
private VoiceItemsAdapter listAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.download_items_fragment, container, false);
String value = null;
try {
if (savedInstanceState != null) {
value = savedInstanceState.getString(VOICE_PROMPT_TYPE_KEY);
if (value != null) {
voicePromptsType = VoicePromptsType.valueOf(value);
}
}
if (voicePromptsType == VoicePromptsType.NONE) {
value = getArguments().getString(VOICE_PROMPT_TYPE_KEY);
if (value != null) {
voicePromptsType = VoicePromptsType.valueOf(value);
}
}
} catch (IllegalArgumentException e) {
LOG.warn("VOICE_PROMPT_TYPE_KEY=" + value);
}
ExpandableListView listView = (ExpandableListView) view.findViewById(android.R.id.list);
listAdapter = new VoiceItemsAdapter(getActivity());
listView.setAdapter(listAdapter);
setListView(listView);
if (voicePromptsType != VoicePromptsType.NONE) {
ItemsListBuilder builder = getDownloadActivity().getItemsBuilder();
if (builder != null) {
fillVoiceItemsAdapter(builder);
listAdapter.notifyDataSetChanged();
expandAllGroups();
}
}
return view;
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putString(VOICE_PROMPT_TYPE_KEY, voicePromptsType.name());
super.onSaveInstanceState(outState);
}
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
Object obj = listAdapter.getChild(groupPosition, childPosition);
if (((ItemViewHolder) v.getTag()).isItemAvailable()) {
IndexItem indexItem = (IndexItem) obj;
((BaseDownloadActivity) getActivity())
.startDownload(indexItem);
return true;
} else {
return false;
}
}
private void expandAllGroups() {
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
getExpandableListView().expandGroup(i);
}
}
public OsmandApplication getMyApplication() {
return (OsmandApplication) getActivity().getApplication();
}
private void fillVoiceItemsAdapter(ItemsListBuilder builder) {
if (listAdapter != null) {
listAdapter.clear();
if (builder.getVoicePromptsItems(voicePromptsType).size() > 0) {
String sectionTitle = "Voice prompts";
listAdapter.add(sectionTitle, builder.getVoicePromptsItems(voicePromptsType));
}
}
}
private DownloadActivity getDownloadActivity() {
return (DownloadActivity) getActivity();
}
public static VoiceItemsFragment createInstance(VoicePromptsType voicePromptsType) {
Bundle bundle = new Bundle();
bundle.putString(VOICE_PROMPT_TYPE_KEY, voicePromptsType.name());
VoiceItemsFragment fragment = new VoiceItemsFragment();
fragment.setArguments(bundle);
return fragment;
}
private class VoiceItemsAdapter extends OsmandBaseExpandableListAdapter {
private Map<String, List<Object>> data = new LinkedHashMap<>();
private List<String> sections = new LinkedList<>();
public VoiceItemsAdapter(Context ctx) {
TypedArray ta = ctx.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
ta.recycle();
}
public void clear() {
data.clear();
sections.clear();
notifyDataSetChanged();
}
public void add(String section, List list) {
if (!sections.contains(section)) {
sections.add(section);
}
if (!data.containsKey(section)) {
data.put(section, new ArrayList<>());
}
data.get(section).addAll(list);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
String section = sections.get(groupPosition);
return data.get(section).get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return groupPosition * 10000 + childPosition;
}
@Override
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final Object child = getChild(groupPosition, childPosition);
ItemViewHolder viewHolder;
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.two_line_with_images_list_item, parent, false);
viewHolder = new ItemViewHolder(convertView);
convertView.setTag(viewHolder);
} else {
viewHolder = (ItemViewHolder) convertView.getTag();
}
IndexItem item = (IndexItem) child;
viewHolder.bindIndexItem(item, getDownloadActivity(), true, false);
return convertView;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View v = convertView;
String section = getGroup(groupPosition);
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getDownloadActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.download_item_list_section, parent, false);
}
TextView nameView = ((TextView) v.findViewById(R.id.section_name));
nameView.setText(section);
v.setOnClickListener(null);
TypedValue typedValue = new TypedValue();
Resources.Theme theme = getActivity().getTheme();
theme.resolveAttribute(R.attr.ctx_menu_info_view_bg, typedValue, true);
v.setBackgroundColor(typedValue.data);
return v;
}
@Override
public int getChildrenCount(int groupPosition) {
String section = sections.get(groupPosition);
return data.get(section).size();
}
@Override
public String getGroup(int groupPosition) {
return sections.get(groupPosition);
}
@Override
public int getGroupCount() {
return sections.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
}

View file

@ -15,6 +15,7 @@ import net.osmand.plus.WorldRegion;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment; import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.items.ItemsListBuilder.VoicePromptsType;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.srtmplugin.SRTMPlugin;
@ -105,12 +106,12 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
int unusedSubIndex = 0; int unusedSubIndex = 0;
List<String> voicePromptsItems = new LinkedList<>(); List<String> voicePromptsItems = new LinkedList<>();
if (!builder.isVoicePromptsItemsEmpty(ItemsListBuilder.VoicePromptsType.RECORDED)) { if (!builder.isVoicePromptsItemsEmpty(VoicePromptsType.RECORDED)) {
voicePromptsItems.add(builder.getVoicePromtName(ItemsListBuilder.VoicePromptsType.RECORDED)); voicePromptsItems.add(builder.getVoicePromtName(VoicePromptsType.RECORDED));
voicePromptsItemsRecordedSubIndex = unusedSubIndex++; voicePromptsItemsRecordedSubIndex = unusedSubIndex++;
} }
if (!builder.isVoicePromptsItemsEmpty(ItemsListBuilder.VoicePromptsType.TTS)) { if (!builder.isVoicePromptsItemsEmpty(VoicePromptsType.TTS)) {
voicePromptsItems.add(builder.getVoicePromtName(ItemsListBuilder.VoicePromptsType.TTS)); voicePromptsItems.add(builder.getVoicePromtName(VoicePromptsType.TTS));
voicePromptsItemsTTSSubIndex = unusedSubIndex; voicePromptsItemsTTSSubIndex = unusedSubIndex;
} }
if (!voicePromptsItems.isEmpty()) { if (!voicePromptsItems.isEmpty()) {
@ -129,7 +130,13 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
((DownloadActivity)getActivity()).showDialog(getActivity(), RegionDialogFragment.createInstance(region.getRegionId())); ((DownloadActivity)getActivity()).showDialog(getActivity(), RegionDialogFragment.createInstance(region.getRegionId()));
return true; return true;
} else if (groupPosition == voicePromptsIndex) { } else if (groupPosition == voicePromptsIndex) {
// if (childPosition == voicePromptsItemsRecordedSubIndex) {
((DownloadActivity)getActivity()).showDialog(getActivity(),
VoiceDialogFragment.createInstance(VoicePromptsType.RECORDED));
} else {
((DownloadActivity) getActivity()).showDialog(getActivity(),
VoiceDialogFragment.createInstance(VoicePromptsType.TTS));
}
} }
return false; return false;
} }
@ -166,7 +173,7 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
private class WorldItemsAdapter extends OsmandBaseExpandableListAdapter { private class WorldItemsAdapter extends OsmandBaseExpandableListAdapter {
private Map<String, List> data = new LinkedHashMap<>(); private Map<String, List<Object>> data = new LinkedHashMap<>();
private List<String> sections = new LinkedList<>(); private List<String> sections = new LinkedList<>();
private Context ctx; private Context ctx;
private boolean srtmDisabled; private boolean srtmDisabled;
@ -197,7 +204,7 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
sections.add(section); sections.add(section);
} }
if (!data.containsKey(section)) { if (!data.containsKey(section)) {
data.put(section, new ArrayList()); data.put(section, new ArrayList<>());
} }
data.get(section).addAll(list); data.get(section).addAll(list);
} }