Update master with backend overhaul branch (#2829)

* Beginnings of integration with Wikipedia client library. (#2642)

* Remove remaining unnecessary API version check.

* Roll up sleeves.

* Add and integrate the beginnings of app adapter.

* Remove vestigial event logging logic.

Event logging is no longer used in this app.

* Beginnings: remove StringUtils and associated redundancies.

* Remove redundant capitalize() method.

* Remove redundant urlEncode() method.

* Remove redundant (and incomplete) language lists.

* Remove redundant usages of SimpleDateFormat.

* Remove redundant json type adapter.

* Remove redundant MW error model classes.

* Rip out redundant MW model classes.

* Pass SessionManager into AppAdapter instead of injecting.

* Wire up more of the AppAdapter.

* Remove redundant Gson initialization and type adapters.

* Rip out PageTitle.

This was being used in some slightly incorrect/unexpected ways.

* Don't need static WikiSite.

* Bump data client library version

* Bump library version and fix build

* Fix tests

* Fix build

* Fix media of the day

* With fixes in recently modified APIs
This commit is contained in:
Vivek Maskara 2019-04-02 08:35:22 +05:30 committed by GitHub
parent 76e5a30fb5
commit dcbf076965
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
76 changed files with 424 additions and 2122 deletions

View file

@ -3,6 +3,8 @@ package fr.free.nrw.commons.upload;
import android.content.Context;
import android.net.Uri;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import javax.inject.Inject;
@ -12,7 +14,6 @@ import fr.free.nrw.commons.mwapi.MediaWikiApi;
import fr.free.nrw.commons.nearby.Place;
import fr.free.nrw.commons.utils.ImageUtils;
import fr.free.nrw.commons.utils.ImageUtilsWrapper;
import fr.free.nrw.commons.utils.StringUtils;
import io.reactivex.Single;
import timber.log.Timber;
@ -172,13 +173,13 @@ public class ImageProcessingService {
*/
private Single<Integer> checkImageGeoLocation(Place place, String filePath) {
Timber.d("Checking for image geolocation %s", filePath);
if (place == null || StringUtils.isNullOrWhiteSpace(place.getWikiDataEntityId())) {
if (place == null || StringUtils.isBlank(place.getWikiDataEntityId())) {
return Single.just(ImageUtils.IMAGE_OK);
}
return Single.fromCallable(() -> filePath)
.map(fileUtilsWrapper::getGeolocationOfFile)
.flatMap(geoLocation -> {
if (StringUtils.isNullOrWhiteSpace(geoLocation)) {
if (StringUtils.isBlank(geoLocation)) {
return Single.just(ImageUtils.IMAGE_OK);
}
return imageUtilsWrapper.checkImageGeolocationIsDifferent(geoLocation, place.getLocation());

View file

@ -11,12 +11,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.URLSpan;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
@ -61,6 +56,7 @@ import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.mwapi.MediaWikiApi;
import fr.free.nrw.commons.nearby.Place;
import fr.free.nrw.commons.theme.BaseActivity;
import fr.free.nrw.commons.ui.widget.HtmlTextView;
import fr.free.nrw.commons.utils.DialogUtil;
import fr.free.nrw.commons.utils.NetworkUtils;
import fr.free.nrw.commons.utils.PermissionUtils;
@ -124,8 +120,7 @@ public class UploadActivity extends BaseActivity implements UploadView, SimilarI
// Final Submission
@BindView(R.id.license_title) TextView licenseTitle;
@BindView(R.id.share_license_summary) TextView licenseSummary;
@BindView(R.id.media_upload_policy) TextView licensePolicy;
@BindView(R.id.share_license_summary) HtmlTextView licenseSummary;
@BindView(R.id.license_list) Spinner licenseSpinner;
@BindView(R.id.submit) Button submit;
@BindView(R.id.license_previous) Button licensePrevious;
@ -152,7 +147,6 @@ public class UploadActivity extends BaseActivity implements UploadView, SimilarI
configureNavigationButtons();
configureCategories();
configureLicenses();
configurePolicy();
presenter.init();
@ -271,8 +265,7 @@ public class UploadActivity extends BaseActivity implements UploadView, SimilarI
public void updateLicenseSummary(String selectedLicense, int imageCount) {
String licenseHyperLink = "<a href='" + Utils.licenseUrlFor(selectedLicense) + "'>" +
getString(Utils.licenseNameFor(selectedLicense)) + "</a><br>";
setTextViewHTML(licenseSummary, getResources().getQuantityString(R.plurals.share_license_summary, imageCount, licenseHyperLink));
licenseSummary.setHtmlText(getResources().getQuantityString(R.plurals.share_license_summary, imageCount, licenseHyperLink));
}
@Override
@ -438,47 +431,6 @@ public class UploadActivity extends BaseActivity implements UploadView, SimilarI
}
}
/**
* Parses links from HTML string, and makes the links clickable in the specified TextView.<br>
* Uses {@link #makeLinkClickable(SpannableStringBuilder, URLSpan)}.
* @see <a href="https://stackoverflow.com/questions/12418279/android-textview-with-clickable-links-how-to-capture-clicks">Source</a>
*/
private void setTextViewHTML(TextView text, String html)
{
CharSequence sequence = Html.fromHtml(html);
SpannableStringBuilder strBuilder = new SpannableStringBuilder(sequence);
URLSpan[] urls = strBuilder.getSpans(0, sequence.length(), URLSpan.class);
for (URLSpan span : urls) {
makeLinkClickable(strBuilder, span);
}
text.setText(strBuilder);
text.setMovementMethod(LinkMovementMethod.getInstance());
}
/**
* Sets onClick handler to launch browser for the specified URLSpan.
* @see <a href="https://stackoverflow.com/questions/12418279/android-textview-with-clickable-links-how-to-capture-clicks">Source</a>
*/
private void makeLinkClickable(SpannableStringBuilder strBuilder, final URLSpan span)
{
int start = strBuilder.getSpanStart(span);
int end = strBuilder.getSpanEnd(span);
int flags = strBuilder.getSpanFlags(span);
ClickableSpan clickable = new ClickableSpan() {
public void onClick(View view) {
// Handle hyperlink click
String hyperLink = span.getURL();
launchBrowser(hyperLink);
}
};
strBuilder.setSpan(clickable, start, end, flags);
strBuilder.removeSpan(span);
}
private void launchBrowser(String hyperLink) {
Utils.handleWebUrl(this, Uri.parse(hyperLink));
}
private void configureLicenses() {
licenseSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
@ -559,10 +511,6 @@ public class UploadActivity extends BaseActivity implements UploadView, SimilarI
categoriesList.setAdapter(categoriesAdapter);
}
private void configurePolicy() {
setTextViewHTML(licensePolicy, getString(R.string.media_upload_policy));
}
@SuppressLint("CheckResult")
private void updateCategoryList(String filter) {
List<String> imageTitleList = presenter.getImageTitleList();

View file

@ -2,6 +2,17 @@ package fr.free.nrw.commons.upload;
import android.annotation.SuppressLint;
import android.content.Context;
import org.apache.commons.lang3.StringUtils;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.category.CategoriesModel;
import fr.free.nrw.commons.contributions.Contribution;
@ -11,7 +22,6 @@ import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.nearby.Place;
import fr.free.nrw.commons.settings.Prefs;
import fr.free.nrw.commons.utils.CustomProxy;
import fr.free.nrw.commons.utils.StringUtils;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
@ -166,7 +176,7 @@ public class UploadPresenter {
break;
default:
String errorMessageForResult = getErrorMessageForResult(context, errorCode);
if (StringUtils.isNullOrWhiteSpace(errorMessageForResult)) {
if (StringUtils.isBlank(errorMessageForResult)) {
return;
}
view.showBadPicturePopup(errorMessageForResult);