mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix: configure Dagger Hilt for DI
This commit is contained in:
@@ -13,6 +13,7 @@ plugins {
|
||||
id("realm-android")
|
||||
id("androidx.navigation.safeargs.kotlin")
|
||||
id("com.itsaky.androidide.desugaring")
|
||||
id("com.google.dagger.hilt.android")
|
||||
}
|
||||
|
||||
apply {
|
||||
@@ -59,6 +60,8 @@ kapt {
|
||||
arguments {
|
||||
arg("eventBusIndex", "${BuildConfig.packageName}.events.AppEventsIndex")
|
||||
}
|
||||
|
||||
correctErrorTypes = true
|
||||
}
|
||||
|
||||
desugaring {
|
||||
@@ -77,6 +80,7 @@ dependencies {
|
||||
// Annotation processors
|
||||
kapt(libs.common.glide.ap)
|
||||
kapt(libs.google.auto.service)
|
||||
kapt(libs.hilt.compiler)
|
||||
kapt(projects.annotation.processors)
|
||||
|
||||
implementation(libs.common.editor)
|
||||
@@ -93,6 +97,8 @@ dependencies {
|
||||
implementation(libs.google.gson)
|
||||
implementation(libs.google.guava)
|
||||
|
||||
implementation(libs.hilt.android)
|
||||
|
||||
// Git
|
||||
implementation(libs.git.jgit)
|
||||
|
||||
|
||||
@@ -102,6 +102,7 @@ import com.itsaky.androidide.viewmodel.EditorViewModel
|
||||
import com.itsaky.androidide.xml.resources.ResourceTableRegistry
|
||||
import com.itsaky.androidide.xml.versions.ApiVersionsRegistry
|
||||
import com.itsaky.androidide.xml.widgets.WidgetTableRegistry
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
@@ -118,6 +119,7 @@ import kotlin.math.roundToLong
|
||||
* @author Akash Yadav
|
||||
*/
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
@AndroidEntryPoint
|
||||
abstract class BaseEditorActivity : EdgeToEdgeIDEActivity(), TabLayout.OnTabSelectedListener,
|
||||
DiagnosticClickListener {
|
||||
|
||||
|
||||
+1
-1
@@ -454,7 +454,7 @@ abstract class ProjectHandlerActivity : BaseEditorActivity() {
|
||||
|
||||
buildServiceConnection.onConnected = null
|
||||
editorViewModel.isBoundToBuildSerice = true
|
||||
Lookup.getDefault().update(BuildService.KEY_BUILD_SERVICE, service)
|
||||
|
||||
service.setEventListener(mBuildEventListener)
|
||||
|
||||
if (!service.isToolingServerStarted()) {
|
||||
|
||||
@@ -58,6 +58,7 @@ import com.itsaky.androidide.utils.VMUtils
|
||||
import com.itsaky.androidide.utils.flashError
|
||||
import com.termux.app.TermuxApplication
|
||||
import com.termux.shared.reflection.ReflectionUtils
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
import io.github.rosemoe.sora.widget.schemes.EditorColorScheme
|
||||
import io.realm.Realm
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
@@ -71,7 +72,7 @@ import java.lang.Thread.UncaughtExceptionHandler
|
||||
import java.time.Duration
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
|
||||
@HiltAndroidApp
|
||||
class IDEApplication : TermuxApplication() {
|
||||
|
||||
private var uncaughtExceptionHandler: UncaughtExceptionHandler? = null
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.di
|
||||
|
||||
import dagger.Module
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.components.ActivityComponent
|
||||
|
||||
/**
|
||||
* @author Akash Yadav
|
||||
*/
|
||||
@Module
|
||||
@InstallIn(ActivityComponent::class)
|
||||
abstract class ActivityModule {
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.di
|
||||
|
||||
import dagger.Module
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.components.ActivityComponent
|
||||
|
||||
/**
|
||||
* @author Akash Yadav
|
||||
*/
|
||||
@Module
|
||||
@InstallIn(ActivityComponent::class)
|
||||
abstract class EditorActivityModule {
|
||||
}
|
||||
+24
-12
@@ -59,6 +59,7 @@ import com.itsaky.androidide.tooling.api.models.ToolingServerMetadata
|
||||
import com.itsaky.androidide.tooling.events.ProgressEvent
|
||||
import com.itsaky.androidide.utils.Environment
|
||||
import com.termux.shared.termux.shell.command.environment.TermuxShellEnvironment
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.CoroutineName
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -78,6 +79,7 @@ import java.util.concurrent.TimeUnit
|
||||
*
|
||||
* @author Akash Yadav
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
class GradleBuildService : Service(), BuildService, IToolingApiClient,
|
||||
ToolingServerRunner.Observer {
|
||||
|
||||
@@ -100,7 +102,8 @@ class GradleBuildService : Service(), BuildService, IToolingApiClient,
|
||||
private var eventListener: EventListener? = null
|
||||
|
||||
private val buildServiceScope = CoroutineScope(
|
||||
Dispatchers.Default + CoroutineName("GradleBuildService"))
|
||||
Dispatchers.Default + CoroutineName("GradleBuildService")
|
||||
)
|
||||
|
||||
private val isGradleWrapperAvailable: Boolean
|
||||
get() {
|
||||
@@ -122,7 +125,6 @@ class GradleBuildService : Service(), BuildService, IToolingApiClient,
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private val log = LoggerFactory.getLogger(GradleBuildService::class.java)
|
||||
private val NOTIFICATION_ID = R.string.app_name
|
||||
private val SERVER_System_err = LoggerFactory.getLogger("ToolingApiErrorStream")
|
||||
@@ -138,8 +140,10 @@ class GradleBuildService : Service(), BuildService, IToolingApiClient,
|
||||
return isToolingServerStarted && server != null
|
||||
}
|
||||
|
||||
private fun showNotification(message: String,
|
||||
@Suppress("SameParameterValue") isProgress: Boolean) {
|
||||
private fun showNotification(
|
||||
message: String,
|
||||
@Suppress("SameParameterValue") isProgress: Boolean
|
||||
) {
|
||||
log.info("Showing notification to user...")
|
||||
createNotificationChannels()
|
||||
startForeground(NOTIFICATION_ID, buildNotification(message, isProgress))
|
||||
@@ -149,7 +153,8 @@ class GradleBuildService : Service(), BuildService, IToolingApiClient,
|
||||
val buildNotificationChannel = NotificationChannel(
|
||||
BaseApplication.NOTIFICATION_GRADLE_BUILD_SERVICE,
|
||||
getString(string.title_gradle_service_notification_channel),
|
||||
NotificationManager.IMPORTANCE_LOW)
|
||||
NotificationManager.IMPORTANCE_LOW
|
||||
)
|
||||
NotificationManagerCompat.from(this)
|
||||
.createNotificationChannel(buildNotificationChannel)
|
||||
}
|
||||
@@ -315,7 +320,8 @@ class GradleBuildService : Service(), BuildService, IToolingApiClient,
|
||||
|
||||
override fun checkGradleWrapperAvailability(): CompletableFuture<GradleWrapperCheckResult> {
|
||||
return if (isGradleWrapperAvailable) CompletableFuture.completedFuture(
|
||||
GradleWrapperCheckResult(true)) else installWrapper()
|
||||
GradleWrapperCheckResult(true)
|
||||
) else installWrapper()
|
||||
}
|
||||
|
||||
internal fun setServerListener(listener: OnServerStartListener?) {
|
||||
@@ -335,8 +341,10 @@ class GradleBuildService : Service(), BuildService, IToolingApiClient,
|
||||
|
||||
private fun doInstallWrapper(): GradleWrapperCheckResult {
|
||||
val extracted = File(Environment.TMP_DIR, "gradle-wrapper.zip")
|
||||
if (!ResourceUtils.copyFileFromAssets(ToolsManager.getCommonAsset("gradle-wrapper.zip"),
|
||||
extracted.absolutePath)
|
||||
if (!ResourceUtils.copyFileFromAssets(
|
||||
ToolsManager.getCommonAsset("gradle-wrapper.zip"),
|
||||
extracted.absolutePath
|
||||
)
|
||||
) {
|
||||
log.error("Unable to extract gradle-plugin.zip from IDE resources.")
|
||||
return GradleWrapperCheckResult(false)
|
||||
@@ -358,8 +366,10 @@ class GradleBuildService : Service(), BuildService, IToolingApiClient,
|
||||
}
|
||||
|
||||
private fun doUpdateNotification(message: String, isProgress: Boolean) {
|
||||
(getSystemService(NOTIFICATION_SERVICE) as NotificationManager).notify(NOTIFICATION_ID,
|
||||
buildNotification(message, isProgress))
|
||||
(getSystemService(NOTIFICATION_SERVICE) as NotificationManager).notify(
|
||||
NOTIFICATION_ID,
|
||||
buildNotification(message, isProgress)
|
||||
)
|
||||
}
|
||||
|
||||
override fun metadata(): CompletableFuture<ToolingServerMetadata> {
|
||||
@@ -368,7 +378,8 @@ class GradleBuildService : Service(), BuildService, IToolingApiClient,
|
||||
}
|
||||
|
||||
override fun initializeProject(
|
||||
params: InitializeProjectParams): CompletableFuture<InitializeResult> {
|
||||
params: InitializeProjectParams
|
||||
): CompletableFuture<InitializeResult> {
|
||||
checkServerStarted()
|
||||
Objects.requireNonNull(params)
|
||||
return performBuildTasks(server!!.initialize(params))
|
||||
@@ -481,7 +492,8 @@ class GradleBuildService : Service(), BuildService, IToolingApiClient,
|
||||
}
|
||||
|
||||
outputReaderJob = buildServiceScope.launch(
|
||||
Dispatchers.IO + CoroutineName("ToolingServerErrorReader")) {
|
||||
Dispatchers.IO + CoroutineName("ToolingServerErrorReader")
|
||||
) {
|
||||
val reader = input.bufferedReader()
|
||||
try {
|
||||
reader.forEachLine { line ->
|
||||
|
||||
Reference in New Issue
Block a user