Skip to content
Snippets Groups Projects
Commit 6c5f5ad0 authored by 박신혁's avatar 박신혁
Browse files

gps auto country change

parent c608161e
Branches
No related tags found
No related merge requests found
......@@ -101,29 +101,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener , com.google.
// You can now create a LatLng Object for use with maps
// val latLng = LatLng(location.latitude, location.longitude)
}
private fun getAddress(latLng: LatLng): String {
// 1
val geocoder = Geocoder(this)
val addresses: List<Address>?
val address: Address?
var addressText = ""
try {
// 2
addresses = geocoder.getFromLocation(latLng.latitude, latLng.longitude, 1)
// 3
if (null != addresses && !addresses.isEmpty()) {
address = addresses[0]
for (i in 0 until address.maxAddressLineIndex) {
addressText += if (i == 0) address.getAddressLine(i) else "\n" + address.getAddressLine(i)
}
}
} catch (e: IOException) {
Log.e("MapsActivity", e.localizedMessage)
}
return addressText
}
@SuppressLint("MissingPermission")
private fun getLocation() {
mLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
......@@ -239,6 +217,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener , com.google.
val geocoder = Geocoder(this)
val addresses: List<Address>?
var add = ""
val items = getHolidayRadioItemsCode()
if (!checkGPSEnabled()) {
return
}
......@@ -255,6 +234,35 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener , com.google.
getLocation();
}
addresses = geocoder.getFromLocation(lat,lng,1)
toast(R.string.importing)
Thread {
var country = ""
for((num,code,file) in items){
if(code == addresses.get(0).countryCode){
country = file.toString()
break
}
}
val holidays = getString(R.string.holidays)
var eventTypeId = dbHelper.getEventTypeIdWithTitle(holidays)
deleteHolidays()
// dbHelper.deleteEventsWithType(eventTypeId)
if (eventTypeId == -1) {
val eventType = EventType(0, holidays, resources.getColor(R.color.default_holidays_color))
eventTypeId = dbHelper.insertEventType(eventType)
}
val result = IcsImporter(this).importEvents(country, eventTypeId, 0, false)
handleParseResult(result)
if (result != IcsImporter.ImportResult.IMPORT_FAIL) {
runOnUiThread {
updateViewPager()
}
}
}.start()
toast(addresses.get(0).countryCode)
......@@ -975,6 +983,70 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener , com.google.
var i = 0
for ((country, file) in this) {
items.add(RadioItem(i++, country, file))
}
}
return items
}
private fun getHolidayRadioItemsCode(): ArrayList<RadioItem> {
val items = ArrayList<RadioItem>()
LinkedHashMap<String, String>().apply {
put("GR", "greece.ics")
put("ZA", "southafrica.ics")
put("NO", "norway.ics")
put("NL", "netherlands.ics")
put("KR", "southkorea.ics")
put("DK", "denmark.ics")
put("DE", "germany.ics")
put("LV", "latvia.ics")
put("RU", "russia.ics")
put("RO", "romania.ics")
put("LT", "lithuania.ics")
put("LU", "luxembourg.ics")
put("MK", "macedonia.ics")
put("MX", "mexico.ics")
put("BO", "bolivia.ics")
put("US", "unitedstates.ics")
put("BE", "belgium.ics")
put("BR", "brazil.ics")
put("RS", "serbia.ics")
put("CH", "switzerland.ics")
put("SE", "sweden.ics")
put("ES", "spain.ics")
put("SK", "slovakia.ics")
put("SI", "slovenia.ics")
put("AR", "argentina.ics")
put("IS", "iceland.ics")
put("IE", "ireland.ics")
put("DZ", "algeria.ics")
put("EE", "estonia.ics")
put("GB", "unitedkingdom.ics")
put("AT", "austria.ics")
put("UA", "ukraine.ics")
put("IT", "italy.ics")
put("IN", "india.ics")
put("ID", "indonesia.ics")
put("JP", "japan.ics")
put("CN", "china.ics")
put("CZ", "czech.ics")
put("CA", "canada.ics")
put("HR", "croatia.ics")
put("PK", "pakistan.ics")
put("PT", "portugal.ics")
put("PL", "poland.ics")
put("FR", "france.ics")
put("FI", "finland.ics")
put("AU", "australia.ics")
put("HU", "hungary.ics")
var i = 0
for ((country, file) in this) {
items.add(RadioItem(i++, country, file))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment