| | |
| | | import androidx.core.content.ContextCompat |
| | | import androidx.fragment.app.Fragment |
| | | import androidx.lifecycle.ViewModelProvider |
| | | import androidx.lifecycle.lifecycleScope |
| | | import androidx.recyclerview.widget.LinearLayoutManager |
| | | import com.bumptech.glide.Glide |
| | | import com.example.firstapp.R |
| | |
| | | import com.example.firstapp.adapter.ExpressAdapter |
| | | import com.example.firstapp.adapter.FinanceAdapter |
| | | import com.example.firstapp.adapter.CategorySelectorAdapter |
| | | import com.example.firstapp.database.service.RetrofitClient |
| | | import com.example.firstapp.databinding.FragmentHomeBinding |
| | | import com.example.firstapp.databinding.DialogCategorySelectorBinding |
| | | import com.example.firstapp.utils.PreferencesManager |
| | | import com.google.android.material.bottomsheet.BottomSheetDialog |
| | | import kotlinx.coroutines.launch |
| | | |
| | | class HomeFragment : Fragment() { |
| | | |
| | |
| | | .into(binding.bottomAdBanner) |
| | | } |
| | | |
| | | // 设置分类选择器 检查会员状态 |
| | | private fun setupCategorySelector() { |
| | | binding.categoryButton.setOnClickListener { |
| | | // TODO: 检查会员状态 |
| | | if (true) { // 临时设置为true,实际应该检查会员状态 |
| | | // 从本地获取保存的手机号 |
| | | val savedPhone = PreferencesManager.getPhone() |
| | | if (savedPhone.isNullOrEmpty()) { |
| | | Toast.makeText(requireContext(), "请先登录", Toast.LENGTH_SHORT).show() |
| | | return@setOnClickListener |
| | | } |
| | | |
| | | // 使用协程检查会员状态 |
| | | lifecycleScope.launch { |
| | | try { |
| | | val response = RetrofitClient.apiService.getUserInfo(savedPhone) |
| | | if (response.code == "0" && response.data != null) { |
| | | if (response.data.isMember) { |
| | | showCategorySelectorDialog() |
| | | } else { |
| | | // 显示会员提示 |
| | | Toast.makeText(requireContext(), "该功能仅对会员开放", Toast.LENGTH_SHORT).show() |
| | | } |
| | | } else { |
| | | Toast.makeText(requireContext(), "获取用户信息失败", Toast.LENGTH_SHORT).show() |
| | | } |
| | | } catch (e: Exception) { |
| | | e.printStackTrace() |
| | | Toast.makeText(requireContext(), "网络错误,请稍后重试", Toast.LENGTH_SHORT).show() |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |