-
Notifications
You must be signed in to change notification settings - Fork 994
/
HelpActivity.kt
97 lines (81 loc) · 2.92 KB
/
HelpActivity.kt
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
97
package com.kickstarter.ui.activities
import android.net.Uri
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.annotation.IntDef
import com.kickstarter.databinding.HelpLayoutBinding
import com.kickstarter.libs.Environment
import com.kickstarter.libs.qualifiers.WebEndpoint
import com.kickstarter.libs.utils.extensions.getEnvironment
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
open class HelpActivity : ComponentActivity() {
@IntDef(HELP_TYPE_TERMS, HELP_TYPE_PRIVACY, HELP_TYPE_HOW_IT_WORKS, HELP_TYPE_COOKIE_POLICY, HELP_TYPE_ACCESSIBILITY)
@Retention(RetentionPolicy.SOURCE)
annotation class HelpType
@HelpType
private var helpType = 0
@WebEndpoint
private var webEndpoint: String? = null
private var environment: Environment? = null
protected fun helpType(@HelpType helpType: Int) {
this.helpType = helpType
}
class Terms : HelpActivity() {
init {
helpType(HELP_TYPE_TERMS)
}
}
class Privacy : HelpActivity() {
init {
helpType(HELP_TYPE_PRIVACY)
}
}
class CookiePolicy : HelpActivity() {
init {
helpType(HELP_TYPE_COOKIE_POLICY)
}
}
class AccessibilityStatement : HelpActivity() {
init {
helpType(HELP_TYPE_ACCESSIBILITY)
}
}
private lateinit var binding: HelpLayoutBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
environment = this.getEnvironment()
webEndpoint = environment?.webEndpoint()
binding = HelpLayoutBinding.inflate(layoutInflater)
setContentView(binding.root)
val url = getUrlForHelpType(helpType)
url?.let { binding.kickstarterWebView.loadUrl(it) }
}
private fun getUrlForHelpType(@HelpType helpType: Int): String? {
webEndpoint?.let {
val builder = Uri.parse(it).buildUpon()
when (helpType) {
HELP_TYPE_TERMS -> builder.appendEncodedPath(TERMS_OF_USE)
HELP_TYPE_PRIVACY -> builder.appendEncodedPath(PRIVACY)
HELP_TYPE_HOW_IT_WORKS -> builder.appendEncodedPath(HELLO)
HELP_TYPE_COOKIE_POLICY -> builder.appendEncodedPath(COOKIES)
HELP_TYPE_ACCESSIBILITY -> builder.appendEncodedPath(ACCESSIBILITY)
}
return builder.toString()
} ?: run {
return null
}
}
companion object {
const val HELP_TYPE_TERMS = 0
const val HELP_TYPE_PRIVACY = 1
const val HELP_TYPE_HOW_IT_WORKS = 2
const val HELP_TYPE_COOKIE_POLICY = 3
const val HELP_TYPE_ACCESSIBILITY = 4
const val TERMS_OF_USE = "terms-of-use"
const val PRIVACY = "privacy"
const val HELLO = "hello"
const val COOKIES = "cookies"
const val ACCESSIBILITY = "accessibility"
}
}