Skip to content

Commit

Permalink
Merge pull request #204 from Ryosuke839/switch-by-pinch
Browse files Browse the repository at this point in the history
Implement switching single by pinching
  • Loading branch information
Ryosuke839 authored Jan 3, 2025
2 parents 02f8bc4 + 8f38033 commit 43fa027
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 37 deletions.
6 changes: 1 addition & 5 deletions app/src/main/java/jp/ddo/hotmist/unicodepad/FindAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal class FindAdapter(activity: Activity, private val pref: SharedPreferenc

override fun instantiate(view: View): View {
super.instantiate(view)
val view = view as RecyclerView
check(view is RecyclerView)
val layout = LinearLayout(activity)
layout.orientation = LinearLayout.VERTICAL
val find = ImageButton(activity)
Expand Down Expand Up @@ -104,10 +104,6 @@ internal class FindAdapter(activity: Activity, private val pref: SharedPreferenc

override fun destroy() {
adapter = null
curList?.close()
curList = null
curEmoji?.close()
curEmoji = null
super.destroy()
}

Expand Down
19 changes: 8 additions & 11 deletions app/src/main/java/jp/ddo/hotmist/unicodepad/ListAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -670,22 +670,19 @@ internal class ListAdapter(activity: Activity, pref: SharedPreferences, db: Name
}
layout.addView(this.view, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f))
(this.view as RecyclerView?)?.also { view ->
view.setOnTouchListener { _, _ ->
runOnUiThread {
highTarget?.setBackgroundColor(resnormal)
highTarget = null
if (highlight != -1) {
notifyItemChanged(highlight)
highlight = -1
}
}
false
}
val e = fromCodePoint.floorEntry(scroll) ?: fromCodePoint.firstEntry()
if (e.value.end < scroll) scroll = e.value.end
scrollToItem(scroll - e.key + e.value.index)
view.setOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
runOnUiThread {
highTarget?.setBackgroundColor(resnormal)
highTarget = null
if (highlight != -1) {
notifyItemChanged(highlight)
highlight = -1
}
}
super.onScrolled(recyclerView, dx, dy)
val manager = recyclerView.layoutManager as androidx.recyclerview.widget.LinearLayoutManager
val firstVisibleItem = manager.findFirstVisibleItemPosition()
Expand Down
50 changes: 37 additions & 13 deletions app/src/main/java/jp/ddo/hotmist/unicodepad/PageAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,31 +110,55 @@ class PageAdapter(private val activity: UnicodeActivity, private val pref: Share
return adapters[position].let { adapter ->
adapter.setListener(this)
if (adapter is DragListUnicodeAdapter<*> && adapter.single) {
DynamicDragListView(activity, null).let { view ->
DynamicDragListView(activity, null).also { view ->
view.setLayoutManager(LinearLayoutManager(activity))
view.setDragListListener(adapter)
view.setAdapter(adapter, false)
view.setCanDragHorizontally(false)
view.setCanDragVertically(true)
view.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
views[position] = view
adapter.instantiate(view).also { layout ->
collection.addView(layout, 0)
layouts[position] = layout
}
}
} else {
check(adapter is RecyclerView.Adapter<*>)
RecyclerView(activity).let { view ->
RecyclerView(activity).also { view ->
view.adapter = adapter
view.layoutManager = adapter.getLayoutManager(activity, column)
view.adapter = adapter
view.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
views[position] = view
adapter.instantiate(view).also { layout ->
collection.addView(layout, 0)
layouts[position] = layout
}
}.let { view ->
view.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
views[position] = view
adapter.instantiate(view).also { layout ->
val scaleDetector = ScaleGestureDetector(activity, object : ScaleGestureDetector.SimpleOnScaleGestureListener() {
override fun onScale(detector: ScaleGestureDetector): Boolean {
return (if (detector.scaleFactor > 1.05f) {
true
} else if (detector.scaleFactor < 0.95f) {
false
} else {
null
})?.let {
if (adapter.single != it) {
pref.edit().putString(
if (adapter === adapterRecent) "single_rec" else
if (adapter === adapterList) "single_list" else
if (adapter === adapterFind) "single_find" else
if (adapter === adapterFavorite) "single_fav" else
if (adapter === adapterEdit) "single_edt" else
if (adapter === adapterEmoji) "single_emoji" else null,
it.toString()
).apply()
notifyDataSetChanged()
}
true
} ?: false
}
})
(if (view is DragListView) view.recyclerView else view).setOnTouchListener { _, event ->
scaleDetector.onTouchEvent(event)
scaleDetector.isInProgress
}
collection.addView(layout, 0)
layouts[position] = layout
}
}
}
Expand Down
26 changes: 18 additions & 8 deletions app/src/main/java/jp/ddo/hotmist/unicodepad/TabsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ package jp.ddo.hotmist.unicodepad

import android.annotation.SuppressLint
import android.os.Bundle
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.view.setPadding
import androidx.recyclerview.widget.LinearLayoutManager
import com.woxthebox.draglistview.DragListView

Expand All @@ -34,14 +37,21 @@ class TabsActivity : BaseActivity() {
@SuppressLint("ClickableViewAccessibility")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val view = DynamicDragListView(this, null)
val adapter = TabsAdapter(this)
view.setLayoutManager(LinearLayoutManager(this))
view.setDragListListener(adapter)
view.setAdapter(adapter, true)
view.setCanDragHorizontally(false)
view.setCanDragVertically(true)
setContentView(view)
setContentView(LinearLayout(this).apply {
orientation = LinearLayout.VERTICAL
addView(TextView(this@TabsActivity).apply {
setText(R.string.tabs_hint)
setPadding((8 * this@TabsActivity.resources.displayMetrics.density).toInt())
})
val view = DynamicDragListView(this@TabsActivity, null)
val adapter = TabsAdapter(this@TabsActivity)
view.setLayoutManager(LinearLayoutManager(this@TabsActivity))
view.setDragListListener(adapter)
view.setAdapter(adapter, true)
view.setCanDragHorizontally(false)
view.setCanDragVertically(true)
addView(view)
})
}

override fun onSupportNavigateUp(): Boolean {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/jp/ddo/hotmist/unicodepad/UnicodeAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class GridLayoutManagerWrapper(context: Context, spanCount: Int) : GridLayoutMan
super.onLayoutChildren(recycler, state)
} catch (e: IndexOutOfBoundsException) {
Log.e("GridLayoutManager", "onLayoutChildren: $e")
} catch (e: IllegalArgumentException) {
Log.e("GridLayoutManager", "onLayoutChildren: $e")
}
}
}
Expand Down
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 @@ -403,6 +403,7 @@
<string name="no_ad_desc">広告を非表示</string>
<string name="skip_guide_desc">チュートリアルをスキップ</string>
<string name="tabs_desc">タブ設定…</string>
<string name="tabs_hint">ヒント: リスト上でピンチイン・アウトすると1列と複数列を素早く切り替えられます</string>
<string name="shown_desc">表示タブ</string>
<string name="hidden_desc">非表示タブ</string>

Expand Down
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 @@ -458,6 +458,7 @@
<string name="no_ad_desc">Opt-out ads</string>
<string name="skip_guide_desc">Skip tutorials</string>
<string name="tabs_desc">Tabs settings…</string>
<string name="tabs_hint">Hint: You can quickly switch between single / multiple columns by pinching in and out on lists</string>
<string name="shown_desc">Shown tabs</string>
<string name="hidden_desc">Hidden tabs</string>

Expand Down

0 comments on commit 43fa027

Please # to comment.