fixed logs screen crashing on older apis
This commit is contained in:
parent
24f04ec2ba
commit
42fbf78ea2
6 changed files with 68 additions and 51 deletions
|
|
@ -125,7 +125,7 @@ dependencies {
|
|||
|
||||
implementation "androidx.appcompat:appcompat:$appCompatVer"
|
||||
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
|
||||
implementation 'com.google.android.material:material:1.7.0'
|
||||
implementation 'com.google.android.material:material:1.8.0'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'androidx.core:core:1.9.0'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.2.1'
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.deniscerri.ytdlnis.ui.downloadLogs
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.FileObserver
|
||||
import android.util.Log
|
||||
|
|
@ -43,7 +44,7 @@ class DownloadLogActivity : AppCompatActivity() {
|
|||
topAppBar.title = file.name
|
||||
content.text = file.readText()
|
||||
|
||||
observer = object : FileObserver(file, MODIFY) {
|
||||
observer = object : FileObserver(file.absolutePath, MODIFY) {
|
||||
override fun onEvent(event: Int, p: String?) {
|
||||
runOnUiThread{
|
||||
content.text = File(path).readText()
|
||||
|
|
|
|||
|
|
@ -2,10 +2,7 @@ package com.deniscerri.ytdlnis.ui.downloadLogs
|
|||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.os.FileObserver
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.*
|
||||
import android.text.InputType
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
|
|
@ -57,7 +54,7 @@ class DownloadLogListActivity : AppCompatActivity(), DownloadLogsAdapter.OnItemC
|
|||
val logFolder = File(filesDir.absolutePath + "/logs")
|
||||
updateList(logFolder)
|
||||
|
||||
val observer: FileObserver = object : FileObserver(logFolder) {
|
||||
val observer: FileObserver = object : FileObserver(logFolder.absolutePath) {
|
||||
override fun onEvent(event: Int, path: String?) {
|
||||
when(event) {
|
||||
CREATE, DELETE -> updateList(logFolder)
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
version!!.summary = BuildConfig.VERSION_NAME
|
||||
|
||||
val values = resources.getStringArray(R.array.language_values)
|
||||
if (Build.VERSION.SDK_INT >= 33){
|
||||
if (Build.VERSION.SDK_INT >= 33 || Build.VERSION.SDK_INT < 24){
|
||||
language!!.isVisible = false
|
||||
}else{
|
||||
val entries = mutableListOf<String>()
|
||||
|
|
@ -299,7 +299,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
}
|
||||
audioQuality!!.onPreferenceChangeListener =
|
||||
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any ->
|
||||
editor.putInt("audio_format", newValue.toString().toInt())
|
||||
editor.putInt("audio_quality", newValue.toString().toInt())
|
||||
editor.apply()
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,23 @@
|
|||
package com.deniscerri.ytdlnis.util
|
||||
|
||||
import android.R.attr.src
|
||||
import android.content.Context
|
||||
import android.media.MediaScannerConnection
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.DocumentsContract
|
||||
import android.util.Log
|
||||
import android.webkit.MimeTypeMap
|
||||
import android.widget.Toast
|
||||
import com.deniscerri.ytdlnis.R
|
||||
import com.deniscerri.ytdlnis.database.models.DownloadItem
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.net.URLDecoder
|
||||
import java.nio.channels.FileChannel
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.StandardCopyOption
|
||||
import java.text.DecimalFormat
|
||||
import kotlin.math.log10
|
||||
import kotlin.math.max
|
||||
import kotlin.math.pow
|
||||
|
||||
|
||||
class FileUtil() {
|
||||
fun deleteFile(path: String){
|
||||
val file = File(path)
|
||||
|
|
@ -97,43 +95,54 @@ class FileUtil() {
|
|||
Files.move(it.toPath(), f.toPath(), StandardCopyOption.REPLACE_EXISTING)
|
||||
progress(100)
|
||||
}else{
|
||||
val mimeType =
|
||||
MimeTypeMap.getSingleton().getMimeTypeFromExtension(it.extension) ?: "*/*"
|
||||
|
||||
val destination = Uri.parse(destDir).run {
|
||||
DocumentsContract.buildChildDocumentsUriUsingTree(this, DocumentsContract.getTreeDocumentId(this))
|
||||
}
|
||||
|
||||
val destUri = DocumentsContract.createDocument(
|
||||
context.contentResolver,
|
||||
destination,
|
||||
mimeType,
|
||||
it.name
|
||||
) ?: return@forEach
|
||||
|
||||
val inputStream = it.inputStream()
|
||||
val outputStream = context.contentResolver.openOutputStream(destUri) ?: return@forEach
|
||||
val fileLength = it.length()
|
||||
var bytesCopied: Long = 0
|
||||
val buffer = ByteArray(DEFAULT_BUFFER_SIZE)
|
||||
var bytes = inputStream.read(buffer)
|
||||
val f = File(formatPath(destDir)+"/"+it.name)
|
||||
|
||||
val inChannel: FileChannel = FileInputStream(it).channel
|
||||
val outChannel: FileChannel = FileOutputStream(f).channel
|
||||
try {
|
||||
while (bytes >= 0) {
|
||||
outputStream.write(buffer, 0, bytes)
|
||||
bytesCopied += bytes
|
||||
progress((bytesCopied * 100 / fileLength).toInt())
|
||||
bytes = inputStream.read(buffer)
|
||||
}
|
||||
}catch (e : Exception){
|
||||
e.printStackTrace()
|
||||
Toast.makeText(context, e.message, Toast.LENGTH_LONG).show()
|
||||
inChannel.transferTo(0, inChannel.size(), outChannel)
|
||||
} finally {
|
||||
inChannel.close()
|
||||
outChannel.close()
|
||||
}
|
||||
|
||||
inputStream.close()
|
||||
outputStream.close()
|
||||
|
||||
it.delete()
|
||||
//
|
||||
// val mimeType =
|
||||
// MimeTypeMap.getSingleton().getMimeTypeFromExtension(it.extension) ?: "*/*"
|
||||
//
|
||||
// val destination = Uri.parse(destDir).run {
|
||||
// DocumentsContract.buildChildDocumentsUriUsingTree(this, DocumentsContract.getTreeDocumentId(this))
|
||||
// }
|
||||
//
|
||||
// val destUri = DocumentsContract.createDocument(
|
||||
// context.contentResolver,
|
||||
// destination,
|
||||
// mimeType,
|
||||
// it.name
|
||||
// ) ?: return@forEach
|
||||
//
|
||||
// val inputStream = it.inputStream()
|
||||
// val outputStream = context.contentResolver.openOutputStream(destUri) ?: return@forEach
|
||||
// val fileLength = it.length()
|
||||
// var bytesCopied: Long = 0
|
||||
// val buffer = ByteArray(DEFAULT_BUFFER_SIZE)
|
||||
// var bytes = inputStream.read(buffer)
|
||||
//
|
||||
// try {
|
||||
// while (bytes >= 0) {
|
||||
// outputStream.write(buffer, 0, bytes)
|
||||
// bytesCopied += bytes
|
||||
// progress((bytesCopied * 100 / fileLength).toInt())
|
||||
// bytes = inputStream.read(buffer)
|
||||
// }
|
||||
// }catch (e : Exception){
|
||||
// e.printStackTrace()
|
||||
// Toast.makeText(context, e.message, Toast.LENGTH_LONG).show()
|
||||
// }
|
||||
//
|
||||
// inputStream.close()
|
||||
// outputStream.close()
|
||||
//
|
||||
// it.delete()
|
||||
}
|
||||
}
|
||||
originDir.delete()
|
||||
|
|
|
|||
|
|
@ -96,6 +96,12 @@
|
|||
android:paddingStart="10dp"
|
||||
android:paddingEnd="0dp"
|
||||
android:textSize="15sp"
|
||||
android:shadowColor="@color/black"
|
||||
android:shadowDx="4"
|
||||
android:shadowDy="4"
|
||||
android:shadowRadius="2"
|
||||
android:textColor="@color/white"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toTopOf="@+id/output"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
|
|
@ -153,9 +159,13 @@
|
|||
android:paddingTop="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:paddingBottom="10dp"
|
||||
android:shadowRadius="1.5"
|
||||
android:textSize="12sp"
|
||||
android:textStyle="bold"
|
||||
android:shadowColor="@color/black"
|
||||
android:shadowDx="4"
|
||||
android:shadowDy="4"
|
||||
android:shadowRadius="2"
|
||||
android:textColor="@color/white"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
|
|
|||
Loading…
Reference in a new issue