Created
October 20, 2015 22:23
-
-
Save lukaspili/7adf14f25b4951cb23d2 to your computer and use it in GitHub Desktop.
Kotlin + Anko beauty on Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lukaspili.angelus.mvp.home.drawer | |
import android.content.Context | |
import android.graphics.Color | |
import android.view.View | |
import android.view.ViewGroup | |
import android.widget.LinearLayout | |
import android.widget.TextView | |
import architect.MortarFactory | |
import architect.Screen | |
import architect.SubScreenService | |
import architect.commons.view.PresentedLinearLayout | |
import architect.robot.dagger.DaggerService | |
import autodagger.AutoInjector | |
import lukaspili.angelus.R | |
import lukaspili.angelus.business.manager.LangManager | |
import lukaspili.angelus.business.manager.tr | |
import lukaspili.angelus.mvp.home.drawer.screen.HomeDrawerScreenComponent | |
import lukaspili.angelus.util.* | |
import org.jetbrains.anko.* | |
import javax.inject.Inject | |
/** | |
* @author Lukasz Piliszczuk - [email protected] | |
*/ | |
@AutoInjector(HomeDrawerPresenter::class) | |
class HomeDrawerView(context: Context) : PresentedLinearLayout<HomeDrawerPresenter>(context) { | |
@field:Inject | |
internal lateinit var langManager: LangManager | |
private lateinit var titleTextView: TextView | |
private lateinit var settingsTextView: TextView | |
private lateinit var prayTextView: TextView | |
private lateinit var intentTextView: TextView | |
private lateinit var wikiTextView: TextView | |
private lateinit var aboutTextView: TextView | |
private lateinit var writeTextView: TextView | |
private lateinit var recommendTextView: TextView | |
private lateinit var appsTextView: TextView | |
private lateinit var legalTextView: TextView | |
private lateinit var creditsTextView: TextView | |
init { | |
val screenContext = MortarFactory.createContext(context, SubScreenService.get<Screen>(context, "drawer")) | |
DaggerService.get<HomeDrawerScreenComponent>(screenContext).inject(this) | |
setupView() | |
refreshContent() | |
} | |
private fun refreshContent() { | |
titleTextView.text = tr("home.title") | |
settingsTextView.text = tr("menu.4") | |
prayTextView.text = tr("menu.2") | |
intentTextView.text = tr("menu.3") | |
wikiTextView.text = tr("menu.1") | |
aboutTextView.text = tr("menu.5") | |
writeTextView.text = tr("menu.6") | |
recommendTextView.text = tr("menu.7") | |
appsTextView.text = tr("menu.10") | |
legalTextView.text = tr("menu.8") | |
creditsTextView.text = tr("menu.9") | |
appsTextView.visibility = if (langManager.interfaceLang == "fr") View.VISIBLE else View.GONE | |
} | |
private fun rowClick(row: Int) { | |
log("row click $row") | |
when (row) { | |
// todo: 20 more lines here | |
} | |
} | |
private fun setupView() { | |
scrollView { | |
lparams(matchParent, matchParent) | |
isFillViewport = true | |
backgroundColor = color(R.color.dark_blue) | |
isVerticalScrollBarEnabled = false | |
verticalLayout { | |
verticalLayout { | |
backgroundColor = Color.WHITE | |
titleTextView = textView { | |
verticalPadding = dip(10) | |
horizontalPadding = dip(10) | |
typeface = font(FONT_CAECILIA_BOLD) | |
textSize = 46f | |
textColor = color(R.color.orange) | |
}.lparams(matchParent) | |
settingsTextView = buildRow(this, true, false, { rowClick(1) }) | |
prayTextView = buildRow(this, true, false, { rowClick(2) }) | |
intentTextView = buildRow(this, true, false, { rowClick(3) }) | |
wikiTextView = buildRow(this, true, true, { rowClick(4) }) | |
}.lparams(matchParent) | |
verticalLayout { | |
aboutTextView = buildRow(this, false, false, { rowClick(5) }) | |
writeTextView = buildRow(this, false, false, { rowClick(6) }) | |
recommendTextView = buildRow(this, false, false, { rowClick(7) }) | |
appsTextView = buildRow(this, false, false, { rowClick(8) }) | |
legalTextView = buildRow(this, false, false, { rowClick(9) }) | |
creditsTextView = buildRow(this, false, true, { rowClick(10) }) | |
}.lparams(matchParent) | |
}.lparams(matchParent, wrapContent) | |
} | |
} | |
private fun buildRow(layout: LinearLayout, firstSection: Boolean, last: Boolean, click: () -> Unit): TextView { | |
with(layout) { | |
val textView = textView { | |
layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) | |
horizontalPadding = dip(15) | |
verticalPadding = dip(10) | |
typeface = font(if (firstSection) FONT_CAECILIA_ROMAN else FONT_HELVETICA) | |
textSize = if (firstSection) 22f else 18f | |
textColor = if (firstSection) Color.BLACK else color(R.color.menu_section2_textcolor) | |
setLineSpacing(0f, 1.3f) | |
onClick { click() } | |
} | |
if (!last) { | |
view { | |
val lparams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dip(1)) | |
lparams.leftMargin = dip(15) | |
lparams.rightMargin = dip(15) | |
layoutParams = lparams | |
backgroundColor = color(if (firstSection) R.color.menu_separator_gray else R.color.menu_separator_blue) | |
} | |
} | |
return textView | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment