added file picker
This commit is contained in:
parent
598b8e0171
commit
55e94c7b66
13 changed files with 110 additions and 26 deletions
|
|
@ -1,7 +1,11 @@
|
|||
package com.deniscerri.ytdlnis
|
||||
|
||||
import android.app.Application
|
||||
import android.app.UiModeManager.MODE_NIGHT_NO
|
||||
import android.app.UiModeManager.MODE_NIGHT_YES
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.work.Configuration
|
||||
import androidx.work.WorkManager
|
||||
|
|
@ -32,6 +36,8 @@ class App : Application() {
|
|||
false
|
||||
)
|
||||
|
||||
val sharedPreferences = getSharedPreferences("root_preferences", MODE_PRIVATE)
|
||||
|
||||
applicationScope = CoroutineScope(SupervisorJob())
|
||||
applicationScope.launch((Dispatchers.IO)) {
|
||||
try {
|
||||
|
|
@ -42,12 +48,19 @@ class App : Application() {
|
|||
}
|
||||
}
|
||||
|
||||
AppCompatDelegate.setDefaultNightMode(
|
||||
when(sharedPreferences.getString("ytdlnis_theme", "Default")){
|
||||
"Default" -> MODE_NIGHT_FOLLOW_SYSTEM
|
||||
"Dark" -> MODE_NIGHT_YES
|
||||
else -> MODE_NIGHT_NO
|
||||
}
|
||||
)
|
||||
|
||||
WorkManager.initialize(
|
||||
this@App,
|
||||
Configuration.Builder()
|
||||
.setExecutor(Executors.newFixedThreadPool(
|
||||
getSharedPreferences("root_preferences", MODE_PRIVATE)
|
||||
.getInt("concurrent_downloads", 1)))
|
||||
sharedPreferences.getInt("concurrent_downloads", 1)))
|
||||
.build())
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,9 +33,11 @@ import com.deniscerri.ytdlnis.ui.HomeFragment
|
|||
import com.deniscerri.ytdlnis.ui.downloads.DownloadQueueActivity
|
||||
import com.deniscerri.ytdlnis.ui.more.settings.SettingsActivity
|
||||
import com.deniscerri.ytdlnis.util.UpdateUtil
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.navigation.NavigationBarView
|
||||
import com.google.android.material.navigation.NavigationView
|
||||
import com.google.android.material.navigationrail.NavigationRailView
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import java.io.BufferedReader
|
||||
|
|
@ -95,17 +97,16 @@ class MainActivity : AppCompatActivity() {
|
|||
val sharedPreferences = getSharedPreferences("root_preferences", Activity.MODE_PRIVATE)
|
||||
|
||||
val startDestination = sharedPreferences.getString("start_destination", "")
|
||||
val graph = navHostFragment.navController.navInflater.inflate(R.navigation.nav_graph)
|
||||
val graph = navController.navInflater.inflate(R.navigation.nav_graph)
|
||||
when(startDestination) {
|
||||
"History" -> graph.setStartDestination(R.id.historyFragment)
|
||||
"More" -> graph.setStartDestination(R.id.moreFragment)
|
||||
else -> graph.setStartDestination(R.id.homeFragment)
|
||||
"History" -> graph.setStartDestination(R.id.historyFragment)
|
||||
"More" -> if (navigationView is NavigationBarView) graph.setStartDestination(R.id.moreFragment) else graph.setStartDestination(R.id.homeFragment)
|
||||
else -> graph.setStartDestination(R.id.homeFragment)
|
||||
}
|
||||
navHostFragment.navController.graph = graph
|
||||
|
||||
|
||||
navController.graph = graph
|
||||
|
||||
if (navigationView is NavigationBarView){
|
||||
(navigationView as NavigationBarView).selectedItemId = graph.startDestinationId
|
||||
(navigationView as NavigationBarView).setupWithNavController(navController)
|
||||
(navigationView as NavigationBarView).setOnItemReselectedListener {
|
||||
when (it.itemId) {
|
||||
|
|
@ -125,6 +126,7 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
if (navigationView is NavigationView){
|
||||
(navigationView as NavigationView).setCheckedItem(graph.startDestinationId)
|
||||
(navigationView as NavigationView).setupWithNavController(navController)
|
||||
//terminate button
|
||||
(navigationView as NavigationView).menu.getItem(7).setOnMenuItemClickListener {
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class ActiveDownloadsFragment() : Fragment(), ActiveDownloadAdapter.OnItemClickL
|
|||
val dpWidth: Float = displayMetrics.widthPixels / displayMetrics.density
|
||||
if (dpWidth > 1200 && landScape){
|
||||
activeRecyclerView.layoutManager = GridLayoutManager(context, 3)
|
||||
}else if (landScape || dpWidth >= 700){
|
||||
}else if (landScape || dpWidth >= 650){
|
||||
activeRecyclerView.layoutManager = GridLayoutManager(context, 2)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ class CancelledDownloadsFragment : Fragment(), GenericDownloadAdapter.OnItemClic
|
|||
val dpWidth: Float = displayMetrics.widthPixels / displayMetrics.density
|
||||
if (dpWidth > 1200 && landScape){
|
||||
cancelledRecyclerView.layoutManager = GridLayoutManager(context, 3)
|
||||
}else if (landScape || dpWidth >= 700){
|
||||
}else if (landScape || dpWidth >= 650){
|
||||
cancelledRecyclerView.layoutManager = GridLayoutManager(context, 2)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ class ErroredDownloadsFragment : Fragment(), GenericDownloadAdapter.OnItemClickL
|
|||
val dpWidth: Float = displayMetrics.widthPixels / displayMetrics.density
|
||||
if (dpWidth > 1200 && landScape){
|
||||
erroredRecyclerView.layoutManager = GridLayoutManager(context, 3)
|
||||
}else if (landScape || dpWidth >= 700){
|
||||
}else if (landScape || dpWidth >= 650){
|
||||
erroredRecyclerView.layoutManager = GridLayoutManager(context, 2)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ class HistoryFragment : Fragment(), HistoryAdapter.OnItemClickListener{
|
|||
val dpWidth: Float = displayMetrics.widthPixels / displayMetrics.density
|
||||
if (dpWidth > 1200 && landScape){
|
||||
recyclerView?.layoutManager = GridLayoutManager(context, 3)
|
||||
}else if (landScape || dpWidth >= 700){
|
||||
}else if (landScape || dpWidth >= 650){
|
||||
recyclerView?.layoutManager = GridLayoutManager(context, 2)
|
||||
}
|
||||
noResults?.visibility = GONE
|
||||
|
|
@ -297,6 +297,9 @@ class HistoryFragment : Fragment(), HistoryAdapter.OnItemClickListener{
|
|||
historyViewModel.setSorting(HistoryRepository.HistorySortType.FILESIZE)
|
||||
changeSortIcon(filesize, historyViewModel.sortOrder.value!!)
|
||||
}
|
||||
val displayMetrics = DisplayMetrics()
|
||||
requireActivity().windowManager.defaultDisplay.getMetrics(displayMetrics)
|
||||
sortSheet!!.behavior.peekHeight = displayMetrics.heightPixels
|
||||
sortSheet!!.show()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ class QueuedDownloadsFragment : Fragment(), GenericDownloadAdapter.OnItemClickLi
|
|||
val dpWidth: Float = displayMetrics.widthPixels / displayMetrics.density
|
||||
if (dpWidth > 1200 && landScape){
|
||||
queuedRecyclerView.layoutManager = GridLayoutManager(context, 3)
|
||||
}else if (landScape || dpWidth >= 700){
|
||||
}else if (landScape || dpWidth >= 650){
|
||||
queuedRecyclerView.layoutManager = GridLayoutManager(context, 2)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import android.os.Bundle
|
|||
import android.os.Environment
|
||||
import android.os.PowerManager
|
||||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
|
|
@ -33,6 +34,7 @@ import java.util.*
|
|||
|
||||
class SettingsFragment : PreferenceFragmentCompat() {
|
||||
private var language: ListPreference? = null
|
||||
private var theme: ListPreference? = null
|
||||
private var ignoreBatteryOptimization: Preference? = null
|
||||
private var musicPath: Preference? = null
|
||||
private var videoPath: Preference? = null
|
||||
|
|
@ -102,6 +104,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
requireContext().getSharedPreferences("root_preferences", Activity.MODE_PRIVATE)
|
||||
val editor = preferences.edit()
|
||||
language = findPreference("app_language")
|
||||
theme = findPreference("ytdlnis_theme")
|
||||
ignoreBatteryOptimization = findPreference("ignore_battery")
|
||||
musicPath = findPreference("music_path")
|
||||
videoPath = findPreference("video_path")
|
||||
|
|
@ -161,6 +164,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
ignoreBatteryOptimization!!.isVisible = false
|
||||
}
|
||||
|
||||
editor.putString("theme", theme!!.value)
|
||||
|
||||
if (preferences.getString("music_path", "")!!.isEmpty()) {
|
||||
editor.putString("music_path", getString(R.string.music_path))
|
||||
}
|
||||
|
|
@ -225,6 +230,32 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
true
|
||||
}
|
||||
|
||||
theme!!.summary = when(theme!!.value){
|
||||
"Default" -> getString(R.string.defaultValue)
|
||||
"Dark" -> getString(R.string.dark)
|
||||
else -> getString(R.string.light)
|
||||
}
|
||||
theme!!.onPreferenceChangeListener =
|
||||
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any ->
|
||||
when(newValue){
|
||||
"Default" -> {
|
||||
theme!!.summary = getString(R.string.defaultValue)
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||
}
|
||||
"Dark" -> {
|
||||
theme!!.summary = getString(R.string.dark)
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||
}
|
||||
else -> {
|
||||
theme!!.summary = getString(R.string.light)
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||
}
|
||||
}
|
||||
editor.putString("ytdlnis_theme", newValue.toString())
|
||||
editor.apply()
|
||||
true
|
||||
}
|
||||
|
||||
ignoreBatteryOptimization!!.onPreferenceClickListener =
|
||||
Preference.OnPreferenceClickListener {
|
||||
val intent = Intent()
|
||||
|
|
|
|||
5
app/src/main/res/drawable/baseline_format_paint_24.xml
Normal file
5
app/src/main/res/drawable/baseline_format_paint_24.xml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<vector android:height="24dp"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="?android:colorAccent" android:pathData="M18,4V3c0,-0.55 -0.45,-1 -1,-1H5c-0.55,0 -1,0.45 -1,1v4c0,0.55 0.45,1 1,1h12c0.55,0 1,-0.45 1,-1V6h1v4H9v11c0,0.55 0.45,1 1,1h2c0.55,0 1,-0.45 1,-1v-9h8V4h-3z"/>
|
||||
</vector>
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/downloads_card_constraintLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
@ -40,11 +41,11 @@
|
|||
<TextView
|
||||
android:id="@+id/downloads_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:paddingTop="10dp"
|
||||
android:paddingHorizontal="10dp"
|
||||
android:paddingTop="10dp"
|
||||
android:scrollbars="none"
|
||||
android:shadowColor="@color/black"
|
||||
android:shadowDx="4"
|
||||
|
|
@ -53,6 +54,7 @@
|
|||
android:textColor="#FFF"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toTopOf="@+id/downloads_info_bottom"
|
||||
app:layout_constraintEnd_toStartOf="@+id/downloads_download_button_type"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
|
@ -62,7 +64,7 @@
|
|||
android:id="@+id/downloads_info_bottom"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:padding="10dp"
|
||||
android:ellipsize="end"
|
||||
android:gravity="bottom"
|
||||
android:maxLines="1"
|
||||
|
|
@ -76,20 +78,25 @@
|
|||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/downloads_info_time"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintVertical_bias="1.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/downloads_title"
|
||||
app:layout_constraintVertical_bias="1.0" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/downloads_download_button_type" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/downloads_info_time"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:padding="10dp"
|
||||
android:ellipsize="end"
|
||||
android:gravity="bottom"
|
||||
android:maxLines="1"
|
||||
android:scrollbars="none"
|
||||
android:shadowColor="@color/black"
|
||||
android:shadowDx="4"
|
||||
android:shadowDy="4"
|
||||
android:shadowRadius="10"
|
||||
android:textColor="@color/white"
|
||||
android:textColor="#FFF"
|
||||
android:textSize="11sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
|
@ -102,14 +109,11 @@
|
|||
style="@style/Widget.Material3.ExtendedFloatingActionButton.Icon.Secondary"
|
||||
android:layout_width="55dp"
|
||||
android:layout_height="55dp"
|
||||
android:layout_marginHorizontal="20dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_margin="10dp"
|
||||
android:clickable="false"
|
||||
app:cornerRadius="10dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.375" />
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
|
|
|||
|
|
@ -163,4 +163,20 @@
|
|||
<item>History</item>
|
||||
<item>More</item>
|
||||
</array>
|
||||
|
||||
<array name="themes">
|
||||
<item>@string/defaultValue</item>
|
||||
<item>@string/dark</item>
|
||||
<item>@string/light</item>
|
||||
</array>
|
||||
|
||||
<array name="themes_values">
|
||||
<item>Default</item>
|
||||
<item>Dark</item>
|
||||
<item>Light</item>
|
||||
</array>
|
||||
|
||||
|
||||
<string name="dark">Dark</string>
|
||||
<string name="light">Light</string>
|
||||
</resources>
|
||||
|
|
@ -223,4 +223,5 @@
|
|||
<string name="codec">Codec</string>
|
||||
<string name="audio_samplerate">Audio Sample Rate</string>
|
||||
<string name="copied_to_clipboard">Copied To Clipboard</string>
|
||||
<string name="Theme">Theme</string>
|
||||
</resources>
|
||||
|
|
@ -8,6 +8,15 @@
|
|||
app:summary="en"
|
||||
app:title="@string/language" />
|
||||
|
||||
<ListPreference
|
||||
android:entries="@array/themes"
|
||||
android:entryValues="@array/themes_values"
|
||||
android:icon="@drawable/baseline_format_paint_24"
|
||||
app:defaultValue="Default"
|
||||
app:key="ytdlnis_theme"
|
||||
app:summary="@string/defaultValue"
|
||||
app:title="@string/Theme" />
|
||||
|
||||
<Preference
|
||||
app:icon="@drawable/ic_battery"
|
||||
app:key="ignore_battery"
|
||||
|
|
|
|||
Loading…
Reference in a new issue