mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Merge pull request #857 from psh/beta-cluster
Product flavors for production and the beta-cluster Wikimedia servers
This commit is contained in:
commit
ffc7c80678
14 changed files with 173 additions and 157 deletions
|
|
@ -77,6 +77,29 @@ android {
|
|||
}
|
||||
}
|
||||
|
||||
productFlavors {
|
||||
prod {
|
||||
buildConfigField "String", "WIKIMEDIA_API_HOST", "\"https://commons.wikimedia.org/w/api.php\""
|
||||
buildConfigField "String", "WIKIMEDIA_FORGE_API_HOST", "\"https://tools.wmflabs.org/\""
|
||||
buildConfigField "String", "IMAGE_URL_BASE", "\"https://upload.wikimedia.org/wikipedia/commons\""
|
||||
buildConfigField "String", "HOME_URL", "\"https://commons.wikimedia.org/wiki/\""
|
||||
buildConfigField "String", "MOBILE_HOME_URL", "\"https://commons.m.wikimedia.org/wiki/\""
|
||||
buildConfigField "String", "EVENTLOG_URL", "\"https://www.wikimedia.org/beacon/event\""
|
||||
buildConfigField "String", "EVENTLOG_WIKI", "\"commonswiki\""
|
||||
}
|
||||
|
||||
beta {
|
||||
// What values do we need to hit the BETA versions of the site / api ?
|
||||
buildConfigField "String", "WIKIMEDIA_API_HOST", "\"https://commons.wikimedia.beta.wmflabs.org/w/api.php\""
|
||||
buildConfigField "String", "WIKIMEDIA_FORGE_API_HOST", "\"https://tools.wmflabs.org/\""
|
||||
buildConfigField "String", "IMAGE_URL_BASE", "\"https://upload.beta.wmflabs.org/wikipedia/commons\""
|
||||
buildConfigField "String", "HOME_URL", "\"https://commons.wikimedia.beta.wmflabs.org/wiki/\""
|
||||
buildConfigField "String", "MOBILE_HOME_URL", "\"https://commons.m.wikimedia.beta.wmflabs.org/wiki/\""
|
||||
buildConfigField "String", "EVENTLOG_URL", "\"https://commons.wikimedia.beta.wmflabs.org/beacon/event\""
|
||||
buildConfigField "String", "EVENTLOG_WIKI", "\"commonswiki\""
|
||||
}
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
disable 'MissingTranslation'
|
||||
disable 'ExtraTranslation'
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
// TODO: use Robolectric and make it runnable without a connected device
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class MediaTest {
|
||||
@Test public void displayTitleShouldStripExtension() {
|
||||
Media m = new Media("File:Example.jpg");
|
||||
Assert.assertThat(m.getDisplayTitle(), is("Example"));
|
||||
}
|
||||
|
||||
@Test public void displayTitleShouldUseSpaceForUnderscore() {
|
||||
Media m = new Media("File:Example 1_2.jpg");
|
||||
Assert.assertThat(m.getDisplayTitle(), is("Example 1 2"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
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.getTargetContext();
|
||||
}
|
||||
|
||||
@Test public void testNullAttractions() {
|
||||
LatLng location = new LatLng(0, 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, 0);
|
||||
List<Place> emptyList = new ArrayList<>();
|
||||
|
||||
List<NearbyBaseMarker> options =
|
||||
NearbyController.loadAttractionsFromLocationToBaseMarkerOptions(
|
||||
location,
|
||||
emptyList,
|
||||
instrumentationContext
|
||||
);
|
||||
|
||||
Assert.assertThat(options.size(), is(0));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
// TODO: use Robolectric and make it runnable without a connected device
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class PageTitleTest {
|
||||
@Test public void displayTextShouldNotBeUnderscored() {
|
||||
Assert.assertThat(new PageTitle("Ex_1 ").getDisplayText(),
|
||||
is("Ex 1"));
|
||||
}
|
||||
|
||||
@Test public void moreThanTwoColons() {
|
||||
Assert.assertThat(new PageTitle("File:sample:a.jpg").getPrefixedText(),
|
||||
is("File:Sample:a.jpg"));
|
||||
}
|
||||
|
||||
@Test public void getTextShouldReturnWithoutNamespace() {
|
||||
Assert.assertThat(new PageTitle("File:sample.jpg").getText(),
|
||||
is("Sample.jpg"));
|
||||
}
|
||||
|
||||
|
||||
@Test public void capitalizeNameAfterNamespace() {
|
||||
Assert.assertThat(new PageTitle("File:sample.jpg").getPrefixedText(),
|
||||
is("File:Sample.jpg"));
|
||||
}
|
||||
|
||||
@Test public void prefixedTextShouldBeUnderscored() {
|
||||
Assert.assertThat(new PageTitle("Ex 1 ").getPrefixedText(),
|
||||
is("Ex_1"));
|
||||
}
|
||||
|
||||
@Test public void getMobileUriForTest() {
|
||||
Assert.assertThat(new PageTitle("Test").getMobileUri().toString(),
|
||||
is("https://commons.m.wikimedia.org/wiki/Test"));
|
||||
}
|
||||
|
||||
@Test public void spaceBecomesUnderscoreInUri() {
|
||||
Assert.assertThat(new PageTitle("File:Ex 1.jpg").getCanonicalUri().toString(),
|
||||
is("https://commons.wikimedia.org/wiki/File:Ex_1.jpg"));
|
||||
}
|
||||
|
||||
@Test public void leaveSubpageNamesUncapitalizedInUri() {
|
||||
Assert.assertThat(new PageTitle("User:Ex/subpage").getCanonicalUri().toString(),
|
||||
is("https://commons.wikimedia.org/wiki/User:Ex/subpage"));
|
||||
}
|
||||
|
||||
@Test public void unicodeUri() throws Throwable {
|
||||
Assert.assertThat(new PageTitle("User:例").getCanonicalUri().toString(),
|
||||
is("https://commons.wikimedia.org/wiki/User:" + URLEncoder.encode("例", "utf-8")));
|
||||
}
|
||||
}
|
||||
BIN
app/src/betaDebug/res/drawable-hdpi/ic_launcher.png
Normal file
BIN
app/src/betaDebug/res/drawable-hdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.3 KiB |
BIN
app/src/betaDebug/res/drawable-mdpi/ic_launcher.png
Normal file
BIN
app/src/betaDebug/res/drawable-mdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
BIN
app/src/betaDebug/res/drawable-xhdpi/ic_launcher.png
Normal file
BIN
app/src/betaDebug/res/drawable-xhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.5 KiB |
|
|
@ -51,12 +51,6 @@ import timber.log.Timber;
|
|||
public class CommonsApplication extends Application {
|
||||
|
||||
private Account currentAccount = null; // Unlike a savings account...
|
||||
public static final String API_URL = "https://commons.wikimedia.org/w/api.php";
|
||||
public static final String IMAGE_URL_BASE = "https://upload.wikimedia.org/wikipedia/commons";
|
||||
public static final String HOME_URL = "https://commons.wikimedia.org/wiki/";
|
||||
public static final String MOBILE_HOME_URL = "https://commons.m.wikimedia.org/wiki/";
|
||||
public static final String EVENTLOG_URL = "https://www.wikimedia.org/beacon/event";
|
||||
public static final String EVENTLOG_WIKI = "commonswiki";
|
||||
|
||||
public static final Object[] EVENT_UPLOAD_ATTEMPT = {"MobileAppUploadAttempts", 5334329L};
|
||||
public static final Object[] EVENT_LOGIN_ATTEMPT = {"MobileAppLoginAttempts", 5257721L};
|
||||
|
|
@ -92,7 +86,7 @@ public class CommonsApplication extends Application {
|
|||
|
||||
public MediaWikiApi getMWApi() {
|
||||
if (api == null) {
|
||||
api = new ApacheHttpClientMediaWikiApi(API_URL);
|
||||
api = new ApacheHttpClientMediaWikiApi(BuildConfig.WIKIMEDIA_API_HOST);
|
||||
}
|
||||
return api;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public class PageTitle {
|
|||
*/
|
||||
@NonNull
|
||||
public Uri getCanonicalUri() {
|
||||
String uriStr = CommonsApplication.HOME_URL + Uri.encode(getPrefixedText(), ":/");
|
||||
String uriStr = BuildConfig.HOME_URL + Uri.encode(getPrefixedText(), ":/");
|
||||
return Uri.parse(uriStr);
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ public class PageTitle {
|
|||
*/
|
||||
@NonNull
|
||||
public Uri getMobileUri() {
|
||||
String uriStr = CommonsApplication.MOBILE_HOME_URL + Uri.encode(getPrefixedText(), ":/");
|
||||
String uriStr = BuildConfig.MOBILE_HOME_URL + Uri.encode(getPrefixedText(), ":/");
|
||||
return Uri.parse(uriStr);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ import javax.xml.transform.stream.StreamResult;
|
|||
import fr.free.nrw.commons.settings.Prefs;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
public class Utils {
|
||||
|
||||
// Get SHA1 of file from input stream
|
||||
|
|
@ -80,10 +79,12 @@ public class Utils {
|
|||
}
|
||||
}
|
||||
|
||||
/** Fix Html.fromHtml is deprecated problem
|
||||
/**
|
||||
* Fix Html.fromHtml is deprecated problem
|
||||
*
|
||||
* @param source provided Html string
|
||||
* @return returned Spanned of appropriate method according to version check
|
||||
* */
|
||||
*/
|
||||
public static Spanned fromHtml(String source) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
return Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY);
|
||||
|
|
@ -127,7 +128,7 @@ public class Utils {
|
|||
public static String makeThumbBaseUrl(String filename) {
|
||||
String name = new PageTitle(filename).getPrefixedText();
|
||||
String sha = new String(Hex.encodeHex(DigestUtils.md5(name)));
|
||||
return String.format("%s/%s/%s/%s", CommonsApplication.IMAGE_URL_BASE, sha.substring(0, 1), sha.substring(0, 2), urlEncode(name));
|
||||
return String.format("%s/%s/%s/%s", BuildConfig.IMAGE_URL_BASE, sha.substring(0, 1), sha.substring(0, 2), urlEncode(name));
|
||||
}
|
||||
|
||||
public static String getStringFromDOM(Node dom) {
|
||||
|
|
|
|||
|
|
@ -41,12 +41,12 @@ public class LogBuilder {
|
|||
try {
|
||||
fullData.put("schema", schema);
|
||||
fullData.put("revision", rev);
|
||||
fullData.put("wiki", CommonsApplication.EVENTLOG_WIKI);
|
||||
fullData.put("wiki", BuildConfig.EVENTLOG_WIKI);
|
||||
data.put("device", EventLog.DEVICE);
|
||||
data.put("platform", "Android/" + Build.VERSION.RELEASE);
|
||||
data.put("appversion", "Android/" + BuildConfig.VERSION_NAME);
|
||||
fullData.put("event", data);
|
||||
return new URL(CommonsApplication.EVENTLOG_URL + "?" + Utils.urlEncode(fullData.toString()) + ";");
|
||||
return new URL(BuildConfig.EVENTLOG_URL + "?" + Utils.urlEncode(fullData.toString()) + ";");
|
||||
} catch (MalformedURLException | JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
|
|||
25
app/src/test/java/fr/free/nrw/commons/MediaTest.java
Normal file
25
app/src/test/java/fr/free/nrw/commons/MediaTest.java
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(constants = BuildConfig.class, sdk = 21)
|
||||
public class MediaTest {
|
||||
@Test
|
||||
public void displayTitleShouldStripExtension() {
|
||||
Media m = new Media("File:Example.jpg");
|
||||
assertThat(m.getDisplayTitle(), is("Example"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayTitleShouldUseSpaceForUnderscore() {
|
||||
Media m = new Media("File:Example 1_2.jpg");
|
||||
assertThat(m.getDisplayTitle(), is("Example 1 2"));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
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.Place;
|
||||
|
||||
import static fr.free.nrw.commons.nearby.NearbyController.loadAttractionsFromLocationToBaseMarkerOptions;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(constants = BuildConfig.class, sdk = 21)
|
||||
public class NearbyControllerTest {
|
||||
|
||||
@Test
|
||||
public void testNullAttractions() {
|
||||
LatLng location = new LatLng(0, 0, 0);
|
||||
|
||||
List<NearbyBaseMarker> options = loadAttractionsFromLocationToBaseMarkerOptions(
|
||||
location, null, RuntimeEnvironment.application);
|
||||
|
||||
assertThat(options.size(), is(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyList() {
|
||||
LatLng location = new LatLng(0, 0, 0);
|
||||
List<Place> emptyList = new ArrayList<>();
|
||||
|
||||
List<NearbyBaseMarker> options = loadAttractionsFromLocationToBaseMarkerOptions(
|
||||
location, emptyList, RuntimeEnvironment.application);
|
||||
|
||||
assertThat(options.size(), is(0));
|
||||
}
|
||||
}
|
||||
70
app/src/test/java/fr/free/nrw/commons/PageTitleTest.java
Normal file
70
app/src/test/java/fr/free/nrw/commons/PageTitleTest.java
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(constants = BuildConfig.class, sdk = 21)
|
||||
public class PageTitleTest {
|
||||
@Test
|
||||
public void displayTextShouldNotBeUnderscored() {
|
||||
assertThat(new PageTitle("Ex_1 ").getDisplayText(),
|
||||
is("Ex 1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void moreThanTwoColons() {
|
||||
assertThat(new PageTitle("File:sample:a.jpg").getPrefixedText(),
|
||||
is("File:Sample:a.jpg"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTextShouldReturnWithoutNamespace() {
|
||||
assertThat(new PageTitle("File:sample.jpg").getText(),
|
||||
is("Sample.jpg"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void capitalizeNameAfterNamespace() {
|
||||
assertThat(new PageTitle("File:sample.jpg").getPrefixedText(),
|
||||
is("File:Sample.jpg"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prefixedTextShouldBeUnderscored() {
|
||||
assertThat(new PageTitle("Ex 1 ").getPrefixedText(),
|
||||
is("Ex_1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMobileUriForTest() {
|
||||
assertThat(new PageTitle("Test").getMobileUri().toString(),
|
||||
is(BuildConfig.MOBILE_HOME_URL + "Test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spaceBecomesUnderscoreInUri() {
|
||||
assertThat(new PageTitle("File:Ex 1.jpg").getCanonicalUri().toString(),
|
||||
is(BuildConfig.HOME_URL + "File:Ex_1.jpg"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void leaveSubpageNamesUncapitalizedInUri() {
|
||||
assertThat(new PageTitle("User:Ex/subpage").getCanonicalUri().toString(),
|
||||
is(BuildConfig.HOME_URL + "User:Ex/subpage"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unicodeUri() throws Throwable {
|
||||
assertThat(new PageTitle("User:例").getCanonicalUri().toString(),
|
||||
is(BuildConfig.HOME_URL + "User:" + URLEncoder.encode("例", "utf-8")));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue