-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
21 changed files
with
741 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 173 additions & 1 deletion
174
app/src/main/java/com/deliner/mosfauna/activity/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
32
app/src/main/java/com/deliner/mosfauna/activity/MapsActivity.kt
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
app/src/main/java/com/deliner/mosfauna/fragment/CommonFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
65
app/src/main/java/com/deliner/mosfauna/fragment/GuideFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.