Skip to content

Commit

Permalink
added first pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Deliner committed Sep 5, 2020
1 parent 9ece89e commit fd17563
Show file tree
Hide file tree
Showing 41 changed files with 926 additions and 70 deletions.
7 changes: 7 additions & 0 deletions app/src/debug/res/values/const_strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<resources>

<!-- Preference keys -->
<string name="pref_login_manger" translatable="false">pref_login_manger</string>
<string name="pref_key_voice" translatable="false">pref_voice</string>

</resources>
21 changes: 18 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,30 @@
android:value="@string/google_maps_key" />

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


<activity
android:name=".activity.StartActivity"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

<activity
android:name=".activity.GreetActivity"
android:noHistory="true" />
<activity
android:name=".activity.JoinActivity"
android:noHistory="true" />
<activity
android:name=".activity.LoginActivity"
android:noHistory="true" />

<activity android:name=".activity.MainActivity" />
</application>
</manifest>
11 changes: 0 additions & 11 deletions app/src/main/java/com/deliner/mosfauna/GreetActivity.kt

This file was deleted.

17 changes: 0 additions & 17 deletions app/src/main/java/com/deliner/mosfauna/JoinActivity.kt

This file was deleted.

11 changes: 0 additions & 11 deletions app/src/main/java/com/deliner/mosfauna/LoginActivity.kt

This file was deleted.

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

import android.os.Bundle
import android.os.Message
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentManager
import com.deliner.mosfauna.dialog.CommonDialogFragment
import com.deliner.mosfauna.dialog.DialogManager
import com.deliner.mosfauna.utils.StaticHandler
import java.lang.Exception

abstract class CommonActivity : AppCompatActivity(), StaticHandler.Callback, DialogManager.Callback {

private lateinit var dialogManager: DialogManager

override fun handleServiceMessage(msg: Message) {
}

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

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

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

override fun getSupportManager(): FragmentManager {
return supportFragmentManager
}

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

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

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import com.deliner.mosfauna.R
import com.deliner.mosfauna.utils.LoginManager

class GreetActivity : AppCompatActivity() {
private lateinit var loginButton: Button
private lateinit var joinButton: Button

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

if (LoginManager.getInstance(applicationContext).getCurrentUser() != null) {
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
startActivity(Intent(this, StartActivity::class.java))
return
}

joinButton = findViewById(R.id.activity_greet_join)
loginButton = findViewById(R.id.activity_greet_login)

joinButton.setOnClickListener { startActivity(Intent(this, JoinActivity::class.java)) }
loginButton.setOnClickListener { startActivity(Intent(this, LoginActivity::class.java)) }
}
}
116 changes: 116 additions & 0 deletions app/src/main/java/com/deliner/mosfauna/activity/JoinActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package com.deliner.mosfauna.activity

import android.content.Intent
import android.os.Bundle
import android.os.Message
import android.view.MenuItem
import android.widget.Button
import android.widget.CheckBox
import android.widget.EditText
import android.widget.Toast
import com.deliner.mosfauna.R
import com.deliner.mosfauna.dialog.CommonDialogFragment
import com.deliner.mosfauna.dialog.DialogTags
import com.deliner.mosfauna.dialog.RequestCodeDialog
import com.deliner.mosfauna.system.CoreConst
import com.deliner.mosfauna.utils.LoginManager
import com.deliner.mosfauna.utils.StaticHandler

class JoinActivity : UserActivity() {

private lateinit var passwordText: EditText
private lateinit var emailText: EditText
private lateinit var loginText: EditText
private lateinit var checkBox: CheckBox

private lateinit var loginButton: Button

private var pendingRequest = false

private var user: LoginManager.User? = null

override fun handleServiceMessage(msg: Message) {
when (msg.what) {
CoreConst.ON_SEND_REQUEST_CODE -> onSendRequestCode(msg.obj as String)
CoreConst.ON_CANCEL_REQUEST_CODE -> pendingRequest = false
else -> super.handleServiceMessage(msg)
}
}

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

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

loginButton = findViewById(R.id.activity_join_button_join)
passwordText = findViewById(R.id.activity_join_password)
emailText = findViewById(R.id.activity_join_email)
loginText = findViewById(R.id.activity_join_login)
checkBox = findViewById(R.id.activity_join_checkbox)

checkBox.isChecked = false
loginButton.isEnabled = false
checkBox.setOnClickListener { loginButton.isEnabled = (it as CheckBox).isChecked }

loginButton.setOnClickListener {
if (checkEmail(emailText.text.toString()) && checkLogin(loginText.text.toString()) && checkPassword(
passwordText.text.toString()
) && !pendingRequest
) {
user = LoginManager.User(
loginText.text.toString(),
passwordText.text.toString(),
emailText.text.toString()
)
pendingRequest = true
showDialogEx(DialogTags.REQUEST_CODE)
}
}
}

private fun onSendRequestCode(code: String) {
if (code == "0000") {
LoginManager.getInstance(applicationContext).setCurrentUser(user!!)
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
startActivity(Intent(this, MainActivity::class.java))
} else {
Toast.makeText(applicationContext, "Invalid code format", Toast.LENGTH_SHORT).show()
pendingRequest = false
}
}

override fun onCreateDialogEx(tag: String, args: Bundle?): CommonDialogFragment {
return when (tag) {
DialogTags.REQUEST_CODE -> RequestCodeDialog.getInstance().setDialogResult(handler)
else -> super.onCreateDialogEx(tag, args)
}
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
}

override fun onBackPressed() {
startActivity(Intent(this, GreetActivity::class.java))
}

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

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

companion object {
private val handler = StaticHandler()
}
}
54 changes: 54 additions & 0 deletions app/src/main/java/com/deliner/mosfauna/activity/LoginActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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 LoginActivity : UserActivity() {

private lateinit var passwordText: EditText
private lateinit var loginText: EditText

private lateinit var loginButton: Button

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

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

loginButton = findViewById(R.id.activity_login_button_login)
passwordText = findViewById(R.id.activity_login_password)
loginText = findViewById(R.id.activity_login_login)

loginButton.setOnClickListener {
if (checkLogin(loginText.text.toString()) && checkPassword(passwordText.text.toString())) {
val user = LoginManager.User(
loginText.text.toString(),
passwordText.text.toString(),
"default@gmail.com"
)
LoginManager.getInstance(applicationContext).setCurrentUser(user)
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
startActivity(Intent(this, MainActivity::class.java))
}
}
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
}

override fun onBackPressed() {
startActivity(Intent(this, GreetActivity::class.java))
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.deliner.mosfauna
package com.deliner.mosfauna.activity

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.deliner.mosfauna.R
import com.deliner.mosfauna.utils.LoginManager

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



}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.deliner.mosfauna
package com.deliner.mosfauna.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.deliner.mosfauna.R

import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
Expand All @@ -17,25 +18,13 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_maps)
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
val mapFragment = supportFragmentManager
.findFragmentById(R.id.map) as SupportMapFragment
val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
mapFragment.getMapAsync(this)
}

/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap

// Add a marker in Sydney and move the camera
val sydney = LatLng(-34.0, 151.0)
mMap.addMarker(MarkerOptions().position(sydney).title("Marker in Sydney"))
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney))
Expand Down
Loading

0 comments on commit fd17563

Please sign in to comment.