package com.snap.wall.activity;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentTransaction;
import com.snap.wall.R;
import com.snap.wall.RecentWallpaperManager;
import com.snap.wall.fragment.RecentWallpaperFragment;
import com.snap.wall.mytool.Comutils;

public class RencentActivity extends AppCompatActivity {

    private RecentWallpaperManager recentManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rencent);
        Comutils.initFull(this, false);

        recentManager = RecentWallpaperManager.getInstance(this);
        ImageView ivBack = findViewById(R.id.iv_back);
        if (ivBack != null) {
            ivBack.setOnClickListener(v -> {
                finish();
            });
        }

        // 清除按钮点击
        TextView tvClearAll = findViewById(R.id.tv_clear_all);
        tvClearAll.setOnClickListener(v -> {
            recentManager.clear();
            Toast.makeText(this, "All recent browsing history has been cleared", Toast.LENGTH_SHORT).show();
            reloadRecentFragment();
        });

        // 加载Fragment
        if (savedInstanceState == null) {
            loadRecentFragment();
        }
    }

    private void loadRecentFragment() {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.fragment_container, new RecentWallpaperFragment());
        transaction.commit();
    }

    private void reloadRecentFragment() {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.fragment_container, new RecentWallpaperFragment());
        transaction.commit();
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 仅保留super调用，删除所有Glide相关代码
    }
}