Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brock2 #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions android/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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/"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,31 @@ 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() {

private val listFragment = ListSegmentFragment()
private val mapFragment = MapSegmentFragment()
private var selectedSegmentIndex = 0
private var data: ArrayList<LocationDto>? = null

private lateinit var segmentButtons: List<ImageButton>

private var adapter: MappingListAdapter? = null


@Inject
lateinit var retrofit: Retrofit

Expand All @@ -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<LocationDto>){
adapter = MappingListAdapter(this, data)
listFragment.setAdapter(adapter!!)
}

private fun downloadData() {
retrofit.create(GitHubService::class.java).listRepos("olivierpineau").enqueue(object : Callback<List<Repo>> {
override fun onFailure(call: Call<List<Repo>>?, t: Throwable?) {
Log.d("street's test", "Oops")
retrofit.create(MappingService::class.java).listData().enqueue(object: Callback<List<LocationDto>>{
override fun onFailure(call: Call<List<LocationDto>>?, t: Throwable?) {
Log.d("PLS", "NO")
}

override fun onResponse(call: Call<List<Repo>>?, response: Response<List<Repo>>?) {
Log.d("street's test", "That's it")
override fun onResponse(call: Call<List<LocationDto>>?, response: Response<List<LocationDto>>?) {
if (response != null) {
val list = response.body()
if (data == null){
data = ArrayList(list)
}
updateAdapter(data!!)
}
}

})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<LocationDto>) : 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
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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<List<LocationDto>>
}
16 changes: 10 additions & 6 deletions android/app/src/main/res/layout/fragment_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
android:orientation="vertical">

<TextView
android:id="@+id/nameTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
Expand All @@ -46,6 +47,7 @@
android:textColor="@color/purpleBrown" />

<TextView
android:id="@+id/componentTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
Expand All @@ -60,14 +62,16 @@
android:orientation="horizontal">

<TextView
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" />
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" />

<TextView
android:id="@+id/distanceTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
Expand Down
17 changes: 17 additions & 0 deletions android/app/src/main/res/layout/fragment_list_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/fragmentText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />

<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"></ListView>

</android.support.constraint.ConstraintLayout>