[bookmarks] Add sorting bookmarks and tracks by name
Signed-off-by: Simon Klüber <48260138+sklueber@users.noreply.github.com>
This commit is contained in:
parent
6f2df3c1c1
commit
97901999c8
7 changed files with 128 additions and 4 deletions
|
@ -74,6 +74,8 @@ public class ChooseBookmarksSortingTypeFragment extends BaseMwmDialogFragment
|
|||
return R.id.sort_by_distance;
|
||||
case BookmarkManager.SORT_BY_TIME:
|
||||
return R.id.sort_by_time;
|
||||
case BookmarkManager.SORT_BY_NAME:
|
||||
return R.id.sort_by_name;
|
||||
}
|
||||
}
|
||||
return R.id.sort_by_default;
|
||||
|
@ -88,7 +90,7 @@ public class ChooseBookmarksSortingTypeFragment extends BaseMwmDialogFragment
|
|||
if (args == null)
|
||||
throw new AssertionError("Arguments of choose sorting type view can't be null.");
|
||||
|
||||
UiUtils.hide(view, R.id.sort_by_type, R.id.sort_by_distance, R.id.sort_by_time);
|
||||
UiUtils.hide(view, R.id.sort_by_type, R.id.sort_by_distance, R.id.sort_by_time, R.id.sort_by_name);
|
||||
|
||||
@BookmarkManager.SortingType
|
||||
int[] availableSortingTypes = args.getIntArray(EXTRA_SORTING_TYPES);
|
||||
|
@ -151,5 +153,7 @@ public class ChooseBookmarksSortingTypeFragment extends BaseMwmDialogFragment
|
|||
setSortingType(BookmarkManager.SORT_BY_DISTANCE);
|
||||
else if (id == R.id.sort_by_time)
|
||||
setSortingType(BookmarkManager.SORT_BY_TIME);
|
||||
else if (id == R.id.sort_by_name)
|
||||
setSortingType(BookmarkManager.SORT_BY_NAME);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,12 +63,13 @@ public enum BookmarkManager
|
|||
public static final int CLOUD_NOT_ENOUGH_DISK_SPACE = 2;
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({ SORT_BY_TYPE, SORT_BY_DISTANCE, SORT_BY_TIME })
|
||||
@IntDef({ SORT_BY_TYPE, SORT_BY_DISTANCE, SORT_BY_TIME, SORT_BY_NAME })
|
||||
public @interface SortingType {}
|
||||
|
||||
public static final int SORT_BY_TYPE = 0;
|
||||
public static final int SORT_BY_DISTANCE = 1;
|
||||
public static final int SORT_BY_TIME = 2;
|
||||
public static final int SORT_BY_NAME = 3;
|
||||
|
||||
// These values have to match the values of kml::CompilationType from kml/types.hpp
|
||||
public static final int CATEGORY = 0;
|
||||
|
|
|
@ -34,6 +34,15 @@
|
|||
android:checked="true"
|
||||
android:text="@string/by_default"/>
|
||||
|
||||
<RadioButton
|
||||
style="?fontSubtitle1"
|
||||
android:id="@+id/sort_by_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/margin_half_double_plus"
|
||||
android:checked="false"
|
||||
android:text="@string/by_name"/>
|
||||
|
||||
<RadioButton
|
||||
style="?fontSubtitle1"
|
||||
android:id="@+id/sort_by_type"
|
||||
|
|
|
@ -716,6 +716,8 @@
|
|||
<string name="by_distance">By distance</string>
|
||||
<!-- Android -->
|
||||
<string name="by_date">By date</string>
|
||||
<!-- Android -->
|
||||
<string name="by_name">By name</string>
|
||||
<string name="week_ago_sorttype">A week ago</string>
|
||||
<string name="month_ago_sorttype">A month ago</string>
|
||||
<string name="moremonth_ago_sorttype">More than a month ago</string>
|
||||
|
|
|
@ -24991,6 +24991,52 @@
|
|||
zh-Hans = 按时间
|
||||
zh-Hant = 按時間
|
||||
|
||||
[by_name]
|
||||
comment = Android
|
||||
tags = android
|
||||
en = By name
|
||||
af = Op Naam
|
||||
ar = بالاسم
|
||||
az = Ada görə
|
||||
be = Па імені
|
||||
bg = По име
|
||||
ca = Per nom
|
||||
cs = Podle jména
|
||||
da = efter navn
|
||||
de = Nach Name
|
||||
el = Με όνομα
|
||||
es = Por nombre
|
||||
es-MX = Por nombre
|
||||
et = Nime järgi
|
||||
eu = Izenaren arabera
|
||||
fa = بر اساس اسم
|
||||
fi = Nimen mukaan
|
||||
fr = Par nom
|
||||
he = לפי שם
|
||||
hi = नाम द्वारा
|
||||
hu = Név szerint
|
||||
id = Berdasarkan Nama
|
||||
it = Per nome
|
||||
ja = 名前で
|
||||
ko = 이름별
|
||||
lt = Pagal pavadinimą
|
||||
mr = नावाने
|
||||
nb = Etter navn
|
||||
nl = Op naam
|
||||
pl = Według nazwy
|
||||
pt = Por nome
|
||||
ro = După nume
|
||||
ru = По имени
|
||||
sk = Podľa mena
|
||||
sv = Efter namn
|
||||
sw = Kwa Jina
|
||||
th = ตามชื่อ
|
||||
tr = İsme göre
|
||||
uk = За назвою
|
||||
vi = Theo Tên
|
||||
zh-Hans = 按名称
|
||||
zh-Hant = 按名字
|
||||
|
||||
[week_ago_sorttype]
|
||||
tags = android,ios
|
||||
en = A week ago
|
||||
|
|
|
@ -103,6 +103,7 @@ std::string ToString(BookmarkManager::SortingType type)
|
|||
case BookmarkManager::SortingType::ByTime: return "ByTime";
|
||||
case BookmarkManager::SortingType::ByType: return "ByType";
|
||||
case BookmarkManager::SortingType::ByDistance: return "ByDistance";
|
||||
case BookmarkManager::SortingType::ByName: return "ByName";
|
||||
}
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
@ -115,6 +116,8 @@ bool GetSortingType(std::string const & typeStr, BookmarkManager::SortingType &
|
|||
type = BookmarkManager::SortingType::ByType;
|
||||
else if (typeStr == ToString(BookmarkManager::SortingType::ByDistance))
|
||||
type = BookmarkManager::SortingType::ByDistance;
|
||||
else if (typeStr == ToString(BookmarkManager::SortingType::ByName))
|
||||
type = BookmarkManager::SortingType::ByName;
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
|
@ -544,7 +547,8 @@ std::vector<BookmarkManager::SortingType> BookmarkManager::GetAvailableSortingTy
|
|||
sortingTypes.push_back(SortingType::ByDistance);
|
||||
if (byTimeChecked)
|
||||
sortingTypes.push_back(SortingType::ByTime);
|
||||
|
||||
// sorting by name should always be possible
|
||||
sortingTypes.push_back(SortingType::ByName);
|
||||
return sortingTypes;
|
||||
}
|
||||
|
||||
|
@ -591,6 +595,12 @@ std::string BookmarkManager::GetTracksSortedBlockName()
|
|||
return platform::GetLocalizedString("tracks_title");
|
||||
}
|
||||
|
||||
// static
|
||||
std::string BookmarkManager::GetBookmarksSortedBlockName()
|
||||
{
|
||||
return platform::GetLocalizedString("bookmarks");
|
||||
}
|
||||
|
||||
// static
|
||||
std::string BookmarkManager::GetOthersSortedBlockName()
|
||||
{
|
||||
|
@ -1035,6 +1045,16 @@ void BookmarkManager::SortTracksByTime(std::vector<SortTrackData> & tracks)
|
|||
});
|
||||
}
|
||||
|
||||
// static
|
||||
void BookmarkManager::SortTracksByName(std::vector<SortTrackData> & tracks)
|
||||
{
|
||||
std::sort(tracks.begin(), tracks.end(),
|
||||
[](SortTrackData const & lbm, SortTrackData const & rbm)
|
||||
{
|
||||
return lbm.m_name < rbm.m_name;
|
||||
});
|
||||
}
|
||||
|
||||
void BookmarkManager::SortByDistance(std::vector<SortBookmarkData> const & bookmarksForSort,
|
||||
std::vector<SortTrackData> const & tracksForSort,
|
||||
m2::PointD const & myPosition,
|
||||
|
@ -1231,6 +1251,35 @@ void BookmarkManager::SortByType(std::vector<SortBookmarkData> const & bookmarks
|
|||
}
|
||||
}
|
||||
|
||||
void BookmarkManager::SortByName(std::vector<SortBookmarkData> const & bookmarksForSort,
|
||||
std::vector<SortTrackData> const & tracksForSort,
|
||||
SortedBlocksCollection & sortedBlocks)
|
||||
{
|
||||
std::vector<SortTrackData> sortedTracks = tracksForSort;
|
||||
SortTracksByName(sortedTracks);
|
||||
AddTracksSortedBlock(sortedTracks, sortedBlocks);
|
||||
|
||||
std::vector<SortBookmarkData const *> sortedMarks;
|
||||
sortedMarks.reserve(bookmarksForSort.size());
|
||||
for (auto const & mark : bookmarksForSort)
|
||||
sortedMarks.push_back(&mark);
|
||||
|
||||
std::sort(sortedMarks.begin(), sortedMarks.end(),
|
||||
[](SortBookmarkData const * lbm, SortBookmarkData const * rbm)
|
||||
{
|
||||
return lbm->m_name < rbm->m_name;
|
||||
});
|
||||
|
||||
// Put all bookmarks into one block
|
||||
SortedBlock bookmarkBlock;
|
||||
bookmarkBlock.m_blockName = GetBookmarksSortedBlockName();
|
||||
for (auto mark : sortedMarks)
|
||||
{
|
||||
bookmarkBlock.m_markIds.push_back(mark->m_id);
|
||||
}
|
||||
sortedBlocks.push_back(bookmarkBlock);
|
||||
}
|
||||
|
||||
void BookmarkManager::GetSortedCategoryImpl(SortParams const & params,
|
||||
std::vector<SortBookmarkData> const & bookmarksForSort,
|
||||
std::vector<SortTrackData> const & tracksForSort,
|
||||
|
@ -1248,6 +1297,9 @@ void BookmarkManager::GetSortedCategoryImpl(SortParams const & params,
|
|||
case SortingType::ByType:
|
||||
SortByType(bookmarksForSort, tracksForSort, sortedBlocks);
|
||||
return;
|
||||
case SortingType::ByName:
|
||||
SortByName(bookmarksForSort, tracksForSort, sortedBlocks);
|
||||
return;
|
||||
}
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
|
|
@ -222,7 +222,8 @@ public:
|
|||
{
|
||||
ByType,
|
||||
ByDistance,
|
||||
ByTime
|
||||
ByTime,
|
||||
ByName
|
||||
};
|
||||
|
||||
struct SortedBlock
|
||||
|
@ -368,6 +369,7 @@ public:
|
|||
void CreateCategories(KMLDataCollection && dataCollection, bool autoSave = false);
|
||||
|
||||
static std::string GetTracksSortedBlockName();
|
||||
static std::string GetBookmarksSortedBlockName();
|
||||
static std::string GetOthersSortedBlockName();
|
||||
static std::string GetNearMeSortedBlockName();
|
||||
enum class SortedByTimeBlockType : uint32_t
|
||||
|
@ -631,6 +633,7 @@ private:
|
|||
{
|
||||
SortBookmarkData(kml::BookmarkData const & bmData, search::ReverseGeocoder::RegionAddress const & address)
|
||||
: m_id(bmData.m_id)
|
||||
, m_name(GetPreferredBookmarkName(bmData))
|
||||
, m_point(bmData.m_point)
|
||||
, m_type(GetBookmarkBaseType(bmData.m_featureTypes))
|
||||
, m_timestamp(bmData.m_timestamp)
|
||||
|
@ -638,6 +641,7 @@ private:
|
|||
{}
|
||||
|
||||
kml::MarkId m_id;
|
||||
std::string m_name;
|
||||
m2::PointD m_point;
|
||||
BookmarkBaseType m_type;
|
||||
kml::Timestamp m_timestamp;
|
||||
|
@ -648,10 +652,12 @@ private:
|
|||
{
|
||||
explicit SortTrackData(kml::TrackData const & trackData)
|
||||
: m_id(trackData.m_id)
|
||||
, m_name(GetPreferredBookmarkStr(trackData.m_name))
|
||||
, m_timestamp(trackData.m_timestamp)
|
||||
{}
|
||||
|
||||
kml::TrackId m_id;
|
||||
std::string m_name;
|
||||
kml::Timestamp m_timestamp;
|
||||
};
|
||||
|
||||
|
@ -669,6 +675,9 @@ private:
|
|||
static void SortByType(std::vector<SortBookmarkData> const & bookmarksForSort,
|
||||
std::vector<SortTrackData> const & tracksForSort,
|
||||
SortedBlocksCollection & sortedBlocks);
|
||||
static void SortByName(std::vector<SortBookmarkData> const & bookmarksForSort,
|
||||
std::vector<SortTrackData> const & tracksForSort,
|
||||
SortedBlocksCollection & sortedBlocks);
|
||||
|
||||
using AddressesCollection = std::vector<std::pair<kml::MarkId, search::ReverseGeocoder::RegionAddress>>;
|
||||
void PrepareBookmarksAddresses(std::vector<SortBookmarkData> & bookmarksForSort, AddressesCollection & newAddresses);
|
||||
|
@ -676,6 +685,7 @@ private:
|
|||
void SetBookmarksAddresses(AddressesCollection const & addresses);
|
||||
static void AddTracksSortedBlock(std::vector<SortTrackData> const & sortedTracks, SortedBlocksCollection & sortedBlocks);
|
||||
static void SortTracksByTime(std::vector<SortTrackData> & tracks);
|
||||
static void SortTracksByName(std::vector<SortTrackData> & tracks);
|
||||
|
||||
kml::MarkId GetTrackSelectionMarkId(kml::TrackId trackId) const;
|
||||
int GetTrackSelectionMarkMinZoom(kml::TrackId trackId) const;
|
||||
|
|
Reference in a new issue