-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathLaunchActivity.kt
More file actions
96 lines (85 loc) · 2.95 KB
/
LaunchActivity.kt
File metadata and controls
96 lines (85 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.commit451.gitlab.activity
import android.annotation.TargetApi
import android.app.Activity
import android.app.KeyguardManager
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.ViewGroup
import android.widget.Toast
import butterknife.BindView
import butterknife.ButterKnife
import com.commit451.gitlab.App
import com.commit451.gitlab.R
import com.commit451.gitlab.data.Prefs
import com.commit451.gitlab.extension.with
import com.commit451.gitlab.migration.Migration261
import com.commit451.gitlab.navigation.Navigator
import timber.log.Timber
/**
* This activity acts as switching platform for the application directing the user to the appropriate
* activity based on their logged in state
*/
class LaunchActivity : BaseActivity() {
companion object {
private const val REQUEST_DEVICE_AUTH = 123
}
@BindView(R.id.root)
lateinit var root: ViewGroup
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_launch)
ButterKnife.bind(this)
figureOutWhatToDo()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
REQUEST_DEVICE_AUTH -> if (resultCode == Activity.RESULT_OK) {
App.authenticated = true
moveAlong()
} else {
finish()
}
}
}
private fun figureOutWhatToDo() {
val accounts = Prefs.getAccounts()
if (accounts.isEmpty()) {
Navigator.navigateToLogin(this)
finish()
} else if (Prefs.isRequiredDeviceAuth) {
showKeyguard()
} else {
moveAlong()
}
}
@TargetApi(21)
private fun showKeyguard() {
val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
val intent = keyguardManager.createConfirmDeviceCredentialIntent(getString(R.string.device_auth_title), getString(R.string.device_auth_message))
if (intent == null) {
moveAlong()
} else {
startActivityForResult(intent, REQUEST_DEVICE_AUTH)
}
}
private fun moveAlong() {
if (account.username == null || account.email == null) {
Migration261.run()
.with(this)
.subscribe({
Navigator.navigateToStartingActivity(this)
finish()
}, {
Timber.e(it)
Toast.makeText(this, "Unable to migrate. Unfortunately, you probably need to re-install the app", Toast.LENGTH_LONG)
.show()
finish()
})
} else {
Navigator.navigateToStartingActivity(this)
finish()
}
}
}