diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 8f5d7d3c2..e5baf8a8a 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -272,9 +272,15 @@
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/github/libretube/MainActivity.kt b/app/src/main/java/com/github/libretube/MainActivity.kt
index 357250e75..5c694a275 100644
--- a/app/src/main/java/com/github/libretube/MainActivity.kt
+++ b/app/src/main/java/com/github/libretube/MainActivity.kt
@@ -34,6 +34,7 @@ import androidx.navigation.findNavController
import androidx.navigation.ui.setupWithNavController
import com.github.libretube.fragments.PlayerFragment
import com.github.libretube.fragments.isFullScreen
+import com.github.libretube.services.ClosingService
import com.github.libretube.util.CronetHelper
import com.github.libretube.util.LocaleHelper
import com.github.libretube.util.PreferenceHelper
@@ -52,6 +53,10 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
DynamicColors.applyToActivityIfAvailable(this)
super.onCreate(savedInstanceState)
+
+ // start service that gets called on closure
+ startService(Intent(this, ClosingService::class.java))
+
CronetHelper.initCronet(this.applicationContext)
RetrofitInstance.url =
diff --git a/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt b/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt
index 9fae8cd8b..cc467c313 100644
--- a/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt
+++ b/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt
@@ -17,10 +17,10 @@ import android.widget.TextView
import androidx.core.app.ActivityCompat
import androidx.core.text.HtmlCompat
import androidx.fragment.app.DialogFragment
-import com.github.libretube.DownloadService
import com.github.libretube.MainActivity
import com.github.libretube.R
import com.github.libretube.obj.Streams
+import com.github.libretube.services.DownloadService
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class DownloadDialog : DialogFragment() {
diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt
index 54fe27fd7..d9d66caa0 100644
--- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt
+++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt
@@ -38,7 +38,6 @@ import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
-import com.github.libretube.IS_DOWNLOAD_RUNNING
import com.github.libretube.MainActivity
import com.github.libretube.R
import com.github.libretube.adapters.ChaptersAdapter
@@ -56,6 +55,7 @@ import com.github.libretube.obj.SponsorBlockPrefs
import com.github.libretube.obj.StreamItem
import com.github.libretube.obj.Streams
import com.github.libretube.obj.Subscribe
+import com.github.libretube.services.IS_DOWNLOAD_RUNNING
import com.github.libretube.util.CronetHelper
import com.github.libretube.util.DescriptionAdapter
import com.github.libretube.util.PreferenceHelper
@@ -252,14 +252,12 @@ class PlayerFragment : Fragment() {
}
}
+ // video description and chapters toggle
+ val descLinLayout = view.findViewById(R.id.desc_linLayout)
view.findViewById(R.id.player_title_layout).setOnClickListener {
val arrowImageView = view.findViewById(R.id.player_description_arrow)
arrowImageView.animate().rotationBy(180F).setDuration(100).start()
- if (playerDescription.isVisible) {
- playerDescription.visibility = View.GONE
- } else {
- playerDescription.visibility = View.VISIBLE
- }
+ descLinLayout.visibility = if (descLinLayout.isVisible) View.GONE else View.VISIBLE
}
view.findViewById(R.id.comments_toggle)
@@ -447,11 +445,11 @@ class PlayerFragment : Fragment() {
relatedStreams = response.relatedStreams
runOnUiThread {
createExoPlayer(view)
- prepareExoPlayerView()
if (response.chapters != null) initializeChapters(response.chapters)
// set media sources for the player
setResolutionAndSubtitles(view, response)
exoPlayer.prepare()
+ prepareExoPlayerView()
initializePlayerView(view, response)
// support for time stamped links
if (arguments?.getLong("timeStamp") != null) {
@@ -717,28 +715,13 @@ class PlayerFragment : Fragment() {
}
private fun initializeChapters(chapters: List) {
- val chaptersToggle = view?.findViewById(R.id.chapters_toggle)
val chaptersRecView = view?.findViewById(R.id.chapters_recView)
- val chaptersToggleText = view?.findViewById(R.id.chapters_toggle_text)
- val chaptersToggleArrow = view?.findViewById(R.id.chapters_toggle_arrow)
if (chapters.isNotEmpty()) {
- chaptersToggle?.visibility = View.VISIBLE
-
- chaptersToggle?.setOnClickListener {
- if (chaptersRecView?.isVisible!!) {
- chaptersRecView?.visibility = View.GONE
- chaptersToggleText?.text = getString(R.string.show_chapters)
- } else {
- chaptersRecView?.visibility = View.VISIBLE
- chaptersToggleText?.text = getString(R.string.hide_chapters)
- }
- chaptersToggleArrow!!.animate().setDuration(100).rotationBy(180F).start()
- }
-
chaptersRecView?.layoutManager =
LinearLayoutManager(this.context, LinearLayoutManager.HORIZONTAL, false)
chaptersRecView?.adapter = ChaptersAdapter(chapters, exoPlayer)
+ chaptersRecView?.visibility = View.VISIBLE
}
}
@@ -1121,7 +1104,7 @@ class PlayerFragment : Fragment() {
enableTransition(R.id.yt_transition, false)
}
view?.findViewById(R.id.main_container)?.isClickable = true
- view?.findViewById(R.id.top_bar)?.visibility = View.GONE
+ view?.findViewById(R.id.top_bar)?.visibility = View.GONE
val mainActivity = activity as MainActivity
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
isFullScreen = false
@@ -1133,7 +1116,7 @@ class PlayerFragment : Fragment() {
exoPlayerView.showController()
exoPlayerView.useController = true
view?.findViewById(R.id.main_container)?.isClickable = false
- view?.findViewById(R.id.top_bar)?.visibility = View.VISIBLE
+ view?.findViewById(R.id.top_bar)?.visibility = View.VISIBLE
}
}
diff --git a/app/src/main/java/com/github/libretube/services/ClosingService.kt b/app/src/main/java/com/github/libretube/services/ClosingService.kt
new file mode 100644
index 000000000..716e6dff9
--- /dev/null
+++ b/app/src/main/java/com/github/libretube/services/ClosingService.kt
@@ -0,0 +1,31 @@
+package com.github.libretube.services
+
+import android.app.NotificationManager
+import android.app.Service
+import android.content.Context
+import android.content.Intent
+import android.os.IBinder
+import android.util.Log
+import androidx.annotation.Nullable
+
+class ClosingService : Service() {
+ private val TAG = "ClosingService"
+
+ @Nullable
+ override fun onBind(intent: Intent?): IBinder? {
+ return null
+ }
+
+ // Handle application closing
+ override fun onTaskRemoved(rootIntent: Intent?) {
+ super.onTaskRemoved(rootIntent)
+
+ // destroy all notifications (especially the player notification)
+ val nManager = this.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
+ nManager.cancelAll()
+ Log.e(TAG, "closed")
+
+ // Destroy the service
+ stopSelf()
+ }
+}
diff --git a/app/src/main/java/com/github/libretube/DownloadService.kt b/app/src/main/java/com/github/libretube/services/DownloadService.kt
similarity index 99%
rename from app/src/main/java/com/github/libretube/DownloadService.kt
rename to app/src/main/java/com/github/libretube/services/DownloadService.kt
index eb7b309aa..8f3c96e71 100644
--- a/app/src/main/java/com/github/libretube/DownloadService.kt
+++ b/app/src/main/java/com/github/libretube/services/DownloadService.kt
@@ -1,4 +1,4 @@
-package com.github.libretube
+package com.github.libretube.services
import android.app.DownloadManager
import android.app.PendingIntent
@@ -18,6 +18,7 @@ import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import com.arthenica.ffmpegkit.FFmpegKit
+import com.github.libretube.R
import com.github.libretube.util.PreferenceHelper
import java.io.File
diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml
index 73ca5679f..904b19f13 100644
--- a/app/src/main/res/layout/activity_settings.xml
+++ b/app/src/main/res/layout/activity_settings.xml
@@ -10,8 +10,8 @@
-
+ android:orientation="vertical"
+ android:animateLayoutChanges="true" >
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ android:layout_marginLeft="3dp"
+ android:layout_marginTop="2dp">
+ android:layout_width="12dp"
+ android:layout_height="12dp"
+ android:layout_gravity="center"
+ android:src="@drawable/ic_like" />
+
+
+
+
+
+
-
+
-
+ android:orientation="vertical"
+ android:visibility="gone">
-
+
+
+
+
wrap_content
- 20dp
- 20dp
- - 15dp
- - 15dp
+ - 12dp
+ - 12dp
- ?android:attr/selectableItemBackground
-
-