1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-24 21:32:07 +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
buildConfigField "boolean", "IS_TEST_BUILD", "false"
buildConfigField "boolean", "IS_GPLAY_BUILD", "false"
buildConfigField "String[]", "APPLICATION_LANGUAGES", "${getUsedAndroidLanguages()}"
buildConfigField "String[]", "DETECTED_ANDROID_LOCALES", "${findUsedAndroidLocales()}"
buildConfigField "String", "GITHASH", "\"${getGitHash()}\""
resValue "string", "manifest_package_id", "com.github.dfa.diaspora_android"
applicationId "com.github.dfa.diaspora_android"
versionName "1.1.0"
@ -53,6 +54,7 @@ android {
flavorGplay {
buildConfigField "boolean", "IS_GPLAY_BUILD", "true"
}*/
flavorTest {
applicationId "com.github.dfa.secondlion"
resValue 'string', 'app_name', "secondlion*"

View file

@ -167,7 +167,7 @@ public class AspectListFragment extends ThemedFragment implements OnSomethingCli
final DiasporaAspect aspect = aspectList[position];
holder.title.setText(aspect.name);
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);
} else {
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];
holder.title.setText(tag);
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);
} else {
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();
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))) {
color = appSettings.getPrimaryColor();
} 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
ContextUtils contextUtils = new ContextUtils(context);
List<String> languages = new ArrayList<>();
Object bcof = contextUtils.getBuildConfigValue("APPLICATION_LANGUAGES");
Object bcof = contextUtils.getBuildConfigValue("DETECTED_ANDROID_LOCALES");
if (bcof instanceof String[]) {
for (String langId : (String[]) bcof) {
Locale locale = contextUtils.getLocaleByAndroidCode(langId);

View file

@ -100,18 +100,23 @@ public class ContextUtils {
public static final String ARRAY = "array";
public static final String DIMEN = "dimen";
public static final String MENU = "menu";
public static final String BOOL = "bool";
public static final String RAW = "raw";
}
public String str(@StringRes int strResId) {
public String rstr(@StringRes int 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);
}
public int color(@ColorRes int resId) {
public int rcolor(@ColorRes int 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
* 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) {
String pkg;
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);
} catch (Exception e) {
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);
if (field != null && field instanceof Boolean) {
return (Boolean) field;
@ -182,27 +196,35 @@ public class ContextUtils {
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() {
return getBuildConfigBoolean("IS_GPLAY_BUILD", true);
return bcbool("IS_GPLAY_BUILD", true);
}
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
public void showDonateBitcoinRequest(@StringRes final int strResBitcoinId, @StringRes final int strResBitcoinAmount, @StringRes final int strResBitcoinMessage, @StringRes final int strResAlternativeDonateUrl) {
if (!isGooglePlayBuild()) {
String btcUri = String.format("bitcoin:%s?amount=%s&label=%s&message=%s",
str(strResBitcoinId), str(strResBitcoinAmount),
str(strResBitcoinMessage), str(strResBitcoinMessage));
rstr(strResBitcoinId), rstr(strResBitcoinAmount),
rstr(strResBitcoinMessage), rstr(strResBitcoinMessage));
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(btcUri));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
_context.startActivity(intent);
} catch (ActivityNotFoundException e) {
openWebpageInExternalBrowser(str(strResAlternativeDonateUrl));
openWebpageInExternalBrowser(rstr(strResAlternativeDonateUrl));
}
}
}
@ -239,7 +261,7 @@ public class ContextUtils {
@SuppressWarnings("RestrictedApi")
public void setTintColorOfButton(AppCompatButton button, @ColorRes int resColor) {
button.setSupportBackgroundTintList(ColorStateList.valueOf(
color(resColor)
rcolor(resColor)
));
}
@ -272,7 +294,7 @@ public class ContextUtils {
return new SimpleMarkdownParser()
.parse(_context.getResources().openRawResource(rawMdFile),
prepend, SimpleMarkdownParser.FILTER_ANDROID_TEXTVIEW)
.replaceColor("#000001", color(getResId(ResType.COLOR, "accent")))
.replaceColor("#000001", rcolor(getResId(ResType.COLOR, "accent")))
.removeMultiNewlines().replaceBulletCharacter("*").getHtml();
} catch (IOException e) {
e.printStackTrace();

View file

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