diff --git a/android/res/drawable-hdpi/ic_show.png b/android/res/drawable-hdpi/ic_show.png index 8d3a8c9f72..f33c6979ba 100644 Binary files a/android/res/drawable-hdpi/ic_show.png and b/android/res/drawable-hdpi/ic_show.png differ diff --git a/android/res/drawable-hdpi/icon_bookmark_blue.png b/android/res/drawable-hdpi/icon_bookmark_blue.png index 8b834a6e4c..9148f59eaf 100644 Binary files a/android/res/drawable-hdpi/icon_bookmark_blue.png and b/android/res/drawable-hdpi/icon_bookmark_blue.png differ diff --git a/android/res/drawable-hdpi/icon_bookmark_brown.png b/android/res/drawable-hdpi/icon_bookmark_brown.png index d97c362bd8..0fe1021123 100644 Binary files a/android/res/drawable-hdpi/icon_bookmark_brown.png and b/android/res/drawable-hdpi/icon_bookmark_brown.png differ diff --git a/android/res/drawable-hdpi/icon_bookmark_green.png b/android/res/drawable-hdpi/icon_bookmark_green.png index 2acb2cf4eb..6bc9ad4ab9 100644 Binary files a/android/res/drawable-hdpi/icon_bookmark_green.png and b/android/res/drawable-hdpi/icon_bookmark_green.png differ diff --git a/android/res/drawable-hdpi/icon_bookmark_lblue.png b/android/res/drawable-hdpi/icon_bookmark_lblue.png index 7cc4012ced..9fe29f69b0 100644 Binary files a/android/res/drawable-hdpi/icon_bookmark_lblue.png and b/android/res/drawable-hdpi/icon_bookmark_lblue.png differ diff --git a/android/res/drawable-hdpi/icon_bookmark_orange.png b/android/res/drawable-hdpi/icon_bookmark_orange.png index e01673744c..6d9cf57b01 100644 Binary files a/android/res/drawable-hdpi/icon_bookmark_orange.png and b/android/res/drawable-hdpi/icon_bookmark_orange.png differ diff --git a/android/res/drawable-hdpi/icon_bookmark_purple.png b/android/res/drawable-hdpi/icon_bookmark_purple.png index 172ca5337a..c27a000f71 100644 Binary files a/android/res/drawable-hdpi/icon_bookmark_purple.png and b/android/res/drawable-hdpi/icon_bookmark_purple.png differ diff --git a/android/res/drawable-hdpi/icon_bookmark_red.png b/android/res/drawable-hdpi/icon_bookmark_red.png index 501fc82757..badfc22b51 100644 Binary files a/android/res/drawable-hdpi/icon_bookmark_red.png and b/android/res/drawable-hdpi/icon_bookmark_red.png differ diff --git a/android/res/drawable-hdpi/icon_bookmark_yellow.png b/android/res/drawable-hdpi/icon_bookmark_yellow.png index bf0a2119c6..0f5206ea53 100644 Binary files a/android/res/drawable-hdpi/icon_bookmark_yellow.png and b/android/res/drawable-hdpi/icon_bookmark_yellow.png differ diff --git a/android/res/drawable-mdpi/ic_show.png b/android/res/drawable-mdpi/ic_show.png index 493c869c4f..d0e4a3e84e 100644 Binary files a/android/res/drawable-mdpi/ic_show.png and b/android/res/drawable-mdpi/ic_show.png differ diff --git a/android/res/drawable-mdpi/icon_bookmark_blue.png b/android/res/drawable-mdpi/icon_bookmark_blue.png index ad9094c6ed..a522bf10f1 100644 Binary files a/android/res/drawable-mdpi/icon_bookmark_blue.png and b/android/res/drawable-mdpi/icon_bookmark_blue.png differ diff --git a/android/res/drawable-mdpi/icon_bookmark_brown.png b/android/res/drawable-mdpi/icon_bookmark_brown.png index 2ea4b9ada4..6e40e76714 100644 Binary files a/android/res/drawable-mdpi/icon_bookmark_brown.png and b/android/res/drawable-mdpi/icon_bookmark_brown.png differ diff --git a/android/res/drawable-mdpi/icon_bookmark_green.png b/android/res/drawable-mdpi/icon_bookmark_green.png index 92918f1497..fafe8c6105 100644 Binary files a/android/res/drawable-mdpi/icon_bookmark_green.png and b/android/res/drawable-mdpi/icon_bookmark_green.png differ diff --git a/android/res/drawable-mdpi/icon_bookmark_lblue.png b/android/res/drawable-mdpi/icon_bookmark_lblue.png index ec328dd736..17da791df3 100644 Binary files a/android/res/drawable-mdpi/icon_bookmark_lblue.png and b/android/res/drawable-mdpi/icon_bookmark_lblue.png differ diff --git a/android/res/drawable-mdpi/icon_bookmark_orange.png b/android/res/drawable-mdpi/icon_bookmark_orange.png index 546b13de9b..cf948361e4 100644 Binary files a/android/res/drawable-mdpi/icon_bookmark_orange.png and b/android/res/drawable-mdpi/icon_bookmark_orange.png differ diff --git a/android/res/drawable-mdpi/icon_bookmark_purple.png b/android/res/drawable-mdpi/icon_bookmark_purple.png index 9635c9801b..f4074e3897 100644 Binary files a/android/res/drawable-mdpi/icon_bookmark_purple.png and b/android/res/drawable-mdpi/icon_bookmark_purple.png differ diff --git a/android/res/drawable-mdpi/icon_bookmark_red.png b/android/res/drawable-mdpi/icon_bookmark_red.png index 88a0d284f3..6cbb3e6ee9 100644 Binary files a/android/res/drawable-mdpi/icon_bookmark_red.png and b/android/res/drawable-mdpi/icon_bookmark_red.png differ diff --git a/android/res/drawable-mdpi/icon_bookmark_yellow.png b/android/res/drawable-mdpi/icon_bookmark_yellow.png index d7a1ff19fa..c39552add5 100644 Binary files a/android/res/drawable-mdpi/icon_bookmark_yellow.png and b/android/res/drawable-mdpi/icon_bookmark_yellow.png differ diff --git a/android/res/drawable-xhdpi/ic_hide.png b/android/res/drawable-xhdpi/ic_hide.png index 2a4fbe3968..b5c0eed49e 100644 Binary files a/android/res/drawable-xhdpi/ic_hide.png and b/android/res/drawable-xhdpi/ic_hide.png differ diff --git a/android/res/drawable-xhdpi/ic_show.png b/android/res/drawable-xhdpi/ic_show.png index c47795c693..f507ca4f8d 100644 Binary files a/android/res/drawable-xhdpi/ic_show.png and b/android/res/drawable-xhdpi/ic_show.png differ diff --git a/android/res/drawable-xhdpi/icon_bookmark_blue.png b/android/res/drawable-xhdpi/icon_bookmark_blue.png index a209e3c1c3..a3711a0394 100644 Binary files a/android/res/drawable-xhdpi/icon_bookmark_blue.png and b/android/res/drawable-xhdpi/icon_bookmark_blue.png differ diff --git a/android/res/drawable-xhdpi/icon_bookmark_brown.png b/android/res/drawable-xhdpi/icon_bookmark_brown.png index ceff66c137..c0877cf000 100644 Binary files a/android/res/drawable-xhdpi/icon_bookmark_brown.png and b/android/res/drawable-xhdpi/icon_bookmark_brown.png differ diff --git a/android/res/drawable-xhdpi/icon_bookmark_green.png b/android/res/drawable-xhdpi/icon_bookmark_green.png index 1bf6cc2edf..bd744971dd 100644 Binary files a/android/res/drawable-xhdpi/icon_bookmark_green.png and b/android/res/drawable-xhdpi/icon_bookmark_green.png differ diff --git a/android/res/drawable-xhdpi/icon_bookmark_lblue.png b/android/res/drawable-xhdpi/icon_bookmark_lblue.png index 05f704b3c8..b99750b777 100644 Binary files a/android/res/drawable-xhdpi/icon_bookmark_lblue.png and b/android/res/drawable-xhdpi/icon_bookmark_lblue.png differ diff --git a/android/res/drawable-xhdpi/icon_bookmark_orange.png b/android/res/drawable-xhdpi/icon_bookmark_orange.png index 9535fb23d1..e90409dc7d 100644 Binary files a/android/res/drawable-xhdpi/icon_bookmark_orange.png and b/android/res/drawable-xhdpi/icon_bookmark_orange.png differ diff --git a/android/res/drawable-xhdpi/icon_bookmark_purple.png b/android/res/drawable-xhdpi/icon_bookmark_purple.png index d96320fe8b..9749098b0c 100644 Binary files a/android/res/drawable-xhdpi/icon_bookmark_purple.png and b/android/res/drawable-xhdpi/icon_bookmark_purple.png differ diff --git a/android/res/drawable-xhdpi/icon_bookmark_red.png b/android/res/drawable-xhdpi/icon_bookmark_red.png index cef5a6a058..b1467078c7 100644 Binary files a/android/res/drawable-xhdpi/icon_bookmark_red.png and b/android/res/drawable-xhdpi/icon_bookmark_red.png differ diff --git a/android/res/drawable-xhdpi/icon_bookmark_yellow.png b/android/res/drawable-xhdpi/icon_bookmark_yellow.png index 0dd8a63261..cdea5a945b 100644 Binary files a/android/res/drawable-xhdpi/icon_bookmark_yellow.png and b/android/res/drawable-xhdpi/icon_bookmark_yellow.png differ diff --git a/android/res/drawable-xxhdpi/ic_hide.png b/android/res/drawable-xxhdpi/ic_hide.png index 9a0f416823..c9f00c8ff2 100644 Binary files a/android/res/drawable-xxhdpi/ic_hide.png and b/android/res/drawable-xxhdpi/ic_hide.png differ diff --git a/android/res/drawable-xxhdpi/ic_show.png b/android/res/drawable-xxhdpi/ic_show.png index e9e000c04c..3f06bf7d7b 100644 Binary files a/android/res/drawable-xxhdpi/ic_show.png and b/android/res/drawable-xxhdpi/ic_show.png differ diff --git a/android/res/drawable-xxhdpi/icon_bookmark_blue.png b/android/res/drawable-xxhdpi/icon_bookmark_blue.png index 1df3c130e2..8bef0043a1 100644 Binary files a/android/res/drawable-xxhdpi/icon_bookmark_blue.png and b/android/res/drawable-xxhdpi/icon_bookmark_blue.png differ diff --git a/android/res/drawable-xxhdpi/icon_bookmark_brown.png b/android/res/drawable-xxhdpi/icon_bookmark_brown.png index ebc0179976..e6d79bb962 100644 Binary files a/android/res/drawable-xxhdpi/icon_bookmark_brown.png and b/android/res/drawable-xxhdpi/icon_bookmark_brown.png differ diff --git a/android/res/drawable-xxhdpi/icon_bookmark_green.png b/android/res/drawable-xxhdpi/icon_bookmark_green.png index 8969551f22..63c59371d5 100644 Binary files a/android/res/drawable-xxhdpi/icon_bookmark_green.png and b/android/res/drawable-xxhdpi/icon_bookmark_green.png differ diff --git a/android/res/drawable-xxhdpi/icon_bookmark_lblue.png b/android/res/drawable-xxhdpi/icon_bookmark_lblue.png index 35d3b62b27..29788ab72f 100644 Binary files a/android/res/drawable-xxhdpi/icon_bookmark_lblue.png and b/android/res/drawable-xxhdpi/icon_bookmark_lblue.png differ diff --git a/android/res/drawable-xxhdpi/icon_bookmark_orange.png b/android/res/drawable-xxhdpi/icon_bookmark_orange.png index 5dae19f44b..f8cfe83b68 100644 Binary files a/android/res/drawable-xxhdpi/icon_bookmark_orange.png and b/android/res/drawable-xxhdpi/icon_bookmark_orange.png differ diff --git a/android/res/drawable-xxhdpi/icon_bookmark_purple.png b/android/res/drawable-xxhdpi/icon_bookmark_purple.png index dace7815ba..6f80c6b342 100644 Binary files a/android/res/drawable-xxhdpi/icon_bookmark_purple.png and b/android/res/drawable-xxhdpi/icon_bookmark_purple.png differ diff --git a/android/res/drawable-xxhdpi/icon_bookmark_red.png b/android/res/drawable-xxhdpi/icon_bookmark_red.png index d6f9c76aa4..ee9ca2f038 100644 Binary files a/android/res/drawable-xxhdpi/icon_bookmark_red.png and b/android/res/drawable-xxhdpi/icon_bookmark_red.png differ diff --git a/android/res/drawable-xxhdpi/icon_bookmark_yellow.png b/android/res/drawable-xxhdpi/icon_bookmark_yellow.png index df053f4000..503eb851c1 100644 Binary files a/android/res/drawable-xxhdpi/icon_bookmark_yellow.png and b/android/res/drawable-xxhdpi/icon_bookmark_yellow.png differ diff --git a/android/res/layout/edit_bookmark_set.xml b/android/res/layout/edit_bookmark_set.xml deleted file mode 100644 index a401f51cbf..0000000000 --- a/android/res/layout/edit_bookmark_set.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/android/res/layout/fragment_bookmark_categories.xml b/android/res/layout/fragment_bookmark_categories.xml index 61dde60e21..14a2a5a54a 100644 --- a/android/res/layout/fragment_bookmark_categories.xml +++ b/android/res/layout/fragment_bookmark_categories.xml @@ -1,12 +1,13 @@ + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical"> - + \ No newline at end of file diff --git a/android/res/layout/fragment_bookmarks_list.xml b/android/res/layout/fragment_bookmarks_list.xml index 7b08d38bb9..a4329feb2a 100644 --- a/android/res/layout/fragment_bookmarks_list.xml +++ b/android/res/layout/fragment_bookmarks_list.xml @@ -1,27 +1,7 @@ - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/android/res/layout/item_bookmark.xml b/android/res/layout/item_bookmark.xml new file mode 100644 index 0000000000..6de5a2a973 --- /dev/null +++ b/android/res/layout/item_bookmark.xml @@ -0,0 +1,34 @@ + + + + + + + + + + \ No newline at end of file diff --git a/android/res/layout/item_bookmark_category.xml b/android/res/layout/item_bookmark_category.xml index d15af3309a..777c3fb191 100644 --- a/android/res/layout/item_bookmark_category.xml +++ b/android/res/layout/item_bookmark_category.xml @@ -12,6 +12,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0" + android:background="@null" android:button="@drawable/btn_bookmark_visibility" android:focusable="false"/> diff --git a/android/res/layout/item_category_title.xml b/android/res/layout/item_category_title.xml new file mode 100644 index 0000000000..5c0e085d1e --- /dev/null +++ b/android/res/layout/item_category_title.xml @@ -0,0 +1,10 @@ + + \ No newline at end of file diff --git a/android/res/layout/list_item_track.xml b/android/res/layout/item_track.xml similarity index 87% rename from android/res/layout/list_item_track.xml rename to android/res/layout/item_track.xml index de5d50aaae..d3305306ca 100644 --- a/android/res/layout/list_item_track.xml +++ b/android/res/layout/item_track.xml @@ -7,7 +7,7 @@ android:paddingRight="3dp" > - - - - - - - - - \ No newline at end of file diff --git a/android/res/layout/list_separator_base.xml b/android/res/layout/list_separator_base.xml deleted file mode 100644 index 4ed5915a4d..0000000000 --- a/android/res/layout/list_separator_base.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/android/src/com/mapswithme/maps/base/BaseMwmFragmentActivity.java b/android/src/com/mapswithme/maps/base/BaseMwmFragmentActivity.java index 88b97ce7b2..63823bb50f 100644 --- a/android/src/com/mapswithme/maps/base/BaseMwmFragmentActivity.java +++ b/android/src/com/mapswithme/maps/base/BaseMwmFragmentActivity.java @@ -1,11 +1,9 @@ package com.mapswithme.maps.base; -import android.app.Activity; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; -import android.view.inputmethod.InputMethodManager; import com.mapswithme.maps.MWMApplication; import com.mapswithme.maps.R; @@ -47,8 +45,6 @@ public class BaseMwmFragmentActivity extends AppCompatActivity { if (item.getItemId() == android.R.id.home) { - final InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE); - imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); onBackPressed(); return true; } diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesFragment.java b/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesFragment.java index 0a8fe66d85..4cf98171a2 100644 --- a/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesFragment.java +++ b/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesFragment.java @@ -17,6 +17,7 @@ import com.mapswithme.maps.bookmarks.data.BookmarkManager; public class BookmarkCategoriesFragment extends BaseMwmListFragment { private int mSelectedPosition; + private BookmarkCategoriesAdapter mAdapter; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) @@ -29,10 +30,23 @@ public class BookmarkCategoriesFragment extends BaseMwmListFragment { super.onViewCreated(view, savedInstanceState); - setListAdapter(new BookmarkCategoriesAdapter(getActivity())); + initAdapter(); + setListAdapter(mAdapter); registerForContextMenu(getListView()); } + private void initAdapter() + { + mAdapter = new BookmarkCategoriesAdapter(getActivity()); + } + + @Override + public void onResume() + { + super.onResume(); + mAdapter.notifyDataSetChanged(); + } + @Override public void onListItemClick(ListView l, View v, int position, long id) { diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java b/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java index 79f8b3ae12..9d5ecd4a25 100644 --- a/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java +++ b/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java @@ -20,9 +20,7 @@ import com.mapswithme.maps.location.LocationHelper; import com.mapswithme.util.UiUtils; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; public class BookmarkListAdapter extends BaseAdapter @@ -31,8 +29,13 @@ public class BookmarkListAdapter extends BaseAdapter private final Activity mActivity; private final BookmarkCategory mCategory; - // reuse drawables - private final Map mBmkToCircle = new HashMap(8); + // view types + static final int TYPE_TRACK = 0; + static final int TYPE_BOOKMARK = 1; + static final int TYPE_SECTION = 2; + + private static final int SECTION_TRACKS = 0; + private static final int SECTION_BMKS = 1; public BookmarkListAdapter(Activity activity, BookmarkCategory cat) { @@ -56,10 +59,6 @@ public class BookmarkListAdapter extends BaseAdapter return 3; // bookmark + track + section } - final static int TYPE_TRACK = 0; - final static int TYPE_BMK = 1; - final static int TYPE_SECTION = 2; - @Override public int getItemViewType(int position) { @@ -70,13 +69,19 @@ public class BookmarkListAdapter extends BaseAdapter return TYPE_SECTION; if (position > bmkPos && !isSectionEmpty(SECTION_BMKS)) - return TYPE_BMK; + return TYPE_BOOKMARK; else if (position > trackPos && !isSectionEmpty(SECTION_TRACKS)) return TYPE_TRACK; throw new IllegalArgumentException("Position not found: " + position); } + @Override + public boolean isEnabled(int position) + { + return getItemViewType(position) != TYPE_SECTION; + } + @Override public View getView(int position, View convertView, ViewGroup parent) { @@ -84,35 +89,27 @@ public class BookmarkListAdapter extends BaseAdapter if (type == TYPE_SECTION) { - View sectionView = null; - TextView sectionName = null; + TextView sectionView; if (convertView == null) - { - sectionView = LayoutInflater.from(mActivity).inflate(R.layout.list_separator_base, null); - sectionName = (TextView) sectionView.findViewById(R.id.text); - sectionView.setTag(sectionName); - } + sectionView = (TextView) LayoutInflater.from(mActivity).inflate(R.layout.item_category_title, parent, false); else - { - sectionView = convertView; - sectionName = (TextView) sectionView.getTag(); - } + sectionView = (TextView) convertView; final int sectionIndex = getSectionForPosition(position); - sectionName.setText(getSections().get(sectionIndex)); + sectionView.setText(getSections().get(sectionIndex)); return sectionView; } if (convertView == null) { - final int id = (type == TYPE_BMK) ? R.layout.list_item_bookmark : R.layout.list_item_track; - convertView = LayoutInflater.from(mActivity).inflate(id, null); + final int id = (type == TYPE_BOOKMARK) ? R.layout.item_bookmark : R.layout.item_track; + convertView = LayoutInflater.from(mActivity).inflate(id, parent, false); convertView.setTag(new PinHolder(convertView)); } final PinHolder holder = (PinHolder) convertView.getTag(); - if (type == TYPE_BMK) + if (type == TYPE_BOOKMARK) holder.set((Bookmark) getItem(position)); else holder.set((Track) getItem(position)); @@ -169,9 +166,9 @@ public class BookmarkListAdapter extends BaseAdapter public PinHolder(View convertView) { - icon = (ImageView) convertView.findViewById(R.id.pi_pin_color); - name = (TextView) convertView.findViewById(R.id.pi_name); - distance = (TextView) convertView.findViewById(R.id.pi_distance); + icon = (ImageView) convertView.findViewById(R.id.iv__bookmark_color); + name = (TextView) convertView.findViewById(R.id.tv__bookmark_name); + distance = (TextView) convertView.findViewById(R.id.tv__bookmark_distance); } void setName(Bookmark bmk) @@ -201,22 +198,9 @@ public class BookmarkListAdapter extends BaseAdapter distance.setText(mActivity.getString(R.string.length) + " " + trk.getLengthString()); } - void setIcon(Bookmark bmk) + void setIcon(Bookmark bookmark) { - final String key = bmk.getIcon().getType(); - Drawable circle = null; - - if (!mBmkToCircle.containsKey(key)) - { - final Resources res = mActivity.getResources(); - final int circleSize = (int) (res.getDimension(R.dimen.circle_size) + .5); - circle = UiUtils.drawCircleForPin(key, circleSize, res); - mBmkToCircle.put(key, circle); - } - else - circle = mBmkToCircle.get(key); - - icon.setImageDrawable(circle); + icon.setImageResource(bookmark.getIcon().getSelectedResId()); } void setIcon(Track trk) @@ -243,9 +227,6 @@ public class BookmarkListAdapter extends BaseAdapter } } - private final static int SECTION_TRACKS = 0; - private final static int SECTION_BMKS = 1; - private int getTracksSectionPosition() { if (isSectionEmpty(SECTION_TRACKS)) diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarksListFragment.java b/android/src/com/mapswithme/maps/bookmarks/BookmarksListFragment.java index e834486771..6c6fb911da 100644 --- a/android/src/com/mapswithme/maps/bookmarks/BookmarksListFragment.java +++ b/android/src/com/mapswithme/maps/bookmarks/BookmarksListFragment.java @@ -6,8 +6,6 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; -import android.text.Editable; -import android.text.TextWatcher; import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; @@ -17,7 +15,6 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; -import android.widget.EditText; import android.widget.ListView; import com.mapswithme.maps.Framework; @@ -34,61 +31,99 @@ import com.mapswithme.util.ShareAction; public class BookmarksListFragment extends BaseMwmListFragment { - public static final String TAG = "BookmarkListActivity"; + public static final String TAG = BookmarksListFragment.class.getSimpleName(); + private static final int ID_SEND_BY_EMAIL = 0x01; + private static final int MENU_DELETE_TRACK = 0x42; - private EditText mSetName; - private BookmarkCategory mEditedSet; + private BookmarkCategory mCategory; + private int mCategoryIndex; private int mSelectedPosition; - private BookmarkListAdapter mPinAdapter; - private int mIndex; + private BookmarkListAdapter mAdapter; + private ActionBar mActionBar; - // Menu routines - static final int ID_SEND_BY_EMAIL = 0x01; - static final int MENU_DELETE_TRACK = 0x42; - - @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) - { - final ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_bookmarks_list, container, false); - setUpViews(root); - return root; - } - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) - { - super.onViewCreated(view, savedInstanceState); - createListAdapter(); - registerForContextMenu(getListView()); - setHasOptionsMenu(true); - if (getActivity() instanceof AppCompatActivity) - mActionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); - } - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - // Initialize with passed edited set. - mIndex = getArguments().getInt(ChooseBookmarkCategoryActivity.BOOKMARK_SET, -1); - mEditedSet = BookmarkManager.INSTANCE.getCategoryById(mIndex); + mCategoryIndex = getArguments().getInt(ChooseBookmarkCategoryActivity.BOOKMARK_SET, -1); + mCategory = BookmarkManager.INSTANCE.getCategoryById(mCategoryIndex); + } + + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) + { + return inflater.inflate(R.layout.fragment_bookmarks_list, container, false); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) + { + super.onViewCreated(view, savedInstanceState); + initListAdapter(); + setListAdapter(mAdapter); + registerForContextMenu(getListView()); + setHasOptionsMenu(true); + if (getActivity() instanceof AppCompatActivity) + { + mActionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); + mActionBar.setTitle(mCategory.getName()); + } + } + + @Override + public void onStart() + { + super.onStart(); + + mAdapter.notifyDataSetChanged(); + } + + @Override + public void onResume() + { + super.onResume(); + + mAdapter.startLocationUpdate(); + } + + + @Override + public void onPause() + { + super.onPause(); + + mAdapter.stopLocationUpdate(); + } + + private void initListAdapter() + { + mAdapter = new BookmarkListAdapter(getActivity(), mCategory); + mAdapter.startLocationUpdate(); + } + + private void assignCategoryParams() + { + // TODO add dialog to edit category name +// final String name = mSetName.getText().toString(); +// if (!name.equals(mCategory.getName())) +// BookmarkManager.INSTANCE.setCategoryName(mCategory, name); } @Override public void onListItemClick(ListView l, View v, int position, long id) { - switch (mPinAdapter.getItemViewType(position)) + switch (mAdapter.getItemViewType(position)) { case BookmarkListAdapter.TYPE_SECTION: return; - case BookmarkListAdapter.TYPE_BMK: - final Bookmark bmk = (Bookmark) mPinAdapter.getItem(position); - BookmarkManager.INSTANCE.showBookmarkOnMap(mIndex, bmk.getBookmarkId()); + case BookmarkListAdapter.TYPE_BOOKMARK: + final Bookmark bookmark = (Bookmark) mAdapter.getItem(position); + BookmarkManager.INSTANCE.showBookmarkOnMap(mCategoryIndex, bookmark.getBookmarkId()); break; case BookmarkListAdapter.TYPE_TRACK: - final Track track = (Track) mPinAdapter.getItem(position); + final Track track = (Track) mAdapter.getItem(position); Framework.nativeShowTrackRect(track.getCategoryId(), track.getTrackId()); break; } @@ -98,68 +133,26 @@ public class BookmarksListFragment extends BaseMwmListFragment startActivity(i); } - private void createListAdapter() - { - mPinAdapter = new BookmarkListAdapter(getActivity(), mEditedSet); - - setListAdapter(mPinAdapter); - - mPinAdapter.startLocationUpdate(); - } - - private void assignCategoryParams() - { - final String name = mSetName.getText().toString(); - if (!name.equals(mEditedSet.getName())) - BookmarkManager.INSTANCE.setCategoryName(mEditedSet, name); - } - - private void setUpViews(ViewGroup root) - { - mSetName = (EditText) root.findViewById(R.id.pin_set_name); - mSetName.setText(mEditedSet.getName()); - mSetName.addTextChangedListener(new TextWatcher() - { - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) - { - // Note! Do not set actual name here - saving process may be too long - // see assignCategoryParams() instead. - if (mActionBar != null) - mActionBar.setTitle(s); - } - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) {} - - @Override - public void afterTextChanged(Editable s) {} - }); - } - @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { - assignCategoryParams(); - - // Some list views can be section delimiters. if (menuInfo instanceof AdapterView.AdapterContextMenuInfo) { final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; mSelectedPosition = info.position; - final Object obj = mPinAdapter.getItem(mSelectedPosition); - final int type = mPinAdapter.getItemViewType(mSelectedPosition); + final Object obj = mAdapter.getItem(mSelectedPosition); + final int type = mAdapter.getItemViewType(mSelectedPosition); - if (type == BookmarkListAdapter.TYPE_BMK) + if (type == BookmarkListAdapter.TYPE_BOOKMARK) { final MenuInflater inflater = getActivity().getMenuInflater(); inflater.inflate(R.menu.pin_sets_context_menu, menu); - for (final ShareAction sa : ShareAction.ACTIONS.values()) + for (final ShareAction action : ShareAction.ACTIONS.values()) { - if (sa.isSupported(getActivity())) - menu.add(Menu.NONE, sa.getId(), sa.getId(), getResources().getString(sa.getNameResId())); + if (action.isSupported(getActivity())) + menu.add(Menu.NONE, action.getId(), action.getId(), getResources().getString(action.getNameResId())); } menu.setHeaderTitle(((Bookmark) obj).getName()); @@ -178,16 +171,16 @@ public class BookmarksListFragment extends BaseMwmListFragment public boolean onContextItemSelected(MenuItem item) { final int itemId = item.getItemId(); - final Object obj = mPinAdapter.getItem(mSelectedPosition); + final Object obj = mAdapter.getItem(mSelectedPosition); if (itemId == R.id.set_edit) { - startPinActivity(mEditedSet.getId(), ((Bookmark) obj).getBookmarkId()); + startPinActivity(mCategory.getId(), ((Bookmark) obj).getBookmarkId()); } else if (itemId == R.id.set_delete) { BookmarkManager.INSTANCE.deleteBookmark((Bookmark) obj); - mPinAdapter.notifyDataSetChanged(); + mAdapter.notifyDataSetChanged(); } else if (ShareAction.ACTIONS.containsKey(itemId)) { @@ -197,7 +190,7 @@ public class BookmarksListFragment extends BaseMwmListFragment else if (itemId == MENU_DELETE_TRACK) { BookmarkManager.INSTANCE.deleteTrack((Track) obj); - mPinAdapter.notifyDataSetChanged(); + mAdapter.notifyDataSetChanged(); } return super.onContextItemSelected(item); @@ -209,38 +202,10 @@ public class BookmarksListFragment extends BaseMwmListFragment .putExtra(ChooseBookmarkCategoryActivity.BOOKMARK, new ParcelablePoint(cat, bmk))); } - @Override - public void onResume() - { - super.onResume(); - - mPinAdapter.startLocationUpdate(); - } - - @Override - public void onStart() - { - super.onStart(); - - mPinAdapter.notifyDataSetChanged(); - } - - @Override - public void onPause() - { - assignCategoryParams(); - - mPinAdapter.stopLocationUpdate(); - - super.onPause(); - } - private void sendBookmarkMail() { - assignCategoryParams(); - String path = MWMApplication.get().getTempPath(); - final String name = BookmarkManager.INSTANCE.saveToKmzFile(mEditedSet.getId(), path); + final String name = BookmarkManager.INSTANCE.saveToKmzFile(mCategory.getId(), path); if (name == null) { // some error occurred @@ -268,7 +233,7 @@ public class BookmarksListFragment extends BaseMwmListFragment @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { -// + // TODO add options menu } @Override