Skip to content

Commit

Permalink
added material drawer and map
Browse files Browse the repository at this point in the history
Deliner committed Sep 5, 2020
1 parent fd17563 commit 0fc7835
Showing 21 changed files with 741 additions and 256 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -3,13 +3,13 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 30
buildToolsVersion "30.0.0"
compileSdkVersion 29
buildToolsVersion "29.0.3"

defaultConfig {
applicationId "com.deliner.mosfauna"
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 29
versionCode 1
versionName "1.0"
}
@@ -41,9 +41,9 @@ dependencies {
implementation "com.mikepenz:materialdrawer-iconics:8.1.5"
implementation "com.mikepenz:iconics-core:5.0.3"

implementation 'com.mikepenz:google-material-typeface:3.0.1.2.original@aar'
implementation 'com.mikepenz:google-material-typeface:3.0.1.4.original-kotlin@aar'
implementation 'com.mikepenz:fontawesome-typeface:5.3.1.2-kotlin@aar'
implementation 'com.mikepenz:octicons-typeface:3.2.0.4@aar'
implementation 'com.mikepenz:octicons-typeface:3.2.0.6-kotlin@aar'

implementation 'com.camerakit:camerakit:1.0.0-beta3.11'
implementation 'com.camerakit:jpegkit:0.1.0'
5 changes: 0 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -30,11 +30,6 @@
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />

<activity
android:name=".activity.MapsActivity"
android:label="@string/title_activity_maps"></activity>


<activity
android:name=".activity.StartActivity"
android:noHistory="true">
174 changes: 173 additions & 1 deletion app/src/main/java/com/deliner/mosfauna/activity/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,188 @@
package com.deliner.mosfauna.activity

import android.content.Intent
import android.content.res.Configuration
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Message
import android.view.Menu
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.fragment.app.Fragment
import com.deliner.mosfauna.R
import com.deliner.mosfauna.fragment.GuideFragment
import com.deliner.mosfauna.fragment.ScoreFragment
import com.deliner.mosfauna.system.CoreConst
import com.deliner.mosfauna.utils.LoginManager
import com.deliner.mosfauna.utils.StaticHandler
import com.deliner.mosfauna.utils.Utils
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
import com.mikepenz.materialdrawer.iconics.iconicsIcon
import com.mikepenz.materialdrawer.iconics.withIcon
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem
import com.mikepenz.materialdrawer.model.ProfileDrawerItem
import com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem
import com.mikepenz.materialdrawer.model.SecondaryDrawerItem
import com.mikepenz.materialdrawer.model.interfaces.*
import com.mikepenz.materialdrawer.util.addStickyDrawerItems
import com.mikepenz.materialdrawer.widget.AccountHeaderView
import com.mikepenz.materialdrawer.widget.MaterialDrawerSliderView
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : CommonActivity() {
private lateinit var slider: MaterialDrawerSliderView

private lateinit var actionBarDrawerToggle: ActionBarDrawerToggle
private lateinit var headerView: AccountHeaderView

private var currentPage: PageTypes? = null

override fun handleServiceMessage(msg: Message) {
when (msg.what) {
CoreConst.ON_LOGOUT -> {
LoginManager.getInstance(applicationContext).deleteUser()
intent.flags = Intent.FLAG_ACTIVITY_NO_HISTORY
startActivity(Intent(this, GreetActivity::class.java))
}
else -> super.handleServiceMessage(msg)
}
}

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

setSupportActionBar(findViewById(R.id.toolbar))
supportActionBar!!.setDisplayHomeAsUpEnabled(false)
supportActionBar!!.setHomeButtonEnabled(true)

slider = findViewById(R.id.activity_main_drawer)

actionBarDrawerToggle = ActionBarDrawerToggle(
this,
root,
findViewById(R.id.toolbar),
com.mikepenz.materialdrawer.R.string.material_drawer_open,
com.mikepenz.materialdrawer.R.string.material_drawer_close
)
root.addDrawerListener(actionBarDrawerToggle)

initSlider()

attachFragment(PageTypes.GUIDE)
}

private fun initSlider() {
val user = LoginManager.getInstance(applicationContext).getCurrentUser()!!
val profile = ProfileDrawerItem().apply {
nameText = user.login; descriptionText = user.mail; identifier = 100
}

headerView = AccountHeaderView(this).apply {
attachToSliderView(slider)
addProfiles(
profile,
ProfileSettingDrawerItem().apply {
nameText = "Выйти";
iconicsIcon = GoogleMaterial.Icon.gmd_delete;
identifier = 1001
})
onAccountHeaderListener = { _, profile, _ ->
if (profile.identifier == 1001L) {
Message.obtain(handler, CoreConst.ON_LOGOUT).sendToTarget()
}
false
}
}



slider.apply {
itemAdapter.add(
PrimaryDrawerItem().withIdentifier(1).withName("Гид")
.withIcon(GoogleMaterial.Icon.gmd_home),
PrimaryDrawerItem().withIdentifier(2).withName("Рейтинг")
.withIcon(GoogleMaterial.Icon.gmd_show_chart),
)
addStickyDrawerItems(
SecondaryDrawerItem().withName("Cвязаться с разработчиками")
.withIcon(GoogleMaterial.Icon.gmd_message).withIdentifier(6),
)
selectedItemIdentifier = 1
}

slider.onDrawerItemClickListener = { _, drawerItem, _ ->
when (drawerItem.identifier) {
1L -> {
attachFragment(PageTypes.GUIDE)
supportActionBar!!.title = "ГИД"
}
2L -> {
attachFragment(PageTypes.SCORE)
supportActionBar!!.title = "РЕЙТИНГ"
}
6L -> Utils.shareTextToEmail(
this,
arrayOf("deliner.work@gmail.com"),
"MOSFAUNA",
""
)
}
false
}
}

private fun attachFragment(type: PageTypes) {
if (currentPage != type) {
val fragment = when (type) {
PageTypes.GUIDE -> GuideFragment()
PageTypes.SCORE -> ScoreFragment()
}
updateFragment(fragment)
currentPage = type
}
}

private fun updateFragment(fragment: Fragment) {
supportFragmentManager
.beginTransaction()
.replace(R.id.activity_main_fragment_holder, fragment)
.commit()
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
actionBarDrawerToggle.onConfigurationChanged(newConfig)
}

override fun onPause() {
handler.dropCallback(this)
super.onPause()
}

override fun onResume() {
super.onResume()
actionBarDrawerToggle.syncState()
handler.setCallback(this)
}

override fun onSaveInstanceState(_outState: Bundle) {
var outState = _outState
outState = slider.saveInstanceState(outState)
outState = headerView.saveInstanceState(outState)
super.onSaveInstanceState(outState)
}

override fun onBackPressed() {
if (root.isDrawerOpen(slider)) {
root.closeDrawer(slider)
} else {
super.onBackPressed()
}
}

private enum class PageTypes { GUIDE, SCORE }

companion object {
private val handler = StaticHandler()
}
}
32 changes: 0 additions & 32 deletions app/src/main/java/com/deliner/mosfauna/activity/MapsActivity.kt

This file was deleted.

51 changes: 51 additions & 0 deletions app/src/main/java/com/deliner/mosfauna/fragment/CommonFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.deliner.mosfauna.fragment

import android.os.Bundle
import android.os.Message
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import com.deliner.mosfauna.dialog.CommonDialogFragment
import com.deliner.mosfauna.dialog.DialogManager
import com.deliner.mosfauna.utils.StaticHandler

abstract class CommonFragment : Fragment(), StaticHandler.Callback, DialogManager.Callback {

private lateinit var dialogManager: DialogManager

override fun handleServiceMessage(msg: Message) {
}

override fun onCreate(savedInstanceState: Bundle?) {
dialogManager = DialogManager(this)
super.onCreate(savedInstanceState)
}

override fun onPause() {
dialogManager.onPause()
super.onPause()
}

override fun onResume() {
dialogManager.onPostResume()
super.onResume()
}

override fun getSupportManager(): FragmentManager {
return requireActivity().supportFragmentManager
}

override fun onCreateDialogEx(tag: String, args: Bundle?): CommonDialogFragment {
throw Exception("No dialog implementation for this tag $tag")
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(getLayoutResource(), container, false)
}

abstract fun getLayoutResource(): Int

protected fun showDialogEx(tag: String, args: Bundle? = null) = dialogManager.showDialogEx(tag, args)
}
65 changes: 65 additions & 0 deletions app/src/main/java/com/deliner/mosfauna/fragment/GuideFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.deliner.mosfauna.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.deliner.mosfauna.R
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.MapView
import com.google.android.gms.maps.MapsInitializer
import com.google.android.gms.maps.model.CameraPosition
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.MarkerOptions


class GuideFragment : Fragment() {

var mMapView: MapView? = null
private var googleMap: GoogleMap? = null

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val rootView: View = inflater.inflate(R.layout.fragment_guide, container, false)
mMapView = rootView.findViewById<View>(R.id.mapView) as MapView
mMapView!!.onCreate(savedInstanceState)
mMapView!!.onResume()
try {
MapsInitializer.initialize(requireActivity().applicationContext)
} catch (e: Exception) {
e.printStackTrace()
}
mMapView!!.getMapAsync { mMap ->
val sydney = LatLng(55.6524933,37.4646361)
val cameraPosition = CameraPosition.Builder().target(sydney).zoom(14f).build()

googleMap = mMap
googleMap!!.addMarker(MarkerOptions().position(sydney).title("").snippet(""))
googleMap!!.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition))
}
return rootView
}

override fun onResume() {
super.onResume()
mMapView!!.onResume()
}

override fun onPause() {
super.onPause()
mMapView!!.onPause()
}

override fun onDestroy() {
super.onDestroy()
mMapView!!.onDestroy()
}

override fun onLowMemory() {
super.onLowMemory()
mMapView!!.onLowMemory()
}

// override fun getLayoutResource(): Int = R.layout.fragment_guide
}
Loading
Oops, something went wrong.

0 comments on commit 0fc7835

Please sign in to comment.