diff options
Diffstat (limited to 'sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt')
-rw-r--r-- | sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt | 622 |
1 files changed, 549 insertions, 73 deletions
diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt index 4fe941b..e6841c8 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt @@ -40,7 +40,10 @@ import ca.allanwang.kau.utils.withSceneTransitionAnimation import ca.allanwang.kau.xml.showChangelog import com.afollestad.materialdialogs.input.input import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial +import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject +@AndroidEntryPoint class MainActivity : KPrefActivity() { var searchView: SearchView? = null @@ -50,60 +53,518 @@ class MainActivity : KPrefActivity() { // some of the most common english words for show val wordBank: List<String> by lazy { listOf( - "the", "name", "of", "very", "to", "through", - "and", "just", "a", "form", "in", "much", "is", "great", "it", "think", "you", "say", - "that", "help", "he", "low", "was", "line", "for", "before", "on", "turn", "are", "cause", - "with", "same", "as", "mean", "I", "differ", "his", "move", "they", "right", "be", "boy", - "at", "old", "one", "too", "have", "does", "this", "tell", "from", "sentence", "or", "set", - "had", "three", "by", "want", "hot", "air", "but", "well", "some", "also", "what", "play", - "there", "small", "we", "end", "can", "put", "out", "home", "other", "read", "were", "hand", - "all", "port", "your", "large", "when", "spell", "up", "add", "use", "even", "word", "land", - "how", "here", "said", "must", "an", "big", "each", "high", "she", "such", "which", "follow", - "do", "act", "their", "why", "time", "ask", "if", "men", "will", "change", "way", "went", - "about", "light", "many", "kind", "then", "off", "them", "need", "would", "house", "write", - "picture", "like", "try", "so", "us", "these", "again", "her", "animal", "long", "point", - "make", "mother", "thing", "world", "see", "near", "him", "build", "two", "self", "has", - "earth", "look", "father", "more", "head", "day", "stand", "could", "own", "go", "page", - "come", "should", "did", "country", "my", "found", "sound", "answer", "no", "school", "most", - "grow", "number", "study", "who", "still", "over", "learn", "know", "plant", "water", "cover", - "than", "food", "call", "sun", "first", "four", "people", "thought", "may", "let", "down", "keep", - "side", "eye", "been", "never", "now", "last", "find", "door", "any", "between", "new", "city", - "work", "tree", "part", "cross", "take", "since", "get", "hard", "place", "start", "made", - "might", "live", "story", "where", "saw", "after", "far", "back", "sea", "little", "draw", - "only", "left", "round", "late", "man", "run", "year", "don't", "came", "while", "show", - "press", "every", "close", "good", "night", "me", "real", "give", "life", "our", "few", "under", - "stopRankWordRankWord", "open", "ten", "seem", "simple", "together", "several", "next", - "vowel", "white", "toward", "children", "war", "begin", "lay", "got", "against", "walk", "pattern", - "example", "slow", "ease", "center", "paper", "love", "often", "person", "always", "money", - "music", "serve", "those", "appear", "both", "road", "mark", "map", "book", "science", "letter", - "rule", "until", "govern", "mile", "pull", "river", "cold", "car", "notice", "feet", "voice", - "care", "fall", "second", "power", "group", "town", "carry", "fine", "took", "certain", "rain", - "fly", "eat", "unit", "room", "lead", "friend", "cry", "began", "dark", "idea", "machine", - "fish", "note", "mountain", "wait", "north", "plan", "once", "figure", "base", "star", "hear", - "box", "horse", "noun", "cut", "field", "sure", "rest", "watch", "correct", "color", "able", - "face", "pound", "wood", "done", "main", "beauty", "enough", "drive", "plain", "stood", "girl", - "contain", "usual", "front", "young", "teach", "ready", "week", "above", "final", "ever", "gave", - "red", "green", "list", "oh", "though", "quick", "feel", "develop", "talk", "sleep", "bird", - "warm", "soon", "free", "body", "minute", "dog", "strong", "family", "special", "direct", "mind", - "pose", "behind", "leave", "clear", "song", "tail", "measure", "produce", "state", "fact", "product", - "street", "black", "inch", "short", "lot", "numeral", "nothing", "class", "course", "wind", "stay", - "question", "wheel", "happen", "full", "complete", "force", "ship", "blue", "area", "object", "half", - "decide", "rock", "surface", "order", "deep", "fire", "moon", "south", "island", "problem", "foot", - "piece", "yet", "told", "busy", "knew", "test", "pass", "record", "farm", "boat", "top", "common", - "whole", "gold", "king", "possible", "size", "plane", "heard", "age", "best", "dry", "hour", "wonder", - "better", "laugh", "true.", "thousand", "during", "ago", "hundred", "ran", "am", "check", "remember", - "game", "step", "shape", "early", "yes", "hold", "hot", "west", "miss", "ground", "brought", "interest", - "heat", "reach", "snow", "fast", "bed", "five", "bring", "sing", "sit", "listen", "perhaps", "six", - "fill", "table", "east", "travel", "weight", "less", "language", "morning", "among" + "the", + "name", + "of", + "very", + "to", + "through", + "and", + "just", + "a", + "form", + "in", + "much", + "is", + "great", + "it", + "think", + "you", + "say", + "that", + "help", + "he", + "low", + "was", + "line", + "for", + "before", + "on", + "turn", + "are", + "cause", + "with", + "same", + "as", + "mean", + "I", + "differ", + "his", + "move", + "they", + "right", + "be", + "boy", + "at", + "old", + "one", + "too", + "have", + "does", + "this", + "tell", + "from", + "sentence", + "or", + "set", + "had", + "three", + "by", + "want", + "hot", + "air", + "but", + "well", + "some", + "also", + "what", + "play", + "there", + "small", + "we", + "end", + "can", + "put", + "out", + "home", + "other", + "read", + "were", + "hand", + "all", + "port", + "your", + "large", + "when", + "spell", + "up", + "add", + "use", + "even", + "word", + "land", + "how", + "here", + "said", + "must", + "an", + "big", + "each", + "high", + "she", + "such", + "which", + "follow", + "do", + "act", + "their", + "why", + "time", + "ask", + "if", + "men", + "will", + "change", + "way", + "went", + "about", + "light", + "many", + "kind", + "then", + "off", + "them", + "need", + "would", + "house", + "write", + "picture", + "like", + "try", + "so", + "us", + "these", + "again", + "her", + "animal", + "long", + "point", + "make", + "mother", + "thing", + "world", + "see", + "near", + "him", + "build", + "two", + "self", + "has", + "earth", + "look", + "father", + "more", + "head", + "day", + "stand", + "could", + "own", + "go", + "page", + "come", + "should", + "did", + "country", + "my", + "found", + "sound", + "answer", + "no", + "school", + "most", + "grow", + "number", + "study", + "who", + "still", + "over", + "learn", + "know", + "plant", + "water", + "cover", + "than", + "food", + "call", + "sun", + "first", + "four", + "people", + "thought", + "may", + "let", + "down", + "keep", + "side", + "eye", + "been", + "never", + "now", + "last", + "find", + "door", + "any", + "between", + "new", + "city", + "work", + "tree", + "part", + "cross", + "take", + "since", + "get", + "hard", + "place", + "start", + "made", + "might", + "live", + "story", + "where", + "saw", + "after", + "far", + "back", + "sea", + "little", + "draw", + "only", + "left", + "round", + "late", + "man", + "run", + "year", + "don't", + "came", + "while", + "show", + "press", + "every", + "close", + "good", + "night", + "me", + "real", + "give", + "life", + "our", + "few", + "under", + "stopRankWordRankWord", + "open", + "ten", + "seem", + "simple", + "together", + "several", + "next", + "vowel", + "white", + "toward", + "children", + "war", + "begin", + "lay", + "got", + "against", + "walk", + "pattern", + "example", + "slow", + "ease", + "center", + "paper", + "love", + "often", + "person", + "always", + "money", + "music", + "serve", + "those", + "appear", + "both", + "road", + "mark", + "map", + "book", + "science", + "letter", + "rule", + "until", + "govern", + "mile", + "pull", + "river", + "cold", + "car", + "notice", + "feet", + "voice", + "care", + "fall", + "second", + "power", + "group", + "town", + "carry", + "fine", + "took", + "certain", + "rain", + "fly", + "eat", + "unit", + "room", + "lead", + "friend", + "cry", + "began", + "dark", + "idea", + "machine", + "fish", + "note", + "mountain", + "wait", + "north", + "plan", + "once", + "figure", + "base", + "star", + "hear", + "box", + "horse", + "noun", + "cut", + "field", + "sure", + "rest", + "watch", + "correct", + "color", + "able", + "face", + "pound", + "wood", + "done", + "main", + "beauty", + "enough", + "drive", + "plain", + "stood", + "girl", + "contain", + "usual", + "front", + "young", + "teach", + "ready", + "week", + "above", + "final", + "ever", + "gave", + "red", + "green", + "list", + "oh", + "though", + "quick", + "feel", + "develop", + "talk", + "sleep", + "bird", + "warm", + "soon", + "free", + "body", + "minute", + "dog", + "strong", + "family", + "special", + "direct", + "mind", + "pose", + "behind", + "leave", + "clear", + "song", + "tail", + "measure", + "produce", + "state", + "fact", + "product", + "street", + "black", + "inch", + "short", + "lot", + "numeral", + "nothing", + "class", + "course", + "wind", + "stay", + "question", + "wheel", + "happen", + "full", + "complete", + "force", + "ship", + "blue", + "area", + "object", + "half", + "decide", + "rock", + "surface", + "order", + "deep", + "fire", + "moon", + "south", + "island", + "problem", + "foot", + "piece", + "yet", + "told", + "busy", + "knew", + "test", + "pass", + "record", + "farm", + "boat", + "top", + "common", + "whole", + "gold", + "king", + "possible", + "size", + "plane", + "heard", + "age", + "best", + "dry", + "hour", + "wonder", + "better", + "laugh", + "true.", + "thousand", + "during", + "ago", + "hundred", + "ran", + "am", + "check", + "remember", + "game", + "step", + "shape", + "early", + "yes", + "hold", + "hot", + "west", + "miss", + "ground", + "brought", + "interest", + "heat", + "reach", + "snow", + "fast", + "bed", + "five", + "bring", + "sing", + "sit", + "listen", + "perhaps", + "six", + "fill", + "table", + "east", + "travel", + "weight", + "less", + "language", + "morning", + "among" ) } const val REQUEST_MEDIA = 27 } + @Inject + lateinit var pref: KPrefSample + override fun kPrefCoreAttributes(): CoreAttributeContract.() -> Unit = { - textColor = KPrefSample::textColor - accentColor = KPrefSample::accentColor + textColor = pref::textColor + accentColor = pref::accentColor } override fun onCreateKPrefs(savedInstanceState: Bundle?): KPrefAdapterBuilder.() -> Unit = { @@ -113,7 +574,7 @@ class MainActivity : KPrefActivity() { /** * This is how the setup looks like with all the proper tags */ - checkbox(title = R.string.checkbox_1, getter = KPrefSample::check1, setter = { KPrefSample.check1 = it }, + checkbox(title = R.string.checkbox_1, getter = pref::check1, setter = { pref.check1 = it }, builder = { descRes = R.string.desc }) @@ -123,25 +584,25 @@ class MainActivity : KPrefActivity() { */ checkbox( R.string.checkbox_2, - KPrefSample::check2, - { KPrefSample.check2 = it; reloadByTitle(R.string.checkbox_3) }) + pref::check2, + { pref.check2 = it; reloadByTitle(R.string.checkbox_3) }) /** * Since the builder is the last argument and is a lambda, we may write the setup cleanly like so: */ - checkbox(R.string.checkbox_3, KPrefSample::check3, { KPrefSample.check3 = it }) { + checkbox(R.string.checkbox_3, pref::check3, { pref.check3 = it }) { descRes = R.string.desc_dependent - enabler = { KPrefSample.check2 } + enabler = { pref.check2 } onDisabledClick = { itemView.context.toast("I am still disabled") } } - colorPicker(R.string.text_color, KPrefSample::textColor, { KPrefSample.textColor = it; reload() }) { + colorPicker(R.string.text_color, pref::textColor, { pref.textColor = it; reload() }) { descRes = R.string.color_custom allowCustom = true } - colorPicker(R.string.accent_color, KPrefSample::accentColor, { - KPrefSample.accentColor = it + colorPicker(R.string.accent_color, pref::accentColor, { + pref.accentColor = it reload() this@MainActivity.navigationBarColor = it toolbarCanvas.ripple(it, RippleCanvas.MIDDLE, RippleCanvas.END, duration = 500L) @@ -150,8 +611,8 @@ class MainActivity : KPrefActivity() { allowCustom = false } - colorPicker(R.string.background_color, KPrefSample::bgColor, { - KPrefSample.bgColor = it; bgCanvas.ripple(it, duration = 500L) + colorPicker(R.string.background_color, pref::bgColor, { + pref.bgColor = it; bgCanvas.ripple(it, duration = 500L) }) { iicon = GoogleMaterial.Icon.gmd_colorize descRes = R.string.color_custom_alpha @@ -159,19 +620,24 @@ class MainActivity : KPrefActivity() { allowCustom = true } - text(R.string.text, KPrefSample::text, { KPrefSample.text = it }) { + text(R.string.text, pref::text, { pref.text = it }) { descRes = R.string.text_desc onClick = { itemView.context.materialDialog { title(text = "Type Text") - input("Type here", prefill = item.pref, maxLength = 20, allowEmpty = true) { _, input -> + input( + "Type here", + prefill = item.pref, + maxLength = 20, + allowEmpty = true + ) { _, input -> item.pref = input.toString() } } } } - seekbar(R.string.seekbar, KPrefSample::seekbar, { KPrefSample.seekbar = it }) { + seekbar(R.string.seekbar, pref::seekbar, { pref.seekbar = it }) { descRes = R.string.kau_lorem_ipsum increments = 5 textViewConfigs = { @@ -215,35 +681,40 @@ class MainActivity : KPrefActivity() { */ checkbox( R.string.checkbox_2, - KPrefSample::check2, - { KPrefSample.check2 = it; reloadByTitle(R.string.checkbox_3) }) { + pref::check2, + { pref.check2 = it; reloadByTitle(R.string.checkbox_3) }) { titleFun = { R.string.checkbox_3 } descRes = R.string.kau_lorem_ipsum } - text(R.string.text, KPrefSample::text, { KPrefSample.text = it }) { + text(R.string.text, pref::text, { pref.text = it }) { descRes = R.string.kau_lorem_ipsum textGetter = { string(R.string.kau_lorem_ipsum) } } - timePicker(R.string.time, KPrefSample::time12, { KPrefSample.time12 = it }) { + timePicker(R.string.time, pref::time12, { pref.time12 = it }) { descRes = R.string.time_desc_12 use24HourFormat = false } - timePicker(R.string.time, KPrefSample::time24, { KPrefSample.time24 = it }) { + timePicker(R.string.time, pref::time24, { pref.time24 = it }) { descRes = R.string.time_desc_24 use24HourFormat = true } } fun subPrefs(): KPrefAdapterBuilder.() -> Unit = { - text(R.string.text, { KPrefSample.text }, { KPrefSample.text = it }) { + text(R.string.text, { pref.text }, { pref.text = it }) { descRes = R.string.text_desc onClick = { itemView.context.materialDialog { title(text = "Type Text") - input("Type here", prefill = item.pref, maxLength = 20, allowEmpty = true) { _, input -> + input( + "Type here", + prefill = item.pref, + maxLength = 20, + allowEmpty = true + ) { _, input -> item.pref = input.toString() reloadSelf() } @@ -254,11 +725,11 @@ class MainActivity : KPrefActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - bgCanvas.set(KPrefSample.bgColor) - toolbarCanvas.set(KPrefSample.accentColor) - this.navigationBarColor = KPrefSample.accentColor - if (KPrefSample.version < BuildConfig.VERSION_CODE) { - KPrefSample.version = BuildConfig.VERSION_CODE + bgCanvas.set(pref.bgColor) + toolbarCanvas.set(pref.accentColor) + this.navigationBarColor = pref.accentColor + if (pref.version < BuildConfig.VERSION_CODE) { + pref.version = BuildConfig.VERSION_CODE if (!BuildConfig.DEBUG) showChangelog(R.xml.kau_changelog) } @@ -308,7 +779,12 @@ class MainActivity : KPrefActivity() { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) when (requestCode) { - REQUEST_MEDIA -> toast("${kauOnMediaPickerResult(resultCode, data).size} items selected") + REQUEST_MEDIA -> toast( + "${kauOnMediaPickerResult( + resultCode, + data + ).size} items selected" + ) } } } |