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

Stats Widget - add site selector #9929

Merged
merged 5 commits into from
May 30, 2019

Conversation

planarvoid
Copy link
Contributor

This PR adds a site selection dialog to the widget configuration screen. I've created a DialogFragment which communicates directly with the ViewModel and shows a list of sites. When the user selects a site, the dialog is dismissed and the selected site is updated.
The sites show the site icon, title and url.
I've also added a few tests for the ViewModel

To test:

  • Try to add the stats views widget
  • Click on the "Site" field on the configuration screen
  • A dialog opens with the list of sites
  • The list is scrollable and retains orientation on rotation
  • Click on a site
  • The site gets selected

@planarvoid planarvoid added this to the 12.7 milestone May 24, 2019
@planarvoid planarvoid requested a review from khaykov May 24, 2019 09:34
@planarvoid planarvoid self-assigned this May 24, 2019
Copy link
Member

@khaykov khaykov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @planarvoid ! Looks good, I only have a couple of minor comments :)

alertDialogBuilder.setView(buildView())
alertDialogBuilder.setTitle(R.string.stats_widget_select_your_site)
alertDialogBuilder.setNegativeButton(R.string.cancel) { dialog, _ ->
dialog?.dismiss()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't actually have to dismiss dialog manually - negative button should do it by default :)

@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
private lateinit var viewModel: ViewsWidgetViewModel
private fun buildView(): View? {
val rootView = activity!!.layoutInflater.inflate(R.layout.stats_site_selector, null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should rename the stats_site_selector to something widget related (stats_widget_site_selector?) to avoid confusion with the "main" Stats resources? Same with stats_site_selector_item

Copy link
Contributor Author

@planarvoid planarvoid May 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea 👍 , I've also renamed the kotlin classes to match the layouts

) {
fun bind(site: SiteUiModel) {
if (site.iconUrl != null) {
imageManager.load(itemView.site_icon, ICON, site.iconUrl)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we use BLAVATAR instead of ICON the correct placeholder will be set automatically, so we can remove null check and replace this block with something like this:

imageManager.load(itemView.site_icon, BLAVATAR, StringUtils.notNullStr(site.iconUrl))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into and the BLAVATAR type has R.color.neutral_0 as a placeholder so I think I still have to set it manually to avoid a grey rectangle.

private val mutableSites = MutableLiveData<List<SiteUiModel>>()
val sites: LiveData<List<SiteUiModel>> = mutableSites
private val mutableHideSiteDialog = MutableLiveData<Event<SiteUiModel>>()
val hideSite: LiveData<Event<SiteUiModel>> = mutableHideSiteDialog
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be hideSiteDialog instead of hideSite? Also, wanted to ask, why we are storing Event<SiteUiModel> in it instead of Unit with call() method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea 👍, I thought Unit defaults to null which wouldn't work

}

private fun selectSite(site: SiteUiModel) {
if (mutableSelectedSite.value != site) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm reading this correctly, this method should not dismiss a dialog when selecting a site that is already selected, yet it does. Wonder if I'm missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that the 2 objects are not equal because both have a different anonymous onClick function. I've fixed that but thinking about it now I don't think it really makes sense. We want the user to be able to reselect a site so I'll remove the if

xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use common values (eg. margin_extra_large) from dimens.xml here and in stats_site_selector_item ?

@planarvoid
Copy link
Contributor Author

@khaykov thanks a lot for the review! I think I addressed everything so it should be ready for another check.

Copy link
Member

@khaykov khaykov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes! Looks good 👍

@khaykov khaykov merged commit 7a0c66b into feature/stats_widgets_readonly May 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants