From 607d496275f5cedc1b2e46ffbe427995779bbcf4 Mon Sep 17 00:00:00 2001 From: Bars107 Date: Thu, 19 Feb 2015 15:04:19 +0200 Subject: [PATCH] Updated audio video notes in my places --- OsmAnd/res/layout/note.xml | 1 + OsmAnd/res/layout/note_edit_dialog.xml | 30 +++++++++++ OsmAnd/res/layout/update_index.xml | 1 + OsmAnd/res/values/strings.xml | 1 + .../plus/activities/FavoritesActivity.java | 9 +++- .../plus/audionotes/AudioNotesLayer.java | 4 +- .../audionotes/AudioVideoNotesPlugin.java | 13 ++++- .../DashAudioVideoNotesFragment.java | 6 +-- .../osmand/plus/audionotes/NotesFragment.java | 52 +++++++++++++++++-- 9 files changed, 104 insertions(+), 13 deletions(-) create mode 100644 OsmAnd/res/layout/note_edit_dialog.xml diff --git a/OsmAnd/res/layout/note.xml b/OsmAnd/res/layout/note.xml index 46280b3f04..4879876f82 100644 --- a/OsmAnd/res/layout/note.xml +++ b/OsmAnd/res/layout/note.xml @@ -48,6 +48,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical" + android:textSize="@dimen/download_descr_text_size" android:maxLines="25" tools:text="@string/app_mode_aircraft"/> diff --git a/OsmAnd/res/layout/note_edit_dialog.xml b/OsmAnd/res/layout/note_edit_dialog.xml new file mode 100644 index 0000000000..d8e2af68e9 --- /dev/null +++ b/OsmAnd/res/layout/note_edit_dialog.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + diff --git a/OsmAnd/res/layout/update_index.xml b/OsmAnd/res/layout/update_index.xml index cfe8dffc4c..86cccc2b0a 100644 --- a/OsmAnd/res/layout/update_index.xml +++ b/OsmAnd/res/layout/update_index.xml @@ -23,6 +23,7 @@ android:id="@+id/header" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginBottom="@dimen/list_header_padding" android:text="@string/download_tab_updates"/> diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 1f2c983951..40e895e3f1 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +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 --> + Rename recording Watch Notes Online map diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesActivity.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesActivity.java index 1b6bdc8cf4..68c551169f 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesActivity.java @@ -20,6 +20,7 @@ import android.view.MenuItem; import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import android.os.Bundle; @@ -29,6 +30,8 @@ import android.view.View; import android.widget.ImageView; import android.widget.TabHost.TabSpec; import android.widget.TextView; + +import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.audionotes.NotesFragment; import net.osmand.plus.views.controls.PagerSlidingTabStrip; @@ -79,8 +82,10 @@ public class FavoritesActivity extends TabActivity { List mTabs = new ArrayList(); mTabs.add(getTabIndicator(R.string.my_favorites, FavoritesTreeFragment.class)); mTabs.add(getTabIndicator(R.string.my_tracks, AvailableGPXFragment.class)); - - mTabs.add(getTabIndicator(R.string.notes, NotesFragment.class)); + AudioVideoNotesPlugin audioVideoNotesPlugin = OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class); + if (audioVideoNotesPlugin != null && audioVideoNotesPlugin.getAllRecordings().size() > 0){ + mTabs.add(getTabIndicator(R.string.notes, NotesFragment.class)); + } mTabs.add(getTabIndicator(R.string.selected_track, SelectedGPXFragment.class)); setViewPagerAdapter(mViewPager, mTabs); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioNotesLayer.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioNotesLayer.java index bddaff7706..81833bbc11 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioNotesLayer.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioNotesLayer.java @@ -169,10 +169,10 @@ public class AudioNotesLayer extends OsmandMapLayer implements IContextMenuProvi @Override public String getObjectName(Object o) { if(o instanceof Recording){ - if(((Recording)o).name == null) { + if(((Recording)o).getName() == null) { return view.getResources().getString(R.string.recording_default_name); } - return ((Recording)o).name; //$NON-NLS-1$ + return ((Recording)o).getName(); //$NON-NLS-1$ } return null; } diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index aa2760f35e..25e81e6984 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -137,8 +137,8 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } public File file; - public String name; + private String name; private double lat; private double lon; private long duration = -1; @@ -170,6 +170,14 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } } + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + public boolean isPhoto() { return file.getName().endsWith(IMG_EXTENSION); } @@ -301,6 +309,9 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { return additional; } + public void setDescription() { + //TODO implement setting description + } } private static void initializeRemoteControlRegistrationMethods() { diff --git a/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java index 799854651b..9ec8bbb22d 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java @@ -96,7 +96,7 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment { @Override public void onClick(View v) { getMyApplication().getSettings().setMapLocationToShow(recording.getLatitude(), recording.getLongitude(), 15, null, - recording.name != null ? recording.name : recording.getDescription(getActivity()), + recording.getName() != null ? recording.getName() : recording.getDescription(getActivity()), recording); //$NON-NLS-1$ MapActivity.launchMapActivityMoveToTop(getActivity()); } @@ -107,8 +107,8 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment { public static void getNoteView(final AudioVideoNotesPlugin.Recording recording, View view, final Context ctx, final AudioVideoNotesPlugin plugin) { - if (recording.name != null){ - ((TextView) view.findViewById(R.id.name)).setText(recording.name); + if (recording.getName() != null){ + ((TextView) view.findViewById(R.id.name)).setText(recording.getName()); ((TextView) view.findViewById(R.id.descr)).setText(recording.getDescription(ctx)); } else { ((TextView) view.findViewById(R.id.name)).setText(recording.getDescription(ctx)); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java index 85f92a6db5..1a6edf0699 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java @@ -1,5 +1,7 @@ package net.osmand.plus.audionotes; +import android.app.AlertDialog; +import android.content.DialogInterface; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.widget.PopupMenu; @@ -8,12 +10,15 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; +import android.widget.EditText; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; + import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording; import net.osmand.plus.dialogs.DirectionsDialogs; import android.support.v4.app.ListFragment; @@ -43,11 +48,12 @@ public class NotesFragment extends ListFragment { @Override public void onResume() { super.onResume(); - items = new ArrayList(plugin.getAllRecordings()); + items = new ArrayList<>(plugin.getAllRecordings()); listAdapter = new NotesAdapter(items); getListView().setAdapter(listAdapter); } + @Override public void onPause() { super.onPause(); @@ -60,7 +66,7 @@ public class NotesFragment extends ListFragment { class NotesAdapter extends ArrayAdapter { NotesAdapter(List recordingList) { - super(getActivity(), R.layout.dash_audio_video_notes_item, recordingList); + super(getActivity(), R.layout.note, recordingList); } @Override @@ -72,9 +78,10 @@ public class NotesFragment extends ListFragment { } final AudioVideoNotesPlugin.Recording recording = getItem(position); - if (recording.name != null){ - ((TextView) row.findViewById(R.id.name)).setText(recording.name); + if (recording.getName() != null){ + ((TextView) row.findViewById(R.id.name)).setText(recording.getName()); ((TextView) row.findViewById(R.id.descr)).setText(recording.getDescription(getActivity())); + row.findViewById(R.id.descr).setVisibility(View.VISIBLE); } else { ((TextView) row.findViewById(R.id.name)).setText(recording.getDescription(getActivity())); row.findViewById(R.id.descr).setVisibility(View.GONE); @@ -126,6 +133,9 @@ public class NotesFragment extends ListFragment { item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { + getMyApplication().getSettings().setMapLocationToShow(recording.getLatitude(), recording.getLongitude(), 15, null, recording.getName(), + recording); //$NON-NLS-1$ + MapActivity.launchMapActivityMoveToTop(getActivity()); return true; } }); @@ -144,6 +154,7 @@ public class NotesFragment extends ListFragment { item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { + editNote(recording); return true; } }); @@ -153,11 +164,42 @@ public class NotesFragment extends ListFragment { item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { - plugin.deleteRecording(recording); + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setMessage(R.string.recording_delete_confirm); + builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + plugin.deleteRecording(recording); + listAdapter.remove(recording); + } + }); + builder.setNegativeButton(R.string.default_buttons_cancel, null); + builder.show(); return true; } }); optionsMenu.show(); } + private void editNote(final Recording recording) { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setTitle(R.string.rename_recording); + final View v = getActivity().getLayoutInflater().inflate(R.layout.note_edit_dialog, + getListView(), false); + final EditText editText = (EditText) v.findViewById(R.id.name); + builder.setView(v); + editText.setText(recording.getName()); + builder.setNegativeButton(R.string.default_buttons_cancel, null); + builder.setPositiveButton(R.string.default_buttons_apply, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + recording.setName(editText.getText().toString()); + recording.setDescription(); + listAdapter.notifyDataSetInvalidated(); + } + }); + builder.create().show(); + editText.requestFocus(); + } + }