mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Resolve crash when submitting feedback without internet access (#6018)
* fix: resolve crash when submitting feedback without internet access * feat:Added check for wheather internet connection was available for a network * feat:Added SnackBar for Retry and User Info * feat:Made the feedback dialog not leave screen in case of error * feat:Removed the network checking from the function * feat:Added try catch block for the Feedback * feat:Removed Unnecessary imports * feat:Used Snackbar and timber instead of log and Toast --------- Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
This commit is contained in:
parent
f51b607312
commit
b2810bcef1
2 changed files with 33 additions and 4 deletions
|
|
@ -7,6 +7,7 @@ import android.text.Html
|
|||
import android.text.Spanned
|
||||
import android.text.method.LinkMovementMethod
|
||||
import android.view.WindowManager
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.databinding.DialogFeedbackBinding
|
||||
import fr.free.nrw.commons.feedback.model.Feedback
|
||||
|
|
@ -17,6 +18,8 @@ import fr.free.nrw.commons.utils.DeviceInfoUtil.getConnectionType
|
|||
import fr.free.nrw.commons.utils.DeviceInfoUtil.getDevice
|
||||
import fr.free.nrw.commons.utils.DeviceInfoUtil.getDeviceManufacturer
|
||||
import fr.free.nrw.commons.utils.DeviceInfoUtil.getDeviceModel
|
||||
import java.net.ConnectException
|
||||
import java.net.UnknownHostException
|
||||
|
||||
class FeedbackDialog(
|
||||
context: Context,
|
||||
|
|
@ -41,9 +44,31 @@ class FeedbackDialog(
|
|||
@Suppress("DEPRECATION")
|
||||
window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
|
||||
binding.btnSubmitFeedback.setOnClickListener {
|
||||
try {
|
||||
submitFeedback()
|
||||
} catch (e: Exception) {
|
||||
when (e) {
|
||||
is UnknownHostException -> {
|
||||
Snackbar.make(findViewById(android.R.id.content),
|
||||
R.string.error_feedback,
|
||||
Snackbar.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
is ConnectException -> {
|
||||
Snackbar.make(findViewById(android.R.id.content),
|
||||
R.string.error_feedback,
|
||||
Snackbar.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
else -> {
|
||||
Snackbar.make(findViewById(android.R.id.content),
|
||||
R.string.error_feedback,
|
||||
Snackbar.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun submitFeedback() {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import fr.free.nrw.commons.settings.SettingsActivity
|
|||
import io.reactivex.Single
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Named
|
||||
|
||||
|
|
@ -182,14 +183,17 @@ class MoreBottomSheetFragment : BottomSheetDialogFragment() {
|
|||
Single.defer { single }
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { success ->
|
||||
.subscribe({ success ->
|
||||
val messageResId = if (success) {
|
||||
R.string.thanks_feedback
|
||||
} else {
|
||||
R.string.error_feedback
|
||||
}
|
||||
Toast.makeText(requireContext(), getString(messageResId), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}, { error ->
|
||||
Timber.e(error)
|
||||
Toast.makeText(requireContext(), R.string.error_feedback, Toast.LENGTH_SHORT).show()
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue