Real help screen (#589)
* the manual is converted from markdown to HTML during build time * The user manual is now included in the application. The Help section will no longer attempt to open it from Github * fixed punctuation mistakes in the manual
This commit is contained in:
parent
4c7c941e44
commit
fa6e379b08
9 changed files with 275 additions and 35 deletions
|
|
@ -28,7 +28,9 @@
|
|||
<meta-data android:name="android.view.im" android:resource="@xml/method"/>
|
||||
</service>
|
||||
|
||||
<activity android:label="@string/app_name_short" android:name="io.github.sspanak.tt9.preferences.PreferencesActivity"
|
||||
<activity
|
||||
android:label="@string/app_name_short"
|
||||
android:name="io.github.sspanak.tt9.preferences.PreferencesActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
|
@ -42,6 +44,16 @@
|
|||
android:name="io.github.sspanak.tt9.ui.dialogs.PopupDialogActivity"
|
||||
android:theme="@style/alertDialog" />
|
||||
|
||||
<activity
|
||||
android:label="@string/pref_help"
|
||||
android:name="io.github.sspanak.tt9.preferences.HelpActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:excludeFromRecents="true"
|
||||
android:label=""
|
||||
|
|
|
|||
|
|
@ -0,0 +1,76 @@
|
|||
package io.github.sspanak.tt9.preferences;
|
||||
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Base64;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.util.Logger;
|
||||
|
||||
public class HelpActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
buildLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSupportNavigateUp() {
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void buildLayout() {
|
||||
enableBackButton();
|
||||
setContent();
|
||||
}
|
||||
|
||||
private void enableBackButton() {
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayShowHomeEnabled(true);
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void setContent() {
|
||||
WebView container = new WebView(this);
|
||||
|
||||
// On API > 30 the WebView does not load the entire String with .loadData(),
|
||||
// so we need to do this weird shit.
|
||||
// The "app:" prefix is mandatory, otherwise the anchor links do not work.
|
||||
// Reference: https://developer.android.com/develop/ui/views/layout/webapps/webview
|
||||
String html = getHelpHtml();
|
||||
String encodedHtml = "app:" + Base64.encodeToString(html.getBytes(), Base64.NO_PADDING);
|
||||
container.loadDataWithBaseURL(encodedHtml, html, "text/html", "UTF-8", null);
|
||||
|
||||
setContentView(container);
|
||||
}
|
||||
|
||||
private String getHelpHtml() {
|
||||
AssetManager assets = getAssets();
|
||||
try {
|
||||
InputStream stream = assets.open("help.html");
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
return builder.toString();
|
||||
} catch (Exception e) {
|
||||
Logger.e(getClass().getSimpleName(), "Failed opening the help.html file.");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -31,7 +31,6 @@ public class MainSettingsScreen extends BaseScreenFragment {
|
|||
@Override
|
||||
public void onCreate() {
|
||||
createSettingsSection();
|
||||
addHelpLink();
|
||||
createAboutSection();
|
||||
resetFontSize(false);
|
||||
}
|
||||
|
|
@ -46,30 +45,6 @@ public class MainSettingsScreen extends BaseScreenFragment {
|
|||
}
|
||||
|
||||
|
||||
private void addHelpLink() {
|
||||
try {
|
||||
if (!releaseVersionRegex.matcher(BuildConfig.VERSION_NAME).find()) {
|
||||
throw new Exception("VERSION_NAME does not match: \\d+.\\d+");
|
||||
}
|
||||
|
||||
Preference helpSection = findPreference("help");
|
||||
if (helpSection == null) {
|
||||
throw new Exception("Could not find Help Preference");
|
||||
}
|
||||
|
||||
String majorVersion = BuildConfig.VERSION_NAME.substring(0, BuildConfig.VERSION_NAME.indexOf('.'));
|
||||
String versionedHelpUrl = getString(R.string.help_url).replace("blob/master", "blob/v" + majorVersion + ".0");
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.setAction("android.intent.action.VIEW");
|
||||
intent.setData(Uri.parse(versionedHelpUrl));
|
||||
helpSection.setIntent(intent);
|
||||
} catch (Exception e) {
|
||||
Logger.w("MainSettingsScreen", "Could not set versioned help URL. Falling back to the default. " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void createAboutSection() {
|
||||
Preference donate = findPreference("donate_link");
|
||||
if (donate != null) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string translatable="false" name="dictionary_url">https://raw.githubusercontent.com/sspanak/tt9/%1$s/app/%2$s</string>
|
||||
<string translatable="false" name="help_url">https://github.com/sspanak/tt9/blob/master/docs/user-manual.md</string>
|
||||
<string name="app_name" translatable="false">Traditional T9</string>
|
||||
<string name="app_name_short" translatable="false">TT9</string>
|
||||
<string name="app_settings">TT9 Settings</string>
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@
|
|||
app:orderingFromXml="true">
|
||||
|
||||
<Preference
|
||||
app:key="help"
|
||||
app:summary="github.com/sspanak/tt9"
|
||||
app:key="screen_help"
|
||||
app:summary="English only"
|
||||
app:title="@string/pref_help">
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="@string/help_url" />
|
||||
android:targetPackage="io.github.sspanak.tt9"
|
||||
android:targetClass="io.github.sspanak.tt9.preferences.HelpActivity" />
|
||||
</Preference>
|
||||
|
||||
<Preference
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue