Skip to content
This repository has been archived by the owner on Jun 6, 2021. It is now read-only.

Commit

Permalink
feat: 히히
Browse files Browse the repository at this point in the history
  • Loading branch information
potados99 committed Jan 12, 2021
1 parent 74e98d2 commit 193fee9
Show file tree
Hide file tree
Showing 13 changed files with 195 additions and 42 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/potados.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 40 additions & 10 deletions app/src/main/java/com/inu/cafeteria/common/navigation/Navigator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
package com.inu.cafeteria.common.navigation

import android.annotation.SuppressLint
import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
import android.os.Handler
import android.view.animation.AnimationUtils
import android.widget.*
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.FragmentActivity
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.inu.cafeteria.R
import com.inu.cafeteria.common.extension.hideKeyboard
Expand All @@ -42,6 +41,7 @@ import com.inu.cafeteria.feature.login.LoginActivity
import com.inu.cafeteria.feature.main.MainActivity
import com.inu.cafeteria.feature.order.AddOrderActivity
import com.inu.cafeteria.feature.reorder.CafeteriaReorderActivity
import com.plattysoft.leonids.ParticleSystem
import org.koin.core.KoinComponent
import timber.log.Timber

Expand Down Expand Up @@ -82,7 +82,7 @@ class Navigator(
}

@SuppressLint("InflateParams")
fun showNotice(activity: FragmentActivity, notice: Notice, onDismiss: () -> Unit) {
fun showNotice(activity: Activity, notice: Notice, onDismiss: () -> Unit) {
val dialog = BottomSheetDialog(activity)
val noticeView = activity.layoutInflater.inflate(R.layout.notice_view, null).apply {
withNonNull(findViewById<TextView>(R.id.title)) {
Expand All @@ -105,7 +105,7 @@ class Navigator(
dialog.show()
}

fun showUpdate(activity: FragmentActivity) {
fun showUpdate(activity: Activity) {
AlertDialog
.Builder(activity)
.setTitle(context.getString(R.string.wait))
Expand All @@ -117,7 +117,7 @@ class Navigator(
.show()
}

fun showOrderFinishedNotification(activity: FragmentActivity, title: String, body: String, onDismiss: () -> Unit = {}) {
fun showOrderFinishedNotification(activity: Activity, title: String, body: String, onDismiss: () -> Unit = {}) {
AlertDialog
.Builder(activity)
.setTitle(title)
Expand All @@ -133,7 +133,7 @@ class Navigator(
)
}

fun showDialog(activity: FragmentActivity, title: String, body: String, onDismiss: () -> Unit = {}) {
fun showDialog(activity: Activity, title: String, body: String, onDismiss: () -> Unit = {}) {
AlertDialog
.Builder(activity)
.setTitle(title)
Expand All @@ -152,7 +152,7 @@ class Navigator(
}

@SuppressLint("RestrictedApi")
fun showBetaTestFeedbackDialog(activity: FragmentActivity, sendFeedback: (String) -> Unit) {
fun showBetaTestFeedbackDialog(activity: Activity, sendFeedback: (String) -> Unit) {
val textInput = EditText(activity).apply {
hint = "관심 가져주셔서 감사합니다 :)"
}
Expand All @@ -175,6 +175,36 @@ class Navigator(
textInput.requestFocusWithKeyboard()
}

@SuppressLint("RestrictedApi")
fun showPotadosDialog(activity: Activity) {
val potadosImageView = ImageView(activity).apply {
setPadding(50, 50, 50, 50)
setImageResource(R.drawable.potato)
setOnClickListener {
startAnimation(AnimationUtils.loadAnimation(context, R.anim.shake_once).apply {
duration = 200
})
}
}

AlertDialog.Builder(activity)
.setTitle("감자 좋아하세요?")
.setMessage("좋은 하루 보내세요 :)\n\nINU 카페테리아\n© potados99")
.setView(potadosImageView, 60, 0, 60, 0)
.setPositiveButton("닫기") { _, _ -> }
.show()

ParticleSystem(activity, 100, R.drawable.dot, 3000)
.setSpeedRange(0.2f, 0.7f)
.oneShot(potadosImageView, 100)

Handler().postDelayed({
potadosImageView.startAnimation(AnimationUtils.loadAnimation(context, R.anim.shake_once).apply {
duration = 200
})
}, 800)
}

fun safeStartActivity(intent: Intent) {
try {
startActivity(intent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.inu.cafeteria.entities.Account
import com.inu.cafeteria.entities.OnboardingHint
import com.inu.cafeteria.exception.NoAccountException
import com.inu.cafeteria.exception.UnauthorizedException
import com.inu.cafeteria.feature.main.EasterEggHelper
import com.inu.cafeteria.service.AccountService
import com.inu.cafeteria.usecase.*
import com.inu.cafeteria.util.SingleLiveEvent
Expand All @@ -48,6 +49,8 @@ class DiscountViewModel : BaseViewModel() {

private val navigator: Navigator by inject()

private val eggs = EasterEggHelper.getBarcodeCardEasterEggs()

private val _barcodeCardReady = MutableLiveData(false)
val barcodeCardReady: LiveData<Boolean> = _barcodeCardReady

Expand Down Expand Up @@ -122,10 +125,19 @@ class DiscountViewModel : BaseViewModel() {
navigator.showLogin()
}

fun onToggleBrightness() {
fun onClickBarcodeCard() {
toggleBrightness()
giveSomeEggs()
}

private fun toggleBrightness() {
_bright.value = !(_bright.value ?: false)
}

private fun giveSomeEggs() {
eggs.haveSomeFun()
}

private fun showBarcode() {
getSavedAccount(Unit) {
it.onSuccess(::showBarcodeForAccount).onError(::handleFailure)
Expand Down Expand Up @@ -195,6 +207,5 @@ class DiscountViewModel : BaseViewModel() {
showDiscountServiceDescriptionEvent.value = Pair(title, body)
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import androidx.lifecycle.MutableLiveData
import com.inu.cafeteria.R
import com.inu.cafeteria.common.base.BaseViewModel
import com.inu.cafeteria.common.extension.onChanged
import com.inu.cafeteria.common.firebase.Events
import com.inu.cafeteria.common.navigation.Navigator
import com.inu.cafeteria.service.AccountService
import com.inu.cafeteria.usecase.Login
import com.inu.cafeteria.util.Events
import org.koin.core.inject
import timber.log.Timber

Expand Down
77 changes: 54 additions & 23 deletions app/src/main/java/com/inu/cafeteria/feature/main/EasterEggHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,62 @@ import android.app.Activity
import android.widget.Toast
import androidx.cardview.widget.CardView
import com.inu.cafeteria.R
import com.inu.cafeteria.common.navigation.Navigator
import com.inu.cafeteria.util.ActivityHelper
import com.inu.cafeteria.util.Events
import com.inu.cafeteria.util.Fun
import com.plattysoft.leonids.ParticleSystem
import org.koin.core.KoinComponent
import org.koin.core.inject

class EasterEggHelper {

companion object {

fun getEasterEggs(activity: Activity) = Fun(
listOf(
Fun.Event(9) {
ParticleSystem(activity, 50, R.drawable.dot, 3000)
.setSpeedRange(0.2f, 0.7f)
.oneShot(activity.findViewById<CardView>(R.id.offline_view), 50)
},
Fun.Event(17) {
Toast.makeText(activity, activity.getString(R.string.egg_help), Toast.LENGTH_SHORT).show()
},
Fun.Event(22) {
Toast.makeText(activity, activity.getString(R.string.egg_upup), Toast.LENGTH_SHORT).show()
},
Fun.Event(99) {
Toast.makeText(activity, activity.getString(R.string.egg_gmg), Toast.LENGTH_SHORT).show()
Toast.makeText(activity, activity.getString(R.string.heart), Toast.LENGTH_SHORT).show()
}
)
object EasterEggHelper : KoinComponent {

fun getOfflineViewEasterEggs(activity: Activity) = Fun(
listOf(
Fun.Event(9) {
ParticleSystem(activity, 50, R.drawable.dot, 3000)
.setSpeedRange(0.2f, 0.7f)
.oneShot(activity.findViewById<CardView>(R.id.offline_view), 50)

Events.onUserDiscoveredEasterEgg("폭죽 발견")
},
Fun.Event(17) {
Toast.makeText(activity, activity.getString(R.string.egg_help), Toast.LENGTH_SHORT).show()

Events.onUserDiscoveredEasterEgg("오프라인 뷰 연타 1")
},
Fun.Event(22) {
Toast.makeText(activity, activity.getString(R.string.egg_upup), Toast.LENGTH_SHORT).show()

Events.onUserDiscoveredEasterEgg("오프라인 뷰 연타 2")
},
Fun.Event(99) {
Toast.makeText(activity, activity.getString(R.string.egg_gmg), Toast.LENGTH_SHORT).show()
Toast.makeText(activity, activity.getString(R.string.heart), Toast.LENGTH_SHORT).show()

Events.onUserDiscoveredEasterEgg("오프라인 뷰 연타 3")
}
)
)

fun getBarcodeCardEasterEggs() = Fun(
listOf(
Fun.Event(5) {
val activity = ActivityHelper.getActivity() ?: return@Event

Toast.makeText(activity, activity.getString(R.string.egg_lightning), Toast.LENGTH_SHORT).show()

Events.onUserDiscoveredEasterEgg("바코드 연타")
},

Fun.Event(10) {
val activity = ActivityHelper.getActivity() ?: return@Event
val navigator: Navigator by inject()

navigator.showPotadosDialog(activity)

Events.onUserDiscoveredEasterEgg("감자 팝업 발견")
}
)
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ import com.inu.cafeteria.common.base.NavigationHostFragment
import com.inu.cafeteria.common.extension.fadeIn
import com.inu.cafeteria.common.extension.fadeOut
import com.inu.cafeteria.common.extension.observe
import com.inu.cafeteria.common.firebase.Events
import com.inu.cafeteria.config.Config
import com.inu.cafeteria.extension.withNonNull
import com.inu.cafeteria.feature.main.EasterEggHelper.Companion.getEasterEggs
import com.inu.cafeteria.util.Events
import org.koin.core.inject
import timber.log.Timber
import java.util.*
Expand Down Expand Up @@ -131,7 +130,7 @@ class MainActivity : NavigationActivity() {
}

private fun setOfflineView() {
val eggs = getEasterEggs(this)
val eggs = EasterEggHelper.getOfflineViewEasterEggs(this)

withNonNull(findViewById<CardView>(R.id.offline_view)) {
val animation = AnimationUtils
Expand Down
Binary file modified app/src/main/res/drawable-hdpi/potato.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/src/main/res/layout/barcode_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
android:id="@+id/student_info_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="@{() -> vm.onToggleBrightness()}"
android:onClick="@{() -> vm.onClickBarcodeCard()}"
android:background="?android:attr/selectableItemBackground">

<!-- UICOOP logo -->
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,6 @@
<string name="title_discount_service_description">학생 할인 혜택 안내</string>
<string name="description_discount_service">%s에서 이용하실 수 있습니다. 할인 제공 여부와 시점은 식당 사정에 따라 달라질 수 있습니다.</string>
<string name="desc_announcement">안내입니다</string>
<string name="egg_lightning">번쩍번쩍!</string>

</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values/id.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
-->

<resources>
<item name="tooltip" type="id"/>
<item name="tooltip" type="id" />
<item name="potados" type="id" />
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,6 @@
<string name="title_discount_service_description">Discount for students</string>
<string name="description_discount_service">Discount supported on %s.</string>
<string name="desc_announcement">This is an announcement</string>
<string name="egg_lightning">Buzzzzzzz!</string>

</resources>
53 changes: 53 additions & 0 deletions common/src/main/java/com/inu/cafeteria/util/ActivityHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* This file is part of INU Cafeteria.
*
* Copyright (C) 2020 INU Global App Center <[email protected]>
*
* INU Cafeteria is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* INU Cafeteria is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.inu.cafeteria.util

import android.annotation.SuppressLint
import android.app.Activity
import java.lang.reflect.Field

object ActivityHelper {

/**
* For non-critical use!
*/
@SuppressLint("PrivateApi")
fun getActivity(): Activity? {
val activityThreadClass = Class.forName("android.app.ActivityThread")
val activityThread = activityThreadClass.getMethod("currentActivityThread").invoke(null)
val activitiesField: Field = activityThreadClass.getDeclaredField("mActivities")
activitiesField.isAccessible = true

val activities = activitiesField.get(activityThread) as? Map<*, *> ?: return null

for (activityRecord in activities.values) {
val activityRecordClass: Class<*> = activityRecord?.javaClass ?: continue
val pausedField: Field = activityRecordClass.getDeclaredField("paused")
pausedField.isAccessible = true
if (!pausedField.getBoolean(activityRecord)) {
val activityField: Field = activityRecordClass.getDeclaredField("activity")
activityField.isAccessible = true
return activityField.get(activityRecord) as Activity
}
}

return null
}
}
Loading

0 comments on commit 193fee9

Please sign in to comment.