Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

added power setting #91

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.kolserdav.ana"
minSdk 21
targetSdk 33
versionCode 135
versionName "1.35"
versionCode 136
versionName "1.36"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
13 changes: 12 additions & 1 deletion android/app/src/main/java/com/kolserdav/ana/Config.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.kolserdav.ana;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;

import java.net.Socket;
import java.security.cert.X509Certificate;

Expand All @@ -15,6 +18,8 @@ class AppInterface {
// Push notifications server
String wsAddress = null;

Boolean notStopWeb = false;

public AppInterface() {

}
Expand All @@ -27,7 +32,7 @@ public class Config {
// Dependency packages/app/types/interfaces.ts.CHECK_URL_PATH
public static final String CHECK_URL_PATH = "/api/check";

public static final Integer DATABASE_VERSION = 30;
public static final Integer DATABASE_VERSION = 33;

public static final String DATABASE_NAME = "db";

Expand All @@ -41,7 +46,13 @@ public class Config {

public static final int WS_RECONNECT_TIMEOUT = 3000;

// Dependency packages/app/utils/constants.ts.ANDROID_NOT_STOP_WEB_DEFAULT
public static final Boolean NOT_STOP_WEB_DEFAULT = true;

@SuppressLint("CustomX509TrustManager")
@TargetApi(24)
public static final TrustManager[] TRUST_ALL_CERTS = new TrustManager[]{

new X509ExtendedTrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType, Socket socket) {}
public void checkServerTrusted(X509Certificate[] chain, String authType, Socket socket) {}
Expand Down
63 changes: 40 additions & 23 deletions android/app/src/main/java/com/kolserdav/ana/DB.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class App extends Table {

public static final String APP_COLUMN_WS_ADDRESS = "wsAddress";

public static final String APP_COLUMN_NOT_STOP_WEB = "notStopWeb";

private static final String TAG = "App";

public App(SQLiteDatabase db) {
Expand All @@ -45,15 +47,17 @@ public App(SQLiteDatabase db) {
APP_COLUMN_URL,
APP_COLUMN_URL_DEFAULT,
APP_COLUMN_PATH,
APP_COLUMN_WS_ADDRESS
APP_COLUMN_WS_ADDRESS,
APP_COLUMN_NOT_STOP_WEB
});
}

public void onCreate() {
db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" +
APP_COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
APP_COLUMN_URL + " TEXT, " + APP_COLUMN_URL_DEFAULT + " TEXT, " +
APP_COLUMN_PATH + " TEXT, " + APP_COLUMN_WS_ADDRESS + " TEXT" + ")");
APP_COLUMN_PATH + " TEXT, " + APP_COLUMN_WS_ADDRESS + " TEXT, " +
APP_COLUMN_NOT_STOP_WEB + " BOOL" + ")");
}

public void setUrl(AppInterface options) {
Expand All @@ -75,49 +79,61 @@ public void drop() {
}

public void setPath(AppInterface options) {
Log.d("INFO", "Update path " + options.path + " with id " + options.id);
Log.d(TAG, "Update path " + options.path + " with id " + options.id);
db.execSQL("UPDATE " + TABLE_NAME +
" SET " + APP_COLUMN_PATH + "='" + options.path + "'" +
" WHERE " + APP_COLUMN_ID + "=" + options.id);
}

public void setNotStopWeb(AppInterface options) {
Log.d(TAG, "Update not stop web " + options.notStopWeb + " with id " + options.id);
db.execSQL("UPDATE " + TABLE_NAME +
" SET " + APP_COLUMN_NOT_STOP_WEB + "='" + options.notStopWeb + "'" +
" WHERE " + APP_COLUMN_ID + "=" + options.id);
}

public void setWSAddress(AppInterface options) {
Log.d("INFO", "Update WS address " + options.wsAddress + " with id " + options.id);
Log.d(TAG, "Update WS address " + options.wsAddress + " with id " + options.id);
db.execSQL("UPDATE " + TABLE_NAME +
" SET " + APP_COLUMN_WS_ADDRESS + "='" + options.wsAddress + "'" +
" WHERE " + APP_COLUMN_ID + "=" + options.id);
}

public AppInterface init() {
// String selection = APP_COLUMN_ID + "=?";
// String[] selectionArgs = {"%" + id + "%"};
/**
* String selection = APP_COLUMN_ID + "=?";
* String[] selectionArgs = {"%" + id + "%"};
*/

AppInterface options = new AppInterface();
Cursor cursor = db.query(
TABLE_NAME,
projections,
null,
null,
null,
null,
null
TABLE_NAME,
projections,
null,
null,
null,
null,
null
);
int count = cursor.getCount();
if (count == 0) {
db.execSQL(
"INSERT INTO " + TABLE_NAME +
" (" +
APP_COLUMN_ID + ", " +
APP_COLUMN_URL + ", " +
APP_COLUMN_URL_DEFAULT + ", " +
APP_COLUMN_PATH + ", " +
APP_COLUMN_WS_ADDRESS + ") " +
"VALUES" +
" (" +
"INSERT INTO " + TABLE_NAME +
" (" +
APP_COLUMN_ID + ", " +
APP_COLUMN_URL + ", " +
APP_COLUMN_URL_DEFAULT + ", " +
APP_COLUMN_PATH + ", " +
APP_COLUMN_WS_ADDRESS + ", " +
APP_COLUMN_NOT_STOP_WEB + ") " +
"VALUES" +
" (" +
options.id + ", '" +
options.url + "', '" +
options.urlDefault + "', '" +
options.path + "', '" +
options.wsAddress + "')"
options.wsAddress + "', '" +
options.notStopWeb + "')"
);
return init();
}
Expand All @@ -132,6 +148,7 @@ public AppInterface init() {
schema.urlDefault = cursor.getString(getAppColumnIndex(APP_COLUMN_URL_DEFAULT));
schema.path = cursor.getString(getAppColumnIndex(APP_COLUMN_PATH));
schema.wsAddress = cursor.getString(getAppColumnIndex(APP_COLUMN_WS_ADDRESS));
schema.notStopWeb = cursor.getString(getAppColumnIndex(APP_COLUMN_NOT_STOP_WEB)).equals("true");
}
return schema;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,26 @@ public void run() {
});
}

@JavascriptInterface
public void setNotStopWeb(final String value) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
AppInterface schemaApp = main.db.app.init();
Log.d(TAG, "Not stop web changed to " + value + " (" + schemaApp.notStopWeb + ")");
schemaApp.notStopWeb = value.equals("true");
main.db.app.setNotStopWeb(schemaApp);
}
});
}

@JavascriptInterface
public String getNotStopWeb() {
AppInterface app = main.db.app.init();
main.notStopWeb = app.notStopWeb;
return main.notStopWeb ? "true" : "false";
}

@JavascriptInterface
public void setUrl(String url) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
Expand Down
33 changes: 25 additions & 8 deletions android/app/src/main/java/com/kolserdav/ana/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ public class MainActivity extends Activity {

private WebSettings webSettings;

public Boolean notStopWeb = Config.NOT_STOP_WEB_DEFAULT;

AndroidCommon androidCommon;


@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Expand Down Expand Up @@ -112,6 +115,8 @@ public void onCreate(Bundle savedInstanceState) {
webSettings.setDisplayZoomControls(false);
webSettings.setSupportZoom(false);



setCacheMode();

webSettings.setDefaultTextEncodingName("utf-8");
Expand Down Expand Up @@ -192,14 +197,14 @@ protected void onPostExecute(String response) {
try {
data = new JSONObject(response);
} catch (JSONException e) {
Log.e(TAG, "Error parse JSON: " + e.getMessage());
Log.e(TAG, "Failed parse JSON: " + e.getMessage());
}
if (data != null) {
Object wsAddress = null;
try {
wsAddress = data.get("data");
} catch (JSONException e) {
Log.e(TAG, "Error get WS address from JSON: " + e.getMessage());
Log.e(TAG, "Failed get WS address from JSON: " + e.getMessage());
}
Log.d(TAG, "WS server is: " + wsAddress);
if (wsAddress != null) {
Expand All @@ -220,10 +225,10 @@ protected void onPostExecute(String response) {
}.execute().get();

} catch (ExecutionException e) {
Log.e(TAG, "Error request E " + e.getMessage());
Log.e(TAG, "Failed request E " + e.getMessage());
}
} catch (InterruptedException e) {
Log.e(TAG, "Error request I " + e.getMessage());
Log.e(TAG, "Failed request I " + e.getMessage());
}
}
};
Expand All @@ -232,9 +237,18 @@ protected void onPostExecute(String response) {
}

private void openScreenDev() {
if (Settings.Secure.getInt(this.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED , 0) == 1) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
/**
if (isDevMode()) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
*/
}

private boolean isDevMode() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return Settings.Secure.getInt(context.getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
} else {
return Settings.Secure.getInt(context.getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1) != 0;
}
}

Expand Down Expand Up @@ -331,9 +345,12 @@ public boolean onKeyDown(final int keyCode, final KeyEvent event) {
}

public void closeApp() {
Log.d(TAG, "Close app with notStopWeb: " + notStopWeb);
finishAffinity();
finish();
destroyWebView();
if (!notStopWeb) {
destroyWebView();
}
}

public void destroyWebView() {
Expand Down
2 changes: 2 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/136.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Create performance settings
- Fixed some bugs
58 changes: 58 additions & 0 deletions packages/app/components/Settings.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,22 @@ export const useChangeNode = ({
const [node, setNode] = useState(url || '');
const [nodeError, setNodeError] = useState('');
const [nodeSuccess, setNodeSuccess] = useState(false);
const [oldSuccessCustomNode, setOldSuccessCustomNode] = useState<string | null>(null);

/**
* Set old success custom node
*/
useEffect(() => {
const _oldSuccessCustomNode = getLocalStorage(LocalStorageName.LAST_SUCCESS_CUSTOM_NODE);
setOldSuccessCustomNode(_oldSuccessCustomNode);
}, []);

const onClickOldSuccessCustomNode = () => {
if (!oldSuccessCustomNode) {
return;
}
setNode(oldSuccessCustomNode);
};

const onChangeRadioWrapper = useCallback(
(name: 'url' | 'urlDefault') => (e: React.ChangeEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -589,6 +605,8 @@ export const useChangeNode = ({
}
androidCommon.setUrl(value);
}
setLocalStorage(LocalStorageName.LAST_SUCCESS_CUSTOM_NODE, value);
setOldSuccessCustomNode(value);
setNodeSuccess(true);
} else {
log('error', serverIsNotRespond, { result });
Expand Down Expand Up @@ -624,6 +642,8 @@ export const useChangeNode = ({
isNode,
nodeError,
nodeSuccess,
oldSuccessCustomNode,
onClickOldSuccessCustomNode,
};
};

Expand All @@ -647,3 +667,41 @@ export const useListenFocus = () => {
};
}, []);
};

export const useNotStopWeb = ({ needUpdateApp }: { needUpdateApp: string }) => {
const [notStopWeb, setNotStopWeb] = useState<boolean>();

const changeNotStopWeb = () => {
if (notStopWeb === undefined) {
return;
}
const _notStopWeb = !notStopWeb;
setNotStopWeb(_notStopWeb);

if (typeof androidCommon === 'undefined') {
return;
}
if (!androidCommon.setNotStopWeb) {
log('warn', needUpdateApp, {}, true);
return;
}
androidCommon.setNotStopWeb(_notStopWeb ? 'true' : 'false');
};

/**
* Set not stop web
*/
useEffect(() => {
if (typeof androidCommon === 'undefined') {
return;
}
if (!androidCommon.getNotStopWeb) {
log('warn', needUpdateApp, {}, true);
return;
}

setNotStopWeb(androidCommon.getNotStopWeb() === 'true');
}, [needUpdateApp, notStopWeb]);

return { setNotStopWeb: changeNotStopWeb, notStopWeb };
};
Loading
Loading