diff --git a/app/src/main/java/com/github/libretube/DownloadService.kt b/app/src/main/java/com/github/libretube/DownloadService.kt index 04d221be0..ca659b718 100644 --- a/app/src/main/java/com/github/libretube/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/DownloadService.kt @@ -5,7 +5,6 @@ import android.app.PendingIntent import android.app.Service import android.content.BroadcastReceiver import android.content.Context -import android.content.Context.DOWNLOAD_SERVICE import android.content.Intent import android.content.IntentFilter import android.net.Uri diff --git a/app/src/main/java/com/github/libretube/dialogs/UpdateAvailableDialog.kt b/app/src/main/java/com/github/libretube/dialogs/UpdateAvailableDialog.kt index aab997947..e5fe2cde5 100644 --- a/app/src/main/java/com/github/libretube/dialogs/UpdateAvailableDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/UpdateAvailableDialog.kt @@ -10,23 +10,32 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder class UpdateAvailableDialog( private val versionTag: String, - private val updateLink: String + private val updateLink: String, + private val updateAvailable: Boolean ) : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { return activity?.let { - MaterialAlertDialogBuilder(requireContext()) - .setTitle(context?.getString(R.string.update_available, versionTag)) - .setMessage(context?.getString(R.string.update_available_text)) - .setNegativeButton(context?.getString(R.string.cancel)) { _, _ -> - dismiss() - } - .setPositiveButton(context?.getString(R.string.okay)) { _, _ -> - val uri = Uri.parse(updateLink) - val intent = Intent(Intent.ACTION_VIEW).setData(uri) - startActivity(intent) - } - .show() + if (updateAvailable) { + MaterialAlertDialogBuilder(requireContext()) + .setTitle(context?.getString(R.string.update_available, versionTag)) + .setMessage(context?.getString(R.string.update_available_text)) + .setNegativeButton(context?.getString(R.string.cancel)) { _, _ -> + dismiss() + } + .setPositiveButton(context?.getString(R.string.okay)) { _, _ -> + val uri = Uri.parse(updateLink) + val intent = Intent(Intent.ACTION_VIEW).setData(uri) + startActivity(intent) + } + .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") } } diff --git a/app/src/main/java/com/github/libretube/preferences/AboutFragment.kt b/app/src/main/java/com/github/libretube/preferences/AboutFragment.kt new file mode 100644 index 000000000..33d205b51 --- /dev/null +++ b/app/src/main/java/com/github/libretube/preferences/AboutFragment.kt @@ -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(R.id.app_version) + appVersion.text = BuildConfig.VERSION_NAME + val website = view?.findViewById(R.id.website) + website?.setOnClickListener { + openLink("https://libre-tube.github.io/") + } + val donate = view?.findViewById(R.id.donate) + donate?.setOnClickListener { + openLink("https://libre-tube.github.io/#donate") + } + val contributing = view?.findViewById(R.id.contributing) + contributing?.setOnClickListener { + openLink("https://github.com/libre-tube/LibreTube") + } + val license = view.findViewById(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(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) + } +} diff --git a/app/src/main/java/com/github/libretube/preferences/MainSettings.kt b/app/src/main/java/com/github/libretube/preferences/MainSettings.kt index 2bf372416..8ab101257 100644 --- a/app/src/main/java/com/github/libretube/preferences/MainSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/MainSettings.kt @@ -3,12 +3,10 @@ package com.github.libretube.preferences import android.Manifest import android.content.ContentResolver import android.content.Context -import android.content.Intent import android.content.pm.PackageManager import android.net.Uri import android.os.Build import android.os.Bundle -import android.text.Html import android.text.TextUtils import android.util.Log import android.widget.Toast @@ -27,8 +25,6 @@ import com.github.libretube.isCurrentViewMainSettings import com.github.libretube.requireMainActivityRestart import com.github.libretube.util.RetrofitInstance 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.InputStream import java.util.zip.ZipEntry @@ -112,11 +108,6 @@ class MainSettings : PreferenceFragmentCompat() { } } super.onCreate(savedInstanceState) - try { - checkUpdate(childFragmentManager) - } catch (e: Exception) { - e.printStackTrace() - } } override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { @@ -186,6 +177,13 @@ class MainSettings : PreferenceFragmentCompat() { true } + val about = findPreference("about") + about?.setOnPreferenceClickListener { + val newFragment = AboutFragment() + navigateSettings(newFragment) + true + } + val importFromYt = findPreference("import_from_yt") importFromYt?.setOnPreferenceClickListener { val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE) @@ -238,34 +236,9 @@ class MainSettings : PreferenceFragmentCompat() { } true } - - val about = findPreference("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("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 parentFragmentManager.beginTransaction() .replace(R.id.settings, newFragment) diff --git a/app/src/main/java/com/github/libretube/util/UpdateChecker.kt b/app/src/main/java/com/github/libretube/util/UpdateChecker.kt index 8b7b6f6b0..7f4db01f3 100644 --- a/app/src/main/java/com/github/libretube/util/UpdateChecker.kt +++ b/app/src/main/java/com/github/libretube/util/UpdateChecker.kt @@ -28,7 +28,16 @@ fun checkUpdate(childFragmentManager: FragmentManager) { if (updateInfo?.tagName != "" && BuildConfig.VERSION_NAME != updateInfo?.tagName) { val updateAvailableDialog = UpdateAvailableDialog( 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") } diff --git a/app/src/main/res/drawable/ic_file_download.xml b/app/src/main/res/drawable/ic_file_download.xml index 9c298875d..abbd2ec20 100644 --- a/app/src/main/res/drawable/ic_file_download.xml +++ b/app/src/main/res/drawable/ic_file_download.xml @@ -3,7 +3,7 @@ android:height="24dp" android:viewportWidth="24" android:viewportHeight="24" - android:tint="?attr/colorControlNormal" > + android:tint="?attr/colorControlNormal"> diff --git a/app/src/main/res/layout/fragment_about.xml b/app/src/main/res/layout/fragment_about.xml new file mode 100644 index 000000000..a89a526d2 --- /dev/null +++ b/app/src/main/res/layout/fragment_about.xml @@ -0,0 +1,205 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ae1373aa6..f73990d14 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -125,4 +125,14 @@ The video format downloaded videos get converted to (only applies if both, audio and video, are downloaded). Download directory The directory where your downloaded media gets stored. + Visit our website to learn more about the app and its features. + Contributing + 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! + The GNU General Public License is a free, copyleft license for software and other kinds of works. + Donate + If you like the app and appreciate our work we\'d be happy about a donation. + App update + Click here to check whether there\'s a new app update available. + App up to date + There\'s currently no new update available. Stay tuned! \ No newline at end of file diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index d9ef825ac..50651364e 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -79,17 +79,12 @@ - + - - + android:icon="@drawable/ic_info" />