change log dialog add

This commit is contained in:
h4h13 2018-08-06 16:16:47 +05:30
parent b27cce969e
commit 1b7a7b68b1

View file

@ -0,0 +1 @@
package code.name.monkey.retromusic.dialogs; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.graphics.Color; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.webkit.WebView; import com.afollestad.materialdialogs.internal.ThemeSingleton; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Objects; import butterknife.BindView; import butterknife.ButterKnife; import code.name.monkey.appthemehelper.util.ATHUtil; import code.name.monkey.appthemehelper.util.ColorUtil; import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.util.PreferenceUtil; import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment; public class ChangelogDialog extends RoundedBottomSheetDialogFragment { @BindView(R.id.web_view) WebView webView; public static ChangelogDialog create() { return new ChangelogDialog(); } public static void setChangelogRead(@NonNull Context context) { try { PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); int currentVersion = pInfo.versionCode; PreferenceUtil.getInstance(context).setLastChangeLogVersion(currentVersion); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } } private static String colorToHex(int color) { return Integer.toHexString(color).substring(2); } @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View layout = inflater.inflate(R.layout.dialog_changelog, container, false); ButterKnife.bind(this, layout); return layout; } @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); try { // Load from phonograph-changelog.html in the assets folder StringBuilder buf = new StringBuilder(); InputStream json = Objects.requireNonNull(getActivity()).getAssets().open ("retro-changelog.html"); BufferedReader in = new BufferedReader(new InputStreamReader(json, "UTF-8")); String str; while ((str = in.readLine()) != null) buf.append(str); in.close(); // Inject color values for WebView body background and links final String backgroundColor = colorToHex(ATHUtil.resolveColor(getActivity(), R.attr.md_background_color, Color.parseColor(ThemeSingleton.get().darkTheme ? "#424242" : "#ffffff"))); final String contentColor = ThemeSingleton.get().darkTheme ? "#ffffff" : "#000000"; webView.loadData(buf.toString() .replace("{style-placeholder}", String.format("body { background-color: %s; color: %s; }", backgroundColor, contentColor)) .replace("{link-color}", colorToHex(ThemeSingleton.get().positiveColor.getDefaultColor())) .replace("{link-color-active}", colorToHex(ColorUtil.lightenColor(ThemeSingleton.get().positiveColor.getDefaultColor()))) , "text/html", "UTF-8"); } catch (Throwable e) { webView.loadData("<h1>Unable to load</h1><p>" + e.getLocalizedMessage() + "</p>", "text/html", "UTF-8"); } setChangelogRead(getActivity()); } }