Add check for country dial code initial commit
This commit is contained in:
parent
965c9de517
commit
524cf91ee0
3 changed files with 271 additions and 5 deletions
|
@ -1,4 +1,212 @@
|
|||
<resources>
|
||||
<string-array name="DialingCountryCode" >
|
||||
<item>32,BE</item>
|
||||
<item>501,BZ</item>
|
||||
<item>229,BJ</item>
|
||||
<item>975,BT</item>
|
||||
<item>591,BO</item>
|
||||
<item>387,BA</item>
|
||||
<item>267,BW</item>
|
||||
<item>55,BR</item>
|
||||
<item>673,BN</item>
|
||||
<item>359,BG</item>
|
||||
<item>226,BF</item>
|
||||
<item>95,MM</item>
|
||||
<item>257,BI</item>
|
||||
<item>855,KH</item>
|
||||
<item>237,CM</item>
|
||||
<item>1,CA</item>
|
||||
<item>238,CV</item>
|
||||
<item>236,CF</item>
|
||||
<item>235,TD</item>
|
||||
<item>56,CL</item>
|
||||
<item>86,CN</item>
|
||||
<item>61,CX</item>
|
||||
<item>61,CC</item>
|
||||
<item>57,CO</item>
|
||||
<item>269,KM</item>
|
||||
<item>242,CG</item>
|
||||
<item>243,CD</item>
|
||||
<item>682,CK</item>
|
||||
<item>506,CR</item>
|
||||
<item>385,HR</item>
|
||||
<item>53,CU</item>
|
||||
<item>357,CY</item>
|
||||
<item>93,AF</item>
|
||||
<item>355,AL</item>
|
||||
<item>213,DZ</item>
|
||||
<item>376,AD</item>
|
||||
<item>244,AO</item>
|
||||
<item>672,AQ</item>
|
||||
<item>54,AR</item>
|
||||
<item>374,AM</item>
|
||||
<item>297,AW</item>
|
||||
<item>61,AU</item>
|
||||
<item>43,AT</item>
|
||||
<item>994,AZ</item>
|
||||
<item>973,BH</item>
|
||||
<item>880,BD</item>
|
||||
<item>375,BY</item>
|
||||
<item>420,CZ</item>
|
||||
<item>45,DK</item>
|
||||
<item>253,DJ</item>
|
||||
<item>670,TL</item>
|
||||
<item>593,EC</item>
|
||||
<item>20,EG</item>
|
||||
<item>503,SV</item>
|
||||
<item>240,GQ</item>
|
||||
<item>358,FI</item>
|
||||
<item>33,FR</item>
|
||||
<item>291,ER</item>
|
||||
<item>372,EE</item>
|
||||
<item>251,ET</item>
|
||||
<item>500,FK</item>
|
||||
<item>298,FO</item>
|
||||
<item>679,FJ</item>
|
||||
<item>689,PF</item>
|
||||
<item>241,GA</item>
|
||||
<item>220,GM</item>
|
||||
<item>995,GE</item>
|
||||
<item>49,DE</item>
|
||||
<item>233,GH</item>
|
||||
<item>350,GI</item>
|
||||
<item>30,GR</item>
|
||||
<item>299,GL</item>
|
||||
<item>502,GT</item>
|
||||
<item>224,GN</item>
|
||||
<item>245,GW</item>
|
||||
<item>592,GY</item>
|
||||
<item>509,HT</item>
|
||||
<item>504,HN</item>
|
||||
<item>852,HK</item>
|
||||
<item>36,HU</item>
|
||||
<item>91,IN</item>
|
||||
<item>62,ID</item>
|
||||
<item>98,IR</item>
|
||||
<item>964,IQ</item>
|
||||
<item>353,IE</item>
|
||||
<item>44,IM</item>
|
||||
<item>972,IL</item>
|
||||
<item>39,IT</item>
|
||||
<item>225,CI</item>
|
||||
<item>81,JP</item>
|
||||
<item>962,JO</item>
|
||||
<item>7,KZ</item>
|
||||
<item>254,KE</item>
|
||||
<item>686,KI</item>
|
||||
<item>965,KW</item>
|
||||
<item>996,KG</item>
|
||||
<item>856,LA</item>
|
||||
<item>371,LV</item>
|
||||
<item>961,LB</item>
|
||||
<item>266,LS</item>
|
||||
<item>231,LR</item>
|
||||
<item>218,LY</item>
|
||||
<item>423,LI</item>
|
||||
<item>370,LT</item>
|
||||
<item>352,LU</item>
|
||||
<item>853,MO</item>
|
||||
<item>389,MK</item>
|
||||
<item>261,MG</item>
|
||||
<item>265,MW</item>
|
||||
<item>60,MY</item>
|
||||
<item>960,MV</item>
|
||||
<item>223,ML</item>
|
||||
<item>356,MT</item>
|
||||
<item>692,MH</item>
|
||||
<item>222,MR</item>
|
||||
<item>230,MU</item>
|
||||
<item>262,YT</item>
|
||||
<item>52,MX</item>
|
||||
<item>691,FM</item>
|
||||
<item>373,MD</item>
|
||||
<item>377,MC</item>
|
||||
<item>976,MN</item>
|
||||
<item>382,ME</item>
|
||||
<item>212,MA</item>
|
||||
<item>258,MZ</item>
|
||||
<item>264,NA</item>
|
||||
<item>674,NR</item>
|
||||
<item>977,NP</item>
|
||||
<item>31,NL</item>
|
||||
<item>599,AN</item>
|
||||
<item>687,NC</item>
|
||||
<item>64,NZ</item>
|
||||
<item>505,NI</item>
|
||||
<item>227,NE</item>
|
||||
<item>234,NG</item>
|
||||
<item>683,NU</item>
|
||||
<item>850,KP</item>
|
||||
<item>47,NO</item>
|
||||
<item>968,OM</item>
|
||||
<item>92,PK</item>
|
||||
<item>680,PW</item>
|
||||
<item>507,PA</item>
|
||||
<item>675,PG</item>
|
||||
<item>595,PY</item>
|
||||
<item>51,PE</item>
|
||||
<item>63,PH</item>
|
||||
<item>870,PN</item>
|
||||
<item>48,PL</item>
|
||||
<item>351,PT</item>
|
||||
<item>1,PR</item>
|
||||
<item>974,QA</item>
|
||||
<item>40,RO</item>
|
||||
<item>7,RU</item>
|
||||
<item>250,RW</item>
|
||||
<item>590,BL</item>
|
||||
<item>685,WS</item>
|
||||
<item>378,SM</item>
|
||||
<item>239,ST</item>
|
||||
<item>966,SA</item>
|
||||
<item>221,SN</item>
|
||||
<item>381,RS</item>
|
||||
<item>248,SC</item>
|
||||
<item>232,SL</item>
|
||||
<item>65,SG</item>
|
||||
<item>421,SK</item>
|
||||
<item>386,SI</item>
|
||||
<item>677,SB</item>
|
||||
<item>252,SO</item>
|
||||
<item>27,ZA</item>
|
||||
<item>82,KR</item>
|
||||
<item>34,ES</item>
|
||||
<item>94,LK</item>
|
||||
<item>290,SH</item>
|
||||
<item>508,PM</item>
|
||||
<item>249,SD</item>
|
||||
<item>597,SR</item>
|
||||
<item>268,SZ</item>
|
||||
<item>46,SE</item>
|
||||
<item>41,CH</item>
|
||||
<item>963,SY</item>
|
||||
<item>886,TW</item>
|
||||
<item>992,TJ</item>
|
||||
<item>255,TZ</item>
|
||||
<item>66,TH</item>
|
||||
<item>228,TG</item>
|
||||
<item>690,TK</item>
|
||||
<item>676,TO</item>
|
||||
<item>216,TN</item>
|
||||
<item>90,TR</item>
|
||||
<item>993,TM</item>
|
||||
<item>688,TV</item>
|
||||
<item>971,AE</item>
|
||||
<item>256,UG</item>
|
||||
<item>44,GB</item>
|
||||
<item>380,UA</item>
|
||||
<item>598,UY</item>
|
||||
<item>1,US</item>
|
||||
<item>998,UZ</item>
|
||||
<item>678,VU</item>
|
||||
<item>39,VA</item>
|
||||
<item>58,VE</item>
|
||||
<item>84,VN</item>
|
||||
<item>681,WF</item>
|
||||
<item>967,YE</item>
|
||||
<item>260,ZM</item>
|
||||
<item>263,ZW</item>
|
||||
</string-array>
|
||||
<string name="shared_string_telegram">Telegram</string>
|
||||
<string name="privacy_policy_use_telegram">We use a Telegram (messaging app) to connect people and make it easier for you to communicate with them.</string>
|
||||
<string name="privacy_policy_telegram_client">Telegram open platform and OsmAnd Tracker is one of the customers. Your contacts can use any other Telegram client.</string>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.telegram.ui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Dialog
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
|
@ -25,8 +26,12 @@ import android.widget.ImageView
|
|||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import net.osmand.PlatformUtil
|
||||
import net.osmand.data.LatLon
|
||||
import net.osmand.telegram.R
|
||||
import net.osmand.telegram.utils.AndroidNetworkUtils
|
||||
import net.osmand.telegram.utils.AndroidUtils
|
||||
import net.osmand.telegram.utils.OsmandApiUtils
|
||||
import org.json.JSONObject
|
||||
import studio.carbonylgroup.textfieldboxes.ExtendedEditText
|
||||
|
||||
|
||||
|
@ -35,7 +40,7 @@ class LoginDialogFragment : BaseDialogFragment() {
|
|||
companion object {
|
||||
|
||||
private const val TAG = "LoginDialogFragment"
|
||||
private val LOG = PlatformUtil.getLog(LoginDialogFragment::class.java)
|
||||
private val log = PlatformUtil.getLog(LoginDialogFragment::class.java)
|
||||
|
||||
private const val LOGIN_DIALOG_TYPE_PARAM_KEY = "login_dialog_type_param"
|
||||
private const val SHOW_PROGRESS_PARAM_KEY = "show_progress_param"
|
||||
|
@ -51,6 +56,8 @@ class LoginDialogFragment : BaseDialogFragment() {
|
|||
|
||||
private var softKeyboardShown: Boolean = false
|
||||
|
||||
private var countryPhoneCode: String = ""
|
||||
|
||||
fun showWelcomeDialog(fragmentManager: FragmentManager) {
|
||||
welcomeDialogShown = true
|
||||
showDialog(fragmentManager, welcomeDialog = true)
|
||||
|
@ -85,7 +92,7 @@ class LoginDialogFragment : BaseDialogFragment() {
|
|||
fragment.updateDialog(loginDialogType, showWelcomeDialog)
|
||||
}
|
||||
} catch (e: RuntimeException) {
|
||||
LOG.error(e)
|
||||
log.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,6 +195,7 @@ class LoginDialogFragment : BaseDialogFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Suppress("DEPRECATION")
|
||||
private fun buildDialog(view: View?) {
|
||||
if (showWelcomeDialog) {
|
||||
|
@ -248,7 +256,7 @@ class LoginDialogFragment : BaseDialogFragment() {
|
|||
val editText: ExtendedEditText? = layout.findViewById(t.editorId)
|
||||
if (editText != null && !showWelcomeDialog) {
|
||||
if (loginDialogActiveType == LoginDialogType.ENTER_PHONE_NUMBER) {
|
||||
editText.setText("+")
|
||||
editText.setText("+$countryPhoneCode")
|
||||
}
|
||||
editText.setOnEditorActionListener { _, actionId, _ ->
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
|
@ -266,10 +274,10 @@ class LoginDialogFragment : BaseDialogFragment() {
|
|||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
|
||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
|
||||
override fun afterTextChanged(s: Editable) {
|
||||
changeContinueButtonEnabled(s.length > 1)
|
||||
changeContinueButtonEnabled(s.length > countryPhoneCode.length + 1)
|
||||
}
|
||||
})
|
||||
changeContinueButtonEnabled(editText.text.length > 1)
|
||||
changeContinueButtonEnabled(editText.text.length > countryPhoneCode.length + 1)
|
||||
editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16F)
|
||||
}
|
||||
|
||||
|
@ -430,6 +438,51 @@ class LoginDialogFragment : BaseDialogFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
checkCountryPhoneCode()
|
||||
}
|
||||
|
||||
private fun checkCountryPhoneCode() {
|
||||
OsmandApiUtils.getLocationByIp(app, object : AndroidNetworkUtils.OnRequestResultListener {
|
||||
override fun onResult(result: String?) {
|
||||
if (result != null) {
|
||||
try {
|
||||
val obj = JSONObject(result)
|
||||
val latitude = obj.getDouble("latitude")
|
||||
val longitude = obj.getDouble("longitude")
|
||||
val countryId = obj.getString("country_code")
|
||||
if (latitude == 0.0 && longitude == 0.0) {
|
||||
log.debug("Empty location")
|
||||
} else {
|
||||
val location = LatLon(latitude, longitude)
|
||||
log.debug("$location")
|
||||
countryPhoneCode = getCountryDialCode(countryId)
|
||||
log.debug(countryPhoneCode)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
log.debug("JSON parsing error: ", e)
|
||||
}
|
||||
} else {
|
||||
log.debug("Empty response")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun getCountryDialCode(countryId: String): String {
|
||||
var countryDialCode = ""
|
||||
val arrCountryCode = this.resources.getStringArray(R.array.DialingCountryCode)
|
||||
arrCountryCode.forEach {
|
||||
val arrDial = it.split(",")
|
||||
if (arrDial[1].trim() == (countryId)) {
|
||||
countryDialCode = arrDial[0]
|
||||
return countryDialCode
|
||||
}
|
||||
}
|
||||
return countryDialCode
|
||||
}
|
||||
|
||||
private fun applyAuthParam(t: LoginDialogType, value: String) {
|
||||
getMainActivity()?.applyAuthParam(this, t, value)
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.json.JSONObject
|
|||
const val BASE_URL = "https://live.osmand.net"
|
||||
|
||||
const val BASE_SHARING_URL = "http://osmand.net/go"
|
||||
const val GEO_IP_URL = "https://osmand.net/api/geo-ip"
|
||||
|
||||
object OsmandApiUtils {
|
||||
|
||||
|
@ -43,6 +44,10 @@ object OsmandApiUtils {
|
|||
}
|
||||
}
|
||||
|
||||
fun getLocationByIp(app: TelegramApplication, listener: AndroidNetworkUtils.OnRequestResultListener) {
|
||||
AndroidNetworkUtils.sendRequestAsync(app, GEO_IP_URL, null, "get location by IP", false, false, listener)
|
||||
}
|
||||
|
||||
fun parseDeviceBot(deviceJSON: JSONObject): TelegramSettings.DeviceBot? {
|
||||
return try {
|
||||
TelegramSettings.DeviceBot().apply {
|
||||
|
|
Loading…
Reference in a new issue