phatak-dev / quiz-macroid Goto Github PK
View Code? Open in Web Editor NEWAndroid Quiz app written in macroid https://github.com/macroid/macroid
License: Apache License 2.0
Android Quiz app written in macroid https://github.com/macroid/macroid
License: Apache License 2.0
scala> None == None
res0: Boolean = true
Hi,
I suggest you to further improve the readability of the code for it to be used as a sample project :)
For example, this is almost impossible to parse quickly:
val answerView = l[LinearLayout](
w[Button] <~ text("Prev")
<~ wrapContent <~ On.click {
currentIndex = if (currentIndex > 0) currentIndex - 1
else
questions.length - 1
questionView <~ text(questions(currentIndex).question)
} <~ wire(prev),
w[Button] <~ text("Next") <~ wire(next)
<~ wrapContent <~ On.click {
currentIndex = (currentIndex + 1) % questions.length
mIsCheater = false
questionView <~ text(questions(currentIndex).question)
}) <~ wrapContent <~ (horizontal) <~ padding(all = 10 dp)
I would write it like this (note that you are not using the wire
s in any way, so I removed them):
def nav(direction: Int) = {
currentIndex = (currentIndex + direction) % questions.length
mIsCheater = false
questionView <~ text(questions(currentIndex).question)
}
val answerView = l[HorizontalLinearLayout](
w[Button] <~
text("Prev") <~
wrapContent <~
On.click(nav(-1)),
w[Button] <~
text("Next") <~
wrapContent <~
On.click(nav(+1))
) <~
wrapContent <~
padding(all = 10 dp)
Another one:
val cheatButton = w[Button] <~ text("Cheat!") <~
wrapContent <~ On.click {
val intent =
new android.content.Intent(QuizActivity.this, classOf[CheatActivity])
val answer = questions(currentIndex).mTrue
intent.putExtra(CheatActivity.EXTRA_ANSWER_IS_TRUE,
answer)
startActivityForResult(intent, 0)
Ui(true)
}
I would change to:
def cheat = {
val intent = Intent(this, classOf[CheatActivity])
val answer = questions(currentIndex).mTrue
intent.putExtra(CheatActivity.EXTRA_ANSWER_IS_TRUE, answer)
startActivityForResult(intent, 0)
}
val cheatButton = w[Button] <~
text("Cheat!") <~
wrapContent <~
On.click(Ui { cheat; true })
A final example:
val landscapeLayout = l[FrameLayout](
questionTextView <~ lp[FrameLayout](
WRAP_CONTENT, WRAP_CONTENT, Gravity.
CENTER_HORIZONTAL),
answerView <~ lp[FrameLayout](
WRAP_CONTENT, WRAP_CONTENT, Gravity.CENTER_VERTICAL
| Gravity.CENTER_HORIZONTAL),
cheatButton <~ lp[FrameLayout](
WRAP_CONTENT, WRAP_CONTENT, Gravity.BOTTOM
| Gravity.CENTER),
prevNextLayout <~ lp[FrameLayout](
WRAP_CONTENT, WRAP_CONTENT, Gravity.BOTTOM
| Gravity.RIGHT)) <~ matchParent
I would tweak slightly:
def wrapContentGravity(gravity: Int) =
lp[FrameLayout](WRAP_CONTENT, WRAP_CONTENT, gravity)
val landscapeLayout = l[FrameLayout](
questionTextView <~ wrapContentGravity(Gravity.CENTER_HORIZONTAL),
answerView <~ wrapContentGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL),
cheatButton <~ wrapContentGravity(Gravity.BOTTOM | Gravity.CENTER),
prevNextLayout <~ wrapContentGravity(Gravity.BOTTOM | Gravity.RIGHT)
) <~ matchParent
I hope you agree that readability makes a huge different, especially for those who want to use your code as a starting point.
Nick
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.