Refactor tour information
This commit is contained in:
parent
bf61c9ed75
commit
74fd02d4f5
11 changed files with 288 additions and 78 deletions
|
@ -1,14 +1,46 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<TextView android:id="@+id/tour_name" android:gravity="center_horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"
|
||||
android:textSize="25sp"></TextView>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" >
|
||||
|
||||
<ImageView android:id="@+id/tour_image"
|
||||
android:paddingLeft="8dp" android:paddingRight="8dp"
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tour_name"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:textSize="25sp" >
|
||||
</TextView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tour_description"
|
||||
android:layout_width="wrap_content"
|
||||
android:paddingTop="4dp" android:layout_height="wrap_content"/>
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="2dp"
|
||||
android:layout_marginTop="2dp"
|
||||
android:textSize="18sp" >
|
||||
</TextView>
|
||||
|
||||
<TextView android:id="@+id/tour_description" android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:textSize="18sp"></TextView>
|
||||
<ImageView
|
||||
android:id="@+id/tour_image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="8dp"
|
||||
android:paddingTop="4dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tour_fulldescription"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="2dp"
|
||||
android:layout_marginTop="2dp"
|
||||
android:textSize="18sp" >
|
||||
</TextView>
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<resources>
|
||||
<string name="no_stages_provided">No stages provided</string>
|
||||
<string name="download_more">Download more</string>
|
||||
<string name="no_tour_selected">No tour selected</string>
|
||||
<string name="settings_file_create_error">Couldn\'t create settings file in tour folder.</string>
|
||||
|
|
|
@ -89,7 +89,7 @@ public class OsmAndAppCustomization {
|
|||
public void updatedLoadedFiles(Map<String, String> indexFileNames, Map<String, String> indexActivatedFileNames) {
|
||||
}
|
||||
|
||||
public Collection<? extends String> onIndexingFiles(IProgress progress, Map<String, String> indexFileNames) {
|
||||
public List<String> onIndexingFiles(IProgress progress, Map<String, String> indexFileNames) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
|
|
@ -202,6 +202,7 @@ public class DownloadFileHelper {
|
|||
try {
|
||||
final List<InputStream> downloadInputStreams = new ArrayList<InputStream>();
|
||||
URL url = new URL(de.urlToDownload); //$NON-NLS-1$
|
||||
log.debug("Url downloading " + de.urlToDownload);
|
||||
downloadInputStreams.add(getInputStreamToDownload(url, forceWifi));
|
||||
de.fileToDownload = de.targetFile;
|
||||
if(!de.unzipFolder) {
|
||||
|
|
|
@ -3,8 +3,6 @@ package net.osmand.plus.sherpafy;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -18,6 +16,7 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.activities.DownloadIndexActivity;
|
||||
import net.osmand.plus.api.FileSettingsAPIImpl;
|
||||
import net.osmand.plus.download.DownloadActivityType;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageInformation;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
|
@ -27,10 +26,13 @@ import android.widget.TextView;
|
|||
|
||||
public class SherpafyCustomization extends OsmAndAppCustomization {
|
||||
|
||||
private static final String SELECTED_TOUR = "sherpafy_tour";
|
||||
private static final String SELECTED_TOUR = "selected_tour";
|
||||
private static final String SELECTED_STAGE = "selected_stage";
|
||||
private OsmandSettings originalSettings;
|
||||
private CommonPreference<String> selectedTourPref;
|
||||
private CommonPreference<String> selectedStagePref;
|
||||
private List<TourInformation> tourPresent = new ArrayList<TourInformation>();
|
||||
private StageInformation selectedStage = null;
|
||||
private TourInformation selectedTour = null;
|
||||
private File toursFolder;
|
||||
|
||||
|
@ -90,8 +92,10 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
|
|||
// toursFolder, "", indexFileNames);
|
||||
}
|
||||
|
||||
public Collection<? extends String> onIndexingFiles(IProgress progress, Map<String, String> indexFileNames) {
|
||||
public List<String> onIndexingFiles(IProgress progress, Map<String, String> indexFileNames) {
|
||||
ArrayList<TourInformation> tourPresent = new ArrayList<TourInformation>();
|
||||
List<String> warns = new ArrayList<String>();
|
||||
selectedTour = null;
|
||||
if(toursFolder.exists()) {
|
||||
File[] availableTours = toursFolder.listFiles();
|
||||
if(availableTours != null) {
|
||||
|
@ -105,14 +109,14 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
|
|||
final TourInformation tourInformation = new TourInformation(tr);
|
||||
tourPresent.add(tourInformation);
|
||||
if (selected) {
|
||||
reloadSelectedTour(progress, tr, tourInformation);
|
||||
reloadSelectedTour(progress, tr, tourInformation, warns);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.tourPresent = tourPresent;
|
||||
return Collections.emptyList();
|
||||
return warns;
|
||||
}
|
||||
|
||||
public List<TourInformation> getTourInformations() {
|
||||
|
@ -123,7 +127,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
|
|||
return selectedTour;
|
||||
}
|
||||
|
||||
private void reloadSelectedTour(IProgress progress, File tr, final TourInformation tourInformation) {
|
||||
private void reloadSelectedTour(IProgress progress, File tr, final TourInformation tourInformation, List<String> warns) {
|
||||
if(progress != null) {
|
||||
progress.startTask(app.getString(R.string.indexing_tour, tr.getName()), -1);
|
||||
}
|
||||
|
@ -136,19 +140,46 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
|
|||
}
|
||||
app.getSettings().setSettingsAPI(fapi);
|
||||
} catch (IOException e) {
|
||||
warns.add(app.getString(R.string.settings_file_create_error));
|
||||
app.showToastMessage(R.string.settings_file_create_error);
|
||||
}
|
||||
selectedStagePref = app.getSettings().registerStringPreference(SELECTED_STAGE, null).makeGlobal();
|
||||
try {
|
||||
tourInformation.loadFullInformation();
|
||||
} catch (Exception e) {
|
||||
warns.add("Selected tour : " + e.getMessage());
|
||||
}
|
||||
selectedTour = tourInformation;
|
||||
if(selectedStagePref.get() != null) {
|
||||
for(StageInformation s : selectedTour.getStageInformation()) {
|
||||
if(s.getName().equals(selectedStagePref.get())) {
|
||||
selectedStage = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public StageInformation getSelectedStage() {
|
||||
return selectedStage;
|
||||
}
|
||||
|
||||
public void selectTour(TourInformation tour) {
|
||||
public void selectStage(StageInformation tour, IProgress progress) {
|
||||
if(tour == null) {
|
||||
selectedStagePref.set(null);
|
||||
} else {
|
||||
selectedStagePref.set(tour.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public void selectTour(TourInformation tour, IProgress progress) {
|
||||
if(tour == null) {
|
||||
selectedTourPref.set(null);
|
||||
} else {
|
||||
selectedTourPref.set(tour.getName());
|
||||
}
|
||||
app.getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS);
|
||||
selectedTour = null;
|
||||
selectedStage = null;
|
||||
app.getResourceManager().reloadIndexes(progress);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,13 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.ProgressDialogImplementation;
|
||||
import net.osmand.plus.R;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
|
@ -57,6 +60,43 @@ public class TourCommonActivity extends SherlockFragmentActivity {
|
|||
}
|
||||
}
|
||||
|
||||
public void selectTour(TourInformation ti){
|
||||
final SherpafyCustomization c = (SherpafyCustomization) ((OsmandApplication) getApplication()).getAppCustomization();
|
||||
|
||||
new AsyncTask<TourInformation, Void, Void> (){
|
||||
private ProgressDialogImplementation dlg;
|
||||
|
||||
protected void onPreExecute() {
|
||||
dlg = ProgressDialogImplementation.createProgressDialog(TourCommonActivity.this, "", getString(R.string.indexing_tour, ""),
|
||||
ProgressDialog.STYLE_SPINNER);
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(TourInformation... params) {
|
||||
c.selectTour(params[0], dlg);
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void onPostExecute(Void result) {
|
||||
dlg.getDialog().dismiss();
|
||||
for(WeakReference<Fragment> ref : fragList) {
|
||||
Fragment f = ref.get();
|
||||
if(f instanceof TourFragment) {
|
||||
if(!f.isDetached()) {
|
||||
((TourFragment) f).refreshTour();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}.execute(ti);
|
||||
}
|
||||
|
||||
public interface TourFragment {
|
||||
|
||||
public void refreshTour();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
|
||||
int itemId = item.getItemId();
|
||||
|
|
|
@ -50,12 +50,21 @@ public class TourDownloadType extends DownloadActivityType {
|
|||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBasename(IndexItem indexItem) {
|
||||
String fileName = indexItem.getFileName().replace('_', ' ');
|
||||
if(fileName.indexOf('.') != -1) {
|
||||
return fileName.substring(0, fileName.indexOf('.'));
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public String getVisibleName(IndexItem indexItem, Context ctx, OsmandRegions osmandRegions) {
|
||||
return getBasename(indexItem) + "\n" + indexItem.getDescription();
|
||||
return getBasename(indexItem).replace('_', ' ') + "\n" + indexItem.getDescription();
|
||||
}
|
||||
|
||||
public String getTargetFileName(IndexItem item) {
|
||||
return item.getBasename();
|
||||
return getBasename(item);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,59 +1,117 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
|
||||
public class TourInformation {
|
||||
final String FILE_PREFIX = "@file:";
|
||||
|
||||
private String name;
|
||||
private File folder;
|
||||
private String description = null;
|
||||
private String shortDescription = "";
|
||||
private String fulldescription = "";
|
||||
private Bitmap defaultImg = null;
|
||||
private File imgFile;
|
||||
private List<StageInformation> stageInformation = new ArrayList<TourInformation.StageInformation>();
|
||||
|
||||
public TourInformation(File f) {
|
||||
this.folder = f;
|
||||
this.name = f.getName();
|
||||
this.name = f.getName().replace('_', ' ');
|
||||
}
|
||||
|
||||
|
||||
private String loadDescription() {
|
||||
File fl = new File(folder, "description.txt");
|
||||
StringBuilder text = new StringBuilder();
|
||||
if (fl.exists()) {
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new FileReader(fl), 256); //$NON-NLS-1$
|
||||
String s;
|
||||
boolean f = true;
|
||||
while ((s = in.readLine()) != null) {
|
||||
if (!f) {
|
||||
text.append("\n"); //$NON-NLS-1$
|
||||
} else {
|
||||
f = false;
|
||||
private static Reader getUTF8Reader(InputStream f) throws IOException {
|
||||
BufferedInputStream bis = new BufferedInputStream(f);
|
||||
assert bis.markSupported();
|
||||
bis.mark(3);
|
||||
boolean reset = true;
|
||||
byte[] t = new byte[3];
|
||||
bis.read(t);
|
||||
if (t[0] == ((byte) 0xef) && t[1] == ((byte) 0xbb) && t[2] == ((byte) 0xbf)) {
|
||||
reset = false;
|
||||
}
|
||||
text.append(s);
|
||||
if (reset) {
|
||||
bis.reset();
|
||||
}
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return text.toString();
|
||||
return new InputStreamReader(bis, "UTF-8");
|
||||
}
|
||||
|
||||
public void loadFullInformation(){
|
||||
description = loadDescription();
|
||||
public void loadFullInformation() throws Exception {
|
||||
XmlPullParser parser = PlatformUtil.newXMLPullParser();
|
||||
final Reader reader = getUTF8Reader(new FileInputStream(new File(folder, "inventory.xml")));
|
||||
parser.setInput(reader); //$NON-NLS-1$
|
||||
int tok;
|
||||
String text = "";
|
||||
StageInformation stage = null;
|
||||
stageInformation.clear();
|
||||
while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) {
|
||||
if (tok == XmlPullParser.START_TAG) {
|
||||
String tag = parser.getName();
|
||||
if(tag.equals("tour")) {
|
||||
name = getDefAttribute(parser, "name", name);
|
||||
} else if (tag.equals("stage")) {
|
||||
String name = getDefAttribute(parser, "name", "");
|
||||
stage = new StageInformation();
|
||||
stage.name = name;
|
||||
}
|
||||
} else if (tok == XmlPullParser.TEXT) {
|
||||
text = parser.getText();
|
||||
} else if (tok == XmlPullParser.END_TAG) {
|
||||
String tag = parser.getName();
|
||||
if(tag.equals("stage")) {
|
||||
stageInformation.add(stage);
|
||||
stage = null;
|
||||
} else if(stage != null && tag.equals("description")) {
|
||||
stage.description = text;
|
||||
} else if(stage != null && tag.equals("gpx")) {
|
||||
if(text.startsWith(FILE_PREFIX)) {
|
||||
stage.gpxFile = new File(folder, text.substring(FILE_PREFIX.length()));
|
||||
}
|
||||
} else if(tag.equals("fullDescription")) {
|
||||
fulldescription = text;
|
||||
} else if(tag.equals("shortDescription")) {
|
||||
shortDescription = text;
|
||||
} else if(tag.equals("defaultImage")) {
|
||||
if(text.startsWith(FILE_PREFIX)) {
|
||||
imgFile = new File(folder, text.substring(FILE_PREFIX.length()));
|
||||
}
|
||||
}
|
||||
text = "";
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
|
||||
private String getDefAttribute(XmlPullParser parser, String string, String def) {
|
||||
String vl = parser.getAttributeValue("", string);
|
||||
if(vl != null && vl.length() > 0) {
|
||||
return vl;
|
||||
}
|
||||
return def;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String getDescription() {
|
||||
return description == null ? "" : description;
|
||||
public String getShortDescription() {
|
||||
return shortDescription;
|
||||
}
|
||||
|
||||
public String getFulldescription() {
|
||||
return fulldescription;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
@ -70,18 +128,17 @@ public class TourInformation {
|
|||
|
||||
|
||||
public Bitmap getImageBitmap() {
|
||||
File fl = new File(folder, "images/Default.jpg");
|
||||
if(fl.exists()) {
|
||||
return BitmapFactory.decodeFile(fl.getAbsolutePath());
|
||||
if(defaultImg == null && imgFile != null && imgFile.exists()) {
|
||||
defaultImg = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
|
||||
}
|
||||
return null;
|
||||
return defaultImg;
|
||||
}
|
||||
|
||||
public static class StageInformation {
|
||||
|
||||
File gpxFile;
|
||||
String name;
|
||||
String description;
|
||||
String name = "";
|
||||
String description = "";
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
|
|
|
@ -5,23 +5,24 @@ package net.osmand.plus.sherpafy;
|
|||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.sherpafy.TourCommonActivity.TourFragment;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ImageView.ScaleType;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockFragment;
|
||||
|
||||
|
||||
public class TourInformationFragment extends SherlockFragment {
|
||||
public class TourInformationFragment extends SherlockFragment implements TourFragment {
|
||||
|
||||
private View view;
|
||||
private SherpafyCustomization appCtx;
|
||||
public View onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container, Bundle savedInstanceState) {
|
||||
view = inflater.inflate(R.layout.tour_info, container, false);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
appCtx = (SherpafyCustomization) getApp().getAppCustomization();
|
||||
return view;
|
||||
}
|
||||
|
@ -29,16 +30,26 @@ public class TourInformationFragment extends SherlockFragment {
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
TextView description = (TextView) view.findViewById(R.id.tour_description);
|
||||
updateView();
|
||||
}
|
||||
|
||||
private void updateView() {
|
||||
ImageView img = (ImageView) view.findViewById(R.id.tour_image);
|
||||
TextView description = (TextView) view.findViewById(R.id.tour_description);
|
||||
TextView fullDescription = (TextView) view.findViewById(R.id.tour_fulldescription);
|
||||
TextView name = (TextView) view.findViewById(R.id.tour_name);
|
||||
if(appCtx.getSelectedTour() != null) {
|
||||
name.setText(appCtx.getSelectedTour().getName());
|
||||
description.setText(appCtx.getSelectedTour().getDescription());
|
||||
description.setText(appCtx.getSelectedTour().getShortDescription());
|
||||
description.setVisibility(View.VISIBLE);
|
||||
fullDescription.setText(appCtx.getSelectedTour().getFulldescription());
|
||||
fullDescription.setVisibility(View.VISIBLE);
|
||||
final Bitmap imageBitmap = appCtx.getSelectedTour().getImageBitmap();
|
||||
if(imageBitmap != null) {
|
||||
img.setImageBitmap(imageBitmap);
|
||||
img.setAdjustViewBounds(true);
|
||||
img.setScaleType(ScaleType.CENTER_INSIDE);
|
||||
img.setCropToPadding(true);
|
||||
img.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
img.setVisibility(View.GONE);
|
||||
|
@ -47,6 +58,7 @@ public class TourInformationFragment extends SherlockFragment {
|
|||
name.setText(R.string.no_tour_selected);
|
||||
img.setVisibility(View.GONE);
|
||||
description.setVisibility(View.GONE);
|
||||
fullDescription.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,5 +67,10 @@ public class TourInformationFragment extends SherlockFragment {
|
|||
return (OsmandApplication) getSherlockActivity().getApplication();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshTour() {
|
||||
updateView();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,8 +7,7 @@ import java.util.List;
|
|||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper;
|
||||
import net.osmand.plus.activities.SettingsActivity;
|
||||
import net.osmand.plus.sherpafy.TourCommonActivity.TourFragment;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -26,7 +25,7 @@ import com.actionbarsherlock.view.MenuItem;
|
|||
import com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener;
|
||||
|
||||
|
||||
public class TourSelectionFragment extends SherlockListFragment {
|
||||
public class TourSelectionFragment extends SherlockListFragment implements TourFragment {
|
||||
public static final int REQUEST_POI_EDIT = 55;
|
||||
private static final int DOWNLOAD_MORE = 0;
|
||||
private SherpafyCustomization appCtx;
|
||||
|
@ -59,10 +58,10 @@ public class TourSelectionFragment extends SherlockListFragment {
|
|||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
final OsmandApplication app = (OsmandApplication) getActivity().getApplication();
|
||||
boolean light = app.getSettings().isLightActionBar();
|
||||
com.actionbarsherlock.view.MenuItem menuItem = menu.add(0, DOWNLOAD_MORE, 0, R.string.download_more).setShowAsActionFlags(
|
||||
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_gdown_light : R.drawable.ic_action_gdown_dark);
|
||||
// boolean light = app.getSettings().isLightActionBar();
|
||||
// menuItem = menuItem.setIcon(light ? R.drawable.ic_action_gdown_light : R.drawable.ic_action_gdown_dark);
|
||||
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
|
||||
|
@ -77,9 +76,9 @@ public class TourSelectionFragment extends SherlockListFragment {
|
|||
public void onListItemClick(ListView parent, View v, int position, long id) {
|
||||
final TourInformation tour = ((LocalAdapter) getListAdapter()).getItem(position);
|
||||
if(appCtx.getSelectedTour() != tour) {
|
||||
appCtx.selectTour(tour);
|
||||
((TourCommonActivity) getActivity()).selectTour(tour);
|
||||
} else {
|
||||
appCtx.selectTour(null);
|
||||
((TourCommonActivity) getActivity()).selectTour(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,8 +105,8 @@ public class TourSelectionFragment extends SherlockListFragment {
|
|||
} else {
|
||||
check.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
if(model.getDescription().length() > 0) {
|
||||
label.setText(model.getName() +"\n" + model.getDescription());
|
||||
if(model.getShortDescription().length() > 0) {
|
||||
label.setText(model.getName() +"\n" + model.getShortDescription());
|
||||
} else {
|
||||
label.setText(model.getName());
|
||||
}
|
||||
|
@ -116,4 +115,10 @@ public class TourSelectionFragment extends SherlockListFragment {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshTour() {
|
||||
setListAdapter(new LocalAdapter(appCtx.getTourInformations()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,8 +6,10 @@ package net.osmand.plus.sherpafy;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.IProgress;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.sherpafy.TourCommonActivity.TourFragment;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageInformation;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -21,7 +23,7 @@ import android.widget.TextView;
|
|||
import com.actionbarsherlock.app.SherlockListFragment;
|
||||
|
||||
|
||||
public class TourStageFragment extends SherlockListFragment {
|
||||
public class TourStageFragment extends SherlockListFragment implements TourFragment {
|
||||
public static final int REQUEST_POI_EDIT = 55;
|
||||
private SherpafyCustomization appCtx;
|
||||
private boolean lightContent;
|
||||
|
@ -42,11 +44,11 @@ public class TourStageFragment extends SherlockListFragment {
|
|||
// return false;
|
||||
// }
|
||||
// });
|
||||
setEmptyText(getString(R.string.no_stages_provided));
|
||||
if(appCtx.getSelectedTour() != null) {
|
||||
setListAdapter(new LocalAdapter(appCtx.getSelectedTour().getStageInformation()));
|
||||
} else {
|
||||
setListAdapter(new LocalAdapter(new ArrayList<TourInformation.StageInformation>()));
|
||||
setEmptyText(getString(R.string.no_tour_selected));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,7 +59,7 @@ public class TourStageFragment extends SherlockListFragment {
|
|||
@Override
|
||||
public void onListItemClick(ListView parent, View v, int position, long id) {
|
||||
final StageInformation model = ((LocalAdapter) getListAdapter()).getItem(position);
|
||||
// TODO
|
||||
appCtx.selectStage(model, IProgress.EMPTY_PROGRESS);
|
||||
}
|
||||
|
||||
private class LocalAdapter extends ArrayAdapter<StageInformation> {
|
||||
|
@ -76,8 +78,13 @@ public class TourStageFragment extends SherlockListFragment {
|
|||
ImageView icon = (ImageView) row.findViewById(R.id.icon);
|
||||
ImageView check = (ImageView) row.findViewById(R.id.check_item);
|
||||
icon.setImageResource(!lightContent ? R.drawable.ic_action_fav_dark : R.drawable.ic_action_fav_light);
|
||||
check.setImageResource(!lightContent ? R.drawable.ic_action_ok_dark : R.drawable.ic_action_ok_light);
|
||||
final StageInformation model = getItem(position);
|
||||
if(appCtx.getSelectedStage() == model) {
|
||||
check.setImageResource(!lightContent ? R.drawable.ic_action_ok_dark : R.drawable.ic_action_ok_light);
|
||||
check.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
check.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
if(model.getDescription().length() > 0) {
|
||||
label.setText(model.getName() +"\n" + model.getDescription());
|
||||
} else {
|
||||
|
@ -88,4 +95,14 @@ public class TourStageFragment extends SherlockListFragment {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshTour() {
|
||||
if(appCtx.getSelectedTour() != null) {
|
||||
setListAdapter(new LocalAdapter(appCtx.getSelectedTour().getStageInformation()));
|
||||
} else {
|
||||
setListAdapter(new LocalAdapter(new ArrayList<TourInformation.StageInformation>()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue