diff --git a/android/.idea/modules.xml b/android/.idea/modules.xml
index abc31fc..42efc7f 100644
--- a/android/.idea/modules.xml
+++ b/android/.idea/modules.xml
@@ -3,7 +3,9 @@
+
+
\ No newline at end of file
diff --git a/android/app/src/main/java/com/mirego/csmapapplication/MapPingApplication.kt b/android/app/src/main/java/com/mirego/csmapapplication/MapPingApplication.kt
index 8ea66d2..eab5a90 100644
--- a/android/app/src/main/java/com/mirego/csmapapplication/MapPingApplication.kt
+++ b/android/app/src/main/java/com/mirego/csmapapplication/MapPingApplication.kt
@@ -19,6 +19,6 @@ class MapPingApplication : Application() {
}
companion object {
- private const val DATA_SOURCE_URL = "https://api.github.com"
+ private const val DATA_SOURCE_URL = "https://s3.amazonaws.com/"
}
}
\ No newline at end of file
diff --git a/android/app/src/main/java/com/mirego/csmapapplication/activity/MainActivity.kt b/android/app/src/main/java/com/mirego/csmapapplication/activity/MainActivity.kt
index d94302b..4a06f9e 100644
--- a/android/app/src/main/java/com/mirego/csmapapplication/activity/MainActivity.kt
+++ b/android/app/src/main/java/com/mirego/csmapapplication/activity/MainActivity.kt
@@ -11,16 +11,17 @@ import android.view.View
import android.widget.ImageButton
import com.mirego.csmapapplication.MapPingApplication
import com.mirego.csmapapplication.R
+import com.mirego.csmapapplication.adapter.MappingListAdapter
import com.mirego.csmapapplication.fragment.ListSegmentFragment
import com.mirego.csmapapplication.fragment.MapSegmentFragment
-import com.mirego.csmapapplication.model.Repo
+import com.mirego.csmapapplication.model.LocationDto
+import com.mirego.csmapapplication.service.MappingService
import kotlinx.android.synthetic.main.activity_main.*
-import retrofit2.Retrofit
-import javax.inject.Inject
-import com.mirego.csmapapplication.service.GitHubService
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
+import retrofit2.Retrofit
+import javax.inject.Inject
class MainActivity : FragmentActivity() {
@@ -28,9 +29,13 @@ class MainActivity : FragmentActivity() {
private val listFragment = ListSegmentFragment()
private val mapFragment = MapSegmentFragment()
private var selectedSegmentIndex = 0
+ private var data: ArrayList? = null
private lateinit var segmentButtons: List
+ private var adapter: MappingListAdapter? = null
+
+
@Inject
lateinit var retrofit: Retrofit
@@ -48,19 +53,38 @@ class MainActivity : FragmentActivity() {
}
setupButtons()
+ setupAdapter()
+ }
- downloadData()
+ private fun setupAdapter(){
+ if (data == null){
+ downloadData()
+ }else{
+ updateAdapter(data!!)
+ }
+ }
+
+ private fun updateAdapter(data: ArrayList){
+ adapter = MappingListAdapter(this, data)
+ listFragment.setAdapter(adapter!!)
}
private fun downloadData() {
- retrofit.create(GitHubService::class.java).listRepos("olivierpineau").enqueue(object : Callback> {
- override fun onFailure(call: Call>?, t: Throwable?) {
- Log.d("street's test", "Oops")
+ retrofit.create(MappingService::class.java).listData().enqueue(object: Callback>{
+ override fun onFailure(call: Call>?, t: Throwable?) {
+ Log.d("PLS", "NO")
}
- override fun onResponse(call: Call>?, response: Response>?) {
- Log.d("street's test", "That's it")
+ override fun onResponse(call: Call>?, response: Response>?) {
+ if (response != null) {
+ val list = response.body()
+ if (data == null){
+ data = ArrayList(list)
+ }
+ updateAdapter(data!!)
+ }
}
+
})
}
diff --git a/android/app/src/main/java/com/mirego/csmapapplication/adapter/MappingListAdapter.kt b/android/app/src/main/java/com/mirego/csmapapplication/adapter/MappingListAdapter.kt
new file mode 100644
index 0000000..2091f35
--- /dev/null
+++ b/android/app/src/main/java/com/mirego/csmapapplication/adapter/MappingListAdapter.kt
@@ -0,0 +1,74 @@
+package com.mirego.csmapapplication.adapter
+
+import android.app.Activity
+import android.content.Context
+import android.util.Log
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.BaseAdapter
+import android.widget.ImageView
+import android.widget.TextView
+import com.mirego.csmapapplication.R
+import com.mirego.csmapapplication.model.LocationDto
+
+class MappingListAdapter(private var activity: Activity, private var items: ArrayList) : BaseAdapter() {
+
+ private class ViewHolder(row: View?) {
+ var txtName: TextView? = null
+ var txtComponent: TextView? = null
+ var txtLat: TextView? = null
+ var txtDistance: TextView? = null
+ var iconImage: ImageView? = null
+
+ init {
+ txtName = row?.findViewById(R.id.nameTxt)
+ txtComponent = row?.findViewById(R.id.componentTxt)
+ txtLat = row?.findViewById(R.id.lat_txt)
+ txtDistance = row?.findViewById(R.id.distanceTxt)
+ iconImage = row?.findViewById(R.id.imageIcon)
+ }
+ }
+
+ override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
+ val view: View?
+ val viewHolder: ViewHolder
+
+ if (convertView == null){
+ val inflater = activity?.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
+ view = inflater.inflate(R.layout.fragment_list, null)
+ viewHolder = ViewHolder(view)
+ view?.tag = viewHolder
+ }else{
+ view = convertView
+ viewHolder = view.tag as ViewHolder
+ }
+
+ var locationDto = items[position]
+ viewHolder.txtComponent?.text = locationDto.component
+ viewHolder.txtName?.text = locationDto.name
+ viewHolder.txtLat?.text = createCoordinates(locationDto.lat, locationDto.lon)
+
+ val resId = view?.resources?.getIdentifier("ic_part_" + locationDto.type, "drawable", view?.context.packageName)
+ resId?.let { viewHolder.iconImage?.setImageResource(it) }
+
+ return view as View
+ }
+
+ fun createCoordinates(lat: Double?, long: Double?): String{
+ return "%.4f° N, %.4f° W".format(lat, long)
+ }
+
+ override fun getItem(i: Int): Any {
+ return items[i]
+ }
+
+ override fun getItemId(i: Int): Long {
+ return i.toLong()
+ }
+
+ override fun getCount(): Int {
+ return items.size
+ }
+
+}
\ No newline at end of file
diff --git a/android/app/src/main/java/com/mirego/csmapapplication/fragment/ListSegmentFragment.kt b/android/app/src/main/java/com/mirego/csmapapplication/fragment/ListSegmentFragment.kt
index 7a461af..928f0fe 100644
--- a/android/app/src/main/java/com/mirego/csmapapplication/fragment/ListSegmentFragment.kt
+++ b/android/app/src/main/java/com/mirego/csmapapplication/fragment/ListSegmentFragment.kt
@@ -2,17 +2,43 @@ package com.mirego.csmapapplication.fragment
import android.support.v4.app.Fragment
import android.os.Bundle
+import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import android.widget.ListView
import com.mirego.csmapapplication.R
+import com.mirego.csmapapplication.adapter.MappingListAdapter
class ListSegmentFragment : Fragment() {
+ var listView: ListView? = null
+ var listAdapter: MappingListAdapter? = null
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+ listView = view?.findViewById(R.id.listView)
+ listView?.adapter = listAdapter
+ }
+
+
+ override fun onResume() {
+ super.onResume()
+ listView?.adapter = listAdapter
+ }
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
- return inflater.inflate(R.layout.fragment_list, container, false)
+ val v = inflater.inflate(R.layout.fragment_list_view, container, false)
+ if (listView == null){
+ listView = view?.findViewById(R.id.listView)
+ }
+ return v
+ }
+
+ fun setAdapter(adapter: MappingListAdapter){
+ listAdapter = adapter
+ listView?.adapter = adapter
}
}
diff --git a/android/app/src/main/java/com/mirego/csmapapplication/model/LocationDto.kt b/android/app/src/main/java/com/mirego/csmapapplication/model/LocationDto.kt
new file mode 100644
index 0000000..20e3165
--- /dev/null
+++ b/android/app/src/main/java/com/mirego/csmapapplication/model/LocationDto.kt
@@ -0,0 +1,11 @@
+package com.mirego.csmapapplication.model
+
+class LocationDto {
+ val name: String? = null
+ val component: String? = null
+ val notes: String? = null
+ val type: String? = null
+ val lat: Double? = null
+ val lon: Double? = null
+ val address: String? = null
+}
\ No newline at end of file
diff --git a/android/app/src/main/java/com/mirego/csmapapplication/service/MappingService.kt b/android/app/src/main/java/com/mirego/csmapapplication/service/MappingService.kt
new file mode 100644
index 0000000..6c6ed6c
--- /dev/null
+++ b/android/app/src/main/java/com/mirego/csmapapplication/service/MappingService.kt
@@ -0,0 +1,10 @@
+package com.mirego.csmapapplication.service
+
+import com.mirego.csmapapplication.model.LocationDto
+import retrofit2.Call
+import retrofit2.http.GET
+
+interface MappingService {
+ @GET("shared.ws.mirego.com/competition/mapping.json")
+ fun listData(): Call>
+}
\ No newline at end of file
diff --git a/android/app/src/main/res/layout/fragment_list.xml b/android/app/src/main/res/layout/fragment_list.xml
index 9e96618..d8ccb01 100644
--- a/android/app/src/main/res/layout/fragment_list.xml
+++ b/android/app/src/main/res/layout/fragment_list.xml
@@ -37,6 +37,7 @@
android:orientation="vertical">
+ android:id="@+id/lat_txt"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:ellipsize="end"
+ android:maxLines="1"
+ android:text="46.7552° N, 71.2265° W"
+ android:textColor="@color/brownishGrey" />
+
+
+
+
+
+
+
\ No newline at end of file