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
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ import com.google.android.material.tabs.TabLayout.Tab
import com.itsaky.androidide.FeedbackButtonManager
import com.itsaky.androidide.R
import com.itsaky.androidide.R.string
import com.itsaky.androidide.activities.MainActivity
import com.itsaky.androidide.actions.build.DebugAction
import com.itsaky.androidide.activities.MainActivity
import com.itsaky.androidide.adapters.DiagnosticsAdapter
import com.itsaky.androidide.adapters.SearchListAdapter
import com.itsaky.androidide.api.BuildOutputProvider
Expand Down Expand Up @@ -216,8 +216,9 @@ abstract class BaseEditorActivity :
@Suppress("ktlint:standard:backing-property-naming")
internal var _binding: ActivityEditorBinding? = null
val binding: ActivityEditorBinding
get() = _binding
?: throw IllegalStateException("Activity destroyed; binding not accessible")
get() =
_binding
?: throw IllegalStateException("Activity destroyed; binding not accessible")
val content: ContentEditorBinding
get() = binding.content

Expand Down Expand Up @@ -261,12 +262,14 @@ abstract class BaseEditorActivity :
memoryUsage.forEachValue { proc ->
_binding?.memUsageView?.chart?.apply {
val dataset =
(data.getDataSetByIndex(
pidToDatasetIdxMap.getOrDefault(
proc.pid,
-1
)
) as LineDataSet?)
(
data.getDataSetByIndex(
pidToDatasetIdxMap.getOrDefault(
proc.pid,
-1,
),
) as LineDataSet?
)
?: run {
log.error(
"No dataset found for process: {}: {}",
Expand Down Expand Up @@ -376,12 +379,13 @@ abstract class BaseEditorActivity :

isDebuggerStarting = true

val intent = Intent(this, DebuggerService::class.java)
.apply {
val currentOrDefaultDisplay =
ContextCompat.getDisplayOrDefault(this@BaseEditorActivity)
putExtra(DebuggerService.EXTRA_DISPLAY_ID, currentOrDefaultDisplay.displayId)
}
val intent =
Intent(this, DebuggerService::class.java)
.apply {
val currentOrDefaultDisplay =
ContextCompat.getDisplayOrDefault(this@BaseEditorActivity)
putExtra(DebuggerService.EXTRA_DISPLAY_ID, currentOrDefaultDisplay.displayId)
}

if (bindService(intent, debuggerServiceConnection, BIND_AUTO_CREATE)) {
postStopDebuggerServiceIfNotConnected()
Expand Down Expand Up @@ -410,7 +414,6 @@ abstract class BaseEditorActivity :
private var editorAppBarInsetTop: Int = 0

companion object {

const val DEBUGGER_SERVICE_STOP_DELAY_MS: Long = 60 * 1000

@JvmStatic
Expand Down Expand Up @@ -536,7 +539,10 @@ abstract class BaseEditorActivity :
_binding?.content?.applyImmersiveModeInsets(systemBars)
}

private fun handleKeyboardInsets(imeInsets: Insets, systemBars: Insets) {
private fun handleKeyboardInsets(
imeInsets: Insets,
systemBars: Insets,
) {
val isImeVisible = imeInsets.bottom > 0
_binding?.content?.bottomSheet?.setImeVisible(isImeVisible)

Expand Down Expand Up @@ -564,9 +570,9 @@ abstract class BaseEditorActivity :
this.isImeVisible = isImeVisible

if (editorViewModel.isFullscreen) {
// Hide the bottom sheet if in fullscreen mode, but only collapse it if keyboard
// is open so the symbol input view is visible
val targetState = if (isImeVisible) STATE_COLLAPSED else STATE_HIDDEN
// Hide the bottom sheet if in fullscreen mode, but only collapse it if keyboard
// is open so the symbol input view is visible
val targetState = if (isImeVisible) STATE_COLLAPSED else STATE_HIDDEN
editorBottomSheet?.state = targetState
}

Expand Down Expand Up @@ -701,19 +707,20 @@ abstract class BaseEditorActivity :
setupBottomSheetObserver()
setupViews()

fullscreenManager = FullscreenManager(
contentBinding = content,
bottomSheetBehavior = editorBottomSheet!!,
closeDrawerAction = {
binding.editorDrawerLayout.closeDrawer(GravityCompat.START)
},
onFullscreenToggleRequested = {
editorViewModel.toggleFullscreen()
},
).also {
it.bind()
it.render(editorViewModel.isFullscreen, animate = false)
}
fullscreenManager =
FullscreenManager(
contentBinding = content,
bottomSheetBehavior = editorBottomSheet!!,
closeDrawerAction = {
binding.editorDrawerLayout.closeDrawer(GravityCompat.START)
},
onFullscreenToggleRequested = {
editorViewModel.toggleFullscreen()
},
).also {
it.bind()
it.render(editorViewModel.isFullscreen, animate = false)
}

setupContainers()
setupDiagnosticInfo()
Expand Down Expand Up @@ -766,7 +773,6 @@ abstract class BaseEditorActivity :
applyImmersiveModeInsets(systemBars)
}


private fun setupToolbar() {
// Set the project name in the title TextView
content.root.findViewById<TextView>(R.id.title_text)?.apply {
Expand Down Expand Up @@ -1041,26 +1047,27 @@ abstract class BaseEditorActivity :
return
}

val pluginMenuItems = if (this is EditorHandlerActivity) {
val self = this
val fileIndex = getFileIndexForTabPosition(position)
if (fileIndex >= 0) {
val file = editorViewModel.getOpenedFile(fileIndex)
val pluginItems =
IDEApplication.getPluginManager()?.getFileTabMenuItems(file) ?: emptyList()
listOf(
FileTabMenuItem(
id = "ide.floating.undock",
title = getString(R.string.undock),
tooltipTag = TooltipTag.WINDOW_UNDOCK,
) { self.undockFileTab(fileIndex) },
) + pluginItems
val pluginMenuItems =
if (this is EditorHandlerActivity) {
val self = this
val fileIndex = getFileIndexForTabPosition(position)
if (fileIndex >= 0) {
val file = editorViewModel.getOpenedFile(fileIndex)
val pluginItems =
IDEApplication.getPluginManager()?.getFileTabMenuItems(file) ?: emptyList()
listOf(
FileTabMenuItem(
id = "ide.floating.undock",
title = getString(R.string.undock),
tooltipTag = TooltipTag.WINDOW_UNDOCK,
) { self.undockFileTab(fileIndex) },
) + pluginItems
} else {
emptyList()
}
} else {
emptyList()
}
} else {
emptyList()
}

showPopupWindow(
context = this,
Expand All @@ -1084,15 +1091,23 @@ abstract class BaseEditorActivity :
hideBottomSheet()
}

open fun handleSearchResults(map: Map<File, List<SearchResult>>?) {
@JvmOverloads
open fun handleSearchResults(
map: Map<File, List<SearchResult>>?,
dismissProgress: Boolean = true,
) {
val results = map ?: emptyMap()
editorViewModel.onSearchResultsReady(results)

bottomSheetViewModel.setSheetState(
sheetState = BottomSheetBehavior.STATE_HALF_EXPANDED,
currentTab = BottomSheetViewModel.TAB_SEARCH_RESULT,
)
doDismissSearchProgress()
// A pending plugin-search fan-out keeps the progress indicator up until it resolves,
// so a query the built-in text search misses does not flash a terminal empty state.
if (dismissProgress) {
doDismissSearchProgress()
}
}

open fun setSearchResultAdapter(adapter: SearchListAdapter) {
Expand Down Expand Up @@ -1180,7 +1195,7 @@ abstract class BaseEditorActivity :
log.warn(
"UI Designer returned invalid result: resultCode={}, data={}",
result.resultCode,
result.data
result.data,
)
return
}
Expand Down Expand Up @@ -1220,10 +1235,11 @@ abstract class BaseEditorActivity :
result.onFailure { error ->
log.error("String injection failed", error)
withContext(Dispatchers.Main) {
val message = when (error) {
is StringsInjectionException -> getString(error.messageRes)
else -> getString(string.msg_strings_injection_failed)
}
val message =
when (error) {
is StringsInjectionException -> getString(error.messageRes)
else -> getString(string.msg_strings_injection_failed)
}
flashError(message)
}
}
Expand All @@ -1233,10 +1249,11 @@ abstract class BaseEditorActivity :

private fun applyGeneratedXmlToEditor(generatedXml: String) {
val view = provideCurrentEditor()
val text = view?.editor?.text ?: run {
log.warn("No file opened to append UI designer result")
return
}
val text =
view?.editor?.text ?: run {
log.warn("No file opened to append UI designer result")
return
}

val endLine = text.lineCount - 1
text.replace(0, 0, endLine, text.getColumnCount(endLine), generatedXml)
Expand Down Expand Up @@ -1392,7 +1409,8 @@ abstract class BaseEditorActivity :

private fun updateSwipeRevealDragState() {
val isFullscreen = editorViewModel.isFullscreen
val isBottomSheetOpen = bottomSheetViewModel.sheetBehaviorState != STATE_COLLAPSED &&
val isBottomSheetOpen =
bottomSheetViewModel.sheetBehaviorState != STATE_COLLAPSED &&
bottomSheetViewModel.sheetBehaviorState != STATE_HIDDEN
binding.swipeReveal.setVerticalDragEnabled(!isFullscreen && !isBottomSheetOpen)
}
Expand Down Expand Up @@ -1547,9 +1565,9 @@ abstract class BaseEditorActivity :
it.realContainer.pivotX = it.realContainer.width.toFloat() / 2f
it.realContainer.pivotY =
(it.realContainer.height.toFloat() / 2f) + (
systemBarInsets?.run { bottom - top }
?: 0
)
systemBarInsets?.run { bottom - top }
?: 0
)
it.viewContainer.viewTreeObserver.removeOnGlobalLayoutListener(this)
}
}
Expand Down Expand Up @@ -1636,19 +1654,23 @@ abstract class BaseEditorActivity :

val startedNearTopEdge = e1.y < topEdgeThreshold
val startedNearBottomEdge = e1.y > bottomEdgeThreshold
val isTopEdgeDismissFling = isVerticalSwipe &&
val isTopEdgeDismissFling =
isVerticalSwipe &&
hasVerticalVelocity &&
startedNearTopEdge &&
hasDownFlingDistance
val isBottomEdgeDismissFling = isVerticalSwipe &&
val isBottomEdgeDismissFling =
isVerticalSwipe &&
hasVerticalVelocity &&
startedNearBottomEdge &&
hasUpFlingDistance
val isDrawerOpenFling = hasRightFlingDistance &&
val isDrawerOpenFling =
hasRightFlingDistance &&
hasHorizontalVelocity &&
isHorizontalSwipe

val isBottomSheetOpen = bottomSheetViewModel.sheetBehaviorState != STATE_COLLAPSED &&
val isBottomSheetOpen =
bottomSheetViewModel.sheetBehaviorState != STATE_COLLAPSED &&
bottomSheetViewModel.sheetBehaviorState != STATE_HIDDEN

if (isBottomSheetOpen) {
Expand Down
Loading
Loading