mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 19:49:33 +01:00
handling error 429 in phonebook sync
Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
This commit is contained in:
parent
d2ad9775b0
commit
79af073d5a
@ -32,6 +32,7 @@ import android.net.Uri
|
|||||||
import android.os.RemoteException
|
import android.os.RemoteException
|
||||||
import android.provider.ContactsContract
|
import android.provider.ContactsContract
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.os.ConfigurationCompat
|
import androidx.core.os.ConfigurationCompat
|
||||||
import androidx.work.Data
|
import androidx.work.Data
|
||||||
@ -143,9 +144,22 @@ class ContactAddressBookWorker(val context: Context, workerParameters: WorkerPar
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onNext(foundContacts: ContactsByNumberOverall) {
|
override fun onNext(foundContacts: ContactsByNumberOverall) {
|
||||||
val contactsWithAssociatedPhoneNumbers = foundContacts.ocs!!.map
|
when (foundContacts.ocs?.meta?.statusCode) {
|
||||||
deleteLinkedAccounts(contactsWithAssociatedPhoneNumbers)
|
HTTP_CODE_TOO_MANY_REQUESTS -> {
|
||||||
createLinkedAccounts(contactsWithAssociatedPhoneNumbers)
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
context.resources.getString(
|
||||||
|
R.string.nc_settings_phone_book_integration_phone_number_dialog_429
|
||||||
|
),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
val contactsWithAssociatedPhoneNumbers = foundContacts.ocs!!.map
|
||||||
|
deleteLinkedAccounts(contactsWithAssociatedPhoneNumbers)
|
||||||
|
createLinkedAccounts(contactsWithAssociatedPhoneNumbers)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onError(e: Throwable) {
|
override fun onError(e: Throwable) {
|
||||||
@ -449,6 +463,7 @@ class ContactAddressBookWorker(val context: Context, workerParameters: WorkerPar
|
|||||||
const val REQUEST_PERMISSION = 231
|
const val REQUEST_PERMISSION = 231
|
||||||
const val KEY_FORCE = "KEY_FORCE"
|
const val KEY_FORCE = "KEY_FORCE"
|
||||||
const val DELETE_ALL = "DELETE_ALL"
|
const val DELETE_ALL = "DELETE_ALL"
|
||||||
|
private const val HTTP_CODE_TOO_MANY_REQUESTS: Int = 429
|
||||||
|
|
||||||
fun run(context: Context) {
|
fun run(context: Context) {
|
||||||
if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_CONTACTS) ==
|
if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_CONTACTS) ==
|
||||||
|
@ -1079,21 +1079,23 @@ class SettingsActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onNext(genericOverall: GenericOverall) {
|
override fun onNext(genericOverall: GenericOverall) {
|
||||||
val statusCode = genericOverall.ocs?.meta?.statusCode
|
when (val statusCode = genericOverall.ocs?.meta?.statusCode) {
|
||||||
if (statusCode == HTTP_CODE) {
|
HTTP_CODE_OK -> {
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
Snackbar.make(
|
Snackbar.make(
|
||||||
binding.root,
|
binding.root,
|
||||||
context.resources.getString(
|
context.resources.getString(
|
||||||
R.string.nc_settings_phone_book_integration_phone_number_dialog_success
|
R.string.nc_settings_phone_book_integration_phone_number_dialog_success
|
||||||
),
|
),
|
||||||
Snackbar.LENGTH_LONG
|
Snackbar.LENGTH_LONG
|
||||||
).show()
|
).show()
|
||||||
} else {
|
}
|
||||||
textInputLayout.helperText = context.resources.getString(
|
else -> {
|
||||||
R.string.nc_settings_phone_book_integration_phone_number_dialog_invalid
|
textInputLayout.helperText = context.resources.getString(
|
||||||
)
|
R.string.nc_settings_phone_book_integration_phone_number_dialog_invalid
|
||||||
Log.d(TAG, "failed to set phoneNumber. statusCode=$statusCode")
|
)
|
||||||
|
Log.d(TAG, "failed to set phoneNumber. statusCode=$statusCode")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1181,7 +1183,7 @@ class SettingsActivity : BaseActivity() {
|
|||||||
private const val START_DELAY: Long = 5000
|
private const val START_DELAY: Long = 5000
|
||||||
private const val DISABLED_ALPHA: Float = 0.38f
|
private const val DISABLED_ALPHA: Float = 0.38f
|
||||||
private const val ENABLED_ALPHA: Float = 1.0f
|
private const val ENABLED_ALPHA: Float = 1.0f
|
||||||
private const val HTTP_CODE: Int = 200
|
private const val HTTP_CODE_OK: Int = 200
|
||||||
private const val PHONE_NUMBER_SIDE_PADDING: Int = 50
|
private const val PHONE_NUMBER_SIDE_PADDING: Int = 50
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -706,5 +706,6 @@ How to translate with transifex:
|
|||||||
<string name="custom">Custom</string>
|
<string name="custom">Custom</string>
|
||||||
<string name="set">Set</string>
|
<string name="set">Set</string>
|
||||||
<string name="calendar">Calendar</string>
|
<string name="calendar">Calendar</string>
|
||||||
|
<string name="nc_settings_phone_book_integration_phone_number_dialog_429">Error 429 Too Many Requests</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user