Move SharedPreferences injection into NearbyMapFragment

This commit is contained in:
misaochan 2018-01-24 21:13:33 +10:00 committed by maskara
parent 89d0f8da8f
commit 9a1a004a25
2 changed files with 12 additions and 5 deletions

View file

@ -23,15 +23,16 @@ class DirectUpload {
private String desc; private String desc;
private ContributionController controller; private ContributionController controller;
private Fragment fragment; private Fragment fragment;
private SharedPreferences prefs;
@Inject @Named("prefs") SharedPreferences prefs;
@Inject @Named("default_preferences") SharedPreferences defaultPrefs;
DirectUpload(String title, String desc, Fragment fragment, ContributionController controller) {
DirectUpload(String title, String desc, Fragment fragment, ContributionController controller, SharedPreferences prefs) {
this.title = title; this.title = title;
this.desc = desc; this.desc = desc;
this.fragment = fragment; this.fragment = fragment;
this.controller = controller; this.controller = controller;
this.prefs = prefs;
} }
void storeSharedPrefs() { void storeSharedPrefs() {

View file

@ -1,6 +1,7 @@
package fr.free.nrw.commons.nearby; package fr.free.nrw.commons.nearby;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Color; import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
@ -39,6 +40,9 @@ import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
import dagger.android.support.DaggerFragment; import dagger.android.support.DaggerFragment;
import fr.free.nrw.commons.R; import fr.free.nrw.commons.R;
import fr.free.nrw.commons.contributions.ContributionController; import fr.free.nrw.commons.contributions.ContributionController;
@ -86,6 +90,8 @@ public class NearbyMapFragment extends DaggerFragment {
private Place place; private Place place;
private Marker selected; private Marker selected;
@Inject @Named("prefs") SharedPreferences prefs;
public NearbyMapFragment() { public NearbyMapFragment() {
} }
@ -403,7 +409,7 @@ public class NearbyMapFragment extends DaggerFragment {
fabCamera.setOnClickListener(view -> { fabCamera.setOnClickListener(view -> {
Timber.d("Camera button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription()); Timber.d("Camera button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
controller = new ContributionController(this); controller = new ContributionController(this);
DirectUpload directUpload = new DirectUpload(place.getName(), place.getLongDescription(), this, controller); DirectUpload directUpload = new DirectUpload(place.getName(), place.getLongDescription(), this, controller, prefs);
directUpload.storeSharedPrefs(); directUpload.storeSharedPrefs();
directUpload.initiateCameraUpload(); directUpload.initiateCameraUpload();
}); });
@ -411,7 +417,7 @@ public class NearbyMapFragment extends DaggerFragment {
fabGallery.setOnClickListener(view -> { fabGallery.setOnClickListener(view -> {
Timber.d("Gallery button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription()); Timber.d("Gallery button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
controller = new ContributionController(this); controller = new ContributionController(this);
DirectUpload directUpload = new DirectUpload(place.getName(), place.getLongDescription(), this, controller); DirectUpload directUpload = new DirectUpload(place.getName(), place.getLongDescription(), this, controller, prefs);
directUpload.storeSharedPrefs(); directUpload.storeSharedPrefs();
directUpload.initiateGalleryUpload(); directUpload.initiateGalleryUpload();