This repository has been archived by the owner on Apr 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create Auth class to enclose authentication functions. * Create App class to get app context from object classes. * Create Accounts models. * Create SplashScreen to run while async tasks are running on startup. * Add sign out button to Main Activity. * Use Kotlin Coroutines to create async tasks. * Update and sort string resources. * Replace "Bus Id" with "Id". * Rename SharedPrefHelper to SharedPref. * Rename LogInActivity to SignInActivity.
- Loading branch information
Showing
21 changed files
with
357 additions
and
174 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
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,17 @@ | ||
package com.tazkrtak.staff | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
|
||
class App : Application() { | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
appContext = applicationContext | ||
} | ||
|
||
companion object { | ||
var appContext: Context? = null | ||
} | ||
|
||
} |
67 changes: 0 additions & 67 deletions
67
app/src/main/java/com/tazkrtak/staff/activities/LogInActivity.kt
This file was deleted.
Oops, something went wrong.
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
66 changes: 66 additions & 0 deletions
66
app/src/main/java/com/tazkrtak/staff/activities/SignInActivity.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,66 @@ | ||
package com.tazkrtak.staff.activities | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.tazkrtak.staff.R | ||
import com.tazkrtak.staff.util.Auth | ||
import kotlinx.android.synthetic.main.activity_sign_in.* | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.launch | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
class SignInActivity : AppCompatActivity(), CoroutineScope { | ||
|
||
override val coroutineContext: CoroutineContext | ||
get() = Dispatchers.Main + job | ||
|
||
private lateinit var job: Job | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
|
||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_sign_in) | ||
|
||
job = Job() | ||
|
||
sign_in_button.setOnClickListener { | ||
|
||
id_edit_text.error = null | ||
id_edit_text.error = null | ||
|
||
val id = id_edit_text.text.toString() | ||
val password = password_edit_text.text.toString() | ||
|
||
launch { | ||
try { | ||
Auth.signIn(id, password) | ||
launchMainActivity() | ||
} catch (e: Auth.AuthIdException) { | ||
id_edit_text.error = e.message | ||
} catch (e: Auth.AuthPasswordException) { | ||
password_edit_text.error = e.message | ||
} | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
override fun onDestroy() { | ||
job.cancel() | ||
super.onDestroy() | ||
} | ||
|
||
private fun launchMainActivity() { | ||
val mainActivityIntent = Intent(this, MainActivity::class.java) | ||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) | ||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
startActivity(mainActivityIntent) | ||
finish() | ||
} | ||
|
||
} | ||
|
49 changes: 49 additions & 0 deletions
49
app/src/main/java/com/tazkrtak/staff/activities/SplashScreenActivity.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,49 @@ | ||
package com.tazkrtak.staff.activities | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.tazkrtak.staff.R | ||
import com.tazkrtak.staff.util.Auth | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.launch | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
class SplashScreenActivity : AppCompatActivity(), CoroutineScope { | ||
|
||
override val coroutineContext: CoroutineContext | ||
get() = Dispatchers.Main + job | ||
|
||
private lateinit var job: Job | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
|
||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_splash_screen) | ||
job = Job() | ||
|
||
launch { | ||
if (Auth.isSignedIn()) { | ||
launchActivity(MainActivity::class.java) | ||
} else { | ||
launchActivity(SignInActivity::class.java) | ||
} | ||
} | ||
|
||
} | ||
|
||
override fun onDestroy() { | ||
job.cancel() | ||
super.onDestroy() | ||
} | ||
|
||
private fun launchActivity(cls: Class<out Any>) { | ||
val activityIntent = Intent(this, cls) | ||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) | ||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
startActivity(activityIntent) | ||
finish() | ||
} | ||
} |
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,21 @@ | ||
package com.tazkrtak.staff.models | ||
|
||
import androidx.core.text.isDigitsOnly | ||
|
||
|
||
interface Account { | ||
|
||
val id: String? | ||
val name: String? | ||
val password: String? | ||
val type: Type | ||
|
||
enum class Type { CONDUCTOR, COLLECTOR } | ||
|
||
companion object { | ||
fun typeOf(id: String): Type { | ||
return if (!id.isDigitsOnly()) Type.CONDUCTOR else Type.COLLECTOR | ||
} | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.tazkrtak.staff.models | ||
|
||
data class Collector( | ||
override val id: String? = null, | ||
override val name: String? = null, | ||
override val password: String? = null | ||
) : Account { | ||
override val type: Account.Type = Account.Type.COLLECTOR | ||
} |
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,10 @@ | ||
package com.tazkrtak.staff.models | ||
|
||
data class Conductor( | ||
override val id: String? = null, | ||
override val name: String? = null, | ||
override val password: String? = null, | ||
val bus: Bus? = null | ||
) : Account { | ||
override val type: Account.Type = Account.Type.CONDUCTOR | ||
} |
Oops, something went wrong.