fix: resolve crash when submitting feedback without internet access

This commit is contained in:
angrezichatterbox 2024-12-09 22:26:36 +05:30
parent 64fd10d00e
commit 5c91f6db9d

View file

@ -5,6 +5,7 @@ import android.annotation.SuppressLint
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.net.ConnectivityManager
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
@ -170,6 +171,11 @@ class MoreBottomSheetFragment : BottomSheetDialogFragment() {
fun uploadFeedback(feedback: Feedback) {
val feedbackContentCreator = FeedbackContentCreator(requireContext(), feedback)
if (!isNetworkAvailable(requireContext())) {
Toast.makeText(requireContext(), R.string.error_feedback, Toast.LENGTH_LONG).show()
return
}
val single = pageEditClient.createNewSection(
"Commons:Mobile_app/Feedback",
feedbackContentCreator.getSectionTitle(),
@ -192,6 +198,15 @@ class MoreBottomSheetFragment : BottomSheetDialogFragment() {
}
}
/**
* This method is to check whether internet connection is available or not
*/
fun isNetworkAvailable(context: Context): Boolean {
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork = connectivityManager.activeNetworkInfo
return activeNetwork != null && activeNetwork.isConnected
}
/**
* This method shows the alert dialog when a user wants to send feedback about the app.
*/