Skip to content

Commit

Permalink
An obscure miui-related crash on pre-Lollipop devices should be fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
yeriomin committed Oct 16, 2018
1 parent 71c8cf1 commit 21d31d2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@

package com.github.yeriomin.yalpstore;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;

import java.lang.reflect.Method;

public class ThemeManager extends ThemeManagerAbstract {

protected int getThemeLight() {
Expand All @@ -29,6 +35,16 @@ protected int getThemeDark() {
return R.style.YalpStoreThemeDark;
}

@Override
protected int getThemeDefault(Context context) {
int themeId = super.getThemeDefault(context);
if (0 == themeId && isMiui()) {
return getThemeDark();
} else {
return themeId;
}
}

@Override
protected int getThemeBlack() {
return R.style.YalpStoreThemeBlack;
Expand All @@ -43,4 +59,22 @@ protected int getDialogThemeLight() {
protected int getDialogThemeDark() {
return R.style.YalpStoreDialogStyleDark;
}

private boolean isMiui() {
return !TextUtils.isEmpty(getSystemProperty("ro.miui.ui.version.code"));
}

/**
* Used for pre-lollipop devices
*/
@SuppressLint("PrivateApi")
private String getSystemProperty(String propertyName) {
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
return (String) get.invoke(c, propertyName);
} catch (Throwable e) {
return "";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private int getThemeId(String theme, Context context) {
}
}

private int getThemeDefault(Context context) {
protected int getThemeDefault(Context context) {
if (isAmazonTv(context)) {
return getThemeDark();
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Expand Down

0 comments on commit 21d31d2

Please sign in to comment.