Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaned up some code #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package sphe.inews.ui.main.news.business

import android.content.Intent
Expand Down Expand Up @@ -43,7 +42,7 @@ class BusinessFragment : DaggerFragment(), ArticleAdapter.ArticleListener {

@Suppress("unused")
@Inject
lateinit var articlePreviewDialogFragment:ArticlePreviewFragment
lateinit var articlePreviewDialogFragment: ArticlePreviewFragment


private val viewModel: BusinessViewModel by lazy {
Expand All @@ -63,12 +62,6 @@ class BusinessFragment : DaggerFragment(), ArticleAdapter.ArticleListener {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

recyclerView?.let {
recyclerView?.apply {
layoutManager = LinearLayoutManager(activity)
}
}

adapter.setListener(this)

btn_retry.setOnClickListener {
Expand All @@ -81,23 +74,26 @@ class BusinessFragment : DaggerFragment(), ArticleAdapter.ArticleListener {

}

override fun onArticleClicked(article: Article,isVideo:Boolean) {
when(isVideo){
true ->{
override fun onArticleClicked(article: Article, isVideo: Boolean) {
when (isVideo) {
true -> {
val bundle = Bundle()
bundle.putString(ViewYoutubeDialogFragment.URL,article.url)
bundle.putString(ViewYoutubeDialogFragment.URL, article.url)
viewYoutubeDialogFragment.arguments = bundle
viewYoutubeDialogFragment.show((activity as DaggerAppCompatActivity).supportFragmentManager,"viewYoutubeDialogFragment")
viewYoutubeDialogFragment.show(
(activity as DaggerAppCompatActivity).supportFragmentManager,
"viewYoutubeDialogFragment"
)
}
false ->{
false -> {
val bundle = Bundle()
bundle.putString(ArticlePreviewFragment.TITLE,article.title)
bundle.putString(ArticlePreviewFragment.CONTENT,article.content)
bundle.putString(ArticlePreviewFragment.IMAGE,article.urlToImage)
bundle.putString(ArticlePreviewFragment.DATE,article.publishedAt)
bundle.putString(ArticlePreviewFragment.ARTICLE_URL,article.url)
bundle.putString(ArticlePreviewFragment.SOURCE_NAME,article.source.name)
findNavController().navigate(R.id.articlePreviewFragment,bundle,null,null)
bundle.putString(ArticlePreviewFragment.TITLE, article.title)
bundle.putString(ArticlePreviewFragment.CONTENT, article.content)
bundle.putString(ArticlePreviewFragment.IMAGE, article.urlToImage)
bundle.putString(ArticlePreviewFragment.DATE, article.publishedAt)
bundle.putString(ArticlePreviewFragment.ARTICLE_URL, article.url)
bundle.putString(ArticlePreviewFragment.SOURCE_NAME, article.source.name)
findNavController().navigate(R.id.articlePreviewFragment, bundle, null, null)
}
}
}
Expand All @@ -111,11 +107,11 @@ class BusinessFragment : DaggerFragment(), ArticleAdapter.ArticleListener {
startActivity(Intent.createChooser(shareIntent, null))
}

private fun getBusinessNews(){
private fun getBusinessNews() {
viewModel.observeBusinessNews("za")?.let {
viewModel.observeBusinessNews("za")?.removeObservers(this)
viewModel.observeBusinessNews("za")?.observe(viewLifecycleOwner, Observer { res ->
when(res.status){
when (res.status) {
Resources.Status.LOADING -> {
this.setErrorViewsVisibility(false)
this.setShimmerLayoutVisibility(true)
Expand All @@ -125,7 +121,7 @@ class BusinessFragment : DaggerFragment(), ArticleAdapter.ArticleListener {
this.setShimmerLayoutVisibility(false)

context?.resources?.let {
txt_message.text = context?.resources?.getString(R.string.msg_error)
txt_message.text = context?.resources?.getString(R.string.msg_error)
}

}
Expand All @@ -146,21 +142,21 @@ class BusinessFragment : DaggerFragment(), ArticleAdapter.ArticleListener {

}

private fun setErrorViewsVisibility(isVisible:Boolean){
if(isVisible){
private fun setErrorViewsVisibility(isVisible: Boolean) {
if (isVisible) {
btn_retry.visibility = View.VISIBLE
txt_message.visibility = View.VISIBLE
}else{
} else {
btn_retry.visibility = View.GONE
txt_message.visibility = View.GONE
}
}

private fun setShimmerLayoutVisibility(isVisible:Boolean){
if(isVisible){
private fun setShimmerLayoutVisibility(isVisible: Boolean) {
if (isVisible) {
shimmer_view_container.visibility = View.VISIBLE
shimmer_view_container.startShimmer()
}else{
} else {
shimmer_view_container.visibility = View.GONE
shimmer_view_container.stopShimmer()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import javax.inject.Inject
/**
* A simple [Fragment] subclass.
*/
class EntertainmentFragment : DaggerFragment() , ArticleAdapter.ArticleListener{
class EntertainmentFragment : DaggerFragment(), ArticleAdapter.ArticleListener {

@Suppress("unused")
@Inject
Expand All @@ -41,10 +41,10 @@ class EntertainmentFragment : DaggerFragment() , ArticleAdapter.ArticleListener{

@Suppress("unused")
@Inject
lateinit var articlePreviewDialogFragment:ArticlePreviewFragment
lateinit var articlePreviewDialogFragment: ArticlePreviewFragment


private val viewModel: EntertainmentViewModel by lazy {
private val viewModel: EntertainmentViewModel by lazy {
ViewModelProvider(this, providerFactory).get(EntertainmentViewModel::class.java)
}

Expand Down Expand Up @@ -79,23 +79,26 @@ class EntertainmentFragment : DaggerFragment() , ArticleAdapter.ArticleListener{
}


override fun onArticleClicked(article: Article,isVideo:Boolean) {
when(isVideo){
true ->{
override fun onArticleClicked(article: Article, isVideo: Boolean) {
when (isVideo) {
true -> {
val bundle = Bundle()
bundle.putString(ViewYoutubeDialogFragment.URL,article.url)
bundle.putString(ViewYoutubeDialogFragment.URL, article.url)
viewYoutubeDialogFragment.arguments = bundle
viewYoutubeDialogFragment.show((activity as DaggerAppCompatActivity).supportFragmentManager,"viewYoutubeDialogFragment")
viewYoutubeDialogFragment.show(
(activity as DaggerAppCompatActivity).supportFragmentManager,
"viewYoutubeDialogFragment"
)
}
false ->{
false -> {
val bundle = Bundle()
bundle.putString(ArticlePreviewFragment.TITLE,article.title)
bundle.putString(ArticlePreviewFragment.CONTENT,article.content)
bundle.putString(ArticlePreviewFragment.IMAGE,article.urlToImage)
bundle.putString(ArticlePreviewFragment.DATE,article.publishedAt)
bundle.putString(ArticlePreviewFragment.ARTICLE_URL,article.url)
bundle.putString(ArticlePreviewFragment.SOURCE_NAME,article.source.name)
findNavController().navigate(R.id.articlePreviewFragment,bundle,null,null)
bundle.putString(ArticlePreviewFragment.TITLE, article.title)
bundle.putString(ArticlePreviewFragment.CONTENT, article.content)
bundle.putString(ArticlePreviewFragment.IMAGE, article.urlToImage)
bundle.putString(ArticlePreviewFragment.DATE, article.publishedAt)
bundle.putString(ArticlePreviewFragment.ARTICLE_URL, article.url)
bundle.putString(ArticlePreviewFragment.SOURCE_NAME, article.source.name)
findNavController().navigate(R.id.articlePreviewFragment, bundle, null, null)
}
}
}
Expand All @@ -109,12 +112,12 @@ class EntertainmentFragment : DaggerFragment() , ArticleAdapter.ArticleListener{
startActivity(Intent.createChooser(shareIntent, null))
}

private fun getEntertainmentNews(){
private fun getEntertainmentNews() {
viewModel.observeEntertainmentNews("za")?.let {
viewModel.observeEntertainmentNews("za")?.removeObservers(this)
viewModel.observeEntertainmentNews("za")?.observe(viewLifecycleOwner, Observer { res ->

when(res.status){
when (res.status) {
Resources.Status.LOADING -> {
this.setErrorViewsVisibility(false)
this.setShimmerLayoutVisibility(true)
Expand All @@ -124,7 +127,7 @@ class EntertainmentFragment : DaggerFragment() , ArticleAdapter.ArticleListener{
this.setShimmerLayoutVisibility(false)

context?.resources?.let {
txt_message.text = context?.resources?.getString(R.string.msg_error)
txt_message.text = context?.resources?.getString(R.string.msg_error)
}
}
Resources.Status.SUCCESS -> {
Expand All @@ -145,21 +148,21 @@ class EntertainmentFragment : DaggerFragment() , ArticleAdapter.ArticleListener{
}


private fun setErrorViewsVisibility(isVisible:Boolean){
if(isVisible){
private fun setErrorViewsVisibility(isVisible: Boolean) {
if (isVisible) {
btn_retry.visibility = View.VISIBLE
txt_message.visibility = View.VISIBLE
}else{
} else {
btn_retry.visibility = View.GONE
txt_message.visibility = View.GONE
}
}

private fun setShimmerLayoutVisibility(isVisible:Boolean){
if(isVisible){
private fun setShimmerLayoutVisibility(isVisible: Boolean) {
if (isVisible) {
shimmer_view_container.visibility = View.VISIBLE
shimmer_view_container.startShimmer()
}else{
} else {
shimmer_view_container.visibility = View.GONE
shimmer_view_container.stopShimmer()

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_business.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
android:layout_width="0dp"
android:layout_height="0dp"
android:scrollbars="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down