fixed terminal glitch

This commit is contained in:
deniscerri 2023-03-26 23:07:02 +02:00
parent fa7bb62320
commit 57f8520e03
No known key found for this signature in database
GPG key ID: 95C43D517D830350
5 changed files with 58 additions and 45 deletions

View file

@ -77,7 +77,7 @@ class CutVideoBottomSheetDialog(private val item: DownloadItem, private val list
val timeSeconds = convertStringToTimestamp(item.duration) val timeSeconds = convertStringToTimestamp(item.duration)
if (item.downloadSections.isEmpty()){ if (item.downloadSections.isEmpty()){
fromTextInput.editText!!.setText("00:00") fromTextInput.editText!!.setText("0:00")
toTextInput.editText!!.setText(item.duration) toTextInput.editText!!.setText(item.duration)
}else{ }else{
val stamps = item.downloadSections.split("-") val stamps = item.downloadSections.split("-")

View file

@ -258,6 +258,9 @@ class DownloadAudioFragment(private var resultItem: ResultItem, private var curr
} }
override fun onChangeCut(from: String, to: String) { override fun onChangeCut(from: String, to: String) {
if (from == "0:00" && to == downloadItem.duration){
return
}
val value = "${from}-${to}" val value = "${from}-${to}"
downloadItem.downloadSections = value downloadItem.downloadSections = value
cut.text = value cut.text = value

View file

@ -283,6 +283,9 @@ class DownloadVideoFragment(private val resultItem: ResultItem, private var curr
} }
override fun onChangeCut(from: String, to: String) { override fun onChangeCut(from: String, to: String) {
if (from == "0:00" && to == downloadItem.duration){
return
}
val value = "${from}-${to}" val value = "${from}-${to}"
downloadItem.downloadSections = value downloadItem.downloadSections = value
cut.text = value cut.text = value
@ -290,6 +293,7 @@ class DownloadVideoFragment(private val resultItem: ResultItem, private var curr
splitByChapters.isEnabled = false splitByChapters.isEnabled = false
splitByChapters.isChecked = false splitByChapters.isChecked = false
addChapters.isEnabled = true addChapters.isEnabled = true
} }
} }
cut.setOnClickListener { cut.setOnClickListener {

View file

@ -1,10 +1,12 @@
package com.deniscerri.ytdlnis.ui.more package com.deniscerri.ytdlnis.ui.more
import android.Manifest import android.Manifest
import android.app.Activity
import android.app.Notification import android.app.Notification
import android.app.PendingIntent import android.app.PendingIntent
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Bundle import android.os.Bundle
import android.os.Looper import android.os.Looper
@ -21,10 +23,7 @@ import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.work.Data import androidx.work.*
import androidx.work.ExistingWorkPolicy
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import com.deniscerri.ytdlnis.App import com.deniscerri.ytdlnis.App
import com.deniscerri.ytdlnis.R import com.deniscerri.ytdlnis.R
import com.deniscerri.ytdlnis.database.repository.DownloadRepository import com.deniscerri.ytdlnis.database.repository.DownloadRepository
@ -67,6 +66,7 @@ class TerminalActivity : AppCompatActivity() {
private var scrollView: ScrollView? = null private var scrollView: ScrollView? = null
private lateinit var bottomAppBar: BottomAppBar private lateinit var bottomAppBar: BottomAppBar
private lateinit var commandTemplateViewModel: CommandTemplateViewModel private lateinit var commandTemplateViewModel: CommandTemplateViewModel
private lateinit var sharedPreferences: SharedPreferences
var context: Context? = null var context: Context? = null
public override fun onCreate(savedInstanceState: Bundle?) { public override fun onCreate(savedInstanceState: Bundle?) {
@ -78,6 +78,7 @@ class TerminalActivity : AppCompatActivity() {
topAppBar!!.setNavigationOnClickListener { onBackPressedDispatcher.onBackPressed() } topAppBar!!.setNavigationOnClickListener { onBackPressedDispatcher.onBackPressed() }
commandTemplateViewModel = ViewModelProvider(this)[CommandTemplateViewModel::class.java] commandTemplateViewModel = ViewModelProvider(this)[CommandTemplateViewModel::class.java]
sharedPreferences = getSharedPreferences("root_preferences", Activity.MODE_PRIVATE)
bottomAppBar = findViewById(R.id.bottomAppBar) bottomAppBar = findViewById(R.id.bottomAppBar)
@ -157,6 +158,7 @@ class TerminalActivity : AppCompatActivity() {
item.findViewById<TextView>(R.id.content).text = template.content item.findViewById<TextView>(R.id.content).text = template.content
item.setOnClickListener { item.setOnClickListener {
input!!.text.insert(input!!.selectionStart, template.content + " ") input!!.text.insert(input!!.selectionStart, template.content + " ")
bottomSheet.cancel()
} }
linearLayout.addView(item) linearLayout.addView(item)
} }
@ -246,7 +248,7 @@ class TerminalActivity : AppCompatActivity() {
YoutubeDL.getInstance().execute(request, downloadID.toString()){ progress, _, line -> YoutubeDL.getInstance().execute(request, downloadID.toString()){ progress, _, line ->
Log.e(TAG, line) Log.e(TAG, line)
runOnUiThread { runOnUiThread {
output!!.append("\n" + line) output!!.text = "${output!!.text}\n$line"
output!!.scrollTo(0, output!!.height) output!!.scrollTo(0, output!!.height)
scrollView!!.fullScroll(View.FOCUS_DOWN) scrollView!!.fullScroll(View.FOCUS_DOWN)
} }
@ -261,11 +263,12 @@ class TerminalActivity : AppCompatActivity() {
}catch (e: Exception){ }catch (e: Exception){
e.printStackTrace() e.printStackTrace()
runOnUiThread { runOnUiThread {
output!!.append("\n" + e.message) output!!.text = "${output!!.text}\n${e.message}"
output!!.scrollTo(0, output!!.height) output!!.scrollTo(0, output!!.height)
scrollView!!.fullScroll(View.FOCUS_DOWN) scrollView!!.fullScroll(View.FOCUS_DOWN)
input!!.visibility = View.VISIBLE input!!.visibility = View.VISIBLE
input!!.requestFocus()
hideCancelFab() hideCancelFab()
} }
@ -275,15 +278,24 @@ class TerminalActivity : AppCompatActivity() {
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ .subscribe({
output!!.scrollTo(0, output!!.height)
scrollView!!.fullScroll(View.FOCUS_DOWN)
input!!.setText("yt-dlp ") input!!.setText("yt-dlp ")
input!!.visibility = View.VISIBLE input!!.visibility = View.VISIBLE
input!!.requestFocus()
try{
val fileUtil = FileUtil()
fileUtil.moveFile(tempFileDir.absoluteFile, this, sharedPreferences.getString("command_path", getString(R.string.command))!!) {}
}catch (e: Exception){
output!!.text = "${output!!.text}\n${e.message}"
output!!.scrollTo(0, output!!.height)
scrollView!!.fullScroll(View.FOCUS_DOWN)
}
hideCancelFab() hideCancelFab()
notificationUtil.cancelDownloadNotification(downloadID) notificationUtil.cancelDownloadNotification(downloadID)
}) { e -> }) { e ->
e.printStackTrace() e.printStackTrace()
output!!.text = "${output!!.text}\n${e.message}"
output!!.scrollTo(0, output!!.height) output!!.scrollTo(0, output!!.height)
scrollView!!.fullScroll(View.FOCUS_DOWN) scrollView!!.fullScroll(View.FOCUS_DOWN)
input!!.setText("yt-dlp ") input!!.setText("yt-dlp ")

View file

@ -30,53 +30,47 @@
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
android:layout_height="match_parent"> android:layout_height="match_parent">
<LinearLayout <ScrollView
android:id="@+id/custom_command_frame_layout" android:layout_margin="10dp"
android:id="@+id/custom_command_scrollview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp" app:layout_constraintVertical_bias="0"
android:clipToPadding="false"
android:paddingBottom="100dp"
app:layout_constraintBottom_toTopOf="@+id/coordinatorLayout" app:layout_constraintBottom_toTopOf="@+id/coordinatorLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<ScrollView <LinearLayout
android:id="@+id/custom_command_scrollview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:clipToPadding="false" android:focusableInTouchMode="true"
android:paddingBottom="100dp"> android:orientation="vertical">
<LinearLayout <TextView
android:id="@+id/custom_command_output"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:fontFamily="monospace"
android:gravity="bottom"
android:textIsSelectable="true" />
<TextView <EditText
android:id="@+id/custom_command_output" android:id="@+id/command_edittext"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fontFamily="monospace" android:background="@android:color/transparent"
android:gravity="bottom" android:fontFamily="monospace"
android:textIsSelectable="true" /> android:gravity="start"
android:inputType="textMultiLine"
android:paddingBottom="100dp"
android:maxLines="100"
android:text="yt-dlp "
android:textSize="15sp" />
<EditText </LinearLayout>
android:id="@+id/command_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:fontFamily="monospace"
android:gravity="start"
android:inputType="textMultiLine"
android:maxLines="100"
android:text="yt-dlp "
android:textSize="14sp" />
</LinearLayout> </ScrollView>
</ScrollView>
</LinearLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout <androidx.coordinatorlayout.widget.CoordinatorLayout