Help menu finalized.

This commit is contained in:
GaidamakUA 2016-04-28 18:40:00 +03:00
parent d90577b8bb
commit 89a8357cfc

View file

@ -30,6 +30,7 @@ public class HelpActivity extends OsmandActionBarActivity implements AdapterView
// public static final String DIALOG = "dialog";
@IdRes
public static final String OSMAND_POLL_HTML = "http://osmand.net/android-poll.html";
public static final int NULL_ID = -1;
private ArrayAdapter<ContextMenuItem> mAdapter;
//public static final String OSMAND_MAP_LEGEND = "http://osmand.net/help/map-legend_default.png";
@ -43,27 +44,22 @@ public class HelpActivity extends OsmandActionBarActivity implements AdapterView
ContextMenuAdapter contextMenuAdapter = new ContextMenuAdapter();
contextMenuAdapter.setDefaultLayoutId(R.layout.two_line_with_images_list_item);
contextMenuAdapter.addItem(createCategory(R.string.begin_with_osmand_menu_group));
createBeginWithOsmandItems(contextMenuAdapter);
contextMenuAdapter.addItem(createCategory(R.string.features_menu_group));
createFeaturesItems(contextMenuAdapter);
contextMenuAdapter.addItem(createCategory(R.string.plugins_menu_group));
createPluginsItems(contextMenuAdapter);
contextMenuAdapter.addItem(createCategory(R.string.help_us_to_improve_menu_group));
createHelpUsToImproveItems(contextMenuAdapter);
contextMenuAdapter.addItem(createCategory(R.string.other_menu_group));
createOtherItems(contextMenuAdapter);
contextMenuAdapter.addItem(createCategory(R.string.follow_us));
createSocialNetworksItems(contextMenuAdapter);
mAdapter = contextMenuAdapter.createListAdapter(this, getMyApplication().getSettings().isLightContent());
boolean lightContent = getMyApplication().getSettings().isLightContent();
mAdapter = contextMenuAdapter.createListAdapter(this, lightContent);
ListView listView = (ListView) findViewById(android.R.id.list);
listView.setAdapter(mAdapter);
listView.setOnItemClickListener(this);
Drawable dividerDrawable = new ColorDrawable(ContextCompat.getColor(this,
getMyApplication().getSettings().isLightContent() ?
R.color.icon_color_light : R.color.dialog_inactive_text_color_dark));
int dividerColor = lightContent ? R.color.icon_color_light : R.color.dialog_inactive_text_color_dark;
Drawable dividerDrawable = new ColorDrawable(ContextCompat.getColor(this, dividerColor));
listView.setDivider(dividerDrawable);
listView.setDividerHeight(AndroidUtils.dpToPx(this, 1f));
@ -71,6 +67,37 @@ public class HelpActivity extends OsmandActionBarActivity implements AdapterView
setupHomeButton();
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ContextMenuAdapter.ItemClickListener listener =
mAdapter.getItem(position).getItemClickListener();
if (listener != null) {
listener.onContextMenuClick(mAdapter, position, position, false);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
return true;
}
return super.onOptionsItemSelected(item);
}
private void createBeginWithOsmandItems(ContextMenuAdapter contextMenuAdapter) {
contextMenuAdapter.addItem(createCategory(R.string.begin_with_osmand_menu_group));
contextMenuAdapter.addItem(createItem(R.string.first_usage_item,
R.string.first_usage_item_description, "feature_articles/start.html"));
contextMenuAdapter.addItem(createItem(R.string.shared_string_navigation,
R.string.navigation_item_description, "feature_articles/navigation.html"));
contextMenuAdapter.addItem(createItem(R.string.faq_item,
R.string.faq_item_description, "feature_articles/faq.html"));
}
private void createSocialNetworksItems(ContextMenuAdapter contextMenuAdapter) {
contextMenuAdapter.addItem(createSocialItem(R.string.twitter, R.string.twitter_address,
R.drawable.ic_action_social_twitter));
@ -81,10 +108,56 @@ public class HelpActivity extends OsmandActionBarActivity implements AdapterView
}
private void createHelpUsToImproveItems(ContextMenuAdapter contextMenuAdapter) {
contextMenuAdapter.addItem(createCategory(R.string.help_us_to_improve_menu_group));
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setLayout(R.layout.help_to_improve_item).createItem());
}
private void createFeaturesItems(ContextMenuAdapter contextMenuAdapter) {
contextMenuAdapter.addItem(createCategory(R.string.features_menu_group));
contextMenuAdapter.addItem(createItem(R.string.map_viewing_item, NULL_ID,
"feature_articles/map-viewing.html"));
contextMenuAdapter.addItem(createItem(R.string.search_on_the_map_item, NULL_ID,
"feature_articles/find-something-on-map.html"));
contextMenuAdapter.addItem(createItem(R.string.planning_trip_item, NULL_ID,
"feature_articles/trip-planning.html"));
contextMenuAdapter.addItem(createItem(R.string.map_legend, NULL_ID,
"feature_articles/map-legend.html"));
}
private void createPluginsItems(ContextMenuAdapter contextMenuAdapter) {
contextMenuAdapter.addItem(createCategory(R.string.plugins_menu_group));
for (final OsmandPlugin osmandPlugin : OsmandPlugin.getAvailablePlugins()) {
final String helpFileName = osmandPlugin.getHelpFileName();
if (helpFileName != null) {
contextMenuAdapter.addItem(createPluginItem(osmandPlugin.getName(), osmandPlugin.getLogoResourceId(),
helpFileName));
}
}
}
private void createOtherItems(ContextMenuAdapter contextMenuAdapter) {
contextMenuAdapter.addItem(createCategory(R.string.other_menu_group));
contextMenuAdapter.addItem(createItem(R.string.instalation_troubleshooting_item, NULL_ID,
"feature_articles/installation-and-troubleshooting.html"));
contextMenuAdapter.addItem(createItem(R.string.techical_articles_item, NULL_ID,
"feature_articles/technical-articles.html"));
contextMenuAdapter.addItem(createItem(R.string.versions_item, NULL_ID,
"feature_articles/changes.html"));
String releasedate = "";
if (!this.getString(R.string.app_edition).equals("")) {
releasedate = ", " + this.getString(R.string.shared_string_release).toLowerCase() + ": " + this.getString(R.string.app_edition);
}
String version = Version.getFullVersion(getMyApplication()) + releasedate;
ShowArticleOnTouchListener listener = new ShowArticleOnTouchListener(
"feature_articles/about.html", this, version);
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitle(getString(R.string.shared_string_about))
.setDescription(version).setListener(listener).createItem());
}
// Helper metods
private ContextMenuItem createCategory(@StringRes int titleRes) {
return new ContextMenuItem.ItemBuilder().setTitle(
getString(titleRes)).setCategory(true)
@ -92,11 +165,15 @@ public class HelpActivity extends OsmandActionBarActivity implements AdapterView
}
private ContextMenuItem createItem(@StringRes int titleRes,
@StringRes String path) {
return new ContextMenuItem.ItemBuilder()
@StringRes int descriptionRes,
String path) {
ContextMenuItem.ItemBuilder builder = new ContextMenuItem.ItemBuilder()
.setTitle(getString(titleRes))
.setListener(new ShowArticleOnTouchListener(path, this))
.createItem();
.setListener(new ShowArticleOnTouchListener(path, this));
if (descriptionRes != -1) {
builder.setDescription(getString(descriptionRes));
}
return builder.createItem();
}
private ContextMenuItem createPluginItem(String title,
@ -131,85 +208,6 @@ public class HelpActivity extends OsmandActionBarActivity implements AdapterView
.createItem();
}
private ContextMenuItem createItem(@StringRes int titleRes,
@StringRes int descriptionRes,
String path) {
return new ContextMenuItem.ItemBuilder()
.setTitle(getString(titleRes))
.setDescription(getString(descriptionRes))
.setListener(new ShowArticleOnTouchListener(path, this))
.createItem();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
return true;
}
return super.onOptionsItemSelected(item);
}
private void createBeginWithOsmandItems(ContextMenuAdapter contextMenuAdapter) {
contextMenuAdapter.addItem(createItem(R.string.first_usage_item, R.string.first_usage_item_description,
"feature_articles/start.html"));
contextMenuAdapter.addItem(createItem(R.string.shared_string_navigation, R.string.navigation_item_description,
"feature_articles/navigation.html"));
contextMenuAdapter.addItem(createItem(R.string.faq_item, R.string.faq_item_description,
"feature_articles/faq.html"));
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ContextMenuAdapter.ItemClickListener listener =
mAdapter.getItem(position).getItemClickListener();
if (listener != null) {
listener.onContextMenuClick(mAdapter, position, position, false);
}
}
private void createFeaturesItems(ContextMenuAdapter contextMenuAdapter) {
contextMenuAdapter.addItem(createItem(R.string.map_viewing_item,
"feature_articles/map-viewing.html"));
contextMenuAdapter.addItem(createItem(R.string.search_on_the_map_item,
"feature_articles/find-something-on-map.html"));
contextMenuAdapter.addItem(createItem(R.string.planning_trip_item,
"feature_articles/trip-planning.html"));
contextMenuAdapter.addItem(createItem(R.string.map_legend,
"feature_articles/map-legend.html"));
}
private void createPluginsItems(ContextMenuAdapter contextMenuAdapter) {
for (final OsmandPlugin osmandPlugin : OsmandPlugin.getAvailablePlugins()) {
final String helpFileName = osmandPlugin.getHelpFileName();
if (helpFileName != null) {
contextMenuAdapter.addItem(createPluginItem(osmandPlugin.getName(), osmandPlugin.getLogoResourceId(),
helpFileName));
}
}
}
private void createOtherItems(ContextMenuAdapter contextMenuAdapter) {
contextMenuAdapter.addItem(createItem(R.string.instalation_troubleshooting_item,
"feature_articles/installation-and-troubleshooting.html"));
contextMenuAdapter.addItem(createItem(R.string.techical_articles_item,
"feature_articles/technical-articles.html"));
contextMenuAdapter.addItem(createItem(R.string.versions_item,
"feature_articles/changes.html"));
String releasedate = "";
if (!this.getString(R.string.app_edition).equals("")) {
releasedate = ", " + this.getString(R.string.shared_string_release).toLowerCase() + ": " + this.getString(R.string.app_edition);
}
String version = Version.getFullVersion(getMyApplication()) + releasedate;
ShowArticleOnTouchListener listener = new ShowArticleOnTouchListener(
"feature_articles/about.html", this, version);
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitle(getString(R.string.shared_string_about))
.setDescription(version).setListener(listener).createItem());
}
private static class ShowArticleOnTouchListener implements ContextMenuAdapter.ItemClickListener {
private final String filename;
private final FragmentActivity ctx;