added download logs support
This commit is contained in:
parent
1328e77711
commit
9574788ae8
11 changed files with 383 additions and 9 deletions
|
|
@ -120,7 +120,7 @@ dependencies {
|
|||
|
||||
implementation "androidx.appcompat:appcompat:$appCompatVer"
|
||||
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
|
||||
implementation 'com.google.android.material:material:1.8.0'
|
||||
implementation 'com.google.android.material:material:1.7.0'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'androidx.core:core:1.9.0'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.2.1'
|
||||
|
|
|
|||
|
|
@ -55,6 +55,26 @@
|
|||
<data android:mimeType="text/plain" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.downloadLogs.DownloadLogListActivity"
|
||||
android:configChanges="layoutDirection|locale"
|
||||
android:parentActivityName=".MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="ytdlnis.downloadLogs.DownloadLogListActivity" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.downloadLogs.DownloadLogActivity"
|
||||
android:configChanges="layoutDirection|locale"
|
||||
android:parentActivityName=".ui.downloadLogs.DownloadLogListActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="ytdlnis.downloadLogs.DownloadLogActivity" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.settings.SettingsActivity"
|
||||
android:configChanges="layoutDirection|locale"
|
||||
|
|
@ -73,7 +93,7 @@
|
|||
android:label="@string/run_command"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="ytdlnis.page.CustomCommandActivity" />
|
||||
<action android:name="ytdlnis.CustomCommandActivity" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
|
|
@ -82,10 +102,6 @@
|
|||
<data android:mimeType="text/plain" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<!-- <service-->
|
||||
<!-- android:name=".DownloaderService"-->
|
||||
<!-- android:enabled="true"-->
|
||||
<!-- android:exported="false" />-->
|
||||
<receiver android:name=".receiver.CancelDownloadNotificationReceiver" />
|
||||
|
||||
<service
|
||||
|
|
|
|||
|
|
@ -0,0 +1,71 @@
|
|||
package com.deniscerri.ytdlnis.adapter
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.TextView
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.recyclerview.widget.AsyncDifferConfig
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.deniscerri.ytdlnis.R
|
||||
import java.io.File
|
||||
|
||||
class DownloadLogsAdapter(onItemClickListener: OnItemClickListener, activity: Activity) : ListAdapter<File?, DownloadLogsAdapter.ViewHolder>(AsyncDifferConfig.Builder(DIFF_CALLBACK).build()) {
|
||||
private val onItemClickListener: OnItemClickListener
|
||||
private val activity: Activity
|
||||
|
||||
init {
|
||||
this.onItemClickListener = onItemClickListener
|
||||
this.activity = activity
|
||||
}
|
||||
|
||||
class ViewHolder(itemView: View, onItemClickListener: OnItemClickListener?) : RecyclerView.ViewHolder(itemView) {
|
||||
val item: ConstraintLayout
|
||||
|
||||
init {
|
||||
item = itemView.findViewById(R.id.download_log_item_constraint)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val cardView = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.download_log_item, parent, false)
|
||||
return ViewHolder(cardView, onItemClickListener)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val item = getItem(position)
|
||||
val card = holder.item
|
||||
|
||||
card.findViewById<TextView>(R.id.title).text = item?.name
|
||||
|
||||
card.findViewById<Button>(R.id.delete).setOnClickListener {
|
||||
onItemClickListener.onDeleteClick(item!!)
|
||||
}
|
||||
|
||||
card.setOnClickListener {
|
||||
onItemClickListener.onItemClick(item!!)
|
||||
}
|
||||
}
|
||||
|
||||
interface OnItemClickListener {
|
||||
fun onItemClick(file: File)
|
||||
fun onDeleteClick(file: File)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val DIFF_CALLBACK: DiffUtil.ItemCallback<File> = object : DiffUtil.ItemCallback<File>() {
|
||||
override fun areItemsTheSame(oldItem: File, newItem: File): Boolean {
|
||||
return oldItem == newItem
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: File, newItem: File): Boolean {
|
||||
return oldItem.absolutePath == newItem.absolutePath
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +1,27 @@
|
|||
package com.deniscerri.ytdlnis.ui
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import com.deniscerri.ytdlnis.R
|
||||
|
||||
class MoreFragment : PreferenceFragmentCompat() {
|
||||
private lateinit var mainSharedPreferences: SharedPreferences
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.more_preferences, rootKey)
|
||||
mainSharedPreferences = requireContext().getSharedPreferences("root_preferences", Activity.MODE_PRIVATE)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "MoreFragment"
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
findPreference<Preference>("download_logs")!!.isVisible =
|
||||
mainSharedPreferences.getBoolean("log_downloads", false)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package com.deniscerri.ytdlnis.ui.downloadLogs
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.os.FileObserver
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.widget.NestedScrollView
|
||||
import com.deniscerri.ytdlnis.R
|
||||
import com.google.android.material.appbar.MaterialToolbar
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.io.File
|
||||
|
||||
|
||||
class DownloadLogActivity : AppCompatActivity() {
|
||||
private lateinit var content: TextView
|
||||
private lateinit var contentScrollView : NestedScrollView
|
||||
private lateinit var topAppBar: MaterialToolbar
|
||||
var context: Context? = null
|
||||
|
||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_download_log)
|
||||
context = baseContext
|
||||
|
||||
topAppBar = findViewById(R.id.title)
|
||||
topAppBar.setNavigationOnClickListener { onBackPressedDispatcher.onBackPressed() }
|
||||
|
||||
content = findViewById(R.id.content)
|
||||
contentScrollView = findViewById(R.id.content_scrollview)
|
||||
|
||||
val path = intent.getStringExtra("path")
|
||||
if (path == null) onBackPressedDispatcher.onBackPressed()
|
||||
|
||||
val file = File(path!!)
|
||||
topAppBar.title = file.name
|
||||
content.text = file.readText()
|
||||
|
||||
val observer: FileObserver = object : FileObserver(file, MODIFY) {
|
||||
override fun onEvent(event: Int, p: String?) {
|
||||
runOnUiThread{
|
||||
content.text = File(path).readText()
|
||||
content.scrollTo(0, content.height)
|
||||
}
|
||||
}
|
||||
}
|
||||
observer.startWatching();
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "DownloadLogActivity"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
package com.deniscerri.ytdlnis.ui.downloadLogs
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.os.FileObserver
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.deniscerri.ytdlnis.R
|
||||
import com.deniscerri.ytdlnis.adapter.DownloadLogsAdapter
|
||||
import com.google.android.material.appbar.MaterialToolbar
|
||||
import java.io.File
|
||||
|
||||
|
||||
class DownloadLogListActivity : AppCompatActivity(), DownloadLogsAdapter.OnItemClickListener {
|
||||
private lateinit var recyclerView: RecyclerView
|
||||
private lateinit var downloadLogAdapter: DownloadLogsAdapter
|
||||
private lateinit var noResults: RelativeLayout
|
||||
private lateinit var fileList: MutableList<File>
|
||||
private lateinit var topAppBar: MaterialToolbar
|
||||
var context: Context? = null
|
||||
|
||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_download_log_list)
|
||||
context = baseContext
|
||||
|
||||
topAppBar = findViewById(R.id.logs_toolbar)
|
||||
topAppBar.setNavigationOnClickListener { onBackPressedDispatcher.onBackPressed() }
|
||||
|
||||
downloadLogAdapter =
|
||||
DownloadLogsAdapter(
|
||||
this,
|
||||
this@DownloadLogListActivity
|
||||
)
|
||||
recyclerView = findViewById(R.id.logs_recyclerview)
|
||||
recyclerView.layoutManager = LinearLayoutManager(context)
|
||||
recyclerView.adapter = downloadLogAdapter
|
||||
noResults = findViewById(R.id.no_results)
|
||||
noResults.visibility = View.GONE
|
||||
|
||||
val logFolder = File(filesDir.absolutePath + "/logs")
|
||||
updateList(logFolder)
|
||||
|
||||
val observer: FileObserver = object : FileObserver(logFolder) {
|
||||
override fun onEvent(event: Int, path: String?) {
|
||||
when(event) {
|
||||
CREATE, DELETE -> updateList(logFolder)
|
||||
}
|
||||
}
|
||||
}
|
||||
observer.startWatching();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private fun updateList(logFolder: File){
|
||||
fileList = mutableListOf()
|
||||
fileList.addAll(logFolder.listFiles()!!)
|
||||
if (fileList.isNotEmpty()) {
|
||||
fileList.reverse()
|
||||
noResults.visibility = View.GONE
|
||||
downloadLogAdapter.submitList(fileList.toList())
|
||||
}else{
|
||||
noResults.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "DownloadLogActivity"
|
||||
}
|
||||
|
||||
override fun onItemClick(file: File) {
|
||||
val intent = Intent(this, DownloadLogActivity::class.java)
|
||||
intent.putExtra("path", file.absolutePath)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
override fun onDeleteClick(file: File) {
|
||||
file.delete()
|
||||
}
|
||||
}
|
||||
51
app/src/main/res/layout/activity_download_log.xml
Normal file
51
app/src/main/res/layout/activity_download_log.xml
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.deniscerri.ytdlnis.ui.CustomCommandActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:liftOnScroll="false"
|
||||
android:background="@android:color/transparent"
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:id="@+id/title"
|
||||
android:elevation="0dp"
|
||||
android:layout_width="match_parent"
|
||||
app:navigationIcon="@drawable/ic_back"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
android:id="@+id/content_scrollview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:paddingBottom="150dp"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/content"
|
||||
android:padding="10dp"
|
||||
android:textSize="15sp"
|
||||
android:layout_width="match_parent"
|
||||
android:textIsSelectable="true"
|
||||
android:gravity="bottom"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
|
||||
<include layout="@layout/history_no_results"
|
||||
android:visibility="gone" />
|
||||
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
42
app/src/main/res/layout/activity_download_log_list.xml
Normal file
42
app/src/main/res/layout/activity_download_log_list.xml
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.deniscerri.ytdlnis.ui.CustomCommandActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:liftOnScroll="false"
|
||||
android:background="@android:color/transparent"
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:id="@+id/logs_toolbar"
|
||||
android:elevation="0dp"
|
||||
app:title="@string/logs"
|
||||
android:layout_width="match_parent"
|
||||
app:navigationIcon="@drawable/ic_back"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
android:id="@+id/logs_recyclerview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
>
|
||||
|
||||
</androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
|
||||
<include layout="@layout/history_no_results"
|
||||
android:visibility="gone" />
|
||||
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
40
app/src/main/res/layout/download_log_item.xml
Normal file
40
app/src/main/res/layout/download_log_item.xml
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:padding="15dp">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/download_log_item_constraint"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:padding="10dp"
|
||||
android:textSize="18sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/delete"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/delete"
|
||||
style="@style/Widget.Material3.Button.IconButton.Filled.Tonal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:icon="@drawable/ic_delete_all"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
@ -180,4 +180,5 @@
|
|||
<string name="error_updating_formats">Error updating formats!</string>
|
||||
<string name="log_downloads">Log Downloads</string>
|
||||
<string name="log_downloads_summary">Create a log file for each download</string>
|
||||
<string name="new_update">New Update</string>
|
||||
</resources>
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
app:icon="@drawable/ic_terminal"
|
||||
app:key="run_command"
|
||||
app:title="@string/terminal">
|
||||
<intent android:action="ytdlnis.page.CustomCommandActivity" />
|
||||
<intent android:action="ytdlnis.CustomCommandActivity" />
|
||||
</Preference>
|
||||
|
||||
<Preference
|
||||
|
|
@ -30,7 +30,7 @@
|
|||
app:key="download_logs"
|
||||
app:allowDividerBelow="true"
|
||||
app:title="@string/logs">
|
||||
<intent android:action="ytdlnis.page.DownloadLogsActivity" />
|
||||
<intent android:action="ytdlnis.downloadLogs.DownloadLogListActivity" />
|
||||
</Preference>
|
||||
|
||||
<Preference
|
||||
|
|
@ -38,7 +38,7 @@
|
|||
app:key="command_templates"
|
||||
app:allowDividerBelow="true"
|
||||
app:title="@string/command_templates">
|
||||
<intent android:action="ytdlnis.page.DownloadLogsActivity" />
|
||||
<intent android:action="ytdlnis.CommandTemplatesActivity" />
|
||||
</Preference>
|
||||
|
||||
<Preference
|
||||
|
|
|
|||
Loading…
Reference in a new issue