| | |
| | | package com.example.firstapp.ui.notifications |
| | | |
| | | import android.content.ClipData |
| | | import android.content.ClipboardManager |
| | | import android.content.Context |
| | | import android.content.Intent |
| | | import android.net.Uri |
| | | import android.os.Bundle |
| | | import android.view.LayoutInflater |
| | | import android.view.View |
| | | import android.view.ViewGroup |
| | | import android.widget.TextView |
| | | import android.widget.EditText |
| | | import android.widget.Toast |
| | | import androidx.fragment.app.Fragment |
| | | import androidx.lifecycle.ViewModelProvider |
| | | import androidx.navigation.fragment.findNavController |
| | | import com.google.android.material.dialog.MaterialAlertDialogBuilder |
| | | import com.example.firstapp.R |
| | | import com.example.firstapp.databinding.FragmentNotificationsBinding |
| | | |
| | | class NotificationsFragment : Fragment() { |
| | |
| | | container: ViewGroup?, |
| | | savedInstanceState: Bundle? |
| | | ): View { |
| | | val notificationsViewModel = |
| | | ViewModelProvider(this).get(NotificationsViewModel::class.java) |
| | | |
| | | _binding = FragmentNotificationsBinding.inflate(inflater, container, false) |
| | | val root: View = binding.root |
| | | |
| | | val textView: TextView = binding.textNotifications |
| | | notificationsViewModel.text.observe(viewLifecycleOwner) { |
| | | textView.text = it |
| | | setupClickListeners() |
| | | |
| | | return binding.root |
| | | } |
| | | |
| | | private fun setupClickListeners() { |
| | | // 设置提醒 |
| | | binding.settingsReminder.setOnClickListener { |
| | | // 跳转到设置提醒页面 |
| | | findNavController().navigate(R.id.action_navigation_notifications_to_reminderSettingsFragment) |
| | | } |
| | | return root |
| | | |
| | | // 关于小红书 |
| | | binding.aboutApp.setOnClickListener { |
| | | // 跳转到小红书账号页面 |
| | | val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://www.xiaohongshu.com/user/profile/64978d5c000000001001ee26")) |
| | | startActivity(intent) |
| | | } |
| | | |
| | | // 邮件联系 |
| | | binding.emailContact.setOnClickListener { |
| | | showEmailDialog() |
| | | } |
| | | |
| | | // 意见与反馈 |
| | | binding.feedback.setOnClickListener { |
| | | showFeedbackDialog() |
| | | } |
| | | |
| | | // 分享给好友 |
| | | binding.shareToFriends.setOnClickListener { |
| | | shareToWechat() |
| | | } |
| | | } |
| | | |
| | | private fun showEmailDialog() { |
| | | val email = "support@example.com" |
| | | MaterialAlertDialogBuilder(requireContext()) |
| | | .setTitle("联系邮箱") |
| | | .setMessage(email) |
| | | .setPositiveButton("复制") { _, _ -> |
| | | val clipboard = requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager |
| | | val clip = ClipData.newPlainText("email", email) |
| | | clipboard.setPrimaryClip(clip) |
| | | Toast.makeText(context, "邮箱已复制", Toast.LENGTH_SHORT).show() |
| | | } |
| | | .setNegativeButton("取消", null) |
| | | .show() |
| | | } |
| | | |
| | | private fun showFeedbackDialog() { |
| | | val dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_feedback, null) |
| | | val editText = dialogView.findViewById<EditText>(R.id.feedback_edit_text) |
| | | |
| | | MaterialAlertDialogBuilder(requireContext()) |
| | | .setTitle("意见反馈") |
| | | .setView(dialogView) |
| | | .setPositiveButton("提交") { _, _ -> |
| | | val feedback = editText.text.toString() |
| | | if (feedback.isNotEmpty()) { |
| | | // TODO: 提交反馈到服务器 |
| | | Toast.makeText(context, "感谢您的反馈", Toast.LENGTH_SHORT).show() |
| | | } |
| | | } |
| | | .setNegativeButton("取消", null) |
| | | .show() |
| | | } |
| | | |
| | | private fun shareToWechat() { |
| | | try { |
| | | val intent = Intent() |
| | | intent.setPackage("com.tencent.mm") |
| | | intent.action = Intent.ACTION_SEND |
| | | intent.type = "text/plain" |
| | | intent.putExtra(Intent.EXTRA_TEXT, "推荐一个很棒的应用给你!") |
| | | startActivity(Intent.createChooser(intent, "分享到微信")) |
| | | } catch (e: Exception) { |
| | | Toast.makeText(context, "请先安装微信", Toast.LENGTH_SHORT).show() |
| | | } |
| | | } |
| | | |
| | | override fun onDestroyView() { |