-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for setting Termux:Tasker log level from TermuxSettings
- Loading branch information
1 parent
6de3713
commit 339b2a2
Showing
10 changed files
with
239 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
app/src/main/java/com/termux/app/fragments/settings/TermuxTaskerPreferencesFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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.TermuxTaskerAppSharedPreferences; | ||
|
||
@Keep | ||
public class TermuxTaskerPreferencesFragment extends PreferenceFragmentCompat { | ||
|
||
@Override | ||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { | ||
Context context = getContext(); | ||
if (context == null) return; | ||
|
||
PreferenceManager preferenceManager = getPreferenceManager(); | ||
preferenceManager.setPreferenceDataStore(TermuxTaskerPreferencesDataStore.getInstance(context)); | ||
|
||
setPreferencesFromResource(R.xml.termux_tasker_preferences, rootKey); | ||
} | ||
|
||
} | ||
|
||
class TermuxTaskerPreferencesDataStore extends PreferenceDataStore { | ||
|
||
private final Context mContext; | ||
private final TermuxTaskerAppSharedPreferences mPreferences; | ||
|
||
private static TermuxTaskerPreferencesDataStore mInstance; | ||
|
||
private TermuxTaskerPreferencesDataStore(Context context) { | ||
mContext = context; | ||
mPreferences = TermuxTaskerAppSharedPreferences.build(context, true); | ||
} | ||
|
||
public static synchronized TermuxTaskerPreferencesDataStore getInstance(Context context) { | ||
if (mInstance == null) { | ||
mInstance = new TermuxTaskerPreferencesDataStore(context); | ||
} | ||
return mInstance; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...in/java/com/termux/app/fragments/settings/termux_tasker/DebuggingPreferencesFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.termux.app.fragments.settings.termux_tasker; | ||
|
||
import android.content.Context; | ||
import android.os.Bundle; | ||
|
||
import androidx.annotation.Keep; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.preference.ListPreference; | ||
import androidx.preference.PreferenceCategory; | ||
import androidx.preference.PreferenceDataStore; | ||
import androidx.preference.PreferenceFragmentCompat; | ||
import androidx.preference.PreferenceManager; | ||
|
||
import com.termux.R; | ||
import com.termux.shared.settings.preferences.TermuxTaskerAppSharedPreferences; | ||
|
||
@Keep | ||
public class DebuggingPreferencesFragment extends PreferenceFragmentCompat { | ||
|
||
@Override | ||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { | ||
Context context = getContext(); | ||
if (context == null) return; | ||
|
||
PreferenceManager preferenceManager = getPreferenceManager(); | ||
preferenceManager.setPreferenceDataStore(DebuggingPreferencesDataStore.getInstance(context)); | ||
|
||
setPreferencesFromResource(R.xml.termux_tasker_debugging_preferences, rootKey); | ||
|
||
configureLoggingPreferences(context); | ||
} | ||
|
||
private void configureLoggingPreferences(@NonNull Context context) { | ||
PreferenceCategory loggingCategory = findPreference("logging"); | ||
if (loggingCategory == null) return; | ||
|
||
ListPreference logLevelListPreference = findPreference("log_level"); | ||
if (logLevelListPreference != null) { | ||
TermuxTaskerAppSharedPreferences preferences = TermuxTaskerAppSharedPreferences.build(context, true); | ||
if (preferences == null) return; | ||
|
||
com.termux.app.fragments.settings.termux.DebuggingPreferencesFragment. | ||
setLogLevelListPreferenceData(logLevelListPreference, context, preferences.getLogLevel(true)); | ||
loggingCategory.addPreference(logLevelListPreference); | ||
} | ||
} | ||
} | ||
|
||
class DebuggingPreferencesDataStore extends PreferenceDataStore { | ||
|
||
private final Context mContext; | ||
private final TermuxTaskerAppSharedPreferences mPreferences; | ||
|
||
private static DebuggingPreferencesDataStore mInstance; | ||
|
||
private DebuggingPreferencesDataStore(Context context) { | ||
mContext = context; | ||
mPreferences = TermuxTaskerAppSharedPreferences.build(context, true); | ||
} | ||
|
||
public static synchronized DebuggingPreferencesDataStore getInstance(Context context) { | ||
if (mInstance == null) { | ||
mInstance = new DebuggingPreferencesDataStore(context); | ||
} | ||
return mInstance; | ||
} | ||
|
||
|
||
|
||
@Override | ||
@Nullable | ||
public String getString(String key, @Nullable String defValue) { | ||
if (mPreferences == null) return null; | ||
if (key == null) return null; | ||
|
||
switch (key) { | ||
case "log_level": | ||
return String.valueOf(mPreferences.getLogLevel(true)); | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public void putString(String key, @Nullable String value) { | ||
if (mPreferences == null) return; | ||
if (key == null) return; | ||
|
||
switch (key) { | ||
case "log_level": | ||
if (value != null) { | ||
mPreferences.setLogLevel(mContext, Integer.parseInt(value), true); | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
app/src/main/res/xml/termux_tasker_debugging_preferences.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<PreferenceScreen xmlns:app="http://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" /> | ||
|
||
</PreferenceCategory> | ||
|
||
</PreferenceScreen> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<Preference | ||
app:title="@string/termux_debugging_preferences_title" | ||
app:summary="@string/termux_debugging_preferences_summary" | ||
app:fragment="com.termux.app.fragments.settings.termux_tasker.DebuggingPreferencesFragment"/> | ||
|
||
</PreferenceScreen> |