-
Notifications
You must be signed in to change notification settings - Fork 553
fix: about event view on collapsing layout #1490
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,19 +5,21 @@ import android.view.LayoutInflater | |
import android.view.MenuItem | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.view.isVisible | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.Observer | ||
import androidx.navigation.fragment.navArgs | ||
import com.google.android.material.appbar.AppBarLayout | ||
import com.google.android.material.snackbar.Snackbar | ||
import com.squareup.picasso.Picasso | ||
import kotlinx.android.synthetic.main.fragment_about_event.view.appBar | ||
import kotlinx.android.synthetic.main.fragment_about_event.view.progressBarAbout | ||
import kotlinx.android.synthetic.main.fragment_about_event.view.aboutEventContent | ||
import kotlinx.android.synthetic.main.fragment_about_event.view.aboutEventDetails | ||
import kotlinx.android.synthetic.main.fragment_about_event.view.eventName | ||
import kotlinx.android.synthetic.main.fragment_about_event.view.detailsHeader | ||
import kotlinx.android.synthetic.main.fragment_about_event.view.aboutEventCollapsingLayout | ||
import kotlinx.android.synthetic.main.fragment_about_event.view.aboutEventImage | ||
import org.fossasia.openevent.general.R | ||
import org.fossasia.openevent.general.event.Event | ||
import org.fossasia.openevent.general.event.EventUtils | ||
|
@@ -26,12 +28,10 @@ import org.fossasia.openevent.general.utils.stripHtml | |
import org.koin.androidx.viewmodel.ext.android.viewModel | ||
import org.fossasia.openevent.general.utils.Utils.setToolbar | ||
|
||
class AboutEventFragment : Fragment(), AppBarLayout.OnOffsetChangedListener { | ||
class AboutEventFragment : Fragment() { | ||
private lateinit var rootView: View | ||
private val aboutEventViewModel by viewModel<AboutEventViewModel>() | ||
private var isHideToolbarView: Boolean = false | ||
private lateinit var eventExtra: Event | ||
private var title: String = "" | ||
private val safeArgs: AboutEventFragmentArgs by navArgs() | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
|
@@ -46,8 +46,6 @@ class AboutEventFragment : Fragment(), AppBarLayout.OnOffsetChangedListener { | |
loadEvent(it) | ||
}) | ||
|
||
rootView.appBar.addOnOffsetChangedListener(this) | ||
|
||
aboutEventViewModel.error | ||
.nonNull() | ||
.observe(viewLifecycleOwner, Observer { | ||
|
@@ -67,30 +65,29 @@ class AboutEventFragment : Fragment(), AppBarLayout.OnOffsetChangedListener { | |
|
||
private fun loadEvent(event: Event) { | ||
eventExtra = event | ||
title = eventExtra.name | ||
rootView.aboutEventContent.text = event.description?.stripHtml() | ||
val startsAt = EventUtils.getEventDateTime(event.startsAt, event.timezone) | ||
val endsAt = EventUtils.getEventDateTime(event.endsAt, event.timezone) | ||
|
||
anhanh11001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rootView.aboutEventDetails.text = EventUtils.getFormattedDateTimeRangeBulleted(startsAt, endsAt) | ||
rootView.eventName.text = event.name | ||
} | ||
|
||
override fun onOffsetChanged(appBarLayout: AppBarLayout, verticalOffset: Int) { | ||
val maxScroll = appBarLayout.totalScrollRange | ||
val percentage = Math.abs(verticalOffset).toFloat() / maxScroll.toFloat() | ||
Picasso.get() | ||
.load(event.originalImageUrl) | ||
.placeholder(R.drawable.header) | ||
.into(rootView.aboutEventImage) | ||
anhanh11001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (percentage == 1f && isHideToolbarView) { | ||
// Collapsed | ||
rootView.detailsHeader.visibility = View.GONE | ||
rootView.aboutEventCollapsingLayout.title = title | ||
isHideToolbarView = !isHideToolbarView | ||
} | ||
if (percentage < 1f && !isHideToolbarView) { | ||
// Not Collapsed | ||
rootView.detailsHeader.visibility = View.VISIBLE | ||
rootView.aboutEventCollapsingLayout.title = " " | ||
isHideToolbarView = !isHideToolbarView | ||
} | ||
rootView.appBar.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { appBarLayout, offset -> | ||
val thisActivity = activity | ||
if (thisActivity is AppCompatActivity) { | ||
if (Math.abs(offset) == appBarLayout.getTotalScrollRange()) { | ||
rootView.detailsHeader.isVisible = false | ||
thisActivity.supportActionBar?.title = event.name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was referring to this part. Never mind, I will send a PR to fix this. |
||
} else { | ||
rootView.detailsHeader.isVisible = true | ||
thisActivity.supportActionBar?.title = "" | ||
} | ||
} | ||
}) | ||
} | ||
|
||
override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<gradient | ||
android:angle="90" | ||
android:endColor="#00000000" | ||
android:startColor="#FF000000"/> | ||
</shape> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,8 +75,8 @@ | |
<dimen name="event_details_divider">1.2dp</dimen> | ||
<dimen name="divider_margin_bottom">20dp</dimen> | ||
<dimen name="divider_margin_top">12dp</dimen> | ||
<dimen name="collapsing_toolbar_height">220dp</dimen> | ||
<dimen name="details_header_margin_top">40dp</dimen> | ||
<dimen name="collapsing_toolbar_height">320dp</dimen> | ||
<dimen name="details_header_margin_top">100dp</dimen> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @liveHarshit this is dimensions inside dimens.xml file... Can you please clarify your review? |
||
<dimen name="event_name_divider_height">2dp</dimen> | ||
<dimen name="event_name_divider_width">200dp</dimen> | ||
<dimen name="logo_icon_width">40dp</dimen> | ||
|
Uh oh!
There was an error while loading. Please reload this page.