Skip to content

Commit

Permalink
copy title
Browse files Browse the repository at this point in the history
  • Loading branch information
ekibun committed Jul 25, 2020
1 parent fbac681 commit c98433f
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 26 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ object BgmIpViewer {
}?.target ?: bgmIp.id

val queue = LinkedList<Int>()
queue.add(id + 1)
queue.add(id)
while (true) {
val nodeId = queue.poll() ?: break
val node = visitNode(nodeId)?.also {
Expand Down
9 changes: 2 additions & 7 deletions app/src/main/java/soko/ekibun/bangumi/ui/say/SayView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,8 @@ class SayView(private val context: SayActivity) {
context.item_swipe.setOnChildScrollUpCallback { _, _ -> canScroll }
}
})
context.title_collapse.setOnClickListener {
if (scroll2Top()) return@setOnClickListener
WebActivity.startActivity(context, context.sayPresenter.say.url)
}
context.title_expand.setOnClickListener {
if (scroll2Top()) return@setOnClickListener
WebActivity.startActivity(context, context.sayPresenter.say.url)
collapsibleAppBarHelper.onTitleClickListener = {
if (!scroll2Top()) WebActivity.startActivity(context, context.sayPresenter.say.url)
}
}

Expand Down
11 changes: 3 additions & 8 deletions app/src/main/java/soko/ekibun/bangumi/ui/topic/TopicView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,8 @@ class TopicView(private val context: TopicActivity) {
context.item_swipe.setOnChildScrollUpCallback { _, _ -> canScroll }
}
})
context.title_collapse.setOnClickListener {
if (scroll2Top()) return@setOnClickListener
WebActivity.startActivity(context, context.topicPresenter.topic.url)
}
context.title_expand.setOnClickListener {
if (scroll2Top()) return@setOnClickListener
WebActivity.startActivity(context, context.topicPresenter.topic.url)
collapsibleAppBarHelper.onTitleClickListener = {
if (!scroll2Top()) WebActivity.startActivity(context, context.topicPresenter.topic.url)
}
}

Expand Down Expand Up @@ -170,7 +165,7 @@ class TopicView(private val context: TopicActivity) {
)
?.into(object : CustomTarget<Drawable>() {
override fun onLoadCleared(placeholder: Drawable?) {
context.window.setBackgroundDrawable(placeholder)
placeholder?.let { context.window.setBackgroundDrawable(it) }
}

override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package soko.ekibun.bangumi.ui.view

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.os.Build
import android.view.ActionMode
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.TextView
import android.widget.Toast
import androidx.constraintlayout.widget.ConstraintLayout
import com.google.android.material.appbar.AppBarLayout
import kotlinx.android.synthetic.main.appbar_layout.view.*
import soko.ekibun.bangumi.util.AppUtil

/**
* App bar helper
Expand All @@ -22,10 +32,76 @@ class CollapsibleAppBarHelper(val appbar: AppBarLayout) {
appBarOffset = verticalOffset
if (collapsible == CollapseStatus.AUTO) updateStatus(Math.abs(appBarOffset.toFloat() / appbar.totalScrollRange))
})
appbar.title_collapse.setOnClickListener { onTitleClickListener(ClickEvent.EVENT_TITLE) }
appbar.title_expand.setOnClickListener { onTitleClickListener(ClickEvent.EVENT_TITLE) }
appbar.title_collapse.setOnClickListener {
if (actionMode != null) hideActionMode() else onTitleClickListener(ClickEvent.EVENT_TITLE)
}
appbar.title_expand.setOnClickListener {
if (actionMode != null) hideActionMode() else onTitleClickListener(ClickEvent.EVENT_TITLE)
}
appbar.title_slice_0.setOnClickListener { onTitleClickListener(ClickEvent.EVENT_SUBTITLE) }
appbar.title_slice_1.setOnClickListener { onTitleClickListener(ClickEvent.EVENT_GROUP) }

appbar.title_collapse.setOnLongClickListener(::onTitleLongClick)
appbar.title_expand.setOnLongClickListener(::onTitleLongClick)
}

var actionMode: ActionMode? = null
private fun hideActionMode() {
actionMode?.finish()
actionMode = null
}

private fun onTitleLongClick(v: View): Boolean {
return if (Build.VERSION.SDK_INT > 22) {
actionMode = v.startActionMode(object : ActionMode.Callback2() {
val ID_COPY = android.R.id.copy
val ID_SHARE = android.R.id.shareText
private val MENU_ITEM_ORDER_COPY = 5
private val MENU_ITEM_ORDER_SHARE = 7

override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
mode.title = null
mode.subtitle = null
mode.titleOptionalHint = true
populateMenuWithItems(menu)
return true
}

private fun populateMenuWithItems(menu: Menu) {
menu.add(
Menu.NONE, ID_COPY, MENU_ITEM_ORDER_COPY,
"复制"
).setAlphabeticShortcut('c').setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
menu.add(
Menu.NONE, ID_SHARE, MENU_ITEM_ORDER_SHARE,
"分享"
).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM)
}

override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?): Boolean {
return true
}

override fun onDestroyActionMode(mode: ActionMode?) {
}

val clipboardManager by lazy { v.context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager }

override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
val str = (v as TextView).text.toString()
when (item.itemId) {
ID_COPY -> {
clipboardManager.primaryClip = ClipData.newPlainText("bangumi_title", str)
Toast.makeText(v.context, "已复制到剪贴板", Toast.LENGTH_LONG).show()
}
ID_SHARE -> AppUtil.shareString(v.context, str)
}
hideActionMode()
return true
}
}, ActionMode.TYPE_FLOATING)
true
} else false
}

enum class CollapseStatus {
Expand Down Expand Up @@ -63,6 +139,7 @@ class CollapsibleAppBarHelper(val appbar: AppBarLayout) {

private var mRatio = 0f
fun updateStatus(ratio: Float = mRatio) {
hideActionMode()
mRatio = ratio
appbar.title_collapse.alpha = 1 - (1 - ratio) * (1 - ratio) * (1 - ratio)
appbar.title_expand.alpha = 1 - ratio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ class BaseLineImageSpan(drawable: UrlDrawable, private val source: String? = nul
override fun getSource(): String? = source
override fun getDrawable(): UrlDrawable = super.getDrawable() as UrlDrawable
override fun getSize(paint: Paint, text: CharSequence?, start: Int, end: Int, fm: Paint.FontMetricsInt?): Int {
val ascent = fm?.ascent
val top = fm?.top
val descent = fm?.descent
val bottom = fm?.bottom
val width = super.getSize(paint, text, start, end, fm)
fm?.descent = descent
fm?.bottom = bottom
fm?.top = Math.min(fm?.top ?: 0, top ?: 0)
fm?.ascent = Math.min(fm?.ascent ?: 0, ascent ?: 0)
fm?.descent = paint.fontMetricsInt.descent
fm?.bottom = paint.fontMetricsInt.bottom
fm?.top = Math.min(fm?.top ?: 0, paint.fontMetricsInt.top)
fm?.ascent = Math.min(fm?.ascent ?: 0, paint.fontMetricsInt.ascent)
return width
}
}

0 comments on commit c98433f

Please sign in to comment.