package hunnu.sj.raise_money;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

public class NewsContentActivity extends AppCompatActivity{
    private long stu_id;
    private long user_id;
    String username;
    String newsTitle;
//    public static void actionStart(Context context, String newsTitle, String newsContent) {
//        Intent intent = new Intent(context, NewsContentActivity.class);
//        intent.putExtra("news_title", newsTitle);
//        intent.putExtra("news_content", newsContent);
//        context.startActivity(intent);
//    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
//        Log.v("news_title","here");
        setContentView(R.layout.news_content);
         newsTitle = getIntent().getStringExtra("news_title"); // 获取传入的新闻标题
        String newsContent = getIntent().getStringExtra("news_content"); // 获取传入的新闻内容
        stu_id = getIntent().getLongExtra("stu_id",0);
        user_id = getIntent().getLongExtra("user_id",0);
        NewsContentFragment newsContentFragment = (NewsContentFragment)
                getFragmentManager().findFragmentById(R.id.news_content_fragment);
        newsContentFragment.refresh(newsTitle, newsContent); // 刷新NewsContentFragment界面

        onToDonate();
        onBrowseRecord();
        onToLongTerm();
    }
    public void onToDonate( ){
       Button button1 = findViewById(R.id.button);//id后面为上方button的id

        button1.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(NewsContentActivity.this, DonateActivity.class);//this前面为当前activty名称，class前面为要跳转到得activity名称
                intent.putExtra("stu_id",stu_id);
                intent.putExtra("user_id",user_id);
                startActivity(intent);
            }
        });
    }

    public void onBrowseRecord(){
        Button button = findViewById(R.id.browse_donated_btn);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(NewsContentActivity.this, BrowseDonatedRecordActivity.class);
                intent.putExtra("stu_id",stu_id);
                startActivity(intent);
            }
        });
    }

    public void onToLongTerm( ){
        Button longterm= findViewById(R.id.longterm);
        longterm.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(NewsContentActivity.this, LongTermDonate.class);//this前面为当前activty名称，class前面为要跳转到得activity名称
                intent.putExtra("stu_id",stu_id);
                intent.putExtra("user_id",user_id);
                startActivity(intent);
            }
        });
    }
}
