Skip to content

Instantly share code, notes, and snippets.

@RafaRuiz
Last active May 25, 2018 20:49
Show Gist options
  • Select an option

  • Save RafaRuiz/69427f1d4a9933f6e596b2d1a355dcbb to your computer and use it in GitHub Desktop.

Select an option

Save RafaRuiz/69427f1d4a9933f6e596b2d1a355dcbb to your computer and use it in GitHub Desktop.
Feature developed
class SimpleListActivity : BaseActivity() {
@BindView(R.id.back)
lateinit var back: AppCompatImageView
@BindView(R.id.listViewMore)
lateinit var listView: ListView
@BindView(R.id.moreToolbar)
lateinit var toolbar: RelativeLayout
@BindView(R.id.bannerImage)
lateinit var bannerIV: ImageView
@BindView(R.id.sign_in_button)
lateinit var signInButton: Button
@BindView(R.id.register_button)
lateinit var registerButton: Button
var pages: List<Page> = ArrayList<Page>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_simple_list)
ButterKnife.bind(this)
listView.adapter = OptionAdapter()
back.setOnClickListener { this.finish() }
listView.setOnItemClickListener { _: AdapterView<*>, _: View, position: Int, _: Long ->
val page = this.pages[position]
when (page.type) {
"link" -> UrlHelper.goToLink(page)
"logout" -> this.showLogoutAlert()
else -> Timber.i("TODO: unknown ${page.type}")
}
}
val toolbarTitle = toolbar.findViewById<TextView>(R.id.titleMore)
toolbarTitle.setText(R.string.more_my_account)
val imagePath = SharedPreferencesHelperInstance.getLoginBanner().url
val url = URLHelper.getFullUrlWithAppBaseUrl(this, imagePath)
ImageLoaderHelper.displayImageNoRepeat(
url,
bannerIV
)
signInButton.setOnClickListener {
LoginPresenterImpl.goToAccountLogin(this)
}
registerButton.setOnClickListener {
AccountNotLoggedInActivityPresenterImpl.goToNotLoggedInWebActivity(this, AccountNotLoggedInActivity.Action.REGISTER)
}
}
override fun onResume() {
super.onResume()
refreshPages()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
}
@Suppress("UNCHECKED_CAST")
private fun getContent(): ArrayList<String> {
return intent.getSerializableExtra(SIMPLE_LIST_KEY) as ArrayList<String>
}
private fun refreshPages() {
val contentManager = ContentManager.Companion.getContentManagerInRAM()
pages = SharedPreferencesHelperInstance.getPages().filter { element ->
element.shouldShowNow
}
}
inner class OptionAdapter : BaseAdapter() {
override fun getCount(): Int {
return pages.size
}
override fun getItemId(p0: Int): Long = p0.toLong()
override fun getItem(p0: Int): Any {
return pages[p0]
}
override fun getView(p0: Int, p1: View?, parent: ViewGroup?): View {
val layoutInflater = layoutInflater
val view = layoutInflater.inflate(R.layout.view_cell, parent, false)
val textView = view.findViewById(R.id.title)
textView.text = pages[p0].title.toUpperCase()
return view
}
}
private fun showLogoutAlert() {
val builder = AlertDialog.Builder(this)
builder.setPositiveButton(R.string.ok, { _, _ ->
LoginUseCase.getInstance()
.logoutUser(this)
refreshPages()
})
builder.setNegativeButton(R.string.cancel, { dialog, _ ->
dialog.dismiss()
})
builder.setTitle(R.string.logout_title)
builder.setMessage(R.string.logout_message)
val dialog = builder.create()
dialog.show()
}
companion object {
val SIMPLE_LIST_KEY = "SIMPLE_LIST_KEY"
fun goToSimpleListActivity(context: Context, content: ArrayList<String>) {
context.startActivity(
Intent(context, SimpleListActivity::class.java)
.putExtra(SIMPLE_LIST_KEY, content)
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment