forked from organicmaps/organicmaps
[android] Remove sSelf and get() from MwmApplication
This commit is contained in:
parent
83aa0c78b5
commit
d37c4d479f
10 changed files with 30 additions and 36 deletions
|
@ -56,7 +56,6 @@ public class MwmApplication extends Application implements AppBackgroundTracker.
|
|||
private Logger mLogger;
|
||||
public final static String TAG = "MwmApplication";
|
||||
|
||||
private static MwmApplication sSelf;
|
||||
private AppBackgroundTracker mBackgroundTracker;
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
|
@ -114,16 +113,6 @@ public class MwmApplication extends Application implements AppBackgroundTracker.
|
|||
public MwmApplication()
|
||||
{
|
||||
super();
|
||||
sSelf = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the {@link #from(Context)} method instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static MwmApplication get()
|
||||
{
|
||||
return sSelf;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -253,9 +242,9 @@ public class MwmApplication extends Application implements AppBackgroundTracker.
|
|||
if (SharedPropertiesUtils.shouldEmulateBadExternalStorage(this))
|
||||
return false;
|
||||
|
||||
return StorageUtils.createDirectory(settingsPath) &&
|
||||
StorageUtils.createDirectory(filesPath) &&
|
||||
StorageUtils.createDirectory(tempPath);
|
||||
return StorageUtils.createDirectory(this, settingsPath) &&
|
||||
StorageUtils.createDirectory(this, filesPath) &&
|
||||
StorageUtils.createDirectory(this, tempPath);
|
||||
}
|
||||
|
||||
private void initNativeFramework()
|
||||
|
|
|
@ -225,7 +225,7 @@ public class SplashActivity extends AppCompatActivity
|
|||
// If the user revoked the external storage permission while the app was killed
|
||||
// we can't update maps automatically during recovering process, so just dismiss updater fragment
|
||||
// and ask the user to grant the permission.
|
||||
if (!PermissionsUtils.isExternalStorageGranted())
|
||||
if (!PermissionsUtils.isExternalStorageGranted(this))
|
||||
{
|
||||
fm.beginTransaction().remove(updaterFragment).commitAllowingStateLoss();
|
||||
fm.executePendingTransactions();
|
||||
|
@ -303,7 +303,7 @@ public class SplashActivity extends AppCompatActivity
|
|||
|
||||
private boolean processPermissionGranting()
|
||||
{
|
||||
mPermissionsGranted = PermissionsUtils.isExternalStorageGranted();
|
||||
mPermissionsGranted = PermissionsUtils.isExternalStorageGranted(this);
|
||||
DialogFragment storagePermissionsDialog = StoragePermissionsDialogFragment.find(this);
|
||||
DialogFragment permissionsDialog = PermissionsDialogFragment.find(this);
|
||||
if (!mPermissionsGranted)
|
||||
|
|
|
@ -52,14 +52,14 @@ public class NotificationService extends JobIntentService
|
|||
return false;
|
||||
}
|
||||
|
||||
final long lastEventTimestamp = prefs(getApplicationContext())
|
||||
final long lastEventTimestamp = prefs(this)
|
||||
.getLong(LAST_AUTH_NOTIFICATION_TIMESTAMP, 0);
|
||||
|
||||
if (System.currentTimeMillis() - lastEventTimestamp > MIN_AUTH_EVENT_DELTA_MILLIS)
|
||||
{
|
||||
LOGGER.d(TAG, "Authentication notification will be sent.");
|
||||
|
||||
prefs(getApplicationContext()).edit()
|
||||
prefs(this).edit()
|
||||
.putLong(LAST_AUTH_NOTIFICATION_TIMESTAMP, System.currentTimeMillis())
|
||||
.apply();
|
||||
|
||||
|
@ -104,14 +104,14 @@ public class NotificationService extends JobIntentService
|
|||
|
||||
private void tryToShowNotification()
|
||||
{
|
||||
if (!PermissionsUtils.isExternalStorageGranted())
|
||||
if (!PermissionsUtils.isExternalStorageGranted(this))
|
||||
{
|
||||
LOGGER.d(TAG, "Notification is rejected. External storage is not granted.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Do not show push when user is in the navigation mode.
|
||||
if (MwmApplication.from(getApplicationContext()).arePlatformAndCoreInitialized()
|
||||
if (MwmApplication.from(this).arePlatformAndCoreInitialized()
|
||||
&& RoutingController.get().isNavigating())
|
||||
{
|
||||
LOGGER.d(TAG, "Notification is rejected. The user is in navigation mode.");
|
||||
|
|
|
@ -74,7 +74,7 @@ public abstract class BaseMwmFragmentActivity extends AppCompatActivity
|
|||
setIntent(initialIntent);
|
||||
|
||||
if (!MwmApplication.from(this).arePlatformAndCoreInitialized()
|
||||
|| !PermissionsUtils.isExternalStorageGranted())
|
||||
|| !PermissionsUtils.isExternalStorageGranted(getApplicationContext()))
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
goToSplashScreen(getIntent());
|
||||
|
@ -217,7 +217,7 @@ public abstract class BaseMwmFragmentActivity extends AppCompatActivity
|
|||
protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
if (!PermissionsUtils.isExternalStorageGranted())
|
||||
if (!PermissionsUtils.isExternalStorageGranted(getApplicationContext()))
|
||||
{
|
||||
goToSplashScreen(null);
|
||||
return;
|
||||
|
|
|
@ -244,7 +244,7 @@ public class DiscoveryFragment extends BaseMwmToolbarFragment implements Discove
|
|||
RecyclerView gallery = getGallery(R.id.attractions);
|
||||
GalleryAdapter adapter = Factory.createSearchBasedAdapter(results, listener, SEARCH_ATTRACTIONS,
|
||||
DISCOVERY,
|
||||
new Items.MoreSearchItem());
|
||||
new Items.MoreSearchItem(requireContext()));
|
||||
gallery.setAdapter(adapter);
|
||||
}
|
||||
|
||||
|
@ -258,7 +258,8 @@ public class DiscoveryFragment extends BaseMwmToolbarFragment implements Discove
|
|||
ItemType.CAFES);
|
||||
RecyclerView gallery = getGallery(R.id.food);
|
||||
gallery.setAdapter(Factory.createSearchBasedAdapter(results, listener, SEARCH_RESTAURANTS,
|
||||
DISCOVERY, new Items.MoreSearchItem()));
|
||||
DISCOVERY,
|
||||
new Items.MoreSearchItem(requireContext())));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -266,8 +267,8 @@ public class DiscoveryFragment extends BaseMwmToolbarFragment implements Discove
|
|||
{
|
||||
updateViewsVisibility(results, R.id.hotelsTitle, R.id.hotels);
|
||||
ItemSelectedListener<Items.SearchItem> listener = new HotelListener(this);
|
||||
GalleryAdapter adapter = Factory.createHotelAdapter(results, listener, SEARCH_HOTELS,
|
||||
DISCOVERY);
|
||||
GalleryAdapter adapter = Factory.createHotelAdapter(requireContext(), results, listener,
|
||||
SEARCH_HOTELS, DISCOVERY);
|
||||
RecyclerView gallery = getGallery(R.id.hotels);
|
||||
gallery.setAdapter(adapter);
|
||||
}
|
||||
|
|
|
@ -171,9 +171,9 @@ public class Items
|
|||
|
||||
public static class MoreSearchItem extends SearchItem
|
||||
{
|
||||
public MoreSearchItem()
|
||||
public MoreSearchItem(@NonNull Context context)
|
||||
{
|
||||
super(MwmApplication.get().getString(R.string.placepage_more_button));
|
||||
super(context.getString(R.string.placepage_more_button));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,14 +53,15 @@ public class Factory
|
|||
}
|
||||
|
||||
@NonNull
|
||||
public static GalleryAdapter createHotelAdapter(@NonNull SearchResult[] results,
|
||||
public static GalleryAdapter createHotelAdapter(@NonNull Context context,
|
||||
@NonNull SearchResult[] results,
|
||||
@Nullable ItemSelectedListener<Items
|
||||
.SearchItem> listener,
|
||||
@NonNull GalleryType type,
|
||||
@NonNull GalleryPlacement placement)
|
||||
{
|
||||
trackProductGalleryShownOrError(results, type, OFFLINE, placement);
|
||||
return new GalleryAdapter<>(new HotelAdapterStrategy(results, listener));
|
||||
return new GalleryAdapter<>(new HotelAdapterStrategy(context, results, listener));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.mapswithme.maps.gallery.impl;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -17,10 +19,11 @@ import java.util.List;
|
|||
|
||||
public class HotelAdapterStrategy extends RegularAdapterStrategy<Items.SearchItem>
|
||||
{
|
||||
HotelAdapterStrategy(@NonNull SearchResult[] results,
|
||||
HotelAdapterStrategy(@NonNull Context context,
|
||||
@NonNull SearchResult[] results,
|
||||
@Nullable ItemSelectedListener<Items.SearchItem> listener)
|
||||
{
|
||||
this(SearchBasedAdapterStrategy.convertItems(results), new Items.MoreSearchItem(), listener);
|
||||
this(SearchBasedAdapterStrategy.convertItems(results), new Items.MoreSearchItem(context), listener);
|
||||
}
|
||||
|
||||
private HotelAdapterStrategy(@NonNull List<Items.SearchItem> items,
|
||||
|
|
|
@ -59,9 +59,9 @@ public final class PermissionsUtils
|
|||
|| shouldShowRequestPermissionRationale(activity, ACCESS_FINE_LOCATION);
|
||||
}
|
||||
|
||||
public static boolean isExternalStorageGranted()
|
||||
public static boolean isExternalStorageGranted(@NonNull Context context)
|
||||
{
|
||||
return checkPermissions(MwmApplication.get()).isExternalStorageGranted();
|
||||
return checkPermissions(context).isExternalStorageGranted();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
|
|
@ -161,12 +161,12 @@ public class StorageUtils
|
|||
return storagePath.concat(String.format(Constants.OBB_PATH, BuildConfig.APPLICATION_ID));
|
||||
}
|
||||
|
||||
public static boolean createDirectory(@NonNull String path)
|
||||
public static boolean createDirectory(@NonNull Context context, @NonNull String path)
|
||||
{
|
||||
File directory = new File(path);
|
||||
if (!directory.exists() && !directory.mkdirs())
|
||||
{
|
||||
boolean isPermissionGranted = PermissionsUtils.isExternalStorageGranted();
|
||||
boolean isPermissionGranted = PermissionsUtils.isExternalStorageGranted(context);
|
||||
Throwable error = new IllegalStateException("Can't create directories for: " + path
|
||||
+ " state = " + Environment.getExternalStorageState()
|
||||
+ " isPermissionGranted = " + isPermissionGranted);
|
||||
|
|
Loading…
Add table
Reference in a new issue