Consolidate shared prefs to a single store (#2613)

* Consolidate shared prefs to a single store
* Fix achievements activity
* Fix store usage
This commit is contained in:
Vivek Maskara 2019-03-16 19:26:56 +05:30 committed by Adam Jones
parent 51f58b7118
commit 7cb87f3cab
41 changed files with 207 additions and 279 deletions

View file

@ -17,7 +17,6 @@ import fr.free.nrw.commons.R;
import fr.free.nrw.commons.filepicker.DefaultCallback;
import fr.free.nrw.commons.filepicker.FilePicker;
import fr.free.nrw.commons.filepicker.UploadableFile;
import fr.free.nrw.commons.kvstore.BasicKvStore;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.nearby.Place;
import fr.free.nrw.commons.upload.UploadActivity;
@ -35,14 +34,11 @@ public class ContributionController {
public static final String ACTION_INTERNAL_UPLOADS = "internalImageUploads";
private final BasicKvStore defaultKvStore;
private final JsonKvStore directKvStore;
private final JsonKvStore defaultKvStore;
@Inject
public ContributionController(@Named("default_preferences") BasicKvStore defaultKvStore,
@Named("direct_nearby_upload_prefs") JsonKvStore directKvStore) {
public ContributionController(@Named("default_preferences") JsonKvStore defaultKvStore) {
this.defaultKvStore = defaultKvStore;
this.directKvStore = directKvStore;
}
/**
@ -134,7 +130,7 @@ public class ContributionController {
shareIntent.setAction(ACTION_INTERNAL_UPLOADS);
shareIntent.putExtra(EXTRA_SOURCE, source);
shareIntent.putParcelableArrayListExtra(EXTRA_FILES, new ArrayList<>(imagesFiles));
Place place = directKvStore.getJson(PLACE_OBJECT, Place.class);
Place place = defaultKvStore.getJson(PLACE_OBJECT, Place.class);
if (place != null) {
shareIntent.putExtra(PLACE_OBJECT, place);
}

View file

@ -44,7 +44,7 @@ import fr.free.nrw.commons.campaigns.CampaignView;
import fr.free.nrw.commons.campaigns.CampaignsPresenter;
import fr.free.nrw.commons.campaigns.ICampaignsView;
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
import fr.free.nrw.commons.kvstore.BasicKvStore;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.location.LocationUpdateListener;
@ -81,7 +81,7 @@ public class ContributionsFragment
ContributionsListFragment.SourceRefresher,
LocationUpdateListener,
ICampaignsView {
@Inject @Named("default_preferences") BasicKvStore defaultKvStore;
@Inject @Named("default_preferences") JsonKvStore store;
@Inject ContributionDao contributionDao;
@Inject MediaWikiApi mediaWikiApi;
@Inject NearbyController nearbyController;
@ -151,7 +151,7 @@ public class ContributionsFragment
checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
// Do not ask for permission on activity start again
defaultKvStore.putBoolean("displayLocationPermissionForCardView",false);
store.putBoolean("displayLocationPermissionForCardView",false);
}
});
@ -222,7 +222,7 @@ public class ContributionsFragment
((MainActivity)getActivity()).showTabs();
// show nearby card view on contributions list is visible
if (nearbyNotificationCardView != null) {
if (defaultKvStore.getBoolean("displayNearbyCardView", true)) {
if (store.getBoolean("displayNearbyCardView", true)) {
if (nearbyNotificationCardView.cardViewVisibilityState == NearbyNotificationCardView.CardViewVisibilityState.READY) {
nearbyNotificationCardView.setVisibility(View.VISIBLE);
}
@ -290,7 +290,7 @@ public class ContributionsFragment
@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
int uploads = defaultKvStore.getInt(UPLOADS_SHOWING, 100);
int uploads = store.getInt(UPLOADS_SHOWING, 100);
return new CursorLoader(getActivity(), BASE_URI, //TODO find out the reason we pass activity here
ALL_FIELDS, "", null,
ContributionDao.CONTRIBUTION_SORT + "LIMIT " + uploads);
@ -365,7 +365,7 @@ public class ContributionsFragment
// No need to display permission request button anymore
locationManager.registerLocationManager();
} else {
if (defaultKvStore.getBoolean("displayLocationPermissionForCardView", true)) {
if (store.getBoolean("displayLocationPermissionForCardView", true)) {
// Still ask for permission
DialogUtil.showAlertDialog(getActivity(),
getString(R.string.nearby_card_permission_title),
@ -501,14 +501,14 @@ public class ContributionsFragment
firstLocationUpdate = true;
locationManager.addLocationListener(this);
boolean isSettingsChanged = defaultKvStore.getBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, false);
defaultKvStore.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, false);
boolean isSettingsChanged = store.getBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, false);
store.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, false);
if (isSettingsChanged) {
refreshSource();
}
if (defaultKvStore.getBoolean("displayNearbyCardView", true)) {
if (store.getBoolean("displayNearbyCardView", true)) {
checkGPS();
if (nearbyNotificationCardView.cardViewVisibilityState == NearbyNotificationCardView.CardViewVisibilityState.READY) {
nearbyNotificationCardView.setVisibility(View.VISIBLE);
@ -529,7 +529,7 @@ public class ContributionsFragment
if (!locationManager.isProviderEnabled()) {
Timber.d("GPS is not enabled");
nearbyNotificationCardView.permissionType = NearbyNotificationCardView.PermissionType.ENABLE_GPS;
if (defaultKvStore.getBoolean("displayLocationPermissionForCardView", true)) {
if (store.getBoolean("displayLocationPermissionForCardView", true)) {
DialogUtil.showAlertDialog(getActivity(),
getString(R.string.nearby_card_permission_title),
getString(R.string.nearby_card_permission_explanation),
@ -553,7 +553,7 @@ public class ContributionsFragment
nearbyNotificationCardView.permissionType = NearbyNotificationCardView.PermissionType.ENABLE_LOCATION_PERMISSION;
// If user didn't selected Don't ask again
if (shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION)
&& defaultKvStore.getBoolean("displayLocationPermissionForCardView", true)) {
&& store.getBoolean("displayLocationPermissionForCardView", true)) {
DialogUtil.showAlertDialog(getActivity(),
getString(R.string.nearby_card_permission_title),
getString(R.string.nearby_card_permission_explanation),
@ -691,7 +691,7 @@ public class ContributionsFragment
* ask the presenter to fetch the campaigns only if user has not manually disabled it
*/
private void fetchCampaigns() {
if (defaultKvStore.getBoolean("displayCampaignsCardView", true)) {
if (store.getBoolean("displayCampaignsCardView", true)) {
presenter.getCampaigns();
}
}

View file

@ -23,7 +23,7 @@ import butterknife.BindView;
import butterknife.ButterKnife;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
import fr.free.nrw.commons.kvstore.BasicKvStore;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.utils.ConfigUtils;
@ -51,8 +51,7 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment {
@BindView(R.id.fab_layout)
LinearLayout fab_layout;
@Inject @Named("default_preferences") BasicKvStore basicKvStore;
@Inject @Named("direct_nearby_upload_prefs") JsonKvStore directKvStore;
@Inject @Named("default_preferences") JsonKvStore kvStore;
@Inject ContributionController controller;
private Animation fab_close;

View file

@ -24,7 +24,8 @@ import javax.inject.Named;
import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.di.ApplicationlessInjection;
import fr.free.nrw.commons.kvstore.BasicKvStore;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.mwapi.LogEventResult;
import fr.free.nrw.commons.mwapi.MediaWikiApi;
import timber.log.Timber;
@ -44,8 +45,8 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
@SuppressWarnings("WeakerAccess")
@Inject MediaWikiApi mwApi;
@Inject
@Named("defaultKvStore")
BasicKvStore defaultKvStore;
@Named("default_preferences")
JsonKvStore defaultKvStore;
public ContributionsSyncAdapter(Context context, boolean autoInitialize) {
super(context, autoInitialize);

View file

@ -31,13 +31,14 @@ import fr.free.nrw.commons.BuildConfig;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.auth.AuthenticatedActivity;
import fr.free.nrw.commons.auth.SessionManager;
import fr.free.nrw.commons.kvstore.BasicKvStore;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.nearby.NearbyFragment;
import fr.free.nrw.commons.nearby.NearbyNotificationCardView;
import fr.free.nrw.commons.notification.Notification;
import fr.free.nrw.commons.notification.NotificationActivity;
import fr.free.nrw.commons.notification.NotificationController;
import fr.free.nrw.commons.quiz.QuizChecker;
import fr.free.nrw.commons.upload.UploadService;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
@ -59,10 +60,9 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
@Inject
public LocationServiceManager locationManager;
@Inject
@Named("default_preferences")
public BasicKvStore defaultKvStore;
@Inject
NotificationController notificationController;
@Inject
QuizChecker quizChecker;
public Intent uploadServiceIntent;
@ -494,6 +494,7 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
protected void onResume() {
super.onResume();
setNotificationCount();
quizChecker.initQuizCheck(this);
}
@Override