| | |
| | | import android.view.ViewGroup |
| | | import android.widget.Button |
| | | import android.widget.ImageView |
| | | import android.widget.LinearLayout |
| | | import android.widget.TextView |
| | | import android.widget.Toast |
| | | import androidx.appcompat.app.AppCompatActivity |
| | |
| | | import com.example.firstapp.App.Companion.context |
| | | import com.example.firstapp.R |
| | | import com.example.firstapp.adapter.InvitationAdapter |
| | | import com.example.firstapp.adapter.InvitationRecord2Adapter |
| | | import com.example.firstapp.adapter.InvitationRecordAdapter |
| | | import com.example.firstapp.database.request.SmsLoginRequest |
| | | import com.example.firstapp.database.service.RetrofitClient |
| | |
| | | private lateinit var recyclerSuccessView: RecyclerView |
| | | private lateinit var recyclerRecordView: RecyclerView |
| | | private lateinit var adapter: InvitationAdapter |
| | | private lateinit var recordadapter: InvitationRecordAdapter |
| | | // private lateinit var recordadapter: InvitationRecordAdapter |
| | | private var data = mutableListOf<InvitationRecord>() |
| | | private var recorddata = mutableListOf<InvitationRecord>() |
| | | private val handler = Handler(Looper.getMainLooper()) |
| | |
| | | private var currentScrollPosition = 0 |
| | | private var currentRecordScrollPosition = 0 |
| | | private var itemHeight = 0 // 动态存储item高度 |
| | | |
| | | private lateinit var invitedRecordRecyclerView2: RecyclerView |
| | | private lateinit var invitationAdapter: InvitationRecord2Adapter |
| | | |
| | | |
| | | |
| | | override fun onCreate(savedInstanceState: Bundle?) { |
| | | super.onCreate(savedInstanceState) |
| | |
| | | //初始化Adapter |
| | | initSuccessAdapter() |
| | | |
| | | initRecorddapter() |
| | | // initRecorddapter() |
| | | |
| | | //加载数据 |
| | | getInvitereward() |
| | |
| | | clipboard.setPrimaryClip(clip) |
| | | Toast.makeText(this, "已复制邀请码", Toast.LENGTH_SHORT).show() |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | } |
| | | // 记录列表 |
| | | recyclerRecordView = findViewById(R.id.invitationrecordRecyclerView) |
| | | recyclerRecordView.layoutManager = LinearLayoutManager(this) |
| | | // recyclerRecordView = findViewById(R.id.invitationrecordRecyclerView) |
| | | // recyclerRecordView.layoutManager = LinearLayoutManager(this) |
| | | } |
| | | |
| | | private fun initSuccessAdapter() { |
| | |
| | | recyclerSuccessView.adapter = adapter |
| | | } |
| | | |
| | | private fun initRecorddapter() { |
| | | recordadapter = InvitationRecordAdapter(this, recorddata) |
| | | recyclerRecordView.adapter = recordadapter |
| | | } |
| | | // private fun initRecorddapter() { |
| | | // recordadapter = InvitationRecordAdapter(this, recorddata) |
| | | // recyclerRecordView.adapter = recordadapter |
| | | // } |
| | | // private fun initRecorddapter() { |
| | | // recordadapter = InvitationRecordAdapter(this, recorddata).apply { |
| | | // registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { |
| | | // override fun onItemRangeInserted(positionStart: Int, itemCount: Int) { |
| | | // // 数据插入时检查高度 |
| | | // recyclerRecordView.post { |
| | | // if (recyclerRecordView.childCount > 0) { |
| | | // itemHeight = recyclerRecordView.getChildAt(0).height |
| | | // } |
| | | // } |
| | | // } |
| | | // }) |
| | | // } |
| | | // recyclerRecordView.adapter = recordadapter |
| | | // } |
| | | |
| | | private fun getInvitereward() { |
| | | lifecycleScope.launch { |
| | |
| | | addAll(records.myInvite ?: emptyList()) // 注意这里使用myInvite |
| | | } |
| | | |
| | | // 加载适配器 |
| | | invitedRecordRecyclerView2 = findViewById(R.id.invited_record_recycler_view_2) |
| | | invitedRecordRecyclerView2.layoutManager = LinearLayoutManager(this@InvitationActivity) |
| | | invitationAdapter = InvitationRecord2Adapter(records.myInvite) |
| | | invitedRecordRecyclerView2.adapter = invitationAdapter |
| | | |
| | | |
| | | // 在UI线程更新适配器 |
| | | withContext(Dispatchers.Main) { |
| | | adapter.notifyDataSetChanged() |
| | | recordadapter.notifyDataSetChanged() |
| | | // recordadapter.notifyDataSetChanged() |
| | | } |
| | | } ?: run { |
| | | Log.w("API", "Response data is null") |