Copy to clipboard when long pressing tracking title (closes #3163)

This commit is contained in:
arkon 2020-05-12 09:11:15 -04:00
parent 46b01c6134
commit 97aed045e6
5 changed files with 30 additions and 20 deletions

View File

@ -37,6 +37,7 @@ class TrackAdapter(controller: TrackController) : RecyclerView.Adapter<TrackHold
interface OnClickListener { interface OnClickListener {
fun onLogoClick(position: Int) fun onLogoClick(position: Int)
fun onSetClick(position: Int) fun onSetClick(position: Int)
fun onTitleLongClick(position: Int)
fun onStatusClick(position: Int) fun onStatusClick(position: Int)
fun onChaptersClick(position: Int) fun onChaptersClick(position: Int)
fun onScoreClick(position: Int) fun onScoreClick(position: Int)

View File

@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.data.track.model.TrackSearch
import eu.kanade.tachiyomi.databinding.TrackControllerBinding import eu.kanade.tachiyomi.databinding.TrackControllerBinding
import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.NucleusController
import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.manga.MangaController
import eu.kanade.tachiyomi.util.system.copyToClipboard
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
@ -104,6 +105,12 @@ class TrackController :
TrackSearchDialog(this, item.service).showDialog(router, TAG_SEARCH_CONTROLLER) TrackSearchDialog(this, item.service).showDialog(router, TAG_SEARCH_CONTROLLER)
} }
override fun onTitleLongClick(position: Int) {
adapter?.getItem(position)?.track?.title?.let {
activity?.copyToClipboard(it, it)
}
}
override fun onStatusClick(position: Int) { override fun onStatusClick(position: Int) {
val item = adapter?.getItem(position) ?: return val item = adapter?.getItem(position) ?: return
if (item.track == null) return if (item.track == null) return

View File

@ -35,6 +35,10 @@ class TrackHolder(view: View, adapter: TrackAdapter) : BaseViewHolder(view) {
logo_container.setOnClickListener { listener.onLogoClick(bindingAdapterPosition) } logo_container.setOnClickListener { listener.onLogoClick(bindingAdapterPosition) }
track_set.setOnClickListener { listener.onSetClick(bindingAdapterPosition) } track_set.setOnClickListener { listener.onSetClick(bindingAdapterPosition) }
track_title.setOnClickListener { listener.onSetClick(bindingAdapterPosition) } track_title.setOnClickListener { listener.onSetClick(bindingAdapterPosition) }
track_title.setOnLongClickListener {
listener.onTitleLongClick(bindingAdapterPosition)
true
}
track_status.setOnClickListener { listener.onStatusClick(bindingAdapterPosition) } track_status.setOnClickListener { listener.onStatusClick(bindingAdapterPosition) }
track_chapters.setOnClickListener { listener.onChaptersClick(bindingAdapterPosition) } track_chapters.setOnClickListener { listener.onChaptersClick(bindingAdapterPosition) }
track_score.setOnClickListener { listener.onScoreClick(bindingAdapterPosition) } track_score.setOnClickListener { listener.onScoreClick(bindingAdapterPosition) }

View File

@ -1,27 +1,7 @@
package eu.kanade.tachiyomi.util.system package eu.kanade.tachiyomi.util.system
import android.app.Activity import android.app.Activity
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.os.Build import android.os.Build
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.lang.truncateCenter
/**
* Copies a string to clipboard
*
* @param label Label to show to the user describing the content
* @param content the actual text to copy to the board
*/
fun Activity.copyToClipboard(label: String, content: String) {
if (content.isBlank()) return
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
clipboard.setPrimaryClip(ClipData.newPlainText(label, content))
toast(getString(R.string.copied_to_clipboard, content.truncateCenter(50)))
}
/** /**
* Checks whether if the device has a display cutout (i.e. notch, camera cutout, etc.). * Checks whether if the device has a display cutout (i.e. notch, camera cutout, etc.).

View File

@ -4,6 +4,8 @@ import android.app.ActivityManager
import android.app.Notification import android.app.Notification
import android.app.NotificationManager import android.app.NotificationManager
import android.content.BroadcastReceiver import android.content.BroadcastReceiver
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
@ -24,6 +26,7 @@ import androidx.core.content.ContextCompat
import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.nononsenseapps.filepicker.FilePickerActivity import com.nononsenseapps.filepicker.FilePickerActivity
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.lang.truncateCenter
import eu.kanade.tachiyomi.widget.CustomLayoutPickerActivity import eu.kanade.tachiyomi.widget.CustomLayoutPickerActivity
import kotlin.math.roundToInt import kotlin.math.roundToInt
@ -47,6 +50,21 @@ fun Context.toast(text: String?, duration: Int = Toast.LENGTH_SHORT) {
Toast.makeText(this, text.orEmpty(), duration).show() Toast.makeText(this, text.orEmpty(), duration).show()
} }
/**
* Copies a string to clipboard
*
* @param label Label to show to the user describing the content
* @param content the actual text to copy to the board
*/
fun Context.copyToClipboard(label: String, content: String) {
if (content.isBlank()) return
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
clipboard.setPrimaryClip(ClipData.newPlainText(label, content))
toast(getString(R.string.copied_to_clipboard, content.truncateCenter(50)))
}
/** /**
* Helper method to create a notification builder. * Helper method to create a notification builder.
* *