PlayerAndroid/app/src/main/java/code/name/monkey/retromusic/activities/WhatsNewActivity.java

90 lines
4.4 KiB
Java
Raw Normal View History

2019-04-20 05:29:45 +00:00
package code.name.monkey.retromusic.activities;
2018-12-08 03:33:02 +00:00
2020-01-05 18:22:21 +00:00
2018-12-08 03:33:02 +00:00
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Color;
2018-12-08 03:33:02 +00:00
import android.os.Bundle;
import android.webkit.WebView;
2019-05-22 02:53:18 +00:00
import androidx.annotation.NonNull;
2019-08-04 10:08:34 +00:00
import androidx.annotation.Nullable;
2019-05-22 02:53:18 +00:00
import androidx.appcompat.widget.Toolbar;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
2020-04-26 19:08:15 +00:00
import java.util.Locale;
2018-12-08 03:33:02 +00:00
import code.name.monkey.appthemehelper.ThemeStore;
2020-02-21 18:18:11 +00:00
import code.name.monkey.appthemehelper.util.ATHUtil;
2018-12-08 03:33:02 +00:00
import code.name.monkey.appthemehelper.util.ColorUtil;
2020-04-28 09:35:14 +00:00
import code.name.monkey.appthemehelper.util.MaterialValueHelper;
2018-12-08 03:33:02 +00:00
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper;
import code.name.monkey.retromusic.R;
2019-04-20 05:29:45 +00:00
import code.name.monkey.retromusic.activities.base.AbsBaseActivity;
import code.name.monkey.retromusic.util.PreferenceUtilKT;
2018-12-08 03:33:02 +00:00
public class WhatsNewActivity extends AbsBaseActivity {
private static String colorToCSS(int color) {
2020-04-28 09:35:14 +00:00
return String.format(Locale.getDefault(), "rgba(%d, %d, %d, %d)", Color.red(color), Color.green(color),
2020-04-26 19:08:15 +00:00
Color.blue(color), Color.alpha(color)); // on API 29, WebView doesn't load with hex colors
}
private static void setChangelogRead(@NonNull Context context) {
try {
PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
int currentVersion = pInfo.versionCode;
PreferenceUtilKT.INSTANCE.setLastVersion(currentVersion);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
2018-12-08 03:33:02 +00:00
@Override
2019-08-04 10:08:34 +00:00
protected void onCreate(@Nullable Bundle savedInstanceState) {
2019-12-05 18:18:54 +00:00
setDrawUnderStatusBar();
2018-12-08 03:33:02 +00:00
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_whats_new);
setStatusbarColorAuto();
2019-12-05 18:18:54 +00:00
setNavigationbarColorAuto();
2018-12-08 03:33:02 +00:00
setTaskDescriptionColorAuto();
2020-05-03 19:24:11 +00:00
WebView webView = findViewById(R.id.webView);
Toolbar toolbar = findViewById(R.id.toolbar);
2020-02-21 18:18:11 +00:00
toolbar.setBackgroundColor(ATHUtil.INSTANCE.resolveColor(this, R.attr.colorSurface));
2018-12-08 03:33:02 +00:00
toolbar.setNavigationOnClickListener(v -> onBackPressed());
2019-10-12 09:29:52 +00:00
ToolbarContentTintHelper.colorBackButton(toolbar);
2020-02-21 18:18:11 +00:00
2018-12-08 03:33:02 +00:00
try {
StringBuilder buf = new StringBuilder();
InputStream json = getAssets().open("retro-changelog.html");
2019-05-22 02:53:18 +00:00
BufferedReader in = new BufferedReader(new InputStreamReader(json, StandardCharsets.UTF_8));
2018-12-08 03:33:02 +00:00
String str;
2020-01-05 18:22:21 +00:00
while ((str = in.readLine()) != null) {
2018-12-08 03:33:02 +00:00
buf.append(str);
2020-01-05 18:22:21 +00:00
}
2018-12-08 03:33:02 +00:00
in.close();
// Inject color values for WebView body background and links
2020-02-21 18:18:11 +00:00
final boolean isDark = ATHUtil.INSTANCE.isWindowBackgroundDark(this);
2020-04-28 09:35:14 +00:00
final int accentColor = ThemeStore.Companion.accentColor(this);
2020-04-26 19:08:15 +00:00
final String backgroundColor = colorToCSS(ATHUtil.INSTANCE.resolveColor(this, R.attr.colorSurface, Color.parseColor(isDark ? "#424242" : "#ffffff")));
final String contentColor = colorToCSS(Color.parseColor(isDark ? "#ffffff" : "#000000"));
2020-04-26 19:08:15 +00:00
final String textColor = colorToCSS(Color.parseColor(isDark ? "#60FFFFFF" : "#80000000"));
2020-04-28 09:35:14 +00:00
final String accentColorString = colorToCSS(ThemeStore.Companion.accentColor(this));
final String accentTextColor = colorToCSS(MaterialValueHelper.getPrimaryTextColor(this, ColorUtil.INSTANCE.isColorLight(accentColor)));
final String changeLog = buf.toString()
2020-05-03 19:24:11 +00:00
.replace("{style-placeholder}", String.format("body { background-color: %s; color: %s; } li {color: %s;} .colorHeader {background-color: %s; color: %s;} .tag {color: %s;}", backgroundColor, contentColor, textColor, accentColorString, accentTextColor, accentColorString))
.replace("{link-color}", colorToCSS(ThemeStore.Companion.accentColor(this)))
2020-04-26 19:08:15 +00:00
.replace("{link-color-active}", colorToCSS(ColorUtil.INSTANCE.lightenColor(ThemeStore.Companion.accentColor(this))));
webView.loadData(changeLog, "text/html", "UTF-8");
2018-12-08 03:33:02 +00:00
} catch (Throwable e) {
webView.loadData("<h1>Unable to load</h1><p>" + e.getLocalizedMessage() + "</p>", "text/html", "UTF-8");
}
setChangelogRead(this);
}
}