forked from organicmaps/organicmaps
[android][notifications] review fixes
This commit is contained in:
parent
fbb9c755d9
commit
250d45831f
11 changed files with 78 additions and 38 deletions
|
@ -2677,10 +2677,11 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
|
||||
public static class ShowUGCEditorTask implements MapTask
|
||||
{
|
||||
private static final long serialVersionUID = 1636712824900113568L;
|
||||
@NonNull
|
||||
private NotificationCandidate.MapObject mMapObject;
|
||||
private final NotificationCandidate.MapObject mMapObject;
|
||||
|
||||
public ShowUGCEditorTask(@NonNull NotificationCandidate.MapObject mapObject)
|
||||
ShowUGCEditorTask(@NonNull NotificationCandidate.MapObject mapObject)
|
||||
{
|
||||
mMapObject = mapObject;
|
||||
}
|
||||
|
|
|
@ -85,6 +85,7 @@ public class MwmApplication extends Application
|
|||
sSelf = this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static MwmApplication get()
|
||||
{
|
||||
return sSelf;
|
||||
|
@ -160,7 +161,7 @@ public class MwmApplication extends Application
|
|||
private void initNotificationChannels()
|
||||
{
|
||||
NotificationChannelProvider channelProvider = NotificationChannelFactory.createProvider(this);
|
||||
channelProvider.setAuthChannel();
|
||||
channelProvider.setUGCChannel();
|
||||
channelProvider.setDownloadingChannel();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package com.mapswithme.maps.background;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
|
@ -19,18 +20,33 @@ public class NotificationCandidate
|
|||
@IntDef({ TYPE_UGC_AUTH, TYPE_UGC_REVIEW })
|
||||
@interface NotificationType {}
|
||||
|
||||
public static class MapObject implements Serializable
|
||||
public static class MapObject implements Parcelable
|
||||
{
|
||||
private final double mMercatorPosX;
|
||||
private final double mMercatorPosY;
|
||||
@NonNull
|
||||
private final String mReadableName;
|
||||
|
||||
@NonNull
|
||||
private final String mDefaultName;
|
||||
@NonNull
|
||||
private final String mBestType;
|
||||
|
||||
public static final Creator<MapObject> CREATOR = new Creator<MapObject>()
|
||||
{
|
||||
@Override
|
||||
public MapObject createFromParcel(Parcel in)
|
||||
{
|
||||
return new MapObject(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapObject[] newArray(int size)
|
||||
{
|
||||
return new MapObject[size];
|
||||
}
|
||||
};
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
MapObject(double posX, double posY, @NonNull String readableName, @NonNull String defaultName,
|
||||
@NonNull String bestType)
|
||||
{
|
||||
|
@ -41,6 +57,31 @@ public class NotificationCandidate
|
|||
mBestType = bestType;
|
||||
}
|
||||
|
||||
protected MapObject(Parcel in)
|
||||
{
|
||||
mMercatorPosX = in.readDouble();
|
||||
mMercatorPosY = in.readDouble();
|
||||
mReadableName = in.readString();
|
||||
mDefaultName = in.readString();
|
||||
mBestType = in.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags)
|
||||
{
|
||||
dest.writeDouble(mMercatorPosX);
|
||||
dest.writeDouble(mMercatorPosY);
|
||||
dest.writeString(mReadableName);
|
||||
dest.writeString(mDefaultName);
|
||||
dest.writeString(mBestType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public double getMercatorPosX()
|
||||
{
|
||||
|
|
|
@ -5,9 +5,9 @@ import android.support.annotation.NonNull;
|
|||
public interface NotificationChannelProvider
|
||||
{
|
||||
@NonNull
|
||||
String getAuthChannel();
|
||||
String getUGCChannel();
|
||||
|
||||
void setAuthChannel();
|
||||
void setUGCChannel();
|
||||
|
||||
@NonNull
|
||||
String getDownloadingChannel();
|
||||
|
|
|
@ -74,11 +74,8 @@ public class NotificationService extends JobIntentService
|
|||
|
||||
private boolean notifySmart()
|
||||
{
|
||||
if (!PermissionsUtils.isExternalStorageGranted()
|
||||
|| MwmApplication.backgroundTracker(getApplication()).isForeground())
|
||||
{
|
||||
if (MwmApplication.backgroundTracker(getApplication()).isForeground())
|
||||
return false;
|
||||
}
|
||||
|
||||
NotificationCandidate candidate = LightFramework.nativeGetNotification();
|
||||
|
||||
|
@ -101,10 +98,10 @@ public class NotificationService extends JobIntentService
|
|||
final String action = intent.getAction();
|
||||
|
||||
if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action))
|
||||
TryToShowNotification();
|
||||
tryToShowNotification();
|
||||
}
|
||||
|
||||
private void TryToShowNotification()
|
||||
private void tryToShowNotification()
|
||||
{
|
||||
if (!PermissionsUtils.isExternalStorageGranted())
|
||||
{
|
||||
|
|
|
@ -57,7 +57,7 @@ public final class Notifier
|
|||
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOAD_COUNTRY_NOTIFICATION_SHOWN);
|
||||
}
|
||||
|
||||
public void notifyAuthentication()
|
||||
void notifyAuthentication()
|
||||
{
|
||||
Intent authIntent = MwmActivity.createAuthenticateIntent(mContext);
|
||||
authIntent.putExtra(EXTRA_CANCEL_NOTIFICATION, Notifier.ID_IS_NOT_AUTHENTICATED);
|
||||
|
@ -67,7 +67,7 @@ public final class Notifier
|
|||
PendingIntent pi = PendingIntent.getActivity(mContext, 0, authIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
String channel = NotificationChannelFactory.createProvider(mContext).getAuthChannel();
|
||||
String channel = NotificationChannelFactory.createProvider(mContext).getUGCChannel();
|
||||
NotificationCompat.Builder builder =
|
||||
getBuilder(mContext.getString(R.string.notification_unsent_reviews_title),
|
||||
mContext.getString(R.string.notification_unsent_reviews_message),
|
||||
|
@ -80,7 +80,7 @@ public final class Notifier
|
|||
Statistics.INSTANCE.trackEvent(Statistics.EventName.UGC_NOT_AUTH_NOTIFICATION_SHOWN);
|
||||
}
|
||||
|
||||
public void notifyLeaveReview(@NonNull NotificationCandidate.MapObject mapObject)
|
||||
void notifyLeaveReview(@NonNull NotificationCandidate.MapObject mapObject)
|
||||
{
|
||||
Intent reviewIntent = MwmActivity.createLeaveReviewIntent(mContext, mapObject);
|
||||
reviewIntent.putExtra(EXTRA_CANCEL_NOTIFICATION, Notifier.ID_LEAVE_REVIEW);
|
||||
|
@ -90,12 +90,12 @@ public final class Notifier
|
|||
PendingIntent pi =
|
||||
PendingIntent.getActivity(mContext, 0, reviewIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
String channel = NotificationChannelFactory.createProvider(mContext).getAuthChannel();
|
||||
String channel = NotificationChannelFactory.createProvider(mContext).getUGCChannel();
|
||||
NotificationCompat.Builder builder =
|
||||
getBuilder(String.format(mContext.getString(R.string.notification_leave_review_title),
|
||||
mapObject.getReadableName()),
|
||||
String.format(mContext.getString(R.string.notification_leave_review_content),
|
||||
mapObject.getReadableName()),
|
||||
getBuilder(mContext.getString(R.string.notification_leave_review_title,
|
||||
mapObject.getReadableName()),
|
||||
mContext.getString(R.string.notification_leave_review_content,
|
||||
mapObject.getReadableName()),
|
||||
pi, channel);
|
||||
|
||||
builder.addAction(0, mContext.getString(R.string.leave_a_review), pi);
|
||||
|
@ -146,13 +146,13 @@ public final class Notifier
|
|||
{
|
||||
|
||||
return new NotificationCompat.Builder(mContext, channel)
|
||||
.setAutoCancel(true)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setColor(mContext.getResources().getColor(R.color.base_accent))
|
||||
.setContentTitle(title)
|
||||
.setContentText(content)
|
||||
.setTicker(getTicker(title, content))
|
||||
.setContentIntent(pendingIntent);
|
||||
.setAutoCancel(true)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setColor(mContext.getResources().getColor(R.color.base_accent))
|
||||
.setContentTitle(title)
|
||||
.setContentText(content)
|
||||
.setTicker(getTicker(title, content))
|
||||
.setContentIntent(pendingIntent);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
|
|
@ -23,10 +23,10 @@ public class OreoCompatNotificationChannelProvider extends StubNotificationChann
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setAuthChannel()
|
||||
public void setUGCChannel()
|
||||
{
|
||||
String name = getApplication().getString(R.string.notification_unsent_reviews_title);
|
||||
setChannelInternal(getAuthChannel(), name);
|
||||
String name = getApplication().getString(R.string.notification_channel_ugc);
|
||||
setChannelInternal(getUGCChannel(), name);
|
||||
}
|
||||
|
||||
private void setChannelInternal(@NonNull String id, @NonNull String name)
|
||||
|
@ -44,7 +44,7 @@ public class OreoCompatNotificationChannelProvider extends StubNotificationChann
|
|||
@Override
|
||||
public void setDownloadingChannel()
|
||||
{
|
||||
String name = "NEED STRING ID FOR CHANNEL";
|
||||
String name = getApplication().getString(R.string.notification_channel_downloader);
|
||||
setChannelInternal(getDownloadingChannel(), name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,13 +32,13 @@ public class StubNotificationChannelProvider implements NotificationChannelProvi
|
|||
|
||||
@Override
|
||||
@NonNull
|
||||
public String getAuthChannel()
|
||||
public String getUGCChannel()
|
||||
{
|
||||
return mAuthChannel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAuthChannel()
|
||||
public void setUGCChannel()
|
||||
{
|
||||
/*Do nothing */
|
||||
}
|
||||
|
|
|
@ -3842,7 +3842,7 @@ double Framework::GetLastBackgroundTime() const
|
|||
return m_startBackgroundTime;
|
||||
}
|
||||
|
||||
bool Framework::MakePlacePageInfo(eye::MapObject const & mapObject, place_page::Info & info)
|
||||
bool Framework::MakePlacePageInfo(eye::MapObject const & mapObject, place_page::Info & info) const
|
||||
{
|
||||
m2::RectD rect = MercatorBounds::RectByCenterXYAndOffset(mapObject.GetPos(), kMwmPointAccuracy);
|
||||
bool found = false;
|
||||
|
|
|
@ -909,5 +909,5 @@ public:
|
|||
bool HaveTransit(m2::PointD const & pt) const override;
|
||||
double GetLastBackgroundTime() const override;
|
||||
|
||||
bool MakePlacePageInfo(eye::MapObject const & mapObject, place_page::Info & info);
|
||||
bool MakePlacePageInfo(eye::MapObject const & mapObject, place_page::Info & info) const;
|
||||
};
|
||||
|
|
|
@ -132,7 +132,7 @@ void NotificationManager::Load()
|
|||
void NotificationManager::TrimExpired()
|
||||
{
|
||||
auto & candidates = m_queue.m_candidates;
|
||||
size_t sizeBefore = candidates.size();
|
||||
size_t const sizeBefore = candidates.size();
|
||||
|
||||
candidates.erase(std::remove_if(candidates.begin(), candidates.end(), [](auto const & item)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue