Skip to content

Commit

Permalink
Merge pull request #6219 from Bnyro/master
Browse files Browse the repository at this point in the history
feat: quick share action to add video to playlist
  • Loading branch information
Bnyro committed Jul 11, 2024
2 parents 4f22fb0 + 025539a commit 94562a3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@

</activity>

<activity
android:name=".ui.activities.AddToPlaylistActivity"
android:enabled="true"
android:exported="true"
android:label="@string/addToPlaylist"
android:launchMode="singleTop"
android:theme="@style/Theme.Material3.DayNight.Dialog">

<intent-filter android:label="@string/addToPlaylist">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>

</activity>

<activity
android:name=".ui.activities.DownloadActivity"
android:enabled="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.github.libretube.ui.activities

import android.content.Intent
import android.os.Bundle
import androidx.core.net.toUri
import androidx.core.os.bundleOf
import com.github.libretube.constants.IntentData
import com.github.libretube.helpers.IntentHelper
import com.github.libretube.ui.base.BaseActivity
import com.github.libretube.ui.dialogs.AddToPlaylistDialog

class AddToPlaylistActivity: BaseActivity() {
override val isDialogActivity: Boolean = true

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val videoId = intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
IntentHelper.resolveType(Intent(), it.toUri())
}?.getStringExtra(IntentData.videoId)

if (videoId == null) {
finishAndRemoveTask()
return
}

supportFragmentManager.setFragmentResultListener(
AddToPlaylistDialog.ADD_TO_PLAYLIST_DIALOG_DISMISSED_KEY,
this
) { _, _ -> finish() }

AddToPlaylistDialog().apply {
arguments = bundleOf(IntentData.videoId to videoId)
}.show(supportFragmentManager, null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import android.content.DialogInterface
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.core.os.bundleOf
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.setFragmentResult
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
Expand Down Expand Up @@ -133,4 +135,14 @@ class AddToPlaylistDialog : DialogFragment() {
appContext.toastFromMainDispatcher(R.string.fail)
}
}

override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)

setFragmentResult(ADD_TO_PLAYLIST_DIALOG_DISMISSED_KEY, bundleOf())
}

companion object {
const val ADD_TO_PLAYLIST_DIALOG_DISMISSED_KEY = "add_to_playlist_dialog_dismissed"
}
}

0 comments on commit 94562a3

Please sign in to comment.