[android] Fixed review notes

This commit is contained in:
Dmitry Donskoy 2018-08-28 19:37:04 +03:00 committed by Aleksandr Zatsepin
parent 192c29caa3
commit d74618ddcb
17 changed files with 222 additions and 167 deletions

View file

@ -1216,7 +1216,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
if (intent == null)
return false;
final Notifier notifier = new Notifier(getApplication());
final Notifier notifier = Notifier.from(getApplication());
notifier.processNotificationExtras(intent);
if (intent.hasExtra(EXTRA_TASK))

View file

@ -16,6 +16,7 @@ import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.core.CrashlyticsCore;
import com.crashlytics.android.ndk.CrashlyticsNdk;
import com.mapswithme.maps.background.AppBackgroundTracker;
import com.mapswithme.maps.background.NotificationChannelFactory;
import com.mapswithme.maps.background.NotificationChannelProvider;
import com.mapswithme.maps.background.Notifier;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
@ -169,18 +170,18 @@ public class MwmApplication extends Application
mPrefs = getSharedPreferences(getString(R.string.pref_file_name), MODE_PRIVATE);
initCoreIndependentSdks();
initNotificationChannels();
mBackgroundTracker = new AppBackgroundTracker();
mBackgroundTracker.addListener(mVisibleAppLaunchListener);
mSubwayManager = new SubwayManager(this);
mConnectivityListener = new ConnectivityJobScheduler(this);
mConnectivityListener.listen();
initNotificationChannels();
}
private void initNotificationChannels()
{
NotificationChannelProvider channelProvider = NotificationChannelProvider.from(this);
NotificationChannelProvider channelProvider = NotificationChannelFactory.createProvider(this);
channelProvider.setAuthChannel();
channelProvider.setDownloadingChannel();
}
@ -485,7 +486,7 @@ public class MwmApplication extends Application
@Override
public void onStatusChanged(List<MapManager.StorageCallbackData> data)
{
Notifier notifier = new Notifier(MwmApplication.this);
Notifier notifier = Notifier.from(MwmApplication.this);
for (MapManager.StorageCallbackData item : data)
if (item.isLeafNode && item.newStatus == CountryItem.STATUS_FAILED)
{

View file

@ -17,9 +17,8 @@ public class PassportAuthDialogFragment extends BaseMwmDialogFragment
@NonNull
private final Authorizer mAuthorizer = new Authorizer(this);
@SuppressWarnings("NullableProblems")
@NonNull
private AuthCallback mAuthCallback;
private final AuthCallback mAuthCallback = new AuthCallback();
@Nullable
private Bundle mSavedInstanceState;
@ -28,8 +27,6 @@ public class PassportAuthDialogFragment extends BaseMwmDialogFragment
public void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Notifier notifier = new Notifier(getAppContextOrThrow());
mAuthCallback = new AuthCallback(notifier);
mSavedInstanceState = savedInstanceState;
}
@ -66,21 +63,15 @@ public class PassportAuthDialogFragment extends BaseMwmDialogFragment
private class AuthCallback implements Authorizer.Callback
{
@NonNull
private final Notifier mNotifier;
AuthCallback(@NonNull Notifier notifier)
{
mNotifier = notifier;
}
@Override
public void onAuthorizationFinish(boolean success)
{
dismiss();
if (success)
mNotifier.cancelNotification(Notifier.ID_IS_NOT_AUTHENTICATED);
{
Notifier notifier = Notifier.from(getActivity().getApplication());
notifier.cancelNotification(Notifier.ID_IS_NOT_AUTHENTICATED);
}
}
@Override

View file

@ -0,0 +1,16 @@
package com.mapswithme.maps.background;
import android.app.Application;
import android.support.annotation.NonNull;
import com.mapswithme.util.Utils;
public class NotificationChannelFactory
{
@NonNull
public static NotificationChannelProvider createProvider(@NonNull Application app)
{
return Utils.isOreoOrLater() ? new OreoCompatNotificationChannelProvider(app)
: new StubNotificationChannelProvider(app);
}
}

View file

@ -1,15 +1,7 @@
package com.mapswithme.maps.background;
import android.annotation.TargetApi;
import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;
import android.support.annotation.NonNull;
import com.mapswithme.maps.R;
import com.mapswithme.util.Utils;
public interface NotificationChannelProvider
{
@NonNull
@ -21,109 +13,4 @@ public interface NotificationChannelProvider
String getDownloadingChannel();
void setDownloadingChannel();
class DefaultNotificationChannelProvider implements NotificationChannelProvider
{
private static final String DEFAULT_NOTIFICATION_CHANNEL = "default_notification_channel";
@NonNull
private final Application mApplication;
@NonNull
private final String mAuthChannel;
@NonNull
private final String mDownloadingChannel;
DefaultNotificationChannelProvider(@NonNull Application context, @NonNull String authChannel,
@NonNull String downloadingChannel)
{
mApplication = context;
mAuthChannel = authChannel;
mDownloadingChannel = downloadingChannel;
}
DefaultNotificationChannelProvider(@NonNull Application context)
{
this(context, DEFAULT_NOTIFICATION_CHANNEL, DEFAULT_NOTIFICATION_CHANNEL);
}
@Override
@NonNull
public String getAuthChannel()
{
return mAuthChannel;
}
@Override
public void setAuthChannel()
{
/*Do nothing */
}
@NonNull
@Override
public String getDownloadingChannel()
{
return mDownloadingChannel;
}
@Override
public void setDownloadingChannel()
{
/*Do nothing */
}
@NonNull
protected Application getApplication()
{
return mApplication;
}
}
@NonNull
static NotificationChannelProvider from(@NonNull Application app)
{
return Utils.isOreoOrLater() ? new OreoCompatProvider(app)
: new DefaultNotificationChannelProvider(app);
}
@TargetApi(Build.VERSION_CODES.O)
class OreoCompatProvider extends DefaultNotificationChannelProvider
{
private static final String AUTH_NOTIFICATION_CHANNEL = "auth_notification_channel";
private static final String DOWNLOADING_NOTIFICATION_CHANNEL = "downloading_notification_channel";
OreoCompatProvider(@NonNull Application app)
{
super(app, AUTH_NOTIFICATION_CHANNEL, DOWNLOADING_NOTIFICATION_CHANNEL);
}
@Override
public void setAuthChannel()
{
String name = getApplication().getString(R.string.notification_unsent_reviews_title);
setChannelInternal(getAuthChannel(), name);
}
private void setChannelInternal(@NonNull String id, @NonNull String name)
{
NotificationManager notificationManager = getApplication().getSystemService(NotificationManager.class);
NotificationChannel channel = notificationManager.getNotificationChannel(id);
if (channel == null)
channel = new NotificationChannel(id, name, NotificationManager.IMPORTANCE_DEFAULT);
else
channel.setName(name);
notificationManager.createNotificationChannel(channel);
}
@Override
public void setDownloadingChannel()
{
String name = "NEED STRING ID FOR CHANNEL";
setChannelInternal(getDownloadingChannel(), name);
}
}
}

View file

@ -1,6 +1,5 @@
package com.mapswithme.maps.background;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
@ -26,8 +25,7 @@ public class NotificationService extends JobIntentService
private static final String TAG = NotificationService.class.getSimpleName();
private static final String LAST_AUTH_NOTIFICATION_TIMESTAMP = "DownloadOrUpdateTimestamp";
private static final int MIN_COUNT_UNSENT_UGC = 2;
private static final int DAYS_COUNT = 5;
private static final long MIN_AUTH_EVENT_DELTA_MILLIS = TimeUnit.DAYS.toMillis(DAYS_COUNT);
private static final long MIN_AUTH_EVENT_DELTA_MILLIS = TimeUnit.DAYS.toMillis(5);
private interface NotificationExecutor
{
@ -43,7 +41,7 @@ public class NotificationService extends JobIntentService
JobIntentService.enqueueWork(context, NotificationService.class, jobId, intent);
}
private static boolean notifyIsNotAuthenticated(@NonNull Application application)
private boolean notifyIsNotAuthenticated()
{
if (!PermissionsUtils.isExternalStorageGranted() ||
!NetworkPolicy.getCurrentNetworkUsageStatus() ||
@ -76,7 +74,7 @@ public class NotificationService extends JobIntentService
.putLong(LAST_AUTH_NOTIFICATION_TIMESTAMP, System.currentTimeMillis())
.apply();
Notifier notifier = new Notifier(application);
Notifier notifier = Notifier.from(getApplication());
notifier.notifyAuthentication();
return true;
@ -99,7 +97,7 @@ public class NotificationService extends JobIntentService
{
final NotificationExecutor notifyOrder[] =
{
() -> notifyIsNotAuthenticated(getApplication())
this::notifyIsNotAuthenticated
};
// Only one notification should be shown at a time.

View file

@ -36,7 +36,7 @@ public final class Notifier
{
}
public Notifier(@NonNull Application context)
private Notifier(@NonNull Application context)
{
mContext = context;
}
@ -51,7 +51,7 @@ public final class Notifier
PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
String channel = NotificationChannelProvider.from(mContext).getDownloadingChannel();
String channel = NotificationChannelFactory.createProvider(mContext).getDownloadingChannel();
placeNotification(title, content, pi, ID_DOWNLOAD_FAILED, channel);
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOAD_COUNTRY_NOTIFICATION_SHOWN);
}
@ -66,7 +66,7 @@ public final class Notifier
PendingIntent pi = PendingIntent.getActivity(mContext, 0, authIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
String channel = NotificationChannelProvider.from(mContext).getAuthChannel();
String channel = NotificationChannelFactory.createProvider(mContext).getAuthChannel();
NotificationCompat.Builder builder =
getBuilder(mContext.getString(R.string.notification_unsent_reviews_title),
mContext.getString(R.string.notification_unsent_reviews_message),
@ -114,6 +114,7 @@ public final class Notifier
getNotificationManager().notify(notificationId, notification);
}
@NonNull
private NotificationCompat.Builder getBuilder(String title, String content,
PendingIntent pendingIntent, @NonNull String channel)
{
@ -128,6 +129,7 @@ public final class Notifier
.setContentIntent(pendingIntent);
}
@NonNull
private CharSequence getTicker(String title, String content)
{
int templateResId = StringUtils.isRtl() ? R.string.notification_ticker_rtl
@ -135,8 +137,16 @@ public final class Notifier
return mContext.getString(templateResId, title, content);
}
@SuppressWarnings("ConstantConditions")
@NonNull
private NotificationManager getNotificationManager()
{
return (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
}
@NonNull
public static Notifier from(Application application)
{
return new Notifier(application);
}
}

View file

@ -0,0 +1,50 @@
package com.mapswithme.maps.background;
import android.annotation.TargetApi;
import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;
import android.support.annotation.NonNull;
import com.mapswithme.maps.R;
import java.util.Objects;
@TargetApi(Build.VERSION_CODES.O)
public class OreoCompatNotificationChannelProvider extends StubNotificationChannelProvider
{
private static final String AUTH_NOTIFICATION_CHANNEL = "auth_notification_channel";
private static final String DOWNLOADING_NOTIFICATION_CHANNEL = "downloading_notification_channel";
OreoCompatNotificationChannelProvider(@NonNull Application app)
{
super(app, AUTH_NOTIFICATION_CHANNEL, DOWNLOADING_NOTIFICATION_CHANNEL);
}
@Override
public void setAuthChannel()
{
String name = getApplication().getString(R.string.notification_unsent_reviews_title);
setChannelInternal(getAuthChannel(), name);
}
private void setChannelInternal(@NonNull String id, @NonNull String name)
{
NotificationManager notificationManager = getApplication().getSystemService(NotificationManager.class);
NotificationChannel channel = Objects.requireNonNull(notificationManager)
.getNotificationChannel(id);
if (channel == null)
channel = new NotificationChannel(id, name, NotificationManager.IMPORTANCE_DEFAULT);
else
channel.setName(name);
notificationManager.createNotificationChannel(channel);
}
@Override
public void setDownloadingChannel()
{
String name = "NEED STRING ID FOR CHANNEL";
setChannelInternal(getDownloadingChannel(), name);
}
}

View file

@ -0,0 +1,64 @@
package com.mapswithme.maps.background;
import android.app.Application;
import android.support.annotation.NonNull;
public class StubNotificationChannelProvider implements NotificationChannelProvider
{
private static final String DEFAULT_NOTIFICATION_CHANNEL = "default_notification_channel";
@NonNull
private final Application mApplication;
@NonNull
private final String mAuthChannel;
@NonNull
private final String mDownloadingChannel;
StubNotificationChannelProvider(@NonNull Application context, @NonNull String authChannel,
@NonNull String downloadingChannel)
{
mApplication = context;
mAuthChannel = authChannel;
mDownloadingChannel = downloadingChannel;
}
StubNotificationChannelProvider(@NonNull Application context)
{
this(context, DEFAULT_NOTIFICATION_CHANNEL, DEFAULT_NOTIFICATION_CHANNEL);
}
@Override
@NonNull
public String getAuthChannel()
{
return mAuthChannel;
}
@Override
public void setAuthChannel()
{
/*Do nothing */
}
@NonNull
@Override
public String getDownloadingChannel()
{
return mDownloadingChannel;
}
@Override
public void setDownloadingChannel()
{
/*Do nothing */
}
@NonNull
protected Application getApplication()
{
return mApplication;
}
}

View file

@ -73,7 +73,7 @@ public class BaseMwmDialogFragment extends DialogFragment
{
Context context = getContext();
if (context == null)
throw new IllegalStateException("Before call this method make sure that getContext() object exist");
throw new IllegalStateException("Before call this method make sure that the context exist");
return (Application) context.getApplicationContext();
}
}

View file

@ -225,7 +225,7 @@ public class BookmarkBackupController implements Authorizer.Callback,
LOGGER.d(TAG, "onAuthorizationFinish, success: " + success);
if (success)
{
final Notifier notifier = new Notifier(mContext.getApplication());
final Notifier notifier = Notifier.from(mContext.getApplication());
notifier.cancelNotification(Notifier.ID_IS_NOT_AUTHENTICATED);
BookmarkManager.INSTANCE.setCloudEnabled(true);
Statistics.INSTANCE.trackEvent(Statistics.EventName.BM_SYNC_PROPOSAL_ENABLED);

View file

@ -26,7 +26,6 @@ import android.widget.TextView;
import com.mapswithme.maps.MwmActivity;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
import com.mapswithme.maps.background.Notifier;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.routing.RoutingController;
import com.mapswithme.util.BottomSheetHelper;
@ -392,15 +391,9 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
break;
case CountryItem.STATUS_FAILED:
final Notifier notifier = new Notifier(mActivity.getApplication());
MapManager.warn3gAndRetry(mActivity, mItem.id, new Runnable()
{
@Override
public void run()
{
notifier.cancelNotification(Notifier.ID_DOWNLOAD_FAILED);
}
});
RetryFailedDownloadConfirmationListener listener =
new RetryFailedDownloadConfirmationListener(mActivity.getApplication());
MapManager.warn3gAndRetry(mActivity, mItem.id, listener);
break;
case CountryItem.STATUS_UPDATABLE:

View file

@ -0,0 +1,29 @@
package com.mapswithme.maps.downloader;
import android.app.Application;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.mapswithme.util.Utils;
class ExpandRetryConfirmationListener extends RetryFailedDownloadConfirmationListener
{
@Nullable
private final Utils.Proc<Boolean> mDialogClickListener;
ExpandRetryConfirmationListener(@NonNull Application app,
@Nullable Utils.Proc<Boolean> dialogClickListener)
{
super(app);
mDialogClickListener = dialogClickListener;
}
@Override
public void run()
{
super.run();
if (mDialogClickListener == null)
return;
mDialogClickListener.invoke(true);
}
}

View file

@ -1,6 +1,7 @@
package com.mapswithme.maps.downloader;
import android.app.Activity;
import android.app.Application;
import android.content.DialogInterface;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -10,7 +11,6 @@ import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import com.mapswithme.maps.R;
import com.mapswithme.maps.background.Notifier;
import com.mapswithme.util.ConnectionState;
import com.mapswithme.util.Utils;
import com.mapswithme.util.statistics.Statistics;
@ -117,7 +117,6 @@ public final class MapManager
throw new IllegalArgumentException("Given error can not be displayed: " + errorData.errorCode);
}
final Notifier notifier = new Notifier(activity.getApplication());
AlertDialog dlg = new AlertDialog.Builder(activity)
.setTitle(R.string.country_status_download_failed)
.setMessage(text)
@ -136,17 +135,10 @@ public final class MapManager
@Override
public void onClick(DialogInterface dialog, int which)
{
warn3gAndRetry(activity, errorData.countryId, new Runnable()
{
@Override
public void run()
{
notifier.cancelNotification(Notifier.ID_DOWNLOAD_FAILED);
if (dialogClickListener != null)
dialogClickListener.invoke(true);
}
});
Application app = activity.getApplication();
RetryFailedDownloadConfirmationListener listener
= new ExpandRetryConfirmationListener(app, dialogClickListener);
warn3gAndRetry(activity, errorData.countryId, listener);
}
}).create();
dlg.setCanceledOnTouchOutside(false);

View file

@ -197,7 +197,7 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
setAutodownloadLocked(true);
}
});
final Notifier notifier = new Notifier(activity.getApplication());
final Notifier notifier = Notifier.from(activity.getApplication());
mButton.setOnClickListener(new View.OnClickListener()
{
@Override

View file

@ -0,0 +1,24 @@
package com.mapswithme.maps.downloader;
import android.app.Application;
import android.support.annotation.NonNull;
import com.mapswithme.maps.background.Notifier;
public class RetryFailedDownloadConfirmationListener implements Runnable
{
@NonNull
private final Application mApplication;
RetryFailedDownloadConfirmationListener(@NonNull Application application)
{
mApplication = application;
}
@Override
public void run()
{
final Notifier notifier = Notifier.from(mApplication);
notifier.cancelNotification(Notifier.ID_DOWNLOAD_FAILED);
}
}

View file

@ -109,7 +109,7 @@ public class UGCEditorFragment extends BaseMwmAuthorizationFragment
{
if (success)
{
final Notifier notifier = new Notifier(getActivity().getApplication());
final Notifier notifier = Notifier.from(getActivity().getApplication());
notifier.cancelNotification(Notifier.ID_IS_NOT_AUTHENTICATED);
}