Skip to content

Commit

Permalink
added dialog to place marker
Browse files Browse the repository at this point in the history
  • Loading branch information
Deliner committed Sep 5, 2020
1 parent 43dfa82 commit d6c9a3d
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 11 deletions.
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
android:name=".activity.LoginActivity"
android:noHistory="true" />

<activity
android:name=".activity.BirdInfoActivity"
android:noHistory="true" />

<activity android:name=".activity.MainActivity" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.deliner.mosfauna.activity

import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import android.widget.Button
import android.widget.EditText
import com.deliner.mosfauna.R
import com.deliner.mosfauna.utils.LoginManager

class BirdInfoActivity : UserActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)

setSupportActionBar(findViewById(R.id.toolbar))
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
}
}
11 changes: 6 additions & 5 deletions app/src/main/java/com/deliner/mosfauna/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ class MainActivity : CommonActivity() {
attachToSliderView(slider)
addProfiles(
profile,
ProfileSettingDrawerItem().apply {
nameText = "Выйти";
iconicsIcon = GoogleMaterial.Icon.gmd_delete;
identifier = 1001
})
// ProfileSettingDrawerItem().apply {
// nameText = "Выйти";
// iconicsIcon = GoogleMaterial.Icon.gmd_delete;
// identifier = 1001
// }
)
onAccountHeaderListener = { _, profile, _ ->
if (profile.identifier == 1001L) {
Message.obtain(handler, CoreConst.ON_LOGOUT).sendToTarget()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package com.deliner.mosfauna.dialog
object DialogTags {

const val REQUEST_CODE = "request_code_dialog"
const val PLACE_MARKER = "place_marker_dialog"
}
55 changes: 55 additions & 0 deletions app/src/main/java/com/deliner/mosfauna/dialog/PlaceMarkerDialog.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.deliner.mosfauna.dialog

import android.content.DialogInterface
import android.os.Bundle
import android.os.Message
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import com.deliner.mosfauna.R
import com.deliner.mosfauna.system.CoreConst


class PlaceMarkerDialog private constructor() : CommonDialogFragment() {

private lateinit var name: String
private var success = false

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.dialog_place_marker, container, false)
view.findViewById<TextView>(R.id.dialog_place_marker_title).text =
"Указать на ${name.toLowerCase()} на карте?"

view.findViewById<Button>(R.id.dialog_request_code_send).setOnClickListener {
success = true
Message.obtain(callback, CoreConst.ON_SEND_MARKER, name).sendToTarget()
dismiss()
}
view.findViewById<Button>(R.id.dialog_request_code_cancel).setOnClickListener {
dismiss()
}
return view
}

override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
if (!success) {
Message.obtain(callback, CoreConst.ON_CANCEL_MARKER, name).sendToTarget()
}
}

companion object {
fun getInstance(name: String): PlaceMarkerDialog {
val dialog = PlaceMarkerDialog()
dialog.name = name
return dialog
}
}
}
49 changes: 43 additions & 6 deletions app/src/main/java/com/deliner/mosfauna/fragment/GuideFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@ package com.deliner.mosfauna.fragment

import android.graphics.drawable.Drawable
import android.os.Bundle
import android.os.Message
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import com.deliner.mosfauna.R
import com.deliner.mosfauna.dialog.CommonDialogFragment
import com.deliner.mosfauna.dialog.DialogTags
import com.deliner.mosfauna.dialog.PlaceMarkerDialog
import com.deliner.mosfauna.system.CoreConst
import com.deliner.mosfauna.utils.Bird
import com.deliner.mosfauna.utils.MultiDrawable
import com.deliner.mosfauna.utils.StaticHandler
import com.google.android.gms.maps.*
import com.google.android.gms.maps.model.*
import com.google.maps.android.clustering.Cluster
Expand All @@ -21,7 +28,8 @@ import com.google.maps.android.ui.IconGenerator
import java.util.*


class GuideFragment : CommonFragment(), OnMapReadyCallback, ClusterManager.OnClusterClickListener<Bird>,
class GuideFragment : CommonFragment(), OnMapReadyCallback,
ClusterManager.OnClusterClickListener<Bird>,
ClusterManager.OnClusterInfoWindowClickListener<Bird>,
ClusterManager.OnClusterItemClickListener<Bird>,
ClusterManager.OnClusterItemInfoWindowClickListener<Bird> {
Expand All @@ -32,6 +40,7 @@ class GuideFragment : CommonFragment(), OnMapReadyCallback, ClusterManager.OnClu
private var mClusterManager: ClusterManager<Bird>? = null

private var currentBirb: Bird? = null
private var clickPos: LatLng? = null

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -57,10 +66,12 @@ class GuideFragment : CommonFragment(), OnMapReadyCallback, ClusterManager.OnClu

override fun onResume() {
super.onResume()
handler.setCallback(this)
mMapView!!.onResume()
}

override fun onPause() {
handler.dropCallback(this)
super.onPause()
mMapView!!.onPause()
}
Expand Down Expand Up @@ -88,11 +99,10 @@ class GuideFragment : CommonFragment(), OnMapReadyCallback, ClusterManager.OnClu
googleMap!!.setOnMarkerClickListener(mClusterManager)
googleMap!!.setOnInfoWindowClickListener(mClusterManager)
googleMap!!.setOnMapClickListener {
if (currentBirb != null){

// show

Toast.makeText(context, "ground", Toast.LENGTH_SHORT).show()
if (currentBirb != null) {
clickPos = it
showDialogEx(DialogTags.PLACE_MARKER, bundleOf("KEY_NAME" to currentBirb!!.name))
// Toast.makeText(context, "ground", Toast.LENGTH_SHORT).show()
}
}
mClusterManager!!.setOnClusterClickListener(this)
Expand All @@ -103,6 +113,27 @@ class GuideFragment : CommonFragment(), OnMapReadyCallback, ClusterManager.OnClu
mClusterManager!!.cluster()
}


override fun handleServiceMessage(msg: Message) {
when (msg.what) {
CoreConst.ON_SEND_MARKER -> sendMarker(currentBirb!!, clickPos!!)
else -> super.handleServiceMessage(msg)
}
}

private fun sendMarker(currentBird: Bird, clickPos: LatLng) {

}


override fun onCreateDialogEx(tag: String, args: Bundle?): CommonDialogFragment {
return when (tag) {
DialogTags.PLACE_MARKER -> PlaceMarkerDialog.getInstance(args!!.getString("KEY_NAME")!!)
.setDialogResult(handler)
else -> super.onCreateDialogEx(tag, args)
}
}

override fun onClusterClick(cluster: Cluster<Bird>): Boolean {
val builder = LatLngBounds.builder()
for (item in cluster.items) {
Expand All @@ -122,6 +153,7 @@ class GuideFragment : CommonFragment(), OnMapReadyCallback, ClusterManager.OnClu
}

override fun onClusterItemClick(item: Bird): Boolean {
currentBirb = item
return false
}

Expand Down Expand Up @@ -229,4 +261,9 @@ class GuideFragment : CommonFragment(), OnMapReadyCallback, ClusterManager.OnClu
mIconGenerator.setContentView(mImageView)
}
}


companion object {
private val handler = StaticHandler()
}
}
3 changes: 3 additions & 0 deletions app/src/main/java/com/deliner/mosfauna/system/CoreConst.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ object CoreConst {
const val ON_SEND_REQUEST_CODE = 1
const val ON_CANCEL_REQUEST_CODE = 2
const val ON_LOGOUT = 3

const val ON_SEND_MARKER = 4
const val ON_CANCEL_MARKER = 5
}
21 changes: 21 additions & 0 deletions app/src/main/res/layout/activity_bird_info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<include
android:id="@+id/toolbar"
layout="@layout/toolbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>


</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.drawerlayout.widget.DrawerLayout>
37 changes: 37 additions & 0 deletions app/src/main/res/layout/dialog_place_marker.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">

<TextView
android:id="@+id/dialog_place_marker_title"
style="@style/TextAppearance.AppCompat.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="12dp"/>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<Button
android:id="@+id/dialog_request_code_cancel"
style="?attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toStartOf="@+id/dialog_request_code_send"
android:text="Отмена"/>

<Button
android:id="@+id/dialog_request_code_send"
style="?attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:text="Да"/>
</RelativeLayout>
</LinearLayout>

0 comments on commit d6c9a3d

Please sign in to comment.