more fixes

feature/terminal-rework
deniscerri 1 month ago
parent 03c3d8000b
commit 614ba3c882
No known key found for this signature in database
GPG Key ID: 95C43D517D830350

@ -354,6 +354,7 @@
android:configChanges="smallestScreenSize|layoutDirection|orientation|screenSize"
android:exported="true"
android:label="@string/terminal"
android:windowSoftInputMode="adjustResize"
android:parentActivityName=".MainActivity">
<intent-filter>
<action android:name="ytdlnis.TerminalActivity" />

@ -24,8 +24,10 @@ import com.deniscerri.ytdl.ui.more.terminal.virtualkeys.VirtualKeysListener
import com.deniscerri.ytdl.ui.more.terminal.virtualkeys.VirtualKeysView
import com.deniscerri.ytdl.ui.more.terminal.TerminalUtils
import com.termux.view.TerminalView
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.receiveAsFlow
import java.lang.ref.WeakReference
@ -96,11 +98,15 @@ class TerminalViewModel(private val application: Application) : AndroidViewModel
private val _isBoundState = MutableStateFlow(false)
val isBoundState: StateFlow<Boolean> = _isBoundState
private val _serviceConnectedEvent = Channel<Unit>(Channel.BUFFERED)
val serviceConnectedEvent = _serviceConnectedEvent.receiveAsFlow()
private val serviceConnection = object : ServiceConnection {
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
sessionBinder = service as SessionService.SessionBinder
isBound = true
_isBoundState.value = true
_serviceConnectedEvent.trySend(Unit)
}
override fun onServiceDisconnected(name: ComponentName?) {

@ -23,7 +23,7 @@ import com.termux.terminal.TerminalSessionClient
class SessionService : Service() {
private val sessions = hashMapOf<String, TerminalSession>()
val sessionList = mutableStateMapOf<String, Int>()
var currentSession = mutableStateOf("main")
var currentSession = mutableStateOf("main1")
inner class SessionBinder : Binder() {
fun getService(): SessionService = this@SessionService
@ -59,7 +59,7 @@ class SessionService : Service() {
}
sessions.remove(id)
sessionList.remove(id)
if (sessions.isNotEmpty()) {
if (sessions.isEmpty()) {
stopSelf()
} else {
updateNotification()
@ -114,7 +114,7 @@ class SessionService : Service() {
)
return NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("ReTerminal")
.setContentTitle("YTDLnis Terminal")
.setContentText(getNotificationContentText())
.setSmallIcon(R.drawable.ic_terminal)
.setContentIntent(pendingIntent)

@ -39,7 +39,7 @@ object KeyShortcutHandler {
val clipboard: ClipboardManager = App.instance.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
val clip = clipboard.primaryClip
if (clip != null) {
val clipText = clip.toString()
val clipText = clip.getItemAt(0).text.toString()
if (clipText.trim().isNotEmpty()) {
viewModel.terminalView?.mEmulator?.paste(clipText)
}

@ -47,7 +47,7 @@ class TerminalBackEnd(
val clipboard: ClipboardManager = activity.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
val clip = clipboard.primaryClip
if (clip != null) {
val clipText = clip.toString()
val clipText = clip.getItemAt(0).text.toString()
if (clipText.trim().isNotEmpty() && terminal.mEmulator != null) {
terminal.mEmulator.paste(clipText)
}

@ -2,6 +2,8 @@ package com.deniscerri.ytdl.ui.more.terminal
import android.annotation.SuppressLint
import android.app.Activity
import android.content.ClipboardManager
import android.content.Context.CLIPBOARD_SERVICE
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
@ -41,6 +43,7 @@ import com.termux.view.TerminalView
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlin.text.toInt
class TerminalFragment : Fragment() {
@ -68,6 +71,7 @@ class TerminalFragment : Fragment() {
}
override fun onResume() {
arguments?.remove("new")
arguments?.remove("share")
super.onResume()
}
@ -122,6 +126,19 @@ class TerminalFragment : Fragment() {
}
}
val slider = requireActivity().findViewById<Slider>(R.id.textsize_seekbar)
slider?.apply {
valueFrom = 10f
valueTo = 37f
value = sharedPreferences.getFloat("terminal_zoom", 35f)
addOnChangeListener { _, value, _ ->
terminalView.setTextSize(value.toInt())
sharedPreferences.edit { putFloat("terminal_zoom", value) }
}
}
bottomAppBar.setOnMenuItemClickListener {
when(it.itemId){
R.id.command_templates -> {
@ -165,6 +182,9 @@ class TerminalFragment : Fragment() {
intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)
commandPathResultLauncher.launch(intent)
}
R.id.text_size -> {
slider?.visibility = if (slider.visibility == View.VISIBLE) View.GONE else View.VISIBLE
}
}
true
@ -173,10 +193,13 @@ class TerminalFragment : Fragment() {
notificationUtil = NotificationUtil(requireContext())
initMenu()
viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
terminalViewModel.isBoundState.collect { isBound ->
if (isBound) {
if (terminalViewModel.isBound && terminalViewModel.sessionBinder != null) {
initSession()
} else {
// If not bound yet, wait for the service connection event
viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
terminalViewModel.serviceConnectedEvent.collect {
initSession()
}
}
@ -187,15 +210,19 @@ class TerminalFragment : Fragment() {
@SuppressLint("UseKtx")
private fun initMenu() {
topAppBar.menu?.findItem(R.id.export_clipboard)?.isVisible = true
topAppBar.menu?.findItem(R.id.text_size)?.isVisible = true
topAppBar.menu?.findItem(R.id.delete)?.isVisible = true
val slider = requireActivity().findViewById<Slider>(R.id.textsize_seekbar)
topAppBar.setOnMenuItemClickListener { menuItem: MenuItem ->
when (menuItem.itemId) {
R.id.add -> {
findNavController().navigate(R.id.terminalFragment, bundleOf(Pair("new", true)),
NavOptions.Builder().setPopUpTo(R.id.terminalFragment, true).build())
}
R.id.delete -> {
sessionId?.apply {
terminalViewModel.sessionBinder?.terminateSession(this)
}
}
R.id.wrap -> {
// var scrollView = requireView().findViewById<HorizontalScrollView>(R.id.horizontalscroll_output)
// if(scrollView != null){
@ -219,34 +246,15 @@ class TerminalFragment : Fragment() {
// }
}
R.id.export_clipboard -> {
// lifecycleScope.launch(Dispatchers.IO){
// val clipboard: ClipboardManager = requireActivity().getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
// clipboard.setText(output.text)
// }
}
R.id.text_size -> {
slider?.visibility = if (slider.visibility == View.VISIBLE) View.GONE else View.VISIBLE
lifecycleScope.launch(Dispatchers.IO){
val clipboard: ClipboardManager = requireActivity().getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
clipboard.setText(session.emulator.screen.transcriptText)
}
}
}
true
}
slider?.apply {
valueFrom = 10f
valueTo = 30f
value = sharedPreferences.getFloat("terminal_zoom", 14f).coerceIn(10f, 30f)
addOnChangeListener { _, value, _ ->
terminalView.setTextSize(value.toInt())
sharedPreferences.edit { putFloat("terminal_zoom", value) }
}
}
sharedPreferences.getBoolean("wrap_text_terminal", false).apply {
if (this){
bottomAppBar.menu.performIdentifierAction(R.id.wrap, 0)
}
}
}
private fun initSession() {
@ -262,15 +270,14 @@ class TerminalFragment : Fragment() {
if (!sessionId.isNullOrBlank()) {
terminalViewModel.changeSession(requireContext(), sessionBinder, sessionId!!)
sessionId = null
}
val newSession = arguments?.getBoolean("new") ?: false
val currentSession = sessionBinder.getSession(service.currentSession.value)
session = if (newSession || currentSession == null) {
val sessionId = KeyShortcutHandler.generateUniqueSessionId(activity)
sessionId = KeyShortcutHandler.generateUniqueSessionId(activity)
sessionBinder.createSession(
sessionId,
sessionId!!,
client
)
} else {
@ -285,7 +292,7 @@ class TerminalFragment : Fragment() {
val termView = view as TerminalView
termView.setTextSize(
sharedPreferences.getFloat("terminal_zoom", 14f).coerceIn(10f, 30f).toInt()
sharedPreferences.getFloat("terminal_zoom", 35f).coerceIn(10f, 30f).toInt()
)
termView.setTypeface(TerminalUtils.typeface)
@ -294,7 +301,7 @@ class TerminalFragment : Fragment() {
termView.requestFocus()
val color = TerminalUtils.getViewColor()
val color = TerminalUtils.getViewColor(requireContext())
val bgColor = TerminalUtils.getBackgroundColor(requireContext())
termView.mEmulator?.mColors?.mCurrentColors?.apply {
set(256, color)
@ -308,7 +315,7 @@ class TerminalFragment : Fragment() {
it
)
}
//buttonTextColor = TerminalUtils.getViewColor()
buttonTextColor = TerminalUtils.getViewColor(requireContext())
reload(VirtualKeysInfo(virtualKeys, "", VirtualKeysConstants.CONTROL_CHARS_ALIASES))
}

@ -9,6 +9,7 @@ import androidx.core.content.ContextCompat
import androidx.core.graphics.ColorUtils
import com.anggrayudi.storage.file.child
import com.deniscerri.ytdl.App
import com.google.android.material.color.MaterialColors
object TerminalUtils {
var typeface: Typeface = Typeface.MONOSPACE
@ -20,13 +21,9 @@ object TerminalUtils {
}
}
fun getViewColor(): Int = Color.WHITE
fun getViewColor(context: Context): Int = MaterialColors.getColor(context, android.R.attr.textColorPrimary, Color.BLACK)
fun getBackgroundColor(context: Context): Int {
val typedValue = TypedValue()
context.theme.resolveAttribute(android.R.attr.windowBackground, typedValue, true)
return typedValue.data
}
fun getBackgroundColor(context: Context): Int = MaterialColors.getColor(context, com.google.android.material.R.attr.colorSurface, Color.BLACK)
fun getComposeColor(): androidx.compose.ui.graphics.Color =
androidx.compose.ui.graphics.Color.White

@ -76,9 +76,9 @@ class VirtualKeysView @JvmOverloads constructor(
_repetitiveKeys = value
}
var buttonTextColor: Int = DEFAULT_BUTTON_TEXT_COLOR
var buttonTextColor: Int = MaterialColors.getColor(context, android.R.attr.textColorPrimary, Color.BLACK)
var buttonActiveTextColor: Int = DEFAULT_BUTTON_ACTIVE_TEXT_COLOR
var buttonBackgroundColor: Int = MaterialColors.getColor(context, com.google.android.material.R.attr.colorSurface, Color.BLACK)
var buttonBackgroundColor: Int = MaterialColors.getColor(context, com.google.android.material.R.attr.colorSurfaceContainer, Color.BLACK)
var buttonActiveBackgroundColor: Int = DEFAULT_BUTTON_ACTIVE_BACKGROUND_COLOR
var isButtonTextAllCaps: Boolean = true
@ -110,10 +110,10 @@ class VirtualKeysView @JvmOverloads constructor(
repetitiveKeys = VirtualKeysConstants.PRIMARY_REPETITIVE_KEYS
specialButtons = getDefaultSpecialButtons(this)
setButtonColors(
DEFAULT_BUTTON_TEXT_COLOR,
DEFAULT_BUTTON_ACTIVE_TEXT_COLOR,
DEFAULT_BUTTON_BACKGROUND_COLOR,
DEFAULT_BUTTON_ACTIVE_BACKGROUND_COLOR
buttonTextColor,
buttonActiveTextColor,
buttonBackgroundColor,
buttonActiveBackgroundColor
)
longPressTimeout = ViewConfiguration.getLongPressTimeout()
longPressRepeatDelay = DEFAULT_LONG_PRESS_REPEAT_DELAY

@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="?attr/colorAccent" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
<path android:fillColor="@android:color/white" android:pathData="M9,4v3h5v12h3L17,7h5L22,4L9,4zM3,12h3v7h3v-7h3L12,9L3,9v3z"/>
</vector>

@ -46,7 +46,7 @@
android:id="@+id/bottomAppBar"
style="@style/Widget.Material3.BottomAppBar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:menu="@menu/terminal_menu" />

@ -18,7 +18,7 @@
<item
android:id="@+id/text_size"
android:title="@string/text_size"
android:icon="@drawable/ic_textformat"
android:icon="@drawable/baseline_format_size_24"
app:showAsAction="always" />
<item

@ -20,4 +20,10 @@
android:title="@string/command_directory"
android:icon="@drawable/baseline_folder_24"
app:showAsAction="always"/>
<item
android:id="@+id/text_size"
android:title="@string/text_size"
android:icon="@drawable/baseline_format_size_24"
app:showAsAction="always"/>
</menu>

@ -7,17 +7,16 @@
app:showAsAction="always"
android:id="@+id/add"/>
<item android:title="@string/Remove"
android:icon="@drawable/baseline_delete_24"
app:showAsAction="always"
android:id="@+id/delete"/>
<!-- <item android:title="@string/wrap_text"-->
<!-- android:icon="@drawable/baseline_wrap_text_24"-->
<!-- app:showAsAction="always"-->
<!-- android:id="@+id/wrap"/>-->
<item
android:id="@+id/text_size"
android:title="@string/text_size"
android:icon="@drawable/ic_textformat"
app:showAsAction="always" />
<item
android:id="@+id/export_clipboard"
android:title="@string/export_from_clipboard"

Loading…
Cancel
Save