Search fragment for live updates. Fixed NPE after rotation on live updates. Small refactoring.
This commit is contained in:
parent
d2a7962474
commit
8505f72c57
9 changed files with 365 additions and 142 deletions
|
@ -51,12 +51,13 @@
|
|||
android:layout_height="60dp"
|
||||
android:src="@drawable/ic_world_globe_dark"/>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/regionReportsSpinner"
|
||||
android:layout_gravity="fill_horizontal|fill_vertical"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="42dp"
|
||||
android:gravity="center_vertical"/>
|
||||
<include
|
||||
android:id="@+id/reportsButton"
|
||||
layout="@layout/reports_for_spinner_item"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="8dp"/>
|
||||
|
||||
<View
|
||||
android:layout_height="1dp"
|
||||
|
|
39
OsmAnd/res/layout/fragment_search_list.xml
Normal file
39
OsmAnd/res/layout/fragment_search_list.xml
Normal file
|
@ -0,0 +1,39 @@
|
|||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context="net.osmand.plus.liveupdates.CountriesSearchSelectionFragment">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/clearButton"
|
||||
style="@style/Widget.AppCompat.Button.Borderless"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:src="@drawable/ic_action_remove_dark"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/searchEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:lines="1"
|
||||
android:background="@null"
|
||||
android:layout_marginLeft="16dp"
|
||||
tools:text="Search request"/>
|
||||
</LinearLayout>
|
||||
|
||||
<include layout="@layout/shadow_bottom"/>
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -9,7 +9,7 @@
|
|||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||
-->
|
||||
<string name="shared_string_remove">Remove</string>
|
||||
<string name="shared_string_remove">Remove</string>
|
||||
<string name="clear_updates_proposition_message">"You can remove downloaded updates and get back to the original map edition"</string>
|
||||
<string name="add_time_span">Add time span</string>
|
||||
<string name="road_blocked">Road blocked</string>
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
package net.osmand.plus.base;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.ColorRes;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.IdRes;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.OsmandActionBarActivity;
|
||||
|
||||
public class BaseOsmAndDialogFragment extends DialogFragment {
|
||||
private IconsCache iconsCache;
|
||||
|
||||
@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);
|
||||
getActivity().getWindow()
|
||||
.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
||||
}
|
||||
|
||||
|
||||
protected OsmandApplication getMyApplication() {
|
||||
return (OsmandApplication) getActivity().getApplication();
|
||||
}
|
||||
|
||||
protected OsmandActionBarActivity getMyActivity() {
|
||||
return (OsmandActionBarActivity) getActivity();
|
||||
}
|
||||
|
||||
protected IconsCache getIconsCache() {
|
||||
if (iconsCache == null) {
|
||||
iconsCache = getMyApplication().getIconsCache();
|
||||
}
|
||||
return iconsCache;
|
||||
}
|
||||
|
||||
protected Drawable getPaintedContentIcon(@DrawableRes int id, @ColorInt int color){
|
||||
return getIconsCache().getPaintedContentIcon(id, color);
|
||||
}
|
||||
|
||||
protected Drawable getIcon(@DrawableRes int id, @ColorRes int colorId){
|
||||
return getIconsCache().getIcon(id, colorId);
|
||||
}
|
||||
|
||||
protected Drawable getContentIcon(@DrawableRes int id){
|
||||
return getIconsCache().getContentIcon(id);
|
||||
}
|
||||
|
||||
protected void setThemedDrawable(View parent, @IdRes int viewId, @DrawableRes int iconId) {
|
||||
((ImageView) parent.findViewById(viewId)).setImageDrawable(getContentIcon(iconId));
|
||||
}
|
||||
|
||||
protected void setThemedDrawable(ImageView view, @DrawableRes int iconId) {
|
||||
view.setImageDrawable(getContentIcon(iconId));
|
||||
}
|
||||
|
||||
protected OsmandSettings getSettings() {
|
||||
return getMyApplication().getSettings();
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ import android.widget.ImageView;
|
|||
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.activities.OsmandActionBarActivity;
|
||||
|
||||
public class BaseOsmAndFragment extends Fragment {
|
||||
|
@ -46,4 +47,12 @@ public class BaseOsmAndFragment extends Fragment {
|
|||
protected void setThemedDrawable(View parent, @IdRes int viewId, @DrawableRes int iconId) {
|
||||
((ImageView) parent.findViewById(viewId)).setImageDrawable(getContentIcon(iconId));
|
||||
}
|
||||
|
||||
protected void setThemedDrawable(View view, @DrawableRes int iconId) {
|
||||
((ImageView) view).setImageDrawable(getContentIcon(iconId));
|
||||
}
|
||||
|
||||
protected OsmandSettings getSettings() {
|
||||
return getMyApplication().getSettings();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment {
|
|||
};
|
||||
private ExpandableListView listView;
|
||||
private LocalIndexesAdapter adapter;
|
||||
private AsyncTask<Void, LocalIndexInfo, List<LocalIndexInfo>> loadLocalIndexesTask;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -89,12 +90,14 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment {
|
|||
return true;
|
||||
}
|
||||
});
|
||||
new LoadLocalIndexTask(adapter, this).execute();
|
||||
loadLocalIndexesTask = new LoadLocalIndexTask(adapter, this).execute();
|
||||
return view;
|
||||
}
|
||||
|
||||
private OsmandSettings getSettings() {
|
||||
return getMyActivity().getMyApplication().getSettings();
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
loadLocalIndexesTask.cancel(true);
|
||||
}
|
||||
|
||||
public void notifyLiveUpdatesChanged() {
|
||||
|
@ -389,16 +392,17 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment {
|
|||
private List<LocalIndexInfo> result;
|
||||
private LocalIndexesAdapter adapter;
|
||||
private LiveUpdatesFragment fragment;
|
||||
private LocalIndexHelper helper;
|
||||
|
||||
public LoadLocalIndexTask(LocalIndexesAdapter adapter,
|
||||
LiveUpdatesFragment fragment) {
|
||||
this.adapter = adapter;
|
||||
this.fragment = fragment;
|
||||
helper = new LocalIndexHelper(fragment.getMyActivity().getMyApplication());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<LocalIndexInfo> doInBackground(Void... params) {
|
||||
LocalIndexHelper helper = new LocalIndexHelper(fragment.getMyActivity().getMyApplication());
|
||||
return helper.getLocalFullMaps(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,27 +1,9 @@
|
|||
package net.osmand.plus.liveupdates;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.map.WorldRegion;
|
||||
import net.osmand.osm.io.NetworkUtils;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.OsmandActionBarActivity;
|
||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -32,39 +14,63 @@ import android.widget.TextView;
|
|||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Activities that contain this fragment must implement the
|
||||
* {@link ReportsFragment.OnFragmentInteractionListener} interface
|
||||
* to handle interaction events.
|
||||
* Use the {@link ReportsFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class ReportsFragment extends BaseOsmAndFragment {
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.map.WorldRegion;
|
||||
import net.osmand.osm.io.NetworkUtils;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ReportsFragment extends BaseOsmAndFragment implements SearchSelectionFragment.OnFragmentInteractionListener {
|
||||
public static final String TITLE = "Report";
|
||||
public static final String TOTAL_CHANGES_BY_MONTH_URL_PATTERN = "http://download.osmand.net/" +
|
||||
"reports/query_report.php?report=total_changes_by_month&month=%s®ion=%s";
|
||||
private static final Log LOG = PlatformUtil.getLog(ReportsFragment.class);
|
||||
|
||||
private TextView contributorsTextView;
|
||||
private TextView editsTextView;
|
||||
|
||||
private Spinner montReportsSpinner;
|
||||
private Spinner regionReportsSpinner;
|
||||
private MonthsForReportsAdapter monthsForReportsAdapter;
|
||||
private RegionsForReportsAdapter regionsForReportsAdapter;
|
||||
|
||||
CountrySearchSelectionFragment searchSelectionFragment = new CountrySearchSelectionFragment();
|
||||
private TextView countryNameTextView;
|
||||
|
||||
HashMap<String, String> queryRegionNames = new HashMap<>();
|
||||
ArrayList<String> regionNames = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
initCountries();
|
||||
View view = inflater.inflate(R.layout.fragment_reports, container, false);
|
||||
montReportsSpinner = (Spinner) view.findViewById(R.id.montReportsSpinner);
|
||||
monthsForReportsAdapter = new MonthsForReportsAdapter(getActivity());
|
||||
montReportsSpinner.setAdapter(monthsForReportsAdapter);
|
||||
|
||||
regionReportsSpinner = (Spinner) view.findViewById(R.id.regionReportsSpinner);
|
||||
regionsForReportsAdapter = new RegionsForReportsAdapter(getMyActivity());
|
||||
regionsForReportsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
regionReportsSpinner.setAdapter(regionsForReportsAdapter);
|
||||
View regionReportsButton = view.findViewById(R.id.reportsButton);
|
||||
regionReportsButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
SearchSelectionFragment countrySearchSelectionFragment =
|
||||
searchSelectionFragment;
|
||||
countrySearchSelectionFragment
|
||||
.show(getChildFragmentManager(), "CountriesSearchSelectionFragment");
|
||||
}
|
||||
});
|
||||
|
||||
countryNameTextView = (TextView) regionReportsButton.findViewById(android.R.id.text1);
|
||||
countryNameTextView.setText(regionNames.get(0));
|
||||
|
||||
setThemedDrawable(view, R.id.calendarImageView, R.drawable.ic_action_data);
|
||||
setThemedDrawable(view, R.id.regionIconImageView, R.drawable.ic_world_globe_dark);
|
||||
|
@ -88,16 +94,13 @@ public class ReportsFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
};
|
||||
montReportsSpinner.setOnItemSelectedListener(onItemSelectedListener);
|
||||
regionReportsSpinner.setOnItemSelectedListener(onItemSelectedListener);
|
||||
return view;
|
||||
}
|
||||
|
||||
public void requestAndUpdateUi() {
|
||||
int monthItemPosition = montReportsSpinner.getSelectedItemPosition();
|
||||
String monthUrlString = monthsForReportsAdapter.getQueryString(monthItemPosition);
|
||||
int regionItemPosition = regionReportsSpinner.getSelectedItemPosition();
|
||||
String regionUrlString = regionsForReportsAdapter.getQueryString(regionItemPosition);
|
||||
regionUrlString = regionUrlString == null ? "" : regionUrlString;
|
||||
String countryUrlString = queryRegionNames.get(countryNameTextView.getText().toString());
|
||||
GetJsonAsyncTask.OnResponseListener<Protocol.TotalChangesByMonthResponse> onResponseListener =
|
||||
new GetJsonAsyncTask.OnResponseListener<Protocol.TotalChangesByMonthResponse>() {
|
||||
@Override
|
||||
|
@ -112,7 +115,7 @@ public class ReportsFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
}
|
||||
};
|
||||
requestData(monthUrlString, regionUrlString, onResponseListener);
|
||||
requestData(monthUrlString, countryUrlString, onResponseListener);
|
||||
}
|
||||
|
||||
private void requestData(String monthUrlString, String regionUrlString,
|
||||
|
@ -124,6 +127,80 @@ public class ReportsFragment extends BaseOsmAndFragment {
|
|||
totalChangesByMontAsyncTask.execute(finalUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchResult(String name) {
|
||||
countryNameTextView.setText(name);
|
||||
requestAndUpdateUi();
|
||||
}
|
||||
|
||||
private void initCountries() {
|
||||
final WorldRegion root = getMyApplication().getRegions().getWorldRegion();
|
||||
ArrayList<WorldRegion> groups = new ArrayList<>();
|
||||
groups.add(root);
|
||||
processGroup(root, groups, getActivity());
|
||||
Collections.sort(groups, new Comparator<WorldRegion>() {
|
||||
@Override
|
||||
public int compare(WorldRegion lhs, WorldRegion rhs) {
|
||||
if (lhs == root) {
|
||||
return -1;
|
||||
}
|
||||
if (rhs == root) {
|
||||
return 1;
|
||||
}
|
||||
return getHumanReadableName(lhs).compareTo(getHumanReadableName(rhs));
|
||||
}
|
||||
});
|
||||
for (WorldRegion group : groups) {
|
||||
String name = getHumanReadableName(group);
|
||||
regionNames.add(name);
|
||||
queryRegionNames.put(name, group.getRegionDownloadName());
|
||||
}
|
||||
}
|
||||
|
||||
private static String getHumanReadableName(WorldRegion group) {
|
||||
String name;
|
||||
if (group.getLevel() > 2 || (group.getLevel() == 2
|
||||
&& group.getSuperregion().getRegionId().equals(WorldRegion.RUSSIA_REGION_ID))) {
|
||||
WorldRegion parent = group.getSuperregion();
|
||||
WorldRegion parentsParent = group.getSuperregion().getSuperregion();
|
||||
if (group.getLevel() == 3) {
|
||||
if (parentsParent.getRegionId().equals(WorldRegion.RUSSIA_REGION_ID)) {
|
||||
name = parentsParent.getLocaleName() + " " + group.getLocaleName();
|
||||
} else if (!parent.getRegionId().equals(WorldRegion.UNITED_KINGDOM_REGION_ID)) {
|
||||
name = parent.getLocaleName() + " " + group.getLocaleName();
|
||||
} else {
|
||||
name = group.getLocaleName();
|
||||
}
|
||||
} else {
|
||||
name = parent.getLocaleName() + " " + group.getLocaleName();
|
||||
}
|
||||
} else {
|
||||
name = group.getLocaleName();
|
||||
}
|
||||
if (name == null) {
|
||||
name = "";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getQueryString(int position) {
|
||||
return queryRegionNames.get(position);
|
||||
}
|
||||
|
||||
private static void processGroup(WorldRegion group,
|
||||
List<WorldRegion> nameList,
|
||||
Context context) {
|
||||
if (group.isRegionMapDownload()) {
|
||||
nameList.add(group);
|
||||
}
|
||||
|
||||
if (group.getSubregions() != null) {
|
||||
for (WorldRegion g : group.getSubregions()) {
|
||||
processGroup(g, nameList, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class MonthsForReportsAdapter extends ArrayAdapter<String> {
|
||||
private static final SimpleDateFormat queryFormat = new SimpleDateFormat("yyyy-MM", Locale.US);
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
|
@ -152,77 +229,6 @@ public class ReportsFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
}
|
||||
|
||||
private static class RegionsForReportsAdapter extends ArrayAdapter<String> {
|
||||
ArrayList<String> queryRegionNames = new ArrayList<>();
|
||||
|
||||
public RegionsForReportsAdapter(final OsmandActionBarActivity context) {
|
||||
super(context, R.layout.reports_for_spinner_item, android.R.id.text1);
|
||||
|
||||
final WorldRegion root = context.getMyApplication().getRegions().getWorldRegion();
|
||||
ArrayList<WorldRegion> groups = new ArrayList<>();
|
||||
groups.add(root);
|
||||
processGroup(root, groups, context);
|
||||
Collections.sort(groups, new Comparator<WorldRegion>() {
|
||||
@Override
|
||||
public int compare(WorldRegion lhs, WorldRegion rhs) {
|
||||
if (lhs == root) {
|
||||
return -1;
|
||||
}
|
||||
if (rhs == root) {
|
||||
return 1;
|
||||
}
|
||||
return getHumanReadableName(lhs).compareTo(getHumanReadableName(rhs));
|
||||
}
|
||||
});
|
||||
for (WorldRegion group : groups) {
|
||||
String name = getHumanReadableName(group);
|
||||
add(name);
|
||||
queryRegionNames.add(group.getRegionDownloadName());
|
||||
}
|
||||
}
|
||||
|
||||
private static String getHumanReadableName(WorldRegion group) {
|
||||
String name;
|
||||
if(group.getLevel() > 2 || (group.getLevel() == 2
|
||||
&& group.getSuperregion().getRegionId().equals(WorldRegion.RUSSIA_REGION_ID))) {
|
||||
WorldRegion parent = group.getSuperregion();
|
||||
WorldRegion parentsParent = group.getSuperregion().getSuperregion();
|
||||
if(group.getLevel() == 3) {
|
||||
if(parentsParent.getRegionId().equals(WorldRegion.RUSSIA_REGION_ID)) {
|
||||
name = parentsParent.getLocaleName() + " " + group.getLocaleName();
|
||||
} else if (!parent.getRegionId().equals(WorldRegion.UNITED_KINGDOM_REGION_ID)) {
|
||||
name = parent.getLocaleName() + " " + group.getLocaleName();
|
||||
} else {
|
||||
name = group.getLocaleName();
|
||||
}
|
||||
} else {
|
||||
name = parent.getLocaleName() + " " + group.getLocaleName();
|
||||
}
|
||||
} else {
|
||||
name = group.getLocaleName();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getQueryString(int position) {
|
||||
return queryRegionNames.get(position);
|
||||
}
|
||||
|
||||
private static void processGroup(WorldRegion group,
|
||||
List<WorldRegion> nameList,
|
||||
Context context) {
|
||||
if (group.isRegionMapDownload()) {
|
||||
nameList.add(group);
|
||||
}
|
||||
|
||||
if (group.getSubregions() != null) {
|
||||
for (WorldRegion g : group.getSubregions()) {
|
||||
processGroup(g, nameList, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class GetJsonAsyncTask<P> extends AsyncTask<String, Void, P> {
|
||||
private static final Log LOG = PlatformUtil.getLog(GetJsonAsyncTask.class);
|
||||
private final Class<P> protocolClass;
|
||||
|
@ -260,4 +266,10 @@ public class ReportsFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
}
|
||||
|
||||
public static class CountrySearchSelectionFragment extends SearchSelectionFragment {
|
||||
@Override
|
||||
protected ArrayList<String> getList() {
|
||||
return ((ReportsFragment) getParentFragment()).regionNames;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
package net.osmand.plus.liveupdates;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ListView;
|
||||
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.BaseOsmAndDialogFragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class SearchSelectionFragment extends BaseOsmAndDialogFragment {
|
||||
private OnFragmentInteractionListener mListener;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_search_list, container, false);
|
||||
ListView listView = (ListView) view.findViewById(android.R.id.list);
|
||||
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(getMyActivity(), android.R.layout.simple_list_item_1);
|
||||
if (getArray() != null) {
|
||||
adapter.addAll(getArray());
|
||||
} else if (getList() != null){
|
||||
adapter.addAll(getList());
|
||||
} else {
|
||||
throw new RuntimeException("Either getArray() or getList() must return non null value.");
|
||||
}
|
||||
listView.setAdapter(adapter);
|
||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
mListener.onSearchResult(adapter.getItem(position));
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
final EditText searchEditText = (EditText) view.findViewById(R.id.searchEditText);
|
||||
searchEditText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
adapter.getFilter().filter(s);
|
||||
}
|
||||
});
|
||||
ImageButton clearButton = (ImageButton) view.findViewById(R.id.clearButton);
|
||||
setThemedDrawable(clearButton, R.drawable.ic_action_remove_dark);
|
||||
clearButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
searchEditText.setText(null);
|
||||
}
|
||||
});
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
if (context instanceof OnFragmentInteractionListener) {
|
||||
mListener = (OnFragmentInteractionListener) context;
|
||||
} else if (getParentFragment() instanceof OnFragmentInteractionListener) {
|
||||
mListener = (OnFragmentInteractionListener) getParentFragment();
|
||||
} else {
|
||||
throw new RuntimeException(context.toString()
|
||||
+ " must implement OnFragmentInteractionListener");
|
||||
}
|
||||
}
|
||||
|
||||
protected String[] getArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected ArrayList<String> getList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
mListener = null;
|
||||
}
|
||||
|
||||
public interface OnFragmentInteractionListener {
|
||||
void onSearchResult(String name);
|
||||
}
|
||||
}
|
|
@ -60,6 +60,7 @@ import net.osmand.plus.OsmandPlugin;
|
|||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.BaseOsmAndDialogFragment;
|
||||
import net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment;
|
||||
import net.osmand.plus.osmedit.dialogs.PoiTypeDialogFragment;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -73,7 +74,7 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class EditPoiDialogFragment extends DialogFragment {
|
||||
public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
|
||||
public static final String TAG = "EditPoiDialogFragment";
|
||||
private static final Log LOG = PlatformUtil.getLog(EditPoiDialogFragment.class);
|
||||
|
||||
|
@ -103,9 +104,9 @@ public class EditPoiDialogFragment extends DialogFragment {
|
|||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
OsmandSettings settings = getMyApplication().getSettings();
|
||||
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
|
||||
if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) {
|
||||
if (getSettings().OFFLINE_EDITION.get()
|
||||
|| !getSettings().isInternetConnectionAvailable(true)) {
|
||||
mOpenstreetmapUtil = plugin.getPoiModificationLocalUtil();
|
||||
} else {
|
||||
mOpenstreetmapUtil = plugin.getPoiModificationRemoteUtil();
|
||||
|
@ -115,23 +116,11 @@ public class EditPoiDialogFragment extends DialogFragment {
|
|||
editPoiData = new EditPoiData(node, getMyApplication());
|
||||
}
|
||||
|
||||
@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);
|
||||
getActivity().getWindow()
|
||||
.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
view = inflater.inflate(R.layout.fragment_edit_poi, container, false);
|
||||
final OsmandSettings settings = getMyApplication().getSettings();
|
||||
boolean isLightTheme = settings.OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
|
||||
boolean isLightTheme = getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -204,8 +193,7 @@ public class EditPoiDialogFragment extends DialogFragment {
|
|||
|
||||
final int colorId = isLightTheme ? R.color.inactive_item_orange : R.color.dash_search_icon_dark;
|
||||
final int color = getResources().getColor(colorId);
|
||||
onlineDocumentationButton.setImageDrawable(getMyApplication().getIconsCache()
|
||||
.getPaintedContentIcon(R.drawable.ic_action_help, color));
|
||||
onlineDocumentationButton.setImageDrawable(getPaintedContentIcon(R.drawable.ic_action_help, color));
|
||||
final ImageButton poiTypeButton = (ImageButton) view.findViewById(R.id.poiTypeButton);
|
||||
poiTypeButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -548,10 +536,6 @@ public class EditPoiDialogFragment extends DialogFragment {
|
|||
}
|
||||
}
|
||||
|
||||
private OsmandApplication getMyApplication() {
|
||||
return (OsmandApplication) getActivity().getApplication();
|
||||
}
|
||||
|
||||
public static EditPoiDialogFragment createAddPoiInstance(double latitude, double longitude,
|
||||
OsmandApplication application) {
|
||||
Node node = new Node(latitude, longitude, -1);
|
||||
|
|
Loading…
Reference in a new issue