mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Fix version number for alpha builds (#2325)
This commit is contained in:
parent
ddc83f1f22
commit
de9611821b
11 changed files with 51 additions and 16 deletions
|
|
@ -141,7 +141,7 @@ android {
|
|||
testCoverageEnabled true
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
||||
testProguardFile 'test-proguard-rules.txt'
|
||||
versionNameSuffix "-debug-" + getBranchName() + "~" + getBuildVersion()
|
||||
versionNameSuffix "-debug-" + getBranchName()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -180,6 +180,7 @@ android {
|
|||
buildConfigField "String", "RECENT_SEARCH_AUTHORITY", "\"fr.free.nrw.commons.explore.recentsearches.contentprovider\""
|
||||
buildConfigField "String", "BOOKMARK_AUTHORITY", "\"fr.free.nrw.commons.bookmarks.contentprovider\""
|
||||
buildConfigField "String", "BOOKMARK_LOCATIONS_AUTHORITY", "\"fr.free.nrw.commons.bookmarks.locations.contentprovider\""
|
||||
buildConfigField "String", "COMMIT_SHA", "\"" + getBuildVersion().toString() + "\""
|
||||
|
||||
dimension 'tier'
|
||||
}
|
||||
|
|
@ -209,6 +210,7 @@ android {
|
|||
buildConfigField "String", "RECENT_SEARCH_AUTHORITY", "\"fr.free.nrw.commons.beta.explore.recentsearches.contentprovider\""
|
||||
buildConfigField "String", "BOOKMARK_AUTHORITY", "\"fr.free.nrw.commons.beta.bookmarks.contentprovider\""
|
||||
buildConfigField "String", "BOOKMARK_LOCATIONS_AUTHORITY", "\"fr.free.nrw.commons.beta.bookmarks.locations.contentprovider\""
|
||||
buildConfigField "String", "COMMIT_SHA", "\"" + getBuildVersion().toString() + "\""
|
||||
|
||||
dimension 'tier'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package fr.free.nrw.commons;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
|
@ -23,6 +22,7 @@ import butterknife.ButterKnife;
|
|||
import butterknife.OnClick;
|
||||
import fr.free.nrw.commons.theme.NavigationBaseActivity;
|
||||
import fr.free.nrw.commons.ui.widget.HtmlTextView;
|
||||
import fr.free.nrw.commons.utils.ConfigUtils;
|
||||
|
||||
/**
|
||||
* Represents about screen of this app
|
||||
|
|
@ -59,7 +59,7 @@ public class AboutActivity extends NavigationBaseActivity {
|
|||
SpannableString content = new SpannableString(getString(R.string.about_faq));
|
||||
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
|
||||
faqText.setText(content);
|
||||
versionText.setText(BuildConfig.VERSION_NAME);
|
||||
versionText.setText(ConfigUtils.getVersionNameWithSha(getApplicationContext()));
|
||||
TextView rate_us = findViewById(R.id.about_rate_us);
|
||||
TextView privacy_policy = findViewById(R.id.about_privacy_policy);
|
||||
TextView translate = findViewById(R.id.about_translate);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package fr.free.nrw.commons.contributions;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.support.annotation.IntDef;
|
||||
|
|
@ -15,6 +16,7 @@ import fr.free.nrw.commons.BuildConfig;
|
|||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.Media;
|
||||
import fr.free.nrw.commons.settings.Prefs;
|
||||
import fr.free.nrw.commons.utils.ConfigUtils;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.SOURCE;
|
||||
|
||||
|
|
@ -139,7 +141,7 @@ public class Contribution extends Media {
|
|||
this.dateUploaded = date;
|
||||
}
|
||||
|
||||
public String getPageContents() {
|
||||
public String getPageContents(Context applicationContext) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
|
||||
|
||||
|
|
@ -163,7 +165,8 @@ public class Contribution extends Media {
|
|||
|
||||
buffer.append("== {{int:license-header}} ==\n")
|
||||
.append(licenseTemplateFor(getLicense())).append("\n\n")
|
||||
.append("{{Uploaded from Mobile|platform=Android|version=").append(BuildConfig.VERSION_NAME).append("}}\n");
|
||||
.append("{{Uploaded from Mobile|platform=Android|version=")
|
||||
.append(ConfigUtils.getVersionNameWithSha(applicationContext)).append("}}\n");
|
||||
if(categories!=null&&categories.size()!=0) {
|
||||
for (int i = 0; i < categories.size(); i++) {
|
||||
String category = categories.get(i);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class CommonsLogSender extends LogsSender {
|
|||
protected String getExtraInfo() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("App Version Name: ")
|
||||
.append(BuildConfig.VERSION_NAME)
|
||||
.append(ConfigUtils.getVersionNameWithSha(context))
|
||||
.append("\n");
|
||||
|
||||
builder.append("User Name: ")
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ import fr.free.nrw.commons.category.QueryContinue;
|
|||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.notification.Notification;
|
||||
import fr.free.nrw.commons.notification.NotificationUtils;
|
||||
import fr.free.nrw.commons.utils.ConfigUtils;
|
||||
import fr.free.nrw.commons.utils.DateUtils;
|
||||
import fr.free.nrw.commons.utils.ViewUtil;
|
||||
import in.yuvi.http.fluent.Http;
|
||||
|
|
@ -115,7 +116,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
|||
@Override
|
||||
@NonNull
|
||||
public String getUserAgent() {
|
||||
return "Commons/" + BuildConfig.VERSION_NAME + " (https://mediawiki.org/wiki/Apps/Commons) Android/" + Build.VERSION.RELEASE;
|
||||
return "Commons/" + ConfigUtils.getVersionNameWithSha(context) + " (https://mediawiki.org/wiki/Apps/Commons) Android/" + Build.VERSION.RELEASE;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package fr.free.nrw.commons.mwapi;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
|
||||
import fr.free.nrw.commons.Utils;
|
||||
|
|
@ -16,14 +17,14 @@ public class EventLog {
|
|||
}
|
||||
}
|
||||
|
||||
private static LogBuilder schema(String schema, long revision, MediaWikiApi mwApi, BasicKvStore prefs) {
|
||||
return new LogBuilder(schema, revision, mwApi, prefs);
|
||||
private static LogBuilder schema(String schema, long revision, MediaWikiApi mwApi, BasicKvStore prefs, Context context) {
|
||||
return new LogBuilder(schema, revision, mwApi, prefs, context);
|
||||
}
|
||||
|
||||
public static LogBuilder schema(Object[] scid, MediaWikiApi mwApi, BasicKvStore prefs) {
|
||||
public static LogBuilder schema(Object[] scid, MediaWikiApi mwApi, BasicKvStore prefs, Context context) {
|
||||
if (scid.length != 2) {
|
||||
throw new IllegalArgumentException("Needs an object array with schema as first param and revision as second");
|
||||
}
|
||||
return schema((String) scid[0], (Long) scid[1], mwApi, prefs);
|
||||
return schema((String) scid[0], (Long) scid[1], mwApi, prefs, context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package fr.free.nrw.commons.mwapi;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
|
||||
|
|
@ -13,6 +14,7 @@ import fr.free.nrw.commons.BuildConfig;
|
|||
import fr.free.nrw.commons.Utils;
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.settings.Prefs;
|
||||
import fr.free.nrw.commons.utils.ConfigUtils;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class LogBuilder {
|
||||
|
|
@ -21,6 +23,7 @@ public class LogBuilder {
|
|||
private final long rev;
|
||||
private final String schema;
|
||||
private final BasicKvStore prefs;
|
||||
private final Context context;
|
||||
|
||||
/**
|
||||
* Main constructor of LogBuilder
|
||||
|
|
@ -30,12 +33,17 @@ public class LogBuilder {
|
|||
* @param mwApi Wiki media API instance
|
||||
* @param prefs Instance of SharedPreferences
|
||||
*/
|
||||
LogBuilder(String schema, long revision, MediaWikiApi mwApi, BasicKvStore prefs) {
|
||||
LogBuilder(String schema,
|
||||
long revision,
|
||||
MediaWikiApi mwApi,
|
||||
BasicKvStore prefs,
|
||||
Context context) {
|
||||
this.prefs = prefs;
|
||||
this.data = new JSONObject();
|
||||
this.schema = schema;
|
||||
this.rev = revision;
|
||||
this.mwApi = mwApi;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -65,7 +73,7 @@ public class LogBuilder {
|
|||
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);
|
||||
data.put("appversion", "Android/" + ConfigUtils.getVersionNameWithSha(context));
|
||||
fullData.put("event", data);
|
||||
return new URL(BuildConfig.EVENTLOG_URL + "?" + Utils.urlEncode(fullData.toString()) + ";");
|
||||
} catch (MalformedURLException | JSONException e) {
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import fr.free.nrw.commons.contributions.MainActivity;
|
|||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.notification.NotificationActivity;
|
||||
import fr.free.nrw.commons.settings.SettingsActivity;
|
||||
import fr.free.nrw.commons.utils.ConfigUtils;
|
||||
import timber.log.Timber;
|
||||
|
||||
public abstract class NavigationBaseActivity extends BaseActivity
|
||||
|
|
@ -195,7 +196,7 @@ public abstract class NavigationBaseActivity extends BaseActivity
|
|||
new String[]{CommonsApplication.FEEDBACK_EMAIL});
|
||||
feedbackIntent.putExtra(Intent.EXTRA_SUBJECT,
|
||||
String.format(CommonsApplication.FEEDBACK_EMAIL_SUBJECT,
|
||||
BuildConfig.VERSION_NAME));
|
||||
ConfigUtils.getVersionNameWithSha(getApplicationContext())));
|
||||
try {
|
||||
startActivity(feedbackIntent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
|
|
|
|||
|
|
@ -281,7 +281,8 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
getString(R.string.upload_progress_notification_title_finishing, contribution.getDisplayTitle()),
|
||||
contribution
|
||||
);
|
||||
UploadResult uploadResult = mwApi.uploadFile(filename, fileInputStream, contribution.getDataLength(), contribution.getPageContents(), contribution.getEditSummary(), contribution.getLocalUri(), contribution.getContentProviderUri(), notificationUpdater);
|
||||
UploadResult uploadResult = mwApi.uploadFile(filename, fileInputStream, contribution.getDataLength(),
|
||||
contribution.getPageContents(getApplicationContext()), contribution.getEditSummary(), contribution.getLocalUri(), contribution.getContentProviderUri(), notificationUpdater);
|
||||
|
||||
Timber.d("Response is %s", uploadResult.toString());
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import fr.free.nrw.commons.BuildConfig;
|
||||
|
||||
public class ConfigUtils {
|
||||
|
|
@ -7,4 +12,16 @@ public class ConfigUtils {
|
|||
public static boolean isBetaFlavour() {
|
||||
return BuildConfig.FLAVOR.equals("beta");
|
||||
}
|
||||
|
||||
private static String getVersionName(Context context) {
|
||||
try {
|
||||
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return BuildConfig.VERSION_NAME;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getVersionNameWithSha(Context context) {
|
||||
return String.format(Locale.getDefault(), "%s~%s", getVersionName(context), BuildConfig.COMMIT_SHA);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.google.gson.Gson
|
|||
import fr.free.nrw.commons.BuildConfig
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore
|
||||
import fr.free.nrw.commons.utils.ConfigUtils
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.mockwebserver.MockResponse
|
||||
import okhttp3.mockwebserver.MockWebServer
|
||||
|
|
@ -320,7 +321,7 @@ class ApacheHttpClientMediaWikiApiTest {
|
|||
private fun assertBasicRequestParameters(server: MockWebServer, method: String): RecordedRequest = server.takeRequest().let {
|
||||
assertEquals("/", it.requestUrl.encodedPath())
|
||||
assertEquals(method, it.method)
|
||||
assertEquals("Commons/${BuildConfig.VERSION_NAME} (https://mediawiki.org/wiki/Apps/Commons) Android/${Build.VERSION.RELEASE}",
|
||||
assertEquals("Commons/${ConfigUtils.getVersionNameWithSha(RuntimeEnvironment.application)} (https://mediawiki.org/wiki/Apps/Commons) Android/${Build.VERSION.RELEASE}",
|
||||
it.getHeader("User-Agent"))
|
||||
if ("POST" == method) {
|
||||
assertEquals("application/x-www-form-urlencoded", it.getHeader("Content-Type"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue