mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 21:33:53 +01:00
Use wrapper for interacting with shared preferences (#2288)
* Use wrapper for accessing shared preferences across the app * Use Json kv store for storing place object * Fix tests * Fix test failure * Fix UI tests
This commit is contained in:
parent
1b7b909107
commit
d4fa9cfa45
61 changed files with 908 additions and 585 deletions
|
|
@ -8,15 +8,18 @@ import android.support.annotation.Nullable;
|
|||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
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;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* A view which represents a single campaign
|
||||
|
|
@ -24,20 +27,21 @@ import java.util.Date;
|
|||
public class CampaignView extends SwipableCardView {
|
||||
Campaign campaign = null;
|
||||
private ViewHolder viewHolder;
|
||||
private BasicKvStore defaultKvStore;
|
||||
|
||||
public CampaignView(@NonNull Context context) {
|
||||
super(context);
|
||||
init();
|
||||
init(context);
|
||||
}
|
||||
|
||||
public CampaignView(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
init(context);
|
||||
}
|
||||
|
||||
public CampaignView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
init(context);
|
||||
}
|
||||
|
||||
public void setCampaign(Campaign campaign) {
|
||||
|
|
@ -52,16 +56,16 @@ public class CampaignView extends SwipableCardView {
|
|||
|
||||
@Override public boolean onSwipe(View view) {
|
||||
view.setVisibility(View.GONE);
|
||||
((MainActivity) getContext()).prefs.edit()
|
||||
.putBoolean("displayCampaignsCardView", false)
|
||||
.apply();
|
||||
((MainActivity) getContext()).defaultKvStore
|
||||
.putBoolean("displayCampaignsCardView", false);
|
||||
ViewUtil.showLongToast(getContext(),
|
||||
getResources().getString(R.string.nearby_campaign_dismiss_message));
|
||||
return true;
|
||||
}
|
||||
|
||||
private void init() {
|
||||
private void init(Context context) {
|
||||
View rootView = inflate(getContext(), R.layout.layout_campagin, this);
|
||||
defaultKvStore = new BasicKvStore(context, "default_preferences");
|
||||
viewHolder = new ViewHolder(rootView);
|
||||
setOnClickListener(view -> {
|
||||
if (campaign != null) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,13 @@
|
|||
package fr.free.nrw.commons.campaigns;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import fr.free.nrw.commons.BasePresenter;
|
||||
import fr.free.nrw.commons.MvpView;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
|
|
@ -9,11 +16,6 @@ import io.reactivex.SingleObserver;
|
|||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The presenter for the campaigns view, fetches the campaigns from the api and informs the view on
|
||||
|
|
@ -33,7 +35,9 @@ public class CampaignsPresenter implements BasePresenter {
|
|||
|
||||
@Override public void onDetachView() {
|
||||
this.view = null;
|
||||
disposable.dispose();
|
||||
if (disposable != null) {
|
||||
disposable.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue