Skip to content

Commit

Permalink
Moved Termux app settings into dedicated "directory" in Termux Settin…
Browse files Browse the repository at this point in the history
…gs and added About page

The `TermuxConstants` class has been updated to `v0.20.0`. Check its Changelog sections for info on changes.
  • Loading branch information
agnostic-apollo committed May 13, 2021
1 parent 90c9a7b commit d42514d
Show file tree
Hide file tree
Showing 19 changed files with 344 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ private void updateUI(Bundle bundle) {

final Markwon markwon = MarkdownUtils.getRecyclerMarkwonBuilder(this);

final MarkwonAdapter adapter = MarkwonAdapter.builderTextViewIsRoot(R.layout.activity_report_adapter_node_default)
.include(FencedCodeBlock.class, SimpleEntry.create(R.layout.activity_report_adapter_node_code_block, R.id.code_text_view))
final MarkwonAdapter adapter = MarkwonAdapter.builderTextViewIsRoot(R.layout.markdown_adapter_node_default)
.include(FencedCodeBlock.class, SimpleEntry.create(R.layout.markdown_adapter_node_code_block, R.id.code_text_view))
.build();

recyclerView.setLayoutManager(new LinearLayoutManager(this));
Expand Down
32 changes: 32 additions & 0 deletions app/src/main/java/com/termux/app/activities/SettingsActivity.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.termux.app.activities;

import android.content.Context;
import android.os.Bundle;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;

import com.termux.R;
import com.termux.app.models.ReportInfo;
import com.termux.app.models.UserAction;
import com.termux.shared.termux.TermuxConstants;
import com.termux.shared.termux.TermuxUtils;

public class SettingsActivity extends AppCompatActivity {

Expand Down Expand Up @@ -37,6 +43,32 @@ public static class RootPreferencesFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.root_preferences, rootKey);

setAboutOnPreferenceClickListener();
}

private void setAboutOnPreferenceClickListener() {
Context context = getContext();
Preference about = findPreference("about");
if (context != null && about != null) {
about.setOnPreferenceClickListener(preference -> {
String title = "About";

StringBuilder aboutString = new StringBuilder();
aboutString.append(TermuxUtils.getAppInfoMarkdownString(context, false));

String termuxPluginAppsInfo = TermuxUtils.getTermuxPluginAppsInfoMarkdownString(context);
if (termuxPluginAppsInfo != null)
aboutString.append("\n\n").append(termuxPluginAppsInfo);

aboutString.append("\n\n").append(TermuxUtils.getDeviceInfoMarkdownString(context));
aboutString.append("\n\n").append(TermuxUtils.getImportantLinksMarkdownString(context));

ReportActivity.startReportActivity(context, new ReportInfo(UserAction.ABOUT, TermuxConstants.TERMUX_APP.TERMUX_SETTINGS_ACTIVITY_NAME, title, null, aboutString.toString(), null, false));

return true;
});
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.termux.app.fragments.settings;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.Keep;
import androidx.preference.PreferenceDataStore;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager;

import com.termux.R;
import com.termux.shared.settings.preferences.TermuxAppSharedPreferences;

@Keep
public class TermuxPreferencesFragment extends PreferenceFragmentCompat {

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
PreferenceManager preferenceManager = getPreferenceManager();
preferenceManager.setPreferenceDataStore(TermuxPreferencesDataStore.getInstance(getContext()));

setPreferencesFromResource(R.xml.termux_preferences, rootKey);
}

}

class TermuxPreferencesDataStore extends PreferenceDataStore {

private final Context mContext;
private final TermuxAppSharedPreferences mPreferences;

private static TermuxPreferencesDataStore mInstance;

private TermuxPreferencesDataStore(Context context) {
mContext = context;
mPreferences = new TermuxAppSharedPreferences(context);
}

public static synchronized TermuxPreferencesDataStore getInstance(Context context) {
if (mInstance == null) {
mInstance = new TermuxPreferencesDataStore(context.getApplicationContext());
}
return mInstance;
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.termux.app.fragments.settings;
package com.termux.app.fragments.settings.termux;

import android.content.Context;
import android.os.Bundle;
Expand All @@ -23,7 +23,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
PreferenceManager preferenceManager = getPreferenceManager();
preferenceManager.setPreferenceDataStore(DebuggingPreferencesDataStore.getInstance(getContext()));

setPreferencesFromResource(R.xml.debugging_preferences, rootKey);
setPreferencesFromResource(R.xml.termux_debugging_preferences, rootKey);

PreferenceCategory loggingCategory = findPreference("logging");

Expand Down Expand Up @@ -125,11 +125,11 @@ public void putBoolean(String key, boolean value) {
public boolean getBoolean(String key, boolean defValue) {
switch (key) {
case "terminal_view_key_logging_enabled":
return mPreferences.getTerminalViewKeyLoggingEnabled();
return mPreferences.isTerminalViewKeyLoggingEnabled();
case "plugin_error_notifications_enabled":
return mPreferences.getPluginErrorNotificationsEnabled();
return mPreferences.arePluginErrorNotificationsEnabled();
case "crash_report_notifications_enabled":
return mPreferences.getCrashReportNotificationsEnabled();
return mPreferences.areCrashReportNotificationsEnabled();
default:
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.termux.app.fragments.settings;
package com.termux.app.fragments.settings.termux;

import android.content.Context;
import android.os.Bundle;
Expand All @@ -19,7 +19,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
PreferenceManager preferenceManager = getPreferenceManager();
preferenceManager.setPreferenceDataStore(TerminalIOPreferencesDataStore.getInstance(getContext()));

setPreferencesFromResource(R.xml.terminal_io_preferences, rootKey);
setPreferencesFromResource(R.xml.termux_terminal_io_preferences, rootKey);
}

}
Expand Down Expand Up @@ -65,9 +65,9 @@ public void putBoolean(String key, boolean value) {
public boolean getBoolean(String key, boolean defValue) {
switch (key) {
case "soft_keyboard_enabled":
return mPreferences.getSoftKeyboardEnabled();
return mPreferences.isSoftKeyboardEnabled();
case "soft_keyboard_enabled_only_if_no_hardware":
return mPreferences.getSoftKeyboardEnabledOnlyIfNoHardware();
return mPreferences.isSoftKeyboardEnabledOnlyIfNoHardware();
default:
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/termux/app/models/UserAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

public enum UserAction {

PLUGIN_EXECUTION_COMMAND("plugin execution command"),
ABOUT("about"),
CRASH_REPORT("crash report"),
PLUGIN_EXECUTION_COMMAND("plugin execution command"),
REPORT_ISSUE_FROM_TRANSCRIPT("report issue from transcript");

private final String name;
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/res/layout/preference_markdown_text.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-appcompat-release/preference/preference/res/layout/preference.xml
-->
<LinearLayout xmlns:android="http:https://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical">

<TextView android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="?android:attr/textColorPrimary" />

<include android:id="@android:id/summary" layout="@layout/markdown_adapter_node_default" />

</LinearLayout>
69 changes: 41 additions & 28 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,42 +122,55 @@
<!-- Termux Settings -->
<string name="title_activity_termux_settings">&TERMUX_APP_NAME; Settings</string>

<!-- Debugging Preferences -->
<string name="debugging_preferences">Debugging</string>
<!-- Termux App Preferences -->
<string name="termux_preferences_title">&TERMUX_APP_NAME;</string>
<string name="termux_preferences_summary">Preferences for &TERMUX_APP_NAME; app</string>

<!-- Logging Category -->
<string name="logging_header">Logging</string>
<!-- Debugging Preferences -->
<string name="termux_debugging_preferences_title">Debugging</string>
<string name="termux_debugging_preferences_summary">Preferences for debugging</string>

<!-- Terminal View Key Logging -->
<string name="terminal_view_key_logging_title">Terminal View Key Logging</string>
<string name="terminal_view_key_logging_off">Logs will not have entries for terminal view keys. (Default)</string>
<string name="terminal_view_key_logging_on">Logcat logs will have entries for terminal view keys. These are very verbose and should be disabled under normal circumstances or will cause performance issues.</string>
<!-- Logging Category -->
<string name="termux_logging_header">Logging</string>

<!-- Plugin Error Notifications -->
<string name="plugin_error_notifications_title">Plugin Error Notifications</string>
<string name="plugin_error_notifications_off">Disable flashes and notifications for plugin errors.</string>
<string name="plugin_error_notifications_on">Show flashes and notifications for plugin errors. (Default)</string>
<!-- Log Level -->
<string name="termux_log_level_title">Log Level</string>

<!-- Crash Report Notifications -->
<string name="crash_report_notifications_title">Crash Report Notifications</string>
<string name="crash_report_notifications_off">Disable notifications for crash reports.</string>
<string name="crash_report_notifications_on">Show notifications for crash reports. (Default)</string>
<!-- Terminal View Key Logging -->
<string name="termux_terminal_view_key_logging_enabled_title">Terminal View Key Logging</string>
<string name="termux_terminal_view_key_logging_enabled_off">Logs will not have entries for terminal view keys. (Default)</string>
<string name="termux_terminal_view_key_logging_enabled_on">Logcat logs will have entries for terminal view keys. These are very verbose and should be disabled under normal circumstances or will cause performance issues.</string>

<!-- Plugin Error Notifications -->
<string name="termux_plugin_error_notifications_enabled_title">Plugin Error Notifications</string>
<string name="termux_plugin_error_notifications_enabled_off">Disable flashes and notifications for plugin errors.</string>
<string name="termux_plugin_error_notifications_enabled_on">Show flashes and notifications for plugin errors. (Default)</string>

<!-- Terminal IO Preferences -->
<string name="terminal_io_preferences">Terminal I/O</string>
<!-- Crash Report Notifications -->
<string name="termux_crash_report_notifications_enabled_title">Crash Report Notifications</string>
<string name="termux_crash_report_notifications_enabled_off">Disable notifications for crash reports.</string>
<string name="termux_crash_report_notifications_enabled_on">Show notifications for crash reports. (Default)</string>

<!-- Keyboard Category -->
<string name="keyboard_header">Keyboard</string>

<!-- Soft Keyboard -->
<string name="soft_keyboard_title">Soft Keyboard Enabled</string>
<string name="soft_keyboard_off">Soft keyboard will be disabled.</string>
<string name="soft_keyboard_on">Soft keyboard will be enabled. (Default)</string>
<!-- Terminal IO Preferences -->
<string name="termux_terminal_io_preferences_title">Terminal I/O</string>
<string name="termux_terminal_io_preferences_summary">Preferences for terminal I/O</string>

<!-- Soft Keyboard Only If No Hardware-->
<string name="soft_keyboard_enabled_only_if_no_hardware_title">Soft Keyboard If No Hardware</string>
<string name="soft_keyboard_enabled_only_if_no_hardware_off">Soft keyboard will be enabled even if hardware keyboard is connected. (Default)</string>
<string name="soft_keyboard_enabled_only_if_no_hardware_on">Soft keyboard will be enabled only if no hardware keyboard is connected.</string>
<!-- Keyboard Category -->
<string name="termux_keyboard_header">Keyboard</string>

<!-- Soft Keyboard -->
<string name="termux_soft_keyboard_enabled_title">Soft Keyboard Enabled</string>
<string name="termux_soft_keyboard_enabled_off">Soft keyboard will be disabled.</string>
<string name="termux_soft_keyboard_enabled_on">Soft keyboard will be enabled. (Default)</string>

<!-- Soft Keyboard Only If No Hardware-->
<string name="termux_soft_keyboard_enabled_only_if_no_hardware_title">Soft Keyboard Only If No Hardware</string>
<string name="termux_soft_keyboard_enabled_only_if_no_hardware_off">Soft keyboard will be enabled even if hardware keyboard is connected. (Default)</string>
<string name="termux_soft_keyboard_enabled_only_if_no_hardware_on">Soft keyboard will be enabled only if no hardware keyboard is connected.</string>


<!-- About Preferences -->
<string name="about_preferences_title">About</string>

</resources>
33 changes: 0 additions & 33 deletions app/src/main/res/xml/debugging_preferences.xml

This file was deleted.

14 changes: 8 additions & 6 deletions app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<PreferenceScreen xmlns:app="http:https://schemas.android.com/apk/res-auto">

<Preference
app:title="@string/debugging_preferences"
app:summary="Preferences for debugging"
app:fragment="com.termux.app.fragments.settings.DebuggingPreferencesFragment"/>
app:key="termux"
app:title="@string/termux_preferences_title"
app:summary="@string/termux_preferences_summary"
app:fragment="com.termux.app.fragments.settings.TermuxPreferencesFragment"/>

<Preference
app:title="@string/terminal_io_preferences"
app:summary="Preferences for terminal I/O"
app:fragment="com.termux.app.fragments.settings.TerminalIOPreferencesFragment"/>
app:key="about"
app:title="@string/about_preferences_title"
app:persistent="false"/>
<!-- app:layout="@layout/preference_markdown_text" -->

</PreferenceScreen>
21 changes: 0 additions & 21 deletions app/src/main/res/xml/terminal_io_preferences.xml

This file was deleted.

33 changes: 33 additions & 0 deletions app/src/main/res/xml/termux_debugging_preferences.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<PreferenceScreen xmlns:app="http:https://schemas.android.com/apk/res-auto">

<PreferenceCategory
app:key="logging"
app:title="@string/termux_logging_header">

<ListPreference
app:defaultValue="1"
app:key="log_level"
app:title="@string/termux_log_level_title"
app:useSimpleSummaryProvider="true" />

<SwitchPreferenceCompat
app:key="terminal_view_key_logging_enabled"
app:summaryOff="@string/termux_terminal_view_key_logging_enabled_off"
app:summaryOn="@string/termux_terminal_view_key_logging_enabled_on"
app:title="@string/termux_terminal_view_key_logging_enabled_title" />

<SwitchPreferenceCompat
app:key="plugin_error_notifications_enabled"
app:summaryOff="@string/termux_plugin_error_notifications_enabled_off"
app:summaryOn="@string/termux_plugin_error_notifications_enabled_on"
app:title="@string/termux_plugin_error_notifications_enabled_title" />

<SwitchPreferenceCompat
app:key="crash_report_notifications_enabled"
app:summaryOff="@string/termux_crash_report_notifications_enabled_off"
app:summaryOn="@string/termux_crash_report_notifications_enabled_on"
app:title="@string/termux_crash_report_notifications_enabled_title" />

</PreferenceCategory>

</PreferenceScreen>
Loading

0 comments on commit d42514d

Please sign in to comment.