Skip to content

Commit

Permalink
v2.2.7
Browse files Browse the repository at this point in the history
新增
1. 设置每行显示卡片数
修复
1. 进入我的订阅概率闪退
  • Loading branch information
fumiama committed Mar 17, 2024
1 parent aa0190f commit 9347a8d
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 78 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/fumiama.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId 'top.fumiama.copymanga'
minSdkVersion 23
targetSdkVersion 34
versionCode 54
versionName '2.2.6'
versionCode 55
versionName '2.2.7'
resourceConfigurations += ['zh', 'zh-rCN']

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ open class MangaPagesFragmentTemplate(inflateRes:Int, private val isLazy: Boolea
cardPerRow = widthData?.get(0) ?: 3
cardWidth = widthData?.get(2) ?: 128
cardHeight = (cardWidth / 0.75 + 0.5).toInt()
withContext(Dispatchers.Main){
withContext(Dispatchers.Main) {
mysp.footerView.lht.text = "加载"
mysp.headerView.lht.text = "刷新"
mydll?.setPadding(0, 0, 0, navBarHeight)
Expand All @@ -102,8 +102,8 @@ open class MangaPagesFragmentTemplate(inflateRes:Int, private val isLazy: Boolea
setListeners()
}

private fun managePage() {
lifecycleScope.launch { addPage() }
private suspend fun managePage() {
addPage()
if (isLazy) {
mysp.apply {
post {
Expand All @@ -118,8 +118,8 @@ open class MangaPagesFragmentTemplate(inflateRes:Int, private val isLazy: Boolea
withContext(Dispatchers.IO) {
reset()
delay(600)
addPage()
}
addPage()
}
}
})
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/top/fumiama/copymanga/tools/ui/UITools.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.view.View
import android.widget.Toast
import androidx.preference.PreferenceManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import top.fumiama.dmzj.copymanga.R
Expand Down Expand Up @@ -94,11 +95,15 @@ class UITools(that: Context?, w: WeakReference<Activity>? = null) {
private fun px2dp(px:Int):Int?{
return zis?.resources?.displayMetrics?.density?.let { (px.toDouble() / it + 0.5).toInt()}
}
fun calcWidthFromDp(marginLeftDp:Int, widthDp:Int):List<Int>{
fun calcWidthFromDp(marginLeftDp:Int, widthDp:Int): List<Int> {
val margin = marginLeftDp.toDouble()
val marginPx = dp2px(marginLeftDp)?:16
val screenWidth = zis?.resources?.displayMetrics?.widthPixels?:1080
val numPerRow = ((px2dp(screenWidth)?:400).toDouble() / (widthDp + 2 * margin) + 0.5).toInt()
val numPerRow = ((px2dp(screenWidth)?:400).toDouble() / (widthDp + 2 * margin) + 0.5).toInt().let {
it + (zis?.let {
a -> PreferenceManager.getDefaultSharedPreferences(a).getInt("settings_cat_general_sb_card_per_row", 0)
} ?: 0)
}.let { if(it <= 0) 3 else it }
val w = (screenWidth - marginPx*numPerRow*2)/numPerRow
val totalWidth = screenWidth/numPerRow
return listOf(numPerRow, w, totalWidth)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class RankFragment : InfoCardLoader(R.layout.fragment_rank, R.id.action_nav_rank

override fun setListeners() {
super.setListeners()
frlai.lrt.addOnTabSelectedListener(object: TabLayout.OnTabSelectedListener {
frlai.lrt.apply { post { addOnTabSelectedListener(object: TabLayout.OnTabSelectedListener {
override fun onTabReselected(tab: TabLayout.Tab?) {}

override fun onTabSelected(tab: TabLayout.Tab?) {
Expand All @@ -68,7 +68,7 @@ class RankFragment : InfoCardLoader(R.layout.fragment_rank, R.id.action_nav_rank
}

override fun onTabUnselected(tab: TabLayout.Tab?) {}
})
}) } }
}

fun showSexInfo(toolsBox: UITools) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,42 @@ class ShelfFragment : InfoCardLoader(R.layout.fragment_shelf, R.id.action_nav_su
}

private fun setUpdate() {
if (ad?.exit == true) return
line_shelf_updated.apt.setText(R.string.menu_update_time)
line_shelf_updated.setOnClickListener {
val same = sortValue in 0..1
sortValue = rotate(it.apim, same, 0)
if (!same) fade()
delayedRefresh(400)
}
line_shelf_updated.apply { post {
if (ad?.exit == true) return@post
apt.setText(R.string.menu_update_time)
setOnClickListener {
val same = sortValue in 0..1
sortValue = rotate(it.apim, same, 0)
if (!same) fade()
delayedRefresh(400)
}
} }
}

private fun setModify() {
if (ad?.exit == true) return
line_shelf_modifier.apt.setText(R.string.menu_add_time)
line_shelf_modifier.setOnClickListener {
val same = sortValue in 2..3
sortValue = rotate(it.apim, same, 2)
if (!same) fade()
delayedRefresh(400)
}
line_shelf_modifier.apply { post {
if (ad?.exit == true) return@post
apt.setText(R.string.menu_add_time)
setOnClickListener {
val same = sortValue in 2..3
sortValue = rotate(it.apim, same, 2)
if (!same) fade()
delayedRefresh(400)
}
} }
}

private fun setBrowse() {
if (ad?.exit == true) return
line_shelf_browse.apt.setText(R.string.menu_read_time)
line_shelf_browse.setOnClickListener {
val same = sortValue>=4
sortValue = rotate(it.apim, same, 4)
if (!same) fade()
delayedRefresh(400)
}
line_shelf_browse.apply { post {
if (ad?.exit == true) return@post
apt.setText(R.string.menu_read_time)
setOnClickListener {
val same = sortValue>=4
sortValue = rotate(it.apim, same, 4)
if (!same) fade()
delayedRefresh(400)
}
} }
}

private fun rotate(img: View, isSameSlot: Boolean, offset: Int): Int {
Expand All @@ -99,22 +105,14 @@ class ShelfFragment : InfoCardLoader(R.layout.fragment_shelf, R.id.action_nav_su
}

private fun fade() {
when(sortValue) {
0, 1 -> {
line_shelf_updated.alpha = 1f
line_shelf_modifier.alpha = 0.5f
line_shelf_browse.alpha = 0.5f
}
2, 3 -> {
line_shelf_updated.alpha = 0.5f
line_shelf_modifier.alpha = 1f
line_shelf_browse.alpha = 0.5f
}
4, 5 -> {
line_shelf_updated.alpha = 0.5f
line_shelf_modifier.alpha = 0.5f
line_shelf_browse.alpha = 1f
}
val alphae = when(sortValue) {
0, 1 -> listOf(1f, 0.5f, 0.5f)
2, 3 -> listOf(0.5f, 1f, 0.5f)
4, 5 -> listOf(0.5f, 0.5f, 1f)
else -> listOf(1f, 1f, 1f)
}
line_shelf_updated.apply { post { alpha = alphae[0] } }
line_shelf_modifier.apply { post { alpha = alphae[1] } }
line_shelf_browse.apply { post { alpha = alphae[2] } }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ import androidx.preference.EditTextPreferenceDialogFragmentCompat
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import top.fumiama.copymanga.tools.ui.UITools
import top.fumiama.dmzj.copymanga.R
import java.lang.Thread.sleep

class SettingsFragment: PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
Expand All @@ -36,7 +34,7 @@ class SettingsFragment: PreferenceFragmentCompat() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
context?.let { c ->
view.setPadding(0, 0, 0, UITools.getNavigationBarHeight(c))
view.apply { post { setPadding(0, 0, 0, UITools.getNavigationBarHeight(c)) } }
}
}

Expand All @@ -46,33 +44,35 @@ class SettingsFragment: PreferenceFragmentCompat() {
val f = EditTextPreferenceDialogFragmentCompat.newInstance(preference.key)
f.setTargetFragment(this, 0)
f.show(parentFragmentManager, null)
Thread {
var diff = 0
var cnt = 0
while (diff == 0 && cnt++ < 20) {
sleep(50)
if (f.dialog == null) continue
val v = view?:return@Thread
// https://github.com/mikepenz/MaterialDrawer/blob/aa9136fb4f5b3a80460fe5f47213985026d20c88/library/src/main/java/com/mikepenz/materialdrawer/util/KeyboardUtil.java
val r = Rect()
//r will be populated with the coordinates of your view that area still visible.
v.getWindowVisibleDisplayFrame(r)
//get screen height and calculate the difference with the useable area from the r
val height = v.context.resources.displayMetrics.heightPixels
diff = height - r.bottom
Log.d("MySF", "diff: $diff")
}
Log.d("MySF", "diff out while: $diff")
if (diff <= 0) return@Thread
Log.d("MySF", "f.dialog is ${f.dialog}")
f.activity?.runOnUiThread {
f.dialog?.window?.apply {
val attr = attributes
Log.d("MySF", "animate from ${attr.y} to ${attr.y-diff/2}")
ObjectAnimator.ofInt(WindowAttributeSetter(this), "y", attr.y, attr.y-diff/2).setDuration(233).start()
lifecycleScope.launch {
withContext(Dispatchers.IO) {
var diff = 0
var cnt = 0
while (diff == 0 && cnt++ < 20) {
delay(50)
if (f.dialog == null) continue
val v = view?:return@withContext
// https://github.com/mikepenz/MaterialDrawer/blob/aa9136fb4f5b3a80460fe5f47213985026d20c88/library/src/main/java/com/mikepenz/materialdrawer/util/KeyboardUtil.java
val r = Rect()
//r will be populated with the coordinates of your view that area still visible.
v.getWindowVisibleDisplayFrame(r)
//get screen height and calculate the difference with the usable area from the r
val height = v.context.resources.displayMetrics.heightPixels
diff = height - r.bottom
Log.d("MySF", "diff: $diff")
}
Log.d("MySF", "diff out while: $diff")
if (diff <= 0) return@withContext
Log.d("MySF", "f.dialog is ${f.dialog}")
withContext(Dispatchers.Main) {
f.dialog?.window?.apply {
val attr = attributes
Log.d("MySF", "animate from ${attr.y} to ${attr.y-diff/2}")
ObjectAnimator.ofInt(WindowAttributeSetter(this), "y", attr.y, attr.y-diff/2).setDuration(233).start()
}
}
}
}.start()
}
return
}
super.onDisplayPreferenceDialog(preference)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@
<string name="settings_cat_general">通用</string>
<string name="settings_cat_general_sb_title_startup_menu">启动时显示</string>
<string name="settings_cat_general_sb_summary_startup_menu">默认主页</string>
<string name="settings_cat_general_sb_card_per_row">每行加载卡片数偏移</string>
<string name="settings_cat_general_sm_card_per_row">默认为0表示无偏移, 在此基础上加减</string>

<string name="settings_cat_net">网络</string>
<string name="settings_cat_net_sb_title_image_resolution">图片分辨率</string>
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/xml/pref_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
app:entries="@array/menus"
app:entryValues="@array/menu_ids"
android:defaultValue="0"/>
<SeekBarPreference
android:defaultValue="0"
android:max="8"
app:iconSpaceReserved="false"
app:key="settings_cat_general_sb_card_per_row"
app:min="-8"
app:showSeekBarValue="true"
app:summary="@string/settings_cat_general_sm_card_per_row"
app:title="@string/settings_cat_general_sb_card_per_row" />
</PreferenceCategory>
<PreferenceCategory
app:iconSpaceReserved="false"
Expand Down

0 comments on commit 9347a8d

Please sign in to comment.