[UI] Add secret features. (#73)

* Add easter egg

* Remove big file

* Reformat code

* Remove unneded blank lines, optimize some code

* Fix small issue

* Update easter egg logic

Co-authored-by: Kuba Szczodrzyński <kuba@szczodrzynski.pl>
This commit is contained in:
Antoni Czaplicki 2021-10-01 18:40:44 +02:00 committed by GitHub
parent 18c306b9ea
commit 959168771b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 93 additions and 12 deletions

View File

@ -1,23 +1,24 @@
package pl.szczodrzynski.edziennik.ui.modules.settings.contributors package pl.szczodrzynski.edziennik.ui.modules.settings.contributors
import android.os.Bundle import android.os.Bundle
import android.os.Process
import android.view.KeyEvent
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isInvisible
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.viewpager.widget.ViewPager import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.tabs.TabLayout
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.*
import pl.szczodrzynski.edziennik.Bundle
import pl.szczodrzynski.edziennik.R
import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi
import pl.szczodrzynski.edziennik.data.api.szkolny.response.ContributorsResponse import pl.szczodrzynski.edziennik.data.api.szkolny.response.ContributorsResponse
import pl.szczodrzynski.edziennik.databinding.ContributorsActivityBinding import pl.szczodrzynski.edziennik.databinding.ContributorsActivityBinding
import pl.szczodrzynski.edziennik.ui.modules.base.lazypager.FragmentLazyPagerAdapter import pl.szczodrzynski.edziennik.ui.modules.base.lazypager.FragmentLazyPagerAdapter
import pl.szczodrzynski.edziennik.ui.modules.error.ErrorSnackbar import pl.szczodrzynski.edziennik.ui.modules.error.ErrorSnackbar
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
import kotlin.system.exitProcess
class ContributorsActivity : AppCompatActivity(), CoroutineScope { class ContributorsActivity : AppCompatActivity(), CoroutineScope {
companion object { companion object {
@ -35,6 +36,28 @@ class ContributorsActivity : AppCompatActivity(), CoroutineScope {
// local/private variables go here // local/private variables go here
private val errorSnackbar: ErrorSnackbar by lazy { ErrorSnackbar(this) } private val errorSnackbar: ErrorSnackbar by lazy { ErrorSnackbar(this) }
private var konami = 0
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
when (keyCode) {
KeyEvent.KEYCODE_DPAD_UP -> konami in 0..1
KeyEvent.KEYCODE_DPAD_DOWN -> konami in 2..3
KeyEvent.KEYCODE_DPAD_LEFT -> konami in 4..6 step 2
KeyEvent.KEYCODE_DPAD_RIGHT -> konami in 5..7 step 2
KeyEvent.KEYCODE_B -> konami == 8
KeyEvent.KEYCODE_A -> konami == 9
else -> false
}.let {
if (!it) {
konami = 0
return super.onKeyUp(keyCode, event)
}
konami++
b.konami.isVisible = konami == 10
return true
}
}
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
app = application as App app = application as App
@ -45,6 +68,40 @@ class ContributorsActivity : AppCompatActivity(), CoroutineScope {
b.tabLayout.isVisible = false b.tabLayout.isVisible = false
b.viewPager.isVisible = false b.viewPager.isVisible = false
b.szkolny.onLongClick {
if (b.konami.isVisible) {
b.glove.isVisible = true
b.szkolny.isInvisible = true
}
true
}
b.glove.onClick {
MaterialAlertDialogBuilder(this)
.setTitle(R.string.are_you_sure)
.setMessage(R.string.dev_mode_enable_warning)
.setPositiveButton(R.string.yes) { _, _ ->
app.config.devMode = true
App.devMode = true
MaterialAlertDialogBuilder(this)
.setTitle("Restart")
.setMessage("Wymagany restart aplikacji")
.setPositiveButton(R.string.ok) { _, _ ->
Process.killProcess(Process.myPid())
Runtime.getRuntime().exit(0)
exitProcess(0)
}
.setCancelable(false)
.show()
}
.setNegativeButton(R.string.no) { _, _ ->
app.config.devMode = false
App.devMode = false
this.finish()
}
.show()
}
launch { launch {
contributors = contributors ?: SzkolnyApi(app).runCatching(errorSnackbar) { contributors = contributors ?: SzkolnyApi(app).runCatching(errorSnackbar) {
getContributors() getContributors()

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -20,6 +20,14 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true"> android:fitsSystemWindows="true">
<ImageView
android:id="@+id/konami"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_gravity="bottom|end"
android:visibility="gone"
app:srcCompat="@drawable/emoji_glasses" />
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -39,15 +47,31 @@
app:layout_collapseMode="parallax" app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7"> app:layout_collapseParallaxMultiplier="0.7">
<ImageView <FrameLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:layout_gravity="center"
android:layout_marginTop="16dp" android:layout_marginTop="16dp">
android:scaleType="center"
android:scaleX="0.8" <ImageView
android:scaleY="0.8" android:id="@+id/szkolny"
android:src="@mipmap/ic_splash" /> android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="center"
android:scaleX="0.8"
android:scaleY="0.8"
android:src="@mipmap/ic_splash" />
<ImageView
android:id="@+id/glove"
android:layout_width="144dp"
android:layout_height="144dp"
android:layout_gravity="center"
android:paddingBottom="4dp"
android:visibility="gone"
app:srcCompat="@drawable/thanos_idle" />
</FrameLayout>
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"