Skip to content

Commit a738573

Browse files
Removed unnecessary changes made by Vivek
1 parent 07e9738 commit a738573

File tree

5 files changed

+85
-60
lines changed

5 files changed

+85
-60
lines changed
Lines changed: 60 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,60 @@
1-
package com.foxdebug.acode
2-
3-
import android.content.Context
4-
import android.os.Bundle
5-
import androidx.lifecycle.lifecycleScope
6-
import com.foxdebug.acode.plugins.NativeLayer
7-
import com.getcapacitor.BridgeActivity
8-
import kotlinx.coroutines.CoroutineScope
9-
import java.lang.ref.WeakReference
10-
11-
12-
class MainActivity : BridgeActivity(){
13-
14-
companion object{
15-
private var activityRef: WeakReference<MainActivity?>? = WeakReference(null)
16-
fun getActivityContext(): Context?{
17-
return activityRef?.get()
18-
}
19-
20-
val lifeCycleScope: CoroutineScope get() {
21-
val scope = activityRef?.get()?.lifecycleScope
22-
return if (scope == null){
23-
throw IllegalStateException("Activity is not available")
24-
}else{
25-
scope
26-
}
27-
}
28-
29-
}
30-
31-
override fun onCreate(savedInstanceState: Bundle?) {
32-
//register plugins before calling super
33-
registerPlugin(NativeLayer::class.java)
34-
35-
36-
super.onCreate(savedInstanceState)
37-
activityRef = WeakReference(this)
38-
}
39-
40-
override fun onDestroy() {
41-
super.onDestroy()
42-
activityRef = WeakReference(null)
43-
activityRef = null
44-
}
45-
}
1+
package com.foxdebug.acode
2+
3+
import android.content.Context
4+
import android.os.Build
5+
import android.os.Bundle
6+
import androidx.core.view.ViewCompat
7+
import androidx.core.view.WindowInsetsCompat
8+
import androidx.lifecycle.lifecycleScope
9+
import com.foxdebug.acode.plugins.NativeLayer
10+
import com.getcapacitor.BridgeActivity
11+
import kotlinx.coroutines.CoroutineScope
12+
import java.lang.ref.WeakReference
13+
14+
15+
class MainActivity : BridgeActivity() {
16+
17+
companion object {
18+
private var activityRef: WeakReference<MainActivity?>? = WeakReference(null)
19+
20+
fun getActivityContext(): Context? {
21+
return activityRef?.get()
22+
}
23+
24+
val lifeCycleScope: CoroutineScope
25+
get() {
26+
return activityRef?.get()?.lifecycleScope ?: throw IllegalStateException("Activity is not available")
27+
}
28+
}
29+
30+
override fun onCreate(savedInstanceState: Bundle?) {
31+
//register plugins before calling super
32+
registerPlugin(NativeLayer::class.java)
33+
34+
super.onCreate(savedInstanceState)
35+
activityRef = WeakReference(this)
36+
37+
// only apply insets for android 13+
38+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
39+
ViewCompat.setOnApplyWindowInsetsListener(window.decorView) { v, insets ->
40+
val systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
41+
val imeInsets = insets.getInsets(WindowInsetsCompat.Type.ime())
42+
val isImeVisible = insets.isVisible(WindowInsetsCompat.Type.ime())
43+
44+
v.setPadding(
45+
systemBarsInsets.left,
46+
systemBarsInsets.top,
47+
systemBarsInsets.right,
48+
if (isImeVisible) imeInsets.bottom else systemBarsInsets.bottom
49+
)
50+
insets
51+
}
52+
}
53+
}
54+
55+
override fun onDestroy() {
56+
super.onDestroy()
57+
activityRef = WeakReference(null)
58+
activityRef = null
59+
}
60+
}

android/app/src/main/java/com/foxdebug/acode/plugins/NativeLayer.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ class NativeLayer : Plugin() {
2727
* Upon clicking "OK", the dialog will resolve the call.
2828
*/
2929
@PluginMethod
30-
fun showDialog(call: PluginCall) = with(call){
31-
autoRejectOnError(onFailure = {}){
32-
existsNot("title"){
30+
fun showDialog(call: PluginCall) = with(call) {
31+
autoRejectOnError(onFailure = {}) {
32+
existsNot("title") {
3333
return@with
3434
}
35-
existsNot("message"){
35+
existsNot("message") {
3636
return@with
3737
}
3838

@@ -48,7 +48,7 @@ class NativeLayer : Plugin() {
4848
AlertDialog.Builder(context).apply {
4949
setTitle(title)
5050
setMessage(message)
51-
setPositiveButton("OK",null)
51+
setPositiveButton("OK", null)
5252
show()
5353
}
5454
call.resolve()
@@ -84,7 +84,7 @@ class NativeLayer : Plugin() {
8484
*/
8585
@PluginMethod
8686
fun launchIntent(call: PluginCall) {
87-
call.autoRejectOnError(onFailure = {}){
87+
call.autoRejectOnError(onFailure = {}) {
8888
val constructorNumber = call.getInt("constructor_number") ?: run {
8989
call.reject("Missing 'constructor_number'")
9090
return

src/lang/zh-cn.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,5 +392,5 @@
392392
"notifications": "消息通知",
393393
"no_unread_notifications": "没有未读消息",
394394
"should_use_current_file_for_preview": "应使当前文件用于预览页面而非使用默认文件 (index.html)",
395-
"fade fold widgets": "Fade Fold Widgets"
395+
"fade fold widgets": "淡入淡出代码折叠按钮"
396396
}

src/lang/zh-hant.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,5 +392,5 @@
392392
"notifications": "消息通知",
393393
"no_unread_notifications": "沒有未讀消息",
394394
"should_use_current_file_for_preview": "應使當前文件用於預覽頁面而非使用默認文件 (index.html)",
395-
"fade fold widgets": "Fade Fold Widgets"
395+
"fade fold widgets": "淡入淡出代碼折疊按鈕"
396396
}

src/lib/run.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,22 @@ async function run(
507507
});
508508
}
509509

510+
function makeUriAbsoluteIfNeeded(uri) {
511+
const termuxRootEncoded =
512+
"content://com.termux.documents/tree/%2Fdata%2Fdata%2Fcom.termux%2Ffiles%2Fhome";
513+
const termuxRootDecoded = "/data/data/com.termux/files/home";
514+
515+
if (uri.startsWith(termuxRootEncoded)) {
516+
// Extract subpath after `::` if already absolute
517+
if (uri.includes("::")) return uri;
518+
519+
const decodedPath = decodeURIComponent(uri.split("tree/")[1] || "");
520+
return `${termuxRootEncoded}::${decodedPath}/`;
521+
}
522+
523+
return uri;
524+
}
525+
510526
function getRelativePath() {
511527
// Get the project url
512528
const projectFolder = addedFolder[0];
@@ -518,13 +534,7 @@ async function run(
518534
}
519535

520536
//make the uri absolute if necessary
521-
if (
522-
rootFolder ===
523-
"content://com.termux.documents/tree/%2Fdata%2Fdata%2Fcom.termux%2Ffiles%2Fhome"
524-
) {
525-
rootFolder =
526-
"content://com.termux.documents/tree/%2Fdata%2Fdata%2Fcom.termux%2Ffiles%2Fhome::/data/data/com.termux/files/home/";
527-
}
537+
rootFolder = makeUriAbsoluteIfNeeded(rootFolder);
528538

529539
console.log("rootFolder", rootFolder);
530540
console.log("pathName", pathName);

0 commit comments

Comments
 (0)