Fixed the help url (#172)
* Fixed the help URL. It now opens the user manual for the current app version, not for the latest * updated documentation
This commit is contained in:
parent
f44cbae530
commit
b470f5e939
3 changed files with 41 additions and 6 deletions
|
|
@ -1,8 +1,14 @@
|
|||
package io.github.sspanak.tt9.preferences.screens;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import io.github.sspanak.tt9.BuildConfig;
|
||||
import io.github.sspanak.tt9.Logger;
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.preferences.items.ItemLoadDictionary;
|
||||
import io.github.sspanak.tt9.preferences.items.ItemSelectLanguage;
|
||||
|
|
@ -12,6 +18,8 @@ import io.github.sspanak.tt9.preferences.items.ItemTruncateDictionary;
|
|||
import io.github.sspanak.tt9.preferences.PreferencesActivity;
|
||||
|
||||
public class MainSettingsScreen extends BaseScreenFragment {
|
||||
private final Pattern releaseVersionRegex = Pattern.compile("^\\d+\\.\\d+$");
|
||||
|
||||
public MainSettingsScreen() {
|
||||
init();
|
||||
}
|
||||
|
|
@ -32,11 +40,13 @@ public class MainSettingsScreen extends BaseScreenFragment {
|
|||
return R.xml.prefs;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
createAboutSection();
|
||||
createAppearanceSection();
|
||||
createDictionarySection();
|
||||
createHelpSection();
|
||||
createPredictiveModeSection();
|
||||
}
|
||||
|
||||
|
|
@ -77,6 +87,30 @@ public class MainSettingsScreen extends BaseScreenFragment {
|
|||
}
|
||||
|
||||
|
||||
private void createHelpSection() {
|
||||
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("tt9/MainSettingsScreen", "Could not set versioned help URL. Falling back to the default. " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void createAboutSection() {
|
||||
Preference vi = findPreference("version_info");
|
||||
if (vi != null) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue