forked from termux/termux-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TermuxTaskerAppSharedPreferences to handle termux-tasker shared p…
…references
- Loading branch information
1 parent
9cee710
commit c9a476c
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
app/src/main/java/com/termux/app/settings/preferences/TermuxTaskerAppSharedPreferences.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,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); | ||
} | ||
|
||
} |