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.record.Record;
import hunnu.sj.raise_money.donate_record.DonateRecordAdapter;

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

    }

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

}
