package hunnu.sj.raise_money;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ListView;

import java.util.ArrayList;

import hunnu.sj.raise_money.donated_record.DonatedRecordAdapter;
import hunnu.sj.raise_money.record.Record;

public class BrowseDonatedRecordActivity extends AppCompatActivity {
    private ArrayList<Record> records = new ArrayList<>();
    private ListView lv_record;
    private DonatedRecordAdapter donatedRecordAdapter;
    private long stu_id;
    private Handler mhandler = new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if(msg.what==1){
                donatedRecordAdapter.notifyDataSetChanged();
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_browse_record);
        Intent intent = getIntent();
        stu_id = intent.getLongExtra("stu_id",0);
        donatedRecordAdapter = new DonatedRecordAdapter(this,records);
        lv_record = findViewById(R.id.lv_browse_denate_record);
        lv_record.setAdapter(donatedRecordAdapter);
        new BrowseDonateRecordThread().start();

    }

    class BrowseDonateRecordThread extends Thread{
        @Override
        public void run() {
            Message msg =mhandler.obtainMessage();
            int flags = InfoUtils.getDonatedRecords(records,stu_id);
            msg.what = flags;
            mhandler.sendMessage(msg);
        }
    }

}