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

92 lines
3.7 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
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.webkit.WebView;
2019-05-22 02:53:18 +00:00
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
2018-12-08 03:33:02 +00:00
import com.google.android.material.appbar.AppBarLayout;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
2019-05-22 02:53:18 +00:00
import java.nio.charset.StandardCharsets;
2019-04-20 05:29:45 +00:00
2018-12-08 03:33:02 +00:00
import code.name.monkey.appthemehelper.ThemeStore;
2019-02-19 10:38:51 +00:00
import code.name.monkey.appthemehelper.util.ATHUtil;
2018-12-08 03:33:02 +00:00
import code.name.monkey.appthemehelper.util.ColorUtil;
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;
2018-12-08 03:33:02 +00:00
import code.name.monkey.retromusic.util.PreferenceUtil;
public class WhatsNewActivity extends AbsBaseActivity {
WebView webView;
Toolbar toolbar;
AppBarLayout appBarLayout;
private static void setChangelogRead(@NonNull Context context) {
try {
PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
int currentVersion = pInfo.versionCode;
PreferenceUtil.getInstance().setLastChangeLogVersion(currentVersion);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
private static String colorToHex(int color) {
return Integer.toHexString(color).substring(2);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_whats_new);
webView = findViewById(R.id.webView);
toolbar = findViewById(R.id.toolbar);
2019-03-18 17:46:52 +00:00
appBarLayout = findViewById(R.id.appBarLayout);
2018-12-08 03:33:02 +00:00
setStatusbarColorAuto();
setNavigationbarColorAuto();
setTaskDescriptionColorAuto();
2018-12-26 17:31:39 +00:00
toolbar.setBackgroundColor(ThemeStore.Companion.primaryColor(this));
appBarLayout.setBackgroundColor(ThemeStore.Companion.primaryColor(this));
2018-12-08 03:33:02 +00:00
setSupportActionBar(toolbar);
2019-05-20 19:38:43 +00:00
2018-12-08 03:33:02 +00:00
toolbar.setNavigationOnClickListener(v -> onBackPressed());
2019-03-18 17:46:52 +00:00
ToolbarContentTintHelper.colorBackButton(toolbar, ThemeStore.Companion.textColorSecondary(this));
2018-12-08 03:33:02 +00:00
try {
// Load from phonograph-changelog.html in the assets folder
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;
while ((str = in.readLine()) != null)
buf.append(str);
in.close();
// Inject color values for WebView body background and links
2018-12-26 17:31:39 +00:00
final String backgroundColor = colorToHex(ThemeStore.Companion.primaryColor(this));
2019-02-19 10:38:51 +00:00
final String contentColor = ATHUtil.INSTANCE.isWindowBackgroundDark(this) ? "#ffffff" : "#000000";
2018-12-08 03:33:02 +00:00
webView.loadData(buf.toString()
.replace("{style-placeholder}",
String.format("body { background-color: %s; color: %s; }", backgroundColor, contentColor))
2019-02-19 10:38:51 +00:00
.replace("{link-color}", colorToHex(ThemeStore.Companion.accentColor(this)))
2019-03-18 17:46:52 +00:00
.replace("{link-color-active}", colorToHex(ColorUtil.INSTANCE.lightenColor(ThemeStore.Companion.accentColor(this))))
2018-12-08 03:33:02 +00:00
, "text/html", "UTF-8");
} catch (Throwable e) {
webView.loadData("<h1>Unable to load</h1><p>" + e.getLocalizedMessage() + "</p>", "text/html", "UTF-8");
}
setChangelogRead(this);
}
}