mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
refactor: refactor
This commit is contained in:
Binary file not shown.
+3
-2
@@ -29,15 +29,16 @@ import com.itsaky.androidide.utils.ILogger
|
||||
*/
|
||||
class GradleBuildServiceConnnection : ServiceConnection {
|
||||
|
||||
internal var onConnected: (GradleBuildService) -> Unit = {}
|
||||
internal var onConnected: ((GradleBuildService) -> Unit)? = null
|
||||
private val log = ILogger.newInstance("GradleBuildServiceConnnection")
|
||||
|
||||
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
|
||||
val serviceBinder = service as GradleServiceBinder
|
||||
onConnected(serviceBinder.service!!)
|
||||
onConnected?.invoke(serviceBinder.service!!)
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(name: ComponentName?) {
|
||||
onConnected = null
|
||||
log.info("Disconnected from Gradle build service")
|
||||
}
|
||||
}
|
||||
@@ -23,18 +23,7 @@ import com.itsaky.androidide.lsp.models.DiagnosticItem
|
||||
*
|
||||
* @author Akash Yadav
|
||||
*/
|
||||
class DiagnosticWindow
|
||||
/**
|
||||
* Create a popup window for editor
|
||||
*
|
||||
* @param editor The editor
|
||||
* @see .FEATURE_SCROLL_AS_CONTENT
|
||||
*
|
||||
* @see .FEATURE_SHOW_OUTSIDE_VIEW_ALLOWED
|
||||
*
|
||||
* @see .FEATURE_HIDE_WHEN_FAST_SCROLL
|
||||
*/
|
||||
(editor: IDEEditor) : BaseEditorWindow(editor) {
|
||||
class DiagnosticWindow(editor: IDEEditor) : BaseEditorWindow(editor) {
|
||||
/**
|
||||
* Show the given diagnostic item.
|
||||
*
|
||||
|
||||
+1
-1
@@ -33,7 +33,6 @@ import org.gradle.tooling.events.OperationType;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
@@ -86,6 +85,7 @@ public class Main {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("NewApi")
|
||||
public static void finalizeLauncher(ConfigurableLauncher<?> launcher) {
|
||||
final var out = new LoggingOutputStream();
|
||||
launcher.setStandardError(out);
|
||||
|
||||
+3
-32
@@ -26,13 +26,7 @@ import com.android.aapt.Resources.XmlElement
|
||||
import com.android.aapt.Resources.XmlNode.NodeCase.ELEMENT
|
||||
import com.android.aaptcompiler.AaptResourceType.ID
|
||||
import com.android.aaptcompiler.AaptResourceType.LAYOUT
|
||||
import com.android.aaptcompiler.BlameLogger
|
||||
import com.android.aaptcompiler.ResourceFile
|
||||
import com.android.aaptcompiler.ResourceFile.Type.ProtoXml
|
||||
import com.android.aaptcompiler.ResourceName
|
||||
import com.android.aaptcompiler.XmlProcessor
|
||||
import com.android.aaptcompiler.extractPathData
|
||||
import com.itsaky.androidide.aapt.logging.IDELogger
|
||||
import com.itsaky.androidide.inflater.DefaultComponentFactory
|
||||
import com.itsaky.androidide.inflater.IAttribute
|
||||
import com.itsaky.androidide.inflater.IComponentFactory
|
||||
@@ -56,7 +50,6 @@ import com.itsaky.androidide.inflater.utils.isParsing
|
||||
import com.itsaky.androidide.inflater.utils.startParse
|
||||
import com.itsaky.androidide.inflater.viewAdapter
|
||||
import com.itsaky.androidide.lookup.Lookup
|
||||
import com.itsaky.androidide.projects.ProjectManager
|
||||
import com.itsaky.androidide.projects.api.AndroidModule
|
||||
import com.itsaky.androidide.xml.widgets.Widget
|
||||
import com.itsaky.androidide.xml.widgets.WidgetTable
|
||||
@@ -241,11 +234,11 @@ open class LayoutInflaterImpl : ILayoutInflater {
|
||||
if (!checkAttr(xmlAttribute)) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
val namespace =
|
||||
if (xmlAttribute.namespaceUri.isNullOrBlank()) null
|
||||
else view.findNamespaceByUri(xmlAttribute.namespaceUri)
|
||||
|
||||
|
||||
val attr = onCreateAttribute(view, namespace, xmlAttribute.name, xmlAttribute.value)
|
||||
view.addAttribute(attribute = attr, update = true)
|
||||
inflationEventListener?.onEvent(OnApplyAttributeEvent(view, attr))
|
||||
@@ -344,29 +337,7 @@ open class LayoutInflaterImpl : ILayoutInflater {
|
||||
}
|
||||
|
||||
protected open fun processXmlFile(file: File): Pair<XmlProcessor, AndroidModule> {
|
||||
val pathData = extractPathData(file)
|
||||
if (pathData.type != LAYOUT) {
|
||||
throw InflateException("File is not a layout file.")
|
||||
}
|
||||
|
||||
if (ProjectManager.rootProject == null) {
|
||||
throw InflateException("Project is not initialized!")
|
||||
}
|
||||
|
||||
val module =
|
||||
ProjectManager.findModuleForFile(file) as? AndroidModule
|
||||
?: throw InflateException("Cannot find module for given file. Is the project initialized?")
|
||||
val resFile =
|
||||
ResourceFile(
|
||||
ResourceName(module.packageName, pathData.type!!, pathData.name),
|
||||
pathData.config,
|
||||
pathData.source,
|
||||
ProtoXml
|
||||
)
|
||||
|
||||
val processor = XmlProcessor(pathData.source, BlameLogger(IDELogger))
|
||||
processor.process(resFile, file.inputStream())
|
||||
return processor to module
|
||||
return com.itsaky.androidide.inflater.utils.processXmlFile(file, LAYOUT)
|
||||
}
|
||||
|
||||
private fun onCreateUnsupportedView(
|
||||
|
||||
@@ -17,14 +17,26 @@
|
||||
|
||||
package com.itsaky.androidide.inflater.utils
|
||||
|
||||
import com.android.aaptcompiler.AaptResourceType
|
||||
import com.android.aaptcompiler.BlameLogger
|
||||
import com.android.aaptcompiler.ResourceFile
|
||||
import com.android.aaptcompiler.ResourceFile.Type.ProtoXml
|
||||
import com.android.aaptcompiler.ResourceName
|
||||
import com.android.aaptcompiler.XmlProcessor
|
||||
import com.android.aaptcompiler.extractPathData
|
||||
import com.itsaky.androidide.aapt.logging.IDELogger
|
||||
import com.itsaky.androidide.inflater.IAttribute
|
||||
import com.itsaky.androidide.inflater.IComponentFactory
|
||||
import com.itsaky.androidide.inflater.ILayoutInflater
|
||||
import com.itsaky.androidide.inflater.ILayoutInflater.Companion
|
||||
import com.itsaky.androidide.inflater.INamespace
|
||||
import com.itsaky.androidide.inflater.IView
|
||||
import com.itsaky.androidide.inflater.InflateException
|
||||
import com.itsaky.androidide.inflater.internal.AttributeImpl
|
||||
import com.itsaky.androidide.lookup.Lookup
|
||||
import com.itsaky.androidide.projects.ProjectManager
|
||||
import com.itsaky.androidide.projects.api.AndroidModule
|
||||
import java.io.File
|
||||
|
||||
/** Get the [ILayoutInflater] registered with [Lookup]. */
|
||||
fun lookupLayoutInflater(): ILayoutInflater? {
|
||||
@@ -65,3 +77,37 @@ fun newAttribute(
|
||||
}
|
||||
return AttributeImpl(namespace, name, value)
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the XML file using [XmlProcessor].
|
||||
*
|
||||
* @param file The file to process.
|
||||
* @param expectedType The expected [type][AaptResourceType] for the XML file.
|
||||
* @return The pair of [XmlProcessor] (processed) instance and the [AndroidModule] instance for the
|
||||
* given file.
|
||||
*/
|
||||
fun processXmlFile(file: File, expectedType: AaptResourceType): Pair<XmlProcessor, AndroidModule> {
|
||||
val pathData = extractPathData(file)
|
||||
if (pathData.type != expectedType) {
|
||||
throw InflateException("File is not a layout file.")
|
||||
}
|
||||
|
||||
if (ProjectManager.rootProject == null) {
|
||||
throw InflateException("Project is not initialized!")
|
||||
}
|
||||
|
||||
val module =
|
||||
ProjectManager.findModuleForFile(file) as? AndroidModule
|
||||
?: throw InflateException("Cannot find module for given file. Is the project initialized?")
|
||||
val resFile =
|
||||
ResourceFile(
|
||||
ResourceName(module.packageName, pathData.type!!, pathData.name),
|
||||
pathData.config,
|
||||
pathData.source,
|
||||
ProtoXml
|
||||
)
|
||||
|
||||
val processor = XmlProcessor(pathData.source, BlameLogger(IDELogger))
|
||||
processor.process(resFile, file.inputStream())
|
||||
return processor to module
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user