mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
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:
parent
51f58b7118
commit
7cb87f3cab
41 changed files with 207 additions and 279 deletions
|
|
@ -13,7 +13,7 @@ import org.junit.Rule;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.settings.Prefs;
|
||||
import fr.free.nrw.commons.settings.SettingsActivity;
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ import fr.free.nrw.commons.concurrency.ThreadPoolService;
|
|||
import fr.free.nrw.commons.contributions.ContributionDao;
|
||||
import fr.free.nrw.commons.data.DBOpenHelper;
|
||||
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.logging.FileLoggingTree;
|
||||
import fr.free.nrw.commons.logging.LogUtils;
|
||||
import fr.free.nrw.commons.modifications.ModifierSequenceDao;
|
||||
|
|
@ -57,8 +58,7 @@ public class CommonsApplication extends Application {
|
|||
@Inject SessionManager sessionManager;
|
||||
@Inject DBOpenHelper dbOpenHelper;
|
||||
|
||||
@Inject @Named("default_preferences") BasicKvStore defaultPrefs;
|
||||
@Inject @Named("application_preferences") BasicKvStore applicationPrefs;
|
||||
@Inject @Named("default_preferences") JsonKvStore defaultPrefs;
|
||||
|
||||
/**
|
||||
* Constants begin
|
||||
|
|
@ -213,8 +213,7 @@ public class CommonsApplication extends Application {
|
|||
Timber.d("All accounts have been removed");
|
||||
//TODO: fix preference manager
|
||||
defaultPrefs.clearAll();
|
||||
applicationPrefs.clearAll();
|
||||
applicationPrefs.putBoolean("firstrun", false);
|
||||
defaultPrefs.putBoolean("firstrun", false);
|
||||
updateAllDatabases();
|
||||
logoutListener.onLogoutComplete();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -14,15 +14,14 @@ import javax.inject.Named;
|
|||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
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.quiz.QuizActivity;
|
||||
import fr.free.nrw.commons.theme.BaseActivity;
|
||||
import fr.free.nrw.commons.utils.ConfigUtils;
|
||||
|
||||
public class WelcomeActivity extends BaseActivity {
|
||||
|
||||
@Inject @Named("application_preferences") BasicKvStore kvStore;
|
||||
|
||||
@BindView(R.id.welcomePager)
|
||||
ViewPager pager;
|
||||
@BindView(R.id.welcomePagerIndicator)
|
||||
|
|
@ -102,7 +101,7 @@ public class WelcomeActivity extends BaseActivity {
|
|||
|
||||
@OnClick(R.id.finishTutorialButton)
|
||||
public void finishTutorial() {
|
||||
kvStore.putBoolean("firstrun", false);
|
||||
defaultKvStore.putBoolean("firstrun", false);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -339,12 +339,12 @@ public class AchievementsActivity extends NavigationBaseActivity {
|
|||
* @param achievements
|
||||
*/
|
||||
private void inflateAchievements(Achievements achievements) {
|
||||
thanksReceived.setText(Integer.toString(achievements.getThanksReceived()));
|
||||
thanksReceived.setText(String.valueOf(achievements.getThanksReceived()));
|
||||
imagesUsedByWikiProgressBar.setProgress
|
||||
(100*achievements.getUniqueUsedImages()/levelInfo.getMaxUniqueImages() );
|
||||
imagesUsedByWikiProgressBar.setProgressTextFormatPattern
|
||||
(achievements.getUniqueUsedImages() + "/" + levelInfo.getMaxUniqueImages());
|
||||
imagesFeatured.setText(Integer.toString(achievements.getFeaturedImages()));
|
||||
imagesFeatured.setText(String.valueOf(achievements.getFeaturedImages()));
|
||||
String levelUpInfoString = getString(R.string.level);
|
||||
levelUpInfoString += " " + Integer.toString(levelInfo.getLevelNumber());
|
||||
levelNumber.setText(levelUpInfoString);
|
||||
|
|
|
|||
|
|
@ -44,7 +44,8 @@ import fr.free.nrw.commons.WelcomeActivity;
|
|||
import fr.free.nrw.commons.category.CategoryImagesActivity;
|
||||
import fr.free.nrw.commons.contributions.MainActivity;
|
||||
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.MediaWikiApi;
|
||||
import fr.free.nrw.commons.theme.NavigationBaseActivity;
|
||||
import fr.free.nrw.commons.ui.widget.HtmlTextView;
|
||||
|
|
@ -67,11 +68,8 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
|||
@Inject MediaWikiApi mwApi;
|
||||
@Inject SessionManager sessionManager;
|
||||
@Inject
|
||||
@Named("application_preferences")
|
||||
BasicKvStore applicationKvStore;
|
||||
@Inject
|
||||
@Named("default_preferences")
|
||||
BasicKvStore defaultKvStore;
|
||||
JsonKvStore applicationKvStore;
|
||||
|
||||
@BindView(R.id.loginButton) Button loginButton;
|
||||
@BindView(R.id.signupButton) Button signupButton;
|
||||
|
|
@ -104,7 +102,7 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
|||
.getCommonsApplicationComponent()
|
||||
.inject(this);
|
||||
|
||||
boolean isDarkTheme = defaultKvStore.getBoolean("theme", false);
|
||||
boolean isDarkTheme = applicationKvStore.getBoolean("theme", false);
|
||||
setTheme(isDarkTheme ? R.style.DarkAppTheme : R.style.LightAppTheme);
|
||||
getDelegate().installViewFactory();
|
||||
getDelegate().onCreate(savedInstanceState);
|
||||
|
|
|
|||
|
|
@ -8,9 +8,13 @@ import android.content.Context;
|
|||
import android.os.Bundle;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import fr.free.nrw.commons.BuildConfig;
|
||||
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.MediaWikiApi;
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.Observable;
|
||||
|
|
@ -23,17 +27,19 @@ import static android.accounts.AccountManager.KEY_ACCOUNT_TYPE;
|
|||
/**
|
||||
* Manage the current logged in user session.
|
||||
*/
|
||||
@Singleton
|
||||
public class SessionManager {
|
||||
private final Context context;
|
||||
private final MediaWikiApi mediaWikiApi;
|
||||
private Account currentAccount; // Unlike a savings account... ;-)
|
||||
private BasicKvStore defaultKvStore;
|
||||
private JsonKvStore defaultKvStore;
|
||||
private static final String KEY_RAWUSERNAME = "rawusername";
|
||||
private Bundle userdata = new Bundle();
|
||||
|
||||
@Inject
|
||||
public SessionManager(Context context,
|
||||
MediaWikiApi mediaWikiApi,
|
||||
BasicKvStore defaultKvStore) {
|
||||
@Named("default_preferences") JsonKvStore defaultKvStore) {
|
||||
this.context = context;
|
||||
this.mediaWikiApi = mediaWikiApi;
|
||||
this.currentAccount = null;
|
||||
|
|
|
|||
|
|
@ -19,15 +19,12 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import dagger.android.support.DaggerFragment;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.contributions.ContributionController;
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.nearby.NearbyAdapterFactory;
|
||||
import fr.free.nrw.commons.nearby.Place;
|
||||
|
||||
|
|
@ -39,8 +36,6 @@ public class BookmarkLocationsFragment extends DaggerFragment {
|
|||
@BindView(R.id.parentLayout) RelativeLayout parentLayout;
|
||||
|
||||
@Inject BookmarkLocationsController controller;
|
||||
@Inject @Named("direct_nearby_upload_prefs") JsonKvStore directKvStore;
|
||||
@Inject @Named("default_preferences") BasicKvStore defaultKvStore;
|
||||
private NearbyAdapterFactory adapterFactory;
|
||||
@Inject ContributionController contributionController;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import butterknife.BindView;
|
|||
import butterknife.ButterKnife;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.contributions.MainActivity;
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.utils.SwipableCardView;
|
||||
import fr.free.nrw.commons.utils.ViewUtil;
|
||||
|
||||
|
|
@ -27,21 +26,20 @@ import fr.free.nrw.commons.utils.ViewUtil;
|
|||
public class CampaignView extends SwipableCardView {
|
||||
Campaign campaign = null;
|
||||
private ViewHolder viewHolder;
|
||||
private BasicKvStore defaultKvStore;
|
||||
|
||||
public CampaignView(@NonNull Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public CampaignView(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public CampaignView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public void setCampaign(Campaign campaign) {
|
||||
|
|
@ -63,9 +61,8 @@ public class CampaignView extends SwipableCardView {
|
|||
return true;
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
private void init() {
|
||||
View rootView = inflate(getContext(), R.layout.layout_campagin, this);
|
||||
defaultKvStore = new BasicKvStore(context, "default_preferences");
|
||||
viewHolder = new ViewHolder(rootView);
|
||||
setOnClickListener(view -> {
|
||||
if (campaign != null) {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class CategoriesModel implements CategoryClickedListener {
|
|||
@Inject
|
||||
public CategoriesModel(MediaWikiApi mwApi,
|
||||
CategoryDao categoryDao,
|
||||
@Named("direct_nearby_upload_prefs") JsonKvStore directKvStore) {
|
||||
@Named("default_preferences") JsonKvStore directKvStore) {
|
||||
this.mwApi = mwApi;
|
||||
this.categoryDao = categoryDao;
|
||||
this.directKvStore = directKvStore;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import butterknife.ButterKnife;
|
|||
import dagger.android.support.DaggerFragment;
|
||||
import fr.free.nrw.commons.Media;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.utils.NetworkUtils;
|
||||
import fr.free.nrw.commons.utils.ViewUtil;
|
||||
import io.reactivex.Observable;
|
||||
|
|
@ -56,8 +56,8 @@ public class CategoryImagesListFragment extends DaggerFragment {
|
|||
|
||||
@Inject CategoryImageController controller;
|
||||
@Inject
|
||||
@Named("category_prefs")
|
||||
BasicKvStore categoryKvStore;
|
||||
@Named("default_preferences")
|
||||
JsonKvStore categoryKvStore;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -23,10 +23,9 @@ import fr.free.nrw.commons.R;
|
|||
import fr.free.nrw.commons.auth.AccountUtil;
|
||||
import fr.free.nrw.commons.auth.SessionManager;
|
||||
import fr.free.nrw.commons.data.DBOpenHelper;
|
||||
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.location.LocationServiceManager;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import fr.free.nrw.commons.settings.Prefs;
|
||||
import fr.free.nrw.commons.upload.UploadController;
|
||||
import fr.free.nrw.commons.utils.ConfigUtils;
|
||||
|
|
@ -123,57 +122,20 @@ public class CommonsApplicationModule {
|
|||
return context.getContentResolver().acquireContentProviderClient(BuildConfig.BOOKMARK_LOCATIONS_AUTHORITY);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("application_preferences")
|
||||
public BasicKvStore providesApplicationKvStore(Context context) {
|
||||
return new BasicKvStore(context, "fr.free.nrw.commons");
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("default_preferences")
|
||||
public BasicKvStore providesDefaultKvStore(Context context) {
|
||||
public JsonKvStore providesDefaultKvStore(Context context, Gson gson) {
|
||||
String storeName = context.getPackageName() + "_preferences";
|
||||
return new BasicKvStore(context, storeName);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("defaultKvStore")
|
||||
public BasicKvStore providesOtherKvStore(Context context) {
|
||||
return new BasicKvStore(context, "defaultKvStore");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @return returns categoryPrefs
|
||||
*/
|
||||
@Provides
|
||||
@Named("category_prefs")
|
||||
public BasicKvStore providesCategoryKvStore(Context context) {
|
||||
return new BasicKvStore(context, "categoryPrefs");
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("direct_nearby_upload_prefs")
|
||||
public JsonKvStore providesDirectNearbyUploadKvStore(Context context, Gson gson) {
|
||||
return new JsonKvStore(context, "direct_nearby_upload_prefs", gson);
|
||||
return new JsonKvStore(context, storeName, gson);
|
||||
}
|
||||
|
||||
@Provides
|
||||
public UploadController providesUploadController(SessionManager sessionManager,
|
||||
@Named("default_preferences") BasicKvStore kvStore,
|
||||
@Named("default_preferences") JsonKvStore kvStore,
|
||||
Context context) {
|
||||
return new UploadController(sessionManager, context, kvStore);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public SessionManager providesSessionManager(Context context,
|
||||
MediaWikiApi mediaWikiApi,
|
||||
@Named("default_preferences") BasicKvStore defaultKvStore) {
|
||||
return new SessionManager(context, mediaWikiApi, defaultKvStore);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public LocationServiceManager provideLocationServiceManager(Context context) {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import javax.inject.Singleton;
|
|||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import fr.free.nrw.commons.BuildConfig;
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.mwapi.ApacheHttpClientMediaWikiApi;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient;
|
||||
|
|
@ -66,10 +66,9 @@ public class NetworkingModule {
|
|||
@Provides
|
||||
@Singleton
|
||||
public MediaWikiApi provideMediaWikiApi(Context context,
|
||||
@Named("default_preferences") BasicKvStore defaultKvStore,
|
||||
@Named("category_prefs") BasicKvStore categoryKvStore,
|
||||
@Named("default_preferences") JsonKvStore defaultKvStore,
|
||||
Gson gson) {
|
||||
return new ApacheHttpClientMediaWikiApi(context, BuildConfig.WIKIMEDIA_API_HOST, BuildConfig.WIKIDATA_API_HOST, defaultKvStore, categoryKvStore, gson);
|
||||
return new ApacheHttpClientMediaWikiApi(context, BuildConfig.WIKIMEDIA_API_HOST, BuildConfig.WIKIDATA_API_HOST, defaultKvStore, gson);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import fr.free.nrw.commons.category.CategoryDetailsActivity;
|
|||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||
import fr.free.nrw.commons.explore.recentsearches.RecentSearch;
|
||||
import fr.free.nrw.commons.explore.recentsearches.RecentSearchesDao;
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import fr.free.nrw.commons.utils.NetworkUtils;
|
||||
import fr.free.nrw.commons.utils.ViewUtil;
|
||||
|
|
@ -62,7 +62,9 @@ public class SearchCategoryFragment extends CommonsDaggerSupportFragment {
|
|||
|
||||
@Inject RecentSearchesDao recentSearchesDao;
|
||||
@Inject MediaWikiApi mwApi;
|
||||
@Inject @Named("default_preferences") BasicKvStore basicKvStore;
|
||||
@Inject
|
||||
@Named("default_preferences")
|
||||
JsonKvStore basicKvStore;
|
||||
|
||||
private RVRendererAdapter<String> categoriesAdapter;
|
||||
private List<String> queryList = new ArrayList<>();
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
|||
import fr.free.nrw.commons.explore.SearchActivity;
|
||||
import fr.free.nrw.commons.explore.recentsearches.RecentSearch;
|
||||
import fr.free.nrw.commons.explore.recentsearches.RecentSearchesDao;
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient;
|
||||
import fr.free.nrw.commons.utils.NetworkUtils;
|
||||
import fr.free.nrw.commons.utils.ViewUtil;
|
||||
|
|
@ -64,7 +64,9 @@ public class SearchImageFragment extends CommonsDaggerSupportFragment {
|
|||
@Inject RecentSearchesDao recentSearchesDao;
|
||||
@Inject
|
||||
OkHttpJsonApiClient okHttpJsonApiClient;
|
||||
@Inject @Named("default_preferences") BasicKvStore defaultKvStore;
|
||||
@Inject
|
||||
@Named("default_preferences")
|
||||
JsonKvStore defaultKvStore;
|
||||
|
||||
private RVRendererAdapter<Media> imagesAdapter;
|
||||
private List<Media> queryList = new ArrayList<>();
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@ import fr.free.nrw.commons.category.CategoryImagesActivity;
|
|||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||
import fr.free.nrw.commons.explore.SearchActivity;
|
||||
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.MediaWikiApi;
|
||||
import fr.free.nrw.commons.utils.ImageUtils;
|
||||
import fr.free.nrw.commons.utils.NetworkUtils;
|
||||
|
|
@ -56,7 +57,7 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
|||
|
||||
@Inject MediaWikiApi mwApi;
|
||||
@Inject SessionManager sessionManager;
|
||||
@Inject @Named("default_preferences") BasicKvStore basicKvStore;
|
||||
@Inject @Named("default_preferences") JsonKvStore store;
|
||||
@Inject BookmarkPicturesDao bookmarkDao;
|
||||
|
||||
@BindView(R.id.mediaDetailsPager) ViewPager pager;
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ import fr.free.nrw.commons.R;
|
|||
import fr.free.nrw.commons.auth.AccountUtil;
|
||||
import fr.free.nrw.commons.category.CategoryImageUtils;
|
||||
import fr.free.nrw.commons.category.QueryContinue;
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.notification.Notification;
|
||||
import fr.free.nrw.commons.notification.NotificationUtils;
|
||||
import fr.free.nrw.commons.utils.ConfigUtils;
|
||||
|
|
@ -65,8 +65,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
|||
private CustomMwApi api;
|
||||
private CustomMwApi wikidataApi;
|
||||
private Context context;
|
||||
private BasicKvStore defaultKvStore;
|
||||
private BasicKvStore categoryKvStore;
|
||||
private JsonKvStore defaultKvStore;
|
||||
private Gson gson;
|
||||
|
||||
private final String ERROR_CODE_BAD_TOKEN = "badtoken";
|
||||
|
|
@ -74,8 +73,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
|||
public ApacheHttpClientMediaWikiApi(Context context,
|
||||
String apiURL,
|
||||
String wikidatApiURL,
|
||||
BasicKvStore defaultKvStore,
|
||||
BasicKvStore categoryKvStore,
|
||||
JsonKvStore defaultKvStore,
|
||||
Gson gson) {
|
||||
this.context = context;
|
||||
BasicHttpParams params = new BasicHttpParams();
|
||||
|
|
@ -92,7 +90,6 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
|||
api = new CustomMwApi(apiURL, httpClient);
|
||||
wikidataApi = new CustomMwApi(wikidatApiURL, httpClient);
|
||||
this.defaultKvStore = defaultKvStore;
|
||||
this.categoryKvStore = categoryKvStore;
|
||||
this.gson = gson;
|
||||
}
|
||||
|
||||
|
|
@ -796,7 +793,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
|||
* @param queryContinue
|
||||
*/
|
||||
private void setQueryContinueValues(String keyword, QueryContinue queryContinue) {
|
||||
categoryKvStore.putString(keyword, gson.toJson(queryContinue));
|
||||
defaultKvStore.putString(keyword, gson.toJson(queryContinue));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -806,7 +803,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
|||
*/
|
||||
@Nullable
|
||||
private QueryContinue getQueryContinueValues(String keyword) {
|
||||
String queryContinueString = categoryKvStore.getString(keyword, null);
|
||||
String queryContinueString = defaultKvStore.getString(keyword, null);
|
||||
return gson.fromJson(queryContinueString, QueryContinue.class);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import android.content.Context;
|
|||
import android.os.Build;
|
||||
|
||||
import fr.free.nrw.commons.Utils;
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
|
||||
public class EventLog {
|
||||
static final String DEVICE;
|
||||
|
|
@ -17,11 +17,11 @@ public class EventLog {
|
|||
}
|
||||
}
|
||||
|
||||
private static LogBuilder schema(String schema, long revision, MediaWikiApi mwApi, BasicKvStore prefs, Context context) {
|
||||
private static LogBuilder schema(String schema, long revision, MediaWikiApi mwApi, JsonKvStore prefs, Context context) {
|
||||
return new LogBuilder(schema, revision, mwApi, prefs, context);
|
||||
}
|
||||
|
||||
public static LogBuilder schema(Object[] scid, MediaWikiApi mwApi, BasicKvStore prefs, Context context) {
|
||||
public static LogBuilder schema(Object[] scid, MediaWikiApi mwApi, JsonKvStore prefs, Context context) {
|
||||
if (scid.length != 2) {
|
||||
throw new IllegalArgumentException("Needs an object array with schema as first param and revision as second");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import java.net.URL;
|
|||
|
||||
import fr.free.nrw.commons.BuildConfig;
|
||||
import fr.free.nrw.commons.Utils;
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.settings.Prefs;
|
||||
import fr.free.nrw.commons.utils.ConfigUtils;
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ public class LogBuilder {
|
|||
private final JSONObject data;
|
||||
private final long rev;
|
||||
private final String schema;
|
||||
private final BasicKvStore prefs;
|
||||
private final JsonKvStore prefs;
|
||||
private final Context context;
|
||||
|
||||
/**
|
||||
|
|
@ -36,7 +36,7 @@ public class LogBuilder {
|
|||
LogBuilder(String schema,
|
||||
long revision,
|
||||
MediaWikiApi mwApi,
|
||||
BasicKvStore prefs,
|
||||
JsonKvStore prefs,
|
||||
Context context) {
|
||||
this.prefs = prefs;
|
||||
this.data = new JSONObject();
|
||||
|
|
|
|||
|
|
@ -27,14 +27,12 @@ import com.google.gson.Gson;
|
|||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.contributions.MainActivity;
|
||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import fr.free.nrw.commons.location.LocationServiceManager;
|
||||
import fr.free.nrw.commons.location.LocationUpdateListener;
|
||||
|
|
@ -76,9 +74,6 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
|
|||
NearbyController nearbyController;
|
||||
@Inject
|
||||
WikidataEditListener wikidataEditListener;
|
||||
@Inject
|
||||
@Named("application_preferences")
|
||||
BasicKvStore applicationKvStore;
|
||||
@Inject Gson gson;
|
||||
|
||||
public NearbyMapFragment nearbyMapFragment;
|
||||
|
|
|
|||
|
|
@ -15,15 +15,12 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.contributions.ContributionController;
|
||||
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 timber.log.Timber;
|
||||
|
||||
|
|
@ -39,8 +36,6 @@ public class NearbyListFragment extends CommonsDaggerSupportFragment {
|
|||
private RecyclerView recyclerView;
|
||||
|
||||
@Inject ContributionController controller;
|
||||
@Inject @Named("direct_nearby_upload_prefs") JsonKvStore directKvStore;
|
||||
@Inject @Named("default_preferences") BasicKvStore defaultKvStore;
|
||||
@Inject Gson gson;
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -8,13 +8,6 @@ import android.graphics.Bitmap;
|
|||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
|
|
@ -29,6 +22,8 @@ import android.widget.ProgressBar;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
|
|
@ -53,6 +48,11 @@ import java.util.List;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
||||
import dagger.android.support.DaggerFragment;
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.R;
|
||||
|
|
@ -60,7 +60,6 @@ import fr.free.nrw.commons.Utils;
|
|||
import fr.free.nrw.commons.auth.LoginActivity;
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
|
||||
import fr.free.nrw.commons.contributions.ContributionController;
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.utils.LocationUtils;
|
||||
import fr.free.nrw.commons.utils.UiUtils;
|
||||
|
|
@ -129,10 +128,7 @@ public class NearbyMapFragment extends DaggerFragment {
|
|||
private Bundle bundleForUpdates;// Carry information from activity about changed nearby places and current location
|
||||
private boolean searchedAroundCurrentLocation = true;
|
||||
|
||||
@Inject @Named("application_preferences") BasicKvStore applicationKvStore;
|
||||
@Inject @Named("defaultKvStore") BasicKvStore prefs;
|
||||
@Inject @Named("direct_nearby_upload_prefs") JsonKvStore directKvStore;
|
||||
@Inject @Named("default_preferences") BasicKvStore defaultKvStore;
|
||||
@Inject @Named("default_preferences") JsonKvStore applicationKvStore;
|
||||
@Inject BookmarkLocationsDao bookmarkLocationDao;
|
||||
@Inject ContributionController controller;
|
||||
@Inject Gson gson;
|
||||
|
|
@ -512,7 +508,7 @@ public class NearbyMapFragment extends DaggerFragment {
|
|||
*/
|
||||
private void setupMapView(Bundle savedInstanceState) {
|
||||
Timber.d("setupMapView called");
|
||||
boolean isDarkTheme = defaultKvStore.getBoolean("theme", false);
|
||||
boolean isDarkTheme = applicationKvStore.getBoolean("theme", false);
|
||||
MapboxMapOptions options = new MapboxMapOptions()
|
||||
.compassGravity(Gravity.BOTTOM | Gravity.LEFT)
|
||||
.compassMargins(new int[]{12, 0, 0, 24})
|
||||
|
|
@ -900,7 +896,7 @@ public class NearbyMapFragment extends DaggerFragment {
|
|||
|
||||
void storeSharedPrefs() {
|
||||
Timber.d("Store place object %s", place.toString());
|
||||
directKvStore.putJson(PLACE_OBJECT, place);
|
||||
applicationKvStore.putJson(PLACE_OBJECT, place);
|
||||
}
|
||||
|
||||
private void openWebView(Uri link) {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ import fr.free.nrw.commons.auth.LoginActivity;
|
|||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
|
||||
import fr.free.nrw.commons.contributions.ContributionController;
|
||||
import fr.free.nrw.commons.di.ApplicationlessInjection;
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
|
@ -69,10 +68,9 @@ public class PlaceRenderer extends Renderer<Place> {
|
|||
private OnBookmarkClick onBookmarkClick;
|
||||
|
||||
@Inject BookmarkLocationsDao bookmarkLocationDao;
|
||||
@Inject @Named("application_preferences") BasicKvStore applicationKvStore;
|
||||
@Inject @Named("defaultKvStore") BasicKvStore prefs;
|
||||
@Inject @Named("direct_nearby_upload_prefs") JsonKvStore directKvStore;
|
||||
@Inject @Named("default_preferences") BasicKvStore defaultKvStore;
|
||||
@Inject
|
||||
@Named("default_preferences")
|
||||
JsonKvStore applicationKvStore;
|
||||
|
||||
public PlaceRenderer(){
|
||||
openedItems = new ArrayList<>();
|
||||
|
|
@ -138,7 +136,7 @@ public class PlaceRenderer extends Renderer<Place> {
|
|||
.setPositiveButton(R.string.login, (dialog, which) -> {
|
||||
startActivityWithFlags( getContext(), LoginActivity.class, Intent.FLAG_ACTIVITY_CLEAR_TOP,
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
prefs.putBoolean("login_skipped", false);
|
||||
applicationKvStore.putBoolean("login_skipped", false);
|
||||
fragment.getActivity().finish();
|
||||
})
|
||||
.show();
|
||||
|
|
@ -158,7 +156,7 @@ public class PlaceRenderer extends Renderer<Place> {
|
|||
.setPositiveButton(R.string.login, (dialog, which) -> {
|
||||
startActivityWithFlags( getContext(), LoginActivity.class, Intent.FLAG_ACTIVITY_CLEAR_TOP,
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
prefs.putBoolean("login_skipped", false);
|
||||
applicationKvStore.putBoolean("login_skipped", false);
|
||||
fragment.getActivity().finish();
|
||||
})
|
||||
.show();
|
||||
|
|
@ -177,7 +175,7 @@ public class PlaceRenderer extends Renderer<Place> {
|
|||
.setPositiveButton(R.string.login, (dialog, which) -> {
|
||||
startActivityWithFlags( getContext(), LoginActivity.class, Intent.FLAG_ACTIVITY_CLEAR_TOP,
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
prefs.putBoolean("login_skipped", false);
|
||||
applicationKvStore.putBoolean("login_skipped", false);
|
||||
fragment.getActivity().finish();
|
||||
})
|
||||
.show();
|
||||
|
|
@ -197,7 +195,7 @@ public class PlaceRenderer extends Renderer<Place> {
|
|||
|
||||
private void storeSharedPrefs() {
|
||||
Timber.d("Store place object %s", place.toString());
|
||||
directKvStore.putJson(PLACE_OBJECT, place);
|
||||
applicationKvStore.putJson(PLACE_OBJECT, place);
|
||||
}
|
||||
|
||||
private void closeLayout(LinearLayout buttonLayout){
|
||||
|
|
|
|||
|
|
@ -1,36 +1,47 @@
|
|||
package fr.free.nrw.commons.quiz;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import androidx.appcompat.app.AlertDialog.Builder;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.WelcomeActivity;
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.auth.SessionManager;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient;
|
||||
import fr.free.nrw.commons.utils.DialogUtil;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
||||
|
||||
/**
|
||||
* fetches the number of images uploaded and number of images reverted.
|
||||
* Then it calculates the percentage of the images reverted
|
||||
* if the percentage of images reverted after last quiz exceeds 50% and number of images uploaded is
|
||||
* greater than 50, then quiz is popped up
|
||||
*/
|
||||
@Singleton
|
||||
public class QuizChecker {
|
||||
|
||||
private int revertCount ;
|
||||
private int totalUploadCount ;
|
||||
private boolean isRevertCountFetched;
|
||||
private boolean isUploadCountFetched;
|
||||
|
||||
private CompositeDisposable compositeDisposable = new CompositeDisposable();
|
||||
public Context context;
|
||||
private String userName;
|
||||
private OkHttpJsonApiClient okHttpJsonApiClient;
|
||||
private BasicKvStore revertKvStore;
|
||||
private BasicKvStore countKvStore;
|
||||
|
||||
private final SessionManager sessionManager;
|
||||
private final OkHttpJsonApiClient okHttpJsonApiClient;
|
||||
private final JsonKvStore revertKvStore;
|
||||
|
||||
private static final int UPLOAD_COUNT_THRESHOLD = 5;
|
||||
private static final String REVERT_PERCENTAGE_FOR_MESSAGE = "50%";
|
||||
|
|
@ -40,32 +51,34 @@ public class QuizChecker {
|
|||
/**
|
||||
* constructor to set the parameters for quiz
|
||||
* @param context context
|
||||
* @param userName Commons user name
|
||||
* @param sessionManager
|
||||
* @param okHttpJsonApiClient instance of MediaWikiApi
|
||||
*/
|
||||
@Inject
|
||||
public QuizChecker(Context context,
|
||||
String userName,
|
||||
SessionManager sessionManager,
|
||||
OkHttpJsonApiClient okHttpJsonApiClient,
|
||||
BasicKvStore revertKvStore,
|
||||
BasicKvStore countKvStore) {
|
||||
@Named("default_preferences") JsonKvStore revertKvStore) {
|
||||
this.context = context;
|
||||
this.userName = userName;
|
||||
this.sessionManager = sessionManager;
|
||||
this.okHttpJsonApiClient = okHttpJsonApiClient;
|
||||
this.revertKvStore = revertKvStore;
|
||||
this.countKvStore = countKvStore;
|
||||
setUploadCount();
|
||||
setRevertCount();
|
||||
}
|
||||
|
||||
public void initQuizCheck(Activity activity) {
|
||||
setUploadCount(activity);
|
||||
setRevertCount(activity);
|
||||
}
|
||||
|
||||
/**
|
||||
* to fet the total number of images uploaded
|
||||
*/
|
||||
private void setUploadCount() {
|
||||
private void setUploadCount(Activity activity) {
|
||||
compositeDisposable.add(okHttpJsonApiClient
|
||||
.getUploadCount(userName)
|
||||
.getUploadCount(sessionManager.getUserName())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::setTotalUploadCount,
|
||||
.subscribe(uploadCount -> setTotalUploadCount(activity, uploadCount),
|
||||
t -> Timber.e(t, "Fetching upload count failed")
|
||||
));
|
||||
}
|
||||
|
|
@ -75,28 +88,28 @@ public class QuizChecker {
|
|||
* call function to check for quiz
|
||||
* @param uploadCount user's upload count
|
||||
*/
|
||||
private void setTotalUploadCount(int uploadCount) {
|
||||
totalUploadCount = uploadCount - countKvStore.getInt(UPLOAD_SHARED_PREFERENCE, 0);
|
||||
private void setTotalUploadCount(Activity activity, int uploadCount) {
|
||||
totalUploadCount = uploadCount - revertKvStore.getInt(UPLOAD_SHARED_PREFERENCE, 0);
|
||||
if ( totalUploadCount < 0){
|
||||
totalUploadCount = 0;
|
||||
countKvStore.putInt(UPLOAD_SHARED_PREFERENCE, 0);
|
||||
revertKvStore.putInt(UPLOAD_SHARED_PREFERENCE, 0);
|
||||
}
|
||||
isUploadCountFetched = true;
|
||||
calculateRevertParameter();
|
||||
calculateRevertParameter(activity);
|
||||
}
|
||||
|
||||
/**
|
||||
* To call the API to get reverts count in form of JSONObject
|
||||
*/
|
||||
private void setRevertCount() {
|
||||
private void setRevertCount(Activity activity) {
|
||||
compositeDisposable.add(okHttpJsonApiClient
|
||||
.getAchievements(userName)
|
||||
.getAchievements(sessionManager.getUserName())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
response -> {
|
||||
if (response != null) {
|
||||
setRevertParameter(response.getDeletedUploads());
|
||||
setRevertParameter(activity, response.getDeletedUploads());
|
||||
}
|
||||
}, throwable -> Timber.e(throwable, "Fetching feedback failed"))
|
||||
);
|
||||
|
|
@ -106,52 +119,52 @@ public class QuizChecker {
|
|||
* to calculate the number of images reverted after previous quiz
|
||||
* @param revertCountFetched count of deleted uploads
|
||||
*/
|
||||
private void setRevertParameter(int revertCountFetched) {
|
||||
private void setRevertParameter(Activity activity, int revertCountFetched) {
|
||||
revertCount = revertCountFetched - revertKvStore.getInt(REVERT_SHARED_PREFERENCE, 0);
|
||||
if (revertCount < 0){
|
||||
revertCount = 0;
|
||||
revertKvStore.putInt(REVERT_SHARED_PREFERENCE, 0);
|
||||
}
|
||||
isRevertCountFetched = true;
|
||||
calculateRevertParameter();
|
||||
calculateRevertParameter(activity);
|
||||
}
|
||||
|
||||
/**
|
||||
* to check whether the criterion to call quiz is satisfied
|
||||
*/
|
||||
private void calculateRevertParameter() {
|
||||
private void calculateRevertParameter(Activity activity) {
|
||||
if ( revertCount < 0 || totalUploadCount < 0){
|
||||
revertKvStore.putInt(REVERT_SHARED_PREFERENCE, 0);
|
||||
countKvStore.putInt(UPLOAD_SHARED_PREFERENCE, 0);
|
||||
revertKvStore.putInt(UPLOAD_SHARED_PREFERENCE, 0);
|
||||
return;
|
||||
}
|
||||
if (isRevertCountFetched && isUploadCountFetched &&
|
||||
totalUploadCount >= UPLOAD_COUNT_THRESHOLD &&
|
||||
(revertCount * 100) / totalUploadCount >= 50) {
|
||||
callQuiz();
|
||||
callQuiz(activity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alert which prompts to quiz
|
||||
*/
|
||||
private void callQuiz() {
|
||||
Builder alert = new Builder(context);
|
||||
alert.setTitle(context.getResources().getString(R.string.quiz));
|
||||
alert.setMessage(context.getResources().getString(R.string.quiz_alert_message,
|
||||
REVERT_PERCENTAGE_FOR_MESSAGE));
|
||||
alert.setPositiveButton(R.string.about_translate_proceed, (dialog, which) -> {
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
private void callQuiz(Activity activity) {
|
||||
DialogUtil.showAlertDialog(activity,
|
||||
context.getResources().getString(R.string.quiz),
|
||||
context.getResources().getString(R.string.quiz_alert_message, REVERT_PERCENTAGE_FOR_MESSAGE),
|
||||
context.getResources().getString(R.string.about_translate_proceed),
|
||||
context.getResources().getString(android.R.string.cancel),
|
||||
() -> startQuizActivity(activity), null);
|
||||
}
|
||||
|
||||
private void startQuizActivity(Activity activity) {
|
||||
int newRevetSharedPrefs = revertCount + revertKvStore.getInt(REVERT_SHARED_PREFERENCE, 0);
|
||||
revertKvStore.putInt(REVERT_SHARED_PREFERENCE, newRevetSharedPrefs);
|
||||
int newUploadCount = totalUploadCount + countKvStore.getInt(UPLOAD_SHARED_PREFERENCE, 0);
|
||||
countKvStore.putInt(UPLOAD_SHARED_PREFERENCE, newUploadCount);
|
||||
int newUploadCount = totalUploadCount + revertKvStore.getInt(UPLOAD_SHARED_PREFERENCE, 0);
|
||||
revertKvStore.putInt(UPLOAD_SHARED_PREFERENCE, newUploadCount);
|
||||
Intent i = new Intent(context, WelcomeActivity.class);
|
||||
i.putExtra("isQuiz", true);
|
||||
dialog.dismiss();
|
||||
context.startActivity(i);
|
||||
});
|
||||
alert.setNegativeButton(android.R.string.cancel, (dialogInterface, i) -> dialogInterface.cancel());
|
||||
androidx.appcompat.app.AlertDialog dialog = alert.create();
|
||||
dialog.show();
|
||||
activity.startActivity(i);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ import javax.inject.Named;
|
|||
import fr.free.nrw.commons.R;
|
||||
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.logging.CommonsLogSender;
|
||||
import fr.free.nrw.commons.utils.PermissionUtils;
|
||||
import fr.free.nrw.commons.utils.ViewUtil;
|
||||
|
|
@ -29,7 +30,7 @@ public class SettingsFragment extends PreferenceFragment {
|
|||
|
||||
@Inject
|
||||
@Named("default_preferences")
|
||||
BasicKvStore defaultKvStore;
|
||||
JsonKvStore defaultKvStore;
|
||||
@Inject
|
||||
CommonsLogSender commonsLogSender;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,12 +7,13 @@ import javax.inject.Named;
|
|||
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.di.CommonsDaggerAppCompatActivity;
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
|
||||
public abstract class BaseActivity extends CommonsDaggerAppCompatActivity {
|
||||
@Inject
|
||||
@Named("default_preferences")
|
||||
BasicKvStore defaultKvStore;
|
||||
public JsonKvStore defaultKvStore;
|
||||
|
||||
protected boolean wasPreviouslyDarkTheme;
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ import fr.free.nrw.commons.auth.LoginActivity;
|
|||
import fr.free.nrw.commons.bookmarks.BookmarksActivity;
|
||||
import fr.free.nrw.commons.category.CategoryImagesActivity;
|
||||
import fr.free.nrw.commons.contributions.MainActivity;
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.logging.CommonsLogSender;
|
||||
import fr.free.nrw.commons.settings.SettingsActivity;
|
||||
import timber.log.Timber;
|
||||
|
|
@ -54,7 +54,9 @@ public abstract class NavigationBaseActivity extends BaseActivity
|
|||
NavigationView navigationView;
|
||||
@BindView(R.id.drawer_layout)
|
||||
DrawerLayout drawerLayout;
|
||||
@Inject @Named("application_preferences") BasicKvStore applicationKvStore;
|
||||
@Inject
|
||||
@Named("default_preferences")
|
||||
JsonKvStore applicationKvStore;
|
||||
@Inject CommonsLogSender commonsLogSender;
|
||||
|
||||
|
||||
|
|
@ -292,7 +294,7 @@ public abstract class NavigationBaseActivity extends BaseActivity
|
|||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||
if (drawer.isDrawerOpen(GravityCompat.START)) {
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import javax.inject.Named;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import fr.free.nrw.commons.caching.CacheController;
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.mwapi.CategoryApi;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import timber.log.Timber;
|
||||
|
|
@ -37,7 +37,7 @@ public class FileProcessor implements SimilarImageDialogFragment.onResponse {
|
|||
CategoryApi apiCall;
|
||||
@Inject
|
||||
@Named("default_preferences")
|
||||
BasicKvStore defaultKvStore;
|
||||
JsonKvStore defaultKvStore;
|
||||
private String filePath;
|
||||
private ContentResolver contentResolver;
|
||||
private GPSExtractor imageObj;
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ public class UploadActivity extends BaseActivity implements UploadView, SimilarI
|
|||
@Inject MediaWikiApi mwApi;
|
||||
@Inject
|
||||
ContributionController contributionController;
|
||||
@Inject @Named("direct_nearby_upload_prefs") JsonKvStore directKvStore;
|
||||
@Inject @Named("default_preferences") JsonKvStore directKvStore;
|
||||
@Inject UploadPresenter presenter;
|
||||
@Inject CategoriesModel categoriesModel;
|
||||
@Inject SessionManager sessionManager;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ import fr.free.nrw.commons.HandlerService;
|
|||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.auth.SessionManager;
|
||||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.settings.Prefs;
|
||||
import fr.free.nrw.commons.utils.ViewUtil;
|
||||
import timber.log.Timber;
|
||||
|
|
@ -39,7 +39,7 @@ public class UploadController {
|
|||
private UploadService uploadService;
|
||||
private SessionManager sessionManager;
|
||||
private Context context;
|
||||
private BasicKvStore defaultKvStore;
|
||||
private JsonKvStore store;
|
||||
|
||||
public interface ContributionUploadProgress {
|
||||
void onUploadStarted(Contribution contribution);
|
||||
|
|
@ -49,10 +49,10 @@ public class UploadController {
|
|||
@Inject
|
||||
public UploadController(SessionManager sessionManager,
|
||||
Context context,
|
||||
BasicKvStore store) {
|
||||
JsonKvStore store) {
|
||||
this.sessionManager = sessionManager;
|
||||
this.context = context;
|
||||
this.defaultKvStore = store;
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
private boolean isUploadServiceConnected;
|
||||
|
|
@ -110,8 +110,8 @@ public class UploadController {
|
|||
//Set creator, desc, and license
|
||||
|
||||
// If author name is enabled and set, use it
|
||||
if (defaultKvStore.getBoolean("useAuthorName", false)) {
|
||||
String authorName = defaultKvStore.getString("authorName", "");
|
||||
if (store.getBoolean("useAuthorName", false)) {
|
||||
String authorName = store.getString("authorName", "");
|
||||
contribution.setCreator(authorName);
|
||||
}
|
||||
|
||||
|
|
@ -130,7 +130,7 @@ public class UploadController {
|
|||
contribution.setDescription("");
|
||||
}
|
||||
|
||||
String license = defaultKvStore.getString(Prefs.DEFAULT_LICENSE, Prefs.Licenses.CC_BY_SA_3);
|
||||
String license = store.getString(Prefs.DEFAULT_LICENSE, Prefs.Licenses.CC_BY_SA_3);
|
||||
contribution.setLicense(license);
|
||||
|
||||
//FIXME: Add permission request here. Only executeAsyncTask if permission has been granted
|
||||
|
|
|
|||
|
|
@ -4,9 +4,6 @@ import android.annotation.SuppressLint;
|
|||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
|
@ -22,7 +19,7 @@ import fr.free.nrw.commons.auth.SessionManager;
|
|||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
import fr.free.nrw.commons.filepicker.MimeTypeMapWrapper;
|
||||
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.settings.Prefs;
|
||||
import fr.free.nrw.commons.utils.ImageUtils;
|
||||
|
|
@ -46,7 +43,7 @@ public class UploadModel {
|
|||
null,
|
||||
-1L, "") {
|
||||
};
|
||||
private final BasicKvStore basicKvStore;
|
||||
private final JsonKvStore store;
|
||||
private final List<String> licenses;
|
||||
private String license;
|
||||
private final Map<String, String> licensesByName;
|
||||
|
|
@ -64,15 +61,15 @@ public class UploadModel {
|
|||
|
||||
@Inject
|
||||
UploadModel(@Named("licenses") List<String> licenses,
|
||||
@Named("default_preferences") BasicKvStore basicKvStore,
|
||||
@Named("default_preferences") JsonKvStore store,
|
||||
@Named("licenses_by_name") Map<String, String> licensesByName,
|
||||
Context context,
|
||||
SessionManager sessionManager,
|
||||
FileProcessor fileProcessor,
|
||||
ImageProcessingService imageProcessingService) {
|
||||
this.licenses = licenses;
|
||||
this.basicKvStore = basicKvStore;
|
||||
this.license = basicKvStore.getString(Prefs.DEFAULT_LICENSE, Prefs.Licenses.CC_BY_SA_3);
|
||||
this.store = store;
|
||||
this.license = store.getString(Prefs.DEFAULT_LICENSE, Prefs.Licenses.CC_BY_SA_3);
|
||||
this.licensesByName = licensesByName;
|
||||
this.context = context;
|
||||
this.sessionManager = sessionManager;
|
||||
|
|
@ -94,7 +91,6 @@ public class UploadModel {
|
|||
return imageProcessingService.validateImage(uploadItem, checkTitle);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private UploadItem getUploadItem(UploadableFile uploadableFile,
|
||||
Place place,
|
||||
String source,
|
||||
|
|
@ -273,7 +269,7 @@ public class UploadModel {
|
|||
|
||||
void setSelectedLicense(String licenseName) {
|
||||
this.license = licensesByName.get(licenseName);
|
||||
basicKvStore.putString(Prefs.DEFAULT_LICENSE, license);
|
||||
store.putString(Prefs.DEFAULT_LICENSE, license);
|
||||
}
|
||||
|
||||
Observable<Contribution> buildContributions(List<String> categoryStringList) {
|
||||
|
|
@ -348,7 +344,7 @@ public class UploadModel {
|
|||
@SuppressLint("CheckResult")
|
||||
UploadItem(Uri originalContentUri,
|
||||
Uri mediaUri, String mimeType, String source, GPSExtractor gpsCoords,
|
||||
@Nullable Place place,
|
||||
Place place,
|
||||
long createdTimestamp,
|
||||
String createdTimestampSource) {
|
||||
this.originalContentUri = originalContentUri;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import fr.free.nrw.commons.R;
|
|||
import fr.free.nrw.commons.category.CategoriesModel;
|
||||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
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.settings.Prefs;
|
||||
|
|
@ -52,19 +51,16 @@ public class UploadPresenter {
|
|||
private final UploadModel uploadModel;
|
||||
private final UploadController uploadController;
|
||||
private final Context context;
|
||||
private final BasicKvStore defaultKvStore;
|
||||
private final JsonKvStore directKvStore;
|
||||
|
||||
@Inject
|
||||
UploadPresenter(UploadModel uploadModel,
|
||||
UploadController uploadController,
|
||||
Context context,
|
||||
@Named("default_preferences") BasicKvStore defaultKvStore,
|
||||
@Named("direct_nearby_upload_prefs") JsonKvStore directKvStore) {
|
||||
@Named("default_preferences") JsonKvStore directKvStore) {
|
||||
this.uploadModel = uploadModel;
|
||||
this.uploadController = uploadController;
|
||||
this.context = context;
|
||||
this.defaultKvStore = defaultKvStore;
|
||||
this.directKvStore = directKvStore;
|
||||
}
|
||||
|
||||
|
|
@ -331,7 +327,7 @@ public class UploadPresenter {
|
|||
* Sets the list of licences and the default license.
|
||||
*/
|
||||
private void updateLicenses() {
|
||||
String selectedLicense = defaultKvStore.getString(Prefs.DEFAULT_LICENSE, Prefs.Licenses.CC_BY_SA_3);
|
||||
String selectedLicense = directKvStore.getString(Prefs.DEFAULT_LICENSE, Prefs.Licenses.CC_BY_SA_3);
|
||||
view.updateLicenses(uploadModel.getLicenses(), selectedLicense);
|
||||
view.updateLicenseSummary(selectedLicense, uploadModel.getCount());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import javax.inject.Named;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import fr.free.nrw.commons.utils.ViewUtil;
|
||||
|
|
@ -30,13 +29,13 @@ public class WikidataEditService {
|
|||
private final Context context;
|
||||
private final MediaWikiApi mediaWikiApi;
|
||||
private final WikidataEditListener wikidataEditListener;
|
||||
private final BasicKvStore directKvStore;
|
||||
private final JsonKvStore directKvStore;
|
||||
|
||||
@Inject
|
||||
public WikidataEditService(Context context,
|
||||
MediaWikiApi mediaWikiApi,
|
||||
WikidataEditListener wikidataEditListener,
|
||||
@Named("direct_nearby_upload_prefs") JsonKvStore directKvStore) {
|
||||
@Named("default_preferences") JsonKvStore directKvStore) {
|
||||
this.context = context;
|
||||
this.mediaWikiApi = mediaWikiApi;
|
||||
this.wikidataEditListener = wikidataEditListener;
|
||||
|
|
|
|||
|
|
@ -7,16 +7,12 @@ import com.google.gson.Gson
|
|||
import com.nhaarman.mockito_kotlin.mock
|
||||
import com.squareup.leakcanary.RefWatcher
|
||||
import fr.free.nrw.commons.auth.AccountUtil
|
||||
import fr.free.nrw.commons.auth.SessionManager
|
||||
import fr.free.nrw.commons.data.DBOpenHelper
|
||||
import fr.free.nrw.commons.di.CommonsApplicationComponent
|
||||
import fr.free.nrw.commons.di.CommonsApplicationModule
|
||||
import fr.free.nrw.commons.di.DaggerCommonsApplicationComponent
|
||||
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.mwapi.MediaWikiApi
|
||||
import fr.free.nrw.commons.upload.UploadController
|
||||
|
||||
class TestCommonsApplication : CommonsApplication() {
|
||||
private var mockApplicationComponent: CommonsApplicationComponent? = null
|
||||
|
|
@ -37,11 +33,7 @@ class TestCommonsApplication : CommonsApplication() {
|
|||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
class MockCommonsApplicationModule(appContext: Context) : CommonsApplicationModule(appContext) {
|
||||
val accountUtil: AccountUtil = mock()
|
||||
val appSharedPreferences: BasicKvStore = mock()
|
||||
val defaultSharedPreferences: BasicKvStore = mock()
|
||||
val otherSharedPreferences: BasicKvStore = mock()
|
||||
val uploadController: UploadController = mock()
|
||||
val mockSessionManager: SessionManager = mock()
|
||||
val defaultSharedPreferences: JsonKvStore = mock()
|
||||
val locationServiceManager: LocationServiceManager = mock()
|
||||
val mockDbOpenHelper: DBOpenHelper = mock()
|
||||
val lruCache: LruCache<String, String> = mock()
|
||||
|
|
@ -57,19 +49,9 @@ class MockCommonsApplicationModule(appContext: Context) : CommonsApplicationModu
|
|||
|
||||
override fun provideModificationContentProviderClient(context: Context?): ContentProviderClient = modificationClient
|
||||
|
||||
override fun providesDirectNearbyUploadKvStore(context: Context?, gson: Gson): JsonKvStore = uploadPrefs
|
||||
|
||||
override fun providesAccountUtil(context: Context): AccountUtil = accountUtil
|
||||
|
||||
override fun providesApplicationKvStore(context: Context): BasicKvStore = appSharedPreferences
|
||||
|
||||
override fun providesDefaultKvStore(context: Context): BasicKvStore = defaultSharedPreferences
|
||||
|
||||
override fun providesOtherKvStore(context: Context): BasicKvStore = otherSharedPreferences
|
||||
|
||||
override fun providesUploadController(sessionManager: SessionManager, sharedPreferences: BasicKvStore, context: Context): UploadController = uploadController
|
||||
|
||||
override fun providesSessionManager(context: Context, mediaWikiApi: MediaWikiApi, sharedPreferences: BasicKvStore): SessionManager = mockSessionManager
|
||||
override fun providesDefaultKvStore(context: Context, gson: Gson): JsonKvStore = defaultSharedPreferences
|
||||
|
||||
override fun provideLocationServiceManager(context: Context): LocationServiceManager = locationServiceManager
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import android.os.Build
|
|||
import com.google.gson.Gson
|
||||
import fr.free.nrw.commons.BuildConfig
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||
import fr.free.nrw.commons.utils.ConfigUtils
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.mockwebserver.MockResponse
|
||||
|
|
@ -30,8 +30,7 @@ class ApacheHttpClientMediaWikiApiTest {
|
|||
private lateinit var testObject: ApacheHttpClientMediaWikiApi
|
||||
private lateinit var server: MockWebServer
|
||||
private lateinit var wikidataServer: MockWebServer
|
||||
private lateinit var sharedPreferences: BasicKvStore
|
||||
private lateinit var categoryPreferences: BasicKvStore
|
||||
private lateinit var sharedPreferences: JsonKvStore
|
||||
private lateinit var okHttpClient: OkHttpClient
|
||||
|
||||
@Before
|
||||
|
|
@ -39,9 +38,8 @@ class ApacheHttpClientMediaWikiApiTest {
|
|||
server = MockWebServer()
|
||||
wikidataServer = MockWebServer()
|
||||
okHttpClient = OkHttpClient()
|
||||
sharedPreferences = mock(BasicKvStore::class.java)
|
||||
categoryPreferences = mock(BasicKvStore::class.java)
|
||||
testObject = ApacheHttpClientMediaWikiApi(RuntimeEnvironment.application, "http://" + server.hostName + ":" + server.port + "/", "http://" + wikidataServer.hostName + ":" + wikidataServer.port + "/", sharedPreferences, categoryPreferences, Gson())
|
||||
sharedPreferences = mock(JsonKvStore::class.java)
|
||||
testObject = ApacheHttpClientMediaWikiApi(RuntimeEnvironment.application, "http://" + server.hostName + ":" + server.port + "/", "http://" + wikidataServer.hostName + ":" + wikidataServer.port + "/", sharedPreferences, Gson())
|
||||
}
|
||||
|
||||
@After
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import fr.free.nrw.commons.HandlerService
|
|||
import fr.free.nrw.commons.auth.SessionManager
|
||||
import fr.free.nrw.commons.contributions.Contribution
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.InjectMocks
|
||||
|
|
@ -21,7 +22,7 @@ class UploadControllerTest {
|
|||
@Mock
|
||||
internal var context: Context? = null
|
||||
@Mock
|
||||
internal var prefs: BasicKvStore? = null
|
||||
internal var prefs: JsonKvStore? = null
|
||||
|
||||
@InjectMocks
|
||||
var uploadController: UploadController? = null
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import android.content.Context
|
|||
import fr.free.nrw.commons.auth.SessionManager
|
||||
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.mwapi.MediaWikiApi
|
||||
import fr.free.nrw.commons.nearby.Place
|
||||
import fr.free.nrw.commons.utils.ImageUtils.IMAGE_OK
|
||||
|
|
@ -34,7 +35,7 @@ class UploadModelTest {
|
|||
internal var licenses: List<String>? = null
|
||||
@Mock
|
||||
@field:[Inject Named("default_preferences")]
|
||||
internal var prefs: BasicKvStore? = null
|
||||
internal var prefs: JsonKvStore? = null
|
||||
@Mock
|
||||
@field:[Inject Named("licenses_by_name")]
|
||||
internal var licensesByName: Map<String, String>? = null
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue