mirror of https://github.com/termux/termux-app
Add TermuxTaskerAppSharedPreferences to handle termux-tasker shared preferences
This commit is contained in:
parent
9cee71004f
commit
c9a476caf7
|
@ -0,0 +1,52 @@
|
||||||
|
package com.termux.app.settings.preferences;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
|
import com.termux.app.TermuxConstants;
|
||||||
|
import com.termux.app.settings.preferences.TermuxPreferenceConstants.TERMUX_TASKER_APP;
|
||||||
|
import com.termux.app.utils.DataUtils;
|
||||||
|
import com.termux.app.utils.Logger;
|
||||||
|
import com.termux.app.utils.TermuxUtils;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public class TermuxTaskerAppSharedPreferences {
|
||||||
|
|
||||||
|
private final Context mContext;
|
||||||
|
private final SharedPreferences mSharedPreferences;
|
||||||
|
private final SharedPreferences mMultiProcessSharedPreferences;
|
||||||
|
|
||||||
|
|
||||||
|
private static final String LOG_TAG = "TermuxTaskerAppSharedPreferences";
|
||||||
|
|
||||||
|
public TermuxTaskerAppSharedPreferences(@Nonnull Context context) {
|
||||||
|
// We use the default context if failed to get termux-tasker package context
|
||||||
|
mContext = DataUtils.getDefaultIfNull(TermuxUtils.getTermuxTaskerPackageContext(context), context);
|
||||||
|
mSharedPreferences = getPrivateSharedPreferences(mContext);
|
||||||
|
mMultiProcessSharedPreferences = getPrivateAndMultiProcessSharedPreferences(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SharedPreferences getPrivateSharedPreferences(Context context) {
|
||||||
|
return SharedPreferenceUtils.getPrivateSharedPreferences(context, TermuxConstants.TERMUX_TASKER_DEFAULT_PREFERENCES_FILE_BASENAME_WITHOUT_EXTENSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SharedPreferences getPrivateAndMultiProcessSharedPreferences(Context context) {
|
||||||
|
return SharedPreferenceUtils.getPrivateAndMultiProcessSharedPreferences(context, TermuxConstants.TERMUX_TASKER_DEFAULT_PREFERENCES_FILE_BASENAME_WITHOUT_EXTENSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public int getLogLevel(boolean readFromFfile) {
|
||||||
|
if(readFromFfile)
|
||||||
|
return SharedPreferenceUtils.getInt(mMultiProcessSharedPreferences, TERMUX_TASKER_APP.KEY_LOG_LEVEL, Logger.DEFAULT_LOG_LEVEL);
|
||||||
|
else
|
||||||
|
return SharedPreferenceUtils.getInt(mSharedPreferences, TERMUX_TASKER_APP.KEY_LOG_LEVEL, Logger.DEFAULT_LOG_LEVEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLogLevel(Context context, int logLevel, boolean commitToFile) {
|
||||||
|
logLevel = Logger.setLogLevel(context, logLevel);
|
||||||
|
SharedPreferenceUtils.setInt(mSharedPreferences, TERMUX_TASKER_APP.KEY_LOG_LEVEL, logLevel, commitToFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue