| | |
| | | import android.widget.EditText |
| | | import android.widget.Toast |
| | | import androidx.fragment.app.Fragment |
| | | import androidx.lifecycle.lifecycleScope |
| | | import androidx.navigation.fragment.findNavController |
| | | import com.google.android.material.dialog.MaterialAlertDialogBuilder |
| | | import com.example.firstapp.R |
| | | import com.example.firstapp.activity.ContentDetailActivity |
| | | import com.example.firstapp.database.service.RetrofitClient |
| | | import com.example.firstapp.databinding.FragmentNotificationsBinding |
| | | import com.example.firstapp.ui.reminderOther.ReminderOtherAddActivity2 |
| | | import com.example.firstapp.ui.reminderOther.ReminderSettingsFragmentOther |
| | | import kotlinx.coroutines.launch |
| | | |
| | | class NotificationsFragment : Fragment() { |
| | | |
| | |
| | | // onDestroyView. |
| | | private val binding get() = _binding!! |
| | | |
| | | // 默认值 |
| | | private val DEFAULT_XIAOHONGSHU_URL = "https://www.xiaohongshu.com/user/profile/64978d5c000000001001ee26" |
| | | private val DEFAULT_EMAIL = "support@example.com" |
| | | private val DEFAULT_SHARE_TEXT = "推荐一个很棒的应用给你!\n下载地址:https://oia.xiaohongshu.com/oia" |
| | | |
| | | // 存储从接口获取的值 |
| | | private var xiaohongshuUrl = "" |
| | | private var contactEmail = "" |
| | | private var shareText = "" |
| | | |
| | | override fun onCreateView( |
| | | inflater: LayoutInflater, |
| | | container: ViewGroup?, |
| | |
| | | ): View { |
| | | _binding = FragmentNotificationsBinding.inflate(inflater, container, false) |
| | | |
| | | setupClickListeners() |
| | | // 先加载配置,再设置点击事件 |
| | | lifecycleScope.launch { |
| | | loadConfigurations() |
| | | setupClickListeners() |
| | | } |
| | | |
| | | return binding.root |
| | | } |
| | | |
| | | private suspend fun loadConfigurations() { |
| | | try { |
| | | // 获取小红书链接 |
| | | val xhsResponse = RetrofitClient.apiService.getDictValue("setting", "xiaohongshu") |
| | | if (xhsResponse.code == 200 && !xhsResponse.data?.itemValue.isNullOrEmpty()) { |
| | | xiaohongshuUrl = xhsResponse.data?.itemValue ?: DEFAULT_XIAOHONGSHU_URL |
| | | } else { |
| | | xiaohongshuUrl = DEFAULT_XIAOHONGSHU_URL |
| | | } |
| | | |
| | | // 获取邮箱 |
| | | val emailResponse = RetrofitClient.apiService.getDictValue("setting", "email") |
| | | if (emailResponse.code == 200 && !emailResponse.data?.itemValue.isNullOrEmpty()) { |
| | | contactEmail = emailResponse.data?.itemValue ?: DEFAULT_EMAIL |
| | | } else { |
| | | contactEmail = DEFAULT_EMAIL |
| | | } |
| | | |
| | | // 获取分享文本 |
| | | val shareResponse = RetrofitClient.apiService.getDictValue("setting", "share_link") |
| | | if (shareResponse.code == 200 && !shareResponse.data?.itemValue.isNullOrEmpty()) { |
| | | shareText = shareResponse.data?.itemValue ?: DEFAULT_SHARE_TEXT |
| | | } else { |
| | | shareText = DEFAULT_SHARE_TEXT |
| | | } |
| | | } catch (e: Exception) { |
| | | // 如果发生错误,使用默认值 |
| | | xiaohongshuUrl = DEFAULT_XIAOHONGSHU_URL |
| | | contactEmail = DEFAULT_EMAIL |
| | | shareText = DEFAULT_SHARE_TEXT |
| | | } |
| | | } |
| | | |
| | | private fun setupClickListeners() { |
| | |
| | | // 关于小红书 |
| | | binding.aboutApp.setOnClickListener { |
| | | // 跳转到小红书账号页面 |
| | | val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://www.xiaohongshu.com/user/profile/64978d5c000000001001ee26")) |
| | | val intent = Intent(Intent.ACTION_VIEW, Uri.parse(xiaohongshuUrl)) |
| | | startActivity(intent) |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | private fun showEmailDialog() { |
| | | val email = "support@example.com" |
| | | MaterialAlertDialogBuilder(requireContext()) |
| | | .setTitle("联系邮箱") |
| | | .setMessage(email) |
| | | .setMessage(contactEmail) |
| | | .setPositiveButton("复制") { _, _ -> |
| | | val clipboard = requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager |
| | | val clip = ClipData.newPlainText("email", email) |
| | | val clip = ClipData.newPlainText("email", contactEmail) |
| | | clipboard.setPrimaryClip(clip) |
| | | Toast.makeText(context, "邮箱已复制", Toast.LENGTH_SHORT).show() |
| | | } |
| | |
| | | // 获取应用程序的包名 |
| | | //val packageName = requireContext().packageName |
| | | |
| | | // 创建分享文本 |
| | | val shareText = "推荐一个很棒的应用给你!\n" + "下载地址:https://oia.xiaohongshu.com/oia" |
| | | |
| | | // 创建分享意图 |
| | | val intent = Intent().apply { |
| | | action = Intent.ACTION_SEND |
| | |
| | | // 指定分享到微信 |
| | | setPackage("com.tencent.mm") |
| | | } |
| | | // 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() |