mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
Grid settings
This commit is contained in:
parent
5c84e204d2
commit
3f05ce9acb
@ -43,7 +43,9 @@ class Home : Fragment() {
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
val recyclerView = view.findViewById<RecyclerView>(R.id.recview)
|
val recyclerView = view.findViewById<RecyclerView>(R.id.recview)
|
||||||
recyclerView.layoutManager = GridLayoutManager(view.context, resources.getInteger(R.integer.grid_items))
|
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||||
|
val grid = sharedPreferences.getString("grid", resources.getInteger(R.integer.grid_items).toString())!!
|
||||||
|
recyclerView.layoutManager = GridLayoutManager(view.context, grid.toInt())
|
||||||
val progressbar = view.findViewById<ProgressBar>(R.id.progressBar)
|
val progressbar = view.findViewById<ProgressBar>(R.id.progressBar)
|
||||||
fetchJson(progressbar,recyclerView)
|
fetchJson(progressbar,recyclerView)
|
||||||
refreshLayout = view.findViewById(R.id.home_refresh)
|
refreshLayout = view.findViewById(R.id.home_refresh)
|
||||||
|
@ -26,10 +26,11 @@ import com.github.libretube.obj.Subscribe
|
|||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.io.InputStream
|
||||||
import java.util.zip.ZipFile
|
import java.util.zip.ZipFile
|
||||||
|
|
||||||
class Settings : PreferenceFragmentCompat() {
|
class Settings : PreferenceFragmentCompat() {
|
||||||
|
val TAG = "Settings"
|
||||||
companion object {
|
companion object {
|
||||||
lateinit var getContent: ActivityResultLauncher<String>
|
lateinit var getContent: ActivityResultLauncher<String>
|
||||||
}
|
}
|
||||||
@ -39,27 +40,34 @@ class Settings : PreferenceFragmentCompat() {
|
|||||||
getContent = registerForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri? ->
|
getContent = registerForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri? ->
|
||||||
|
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
var zipfile = ZipFile(UriUtils.uri2File(uri))
|
try{
|
||||||
|
Log.d(TAG,UriUtils.uri2File(uri).toString())
|
||||||
|
val file = UriUtils.uri2File(uri)
|
||||||
|
var inputStream: InputStream? = null
|
||||||
|
if (file.extension == "zip") {
|
||||||
|
var zipfile = ZipFile(file)
|
||||||
|
|
||||||
var zipentry =
|
var zipentry =
|
||||||
zipfile.getEntry("Takeout/YouTube and YouTube Music/subscriptions/subscriptions.csv")
|
zipfile.getEntry("Takeout/YouTube and YouTube Music/subscriptions/subscriptions.csv")
|
||||||
|
|
||||||
var inputStream = zipfile.getInputStream(zipentry)
|
inputStream = zipfile.getInputStream(zipentry)
|
||||||
|
}else if(file.extension == "csv"){
|
||||||
val baos = ByteArrayOutputStream()
|
inputStream = file.inputStream()
|
||||||
|
|
||||||
inputStream.use { it.copyTo(baos) }
|
|
||||||
|
|
||||||
var subscriptions = baos.toByteArray().decodeToString()
|
|
||||||
|
|
||||||
var subscribedCount = 0
|
|
||||||
|
|
||||||
for (text in subscriptions.lines()) {
|
|
||||||
if (text.take(24) != "Channel Id,Channel Url,C" && !text.take(24).isEmpty()) {
|
|
||||||
subscribe(text.take(24))
|
|
||||||
subscribedCount++
|
|
||||||
Log.d(TAG, "subscribed: " + text + " total: " + subscribedCount)
|
|
||||||
}
|
}
|
||||||
|
val baos = ByteArrayOutputStream()
|
||||||
|
|
||||||
|
inputStream?.use { it.copyTo(baos) }
|
||||||
|
|
||||||
|
var subscriptions = baos.toByteArray().decodeToString()
|
||||||
|
|
||||||
|
var subscribedCount = 0
|
||||||
|
|
||||||
|
for (text in subscriptions.lines()) {
|
||||||
|
if (text.take(24) != "Channel Id,Channel Url,C" && text.take(24).isNotEmpty()) {
|
||||||
|
subscribe(text.take(24))
|
||||||
|
subscribedCount++
|
||||||
|
Log.d(TAG, "subscribed: " + text + " total: " + subscribedCount)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
@ -67,7 +75,15 @@ class Settings : PreferenceFragmentCompat() {
|
|||||||
"Subscribed to " + subscribedCount + " channels.",
|
"Subscribed to " + subscribedCount + " channels.",
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
|
}catch (e: Exception){
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
R.string.error,
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -111,6 +127,8 @@ class Settings : PreferenceFragmentCompat() {
|
|||||||
Manifest.permission.MANAGE_EXTERNAL_STORAGE
|
Manifest.permission.MANAGE_EXTERNAL_STORAGE
|
||||||
), 1
|
), 1
|
||||||
) //permission request code is just an int
|
) //permission request code is just an int
|
||||||
|
}else{
|
||||||
|
getContent.launch("*/*")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (ActivityCompat.checkSelfPermission(
|
if (ActivityCompat.checkSelfPermission(
|
||||||
@ -129,12 +147,10 @@ class Settings : PreferenceFragmentCompat() {
|
|||||||
),
|
),
|
||||||
1
|
1
|
||||||
)
|
)
|
||||||
|
}else{
|
||||||
|
getContent.launch("*/*")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getContent.launch("application/zip")
|
|
||||||
|
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
app/src/main/res/drawable/ic_column.xml
Normal file
10
app/src/main/res/drawable/ic_column.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M10,18h5L15,5h-5v13zM4,18h5L9,5L4,5v13zM16,5v13h5L21,5h-5z"/>
|
||||||
|
</vector>
|
@ -192,12 +192,12 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:layout_toEndOf="@+id/player_channelImage"
|
|
||||||
android:layout_toStartOf="@+id/player_subscribe"
|
android:layout_toStartOf="@+id/player_subscribe"
|
||||||
android:text=""
|
android:layout_toEndOf="@+id/player_channelImage"
|
||||||
android:textStyle="bold"
|
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="1"/>
|
android:maxLines="1"
|
||||||
|
android:text=""
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
|
@ -51,7 +51,9 @@
|
|||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
app:layout_constraintEnd_toEndOf="@+id/thumbnailcard"
|
app:layout_constraintEnd_toEndOf="@+id/thumbnailcard"
|
||||||
app:layout_constraintStart_toEndOf="@+id/channel_image"
|
app:layout_constraintStart_toEndOf="@+id/channel_image"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/thumbnailcard" />
|
app:layout_constraintTop_toBottomOf="@+id/thumbnailcard"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="2"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textView_channel"
|
android:id="@+id/textView_channel"
|
||||||
|
@ -434,4 +434,11 @@
|
|||||||
<item>240p</item>
|
<item>240p</item>
|
||||||
<item>144p</item>
|
<item>144p</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
<string-array name="grid">
|
||||||
|
<item>1</item>
|
||||||
|
<item>2</item>
|
||||||
|
<item>3</item>
|
||||||
|
<item>4</item>
|
||||||
|
<item>5</item>
|
||||||
|
</string-array>
|
||||||
</resources>
|
</resources>
|
@ -33,7 +33,9 @@
|
|||||||
<string name="app_theme">App theme</string>
|
<string name="app_theme">App theme</string>
|
||||||
<string name="server_error">Server countered a problem. Maybe try another instance?</string>
|
<string name="server_error">Server countered a problem. Maybe try another instance?</string>
|
||||||
<string name="unknown_error">Network error!</string>
|
<string name="unknown_error">Network error!</string>
|
||||||
|
<string name="error">Something went wrong!</string>
|
||||||
<string name="empty">Username and Password can\'t be empty!</string>
|
<string name="empty">Username and Password can\'t be empty!</string>
|
||||||
<string name="notgmail">This is not your gmail account!</string>
|
<string name="notgmail">This is not your gmail account!</string>
|
||||||
<string name="defres">Default Video Resolution</string>
|
<string name="defres">Default Video Resolution</string>
|
||||||
|
<string name="grid">Choose the grid columns</string>
|
||||||
</resources>
|
</resources>
|
@ -1,11 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<androidx.preference.SwitchPreferenceCompat
|
|
||||||
app:key="darkMode"
|
|
||||||
app:title="Toggle dark mode"
|
|
||||||
app:isPreferenceVisible="false"/>
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
app:key="region"
|
app:key="region"
|
||||||
app:title="@string/region"
|
app:title="@string/region"
|
||||||
@ -59,5 +54,14 @@
|
|||||||
android:icon="@drawable/ic_hd"
|
android:icon="@drawable/ic_hd"
|
||||||
app:useSimpleSummaryProvider="true"
|
app:useSimpleSummaryProvider="true"
|
||||||
/>
|
/>
|
||||||
|
<ListPreference
|
||||||
|
app:title="@string/grid"
|
||||||
|
app:key="grid"
|
||||||
|
app:entries="@array/grid"
|
||||||
|
app:entryValues="@array/grid"
|
||||||
|
app:defaultValue=""
|
||||||
|
android:icon="@drawable/ic_column"
|
||||||
|
app:useSimpleSummaryProvider="true"
|
||||||
|
/>
|
||||||
|
|
||||||
</androidx.preference.PreferenceScreen>
|
</androidx.preference.PreferenceScreen>
|
Loading…
x
Reference in New Issue
Block a user