Use generated version name from BuildConfig

This commit is contained in:
veyndan 2017-03-24 03:09:43 +00:00
parent 0d582100b3
commit 0e3bd3c74a
5 changed files with 7 additions and 16 deletions

View file

@ -30,7 +30,7 @@ public class AboutActivity extends BaseActivity {
ButterKnife.bind(this); ButterKnife.bind(this);
uploadsToText.setText(CommonsApplication.EVENTLOG_WIKI); uploadsToText.setText(CommonsApplication.EVENTLOG_WIKI);
versionText.setText(CommonsApplication.APPLICATION_VERSION); versionText.setText(BuildConfig.VERSION_NAME);
// We can't use formatted strings directly because it breaks with // We can't use formatted strings directly because it breaks with
// our localization tools. Grab an HTML string and turn it into // our localization tools. Grab an HTML string and turn it into

View file

@ -5,7 +5,6 @@ import android.accounts.AccountManager;
import android.accounts.AuthenticatorException; import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException; import android.accounts.OperationCanceledException;
import android.app.Application; import android.app.Application;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.Build; import android.os.Build;
@ -52,8 +51,6 @@ import fr.free.nrw.commons.caching.CacheController;
) )
public class CommonsApplication extends Application { public class CommonsApplication extends Application {
public static String APPLICATION_VERSION; // Populated in onCreate. Race conditions theoretically possible, but practically not?
private MWApi api; private MWApi api;
private Account currentAccount = null; // Unlike a savings account... 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 API_URL = "https://commons.wikimedia.org/w/api.php";
@ -84,7 +81,7 @@ public class CommonsApplication extends Application {
final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
schemeRegistry.register(new Scheme("https", sslSocketFactory, 443)); schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
params.setParameter(CoreProtocolPNames.USER_AGENT, "Commons/" + APPLICATION_VERSION + " (https://mediawiki.org/wiki/Apps/Commons) Android/" + Build.VERSION.RELEASE); params.setParameter(CoreProtocolPNames.USER_AGENT, "Commons/" + BuildConfig.VERSION_NAME + " (https://mediawiki.org/wiki/Apps/Commons) Android/" + Build.VERSION.RELEASE);
return new DefaultHttpClient(cm, params); return new DefaultHttpClient(cm, params);
} }
@ -105,14 +102,6 @@ public class CommonsApplication extends Application {
.build(); .build();
ImageLoader.getInstance().init(imageLoaderConfiguration); ImageLoader.getInstance().init(imageLoaderConfiguration);
try {
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
APPLICATION_VERSION = pInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
// LET US WIN THE AWARD FOR DUMBEST CHECKED EXCEPTION EVER!
throw new RuntimeException(e);
}
// Initialize EventLogging // Initialize EventLogging
EventLog.setApp(this); EventLog.setApp(this);

View file

@ -90,7 +90,7 @@ public class EventLog {
fullData.put("wiki", CommonsApplication.EVENTLOG_WIKI); fullData.put("wiki", CommonsApplication.EVENTLOG_WIKI);
data.put("device", DEVICE); data.put("device", DEVICE);
data.put("platform", "Android/" + Build.VERSION.RELEASE); data.put("platform", "Android/" + Build.VERSION.RELEASE);
data.put("appversion", "Android/" + CommonsApplication.APPLICATION_VERSION); data.put("appversion", "Android/" + BuildConfig.VERSION_NAME);
fullData.put("event", data); fullData.put("event", data);
return new URL(CommonsApplication.EVENTLOG_URL + "?" + Utils.urlEncode(fullData.toString()) + ";"); return new URL(CommonsApplication.EVENTLOG_URL + "?" + Utils.urlEncode(fullData.toString()) + ";");
} catch (MalformedURLException e) { } catch (MalformedURLException e) {

View file

@ -13,6 +13,7 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import fr.free.nrw.commons.BuildConfig;
import fr.free.nrw.commons.CommonsApplication; import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.EventLog; import fr.free.nrw.commons.EventLog;
import fr.free.nrw.commons.Media; import fr.free.nrw.commons.Media;
@ -154,7 +155,7 @@ public class Contribution extends Media {
buffer.append("== {{int:license-header}} ==\n") buffer.append("== {{int:license-header}} ==\n")
.append(Utils.licenseTemplateFor(getLicense())).append("\n\n") .append(Utils.licenseTemplateFor(getLicense())).append("\n\n")
.append("{{Uploaded from Mobile|platform=Android|version=").append(CommonsApplication.APPLICATION_VERSION).append("}}\n") .append("{{Uploaded from Mobile|platform=Android|version=").append(BuildConfig.VERSION_NAME).append("}}\n")
.append(getTrackingTemplates()); .append(getTrackingTemplates());
return buffer.toString(); return buffer.toString();
} }

View file

@ -26,6 +26,7 @@ import android.widget.Toast;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import fr.free.nrw.commons.AboutActivity; import fr.free.nrw.commons.AboutActivity;
import fr.free.nrw.commons.BuildConfig;
import fr.free.nrw.commons.CommonsApplication; import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.R; import fr.free.nrw.commons.R;
import fr.free.nrw.commons.SettingsActivity; import fr.free.nrw.commons.SettingsActivity;
@ -136,7 +137,7 @@ public class ContributionsListFragment extends Fragment {
Intent feedbackIntent = new Intent(Intent.ACTION_SEND); Intent feedbackIntent = new Intent(Intent.ACTION_SEND);
feedbackIntent.setType("message/rfc822"); feedbackIntent.setType("message/rfc822");
feedbackIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { CommonsApplication.FEEDBACK_EMAIL }); feedbackIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { CommonsApplication.FEEDBACK_EMAIL });
feedbackIntent.putExtra(Intent.EXTRA_SUBJECT, String.format(CommonsApplication.FEEDBACK_EMAIL_SUBJECT, CommonsApplication.APPLICATION_VERSION)); feedbackIntent.putExtra(Intent.EXTRA_SUBJECT, String.format(CommonsApplication.FEEDBACK_EMAIL_SUBJECT, BuildConfig.VERSION_NAME));
try { try {
startActivity(feedbackIntent); startActivity(feedbackIntent);
} }