lmw
2023-05-12 f67802a41f9e01444d1115f34ecc6e1beb05fc3b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.fuban.user.ui.crosscity
 
import android.app.Activity
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import androidx.recyclerview.widget.LinearLayoutManager
import cn.sinata.xldutils.view.SwipeRefreshRecyclerLayout
import com.fuban.user.R
import com.fuban.user.network.entity.Line
import com.fuban.user.ui.TransparentStatusBarActivity
import com.fuban.user.ui.crosscity.adapter.LineAdapter
import org.jetbrains.anko.find
import org.jetbrains.anko.startActivity
 
class ChooseLineActivity :TransparentStatusBarActivity(){
    override fun setContentView() = R.layout.base_recyclerview_layout
 
    private val lvLine by lazy {
        find<SwipeRefreshRecyclerLayout>(R.id.swipeRefreshLayout)
    }
    private val datas by lazy {
        intent.getParcelableArrayListExtra<Line>("data")
    }
    private val adapter by lazy {
        LineAdapter(datas)
    }
    private val isScan by lazy { //是否扫码下单
        intent.getBooleanExtra("isScan",false)
    }
    private var receiver: BroadcastReceiver? = null
 
    override fun initClick() {
        adapter.setOnItemClickListener { view, position ->
            if (isScan){
                setResult(Activity.RESULT_OK,intent.putExtra("line" , datas[position]))
                finish()
            } else
                startActivity<ShiftActivity>("data" to datas[position],
                    "startCity" to intent.getStringExtra("startCity"),
                    "endCity" to intent.getStringExtra("endCity"),
                    "startId" to intent.getIntExtra("startId",0),
                    "endId" to intent.getIntExtra("endId",0))
        }
    }
 
    override fun initView() {
        title = "选择线路"
        lvLine.setPadding(0,2,0,0)
        lvLine.setLayoutManager(LinearLayoutManager(this))
        lvLine.setMode(SwipeRefreshRecyclerLayout.Mode.None)
        lvLine.setAdapter(adapter)
        receiver = object :BroadcastReceiver() {
            override fun onReceive(context: Context?, intent: Intent?) {
                finish()
            }
        }
        registerReceiver(receiver, IntentFilter("crossOrderSuccess"))
    }
 
    override fun onDestroy() {
        super.onDestroy()
        if (receiver!=null)
            unregisterReceiver(receiver)
    }
}