download location settings

This commit is contained in:
Bnyro 2022-06-09 14:22:07 +02:00
parent 3100e80830
commit 4dc6e1024b
8 changed files with 57 additions and 58 deletions

View File

@ -11,6 +11,8 @@ import android.net.Uri
import android.os.Build
import android.os.Environment
import android.os.Environment.DIRECTORY_DOWNLOADS
import android.os.Environment.DIRECTORY_MOVIES
import android.os.Environment.DIRECTORY_MUSIC
import android.os.IBinder
import android.util.Log
import androidx.core.app.NotificationCompat
@ -82,20 +84,21 @@ class DownloadService : Service() {
Log.e(TAG, "Directory already have")
}
// create LibreTube folder in Downloads
/*
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
val downloadsDirectory = sharedPreferences.getString("download_directory_path", "")
Log.i(TAG, downloadsDirectory!!)
libretubeDir = if (downloadsDirectory == "") File(
Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS),
"LibreTube"
)
else File(downloadsDirectory)
*/
val downloadLocationPref = sharedPreferences.getString("download_location", "")
val folderName = sharedPreferences.getString("download_folder", "")
val location = when (downloadLocationPref) {
"downloads" -> Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS)
"music" -> Environment.getExternalStoragePublicDirectory(DIRECTORY_MUSIC)
"movies" -> Environment.getExternalStoragePublicDirectory(DIRECTORY_MOVIES)
"sdcard" -> Environment.getExternalStorageDirectory()
else -> Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS)
}
libretubeDir = File(
Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS),
"LibreTube"
location,
folderName
)
if (!libretubeDir.exists()) libretubeDir.mkdirs()
Log.i(TAG, libretubeDir.toString())

View File

@ -40,7 +40,7 @@ class ShareDialog(private val videoId: String) : DialogFragment() {
intent.action = Intent.ACTION_SEND
intent.putExtra(Intent.EXTRA_TEXT, url)
intent.type = "text/plain"
context?.startActivity(Intent.createChooser(intent, "Share Url To:"))
context?.startActivity(Intent.createChooser(intent, context?.getString(R.string.shareTo)))
}
.show()
} ?: throw IllegalStateException("Activity cannot be null")

View File

@ -1,10 +1,7 @@
package com.github.libretube.preferences
import android.content.Intent
import android.os.Bundle
import android.provider.DocumentsContract
import android.widget.TextView
import androidx.core.net.toUri
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
@ -12,7 +9,7 @@ import com.github.libretube.R
class AdvancedSettings : PreferenceFragmentCompat() {
val TAG = "AdvancedSettings"
private val directoryRequestCode = 9999
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.advanced_settings, rootKey)
@ -26,36 +23,5 @@ class AdvancedSettings : PreferenceFragmentCompat() {
sharedPreferences.edit().remove("search_history").commit()
true
}
// doesn't work yet
val directory = findPreference<Preference>("download_directory")
directory?.setOnPreferenceClickListener {
val sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(requireContext())
val pickerInitialUri = sharedPreferences
.getString("download_directory_path", "")?.toUri()
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
intent.addCategory(Intent.CATEGORY_DEFAULT)
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, pickerInitialUri)
startActivityForResult(
Intent.createChooser(intent, "Choose directory"),
directoryRequestCode
)
true
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
directoryRequestCode -> {
val directoryUri = data?.data
// save selected download directory to the shared preferences
val sharedPref = PreferenceManager
.getDefaultSharedPreferences(requireContext())
sharedPref.edit().putString("download_directory_path", directoryUri.toString())
.apply()
}
}
}
}

View File

@ -1,6 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:width="24dp"
android:height="24dp"
android:viewportWidth="48"
android:viewportHeight="48"
android:tint="?android:attr/colorControlNormal">

View File

@ -6,5 +6,5 @@
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M20,6h-8l-2,-2L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,8c0,-1.1 -0.9,-2 -2,-2zM20,18L4,18L4,8h16v10z" />
android:pathData="M10,4H4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8c0,-1.1 -0.9,-2 -2,-2h-8l-2,-2z" />
</vector>

View File

@ -630,4 +630,18 @@
<item>2F</item>
</string-array>
<string-array name="downloadLocation">
<item>@string/downloads_directory</item>
<item>@string/music_directory</item>
<item>@string/movies_directory</item>
<item>@string/sdcard</item>
</string-array>
<string-array name="downloadLocationValues">
<item>downloads</item>
<item>music</item>
<item>movies</item>
<item>sdcard</item>
</string-array>
</resources>

View File

@ -123,8 +123,8 @@
<string name="downloads">Downloads</string>
<string name="video_format">Video format</string>
<string name="video_format_summary">The video format downloaded videos get converted to (only applies if both, audio and video, are downloaded).</string>
<string name="download_directory">Download directory</string>
<string name="download_directory_summary">The directory where your downloaded media gets stored.</string>
<string name="download_directory">Download location</string>
<string name="download_directory_summary">The location where your downloaded media gets stored.</string>
<string name="website_summary">Visit our website to learn more about the app and its features.</string>
<string name="contributing">Contributing</string>
<string name="contributing_summary">Whether you have ideas, translations, design changes, code cleaning, or real heavy code changes, help is always welcome. The more is done the better it gets!</string>
@ -144,4 +144,12 @@
<string name="no_replies">This comment has no replies.</string>
<string name="authors">Authors</string>
<string name="authors_summary">Find out who\'s behind Team LibreTube and does the magic.</string>
<string name="download_folder">Directory name</string>
<string name="download_folder_summary">The name of the directory downloaded media gets stored in.</string>
<string name="internal_storage">Internal storage</string>
<string name="downloads_directory">Downloads directory</string>
<string name="sdcard">SD card</string>
<string name="music_directory">Music directory</string>
<string name="movies_directory">Movies directory</string>
<string name="shareTo">Share Url To:</string>
</resources>

View File

@ -35,13 +35,21 @@
app:summary="@string/video_format_summary"
app:icon="@drawable/ic_videocam" />
<!--
<Preference
app:key="download_directory"
<ListPreference
app:key="download_location"
app:title="@string/download_directory"
app:summary="@string/download_directory_summary"
app:icon="@drawable/ic_folder" />
-->
android:defaultValue="downloads"
android:entries="@array/downloadLocation"
android:entryValues="@array/downloadLocationValues"
app:icon="@drawable/ic_download" />
<EditTextPreference
app:key="download_folder"
app:title="@string/download_folder"
app:summary="@string/download_folder_summary"
app:icon="@drawable/ic_folder"
android:defaultValue="LibreTube" />
</PreferenceCategory>