Merge pull request #418 from Bnyro/about

About Section in Settings
This commit is contained in:
Bnyro 2022-06-07 16:02:20 +02:00 committed by GitHub
commit ba97d123c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 330 additions and 59 deletions

View File

@ -5,7 +5,6 @@ import android.app.PendingIntent
import android.app.Service import android.app.Service
import android.content.BroadcastReceiver import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Context.DOWNLOAD_SERVICE
import android.content.Intent import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
import android.net.Uri import android.net.Uri

View File

@ -10,23 +10,32 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
class UpdateAvailableDialog( class UpdateAvailableDialog(
private val versionTag: String, private val versionTag: String,
private val updateLink: String private val updateLink: String,
private val updateAvailable: Boolean
) : DialogFragment() { ) : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return activity?.let { return activity?.let {
MaterialAlertDialogBuilder(requireContext()) if (updateAvailable) {
.setTitle(context?.getString(R.string.update_available, versionTag)) MaterialAlertDialogBuilder(requireContext())
.setMessage(context?.getString(R.string.update_available_text)) .setTitle(context?.getString(R.string.update_available, versionTag))
.setNegativeButton(context?.getString(R.string.cancel)) { _, _ -> .setMessage(context?.getString(R.string.update_available_text))
dismiss() .setNegativeButton(context?.getString(R.string.cancel)) { _, _ ->
} dismiss()
.setPositiveButton(context?.getString(R.string.okay)) { _, _ -> }
val uri = Uri.parse(updateLink) .setPositiveButton(context?.getString(R.string.okay)) { _, _ ->
val intent = Intent(Intent.ACTION_VIEW).setData(uri) val uri = Uri.parse(updateLink)
startActivity(intent) val intent = Intent(Intent.ACTION_VIEW).setData(uri)
} startActivity(intent)
.show() }
.show()
} else {
MaterialAlertDialogBuilder(requireContext())
.setTitle(context?.getString(R.string.app_uptodate))
.setMessage(context?.getString(R.string.no_update_available))
.setPositiveButton(context?.getString(R.string.okay)) { _, _ -> }
.show()
}
} ?: throw IllegalStateException("Activity cannot be null") } ?: throw IllegalStateException("Activity cannot be null")
} }
} }

View File

@ -0,0 +1,71 @@
package com.github.libretube.preferences
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.text.Html
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.github.libretube.BuildConfig
import com.github.libretube.R
import com.github.libretube.util.checkUpdate
import com.google.android.material.card.MaterialCardView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class AboutFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_about, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val appVersion = view?.findViewById<TextView>(R.id.app_version)
appVersion.text = BuildConfig.VERSION_NAME
val website = view?.findViewById<MaterialCardView>(R.id.website)
website?.setOnClickListener {
openLink("https://libre-tube.github.io/")
}
val donate = view?.findViewById<MaterialCardView>(R.id.donate)
donate?.setOnClickListener {
openLink("https://libre-tube.github.io/#donate")
}
val contributing = view?.findViewById<MaterialCardView>(R.id.contributing)
contributing?.setOnClickListener {
openLink("https://github.com/libre-tube/LibreTube")
}
val license = view.findViewById<MaterialCardView>(R.id.license)
license?.setOnClickListener {
val licenseString = view?.context?.assets!!
.open("gpl3.html").bufferedReader().use {
it.readText()
}
val licenseHtml = if (Build.VERSION.SDK_INT >= 24) Html.fromHtml(licenseString, 1)
else Html.fromHtml(licenseString)
MaterialAlertDialogBuilder(view?.context!!)
.setPositiveButton(getString(R.string.okay)) { _, _ -> }
.setMessage(licenseHtml)
.create()
.show()
true
}
val update = view.findViewById<MaterialCardView>(R.id.update)
update?.setOnClickListener {
checkUpdate(childFragmentManager)
}
}
private fun openLink(link: String) {
val uri = Uri.parse(link)
val intent = Intent(Intent.ACTION_VIEW).setData(uri)
startActivity(intent)
}
}

View File

@ -3,12 +3,10 @@ package com.github.libretube.preferences
import android.Manifest import android.Manifest
import android.content.ContentResolver import android.content.ContentResolver
import android.content.Context import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.text.Html
import android.text.TextUtils import android.text.TextUtils
import android.util.Log import android.util.Log
import android.widget.Toast import android.widget.Toast
@ -27,8 +25,6 @@ import com.github.libretube.isCurrentViewMainSettings
import com.github.libretube.requireMainActivityRestart import com.github.libretube.requireMainActivityRestart
import com.github.libretube.util.RetrofitInstance import com.github.libretube.util.RetrofitInstance
import com.github.libretube.util.ThemeHelper import com.github.libretube.util.ThemeHelper
import com.github.libretube.util.checkUpdate
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.io.IOException import java.io.IOException
import java.io.InputStream import java.io.InputStream
import java.util.zip.ZipEntry import java.util.zip.ZipEntry
@ -112,11 +108,6 @@ class MainSettings : PreferenceFragmentCompat() {
} }
} }
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
try {
checkUpdate(childFragmentManager)
} catch (e: Exception) {
e.printStackTrace()
}
} }
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
@ -186,6 +177,13 @@ class MainSettings : PreferenceFragmentCompat() {
true true
} }
val about = findPreference<Preference>("about")
about?.setOnPreferenceClickListener {
val newFragment = AboutFragment()
navigateSettings(newFragment)
true
}
val importFromYt = findPreference<Preference>("import_from_yt") val importFromYt = findPreference<Preference>("import_from_yt")
importFromYt?.setOnPreferenceClickListener { importFromYt?.setOnPreferenceClickListener {
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE) val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
@ -238,34 +236,9 @@ class MainSettings : PreferenceFragmentCompat() {
} }
true true
} }
val about = findPreference<Preference>("about")
about?.setOnPreferenceClickListener {
val uri = Uri.parse("https://libre-tube.github.io/")
val intent = Intent(Intent.ACTION_VIEW).setData(uri)
startActivity(intent)
true
}
val license = findPreference<Preference>("license")
license?.setOnPreferenceClickListener {
val licenseString = view?.context?.assets!!
.open("gpl3.html").bufferedReader().use {
it.readText()
}
val licenseHtml = if (Build.VERSION.SDK_INT >= 24) Html.fromHtml(licenseString, 1)
else Html.fromHtml(licenseString)
MaterialAlertDialogBuilder(view?.context!!)
.setPositiveButton(getString(R.string.okay)) { _, _ -> }
.setMessage(licenseHtml)
.create()
.show()
true
}
} }
private fun navigateSettings(newFragment: PreferenceFragmentCompat) { private fun navigateSettings(newFragment: Fragment) {
isCurrentViewMainSettings = false isCurrentViewMainSettings = false
parentFragmentManager.beginTransaction() parentFragmentManager.beginTransaction()
.replace(R.id.settings, newFragment) .replace(R.id.settings, newFragment)

View File

@ -28,7 +28,16 @@ fun checkUpdate(childFragmentManager: FragmentManager) {
if (updateInfo?.tagName != "" && BuildConfig.VERSION_NAME != updateInfo?.tagName) { if (updateInfo?.tagName != "" && BuildConfig.VERSION_NAME != updateInfo?.tagName) {
val updateAvailableDialog = UpdateAvailableDialog( val updateAvailableDialog = UpdateAvailableDialog(
updateInfo?.tagName!!, updateInfo?.tagName!!,
updateInfo?.updateUrl!! updateInfo?.updateUrl!!,
true
)
updateAvailableDialog.show(childFragmentManager, "UpdateDialog")
} else {
// otherwise show the no update available dialog
val updateAvailableDialog = UpdateAvailableDialog(
updateInfo?.tagName!!,
updateInfo?.updateUrl!!,
false
) )
updateAvailableDialog.show(childFragmentManager, "UpdateAvailableDialog") updateAvailableDialog.show(childFragmentManager, "UpdateAvailableDialog")
} }

View File

@ -3,7 +3,7 @@
android:height="24dp" android:height="24dp"
android:viewportWidth="24" android:viewportWidth="24"
android:viewportHeight="24" android:viewportHeight="24"
android:tint="?attr/colorControlNormal" > android:tint="?attr/colorControlNormal">
<path <path
android:fillColor="@android:color/white" android:fillColor="@android:color/white"
android:pathData="M19,9h-4V3H9v6H5l7,7 7,-7zM5,18v2h14v-2H5z" /> android:pathData="M19,9h-4V3H9v6H5l7,7 7,-7zM5,18v2h14v-2H5z" />

View File

@ -0,0 +1,205 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
style="@style/roundedImageViewRounded"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:layout_marginTop="100dp"
android:src="@mipmap/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="LibreTube"
android:textSize="27sp"
android:textStyle="bold" />
<TextView
android:id="@+id/app_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:layout_marginBottom="30dp"
android:textSize="18sp" />
<com.google.android.material.card.MaterialCardView
android:id="@+id/website"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_marginBottom="16dp"
android:padding="20dp"
app:cardCornerRadius="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="10dp"
android:text="@string/website"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="20dp"
android:layout_marginBottom="10dp"
android:text="@string/website_summary" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="@+id/contributing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_marginBottom="16dp"
android:padding="20dp"
app:cardCornerRadius="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="10dp"
android:text="@string/contributing"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="20dp"
android:layout_marginBottom="10dp"
android:text="@string/contributing_summary" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="@+id/donate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_marginBottom="16dp"
android:padding="20dp"
app:cardCornerRadius="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="10dp"
android:text="@string/donate"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="20dp"
android:layout_marginBottom="10dp"
android:text="@string/donate_summary" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="@+id/license"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_marginBottom="16dp"
android:padding="20dp"
app:cardCornerRadius="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="10dp"
android:text="@string/license"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="20dp"
android:layout_marginBottom="10dp"
android:text="@string/license_summary" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="@+id/update"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_marginBottom="20dp"
android:padding="20dp"
app:cardCornerRadius="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="10dp"
android:text="@string/update"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="20dp"
android:layout_marginBottom="10dp"
android:text="@string/update_summary" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
</ScrollView>

View File

@ -125,4 +125,14 @@
<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="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">Download directory</string>
<string name="download_directory_summary">The directory where your downloaded media gets stored.</string> <string name="download_directory_summary">The directory 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>
<string name="license_summary">The GNU General Public License is a free, copyleft license for software and other kinds of works.</string>
<string name="donate">Donate</string>
<string name="donate_summary">If you like the app and appreciate our work we\'d be happy about a donation.</string>
<string name="update">App update</string>
<string name="update_summary">Click here to check whether there\'s a new app update available.</string>
<string name="app_uptodate">App up to date</string>
<string name="no_update_available">There\'s currently no new update available. Stay tuned!</string>
</resources> </resources>

View File

@ -79,17 +79,12 @@
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory app:title="@string/about"> <PreferenceCategory>
<Preference <Preference
app:title="@string/website" app:title="@string/about"
app:key="about" app:key="about"
android:icon="@drawable/ic_region" /> android:icon="@drawable/ic_info" />
<Preference
app:title="@string/license"
app:key="license"
android:icon="@drawable/ic_license" />
</PreferenceCategory> </PreferenceCategory>