1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-22 04:12:08 +01:00

Fix secondlion BuildConfig, githash

This commit is contained in:
Gregor Santner 2018-03-05 23:37:24 +01:00
parent 07acb6bd02
commit 5921549a9c
7 changed files with 48 additions and 23 deletions

View file

@ -14,8 +14,9 @@ android {
targetSdkVersion version_setup_targetSdk targetSdkVersion version_setup_targetSdk
buildConfigField "boolean", "IS_TEST_BUILD", "false" buildConfigField "boolean", "IS_TEST_BUILD", "false"
buildConfigField "boolean", "IS_GPLAY_BUILD", "false" buildConfigField "boolean", "IS_GPLAY_BUILD", "false"
buildConfigField "String[]", "APPLICATION_LANGUAGES", "${getUsedAndroidLanguages()}" buildConfigField "String[]", "DETECTED_ANDROID_LOCALES", "${findUsedAndroidLocales()}"
buildConfigField "String", "GITHASH", "\"${getGitHash()}\"" buildConfigField "String", "GITHASH", "\"${getGitHash()}\""
resValue "string", "manifest_package_id", "com.github.dfa.diaspora_android"
applicationId "com.github.dfa.diaspora_android" applicationId "com.github.dfa.diaspora_android"
versionName "1.1.0" versionName "1.1.0"
@ -53,6 +54,7 @@ android {
flavorGplay { flavorGplay {
buildConfigField "boolean", "IS_GPLAY_BUILD", "true" buildConfigField "boolean", "IS_GPLAY_BUILD", "true"
}*/ }*/
flavorTest { flavorTest {
applicationId "com.github.dfa.secondlion" applicationId "com.github.dfa.secondlion"
resValue 'string', 'app_name', "secondlion*" resValue 'string', 'app_name', "secondlion*"

View file

@ -167,7 +167,7 @@ public class AspectListFragment extends ThemedFragment implements OnSomethingCli
final DiasporaAspect aspect = aspectList[position]; final DiasporaAspect aspect = aspectList[position];
holder.title.setText(aspect.name); holder.title.setText(aspect.name);
if (position % 2 == 1) { if (position % 2 == 1) {
holder.root.setBackgroundColor(isAmoledColorMode ? Color.BLACK : ContextUtils.get().color(R.color.alternate_row_color)); holder.root.setBackgroundColor(isAmoledColorMode ? Color.BLACK : ContextUtils.get().rcolor(R.color.alternate_row_color));
holder.title.setTextColor(isAmoledColorMode ? Color.GRAY : Color.BLACK); holder.title.setTextColor(isAmoledColorMode ? Color.GRAY : Color.BLACK);
} else { } else {
holder.root.setBackgroundColor(isAmoledColorMode ? Color.BLACK : Color.WHITE); holder.root.setBackgroundColor(isAmoledColorMode ? Color.BLACK : Color.WHITE);

View file

@ -166,7 +166,7 @@ public class TagListFragment extends ThemedFragment implements OnSomethingClickL
final String tag = followedTagsList[position]; final String tag = followedTagsList[position];
holder.title.setText(tag); holder.title.setText(tag);
if (position % 2 == 1) { if (position % 2 == 1) {
holder.root.setBackgroundColor(isAmoledColorMode ? Color.BLACK : ContextUtils.get().color(R.color.alternate_row_color)); holder.root.setBackgroundColor(isAmoledColorMode ? Color.BLACK : ContextUtils.get().rcolor(R.color.alternate_row_color));
holder.title.setTextColor(isAmoledColorMode ? Color.GRAY : Color.BLACK); holder.title.setTextColor(isAmoledColorMode ? Color.GRAY : Color.BLACK);
} else { } else {
holder.root.setBackgroundColor(isAmoledColorMode ? Color.BLACK : Color.WHITE); holder.root.setBackgroundColor(isAmoledColorMode ? Color.BLACK : Color.WHITE);

View file

@ -50,7 +50,7 @@ public class ThemedColorPickerPreference extends Preference implements Themeable
AppSettings appSettings = AppSettings.get(); AppSettings appSettings = AppSettings.get();
String key = getKey(); String key = getKey();
int color = ContextUtils.get().color(R.color.primary); int color = ContextUtils.get().rcolor(R.color.primary);
if ((appSettings.isKeyEqual(key, R.string.pref_key__primary_color_shade))) { if ((appSettings.isKeyEqual(key, R.string.pref_key__primary_color_shade))) {
color = appSettings.getPrimaryColor(); color = appSettings.getPrimaryColor();
} else if ((appSettings.isKeyEqual(key, R.string.pref_key__accent_color_shade))) { } else if ((appSettings.isKeyEqual(key, R.string.pref_key__accent_color_shade))) {

View file

@ -114,7 +114,7 @@ public class LanguagePreference extends ListPreference {
// Fetch readable details // Fetch readable details
ContextUtils contextUtils = new ContextUtils(context); ContextUtils contextUtils = new ContextUtils(context);
List<String> languages = new ArrayList<>(); List<String> languages = new ArrayList<>();
Object bcof = contextUtils.getBuildConfigValue("APPLICATION_LANGUAGES"); Object bcof = contextUtils.getBuildConfigValue("DETECTED_ANDROID_LOCALES");
if (bcof instanceof String[]) { if (bcof instanceof String[]) {
for (String langId : (String[]) bcof) { for (String langId : (String[]) bcof) {
Locale locale = contextUtils.getLocaleByAndroidCode(langId); Locale locale = contextUtils.getLocaleByAndroidCode(langId);

View file

@ -100,18 +100,23 @@ public class ContextUtils {
public static final String ARRAY = "array"; public static final String ARRAY = "array";
public static final String DIMEN = "dimen"; public static final String DIMEN = "dimen";
public static final String MENU = "menu"; public static final String MENU = "menu";
public static final String BOOL = "bool";
public static final String RAW = "raw"; public static final String RAW = "raw";
} }
public String str(@StringRes int strResId) { public String rstr(@StringRes int strResId) {
return _context.getString(strResId); return _context.getString(strResId);
} }
public Drawable drawable(@DrawableRes int resId) { public String rstr(String strResKey) {
return rstr(getResId(ResType.STRING, strResKey));
}
public Drawable rdrawable(@DrawableRes int resId) {
return ContextCompat.getDrawable(_context, resId); return ContextCompat.getDrawable(_context, resId);
} }
public int color(@ColorRes int resId) { public int rcolor(@ColorRes int resId) {
return ContextCompat.getColor(_context, resId); return ContextCompat.getColor(_context, resId);
} }
@ -159,14 +164,23 @@ public class ContextUtils {
} }
/** /**
* Get field from PackageId.BuildConfig * Get field from ${applicationId}.BuildConfig
* May be helpful in libraries, where a access to * May be helpful in libraries, where a access to
* BuildConfig would only get values of the library * BuildConfig would only get values of the library
* rather than the app ones * rather than the app ones. It awaits a string resource
* of the package set in manifest (root element).
* Falls back to applicationId of the app which may differ from manifest.
*/ */
public Object getBuildConfigValue(String fieldName) { public Object getBuildConfigValue(String fieldName) {
String pkg;
try { try {
Class<?> c = Class.forName(_context.getPackageName() + ".BuildConfig"); pkg = rstr("manifest_package_id");
} catch (Resources.NotFoundException ex) {
pkg = _context.getPackageName();
}
pkg += ".BuildConfig";
try {
Class<?> c = Class.forName(pkg);
return c.getField(fieldName).get(null); return c.getField(fieldName).get(null);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -174,7 +188,7 @@ public class ContextUtils {
} }
} }
public boolean getBuildConfigBoolean(String fieldName, boolean defaultValue) { public boolean bcbool(String fieldName, boolean defaultValue) {
Object field = getBuildConfigValue(fieldName); Object field = getBuildConfigValue(fieldName);
if (field != null && field instanceof Boolean) { if (field != null && field instanceof Boolean) {
return (Boolean) field; return (Boolean) field;
@ -182,27 +196,35 @@ public class ContextUtils {
return defaultValue; return defaultValue;
} }
public String bcstr(String fieldName, String defaultValue) {
Object field = getBuildConfigValue(fieldName);
if (field != null && field instanceof String) {
return (String) field;
}
return defaultValue;
}
public boolean isGooglePlayBuild() { public boolean isGooglePlayBuild() {
return getBuildConfigBoolean("IS_GPLAY_BUILD", true); return bcbool("IS_GPLAY_BUILD", true);
} }
public boolean isFossBuild() { public boolean isFossBuild() {
return getBuildConfigBoolean("IS_FOSS_BUILD", false); return bcbool("IS_FOSS_BUILD", false);
} }
// Requires donate__bitcoin_* resources (see below) to be available as string resource // Requires donate__bitcoin_* resources (see below) to be available as string resource
public void showDonateBitcoinRequest(@StringRes final int strResBitcoinId, @StringRes final int strResBitcoinAmount, @StringRes final int strResBitcoinMessage, @StringRes final int strResAlternativeDonateUrl) { public void showDonateBitcoinRequest(@StringRes final int strResBitcoinId, @StringRes final int strResBitcoinAmount, @StringRes final int strResBitcoinMessage, @StringRes final int strResAlternativeDonateUrl) {
if (!isGooglePlayBuild()) { if (!isGooglePlayBuild()) {
String btcUri = String.format("bitcoin:%s?amount=%s&label=%s&message=%s", String btcUri = String.format("bitcoin:%s?amount=%s&label=%s&message=%s",
str(strResBitcoinId), str(strResBitcoinAmount), rstr(strResBitcoinId), rstr(strResBitcoinAmount),
str(strResBitcoinMessage), str(strResBitcoinMessage)); rstr(strResBitcoinMessage), rstr(strResBitcoinMessage));
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(btcUri)); intent.setData(Uri.parse(btcUri));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try { try {
_context.startActivity(intent); _context.startActivity(intent);
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
openWebpageInExternalBrowser(str(strResAlternativeDonateUrl)); openWebpageInExternalBrowser(rstr(strResAlternativeDonateUrl));
} }
} }
} }
@ -239,7 +261,7 @@ public class ContextUtils {
@SuppressWarnings("RestrictedApi") @SuppressWarnings("RestrictedApi")
public void setTintColorOfButton(AppCompatButton button, @ColorRes int resColor) { public void setTintColorOfButton(AppCompatButton button, @ColorRes int resColor) {
button.setSupportBackgroundTintList(ColorStateList.valueOf( button.setSupportBackgroundTintList(ColorStateList.valueOf(
color(resColor) rcolor(resColor)
)); ));
} }
@ -272,7 +294,7 @@ public class ContextUtils {
return new SimpleMarkdownParser() return new SimpleMarkdownParser()
.parse(_context.getResources().openRawResource(rawMdFile), .parse(_context.getResources().openRawResource(rawMdFile),
prepend, SimpleMarkdownParser.FILTER_ANDROID_TEXTVIEW) prepend, SimpleMarkdownParser.FILTER_ANDROID_TEXTVIEW)
.replaceColor("#000001", color(getResId(ResType.COLOR, "accent"))) .replaceColor("#000001", rcolor(getResId(ResType.COLOR, "accent")))
.removeMultiNewlines().replaceBulletCharacter("*").getHtml(); .removeMultiNewlines().replaceBulletCharacter("*").getHtml();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -63,7 +63,7 @@ task copyRepoFiles(type: Copy) {
@SuppressWarnings(["UnnecessaryQualifiedReference", "SpellCheckingInspection", "GroovyUnusedDeclaration"]) @SuppressWarnings(["UnnecessaryQualifiedReference", "SpellCheckingInspection", "GroovyUnusedDeclaration"])
// Returns used android languages as a buildConfig array: {'de', 'it', ..}" // Returns used android languages as a buildConfig array: {'de', 'it', ..}"
static String getUsedAndroidLanguages() { static String findUsedAndroidLocales() {
Set<String> langs = new HashSet<>() Set<String> langs = new HashSet<>()
new File('.').eachFileRecurse(groovy.io.FileType.DIRECTORIES) { new File('.').eachFileRecurse(groovy.io.FileType.DIRECTORIES) {
final foldername = it.name final foldername = it.name
@ -80,12 +80,13 @@ static String getUsedAndroidLanguages() {
ext.getGitHash = { -> ext.getGitHash = { ->
try { try {
def stdout = new ByteArrayOutputStream() exec { def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', 'HEAD' commandLine 'git', 'rev-parse', 'HEAD'
standardOutput = stdout standardOutput = stdout
} }
return stdout.toString().trim() return stdout.toString().trim()
} catch (Exception e) { } catch (Exception ignored) {
return '???' return 'unknown'
} }
} }