[bookmarks][android][ios] Invalid categories -> Expired categories

This commit is contained in:
Arsentiy Milchakov 2020-07-24 19:15:03 +03:00 committed by Anatoliy V. Tomilov
parent 18cdbf57f5
commit 540e2edd6e
11 changed files with 80 additions and 80 deletions

View file

@ -56,7 +56,7 @@ jmethodID g_catalogCustomPropertyConstructor;
jmethodID g_onPingFinishedMethod;
jmethodID g_onCheckInvalidCategoriesMethod;
jmethodID g_onCheckExpiredCategoriesMethod;
jclass g_sortedBlockClass;
jmethodID g_sortedBlockConstructor;
@ -121,8 +121,8 @@ void PrepareClassRefs(JNIEnv * env)
g_onPingFinishedMethod = jni::GetMethodID(env, bookmarkManagerInstance, "onPingFinished", "(Z)V");
g_onCheckInvalidCategoriesMethod = jni::GetMethodID(env, bookmarkManagerInstance,
"onCheckInvalidCategories", "(Z)V");
g_onCheckExpiredCategoriesMethod = jni::GetMethodID(env, bookmarkManagerInstance,
"onCheckExpiredCategories", "(Z)V");
g_longClass = jni::GetGlobalClassRef(env,"java/lang/Long");
g_longConstructor = jni::GetConstructorID(env, g_longClass, "(J)V");
@ -447,14 +447,14 @@ void OnPingFinished(JNIEnv * env, bool isSuccessful)
jni::HandleJavaException(env);
}
void OnCheckInvalidCategories(JNIEnv * env, bool hasInvalidCategories)
void OnCheckExpiredCategories(JNIEnv * env, bool hasExpiredCategories)
{
ASSERT(g_bookmarkManagerClass, ());
auto bookmarkManagerInstance = env->GetStaticObjectField(g_bookmarkManagerClass,
g_bookmarkManagerInstanceField);
env->CallVoidMethod(bookmarkManagerInstance, g_onCheckInvalidCategoriesMethod,
static_cast<jboolean>(hasInvalidCategories));
env->CallVoidMethod(bookmarkManagerInstance, g_onCheckExpiredCategoriesMethod,
static_cast<jboolean>(hasExpiredCategories));
jni::HandleJavaException(env);
}
@ -1154,27 +1154,27 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativePingBookmarkCatalo
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeCheckInvalidCategories(JNIEnv * env,
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeCheckExpiredCategories(JNIEnv * env,
jobject)
{
frm()->GetBookmarkManager().CheckInvalidCategories([env](bool hasInvalidCategories)
frm()->GetBookmarkManager().CheckExpiredCategories([env](bool hasExpiredCategories)
{
OnCheckInvalidCategories(env, hasInvalidCategories);
OnCheckExpiredCategories(env, hasExpiredCategories);
});
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeDeleteInvalidCategories(JNIEnv * env,
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeDeleteExpiredCategories(JNIEnv * env,
jobject)
{
frm()->GetBookmarkManager().DeleteInvalidCategories();
frm()->GetBookmarkManager().DeleteExpiredCategories();
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeResetInvalidCategories(JNIEnv * env,
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeResetExpiredCategories(JNIEnv * env,
jobject)
{
frm()->GetBookmarkManager().ResetInvalidCategories();
frm()->GetBookmarkManager().ResetExpiredCategories();
}
JNIEXPORT jstring JNICALL

View file

@ -42,7 +42,7 @@ class BookmarksDownloadFragmentDelegate implements Authorizer.Callback, Bookmark
private Runnable mAuthCompletionRunnable;
@NonNull
private final InvalidCategoriesListener mInvalidCategoriesListener;
private final ExpiredCategoriesListener mExpiredCategoriesListener;
@NonNull
private final Bundle mBundle;
@ -54,7 +54,7 @@ class BookmarksDownloadFragmentDelegate implements Authorizer.Callback, Bookmark
BookmarksDownloadFragmentDelegate(@NonNull Fragment fragment, @NonNull Bundle bundle)
{
mFragment = fragment;
mInvalidCategoriesListener = new InvalidCategoriesListener(fragment);
mExpiredCategoriesListener = new ExpiredCategoriesListener(fragment);
mBundle = bundle;
}
@ -72,13 +72,13 @@ class BookmarksDownloadFragmentDelegate implements Authorizer.Callback, Bookmark
{
mAuthorizer.attach(this);
mDownloadController.attach(this);
mInvalidCategoriesListener.attach(mFragment);
mExpiredCategoriesListener.attach(mFragment);
}
void onResume()
{
LOGGER.i(TAG, "Check invalid bookmark categories...");
BookmarkManager.INSTANCE.checkInvalidCategories();
BookmarkManager.INSTANCE.checkExpiredCategories();
}
void onPause()
@ -90,17 +90,17 @@ class BookmarksDownloadFragmentDelegate implements Authorizer.Callback, Bookmark
{
mAuthorizer.detach();
mDownloadController.detach();
mInvalidCategoriesListener.detach();
mExpiredCategoriesListener.detach();
}
void onCreateView(@Nullable Bundle savedInstanceState)
{
BookmarkManager.INSTANCE.addInvalidCategoriesListener(mInvalidCategoriesListener);
BookmarkManager.INSTANCE.addExpiredCategoriesListener(mExpiredCategoriesListener);
}
void onDestroyView()
{
BookmarkManager.INSTANCE.removeInvalidCategoriesListener(mInvalidCategoriesListener);
BookmarkManager.INSTANCE.removeExpiredCategoriesListener(mExpiredCategoriesListener);
}
void onSaveInstanceState(@NonNull Bundle outState)
@ -116,7 +116,7 @@ class BookmarksDownloadFragmentDelegate implements Authorizer.Callback, Bookmark
switch (requestCode)
{
case PurchaseUtils.REQ_CODE_PAY_CONTINUE_SUBSCRIPTION:
BookmarkManager.INSTANCE.resetInvalidCategories();
BookmarkManager.INSTANCE.resetExpiredCategories();
break;
case PurchaseUtils.REQ_CODE_PAY_BOOKMARK:
mDownloadController.retryDownloadBookmark();
@ -216,29 +216,29 @@ class BookmarksDownloadFragmentDelegate implements Authorizer.Callback, Bookmark
mAuthorizer.authorize(mBundle);
}
private static class InvalidCategoriesListener implements BookmarkManager.BookmarksInvalidCategoriesListener, Detachable<Fragment>
private static class ExpiredCategoriesListener implements BookmarkManager.BookmarksExpiredCategoriesListener, Detachable<Fragment>
{
@Nullable
private Fragment mFrag;
@Nullable
private Boolean mPendingInvalidCategoriesResult;
private Boolean mPendingExpiredCategoriesResult;
InvalidCategoriesListener(@NonNull Fragment fragment)
ExpiredCategoriesListener(@NonNull Fragment fragment)
{
mFrag = fragment;
}
@Override
public void onCheckInvalidCategories(boolean hasInvalidCategories)
public void onCheckExpiredCategories(boolean hasExpiredCategories)
{
LOGGER.i(TAG, "Has invalid categories: " + hasInvalidCategories);
LOGGER.i(TAG, "Has invalid categories: " + hasExpiredCategories);
if (mFrag == null)
{
mPendingInvalidCategoriesResult = hasInvalidCategories;
mPendingExpiredCategoriesResult = hasExpiredCategories;
return;
}
if (!hasInvalidCategories)
if (!hasExpiredCategories)
return;
showInvalidBookmarksDialog();
@ -271,10 +271,10 @@ class BookmarksDownloadFragmentDelegate implements Authorizer.Callback, Bookmark
public void attach(@NonNull Fragment object)
{
mFrag = object;
if (Boolean.TRUE.equals(mPendingInvalidCategoriesResult))
if (Boolean.TRUE.equals(mPendingExpiredCategoriesResult))
{
showInvalidBookmarksDialog();
mPendingInvalidCategoriesResult = null;
mPendingExpiredCategoriesResult = null;
}
}

View file

@ -34,7 +34,7 @@ class InvalidSubscriptionAlertDialogCallback implements AlertDialogCallback
Logger logger = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.BILLING);
String tag = InvalidSubscriptionAlertDialogCallback.class.getSimpleName();
logger.i(tag, "Delete invalid categories, user didn't continue subscription...");
BookmarkManager.INSTANCE.deleteInvalidCategories();
BookmarkManager.INSTANCE.deleteExpiredCategories();
}
@Override

View file

@ -98,7 +98,7 @@ public enum BookmarkManager
private final List<BookmarksCatalogPingListener> mCatalogPingListeners = new ArrayList<>();
@NonNull
private final List<BookmarksInvalidCategoriesListener> mInvalidCategoriesListeners = new ArrayList<>();
private final List<BookmarksExpiredCategoriesListener> mExpiredCategoriesListeners = new ArrayList<>();
@Nullable
private OnElevationCurrentPositionChangedListener mOnElevationCurrentPositionChangedListener;
@ -209,14 +209,14 @@ public enum BookmarkManager
mCatalogListeners.remove(listener);
}
public void addInvalidCategoriesListener(@NonNull BookmarksInvalidCategoriesListener listener)
public void addExpiredCategoriesListener(@NonNull BookmarksExpiredCategoriesListener listener)
{
mInvalidCategoriesListeners.add(listener);
mExpiredCategoriesListeners.add(listener);
}
public void removeInvalidCategoriesListener(@NonNull BookmarksInvalidCategoriesListener listener)
public void removeExpiredCategoriesListener(@NonNull BookmarksExpiredCategoriesListener listener)
{
mInvalidCategoriesListeners.remove(listener);
mExpiredCategoriesListeners.remove(listener);
}
public void addCatalogPingListener(@NonNull BookmarksCatalogPingListener listener)
@ -438,10 +438,10 @@ public enum BookmarkManager
// Called from JNI.
@SuppressWarnings("unused")
@MainThread
public void onCheckInvalidCategories(boolean hasInvalidCategories)
public void onCheckExpiredCategories(boolean hasExpiredCategories)
{
for (BookmarksInvalidCategoriesListener listener : mInvalidCategoriesListeners)
listener.onCheckInvalidCategories(hasInvalidCategories);
for (BookmarksExpiredCategoriesListener listener : mExpiredCategoriesListeners)
listener.onCheckExpiredCategories(hasExpiredCategories);
}
// Called from JNI.
@ -827,19 +827,19 @@ public enum BookmarkManager
nativePingBookmarkCatalog();
}
public void checkInvalidCategories()
public void checkExpiredCategories()
{
nativeCheckInvalidCategories();
nativeCheckExpiredCategories();
}
public void deleteInvalidCategories()
public void deleteExpiredCategories()
{
nativeDeleteInvalidCategories();
nativeDeleteExpiredCategories();
}
public void resetInvalidCategories()
public void resetExpiredCategories()
{
nativeResetInvalidCategories();
nativeResetExpiredCategories();
}
public boolean isCategoryFromCatalog(long catId)
@ -1145,9 +1145,9 @@ public enum BookmarkManager
private static native void nativePingBookmarkCatalog();
private static native void nativeCheckInvalidCategories();
private static native void nativeDeleteInvalidCategories();
private static native void nativeResetInvalidCategories();
private static native void nativeCheckExpiredCategories();
private static native void nativeDeleteExpiredCategories();
private static native void nativeResetExpiredCategories();
private native boolean nativeHasLastSortingType(long catId);
@ -1291,9 +1291,9 @@ public enum BookmarkManager
void onPingFinished(boolean isServiceAvailable);
}
public interface BookmarksInvalidCategoriesListener
public interface BookmarksExpiredCategoriesListener
{
void onCheckInvalidCategories(boolean hasInvalidCategories);
void onCheckExpiredCategories(boolean hasExpiredCategories);
}
public interface BookmarksCatalogListener

View file

@ -111,9 +111,9 @@ NS_SWIFT_NAME(BookmarksManager)
progress:(_Nullable ProgressBlock)progress
completion:(UploadCompletionBlock)completion;
- (void)ping:(PingCompletionBlock)callback;
- (void)checkForInvalidCategories:(MWMBoolBlock)completion;
- (void)deleteInvalidCategories;
- (void)resetInvalidCategories;
- (void)checkForExpiredCategories:(MWMBoolBlock)completion;
- (void)deleteExpiredCategories;
- (void)resetExpiredCategories;
- (instancetype)init __attribute__((unavailable("call +manager instead")));
- (instancetype)copy __attribute__((unavailable("call +manager instead")));

View file

@ -784,18 +784,18 @@ static kml::PredefinedColor convertBookmarkColor(MWMBookmarkColor bookmarkColor)
});
}
- (void)checkForInvalidCategories:(MWMBoolBlock)completion {
self.bm.CheckInvalidCategories([completion] (bool hasInvalidCategories) {
completion(hasInvalidCategories);
- (void)checkForExpiredCategories:(MWMBoolBlock)completion {
self.bm.CheckExpiredCategories([completion] (bool hasExpiredCategories) {
completion(hasExpiredCategories);
});
}
- (void)deleteInvalidCategories {
self.bm.DeleteInvalidCategories();
- (void)deleteExpiredCategories {
self.bm.DeleteExpiredCategories();
}
- (void)resetInvalidCategories {
self.bm.ResetInvalidCategories();
- (void)resetExpiredCategories {
self.bm.ResetExpiredCategories();
}
- (BOOL)isGuide:(MWMMarkGroupID)groupId {

View file

@ -305,7 +305,7 @@ extension PaidRouteViewController: SubscriptionManagerListener {
func didSubscribe(_ subscription: ISubscription) {
subscriptionManager.setSubscriptionActive(true)
BookmarksManager.shared().resetInvalidCategories()
BookmarksManager.shared().resetExpiredCategories()
}
func didDefer(_ subscription: ISubscription) {

View file

@ -23,7 +23,7 @@ extension UIViewController {
}
let onDelete = {
self?.dismiss(animated: true)
BookmarksManager.shared().deleteInvalidCategories()
BookmarksManager.shared().deleteExpiredCategories()
completion?(true)
}
let subscriptionExpiredDialog = SubscriptionExpiredViewController(onSubscribe: onSubscribe, onDelete: onDelete)

View file

@ -92,7 +92,7 @@ extension SubscriptionInteractor: SubscriptionManagerListener {
func didSubscribe(_ subscription: ISubscription) {
subscriptionManager.setSubscriptionActive(true)
bookmarksManager.resetInvalidCategories()
bookmarksManager.resetExpiredCategories()
}
func didDefer(_ subscription: ISubscription) {}

View file

@ -3724,45 +3724,45 @@ void BookmarkManager::EnableTestMode(bool enable)
m_testModeEnabled = enable;
}
void BookmarkManager::CheckInvalidCategories(CheckInvalidCategoriesHandler && handler)
void BookmarkManager::CheckExpiredCategories(CheckExpiredCategoriesHandler && handler)
{
CHECK_THREAD_CHECKER(m_threadChecker, ());
auto f = [this, handler = std::move(handler)](std::vector<std::string> const & serverIds)
{
CHECK_THREAD_CHECKER(m_threadChecker, ());
m_invalidCategories.clear();
m_expiredCategories.clear();
for (auto const & s : serverIds)
{
for (auto const & category : m_categories)
{
if (category.second->GetServerId() == s)
m_invalidCategories.emplace_back(category.first);
m_expiredCategories.emplace_back(category.first);
}
}
if (handler)
handler(!m_invalidCategories.empty());
handler(!m_expiredCategories.empty());
};
m_bookmarkCatalog.RequestBookmarksToDelete(m_user.GetAccessToken(), m_user.GetUserId(),
GetAllPaidCategoriesIds(), f);
}
void BookmarkManager::DeleteInvalidCategories()
void BookmarkManager::DeleteExpiredCategories()
{
CHECK_THREAD_CHECKER(m_threadChecker, ());
if (m_invalidCategories.empty())
if (m_expiredCategories.empty())
return;
auto session = GetEditSession();
for (auto const markGroupId : m_invalidCategories)
for (auto const markGroupId : m_expiredCategories)
DeleteBmCategory(markGroupId);
}
void BookmarkManager::ResetInvalidCategories()
void BookmarkManager::ResetExpiredCategories()
{
CHECK_THREAD_CHECKER(m_threadChecker, ());
m_invalidCategories.clear();
m_expiredCategories.clear();
}
void BookmarkManager::FilterInvalidBookmarks(kml::MarkIdCollection & bookmarks) const

View file

@ -416,16 +416,16 @@ public:
bool IsMyCategory(kml::MarkGroupId categoryId) const;
// CheckInvalidCategories checks invalid categories asynchronously, it prepares a state for following
// CheckExpiredCategories checks invalid categories asynchronously, it prepares a state for following
// functions calls.
using CheckInvalidCategoriesHandler = std::function<void(bool hasInvalidCategories)>;
void CheckInvalidCategories(CheckInvalidCategoriesHandler && handler);
using CheckExpiredCategoriesHandler = std::function<void(bool hasExpiredCategories)>;
void CheckExpiredCategories(CheckExpiredCategoriesHandler && handler);
// The following 2 functions allow to delete invalid categories or forget about them.
// These functions are stateful, so they must be called after finishing CheckInvalidCategoriesHandler.
// ResetInvalidCategories resets internal state.
void DeleteInvalidCategories();
void ResetInvalidCategories();
// These functions are stateful, so they must be called after finishing CheckExpiredCategoriesHandler.
// ResetExpiredCategories resets internal state.
void DeleteExpiredCategories();
void ResetExpiredCategories();
void FilterInvalidBookmarks(kml::MarkIdCollection & bookmarks) const;
void FilterInvalidTracks(kml::TrackIdCollection & tracks) const;
@ -867,7 +867,7 @@ private:
};
std::map<std::string, RestoringCache> m_restoringCache;
std::vector<kml::MarkGroupId> m_invalidCategories;
std::vector<kml::MarkGroupId> m_expiredCategories;
struct Properties