mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Merge remote-tracking branch 'refs/remotes/commons-app/master'
This commit is contained in:
commit
3274c4cc4a
20 changed files with 185 additions and 93 deletions
|
|
@ -0,0 +1,57 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import fr.free.nrw.commons.nearby.NearbyBaseMarker;
|
||||
import fr.free.nrw.commons.nearby.NearbyController;
|
||||
import fr.free.nrw.commons.nearby.Place;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class NearbyControllerTest {
|
||||
private Context instrumentationContext;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
instrumentationContext = InstrumentationRegistry.getContext();
|
||||
}
|
||||
|
||||
@Test public void testNullAttractions() {
|
||||
LatLng location = new LatLng(0, 0);
|
||||
|
||||
List<NearbyBaseMarker> options =
|
||||
NearbyController.loadAttractionsFromLocationToBaseMarkerOptions(
|
||||
location,
|
||||
null,
|
||||
instrumentationContext
|
||||
);
|
||||
|
||||
Assert.assertThat(options.size(), is(0));
|
||||
}
|
||||
|
||||
@Test public void testEmptyList() {
|
||||
LatLng location = new LatLng(0, 0);
|
||||
List<Place> emptyList = new ArrayList<>();
|
||||
|
||||
List<NearbyBaseMarker> options =
|
||||
NearbyController.loadAttractionsFromLocationToBaseMarkerOptions(
|
||||
location,
|
||||
emptyList,
|
||||
instrumentationContext
|
||||
);
|
||||
|
||||
Assert.assertThat(options.size(), is(0));
|
||||
}
|
||||
}
|
||||
|
|
@ -3,9 +3,11 @@ package fr.free.nrw.commons;
|
|||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.graphics.drawable.VectorDrawableCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
|
||||
public class MediaWikiImageView extends SimpleDraweeView {
|
||||
|
|
@ -13,14 +15,17 @@ public class MediaWikiImageView extends SimpleDraweeView {
|
|||
|
||||
public MediaWikiImageView(Context context) {
|
||||
this(context, null);
|
||||
init();
|
||||
}
|
||||
|
||||
public MediaWikiImageView(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
init();
|
||||
}
|
||||
|
||||
public MediaWikiImageView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init();
|
||||
}
|
||||
|
||||
public void setMedia(Media media) {
|
||||
|
|
@ -48,6 +53,16 @@ public class MediaWikiImageView extends SimpleDraweeView {
|
|||
super.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setHierarchy(GenericDraweeHierarchyBuilder
|
||||
.newInstance(getResources())
|
||||
.setPlaceholderImage(VectorDrawableCompat.create(getResources(),
|
||||
R.drawable.ic_image_black_24dp, getContext().getTheme()))
|
||||
.setFailureImage(VectorDrawableCompat.create(getResources(),
|
||||
R.drawable.ic_image_black_24dp, getContext().getTheme()))
|
||||
.build());
|
||||
}
|
||||
|
||||
private void setImageUrl(@Nullable String url) {
|
||||
setImageURI(url);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ public class WelcomeActivity extends BaseActivity {
|
|||
|
||||
@BindView(R.id.welcomePager) ViewPager pager;
|
||||
@BindView(R.id.welcomePagerIndicator) CirclePageIndicator indicator;
|
||||
private WelcomePagerAdapter adapter = new WelcomePagerAdapter();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
|
@ -24,12 +25,19 @@ public class WelcomeActivity extends BaseActivity {
|
|||
}
|
||||
ButterKnife.bind(this);
|
||||
|
||||
setUpAdapter();
|
||||
}
|
||||
|
||||
private void setUpAdapter() {
|
||||
WelcomePagerAdapter adapter = new WelcomePagerAdapter(this);
|
||||
pager.setAdapter(adapter);
|
||||
indicator.setViewPager(pager);
|
||||
adapter.setCallback(new WelcomePagerAdapter.Callback() {
|
||||
@Override
|
||||
public void onYesClicked() {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
adapter.setCallback(null);
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
|
@ -11,10 +10,12 @@ import butterknife.ButterKnife;
|
|||
import butterknife.OnClick;
|
||||
|
||||
public class WelcomePagerAdapter extends PagerAdapter {
|
||||
|
||||
private Context context;
|
||||
|
||||
private static final int PAGE_FINAL = 4;
|
||||
private Callback callback;
|
||||
|
||||
public interface Callback {
|
||||
void onYesClicked();
|
||||
}
|
||||
|
||||
static final int[] PAGE_LAYOUTS = new int[]{
|
||||
R.layout.welcome_wikipedia,
|
||||
|
|
@ -24,8 +25,8 @@ public class WelcomePagerAdapter extends PagerAdapter {
|
|||
R.layout.welcome_final
|
||||
};
|
||||
|
||||
public WelcomePagerAdapter(Context context) {
|
||||
this.context = context;
|
||||
public void setCallback(@Nullable Callback callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -40,11 +41,11 @@ public class WelcomePagerAdapter extends PagerAdapter {
|
|||
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
LayoutInflater inflater = LayoutInflater.from(container.getContext());
|
||||
ViewGroup layout = (ViewGroup) inflater.inflate(PAGE_LAYOUTS[position], container, false);
|
||||
|
||||
if (position == PAGE_FINAL) {
|
||||
ViewHolder holder = new ViewHolder(layout, context);
|
||||
ViewHolder holder = new ViewHolder(layout);
|
||||
layout.setTag(holder);
|
||||
}
|
||||
container.addView(layout);
|
||||
|
|
@ -56,17 +57,16 @@ public class WelcomePagerAdapter extends PagerAdapter {
|
|||
container.removeView((View) obj);
|
||||
}
|
||||
|
||||
public static class ViewHolder {
|
||||
private Context context;
|
||||
|
||||
public ViewHolder(View view, Context context) {
|
||||
class ViewHolder {
|
||||
ViewHolder(View view) {
|
||||
ButterKnife.bind(this, view);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@OnClick(R.id.welcomeYesButton)
|
||||
void onClicked() {
|
||||
((Activity) context).finish();
|
||||
if (callback != null) {
|
||||
callback.onYesClicked();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
|||
app = CommonsApplication.getInstance();
|
||||
|
||||
setContentView(R.layout.activity_login);
|
||||
final LoginActivity that = this;
|
||||
|
||||
loginButton = (Button) findViewById(R.id.loginButton);
|
||||
Button signupButton = (Button) findViewById(R.id.signupButton);
|
||||
|
|
@ -62,12 +61,14 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
|||
loginButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
that.performLogin();
|
||||
performLogin();
|
||||
}
|
||||
});
|
||||
signupButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) { that.signUp(v); }
|
||||
public void onClick(View v) {
|
||||
signUp(v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -115,7 +116,7 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
|||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (prefs.getBoolean("firstrun", true)) {
|
||||
this.startWelcomeIntent();
|
||||
startWelcomeIntent();
|
||||
prefs.edit().putBoolean("firstrun", false).apply();
|
||||
}
|
||||
if (app.getCurrentAccount() != null) {
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ public class ContributionsActivity
|
|||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
getSupportFragmentManager().removeOnBackStackChangedListener(this);
|
||||
super.onDestroy();
|
||||
if(isUploadServiceConnected) {
|
||||
unbindService(uploadServiceConnection);
|
||||
|
|
@ -227,7 +228,8 @@ public class ContributionsActivity
|
|||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
|
||||
if(contributionsList.getAdapter() == null) {
|
||||
contributionsList.setAdapter(new ContributionsListAdapter(this, cursor, 0));
|
||||
contributionsList
|
||||
.setAdapter(new ContributionsListAdapter(getApplicationContext(), cursor, 0));
|
||||
} else {
|
||||
((CursorAdapter)contributionsList.getAdapter()).swapCursor(cursor);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,24 @@
|
|||
package fr.free.nrw.commons.contributions;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.support.v4.widget.CursorAdapter;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import fr.free.nrw.commons.R;
|
||||
|
||||
class ContributionsListAdapter extends CursorAdapter {
|
||||
private Activity activity;
|
||||
|
||||
public ContributionsListAdapter(Activity activity, Cursor c, int flags) {
|
||||
super(activity, c, flags);
|
||||
this.activity = activity;
|
||||
public ContributionsListAdapter(Context context, Cursor c, int flags) {
|
||||
super(context, c, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View newView(Context context, Cursor cursor, ViewGroup viewGroup) {
|
||||
View parent = activity.getLayoutInflater().inflate(R.layout.layout_contribution, viewGroup, false);
|
||||
View parent = LayoutInflater.from(context)
|
||||
.inflate(R.layout.layout_contribution, viewGroup, false);
|
||||
parent.setTag(new ContributionViewHolder(parent));
|
||||
return parent;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,6 @@ public class CategoryModifier extends PageModifier {
|
|||
|
||||
@Override
|
||||
public String getEditSumary() {
|
||||
return String.format("Added " + params.optJSONArray(PARAM_CATEGORIES).length() + " categories.");
|
||||
return "Added " + params.optJSONArray(PARAM_CATEGORIES).length() + " categories.";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,14 +84,20 @@ public class NearbyController {
|
|||
*Loads attractions from location for map view, we need to return BaseMarkerOption data type.
|
||||
* @param curLatLng users current location
|
||||
* @param placeList list of nearby places in Place data type
|
||||
* @return BaseMarkerOprions list that holds nearby places
|
||||
* @return BaseMarkerOptions list that holds nearby places
|
||||
*/
|
||||
public static List<NearbyBaseMarker> loadAttractionsFromLocationToBaseMarkerOptions(
|
||||
LatLng curLatLng,
|
||||
List<Place> placeList,
|
||||
Context context) {
|
||||
List<NearbyBaseMarker> baseMarkerOptionses = new ArrayList<>();
|
||||
List<NearbyBaseMarker> baseMarkerOptions = new ArrayList<>();
|
||||
|
||||
if (placeList == null) {
|
||||
return baseMarkerOptions;
|
||||
}
|
||||
|
||||
placeList = placeList.subList(0, Math.min(placeList.size(), MAX_RESULTS));
|
||||
|
||||
for (Place place: placeList) {
|
||||
String distance = formatDistanceBetween(curLatLng, place.location);
|
||||
place.setDistance(distance);
|
||||
|
|
@ -108,8 +114,8 @@ public class NearbyController {
|
|||
nearbyBaseMarker.place(place);
|
||||
nearbyBaseMarker.icon(icon);
|
||||
|
||||
baseMarkerOptionses.add(nearbyBaseMarker);
|
||||
baseMarkerOptions.add(nearbyBaseMarker);
|
||||
}
|
||||
return baseMarkerOptionses;
|
||||
return baseMarkerOptions;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class FileUtils {
|
|||
*/
|
||||
// Can be safely suppressed, checks for isKitKat before running isDocumentUri
|
||||
@SuppressLint("NewApi")
|
||||
public static String getPath(final Context context, final Uri uri) {
|
||||
public static String getPath(Context context, Uri uri) {
|
||||
|
||||
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import android.support.annotation.Nullable;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import timber.log.Timber;
|
||||
|
||||
/**
|
||||
|
|
@ -26,15 +27,13 @@ public class GPSExtractor {
|
|||
private double decLatitude, decLongitude;
|
||||
private Double currentLatitude = null;
|
||||
private Double currentLongitude = null;
|
||||
private Context context;
|
||||
public boolean imageCoordsExists;
|
||||
private MyLocationListener myLocationListener;
|
||||
private LocationManager locationManager;
|
||||
|
||||
|
||||
public GPSExtractor(String filePath, Context context){
|
||||
public GPSExtractor(String filePath) {
|
||||
this.filePath = filePath;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -42,7 +41,8 @@ public class GPSExtractor {
|
|||
* @return true if enabled, false if disabled
|
||||
*/
|
||||
private boolean gpsPreferenceEnabled() {
|
||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
SharedPreferences sharedPref
|
||||
= PreferenceManager.getDefaultSharedPreferences(CommonsApplication.getInstance());
|
||||
boolean gpsPref = sharedPref.getBoolean("allowGps", false);
|
||||
Timber.d("Gps pref set to: %b", gpsPref);
|
||||
return gpsPref;
|
||||
|
|
@ -52,7 +52,8 @@ public class GPSExtractor {
|
|||
* Registers a LocationManager to listen for current location
|
||||
*/
|
||||
protected void registerLocationManager() {
|
||||
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||
locationManager = (LocationManager) CommonsApplication.getInstance()
|
||||
.getSystemService(Context.LOCATION_SERVICE);
|
||||
Criteria criteria = new Criteria();
|
||||
String provider = locationManager.getBestProvider(criteria, true);
|
||||
myLocationListener = new MyLocationListener();
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ public class MultipleShareActivity
|
|||
|
||||
Timber.d("Multiple upload begins");
|
||||
|
||||
final ProgressDialog dialog = new ProgressDialog(MultipleShareActivity.this);
|
||||
final ProgressDialog dialog = new ProgressDialog(this);
|
||||
dialog.setIndeterminate(false);
|
||||
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||
dialog.setMax(photosList.size());
|
||||
|
|
@ -145,12 +145,12 @@ public class MultipleShareActivity
|
|||
|
||||
uploadsList.setImageOnlyMode(true);
|
||||
|
||||
categorizationFragment = (CategorizationFragment) this.getSupportFragmentManager().findFragmentByTag("categorization");
|
||||
categorizationFragment = (CategorizationFragment) getSupportFragmentManager().findFragmentByTag("categorization");
|
||||
if(categorizationFragment == null) {
|
||||
categorizationFragment = new CategorizationFragment();
|
||||
}
|
||||
// FIXME: Stops the keyboard from being shown 'stale' while moving out of this fragment into the next
|
||||
View target = this.getCurrentFocus();
|
||||
View target = getCurrentFocus();
|
||||
if (target != null) {
|
||||
InputMethodManager imm = (InputMethodManager) target.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(target.getWindowToken(), 0);
|
||||
|
|
@ -203,7 +203,7 @@ public class MultipleShareActivity
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
uploadController = new UploadController(this);
|
||||
uploadController = new UploadController();
|
||||
|
||||
setContentView(R.layout.activity_multiple_uploads);
|
||||
app = CommonsApplication.getInstance();
|
||||
|
|
@ -221,18 +221,19 @@ public class MultipleShareActivity
|
|||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
getSupportFragmentManager().removeOnBackStackChangedListener(this);
|
||||
uploadController.cleanup();
|
||||
}
|
||||
|
||||
private void showDetail(int i) {
|
||||
if(mediaDetails == null ||!mediaDetails.isVisible()) {
|
||||
mediaDetails = new MediaDetailPagerFragment(true);
|
||||
this.getSupportFragmentManager()
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(R.id.uploadsFragmentContainer, mediaDetails)
|
||||
.addToBackStack(null)
|
||||
.commit();
|
||||
this.getSupportFragmentManager().executePendingTransactions();
|
||||
getSupportFragmentManager().executePendingTransactions();
|
||||
}
|
||||
mediaDetails.showImage(i);
|
||||
}
|
||||
|
|
@ -267,7 +268,7 @@ public class MultipleShareActivity
|
|||
uploadsList = (MultipleUploadListFragment) getSupportFragmentManager().findFragmentByTag("uploadsList");
|
||||
if(uploadsList == null) {
|
||||
uploadsList = new MultipleUploadListFragment();
|
||||
this.getSupportFragmentManager()
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.add(R.id.uploadsFragmentContainer, uploadsList, "uploadsList")
|
||||
.commit();
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ import android.content.Context;
|
|||
import android.graphics.Point;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.graphics.drawable.VectorDrawableCompat;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
|
|
@ -24,6 +26,7 @@ import android.widget.GridView;
|
|||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
|
||||
import fr.free.nrw.commons.R;
|
||||
|
|
@ -82,7 +85,13 @@ public class MultipleUploadListFragment extends Fragment {
|
|||
holder.overlay = (RelativeLayout) view.findViewById(R.id.uploadOverlay);
|
||||
|
||||
holder.image.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, photoSize.y));
|
||||
|
||||
holder.image.setHierarchy(GenericDraweeHierarchyBuilder
|
||||
.newInstance(getResources())
|
||||
.setPlaceholderImage(VectorDrawableCompat.create(getResources(),
|
||||
R.drawable.ic_image_black_24dp, getContext().getTheme()))
|
||||
.setFailureImage(VectorDrawableCompat.create(getResources(),
|
||||
R.drawable.ic_error_outline_black_24dp, getContext().getTheme()))
|
||||
.build());
|
||||
view.setTag(holder);
|
||||
} else {
|
||||
holder = (UploadHolderView)view.getTag();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package fr.free.nrw.commons.upload;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.android.volley.Cache;
|
||||
|
|
@ -21,6 +20,7 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import timber.log.Timber;
|
||||
|
||||
/**
|
||||
|
|
@ -32,15 +32,13 @@ public class MwVolleyApi {
|
|||
|
||||
private static RequestQueue REQUEST_QUEUE;
|
||||
private static final Gson GSON = new GsonBuilder().create();
|
||||
private Context context;
|
||||
|
||||
protected static Set<String> categorySet;
|
||||
private static List<String> categoryList;
|
||||
|
||||
private static final String MWURL = "https://commons.wikimedia.org/";
|
||||
|
||||
public MwVolleyApi(Context context) {
|
||||
this.context = context;
|
||||
public MwVolleyApi() {
|
||||
categorySet = new HashSet<>();
|
||||
}
|
||||
|
||||
|
|
@ -94,12 +92,8 @@ public class MwVolleyApi {
|
|||
}
|
||||
|
||||
private synchronized RequestQueue getQueue() {
|
||||
return getQueue(context);
|
||||
}
|
||||
|
||||
private static RequestQueue getQueue(Context context) {
|
||||
if (REQUEST_QUEUE == null) {
|
||||
REQUEST_QUEUE = Volley.newRequestQueue(context);
|
||||
REQUEST_QUEUE = Volley.newRequestQueue(CommonsApplication.getInstance());
|
||||
}
|
||||
return REQUEST_QUEUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.graphics.drawable.VectorDrawableCompat;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.MenuItem;
|
||||
|
|
@ -16,6 +17,7 @@ import android.view.View;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -60,7 +62,6 @@ public class ShareActivity
|
|||
|
||||
private UploadController uploadController;
|
||||
|
||||
private CommonsApplication cacheObj;
|
||||
private boolean cacheFound;
|
||||
|
||||
private GPSExtractor imageObj;
|
||||
|
|
@ -196,7 +197,7 @@ public class ShareActivity
|
|||
categorizationFragment = (CategorizationFragment) getSupportFragmentManager().findFragmentByTag("categorization");
|
||||
if(shareView == null && categorizationFragment == null) {
|
||||
shareView = new SingleUploadFragment();
|
||||
this.getSupportFragmentManager()
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.add(R.id.single_upload_fragment_container, shareView, "shareView")
|
||||
.commitAllowingStateLoss();
|
||||
|
|
@ -214,12 +215,19 @@ public class ShareActivity
|
|||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
uploadController = new UploadController(this);
|
||||
uploadController = new UploadController();
|
||||
setContentView(R.layout.activity_share);
|
||||
ButterKnife.bind(this);
|
||||
initBack();
|
||||
app = CommonsApplication.getInstance();
|
||||
backgroundImageView = (SimpleDraweeView)findViewById(R.id.backgroundImage);
|
||||
backgroundImageView.setHierarchy(GenericDraweeHierarchyBuilder
|
||||
.newInstance(getResources())
|
||||
.setPlaceholderImage(VectorDrawableCompat.create(getResources(),
|
||||
R.drawable.ic_image_black_24dp, getTheme()))
|
||||
.setFailureImage(VectorDrawableCompat.create(getResources(),
|
||||
R.drawable.ic_error_outline_black_24dp, getTheme()))
|
||||
.build());
|
||||
|
||||
//Receive intent from ContributionController.java when user selects picture to upload
|
||||
Intent intent = getIntent();
|
||||
|
|
@ -373,11 +381,11 @@ public class ShareActivity
|
|||
* @param gpsEnabled
|
||||
*/
|
||||
public void getFileMetadata(boolean gpsEnabled) {
|
||||
String filePath = FileUtils.getPath(this, mediaUri);
|
||||
String filePath = FileUtils.getPath(getApplicationContext(), mediaUri);
|
||||
Timber.d("Filepath: %s", filePath);
|
||||
Timber.d("Calling GPSExtractor");
|
||||
if(imageObj == null) {
|
||||
imageObj = new GPSExtractor(filePath, this);
|
||||
imageObj = new GPSExtractor(filePath);
|
||||
}
|
||||
|
||||
if (filePath != null && !filePath.equals("")) {
|
||||
|
|
@ -402,7 +410,7 @@ public class ShareActivity
|
|||
app.getCacheData().setQtPoint(decLongitude, decLatitude);
|
||||
}
|
||||
|
||||
MwVolleyApi apiCall = new MwVolleyApi(this);
|
||||
MwVolleyApi apiCall = new MwVolleyApi();
|
||||
|
||||
List<String> displayCatList = app.getCacheData().findCategory();
|
||||
boolean catListEmpty = displayCatList.isEmpty();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package fr.free.nrw.commons.upload;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
|
@ -26,16 +25,13 @@ import timber.log.Timber;
|
|||
|
||||
public class UploadController {
|
||||
private UploadService uploadService;
|
||||
|
||||
private final Activity activity;
|
||||
final CommonsApplication app;
|
||||
private final CommonsApplication app;
|
||||
|
||||
public interface ContributionUploadProgress {
|
||||
void onUploadStarted(Contribution contribution);
|
||||
}
|
||||
|
||||
public UploadController(Activity activity) {
|
||||
this.activity = activity;
|
||||
public UploadController() {
|
||||
app = CommonsApplication.getInstance();
|
||||
}
|
||||
|
||||
|
|
@ -55,15 +51,15 @@ public class UploadController {
|
|||
};
|
||||
|
||||
public void prepareService() {
|
||||
Intent uploadServiceIntent = new Intent(activity, UploadService.class);
|
||||
Intent uploadServiceIntent = new Intent(app, UploadService.class);
|
||||
uploadServiceIntent.setAction(UploadService.ACTION_START_SERVICE);
|
||||
activity.startService(uploadServiceIntent);
|
||||
activity.bindService(uploadServiceIntent, uploadServiceConnection, Context.BIND_AUTO_CREATE);
|
||||
app.startService(uploadServiceIntent);
|
||||
app.bindService(uploadServiceIntent, uploadServiceConnection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
if(isUploadServiceConnected) {
|
||||
activity.unbindService(uploadServiceConnection);
|
||||
app.unbindService(uploadServiceConnection);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +78,7 @@ public class UploadController {
|
|||
|
||||
public void startUpload(final Contribution contribution, final ContributionUploadProgress onComplete) {
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(app);
|
||||
|
||||
//Set creator, desc, and license
|
||||
if(TextUtils.isEmpty(contribution.getCreator())) {
|
||||
|
|
@ -107,10 +103,13 @@ public class UploadController {
|
|||
long length;
|
||||
try {
|
||||
if(contribution.getDataLength() <= 0) {
|
||||
length = activity.getContentResolver().openAssetFileDescriptor(contribution.getLocalUri(), "r").getLength();
|
||||
length = app.getContentResolver()
|
||||
.openAssetFileDescriptor(contribution.getLocalUri(), "r")
|
||||
.getLength();
|
||||
if(length == -1) {
|
||||
// Let us find out the long way!
|
||||
length = Utils.countBytes(activity.getContentResolver().openInputStream(contribution.getLocalUri()));
|
||||
length = Utils.countBytes(app.getContentResolver()
|
||||
.openInputStream(contribution.getLocalUri()));
|
||||
}
|
||||
contribution.setDataLength(length);
|
||||
}
|
||||
|
|
@ -126,7 +125,7 @@ public class UploadController {
|
|||
Boolean imagePrefix = false;
|
||||
|
||||
if(mimeType == null || TextUtils.isEmpty(mimeType) || mimeType.endsWith("*")) {
|
||||
mimeType = activity.getContentResolver().getType(contribution.getLocalUri());
|
||||
mimeType = app.getContentResolver().getType(contribution.getLocalUri());
|
||||
}
|
||||
|
||||
if(mimeType != null) {
|
||||
|
|
@ -136,7 +135,7 @@ public class UploadController {
|
|||
}
|
||||
|
||||
if(imagePrefix && contribution.getDateCreated() == null) {
|
||||
Cursor cursor = activity.getContentResolver().query(contribution.getLocalUri(),
|
||||
Cursor cursor = app.getContentResolver().query(contribution.getLocalUri(),
|
||||
new String[]{MediaStore.Images.ImageColumns.DATE_TAKEN}, null, null, null);
|
||||
if(cursor != null && cursor.getCount() != 0) {
|
||||
cursor.moveToFirst();
|
||||
|
|
|
|||
|
|
@ -26,9 +26,7 @@
|
|||
android:id="@+id/backgroundImage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:actualImageScaleType="centerCrop"
|
||||
app:placeholderImage="@drawable/ic_image_black_24dp"
|
||||
app:failureImage="@drawable/ic_error_outline_black_24dp" />
|
||||
app:actualImageScaleType="centerCrop" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/single_upload_fragment_container"
|
||||
|
|
|
|||
|
|
@ -22,8 +22,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:actualImageScaleType="fitCenter"
|
||||
app:placeholderImage="@drawable/ic_image_black_24dp"
|
||||
app:failureImage="@drawable/ic_image_black_24dp"
|
||||
/>
|
||||
|
||||
<ScrollView
|
||||
|
|
|
|||
|
|
@ -23,8 +23,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="240dp"
|
||||
app:actualImageScaleType="centerCrop"
|
||||
app:placeholderImage="@drawable/ic_image_black_24dp"
|
||||
app:failureImage="@drawable/ic_image_black_24dp"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="192dp"
|
||||
app:actualImageScaleType="centerCrop"
|
||||
app:placeholderImage="@drawable/ic_image_black_24dp"
|
||||
app:failureImage="@drawable/ic_error_outline_black_24dp"
|
||||
android:scaleType="centerCrop"
|
||||
android:contentDescription="@string/upload_image"
|
||||
/>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue