Add a basic map view to app

This commit is contained in:
Danila Fedorin 2020-02-16 16:36:25 -08:00
parent 5b0bb1e862
commit cfae237d17
4 changed files with 41 additions and 3 deletions

View File

@ -23,6 +23,10 @@ android {
}
}
repositories {
mavenCentral()
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
@ -35,4 +39,6 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'org.osmdroid:osmdroid-android:6.1.5'
implementation "androidx.preference:preference-ktx:1.1.0"
}

View File

@ -3,6 +3,8 @@
package="com.danilafe.fencelessgrazing">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"

View File

@ -2,23 +2,34 @@ package com.danilafe.fencelessgrazing
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import org.osmdroid.config.Configuration
import org.osmdroid.tileprovider.tilesource.TileSourceFactory
import org.osmdroid.views.MapView
class CollarListActivity : AppCompatActivity() {
private lateinit var token: String
private lateinit var summaryAdapter: CollarSummaryAdapter
private lateinit var map: MapView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Configuration.getInstance().load(applicationContext,
PreferenceManager.getDefaultSharedPreferences(applicationContext))
setContentView(R.layout.activity_collar_list)
val collarList: RecyclerView = findViewById(R.id.collarSummaryList)
val layoutManager = LinearLayoutManager(collarList.context)
token = intent.getStringExtra("token")!!
summaryAdapter = CollarSummaryAdapter(collarList.context, getString(R.string.apiUrl), token)
map = findViewById(R.id.map)
map.setTileSource(TileSourceFactory.MAPNIK)
collarList.adapter = summaryAdapter
collarList.layoutManager = layoutManager
@ -26,4 +37,14 @@ class CollarListActivity : AppCompatActivity() {
summaryAdapter.triggerRefresh()
}
override fun onResume() {
super.onResume()
map.onResume()
}
override fun onPause() {
super.onPause()
map.onPause()
}
}

View File

@ -6,11 +6,20 @@
android:layout_height="match_parent"
tools:context=".CollarListActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/collarSummaryList"
<org.osmdroid.views.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="16:9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/collarSummaryList"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/map"
tools:layout_editor_absoluteX="0dp" />
</androidx.constraintlayout.widget.ConstraintLayout>