Last active
January 4, 2018 15:57
-
-
Save RafaRuiz/729fbeb2c17673426ecce0fc1b5987db to your computer and use it in GitHub Desktop.
Refactor
This file contains 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
class SimpleListActivity : BaseActivity() { | |
@BindView(R.id.back_IV) | |
lateinit var backMore: AppCompatImageView | |
@BindView(R.id.recyclerViewMore) | |
lateinit var recyclerView: RecyclerView | |
@BindView(R.id.moreBannerImage) | |
lateinit var bannerImage: ImageView | |
@BindView(R.id.notLoggedInArea) | |
lateinit var notLoggedInArea: LinearLayout | |
@BindView(R.id.more_sign_in_button) | |
lateinit var moreSignInButton: Button | |
@BindView(R.id.more_register_button) | |
lateinit var moreRegisterButton: Button | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_simple_list) | |
ButterKnife.bind(this) | |
setOnClickListeners() | |
loadBannerImage() | |
configureRecyclerViewView() | |
} | |
private fun configureRecyclerViewView() { | |
recyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) | |
recyclerView.adapter = MoreOptionAdapter(this, getPages(), onLogout = { refreshView() }) | |
} | |
private fun loadBannerImage() { | |
val imagePath = ContentManager.getContentManagerInRAM().loginBanner.url | |
val url = URLHelper.getFullUrlWithAppBaseUrl(bannerImage.context, imagePath) | |
ImageLoaderHelper.displayImageNoRepeat( | |
url, | |
bannerImage | |
) | |
} | |
private fun setOnClickListeners() { | |
backMore.setOnClickListener { finish() } | |
moreSignInButton.setOnClickListener { | |
LoginPresenterLogic.goToAccountLogin(this) | |
} | |
moreRegisterButton.setOnClickListener { | |
AccountNotLoggedInActivityPresenterLogic.goToNotLoggedInWebActivity(this, AccountNotLoggedInActivity.Action.REGISTER) | |
} | |
} | |
override fun onResume() { | |
super.onResume() | |
refreshView() | |
} | |
private fun refreshView() { | |
if (LoginHelper.isUserLoggedIn(this)) { | |
notLoggedInArea.visibility = GONE | |
} else { | |
notLoggedInArea.visibility = VISIBLE | |
} | |
recyclerView.adapter?.notifyDataSetChanged() | |
} | |
private fun getPages(): ArrayList<Page> { | |
val contentManager = ContentManager.Companion.getContentManagerInRAM() | |
return contentManager.pages.filter { element -> | |
element.showOnAndroidPhone && (!element.isSecure || LoginHelper.isUserLoggedIn(this)) | |
} as ArrayList | |
} | |
companion object { | |
private 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