mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 13:50:30 +05:30
kill notifications on closure
This commit is contained in:
parent
66984ad727
commit
f81446095d
@ -272,9 +272,15 @@
|
|||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".DownloadService"
|
android:name=".services.DownloadService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
|
|
||||||
|
<service
|
||||||
|
android:name=".services.ClosingService"
|
||||||
|
android:stopWithTask="false"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="false"/>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@ -34,6 +34,7 @@ import androidx.navigation.findNavController
|
|||||||
import androidx.navigation.ui.setupWithNavController
|
import androidx.navigation.ui.setupWithNavController
|
||||||
import com.github.libretube.fragments.PlayerFragment
|
import com.github.libretube.fragments.PlayerFragment
|
||||||
import com.github.libretube.fragments.isFullScreen
|
import com.github.libretube.fragments.isFullScreen
|
||||||
|
import com.github.libretube.services.ClosingService
|
||||||
import com.github.libretube.util.CronetHelper
|
import com.github.libretube.util.CronetHelper
|
||||||
import com.github.libretube.util.LocaleHelper
|
import com.github.libretube.util.LocaleHelper
|
||||||
import com.github.libretube.util.PreferenceHelper
|
import com.github.libretube.util.PreferenceHelper
|
||||||
@ -52,6 +53,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
DynamicColors.applyToActivityIfAvailable(this)
|
DynamicColors.applyToActivityIfAvailable(this)
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
startService(Intent(this, ClosingService::class.java))
|
||||||
|
|
||||||
CronetHelper.initCronet(this.applicationContext)
|
CronetHelper.initCronet(this.applicationContext)
|
||||||
|
|
||||||
RetrofitInstance.url =
|
RetrofitInstance.url =
|
||||||
|
@ -17,10 +17,10 @@ import android.widget.TextView
|
|||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
import androidx.core.text.HtmlCompat
|
import androidx.core.text.HtmlCompat
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import com.github.libretube.DownloadService
|
|
||||||
import com.github.libretube.MainActivity
|
import com.github.libretube.MainActivity
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.obj.Streams
|
import com.github.libretube.obj.Streams
|
||||||
|
import com.github.libretube.services.DownloadService
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
|
||||||
class DownloadDialog : DialogFragment() {
|
class DownloadDialog : DialogFragment() {
|
||||||
|
@ -38,7 +38,7 @@ import androidx.lifecycle.lifecycleScope
|
|||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.github.libretube.IS_DOWNLOAD_RUNNING
|
import com.github.libretube.services.IS_DOWNLOAD_RUNNING
|
||||||
import com.github.libretube.MainActivity
|
import com.github.libretube.MainActivity
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.adapters.ChaptersAdapter
|
import com.github.libretube.adapters.ChaptersAdapter
|
||||||
@ -447,11 +447,11 @@ class PlayerFragment : Fragment() {
|
|||||||
relatedStreams = response.relatedStreams
|
relatedStreams = response.relatedStreams
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
createExoPlayer(view)
|
createExoPlayer(view)
|
||||||
prepareExoPlayerView()
|
|
||||||
if (response.chapters != null) initializeChapters(response.chapters)
|
if (response.chapters != null) initializeChapters(response.chapters)
|
||||||
// set media sources for the player
|
// set media sources for the player
|
||||||
setResolutionAndSubtitles(view, response)
|
setResolutionAndSubtitles(view, response)
|
||||||
exoPlayer.prepare()
|
exoPlayer.prepare()
|
||||||
|
prepareExoPlayerView()
|
||||||
initializePlayerView(view, response)
|
initializePlayerView(view, response)
|
||||||
// support for time stamped links
|
// support for time stamped links
|
||||||
if (arguments?.getLong("timeStamp") != null) {
|
if (arguments?.getLong("timeStamp") != null) {
|
||||||
@ -717,25 +717,9 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initializeChapters(chapters: List<ChapterSegment>) {
|
private fun initializeChapters(chapters: List<ChapterSegment>) {
|
||||||
val chaptersToggle = view?.findViewById<LinearLayout>(R.id.chapters_toggle)
|
|
||||||
val chaptersRecView = view?.findViewById<RecyclerView>(R.id.chapters_recView)
|
val chaptersRecView = view?.findViewById<RecyclerView>(R.id.chapters_recView)
|
||||||
val chaptersToggleText = view?.findViewById<TextView>(R.id.chapters_toggle_text)
|
|
||||||
val chaptersToggleArrow = view?.findViewById<ImageView>(R.id.chapters_toggle_arrow)
|
|
||||||
|
|
||||||
if (chapters.isNotEmpty()) {
|
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 =
|
chaptersRecView?.layoutManager =
|
||||||
LinearLayoutManager(this.context, LinearLayoutManager.HORIZONTAL, false)
|
LinearLayoutManager(this.context, LinearLayoutManager.HORIZONTAL, false)
|
||||||
chaptersRecView?.adapter = ChaptersAdapter(chapters, exoPlayer)
|
chaptersRecView?.adapter = ChaptersAdapter(chapters, exoPlayer)
|
||||||
@ -1121,7 +1105,7 @@ class PlayerFragment : Fragment() {
|
|||||||
enableTransition(R.id.yt_transition, false)
|
enableTransition(R.id.yt_transition, false)
|
||||||
}
|
}
|
||||||
view?.findViewById<ConstraintLayout>(R.id.main_container)?.isClickable = true
|
view?.findViewById<ConstraintLayout>(R.id.main_container)?.isClickable = true
|
||||||
view?.findViewById<FrameLayout>(R.id.top_bar)?.visibility = View.GONE
|
view?.findViewById<LinearLayout>(R.id.top_bar)?.visibility = View.GONE
|
||||||
val mainActivity = activity as MainActivity
|
val mainActivity = activity as MainActivity
|
||||||
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
||||||
isFullScreen = false
|
isFullScreen = false
|
||||||
@ -1133,7 +1117,7 @@ class PlayerFragment : Fragment() {
|
|||||||
exoPlayerView.showController()
|
exoPlayerView.showController()
|
||||||
exoPlayerView.useController = true
|
exoPlayerView.useController = true
|
||||||
view?.findViewById<ConstraintLayout>(R.id.main_container)?.isClickable = false
|
view?.findViewById<ConstraintLayout>(R.id.main_container)?.isClickable = false
|
||||||
view?.findViewById<FrameLayout>(R.id.top_bar)?.visibility = View.VISIBLE
|
view?.findViewById<LinearLayout>(R.id.top_bar)?.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.github.libretube
|
package com.github.libretube.services
|
||||||
|
|
||||||
import android.app.DownloadManager
|
import android.app.DownloadManager
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
@ -18,6 +18,7 @@ import android.util.Log
|
|||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import androidx.core.app.NotificationManagerCompat
|
import androidx.core.app.NotificationManagerCompat
|
||||||
import com.arthenica.ffmpegkit.FFmpegKit
|
import com.arthenica.ffmpegkit.FFmpegKit
|
||||||
|
import com.github.libretube.R
|
||||||
import com.github.libretube.util.PreferenceHelper
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
@ -55,21 +55,16 @@
|
|||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginHorizontal="10dp"
|
|
||||||
android:layout_marginTop="5dp"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:layout_marginHorizontal="10dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/player_views_info"
|
android:id="@+id/player_views_info"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="10M views 2 days ago " />
|
android:text="10M views 2 days ago " />
|
||||||
|
|
||||||
@ -81,8 +76,8 @@
|
|||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:layout_width="15dp"
|
android:layout_width="12dp"
|
||||||
android:layout_height="15dp"
|
android:layout_height="12dp"
|
||||||
android:src="@drawable/ic_like" />
|
android:src="@drawable/ic_like" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@ -94,8 +89,8 @@
|
|||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:layout_width="15dp"
|
android:layout_width="12dp"
|
||||||
android:layout_height="15dp"
|
android:layout_height="12dp"
|
||||||
android:layout_marginLeft="5dp"
|
android:layout_marginLeft="5dp"
|
||||||
android:src="@drawable/ic_like"
|
android:src="@drawable/ic_like"
|
||||||
android:rotation="180"/>
|
android:rotation="180"/>
|
||||||
@ -111,31 +106,6 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/chapters_toggle"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignParentEnd="true"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:visibility="gone">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/chapters_toggle_text"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/show_chapters" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/chapters_toggle_arrow"
|
|
||||||
android:layout_width="16dp"
|
|
||||||
android:layout_height="16dp"
|
|
||||||
android:layout_gravity="bottom"
|
|
||||||
android:src="@drawable/ic_arrow_down" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/chapters_recView"
|
android:id="@+id/chapters_recView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
Loading…
Reference in New Issue
Block a user