Skip to content

Commit

Permalink
Allow sharing of channel, video and clip links. (#554)
Browse files Browse the repository at this point in the history
* add share button.

* fixes

---------

Co-authored-by: crackededed <[email protected]>
  • Loading branch information
crimera and crackededed authored Sep 24, 2024
1 parent f620b24 commit 21e76f7
Show file tree
Hide file tree
Showing 21 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ class ChannelPagerFragment : BaseNetworkFragment(), Scrollable, FragmentHost, In
}
true
}
R.id.share -> {
context?.let { FragmentUtils.shareLink(it, "https://twitch.tv/${args.channelLogin}", args.channelName) }
true
}
R.id.download -> {
viewModel.stream.value?.let { DownloadDialog.newInstance(it).show(childFragmentManager, null) }
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.github.andreyasadchy.xtra.ui.games.GameMediaFragmentDirections
import com.github.andreyasadchy.xtra.ui.games.GamePagerFragmentDirections
import com.github.andreyasadchy.xtra.ui.main.MainActivity
import com.github.andreyasadchy.xtra.util.C
import com.github.andreyasadchy.xtra.util.FragmentUtils
import com.github.andreyasadchy.xtra.util.TwitchApiHelper
import com.github.andreyasadchy.xtra.util.gone
import com.github.andreyasadchy.xtra.util.loadImage
Expand Down Expand Up @@ -139,6 +140,7 @@ class ClipsAdapter(
setOnMenuItemClickListener {
when(it.itemId) {
R.id.download -> showDownloadDialog(item)
R.id.share -> FragmentUtils.shareLink(context, "https://twitch.tv/${item.channelLogin}/clip/${item.id}", item.title)
else -> menu.close()
}
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.github.andreyasadchy.xtra.util.gone
import com.github.andreyasadchy.xtra.util.loadImage
import com.github.andreyasadchy.xtra.util.prefs
import com.github.andreyasadchy.xtra.util.visible
import com.github.andreyasadchy.xtra.util.FragmentUtils

class ChannelClipsAdapter(
private val fragment: Fragment,
Expand Down Expand Up @@ -116,6 +117,7 @@ class ChannelClipsAdapter(
setOnMenuItemClickListener {
when(it.itemId) {
R.id.download -> showDownloadDialog(item)
R.id.share -> FragmentUtils.shareLink(context, "https://twitch.tv/${item.channelLogin}/clip/${item.id}", item.title)
else -> menu.close()
}
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.github.andreyasadchy.xtra.util.gone
import com.github.andreyasadchy.xtra.util.loadImage
import com.github.andreyasadchy.xtra.util.prefs
import com.github.andreyasadchy.xtra.util.visible
import com.github.andreyasadchy.xtra.util.FragmentUtils

class VideosAdapter(
private val fragment: Fragment,
Expand Down Expand Up @@ -210,6 +211,7 @@ class VideosAdapter(
when(it.itemId) {
R.id.download -> showDownloadDialog(item)
R.id.bookmark -> saveBookmark(item)
R.id.share -> FragmentUtils.shareLink(context, "https://twitch.tv/videos/${item.id}", item.title)
else -> menu.close()
}
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.github.andreyasadchy.xtra.util.gone
import com.github.andreyasadchy.xtra.util.loadImage
import com.github.andreyasadchy.xtra.util.prefs
import com.github.andreyasadchy.xtra.util.visible
import com.github.andreyasadchy.xtra.util.FragmentUtils

class ChannelVideosAdapter(
private val fragment: Fragment,
Expand Down Expand Up @@ -188,6 +189,7 @@ class ChannelVideosAdapter(
when(it.itemId) {
R.id.download -> showDownloadDialog(item)
R.id.bookmark -> saveBookmark(item)
R.id.share -> FragmentUtils.shareLink(context, "https://twitch.tv/videos/${item.id}", item.title)
else -> menu.close()
}
true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.andreyasadchy.xtra.util

import android.content.Context
import android.content.Intent
import androidx.fragment.app.FragmentManager
import com.github.andreyasadchy.xtra.R
import com.github.andreyasadchy.xtra.model.ui.Game
Expand Down Expand Up @@ -59,4 +60,17 @@ object FragmentUtils {
fun showPlayerViewerListDialog(fragmentManager: FragmentManager, login: String) {
PlayerViewerListDialog.newInstance(login).show(fragmentManager, "closeOnPip")
}

fun shareLink(context: Context, url: String, title: String?) {
val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, url)
title?.let {
putExtra(Intent.EXTRA_TITLE, title)
}
type = "text/plain"
}

context.startActivity(Intent.createChooser(sendIntent, null))
}
}
3 changes: 3 additions & 0 deletions app/src/main/res/menu/channel_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<item
android:id="@+id/login"
android:title="@string/log_in" />
<item
android:id="@+id/share"
android:title="@string/share"/>
<item
android:id="@+id/download"
android:title="@string/download" />
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/menu/media_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
android:id="@+id/bookmark"
android:title="@string/add_bookmark"
android:visible="false" />
<item
android:id="@+id/share"
android:title="@string/share" />
</menu>
1 change: 1 addition & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,5 @@
<string name="text_size">Text size</string>
<string name="backup_settings">Backup settings and data</string>
<string name="restore_settings">Restore settings and data</string>
<string name="share">Share</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,5 @@
<string name="text_size">Text size</string>
<string name="backup_settings">Backup settings and data</string>
<string name="restore_settings">Restore settings and data</string>
<string name="share">Share</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,5 @@
<string name="text_size">Text size</string>
<string name="backup_settings">Backup settings and data</string>
<string name="restore_settings">Restore settings and data</string>
<string name="share">Share</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,5 @@
<string name="text_size">Text size</string>
<string name="backup_settings">Backup settings and data</string>
<string name="restore_settings">Restore settings and data</string>
<string name="share">Share</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,5 @@
<string name="text_size">Text size</string>
<string name="backup_settings">Backup settings and data</string>
<string name="restore_settings">Restore settings and data</string>
<string name="share">Share</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,5 @@
<string name="text_size">Text size</string>
<string name="backup_settings">Backup settings and data</string>
<string name="restore_settings">Restore settings and data</string>
<string name="share">Share</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,5 @@
<string name="text_size">Text size</string>
<string name="backup_settings">Backup settings and data</string>
<string name="restore_settings">Restore settings and data</string>
<string name="share">Share</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,5 @@
<string name="text_size">Text size</string>
<string name="backup_settings">Backup settings and data</string>
<string name="restore_settings">Restore settings and data</string>
<string name="share">Share</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,5 @@
<string name="text_size">Text size</string>
<string name="backup_settings">Backup settings and data</string>
<string name="restore_settings">Restore settings and data</string>
<string name="share">Share</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,5 @@
<string name="text_size">Text size</string>
<string name="backup_settings">Backup settings and data</string>
<string name="restore_settings">Restore settings and data</string>
<string name="share">Share</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,5 @@
<string name="text_size">Text size</string>
<string name="backup_settings">Backup settings and data</string>
<string name="restore_settings">Restore settings and data</string>
<string name="share">Share</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,5 @@
<string name="text_size">Text size</string>
<string name="backup_settings">Backup settings and data</string>
<string name="restore_settings">Restore settings and data</string>
<string name="share">Share</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -648,4 +648,5 @@
<string name="text_size">Text size</string>
<string name="backup_settings">Backup settings and data</string>
<string name="restore_settings">Restore settings and data</string>
<string name="share">Share</string>
</resources>

0 comments on commit 21e76f7

Please sign in to comment.