mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-11-02 15:53:55 +01:00
feat:Made the feedback dialog not leave screen in case of error
This commit is contained in:
parent
d318aa7413
commit
dad6d98558
1 changed files with 43 additions and 2 deletions
|
|
@ -2,11 +2,17 @@ package fr.free.nrw.commons.feedback
|
||||||
|
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.net.ConnectivityManager
|
||||||
|
import android.net.Network
|
||||||
|
import android.net.NetworkCapabilities
|
||||||
|
import android.net.NetworkInfo
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.Html
|
import android.text.Html
|
||||||
import android.text.Spanned
|
import android.text.Spanned
|
||||||
import android.text.method.LinkMovementMethod
|
import android.text.method.LinkMovementMethod
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
|
import android.widget.Toast
|
||||||
import fr.free.nrw.commons.R
|
import fr.free.nrw.commons.R
|
||||||
import fr.free.nrw.commons.databinding.DialogFeedbackBinding
|
import fr.free.nrw.commons.databinding.DialogFeedbackBinding
|
||||||
import fr.free.nrw.commons.feedback.model.Feedback
|
import fr.free.nrw.commons.feedback.model.Feedback
|
||||||
|
|
@ -41,11 +47,46 @@ class FeedbackDialog(
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
|
window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
|
||||||
binding.btnSubmitFeedback.setOnClickListener {
|
binding.btnSubmitFeedback.setOnClickListener {
|
||||||
submitFeedback()
|
if (isInternetConnectionAvailable(context) ) {
|
||||||
|
submitFeedback()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Toast.makeText(context,R.string.error_feedback, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is to check whether internet connection is available or not
|
||||||
|
*/
|
||||||
|
fun isInternetConnectionAvailable(context: Context): Boolean {
|
||||||
|
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
val activeNetwork: Network? = connectivityManager.activeNetwork
|
||||||
|
val networkCapabilities = connectivityManager.getNetworkCapabilities(activeNetwork)
|
||||||
|
|
||||||
|
return if (networkCapabilities != null) {
|
||||||
|
val hasInternet = networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||||
|
val hasValidation = networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)
|
||||||
|
val downlinkBandwidth = networkCapabilities.linkDownstreamBandwidthKbps
|
||||||
|
val uplinkBandwidth = networkCapabilities.linkUpstreamBandwidthKbps
|
||||||
|
val isBandwidthSufficient = downlinkBandwidth >= 150 && uplinkBandwidth >= 100
|
||||||
|
|
||||||
|
hasInternet && hasValidation && isBandwidthSufficient
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
val activeNetworkInfo: NetworkInfo? = connectivityManager.activeNetworkInfo
|
||||||
|
return activeNetworkInfo != null && activeNetworkInfo.isConnected
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fun submitFeedback() {
|
fun submitFeedback() {
|
||||||
if (binding.feedbackItemEditText.getText().toString() == "") {
|
if (binding.feedbackItemEditText.getText().toString() == "") {
|
||||||
binding.feedbackItemEditText.error = context.getString(R.string.enter_description)
|
binding.feedbackItemEditText.error = context.getString(R.string.enter_description)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue