diff --git a/app/build.gradle b/app/build.gradle index 1c46b85..7387cd8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -35,6 +35,7 @@ android { } } + dependencies { implementation 'androidx.core:core-ktx:1.9.0' @@ -44,7 +45,10 @@ dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3' implementation 'androidx.navigation:navigation-ui-ktx:2.5.3' + implementation 'androidx.core:core-ktx:1.9.0' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' diff --git a/app/src/main/java/net/helcel/beendroid/Country.kt b/app/src/main/java/net/helcel/beendroid/Country.kt deleted file mode 100644 index b00d322..0000000 --- a/app/src/main/java/net/helcel/beendroid/Country.kt +++ /dev/null @@ -1,22 +0,0 @@ -package net.helcel.beendroid - -enum class Country { - ANT, - - AFG,XAD,ALA,ALB,DZA,ASM,AND,AGO,AIA,ATG,ARG,ARM,ABW,AUS,AUT,AZE, - BHS,BHR,BGD,BRB,BLR,BEL,BLZ,BEN,BMU,BTN,BOL,BES,BIH,BWA,BVT,BRA, IOT,VGB,BRN,BGR,BFA,BDI,KHM, - CMR,CAN,CPV,XCA,CYM,CAF,TCD,CHL,CHN,CXR,XCL,CCK,COL,COM,COK,CRI,CIV,HRV,CUB,CUW,CYP,CZE,COD, - DNK,DJI,DMA,DOM,ECU,EGY,SLV,GNQ,ERI,EST,ETH,FLK,FRO,FJI,FIN,FRA,GUF,PYF,ATF, - GAB,GMB,GEO,DEU,GHA,GIB,GRC,GRL,GRD,GLP,GUM,GTM,GGY,GIN,GNB,GUY,HTI,HMD,HND,HKG,HUN, - ISL,IND,IDN,IRN,IRQ,IRL,IMN,ISR,ITA,JAM,JPN,JEY,JOR,KAZ,KEN,KIR,XKO,KWT,KGZ, - LAO,LVA,LBN,LSO,LBR,LBY,LIE,LTU,LUX, - MAC,MKD,MDG,MWI,MYS,MDV,MLI,MLT,MHL,MTQ,MRT,MUS,MYT,MEX,FSM,MDA,MCO,MNG,MNE,MSR,MAR,MOZ,MMR, - NAM,NRU,NPL,NLD,NCL,NZL,NIC,NER,NGA,NIU,NFK,PRK,XNC,MNP,NOR,OMN, - PAK,PLW,PSE,PAN,PNG,PRY,PER,PHL,PCN,POL,PRT,PRI,QAT,COG,REU,ROU,RUS,RWA,BLM,MAF, - SHN,KNA,LCA,SPM,VCT,WSM,SMR,STP,SAU,SEN,SRB,SYC,SLE,SGP,SVK,SVN,SLB,SOM,ZAF,SGS,KOR,SSD,ESP, - LKA,SDN,SUR,SJM,SWZ,SWE,CHE,SYR,TWN,TJK,TZA,THA,TLS,TGO,TKL,TON,TTO,TUN,TUR,TKM,TCA,TUV,UGA, - UKR,ARE,GBR,USA,UMI,URY,UZB,VUT,VAT,VEN,VNM,VIR,WLF,ESH,YEM,ZMB,ZWE; - - val code = this.name; -} - diff --git a/app/src/main/java/net/helcel/beendroid/FoldingListAdapter.kt b/app/src/main/java/net/helcel/beendroid/FoldingListAdapter.kt new file mode 100644 index 0000000..fbb3bc5 --- /dev/null +++ b/app/src/main/java/net/helcel/beendroid/FoldingListAdapter.kt @@ -0,0 +1,78 @@ +package net.helcel.beendroid + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.CheckBox +import android.widget.TextView +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import net.helcel.beendroid.countries.GeoLoc +import net.helcel.beendroid.countries.LocType +import java.util.* + + +class FoldingListAdapter(private val ctx: Context, l: List) : + RecyclerView.Adapter() { + + private var cg : MutableMap = l.sortedBy { it.fullName }.fold(LinkedHashMap()) { acc, e -> + acc[e] = false + acc + } + + override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): FoldingListViewHolder { + val view: View = LayoutInflater + .from(viewGroup.context) + .inflate(R.layout.item_list, viewGroup, false) + return FoldingListViewHolder(ctx, view) + } + + override fun onBindViewHolder(holder: FoldingListViewHolder, position: Int) { + val el = cg.toList()[position] + holder.bind(el) + holder.itemView.setOnClickListener { + holder.checkBox.toggle() + } + holder.itemView.setOnLongClickListener { + if (el.second) { + cg[el.first] = false + }else { + cg.forEach { + cg[it.key] = it.key == el.first + } + + } + notifyItemChanged(position) + true + } + } + + override fun getItemCount(): Int { + return cg.size + } + + class FoldingListViewHolder(private val ctx: Context, itemView: View) : RecyclerView.ViewHolder(itemView) { + private val textView: TextView + val checkBox: CheckBox + private val subItemView: View + + init { + textView = itemView.findViewById(R.id.textView) + checkBox = itemView.findViewById(R.id.checkBox) + subItemView = itemView.findViewById(R.id.sub_item) + } + + fun bind(el: Pair) { + subItemView.visibility = if (el.second) View.VISIBLE else View.GONE + textView.text = el.first.fullName + if(el.first.type == LocType.STATE || el.first.children.isEmpty()) + return + + val list: RecyclerView = itemView.findViewById(R.id.list_list) + list.layoutManager = LinearLayoutManager(ctx, RecyclerView.VERTICAL, false) + list.adapter = FoldingListAdapter(ctx, el.first.children) + } + + } +} diff --git a/app/src/main/java/net/helcel/beendroid/ListAdapter.kt b/app/src/main/java/net/helcel/beendroid/ListAdapter.kt deleted file mode 100644 index 9efdd1d..0000000 --- a/app/src/main/java/net/helcel/beendroid/ListAdapter.kt +++ /dev/null @@ -1,36 +0,0 @@ -package net.helcel.beendroid - -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.CheckBox -import android.widget.TextView -import androidx.recyclerview.widget.RecyclerView - -class ListAdapter(private val dataSet: List) : - RecyclerView.Adapter() { - - class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { - val textView: TextView - val checkBox: CheckBox - - init { - textView = view.findViewById(R.id.textView) - checkBox = view.findViewById(R.id.checkBox) - } - } - - override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder { - val view = LayoutInflater.from(viewGroup.context) - .inflate(R.layout.item_list, viewGroup, false) - - return ViewHolder(view) - } - - override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) { - viewHolder.textView.text = dataSet[position] - } - - override fun getItemCount() = dataSet.size - -} diff --git a/app/src/main/java/net/helcel/beendroid/MainActivity.kt b/app/src/main/java/net/helcel/beendroid/MainActivity.kt index caeb86b..7381771 100644 --- a/app/src/main/java/net/helcel/beendroid/MainActivity.kt +++ b/app/src/main/java/net/helcel/beendroid/MainActivity.kt @@ -3,16 +3,13 @@ package net.helcel.beendroid import android.graphics.Bitmap import android.graphics.Canvas import android.os.Bundle -import android.view.View -import androidx.annotation.Nullable import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView import com.caverock.androidsvg.SVG import com.caverock.androidsvg.SVGImageView -import net.helcel.beendroid.R -import java.nio.charset.StandardCharsets +import net.helcel.beendroid.countries.Country +import net.helcel.beendroid.countries.WORLD class MainActivity : AppCompatActivity() { @@ -26,13 +23,13 @@ class MainActivity : AppCompatActivity() { setContentView(R.layout.activity_main) map = findViewById(R.id.map) - val cm = HashMap() + val cm = HashMap() Country.values().forEach { c-> - cm[c] = SVGWrapper(applicationContext,c,Level.ZERO).load() + cm[c] = PSVGWrapper(applicationContext,c,Level.ZERO).load() } val fm = cm.values.fold("") { acc, e -> acc + e.data } - val svg = SVG.getFromString(""+fm+"") + val svg = SVG.getFromString("$fm") val bitmap = Bitmap.createBitmap(1200,1200, Bitmap.Config.ARGB_8888) val canvas = Canvas(bitmap) @@ -42,7 +39,7 @@ class MainActivity : AppCompatActivity() { map.setImageBitmap(bitmap) list = findViewById(R.id.list) - list.layoutManager = LinearLayoutManager(applicationContext, RecyclerView.VERTICAL, false) - list.adapter = ListAdapter(Country.values().map{ it.code }) + list.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false) + list.adapter = FoldingListAdapter(this, WORLD) } } \ No newline at end of file diff --git a/app/src/main/java/net/helcel/beendroid/PSVGWrapper.kt b/app/src/main/java/net/helcel/beendroid/PSVGWrapper.kt new file mode 100644 index 0000000..47d8152 --- /dev/null +++ b/app/src/main/java/net/helcel/beendroid/PSVGWrapper.kt @@ -0,0 +1,28 @@ +package net.helcel.beendroid + +import android.content.Context +import net.helcel.beendroid.countries.Country +import java.nio.charset.StandardCharsets + + +class PSVGWrapper(private val c: Context, private val country: Country, private var level: Level) { + var data = "" + + fun load(): PSVGWrapper { + data = try { + String( + c.assets.open("${country.code}_${level.id}.psvg").readBytes(), + StandardCharsets.UTF_8 + ) + }catch(e: Exception){ + "" + } + return this + } + + fun changeLevel(level: Level): PSVGWrapper { + this.level = level + this.load() + return this + } +} \ No newline at end of file diff --git a/app/src/main/java/net/helcel/beendroid/SVGWrapper.kt b/app/src/main/java/net/helcel/beendroid/SVGWrapper.kt deleted file mode 100644 index 0e928ba..0000000 --- a/app/src/main/java/net/helcel/beendroid/SVGWrapper.kt +++ /dev/null @@ -1,27 +0,0 @@ -package net.helcel.beendroid - -import android.content.Context -import java.nio.charset.StandardCharsets - - -class SVGWrapper(private val c: Context, private val country: Country, private var level: Level) { - var data = "" - - fun load(): SVGWrapper { - data = try { - String( - c.assets.open(country.code + "_" + level.id + ".psvg").readBytes(), - StandardCharsets.UTF_8 - ) - }catch(e: Exception){ - "" - } - return this; - } - - fun changeLevel(level: Level): SVGWrapper { - this.level = level - this.load() - return this; - } -} \ No newline at end of file diff --git a/app/src/main/java/net/helcel/beendroid/countries/Country.kt b/app/src/main/java/net/helcel/beendroid/countries/Country.kt new file mode 100644 index 0000000..a6a4cdc --- /dev/null +++ b/app/src/main/java/net/helcel/beendroid/countries/Country.kt @@ -0,0 +1,265 @@ +package net.helcel.beendroid.countries + + +enum class Country(override val fullName: String, override val area : Int) : GeoLoc { + AFG("Afghanistan", 652864), + ALA("Åland Islands", 1580), + ALB("Albania", 28748), + DZA("Algeria", 2381741), + ASM("American Samoa", 199000), + AND("Andorra", 468765), + AGO("Angola", 1246700), + AIA("Anguilla", 96), + ATA("Antarctica", 14000000), + ATG("Antigua and Barbuda", 442), + ARG("Argentina", 2780400), + ARM("Armenia", 29743), + ABW("Aruba", 180), + AUS("Australia", 7692024), + AUT("Austria", 83879), + AZE("Azerbaijan", 86600), + BHS("Bahamas", 13878), + BHR("Bahrain", 778), + BGD("Bangladesh", 143998), + BRB("Barbados", 430), + BLR("Belarus", 207595), + BEL("Belgium", 30528), + BLZ("Belize", 22965), + BEN("Benin", 114763), + BMU("Bermuda", 54), + BTN("Bhutan", 38394), + BOL("Bolivia (Plurinational State of)", 1098581), + BES("Bonaire, Sint Eustatius and Saba", 294), + BIH("Bosnia and Herzegovina", 51209), + BWA("Botswana", 581730), + BVT("Bouvet Island", 49), + BRA("Brazil", 8515767), + IOT("British Indian Ocean Territory", 60), + BRN("Brunei Darussalam", 5765), + BGR("Bulgaria", 110994), + BFA("Burkina Faso", 274200), + BDI("Burundi", 27834), + CPV("Cabo Verde", 4033), + KHM("Cambodia", 181035), + CMR("Cameroon", 475442), + CAN("Canada", 9984670), + CYM("Cayman Islands", 264), + CAF("Central African Republic", 622436), + TCD("Chad", 1284000), + CHL("Chile", 756102), + CHN("China", 9596961), + CXR("Christmas Island", 135), + CCK("Cocos (Keeling) Islands", 14), + COL("Colombia", 1141748), + COM("Comoros", 2235), + COG("Congo", 342000), + COD("Congo, Democratic Republic of the", 2344858), + COK("Cook Islands", 237), + CRI("Costa Rica", 51100), + CIV("Côte d'Ivoire", 322463), + HRV("Croatia", 56594), + CUB("Cuba", 109884), + CUW("Curaçao", 444), + CYP("Cyprus", 9251), + CZE("Czech Republic", 78865), + DNK("Denmark", 42933), + DJI("Djibouti", 23200), + DMA("Dominica", 750), + ECU("Ecuador", 276841), + EGY("Egypt", 1002450), + SLV("El Salvador", 21041), + GNQ("Equatorial Guinea", 28051), + ERI("Eritrea", 117600), + EST("Estonia", 45227), + SWZ("Eswatini", 17364), + ETH("Ethiopia", 1104300), + FLK("Falkland Islands (Malvinas)", 12173), + FRO("Faroe Islands", 1399), + FJI("Fiji", 18333), + FIN("Finland", 338424), + FRA("France", 643801), + GUF("French Guiana", 83534), + PYF("French Polynesia", 4167), + ATF("French Southern Territories", 7747), + GAB("Gabon", 267667), + GMB("Gambia", 11295), + GEO("Georgia", 69700), + DEU("Germany", 357408), + GHA("Ghana", 238533), + GIB("Gibraltar", 6), + GRC("Greece", 131957), + GRL("Greenland", 2166086), + GRD("Grenada", 344), + GLP("Guadeloupe", 1628), + GUM("Guam", 541), + GTM("Guatemala", 108889), + GGY("Guernsey", 78), + GIN("Guinea", 245857), + GNB("Guinea-Bissau", 36125), + GUY("Guyana", 214969), + HTI("Haiti", 27750), + HMD("Heard Island and McDonald Islands", 412), + VAT("Holy See (Vatican)", 1), + HND("Honduras", 112492), + HKG("Hong Kong", 1104), + HUN("Hungary", 93028), + ISL("Iceland", 102775), + IND("India", 3287263), + IDN("Indonesia", 1904569), + IRN("Iran (Islamic Republic of)", 1648195), + IRQ("Iraq", 438317), + IRL("Ireland", 70273), + IMN("Isle of Man", 572), + ISR("Israel", 22072), + ITA("Italy", 301340), + JAM("Jamaica", 10991), + JPN("Japan", 377915), + JEY("Jersey", 118), + JOR("Jordan", 89342), + KAZ("Kazakhstan", 2724900), + KEN("Kenya", 580367), + KIR("Kiribati", 811), + PRK("Korea (Democratic People's Republic of)", 120538), + KOR("Korea, Republic of", 100210), + XKO("Kosovo", 10887), + KWT("Kuwait", 17818), + KGZ("Kyrgyzstan", 199900), + LAO("Lao People's Democratic Republic", 236800), + LVA("Latvia", 64559), + LBN("Lebanon", 10452), + LSO("Lesotho", 30355), + LBR("Liberia", 111369), + LBY("Libya", 1759540), + LIE("Liechtenstein", 160), + LTU("Lithuania", 65300), + LUX("Luxembourg", 2586), + MAC("Macao", 32), + MDG("Madagascar", 587041), + MWI("Malawi", 118484), + MYS("Malaysia", 330803), + MDV("Maldives", 300), + MLI("Mali", 1240192), + MLT("Malta", 316), + MHL("Marshall Islands", 181), + MTQ("Martinique", 1128), + MRT("Mauritania", 1030700), + MUS("Mauritius", 2040), + MYT("Mayotte", 374), + MEX("Mexico", 1964375), + FSM("Micronesia (Federated States of)", 702), + MDA("Moldova, Republic of", 33846), + MCO("Monaco", 2), + MNG("Mongolia", 1564116), + MNE("Montenegro", 13812), + MSR("Montserrat", 102), + MAR("Morocco", 446550), + MOZ("Mozambique", 799380), + MMR("Myanmar", 676578), + NAM("Namibia", 824292), + NRU("Nauru", 21), + NPL("Nepal", 147181), + NLD("Netherlands", 41526), + NCL("New Caledonia", 18575), + NZL("New Zealand", 270467), + NIC("Nicaragua", 130373), + NER("Niger", 1267000), + NGA("Nigeria", 923768), + NIU("Niue", 261), + NFK("Norfolk Island", 35), + MNP("Northern Mariana Islands", 457), + NOR("Norway", 385207), + OMN("Oman", 309500), + PAK("Pakistan", 881913), + PLW("Palau", 459), + PSE("Palestine, State of", 6220), + PAN("Panama", 75417), + PNG("Papua New Guinea", 462840), + PRY("Paraguay", 406752), + PER("Peru", 1285216), + PHL("Philippines", 300000), + PCN("Pitcairn", 47), + POL("Poland", 312696), + PRT("Portugal", 92090), + PRI("Puerto Rico", 9104), + QAT("Qatar", 11586), + MKD("Republic of North Macedonia", 25713), + ROU("Romania", 238391), + RUS("Russian Federation", 17125242), + RWA("Rwanda", 26338), + REU("Réunion", 2511), + BLM("Saint Barthélemy", 21), + SHN("Saint Helena, Ascension and Tristan da Cunha", 394), + KNA("Saint Kitts and Nevis", 270), + LCA("Saint Lucia", 617), + MAF("Saint Martin (French part)", 53), + SPM("Saint Pierre and Miquelon", 242), + VCT("Saint Vincent and the Grenadines", 389), + WSM("Samoa", 2831), + SMR("San Marino", 61), + STP("Sao Tome and Principe", 1001), + SAU("Saudi Arabia", 2149690), + SEN("Senegal", 196722), + SRB("Serbia", 88361), + SYC("Seychelles", 459), + SLE("Sierra Leone", 71740), + SGP("Singapore", 725), + SXM("Sint Maarten (Dutch part)", 34), + SVK("Slovakia", 49036), + SVN("Slovenia", 20273), + SLB("Solomon Islands", 28896), + SOM("Somalia", 637657), + ZAF("South Africa", 1221037), + SGS("South Georgia and the South Sandwich Islands", 3903), + SSD("South Sudan", 619745), + ESP("Spain", 505990), + LKA("Sri Lanka", 65610), + SDN("Sudan", 1839542), + SUR("Suriname", 163820), + SJM("Svalbard and Jan Mayen", 61399), + SWE("Sweden", 450295), + CHE("Switzerland", 41284), + SYR("Syrian Arab Republic", 185180), + TWN("Taiwan, Province of China", 36193), + TJK("Tajikistan", 143100), + TZA("Tanzania, United Republic of", 947300), + THA("Thailand", 513120), + TLS("Timor-Leste", 14919), + TGO("Togo", 56785), + TKL("Tokelau", 12), + TON("Tonga", 747), + TTO("Trinidad and Tobago", 5128), + TUN("Tunisia", 163610), + TUR("Turkey", 783562), + TKM("Turkmenistan", 488100), + TCA("Turks and Caicos Islands", 948), + TUV("Tuvalu", 26), + UGA("Uganda", 241551), + UKR("Ukraine", 603700), + ARE("United Arab Emirates", 83600), + GBR("United Kingdom of Great Britain and Northern Ireland", 242910), + USA("United States of America", 9833517), + UMI("United States Minor Outlying Islands", 34), + URY("Uruguay", 176215), + UZB("Uzbekistan", 447400), + VUT("Vanuatu", 12189), + VEN("Venezuela (Bolivarian Republic of)", 912050), + VNM("Viet Nam", 331212), + VGB("Virgin Islands (British", 153), + VIR("Virgin Islands (U.S.)", 347), + WLF("Wallis and Futuna", 142), + ESH("Western Sahara", 266000), + YEM("Yemen", 527968), + ZMB("Zambia", 752612), + ZWE("Zimbabwe", 390757), + DOM("Dominican Republic", 48671), + ANT("Netherlands Antilles", 800), + XAD("Akrotiri and Dhekelia", 254), + XCL("Clipperton Island", 6), + ZNC("Nothern Cyprus", 3355), + ; + + override val code = this.name + override val type = LocType.COUNTRY + override val children = emptyList() +} + diff --git a/app/src/main/java/net/helcel/beendroid/countries/GeoLoc.kt b/app/src/main/java/net/helcel/beendroid/countries/GeoLoc.kt new file mode 100644 index 0000000..30931b7 --- /dev/null +++ b/app/src/main/java/net/helcel/beendroid/countries/GeoLoc.kt @@ -0,0 +1,14 @@ +package net.helcel.beendroid.countries + +enum class LocType { + WORLD, GROUP, CUSTOM_GROUP, COUNTRY, STATE; +} + +interface GeoLoc { + val code : String + val fullName : String + val area : Int + + val type : LocType + val children : List +} \ No newline at end of file diff --git a/app/src/main/java/net/helcel/beendroid/countries/Group.kt b/app/src/main/java/net/helcel/beendroid/countries/Group.kt new file mode 100644 index 0000000..735261b --- /dev/null +++ b/app/src/main/java/net/helcel/beendroid/countries/Group.kt @@ -0,0 +1,91 @@ +package net.helcel.beendroid.countries + +import net.helcel.beendroid.countries.Country.* + +val WORLD = listOf( + CountryGroup.EEE, + CountryGroup.ABB, + CountryGroup.FFF, + CountryGroup.NNN, + CountryGroup.SRR, + CountryGroup.UUU, + CountryGroup.XXX +) + +enum class CountryGroup(override val fullName: String, override val children: List) : GeoLoc { + + EEE("Europe",listOf( + ALB, AND, AUT, BLR, BEL, BIH, BGR, HRV, CYP, CZE, DNK, EST, FIN, FRA, + DEU, GRC, HUN, ISL, IRL, ITA, KAZ, XKO, LVA, LIE, LTU, LUX, MLT, MDA, + MCO, MNE, NLD, MKD, NOR, POL, PRT, ROU, RUS, SMR, SRB, SVK, SVN, ESP, + SWE, CHE, UKR, GBR, VAT, XAD, + )), + ABB("Asia", listOf( + AFG, ARM, AZE, BHR, BGD, BTN, BRN, KHM, CHN, GEO, HKG, IND, IDN, IRN, + IRQ, ISR, JPN, JOR, KWT, KGZ, LAO, LBN, MAC, MYS, MDV, MNG, MMR, + NPL, PRK, OMN, PAK, PSE, PHL, QAT, SAU, SGP, KOR, LKA, SYR, TWN, TJK, + THA, TLS, TUR, TKM, ARE, UZB, VNM, YEM, ZNC, + )), + FFF("Africa", listOf( + DZA, AGO, BDI, BEN, BWA, BFA, BDI, CPV, CMR, CAF, TCD, COM, COG, COD, CIV, DJI, EGY, + GNQ, ERI, SWZ, ETH, GAB, GMB, GHA, GIN, GNB, KEN, LSO, LBR, LBY, MDG, MWI, MLI, MRT, + MUS, MYT, MAR, MOZ, NAM, NER, NGA, COD, REU, RWA, STP, SEN, SYC, SLE, SOM, ZAF, SSD, + SHN, SDN, TZA, TGO, TUN, UGA, COD, ZMB, ZWE, + )), + NNN("North America", listOf( + ABW, AIA, ATG, BHS, BRB, BLZ, BMU, VGB, CAN, CYM, CRI, CUB, CUW, DMA, + DOM, SLV, GRL, GRD, GLP, GTM, HTI, HND, JAM, MTQ, MEX, MSR, ANT, CUW, + NIC, PAN, PRI, KNA, LCA, MAF, SPM, VCT, TTO, TCA, USA, XCL, + )), + SRR("South America", listOf( + ARG, BOL, BRA, CHL, COL, ECU, FLK, GUF, GUY, PRY, PER, SUR, URY, VEN, + )), + UUU("Oceania", listOf( + ASM, AUS, COK, FJI, PYF, GUM, KIR, MHL, FSM, NRU, NCL, NZL, NIU, NFK, + MNP, PLW, PNG, PCN, SLB, TKL, TON, TUV, VUT, WLF, + )), + + XXX("Others", listOf( + ATA, // Antarctica: not in any other region + ALA, // Åland Islands: an autonomous region of Finland, but not a member of the EU or UN + BES, // Bonaire, Sint Eustatius and Saba: special municipalities of the Netherlands in the Caribbean + BVT, // Bouvet Island: an uninhabited territory of Norway in the South Atlantic + IOT, // British Indian Ocean Territory: a British overseas territory in the Indian Ocean + CXR, // Christmas Island: an Australian external territory in the Indian Ocean + CCK, // Cocos (Keeling) Islands: an Australian external territory in the Indian Ocean + FRO, // Faroe Islands: an autonomous region of Denmark + ATF, // French Southern and Antarctic Lands: a territory of France located in the southern Indian Ocean + GIB, // Gibraltar: a British overseas territory located at the southern tip of the Iberian Peninsula + GGY, // Guernsey: a British Crown dependency in the English Channel + HMD, // Heard Island and McDonald Islands: an uninhabited Australian external territory in the southern Indian Ocean + IMN, // Isle of Man: a British Crown dependency located in the Irish Sea + JEY, // Jersey: a British Crown dependency located in the English Channel + BLM, // Saint Barthélemy: an overseas collectivity of France in the Caribbean + WSM, // Samoa: an independent island nation in the South Pacific + SXM, // Sint Maarten: a constituent country of the Kingdom of the Netherlands in the Caribbean + SGS, // South Georgia and the South Sandwich Islands: a British overseas territory in the southern Atlantic Ocean + SJM, // Svalbard and Jan Mayen: an archipelago administered by Norway + UMI, // United States Minor Outlying Islands: a collection of nine insular areas of the United States + VIR, // United States Virgin Islands: an unincorporated territory of the United States in the Caribbean + ESH // Western Sahara: a disputed territory claimed by both Morocco and the Sahrawi Arab Democratic Republic + )), + + ZZZ("Undefined", listOf( + )), + + + NTT("NATO", listOf( + ALB, BEL, BGR, CAN, HRV, CZE, DNK, EST, FRA, DEU, GRC, HUN, ISL, ITA, LVA, LTU, LUX, + MNE, NLD, NOR, POL, PRT, ROU, SVK, SVN, ESP, TUR, GBR, USA + )) + ; + + override val area = children.fold(0) { acc, i -> + acc + i.area + } + + private val isInWorld = listOf("EEE","ABB","FFF","NNN","SRR","UUU","XXX").contains(this.name) + + override val type: LocType = if (isInWorld) LocType.GROUP else LocType.CUSTOM_GROUP + override val code = this.name +} \ No newline at end of file diff --git a/app/src/main/res/layout/item_list.xml b/app/src/main/res/layout/item_list.xml index 40be8c5..fa6e36a 100644 --- a/app/src/main/res/layout/item_list.xml +++ b/app/src/main/res/layout/item_list.xml @@ -1,35 +1,55 @@ + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toTopOf="@+id/checkBox" + app:layout_constraintVertical_bias="0.5" /> + + + + + - \ No newline at end of file diff --git a/app/src/test/java/net/helcel/beendroid/CountryTest.kt b/app/src/test/java/net/helcel/beendroid/CountryTest.kt new file mode 100644 index 0000000..af6e627 --- /dev/null +++ b/app/src/test/java/net/helcel/beendroid/CountryTest.kt @@ -0,0 +1,104 @@ +package net.helcel.beendroid + +import net.helcel.beendroid.countries.Country +import net.helcel.beendroid.countries.CountryGroup +import net.helcel.beendroid.countries.CountryGroup.* + +import org.junit.Assert +import org.junit.Test + +class CountryTest { + private val codes = listOf("AFG","XAD","ALA","ALB","DZA","ASM","AND","AGO","AIA","ATG","ARG","ARM","ABW","AUS","AUT","AZE", + "BHS","BHR","BGD","BRB","BLR","BEL","BLZ","BEN","BMU","BTN","BOL","BES","BIH","BWA","BVT","BRA", "IOT","VGB","BRN","BGR","BFA","BDI","KHM", + "CMR","CAN","CPV","CYM","CAF","TCD","CHL","CHN","CXR","XCL","CCK","COL","COM","COK","CRI","CIV","HRV","CUB","CUW","CYP","CZE","COD", + "DNK","DJI","DMA","DOM","ECU","EGY","SLV","GNQ","ERI","EST","ETH","FLK","FRO","FJI","FIN","FRA","GUF","PYF","ATF", + "GAB","GMB","GEO","DEU","GHA","GIB","GRC","GRL","GRD","GLP","GUM","GTM","GGY","GIN","GNB","GUY","HTI","HMD","HND","HUN", + "ISL","IND","IDN","IRN","IRQ","IRL","IMN","ISR","ITA","JAM","JPN","JEY","JOR","KAZ","KEN","KIR","XKO","KWT","KGZ", + "LAO","LVA","LBN","LSO","LBR","LBY","LIE","LTU","LUX","SXM", + "MKD","MDG","MWI","MYS","MDV","MLI","MLT","MHL","MTQ","MRT","MUS","MYT","MEX","FSM","MDA","MCO","MNG","MNE","MSR","MAR","MOZ","MMR", + "NAM","NRU","NPL","NLD","NCL","NZL","NIC","NER","NGA","NIU","NFK","PRK","ZNC","MNP","NOR","OMN", + "PAK","PLW","PSE","PAN","PNG","PRY","PER","PHL","PCN","POL","PRT","PRI","QAT","COG","REU","ROU","RUS","RWA","BLM","MAF", + "SHN","KNA","LCA","SPM","VCT","WSM","SMR","STP","SAU","SEN","SRB","SYC","SLE","SGP","SVK","SVN","SLB","SOM","ZAF","SGS","KOR","SSD","ESP", + "LKA","SDN","SUR","SJM","SWZ","SWE","CHE","SYR","TWN","TJK","TZA","THA","TLS","TGO","TKL","TON","TTO","TUN","TUR","TKM","TCA","TUV","UGA", + "UKR","ARE","GBR","USA","UMI","URY","UZB","VUT","VAT","VEN","VNM","VIR","WLF","ESH","YEM","ZMB","ZWE") + + private val codesIgnore = listOf( + "ATA", // Antarctica not present in dataset + "HKG", // HongKong: Included in china ? + "MAC", // Macao: Included in china ? + "ANT", //Netherlands Antilles: Dissolution + ) + + + @Test + fun allCountriesInAGroup() { + Country.values().forEach { c -> + val cnt = CountryGroup.values().none { + it.countries.contains((c)) + } + Assert.assertEquals("$c has no group !",cnt,false) + } + } + + @Test + fun allCountriesInASingleGroup() { + Country.values().forEach { c -> + val cnt = listOf(EEE,FFF,ABB,NNN,SRR,UUU,XXX,ZZZ).count { + it.countries.contains((c)) + } + Assert.assertEquals("$c is in none or multiple continents",cnt,1) + } + } + + @Test + fun allCountriesFoundInEnum() { + codes.forEach {co -> + val r = Country.values().map { it.code }.contains(co) + Assert.assertEquals("$co not found in enum", r, true) + } + } + + + @Test + fun allCountriesFoundInImport() { + Country.values().forEach { + if(codesIgnore.contains(it.code)) + return@forEach + val r = codes.contains(it.code) + Assert.assertEquals("$it not found in import", r, true) + } + } + + @Test + fun allCountriesValidName() { + Country.values().forEach { + Assert.assertEquals("$it has no full_name", it.fullName.isNotEmpty(), true) + } + } + + @Test + fun allCountriesValidArea() { + Country.values().forEach { + Assert.assertEquals("$it has an area of 0", it.area > 0, true) + } + } + + @Test + fun allCountryGroupsValidName() { + CountryGroup.values().forEach { + Assert.assertEquals("$it has no full_name", it.fullName.isNotEmpty(), true) + } + } + + @Test + fun allCountryGroupsValidArea() { + CountryGroup.values().forEach { + Assert.assertEquals("$it has an area of 0", it.area >= 0, true) + } + } + + @Test + fun allRegionHaveCode() { + Assert.assertEquals(EEE.code, "EEE") + } +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index ab2b874..71ad002 100644 --- a/build.gradle +++ b/build.gradle @@ -2,5 +2,5 @@ plugins { id 'com.android.application' version '7.4.2' apply false id 'com.android.library' version '7.4.2' apply false - id 'org.jetbrains.kotlin.android' version '1.8.0' apply false + id 'org.jetbrains.kotlin.android' version '1.8.20' apply false } \ No newline at end of file diff --git a/gen_svg.js b/gen_svg.js index 76c186b..4902ff9 100644 --- a/gen_svg.js +++ b/gen_svg.js @@ -25,10 +25,10 @@ const countries = //["CHN"]//["CHE","GBR","USA","DEU","AUT","AUS","JPN"] "BHS","BHR","BGD","BRB","BLR","BEL","BLZ","BEN","BMU","BTN","BOL","BES","BIH","BWA","BVT","BRA", "IOT","VGB","BRN","BGR","BFA","BDI","KHM", "CMR","CAN","CPV","XCA","CYM","CAF","TCD","CHL","CHN","CXR","XCL","CCK","COL","COM","COK","CRI","CIV","HRV","CUB","CUW","CYP","CZE","COD", "DNK","DJI","DMA","DOM","ECU","EGY","SLV","GNQ","ERI","EST","ETH","FLK","FRO","FJI","FIN","FRA","GUF","PYF","ATF", - "GAB","GMB","GEO","DEU","GHA","GIB","GRC","GRL","GRD","GLP","GUM","GTM","GGY","GIN","GNB","GUY","HTI","HMD","HND",,"HUN", + "GAB","GMB","GEO","DEU","GHA","GIB","GRC","GRL","GRD","GLP","GUM","GTM","GGY","GIN","GNB","GUY","HTI","HMD","HND","HUN", "ISL","IND","IDN","IRN","IRQ","IRL","IMN","ISR","ITA","JAM","JPN","JEY","JOR","KAZ","KEN","KIR","XKO","KWT","KGZ", - "LAO","LVA","LBN","LSO","LBR","LBY","LIE","LTU","LUX", - ,"MKD","MDG","MWI","MYS","MDV","MLI","MLT","MHL","MTQ","MRT","MUS","MYT","MEX","FSM","MDA","MCO","MNG","MNE","MSR","MAR","MOZ","MMR", + "LAO","LVA","LBN","LSO","LBR","LBY","LIE","LTU","LUX","SXM", + "MKD","MDG","MWI","MYS","MDV","MLI","MLT","MHL","MTQ","MRT","MUS","MYT","MEX","FSM","MDA","MCO","MNG","MNE","MSR","MAR","MOZ","MMR", "NAM","NRU","NPL","NLD","NCL","NZL","NIC","NER","NGA","NIU","NFK","PRK","ZNC","MNP","NOR","OMN", "PAK","PLW","PSE","PAN","PNG","PRY","PER","PHL","PCN","POL","PRT","PRI","QAT","COG","REU","ROU","RUS","RWA","BLM","MAF", "SHN","KNA","LCA","SPM","VCT","WSM","SMR","STP","SAU","SEN","SRB","SYC","SLE","SGP","SVK","SVN","SLB","SOM","ZAF","SGS","KOR","SSD","ESP", diff --git a/settings.gradle b/settings.gradle index b8c1cff..34c822e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,6 +3,7 @@ pluginManagement { google() mavenCentral() gradlePluginPortal() + maven { url 'https://jitpack.io' } } } dependencyResolutionManagement { @@ -10,6 +11,7 @@ dependencyResolutionManagement { repositories { google() mavenCentral() + maven { url 'https://jitpack.io' } } } rootProject.name = "beendroid"