fix: getString always returns a value

This commit is contained in:
TwistedUmbrellaX
2024-03-20 10:01:38 -04:00
parent ef45444de1
commit d917899db0
3 changed files with 26 additions and 15 deletions

View File

@@ -999,8 +999,8 @@ class EmptyAdapter(private val count: Int) : RecyclerView.Adapter<RecyclerView.V
inner class EmptyViewHolder(view: View) : RecyclerView.ViewHolder(view)
}
fun getAppString(res: Int?): String? {
return res?.let { App.instance?.getString(it) }
fun getAppString(res: Int): String {
return App.instance?.getString(res) ?: ""
}
fun toast(string: String?) {
@@ -1053,8 +1053,8 @@ fun snackString(s: String?, activity: Activity? = null, clipboard: String? = nul
return null
}
fun snackString(r: Int?, activity: Activity? = null, clipboard: String? = null): Snackbar? {
snackString(getAppString(r), activity, clipboard)
fun snackString(r: Int, activity: Activity? = null, clipboard: String? = null): Snackbar? {
return snackString(getAppString(r), activity, clipboard)
}
open class NoPaddingArrayAdapter<T>(context: Context, layoutId: Int, items: List<T>) :

View File

@@ -137,8 +137,7 @@ class CommentItem(val comment: Comment,
viewBinding.adminBadge.visibility = if (comment.isAdmin == true) View.VISIBLE else View.GONE
viewBinding.commentDelete.setOnClickListener {
dialogBuilder(getAppString(R.string.delete_comment), getAppString(R.string.delete_comment_confirm)) {
val scope = CoroutineScope(Dispatchers.Main + SupervisorJob())
scope.launch {
CoroutineScope(Dispatchers.Main + SupervisorJob()).launch {
val success = CommentsAPI.deleteComment(comment.commentId)
if (success) {
snackString(R.string.comment_deleted)
@@ -148,23 +147,26 @@ class CommentItem(val comment: Comment,
}
}
viewBinding.commentBanUser.setOnClickListener {
dialogBuilder("Ban User", "Are you sure you want to ban this user?") {
val scope = CoroutineScope(Dispatchers.Main + SupervisorJob())
scope.launch {
dialogBuilder(getAppString(R.string.ban_user), getAppString(R.string.ban_user_confirm)) {
CoroutineScope(Dispatchers.Main + SupervisorJob()).launch {
val success = CommentsAPI.banUser(comment.userId)
if (success) {
snackString("User Banned")
snackString(R.string.user_banned)
}
}
}
}
viewBinding.commentReport.setOnClickListener {
dialogBuilder("Report Comment", "Only report comments that violate the rules. Are you sure you want to report this comment?") {
val scope = CoroutineScope(Dispatchers.Main + SupervisorJob())
scope.launch {
val success = CommentsAPI.reportComment(comment.commentId, comment.username, commentsFragment.mediaName, comment.userId)
dialogBuilder(getAppString(R.string.report_comment), getAppString(R.string.report_comment_confirm)) {
CoroutineScope(Dispatchers.Main + SupervisorJob()).launch {
val success = CommentsAPI.reportComment(
comment.commentId,
comment.username,
commentsFragment.mediaName,
comment.userId
)
if (success) {
snackString("Comment Reported")
snackString(R.string.comment_reported)
}
}
}
@@ -280,6 +282,7 @@ class CommentItem(val comment: Comment,
}
}
@SuppressLint("SimpleDateFormat")
private fun formatTimestamp(timestamp: String): String {
return try {
val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")

View File

@@ -721,4 +721,12 @@ Non quae tempore quo provident laudantium qui illo dolor vel quia dolor et exerc
<string name="delete_comment">Delete Comment</string>
<string name="delete_comment_confirm">Are you sure you want to delete this comment?</string>
<string name="comment_deleted">Comment Deleted</string>
<string name="ban_user">Ban User</string>
<string name="ban_user_confirm">Are you sure you want to ban this user?</string>
<string name="user_banned">User Banned</string>
<string name="report_comment">Report Comment</string>
<string name="report_comment_confirm">Only report comments that violate the rules. Are you sure you want to report this comment?</string>
<string name="comment_reported">Comment Reported</string>
</resources>