Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: quick share action to add video to playlist #6219

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}
Loading