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;
|
2019-09-02 14:51:53 +00:00
|
|
|
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;
|
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;
|
|
|
|
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;
|
|
|
|
|
2019-09-02 14:51:53 +00:00
|
|
|
import static code.name.monkey.appthemehelper.util.ATHUtil.INSTANCE;
|
|
|
|
|
2018-12-08 03:33:02 +00:00
|
|
|
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;
|
2019-09-09 13:04:53 +00:00
|
|
|
PreferenceUtil.getInstance(context).setLastChangeLogVersion(currentVersion);
|
2018-12-08 03:33:02 +00:00
|
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-02 14:51:53 +00:00
|
|
|
private static String colorToCSS(int color) {
|
|
|
|
return String.format("rgb(%d, %d, %d)", Color.red(color), Color.green(color), Color.blue(color)); // on API 29, WebView doesn't load with hex colors
|
2018-12-08 03:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-08-04 10:08:34 +00:00
|
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
2018-12-08 03:33:02 +00:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_whats_new);
|
|
|
|
|
|
|
|
setStatusbarColorAuto();
|
2019-09-28 17:52:49 +00:00
|
|
|
setNavigationBarColorPrimary();
|
2018-12-08 03:33:02 +00:00
|
|
|
setTaskDescriptionColorAuto();
|
|
|
|
|
2019-05-22 04:15:01 +00:00
|
|
|
webView = findViewById(R.id.webView);
|
|
|
|
toolbar = findViewById(R.id.toolbar);
|
|
|
|
appBarLayout = findViewById(R.id.appBarLayout);
|
|
|
|
|
2019-10-09 13:46:25 +00:00
|
|
|
int primaryColor = INSTANCE.resolveColor(this, R.attr.colorPrimary);
|
|
|
|
toolbar.setBackgroundColor(primaryColor);
|
|
|
|
appBarLayout.setBackgroundColor(primaryColor);
|
2019-05-22 04:15:01 +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-10-12 09:29:52 +00:00
|
|
|
ToolbarContentTintHelper.colorBackButton(toolbar);
|
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;
|
|
|
|
while ((str = in.readLine()) != null)
|
|
|
|
buf.append(str);
|
|
|
|
in.close();
|
|
|
|
|
|
|
|
// Inject color values for WebView body background and links
|
2019-09-02 14:51:53 +00:00
|
|
|
final boolean isDark = INSTANCE.isWindowBackgroundDark(this);
|
2019-09-28 17:52:49 +00:00
|
|
|
final String backgroundColor = colorToCSS(INSTANCE.resolveColor(this, R.attr.colorPrimary, Color.parseColor(isDark ? "#424242" : "#ffffff")));
|
2019-09-02 14:51:53 +00:00
|
|
|
final String contentColor = colorToCSS(Color.parseColor(isDark ? "#ffffff" : "#000000"));
|
|
|
|
final String changeLog = buf.toString()
|
|
|
|
.replace("{style-placeholder}",
|
|
|
|
String.format("body { background-color: %s; color: %s; }", backgroundColor, contentColor))
|
|
|
|
.replace("{link-color}", colorToCSS(ThemeStore.Companion.accentColor(this)))
|
|
|
|
.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);
|
|
|
|
}
|
|
|
|
}
|