Skip to content
Open
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ autopush.sh
/server
local.properties

# personal ideas
current-idea.md

#
information/
.gitignore

# Crowdin
crowdin.properties
.idea/crowdin_settings.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ fun Project.loadSigningProperties(): SigningConfig? {
localFile.inputStream().use { load(it) }
}

val storeFile = props.getProperty("signing.storeFile") ?: return null
val storePassword = props.getProperty("signing.storePassword") ?: return null
val keyAlias = props.getProperty("signing.keyAlias") ?: return null
val keyPassword = props.getProperty("signing.keyPassword") ?: return null
val storeFile = props.getProperty("signing.storeFile")?.takeIf { it.isNotBlank() } ?: return null
val storePassword = props.getProperty("signing.storePassword")?.takeIf { it.isNotBlank() } ?: return null
val keyAlias = props.getProperty("signing.keyAlias")?.takeIf { it.isNotBlank() } ?: return null
val keyPassword = props.getProperty("signing.keyPassword")?.takeIf { it.isNotBlank() } ?: return null

return SigningConfig(storeFile, storePassword, keyAlias, keyPassword)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class SigningConfigPlugin : Plugin<Project> {
val envKeyPassword = System.getenv("SIGNING_KEY_PASSWORD")
val envKeyAlias = System.getenv("SIGNING_KEY_ALIAS") ?: "AndroidCS"

if (envStorePassword != null && envKeyPassword != null) {
if (!envStorePassword.isNullOrBlank() && !envKeyPassword.isNullOrBlank()) {
return SigningConfig(
storeFile = envStoreFile,
storePassword = envStorePassword,
Expand All @@ -82,7 +82,7 @@ class SigningConfigPlugin : Plugin<Project> {
val gradleKeyPassword = findProperty("signingKeyPassword") as? String
val gradleKeyAlias = findProperty("signingKeyAlias") as? String ?: "AndroidCS"

if (gradleStorePassword != null && gradleKeyPassword != null) {
if (!gradleStorePassword.isNullOrBlank() && !gradleKeyPassword.isNullOrBlank()) {
return SigningConfig(
storeFile = gradleStoreFile,
storePassword = gradleStorePassword,
Expand Down
72 changes: 60 additions & 12 deletions core/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.tom.rv2ide.build.config.BuildConfig
import com.tom.rv2ide.desugaring.utils.JavaIOReplacements.applyJavaIOReplacements
import com.tom.rv2ide.plugins.AndroidIDEAssetsPlugin
import java.security.KeyStore
import java.util.Properties

plugins {
Expand Down Expand Up @@ -74,19 +75,62 @@ android {
experimentalProperties["android.experimental.enableGlobalSynthetics"] = true


val localProps = Properties().apply {
val file = rootProject.file("local.properties")
if (file.exists()) {
file.inputStream().use { load(it) }
}
}
val signingStorePassword =
System.getProperty("SIGNING_STORE_PASSWORD")?.takeIf { it.isNotBlank() }
?: System.getenv("SIGNING_STORE_PASSWORD")?.takeIf { it.isNotBlank() }
?: localProps.getProperty("signing.storePassword")?.takeIf { it.isNotBlank() }
val signingKeyPassword =
System.getProperty("SIGNING_KEY_PASSWORD")?.takeIf { it.isNotBlank() }
?: System.getenv("SIGNING_KEY_PASSWORD")?.takeIf { it.isNotBlank() }
?: localProps.getProperty("signing.keyPassword")?.takeIf { it.isNotBlank() }
val customKeyStoreFile =
localProps.getProperty("signing.storeFile")
?.takeIf { it.isNotBlank() }
?.let { rootProject.file(it) }
?: rootProject.file("signing/signing-key.jks")
val customKeyAlias =
localProps.getProperty("signing.keyAlias")?.takeIf { it.isNotBlank() } ?: "androidcs"
val hasCustomSigning =
if (customKeyStoreFile.exists() &&
!signingStorePassword.isNullOrBlank() &&
!signingKeyPassword.isNullOrBlank()
) {
try {
val ks = KeyStore.getInstance(customKeyStoreFile, signingStorePassword.toCharArray())
val key = ks.getKey(customKeyAlias, signingKeyPassword.toCharArray())
if (key == null) {
logger.warn(
"Key alias '$customKeyAlias' not found in ${customKeyStoreFile.name}; falling back to debug signing."
)
false
} else {
true
}
} catch (e: Exception) {
logger.warn(
"Custom keystore ${customKeyStoreFile.name} rejected configured password (${e.message}); falling back to debug signing."
)
false
}
} else {
false
}

signingConfigs {
if (hasCustomSigning) {
create("custom") {
val keyStorePath = "${rootProject.projectDir}/signing/signing-key.jks"
val keyStoreFile = file(keyStorePath)

val signing_storePassword = System.getProperty("SIGNING_STORE_PASSWORD") ?: ""
val signing_keyPassword = System.getProperty("SIGNING_KEY_PASSWORD") ?: ""

storeFile = keyStoreFile
storePassword = signing_storePassword
keyAlias = "androidcs"
keyPassword = signing_keyPassword
storeFile = customKeyStoreFile
storePassword = signingStorePassword
keyAlias = customKeyAlias
keyPassword = signingKeyPassword
}
}
}

androidResources { generateLocaleConfig = true }
Expand All @@ -96,14 +140,18 @@ android {
dataBinding = true
}

val resolvedSigning =
if (hasCustomSigning) signingConfigs.getByName("custom")
else signingConfigs.getByName("debug")

buildTypes {
debug {
signingConfig = signingConfigs.getByName("custom")
signingConfig = resolvedSigning
}

release {
isShrinkResources = false
signingConfig = signingConfigs.getByName("custom")
signingConfig = resolvedSigning
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ import androidx.activity.viewModels
import androidx.core.content.ContextCompat
import com.tom.rv2ide.R
import com.tom.rv2ide.app.EdgeToEdgeIDEActivity
import com.tom.rv2ide.fragments.FileBrowserFragment
import com.tom.rv2ide.utils.FileBrowserNavigationHelper
import com.tom.rv2ide.viewmodel.MainViewModel
import com.tom.rv2ide.viewmodel.MainViewModel.Companion.SCREEN_MAIN
import com.tom.rv2ide.fragments.FileBrowserFragment

/**
* @author Mohammed-baqer-null @ https://github.com/Mohammed-baqer-null
Expand All @@ -45,21 +46,23 @@ class FileBrowserActivity : EdgeToEdgeIDEActivity() {

private val requestPermissionLauncher =
registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted: Boolean ->
if (isGranted) {
loadFileBrowserFragment()
} else {
Toast.makeText(this, "Permission denied to read storage", Toast.LENGTH_SHORT).show()
if (!isGranted) {
Toast.makeText(
this,
"Shared storage permission denied; private app storage remains accessible.",
Toast.LENGTH_SHORT
).show()
}
}

private val manageStoragePermissionLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (Environment.isExternalStorageManager()) {
loadFileBrowserFragment()
} else {
Toast.makeText(this, "Permission denied to manage storage", Toast.LENGTH_SHORT).show()
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !Environment.isExternalStorageManager()) {
Toast.makeText(
this,
"All files access not granted; private app storage remains accessible.",
Toast.LENGTH_SHORT
).show()
}
}

Expand All @@ -68,36 +71,35 @@ class FileBrowserActivity : EdgeToEdgeIDEActivity() {

viewModel.setScreen(SCREEN_MAIN)

checkAndRequestPermissions()
// Always open the file browser so $HOME and root navigation work even without external storage access
loadFileBrowserFragment()
checkAndRequestPermissionsIfNeeded()
}

private fun checkAndRequestPermissions() {
private fun checkAndRequestPermissionsIfNeeded() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (Environment.isExternalStorageManager()) {
loadFileBrowserFragment()
} else {
val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
val uri = Uri.fromParts("package", packageName, null)
intent.data = uri
manageStoragePermissionLauncher.launch(intent)
}
} else {
when {
ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) ==
PackageManager.PERMISSION_GRANTED -> {
loadFileBrowserFragment()
}
else -> {
requestPermissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE)
if (!Environment.isExternalStorageManager()) {
runCatching {
val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION).apply {
data = Uri.fromParts("package", packageName, null)
}
manageStoragePermissionLauncher.launch(intent)
}
}
} else if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED
) {
requestPermissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE)
}
}

private fun loadFileBrowserFragment() {
if (supportFragmentManager.findFragmentById(R.id.fragment_container) == null) {
supportFragmentManager.beginTransaction()
.replace(R.id.fragment_container, FileBrowserFragment.newInstance())
.replace(
R.id.fragment_container,
FileBrowserFragment.newInstance(FileBrowserNavigationHelper.defaultStartPath())
)
.commit()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ package com.tom.rv2ide.activities.IdeConfigurations.net
/** * @author Mohammed-baqer-null @ https://github.com/Mohammed-baqer-null */
import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkCapabilities

fun isOnline(context: Context): Boolean {
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
return cm.activeNetworkInfo?.isConnected == true
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager
?: return false
val network = cm.activeNetwork ?: return false
val capabilities = cm.getNetworkCapabilities(network) ?: return false
return capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding
import androidx.core.view.updatePaddingRelative
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.blankj.utilcode.constant.MemoryConstants
import com.blankj.utilcode.util.ConvertUtils.byte2MemorySize
import com.blankj.utilcode.util.FileUtils
Expand Down Expand Up @@ -126,7 +128,10 @@ import kotlin.math.roundToInt
import kotlin.math.roundToLong
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -741,27 +746,44 @@ override fun onApplySystemBarInsets(insets: Insets) {
}

if (BuildPreferences.isKtIndexingNotificationEnabled) {
// Use IndexingBanner to show progress
val indexingBanner = IndexingBanner(this)

lifecycleScope.launch {
LogStream.outputFlow.collect { logMessage ->
if (Index.isIndexing() && !Initialization.isProjectInitializing.value) {
indexingBanner.updateMessage(logMessage)
}
}
}

var dismissedForSession = false
indexingBanner.setOnDismissListener { dismissedForSession = true }

lifecycleScope.launch {
combine(
Initialization.isProjectInitializing,
Index.isProjectIndexing
) { isInitializing, isIndexing ->
!isInitializing && isIndexing
}.collect { shouldShowIndexing ->
if (shouldShowIndexing) {
indexingBanner.show()
} else {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
try {
coroutineScope {
launch {
LogStream.outputFlow.collect { logMessage ->
if (Index.isIndexing() && !Initialization.isProjectInitializing.value) {
indexingBanner.updateMessage(logMessage)
}
}
}

// Debounce state transitions so rapid per-file/module LSP updates don't strobe the banner
combine(
Initialization.isProjectInitializing,
Index.isProjectIndexing,
) { isInitializing, isIndexing ->
!isInitializing && isIndexing
}
.distinctUntilChanged()
.collectLatest { shouldShowIndexing ->
if (shouldShowIndexing) {
delay(350)
if (!dismissedForSession) {
indexingBanner.show()
}
} else {
delay(1200)
dismissedForSession = false
indexingBanner.hide()
}
}
}
} finally {
indexingBanner.hide()
}
}
Expand Down Expand Up @@ -1161,34 +1183,6 @@ override fun onApplySystemBarInsets(insets: Insets) {
return filesTreeFragment
}

private fun hasNativeFiles(projectRoot: File): Boolean {
val androidMkFile = File(projectRoot, "src/main/jni/Android.mk")
val cmakeListsFile = File(projectRoot, "src/main/jni/CMakeLists.txt")
return androidMkFile.exists() || cmakeListsFile.exists()
}

private fun isNdkInstalled(): Boolean {
val ndkBuildFile = File(Environment.ANDROID_HOME, "ndk/28.2.13676358/ndk-build")
return ndkBuildFile.exists()
}

private fun showNdkNotInstalledDialog(context: Context, onDismiss: () -> Unit = {}) {
MaterialAlertDialogBuilder(context)
.setTitle("NDK Not Found")
.setMessage(
"A compatible NDK (version 28.2.13676358) is not installed.\n\n" +
"Native code features will be disabled for this project.\n\n" +
"To enable native development, please install NDK version 28.2.13676358 " +
"open a terminal then run: 'idesetup -y -c -wn'."
)
.setPositiveButton("OK") { dialog, _ ->
dialog.dismiss()
onDismiss()
}
.setCancelable(false)
.show()
}

fun doSetStatus(text: CharSequence, @GravityInt gravity: Int) {
editorViewModel.statusText = text
editorViewModel.statusGravity = gravity
Expand Down
Loading