@@ -8,15 +8,11 @@ import android.os.Looper
88import android.view.View
99import android.view.ViewGroup
1010import android.view.ViewTreeObserver
11+ import android.widget.LinearLayout
12+ import android.widget.TextView
1113import android.widget.Toast
1214import android.widget.ToggleButton
1315import com.google.gson.Gson
14- import kotlinx.android.synthetic.main.activity_dl.*
15- import kotlinx.android.synthetic.main.button_tbutton.view.*
16- import kotlinx.android.synthetic.main.line_caption.view.*
17- import kotlinx.android.synthetic.main.line_horizonal.view.*
18- import kotlinx.android.synthetic.main.widget_downloadbar.*
19- import kotlinx.android.synthetic.main.widget_titlebar.*
2016import top.fumiama.copymangaweb.R
2117import top.fumiama.copymangaweb.activity.MainActivity.Companion.mh
2218import top.fumiama.copymangaweb.activity.template.ToolsBoxActivity
@@ -33,6 +29,7 @@ import java.io.File
3329import java.lang.Thread.sleep
3430
3531class DlActivity : ToolsBoxActivity () {
32+ lateinit var mBinding: ActivityDlBinding
3633 private var tbtncnt = 0
3734 private var isNewTitle = false
3835 var haveSElectAll = false
@@ -52,11 +49,11 @@ class DlActivity : ToolsBoxActivity() {
5249 @SuppressLint(" SetTextI18n" )
5350 override fun onCreate (savedInstanceState : Bundle ? ) {
5451 super .onCreate(savedInstanceState)
55- val binding = ActivityDlBinding .inflate(layoutInflater)
56- setContentView(binding .root)
52+ mBinding = ActivityDlBinding .inflate(layoutInflater)
53+ setContentView(mBinding .root)
5754 mh?.saveUrlsOnly = true
5855 mangaDlTools = MangaDlTools (this )
59- dwh.apply { post {
56+ mBinding. dwh.apply { post {
6057 settings.userAgentString = getString(R .string.pc_ua)
6158 webChromeClient = WebChromeClient ()
6259 setWebViewClient(" h.js" )
@@ -72,16 +69,24 @@ class DlActivity : ToolsBoxActivity() {
7269 super .onDestroy()
7370 }
7471
75- private fun showDlCard (){
76- // ObjectAnimator.ofFloat(csdwn, "alpha", 0.3f, 0.9f).setDuration(233).start()
77- ObjectAnimator .ofFloat(csdwn, " translationX" , cdwnWidth.toFloat() * 0.9f , 0f ).setDuration(
72+ private fun showDlCard () {
73+ ObjectAnimator .ofFloat(
74+ mBinding.dldlbar.csdwn,
75+ " translationX" ,
76+ cdwnWidth.toFloat() * 0.9f ,
77+ 0f
78+ ).setDuration(
7879 233
7980 ).start()
8081 }
8182
82- private fun hideDlCard (){
83- // ObjectAnimator.ofFloat(csdwn, "alpha", 0.9f, 0.3f).setDuration(233).start()
84- ObjectAnimator .ofFloat(csdwn, " translationX" , 0f , cdwnWidth.toFloat() * 0.9f ).setDuration(
83+ private fun hideDlCard () {
84+ ObjectAnimator .ofFloat(
85+ mBinding.dldlbar.csdwn,
86+ " translationX" ,
87+ 0f ,
88+ cdwnWidth.toFloat() * 0.9f
89+ ).setDuration(
8590 233
8691 ).start()
8792 }
@@ -112,28 +117,28 @@ class DlActivity : ToolsBoxActivity() {
112117
113118 @SuppressLint(" SetTextI18n" )
114119 fun setLayouts () {
115- ttitle.apply { post { text = comicName } }
120+ mBinding.dtitle. ttitle.apply { post { text = comicName } }
116121 val widthData = toolsBox.calcWidthFromDp(8 , 64 )
117122 btnNumPerRow = widthData[0 ]
118123 btnw = widthData[1 ]
119- csdwn.apply { post { viewTreeObserver.addOnGlobalLayoutListener(object :
124+ mBinding.dldlbar. csdwn.apply { post { viewTreeObserver.addOnGlobalLayoutListener(object :
120125 ViewTreeObserver .OnGlobalLayoutListener {
121126 override fun onGlobalLayout () {
122- cdwnWidth = csdwn. width
127+ cdwnWidth = width
123128 viewTreeObserver.removeOnGlobalLayoutListener(this )
124129 }
125130 }) } }
126- dllazys.onScrollListener = object : LazyScrollView .OnScrollListener {
131+ mBinding. dllazys.onScrollListener = object : LazyScrollView .OnScrollListener {
127132 override fun onBottom () {}
128- override fun onScroll () { if (csdwn.translationX == 0f ) hideDlCard() }
133+ override fun onScroll () { if (mBinding.dldlbar. csdwn.translationX == 0f ) hideDlCard() }
129134 override fun onTop () {}
130135 }
131- cdwn.let { it.post {
136+ mBinding.dldlbar. cdwn.let { it.post {
132137 it.setOnClickListener {
133- if (csdwn.translationX != 0f ) showDlCard()
138+ if (mBinding.dldlbar. csdwn.translationX != 0f ) showDlCard()
134139 else if (checkedChapter == 0 ) hideDlCard()
135140 else {
136- pdwn.progress = 0
141+ mBinding.dldlbar. pdwn.progress = 0
137142 if (canDl || checkedChapter == 0 ) canDl = false
138143 else {
139144 haveDlStarted = true
@@ -152,7 +157,9 @@ class DlActivity : ToolsBoxActivity() {
152157 return @setOnLongClickListener true
153158 }
154159 } }
155- isearch.apply { post { setOnClickListener { showMultiSelectInfo() } } }
160+ mBinding.dtitle.isearch.apply { post {
161+ setOnClickListener { showMultiSelectInfo() }
162+ } }
156163 Thread { analyzeStructure() }.start()
157164 }
158165
@@ -165,9 +172,9 @@ class DlActivity : ToolsBoxActivity() {
165172 ViewMangaActivity .zipList = arrayOf()
166173 Gson ().fromJson(json?.reader(), Array <ComicStructure >::class .java)?.let {
167174 for (group in it) {
168- val tc = layoutInflater.inflate(R .layout.line_caption, ldwn, false )
169- tc.tcptn.text = group.name
170- ldwn.apply { post {
175+ val tc = layoutInflater.inflate(R .layout.line_caption, mBinding. ldwn, false )
176+ tc.findViewById< TextView >( R .id. tcptn) .text = group.name
177+ mBinding. ldwn.apply { post {
171178 addView(
172179 tc,
173180 ViewGroup .LayoutParams (
@@ -176,7 +183,7 @@ class DlActivity : ToolsBoxActivity() {
176183 )
177184 )
178185 addView(
179- layoutInflater.inflate(R .layout.div_h, ldwn, false ),
186+ layoutInflater.inflate(R .layout.div_h, mBinding. ldwn, false ),
180187 ViewGroup .LayoutParams (
181188 ViewGroup .LayoutParams .MATCH_PARENT ,
182189 ViewGroup .LayoutParams .WRAP_CONTENT
@@ -227,53 +234,60 @@ class DlActivity : ToolsBoxActivity() {
227234 @SuppressLint(" SetTextI18n" )
228235 fun addToggleButton (title : String , url : String , caption : String ) {
229236 if ((tbtncnt % btnNumPerRow == 0 ) || isNewTitle) {
230- toggleButtonLine = layoutInflater.inflate(R .layout.line_horizonal, ldwn, false )
231- ldwn.apply {
237+ toggleButtonLine = layoutInflater.inflate(R .layout.line_horizonal, mBinding. ldwn, false )
238+ mBinding. ldwn.apply {
232239 val t = toggleButtonLine
233240 post { addView(t) }
234241 }
235242 tbtncnt = 0
236243 isNewTitle = false
237244 }
238- val tbv = layoutInflater.inflate(R .layout.button_tbutton, toggleButtonLine.ltbtn, false )
239- tbv.tbtn.index = tbtnlist.size
240- tbtnlist + = tbv.tbtn
241- tbv.tbtn.url = url
245+ val tbv = layoutInflater.inflate(R .layout.button_tbutton, toggleButtonLine.findViewById(R .id.ltbtn), false )
246+ val tbvTbtn = tbv.findViewById<ChapterToggleButton >(R .id.tbtn)? : return
247+ tbvTbtn.index = tbtnlist.size
248+ tbtnlist + = tbvTbtn
249+ tbvTbtn.url = url
242250 tbtncnt++
243251 val zipPosition = ViewMangaActivity .zipList?.size
244252 ViewMangaActivity .zipList = ViewMangaActivity .zipList?.plus(" $title .zip" )
245- tbv.tbtn .textOff = title
246- tbv.tbtn .textOn = title
247- tbv.tbtn .text = title
248- tbv.tbtn .hint = caption
249- tbv.tbtn .layoutParams.width = btnw
253+ tbvTbtn .textOff = title
254+ tbvTbtn .textOn = title
255+ tbvTbtn .text = title
256+ tbvTbtn .hint = caption
257+ tbvTbtn .layoutParams.width = btnw
250258 val zipFile = File (" ${getExternalFilesDir(" " )} /$comicName /$caption /$title .zip" )
251259 if (zipFile.exists()) {
252- tbv.tbtn .setBackgroundResource(R .drawable.rndbg_checked)
253- tbv.tbtn .isChecked = false
254- tbv.tbtn .freezesText = true
260+ tbvTbtn .setBackgroundResource(R .drawable.rndbg_checked)
261+ tbvTbtn .isChecked = false
262+ tbvTbtn .freezesText = true
255263 }
256264 toggleButtonLine.apply { post {
257- ltbtn.addView(tbv)
265+ findViewById< LinearLayout >( R .id. ltbtn)? .addView(tbv)
258266 invalidate()
259267 } }
260- tbv.tbtn .setOnClickListener { v ->
268+ tbvTbtn .setOnClickListener { v ->
261269 val normalAct = (multiSelect && zipFile.exists()) || ! zipFile.exists()
262- if (zipFile.exists() && ! v.tbtn.isChecked) v.tbtn.apply { post { setBackgroundResource(R .drawable.rndbg_checked) } }
263- else if (normalAct) v.tbtn.apply { post { setBackgroundResource(R .drawable.toggle_button) } }
270+ val tbtn = v.findViewById<ChapterToggleButton >(R .id.tbtn)? : return @setOnClickListener
271+ if (zipFile.exists() && ! tbtn.isChecked) tbtn.apply { post { setBackgroundResource(R .drawable.rndbg_checked) } }
272+ else if (normalAct) tbtn.apply { post { setBackgroundResource(R .drawable.toggle_button) } }
264273 if (normalAct) {
265- if (v.tbtn.isChecked) tdwn.apply { post { text = " $dldChapter /${++ checkedChapter} " } }
266- else tdwn.apply { post { text = " $dldChapter /${-- checkedChapter} " } }
267- } else if (v.tbtn.isChecked) {
268- v.tbtn.apply { post {
274+ mBinding.dldlbar.tdwn.apply {
275+ if (tbtn.isChecked) post {
276+ text = " $dldChapter /${++ checkedChapter} "
277+ } else post {
278+ text = " $dldChapter /${-- checkedChapter} "
279+ }
280+ }
281+ } else if (tbtn.isChecked) {
282+ tbtn.apply { post {
269283 isChecked = false
270284 zipPosition?.let { Thread {
271285 callVM(title, zipFile, it)
272286 }.start() }
273287 } }
274288 }
275289 }
276- tbv.tbtn .setOnLongClickListener {
290+ tbvTbtn .setOnLongClickListener {
277291 if (zipFile.exists()) {
278292 toolsBox.buildInfo(" 确认删除这些章节?" ,
279293 " 该操作将不可撤销" ,
@@ -282,8 +296,10 @@ class DlActivity : ToolsBoxActivity() {
282296 " 取消" ,
283297 {
284298 if (checkedChapter == 0 ) {
285- it.tbtn.apply { post { isChecked = true } }
286- tdwn.apply { post { text = " $dldChapter /${++ checkedChapter} " } }
299+ tbvTbtn.apply { post { isChecked = true } }
300+ mBinding.dldlbar.tdwn.apply { post {
301+ text = " $dldChapter /${++ checkedChapter} "
302+ } }
287303 }
288304 handler.sendEmptyMessage(7 )
289305 })
@@ -324,7 +340,9 @@ class DlActivity : ToolsBoxActivity() {
324340
325341 @SuppressLint(" SetTextI18n" )
326342 fun updateProgressBar () {
327- tdwn.apply { post { text = " ${++ dldChapter} /$checkedChapter " } }
343+ mBinding.dldlbar.tdwn.apply { post {
344+ text = " ${++ dldChapter} /$checkedChapter "
345+ } }
328346 setProgress2(dldChapter * 100 / checkedChapter, 233 )
329347 }
330348
@@ -336,6 +354,7 @@ class DlActivity : ToolsBoxActivity() {
336354 }
337355
338356 fun setProgress2 (end : Int , duration : Long ) {
357+ val pdwn = mBinding.dldlbar.pdwn
339358 ObjectAnimator .ofInt(
340359 pdwn,
341360 " progress" ,
0 commit comments