Skip to content

Commit

Permalink
Merge pull request #152 from Ryosuke839/develop
Browse files Browse the repository at this point in the history
Release 2.13.3
  • Loading branch information
Ryosuke839 committed Oct 22, 2023
2 parents ac7457d + 8f47039 commit 869f78b
Show file tree
Hide file tree
Showing 29 changed files with 682 additions and 592 deletions.
7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "jp.ddo.hotmist.unicodepad"
minSdkVersion 19
targetSdkVersion 34
versionCode 57
versionName "2.13.1"
versionCode 59
versionName "2.13.3"
}

compileOptions {
Expand All @@ -25,6 +25,7 @@ android {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

Expand Down Expand Up @@ -54,7 +55,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.emoji2:emoji2:1.4.0'
implementation 'androidx.preference:preference-ktx:1.2.1'
implementation 'com.mobeta.android.dslv:library:0.9.0'
implementation 'com.github.woxthebox:draglistview:1.7.3'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'com.github.mreram:showcaseview:1.4.1'

Expand Down
1 change: 1 addition & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-keep class com.woxthebox.draglistview.** { *; }
Binary file modified app/src/main/assets/namedb.zip
Binary file not shown.
32 changes: 32 additions & 0 deletions app/src/main/java/jp/ddo/hotmist/unicodepad/BaseActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package jp.ddo.hotmist.unicodepad

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceManager

private val THEME = intArrayOf(
R.style.Theme,
R.style.Theme_Light,
R.style.Theme_Light_DarkActionBar,
R.style.Theme_DayNight
)

abstract class BaseActivity : AppCompatActivity() {
private var currentTheme = -1
private fun getThemeFromPref(): Int {
val pref = PreferenceManager.getDefaultSharedPreferences(this)
return THEME[(pref.getString("theme", null)?.toIntOrNull() ?: 2131492983) - 2131492983]
}

override fun onCreate(savedInstanceState: Bundle?) {
setTheme(getThemeFromPref().also { currentTheme = it })
super.onCreate(savedInstanceState)
}

override fun onResume() {
super.onResume()
if (currentTheme != getThemeFromPref()) {
recreate()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import android.widget.Filter
import android.widget.Filterable
import android.widget.TextView
import java.util.*
import kotlin.math.min

internal class CompleteAdapter(context: Context, pref: SharedPreferences) : BaseAdapter(), Filterable {
private val lock = Any()
Expand All @@ -48,7 +49,7 @@ internal class CompleteAdapter(context: Context, pref: SharedPreferences) : Base

fun save(edit: SharedPreferences.Editor) {
var str = ""
for (s in list) str += """
for (s in list.subList(0, min(list.size, 255))) str += """
$s
""".trimIndent()
Expand All @@ -60,7 +61,7 @@ internal class CompleteAdapter(context: Context, pref: SharedPreferences) : Base
}

override fun getItem(position: Int): Any {
return current + list[position] + " "
return current + list[position]
}

override fun getItemId(position: Int): Long {
Expand Down
191 changes: 116 additions & 75 deletions app/src/main/java/jp/ddo/hotmist/unicodepad/EditAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,46 @@
package jp.ddo.hotmist.unicodepad

import android.app.Activity
import android.os.Build
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import android.widget.AbsListView
import android.widget.EditText
import com.mobeta.android.dslv.DragSortListView.DropListener
import com.mobeta.android.dslv.DragSortListView.RemoveListener
import java.util.*
import kotlin.streams.toList

internal class EditAdapter(activity: Activity, db: NameDatabase, single: Boolean, private val edit: EditText) : UnicodeAdapter(activity, db, single), TextWatcher, DropListener, RemoveListener {
private val list: ArrayList<Int> = ArrayList()
internal class EditAdapter(activity: Activity, db: NameDatabase, single: Boolean, private val edit: EditText) : DragListUnicodeAdapter<Long>(activity, db, single), TextWatcher {
private var suspend = false
override fun instantiate(view: View): View {
val view = view as AbsListView
list.clear()
val str = edit.editableText.toString()
var i = 0
while (i < str.length) {
val code = str.codePointAt(i)
list.add(code)
i += Character.charCount(code)
private var sequence = 0L

private fun setString(s: CharSequence) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
mItemList = s.codePoints().mapToLong { it.toLong() or (sequence++ shl 32) }.toList().toMutableList()
} else {
mItemList = ArrayList()
for (i in s.indices) {
if (Character.isLowSurrogate(s[i])) continue
mItemList.add(Character.codePointAt(s, i).toLong() or (sequence++ shl 32))
}
}
notifyDataSetChanged()
}

private fun isSameString(s: CharSequence): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
mItemList.map { it.toInt() } == s.codePoints().toList()
} else {
val list = ArrayList<Int>()
for (i in s.indices) {
if (Character.isLowSurrogate(s[i])) continue
list.add(Character.codePointAt(s, i))
}
mItemList.map { it.toInt() } == list
}
}

override fun instantiate(view: View): View {
setString(edit.editableText)
edit.addTextChangedListener(this)
return super.instantiate(view)
}
Expand All @@ -49,84 +67,107 @@ internal class EditAdapter(activity: Activity, db: NameDatabase, single: Boolean

fun updateString() {
if (suspend) return
val str = edit.editableText.toString()
list.clear()
var i = 0
while (i < str.length) {
val code = str.codePointAt(i)
list.add(code)
i += Character.charCount(code)
setString(edit.editableText)
}

override fun getUniqueItemId(position: Int): Long {
return mItemList[position].toLong()
}

override fun onItemDragStarted(position: Int) {
}

override fun onItemDragging(itemPosition: Int, x: Float, y: Float) {
}

override fun onItemDragEnded(fromPosition: Int, toPosition: Int) {
runOnUiThread {
suspend = true
val count = Character.charCount(mItemList[toPosition].toInt())
val (from, to) = if (fromPosition < toPosition) {
val p = mItemList.subList(0, fromPosition).sumOf { ch ->
Character.charCount(ch.toInt())
}
p to p + mItemList.subList(fromPosition, toPosition).sumOf { ch ->
Character.charCount(ch.toInt())
}
} else {
val p = mItemList.subList(0, toPosition).sumOf { ch ->
Character.charCount(ch.toInt())
}
p + mItemList.subList(toPosition + 1, fromPosition + 1).sumOf { ch ->
Character.charCount(ch.toInt())
} to p
}
edit.editableText.delete(from, from + count)
edit.editableText.insert(to, String(Character.toChars(mItemList[toPosition].toInt())))
suspend = false
if (!isSameString(edit.editableText)) {
setString(edit.editableText)
}
}
}

override fun name(): Int {
return R.string.edit
}

override fun getCount(): Int {
return list.size
}

override fun getItemCodePoint(i: Int): Long {
return list[i].toLong()
return (mItemList[i] and 0x1FFFFF).toLong()
}

override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
if (suspend) return
if (before == 0 && count == 0) return
val str = s.toString()
list.clear()
var i = 0
while (i < str.length) {
val code = str.codePointAt(i)
list.add(code)
i += Character.charCount(code)
if (count == 0) return
val startCp = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
s.subSequence(0, start).codePoints().count().toInt()
} else {
Character.codePointCount(s, 0, start)
}
invalidateViews()
}

override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun afterTextChanged(s: Editable) {}
override fun drop(from: Int, to: Int) {
runOnUiThread {
suspend = true
var fromBegin = 0
var fromEnd = 0
for (i in list.indices) {
if (i == from) fromBegin = fromEnd
fromEnd += Character.charCount(list[i])
if (i == from) break
}
edit.editableText.delete(fromBegin, fromEnd)
val ch = list.removeAt(from)
var toBegin = 0
for (i in list.indices) {
if (i == to) break
toBegin += Character.charCount(list[i])
val cps = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
s.subSequence(start, start + count).codePoints().toList()
} else {
val list = ArrayList<Int>()
for (i in 0 until count) {
if (Character.isLowSurrogate(s[start + i])) continue
list.add(Character.codePointAt(s, start + i))
}
edit.editableText.insert(toBegin, String(Character.toChars(ch)))
edit.editableText.replace(0, edit.editableText.length, edit.editableText)
suspend = false
list.add(to, ch)
invalidateViews()
list
}
cps.forEachIndexed { index, i ->
mItemList.add(startCp + index, i.toLong() or (sequence++ shl 32))
}
notifyItemRangeInserted(startCp, cps.size)
if (!isSameString(edit.editableText)) {
setString(edit.editableText)
}
}

override fun remove(which: Int) {
runOnUiThread {
suspend = true
var whichBegin = 0
var whichEnd = 0
for (i in list.indices) {
if (i == which) whichBegin = whichEnd
whichEnd += Character.charCount(list[i])
if (i == which) break
}
edit.editableText.delete(whichBegin, whichEnd)
edit.editableText.replace(0, edit.editableText.length, edit.editableText)
suspend = false
list.removeAt(which)
invalidateViews()
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
if (suspend) return
if (count == 0) return
if (!isSameString(edit.editableText)) {
setString(edit.editableText)
}
val startCp = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
s.subSequence(0, start).codePoints().count().toInt()
} else {
Character.codePointCount(s, 0, start)
}
val countCp = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
s.subSequence(start, start + count).codePoints().count().toInt()
} else {
Character.codePointCount(s, start, start + count)
}
for (i in 0 until countCp) {
mItemList.removeAt(startCp)
}
notifyItemRangeRemoved(startCp, countCp)
}

override fun afterTextChanged(s: Editable) {}

init {
mItemList = ArrayList()
}
}
6 changes: 3 additions & 3 deletions app/src/main/java/jp/ddo/hotmist/unicodepad/EmojiAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import android.widget.AdapterView.OnItemSelectedListener
import androidx.recyclerview.widget.RecyclerView
import java.util.*

internal class EmojiAdapter(activity: Activity, pref: SharedPreferences, private val db: NameDatabase, single: Boolean) : UnicodeAdapter(activity, db, single) {
internal class EmojiAdapter(activity: Activity, pref: SharedPreferences, private val db: NameDatabase, single: Boolean) : RecyclerUnicodeAdapter(activity, db, single) {
private var cur: Cursor? = null
private var jump: Spinner? = null
private lateinit var map: NavigableMap<Int, Int>
Expand Down Expand Up @@ -183,9 +183,9 @@ internal class EmojiAdapter(activity: Activity, pref: SharedPreferences, private
return grp[i]
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
super.onBindViewHolder(holder, position)
if (holder is CharacterViewHolder) holder.characterView.drawSlash(false)
if (holder is UnicodeAdapter.CharacterViewHolder) holder.characterView.drawSlash(false)
}

override fun save(edit: SharedPreferences.Editor) {
Expand Down
Loading

0 comments on commit 869f78b

Please sign in to comment.