Skip to content

Commit

Permalink
[android] Refacroring MwmApplication.
Browse files Browse the repository at this point in the history
Remove prefs() from NotificationService, EditorHostfragment, ViralFragment, SplashActivity, PlacePageView.
  • Loading branch information
velichkomarija authored and alexzatsepin committed Nov 27, 2020
1 parent 0c40406 commit ca6c536
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion android/src/com/mapswithme/maps/SplashActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ private void resumeDialogs()
boolean showNews = NewsFragment.showOn(this, this);
if (!showNews)
{
if (ViralFragment.shouldDisplay())
if (ViralFragment.shouldDisplay(getApplicationContext()))
{
UiUtils.hide(mIvLogo, mAppName);
ViralFragment dialog = new ViralFragment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ private boolean notifyIsNotAuthenticated()
return false;
}

final long lastEventTimestamp = prefs().getLong(LAST_AUTH_NOTIFICATION_TIMESTAMP, 0);
final long lastEventTimestamp = prefs(getApplicationContext())
.getLong(LAST_AUTH_NOTIFICATION_TIMESTAMP, 0);

if (System.currentTimeMillis() - lastEventTimestamp > MIN_AUTH_EVENT_DELTA_MILLIS)
{
LOGGER.d(TAG, "Authentication notification will be sent.");

prefs().edit()
.putLong(LAST_AUTH_NOTIFICATION_TIMESTAMP, System.currentTimeMillis())
.apply();
prefs(getApplicationContext()).edit()
.putLong(LAST_AUTH_NOTIFICATION_TIMESTAMP, System.currentTimeMillis())
.apply();

Notifier notifier = Notifier.from(getApplication());
notifier.notifyAuthentication();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public void onClick(View v)
return;

// Save object edits
if (!MwmApplication.prefs().contains(NOOB_ALERT_SHOWN))
if (!MwmApplication.prefs(requireContext()).contains(NOOB_ALERT_SHOWN))
{
showNoobDialog();
}
Expand Down Expand Up @@ -385,7 +385,7 @@ private void showNoobDialog()
@Override
public void onClick(DialogInterface dlg, int which)
{
MwmApplication.prefs().edit()
MwmApplication.prefs(requireContext()).edit()
.putBoolean(NOOB_ALERT_SHOWN, true)
.apply();
saveNote();
Expand Down
9 changes: 6 additions & 3 deletions android/src/com/mapswithme/maps/editor/ViralFragment.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.mapswithme.maps.editor;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -30,9 +33,9 @@ public class ViralFragment extends BaseMwmDialogFragment
@Nullable
private Runnable mDismissListener;

public static boolean shouldDisplay()
public static boolean shouldDisplay(@NonNull Context context)
{
return !MwmApplication.prefs().contains(EXTRA_CONGRATS_SHOWN) &&
return !MwmApplication.prefs(context).contains(EXTRA_CONGRATS_SHOWN) &&
Editor.nativeGetStats()[0] == 2 &&
ConnectionState.isConnected();
}
Expand All @@ -47,7 +50,7 @@ protected int getStyle()
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
MwmApplication.prefs().edit().putBoolean(EXTRA_CONGRATS_SHOWN, true).apply();
MwmApplication.prefs(requireContext()).edit().putBoolean(EXTRA_CONGRATS_SHOWN, true).apply();

@SuppressLint("InflateParams")
final View root = inflater.inflate(R.layout.fragment_editor_viral, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public PlacePageView(Context context, AttributeSet attrs)
public PlacePageView(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs);
mIsLatLonDms = MwmApplication.prefs().getBoolean(PREF_USE_DMS, false);
mIsLatLonDms = MwmApplication.prefs(context).getBoolean(PREF_USE_DMS, false);
mGalleryAdapter = new com.mapswithme.maps.widget.placepage.GalleryAdapter(context);
init(attrs, defStyleAttr);
}
Expand Down Expand Up @@ -1858,7 +1858,7 @@ public void onClick(View v)
break;
case R.id.ll__place_latlon:
mIsLatLonDms = !mIsLatLonDms;
MwmApplication.prefs().edit().putBoolean(PREF_USE_DMS, mIsLatLonDms).apply();
MwmApplication.prefs(getContext()).edit().putBoolean(PREF_USE_DMS, mIsLatLonDms).apply();
if (mMapObject == null)
{
LOGGER.e(TAG, "A LatLon cannot be refreshed, mMapObject is null");
Expand Down

0 comments on commit ca6c536

Please sign in to comment.