日报2025422

今日修改个人作业一阶段中每日总结博客日报地址

package com.example.dailyreport.adapter;

import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.dailyreport.R;
import com.example.dailyreport.model.Blog;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public class BlogAdapter extends RecyclerView.Adapter<BlogAdapter.ViewHolder> {
    private List<Blog> blogList;
    // 修改这里,将OnItemClickListener改为OnBlogClickListener
    private OnBlogClickListener onBlogClickListener;

    public interface OnBlogClickListener {
        void onBlogClick(Blog blog);
    }

    public BlogAdapter(List<Blog> blogList, OnBlogClickListener onBlogClickListener) {
        this.blogList = blogList != null ? blogList : new ArrayList<>();
        this.onBlogClickListener = onBlogClickListener;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_blog, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Blog blog = blogList.get(position);
        holder.tvBlogAddress.setText(blog.getBlogAddress());
        
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        holder.tvCreateDate.setText(sdf.format(blog.getCreateDate()));
        
        // 新增查看按钮点击事件
        holder.btnView.setOnClickListener(v -> {
            if (onBlogClickListener != null) {
                onBlogClickListener.onBlogClick(blog);
            }
        });
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        final TextView tvBlogAddress;
        final TextView tvCreateDate;
        final Button btnView;

        public ViewHolder(View itemView) {
            super(itemView);
            tvBlogAddress = itemView.findViewById(R.id.tvBlogAddress);
            tvCreateDate = itemView.findViewById(R.id.tvCreateDate);
            btnView = itemView.findViewById(R.id.btnView);
        }
    }

    @Override
    public int getItemCount() {
        return blogList.size();
    }

    // 添加这个方法来更新博客列表
    public void setBlogList(List<Blog> blogList) {
        this.blogList = blogList;
        notifyDataSetChanged();
    }
}
package com.example.dailyreport.model;

import java.util.Date;

public class Blog {
    private String id;
    private String blogAddress;
    private Date createDate;

    // 添加日期格式化方法
    public void setCreateDateFromString(String dateString) {
        try {
            this.createDate = new Date(dateString); // 或者使用SimpleDateFormat解析特定格式
        } catch (Exception e) {
            this.createDate = new Date(); // 解析失败使用当前时间
        }
    }

    @Override
    public String toString() {
        return "Blog{" +
                "id='" + id + '\'' +
                ", blogAddress='" + blogAddress + '\'' +
                ", createDate=" + createDate +
                '}';
    }

    // Getters and Setters
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getBlogAddress() {
        return blogAddress;
    }

    public void setBlogAddress(String blogAddress) {
        this.blogAddress = blogAddress;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }
}
package com.example.dailyreport.ui.blog;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.example.dailyreport.R;
import com.example.dailyreport.model.Blog;
import com.example.dailyreport.network.RetrofitClient;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class AddBlogActivity extends AppCompatActivity {
    private String userId;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_blog);

        userId = getIntent().getStringExtra("userId");
        if (userId == null) {
            Toast.makeText(this, "用户ID获取失败", Toast.LENGTH_SHORT).show();
            finish();
        }


        EditText etBlogAddress = findViewById(R.id.etBlogAddress);
        Button btnSubmit = findViewById(R.id.btnSubmit);

        btnSubmit.setOnClickListener(v -> {
            String blogAddress = etBlogAddress.getText().toString().trim();
            Toast.makeText(this, blogAddress, Toast.LENGTH_SHORT).show();
            if (blogAddress.isEmpty()) {
                Toast.makeText(this, "请输入博客地址", Toast.LENGTH_SHORT).show();
                return;
            }

            Blog blog = new Blog();
            blog.setId(userId);
            blog.setBlogAddress(blogAddress);
            blog.setCreateDateFromString("2023-01-01"); // 这里替换为实际获取的日期字符串
            System.out.println(blog);

            RetrofitClient.getInstance().getApiService().addBlog(blog).enqueue(new Callback<Void>() {
                @Override
                public void onResponse(Call<Void> call, Response<Void> response) {
                    if (response.isSuccessful()) {
                        Toast.makeText(AddBlogActivity.this, "添加成功", Toast.LENGTH_SHORT).show();
                        finish();
                    } else {
                        Toast.makeText(AddBlogActivity.this, "添加失败", Toast.LENGTH_SHORT).show();
                    }
                }

                @Override
                public void onFailure(Call<Void> call, Throwable t) {
                    Toast.makeText(AddBlogActivity.this, "网络错误", Toast.LENGTH_SHORT).show();
                }
            });
        });
    }

    // 实现获取当前用户ID的方法

}
package com.example.dailyreport.ui.blog;

import android.os.Bundle;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.example.dailyreport.R;

public class WebViewActivity extends AppCompatActivity {
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_webview);
        
        String url = getIntent().getStringExtra("url");
        if (url == null || url.isEmpty()) {
            Toast.makeText(this, "无效的URL", Toast.LENGTH_SHORT).show();
            finish();
            return;
        }
        
        // 确保URL格式正确
        if (!url.startsWith("http://") && !url.startsWith("https://")) {
            url = "https://" + url;
        }
        
        WebView webView = findViewById(R.id.webView);
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setDomStorageEnabled(true);
        webSettings.setLoadsImagesAutomatically(true);
        webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
        webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        
        // 允许加载任何来源的内容
        webSettings.setAllowContentAccess(true);
        webSettings.setAllowFileAccess(true);
        webSettings.setAllowFileAccessFromFileURLs(true);
        webSettings.setAllowUniversalAccessFromFileURLs(true);
        
        final String finalUrl = url;
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
                Toast.makeText(WebViewActivity.this, 
                    "加载失败,请检查网络连接或URL是否正确", Toast.LENGTH_LONG).show();
            }
            
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                return false; // 允许WebView处理URL加载
            }
            
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                // 页面加载完成
                Toast.makeText(WebViewActivity.this, "页面加载完成", Toast.LENGTH_SHORT).show();
            }
        });
        
        try {
            // 打印URL,便于调试
            System.out.println("正在加载URL: " + finalUrl);
            webView.loadUrl(finalUrl);
        } catch (Exception e) {
            Toast.makeText(this, "加载URL时出错: " + e.getMessage(), Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }
    }
    
    @Override
    public void onBackPressed() {
        WebView webView = findViewById(R.id.webView);
        if (webView.canGoBack()) {
            webView.goBack();
        } else {
            super.onBackPressed();
        }
    }
}
package com.example.dailyreport.ui.blog;

import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.dailyreport.R;
import com.example.dailyreport.adapter.BlogAdapter;
import com.example.dailyreport.model.Blog;
import com.example.dailyreport.network.ApiResponse;
import com.example.dailyreport.network.RetrofitClient;

import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ViewBlogsActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private BlogAdapter adapter;
    private String userId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_blogs);
        
        // 获取当前用户ID
        userId = getIntent().getStringExtra("userId");
        if(userId == null) {
            Toast.makeText(this, "用户ID获取失败", Toast.LENGTH_SHORT).show();
            finish();
            return;
        }

        // 在onCreate方法中添加以下代码,显示学生姓名
        String studentName = getIntent().getStringExtra("studentName");
        if (studentName != null && !studentName.isEmpty()) {
            setTitle(studentName + "的博客列表");
        }
        recyclerView = findViewById(R.id.rvBlogs);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        
        loadBlogs();
        // 在onCreate方法中添加以下代码,初始化适配器
        // 在onCreate方法中初始化适配器时添加点击监听
        adapter = new BlogAdapter(new ArrayList<>(), blog -> {
            // 处理博客点击事件
            if (blog != null && blog.getBlogAddress() != null) {
                String url = blog.getBlogAddress();
                // 添加URL格式验证
                if (!url.startsWith("http://") && !url.startsWith("https://")) {
                    url = "http://" + url;
                }
                
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(url));
                startActivity(intent);
            }
        });
        recyclerView.setAdapter(adapter);
    }

    private void loadBlogs() {
        ProgressDialog progressDialog = new ProgressDialog(this);
        progressDialog.setMessage("正在加载博客列表...");
        progressDialog.show();
        
        RetrofitClient.getInstance().getApiService()
            .selectByUserId(userId)
            .enqueue(new Callback<ApiResponse<List<Blog>>>() {
                @Override
                public void onResponse(Call<ApiResponse<List<Blog>>> call, Response<ApiResponse<List<Blog>>> response) {
                    progressDialog.dismiss();
                    try {
                        if (response.isSuccessful() && response.body() != null) {
                            ApiResponse<List<Blog>> apiResponse = response.body();
                            List<Blog> blogs = apiResponse.getData();
                            
                            if (blogs == null || blogs.isEmpty()) {
                                Toast.makeText(ViewBlogsActivity.this, "没有找到博客", Toast.LENGTH_SHORT).show();
                            } else {
                                // 使用新添加的方法更新适配器
                                adapter.setBlogList(blogs);
                            }
                        } else {
                            Toast.makeText(ViewBlogsActivity.this, "获取博客失败", Toast.LENGTH_SHORT).show();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        Toast.makeText(ViewBlogsActivity.this, "处理响应异常: " + e.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                }
                
                @Override
                public void onFailure(Call<ApiResponse<List<Blog>>> call, Throwable t) {
                    progressDialog.dismiss();
                    Toast.makeText(ViewBlogsActivity.this, 
                        "网络错误: " + t.getMessage(), Toast.LENGTH_SHORT).show();
                }
            });
    }
}
package com.example.dailyreport.ui.blog;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import com.example.dailyreport.R;

public class DailySummaryActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_daily_summary);

        Button btnAddBlog = findViewById(R.id.btnAddBlog);
        Button btnViewBlogs = findViewById(R.id.btnViewBlogs);

        btnAddBlog.setOnClickListener(v -> {
            Intent intent = new Intent(this, AddBlogActivity.class);
            intent.putExtra("userId", getIntent().getStringExtra("userId"));
            startActivity(intent);
        });

        btnViewBlogs.setOnClickListener(v -> {
            Intent intent = new Intent(this, ViewBlogsActivity.class);
            intent.putExtra("userId", getIntent().getStringExtra("userId")); // 传递当前用户ID
            startActivity(intent);
        });
    }
}
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="添加每日编程记录"
            android:textSize="20sp"
            android:textStyle="bold"
            android:gravity="center"
            android:layout_marginBottom="16dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="日期"
            android:textStyle="bold"/>

        <EditText
            android:id="@+id/etDate"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:hint="选择日期"
            android:layout_marginBottom="16dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="计划时间估计(小时)"
            android:textStyle="bold"/>

        <EditText
            android:id="@+id/etPlanningTime"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="numberDecimal"
            android:hint="例如: 2.5"
            android:layout_marginBottom="16dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="开发分析内容 *"
            android:textStyle="bold"/>

        <EditText
            android:id="@+id/etAnalysis"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textMultiLine"
            android:minLines="3"
            android:gravity="top|start"
            android:hint="请输入开发分析内容"
            android:layout_marginBottom="16dp"/>

        <CheckBox
            android:id="@+id/cbDesignDoc"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="是否生成设计文档"
            android:layout_marginBottom="16dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="采用的代码规范"
            android:textStyle="bold"/>

        <EditText
            android:id="@+id/etCodingStandard"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="请输入采用的代码规范"
            android:layout_marginBottom="16dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="设计细节"
            android:textStyle="bold"/>

        <EditText
            android:id="@+id/etDesignDetails"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textMultiLine"
            android:minLines="3"
            android:gravity="top|start"
            android:hint="请输入设计细节"
            android:layout_marginBottom="16dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="代码"
            android:textStyle="bold"/>

        <EditText
            android:id="@+id/etCode"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textMultiLine"
            android:minLines="3"
            android:gravity="top|start"
            android:hint="请输入代码"
            android:layout_marginBottom="16dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="代码变更"
            android:textStyle="bold"/>

        <EditText
            android:id="@+id/etCodeChanges"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textMultiLine"
            android:minLines="3"
            android:gravity="top|start"
            android:hint="请输入代码变更"
            android:layout_marginBottom="16dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="工作量测量"
            android:textStyle="bold"/>

        <EditText
            android:id="@+id/etWorkload"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="请输入工作量测量"
            android:layout_marginBottom="16dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="事后分析"
            android:textStyle="bold"/>

        <EditText
            android:id="@+id/etPostmortem"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textMultiLine"
            android:minLines="3"
            android:gravity="top|start"
            android:hint="请输入事后分析"
            android:layout_marginBottom="16dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="改进计划"
            android:textStyle="bold"/>

        <EditText
            android:id="@+id/etImprovement"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textMultiLine"
            android:minLines="3"
            android:gravity="top|start"
            android:hint="请输入改进计划"
            android:layout_marginBottom="16dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="总工时(小时)"
            android:textStyle="bold"/>

        <EditText
            android:id="@+id/etTotalHours"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="numberDecimal"
            android:hint="例如: 8.5"
            android:layout_marginBottom="16dp"/>

        <Button
            android:id="@+id/btnSubmit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="提交"
            android:layout_marginTop="16dp"/>

    </LinearLayout>
</ScrollView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="16dp">

    <EditText
        android:id="@+id/etBlogAddress"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="输入博客地址" />

    <Button
        android:id="@+id/btnAddBlog"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="添加博客"
        android:layout_gravity="end"
        android:layout_marginTop="8dp" />

    <RecyclerView
        android:id="@+id/rvBlogs"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="16dp" />
</LinearLayout>
posted @ 2025-04-22 21:34  花落水无痕  阅读(34)  评论(0)    收藏  举报