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

[Feature] Bookmarks Improvement #1441

Merged

Conversation

4shutosh
Copy link
Contributor

@4shutosh 4shutosh commented Sep 22, 2021

Task/Issue URL:
#1438
#1439
#1440

PR related to the feature proposal mentioned in discussion #1442

Description

  • Users can create a bookmark folder from the edit bookmark screen.
  • Edit Bookmark shows the correct Bookmark Location, From BrowserFragment

Steps to test this PR

  1. Add a bookmark
  2. Edit the bookmark from the menu or from the snackbar
  3. Select the Location
  4. New bookmark folder can be created.
  5. After creating a new bookmark folder, select the bookmark folder
  6. Save : bookmark saved inside the new bookmark folder.

@4shutosh
Copy link
Contributor Author

4shutosh commented Sep 22, 2021

Screenshot_20210922-124907_DuckDuckGo
Screenshot_20210922-124913_DuckDuckGo

@cmonfortep
Copy link
Contributor

@4shutosh thanks for your time here. As I posted in the different issues you created, let's first have a discussion before we introduce any improvement.

We accept contributions for bug fixes after we triage the issue and we add the label "help wanted".

For feature requests/improvements, you need to open a discussion first. Inside the discussion, we will have a nice chat to know more about the proposal, understand what's the user value, etc. That's because we will need to share the proposed change with our Product team and/or Design team. If it's aligned with our roadmap and we are happy with the idea then we will be able to give you support with the improvements.

Hope that's ok with you, let's close this PR for now. We can open it again once I get the internal approval. Thanks again, and I think the proposal makes sense, but we need to check internally first 👍

@cmonfortep cmonfortep closed this Sep 22, 2021
@4shutosh
Copy link
Contributor Author

Thank you for the explanation @cmonfortep 🙌🏻

That's unfortunate but will surely do the required.

I've created a discussion here #1442

@4shutosh
Copy link
Contributor Author

@cmonfortep can you please reopen this PR, I'll make it as a draft and ask for approval on completion.

@cmonfortep cmonfortep reopened this Oct 28, 2021
@4shutosh 4shutosh marked this pull request as draft October 28, 2021 11:38
@4shutosh 4shutosh marked this pull request as ready for review November 3, 2021 07:55
@4shutosh
Copy link
Contributor Author

4shutosh commented Nov 3, 2021

Behavioral changes introduced in this PR:

  • The edit bookmark shows the folder name now
  • We can now create a new bookmark folder while editing the bookmark from the edit option either from snackbar or from the menu options.

@cmonfortep please review.
Do let me know with any changes are required along with new tests to be written or not.

@cmonfortep
Copy link
Contributor

Thanks @4shutosh.

"The edit bookmark shows the folder name now". Sorry if it was not clear, but we discarded de idea of showing folder names in the snackbar (see my comment: https://github.com/duckduckgo/Android/discussions/1442#discussioncomment-1551699)

@cmonfortep cmonfortep self-assigned this Nov 3, 2021
@4shutosh
Copy link
Contributor Author

4shutosh commented Nov 3, 2021

Sorry for the confusion. Yes it is not on the snackbar but on the edit saved site screen.
image
Here the "Edited" is the bookmark folder name.

@cmonfortep
Copy link
Contributor

Thanks. I will try to review the PR this week. Could you update the description? (just to reflect what this PR is finally addressing since we discarded some initial proposals)

@cmonfortep
Copy link
Contributor

@4shutosh just to give you some heads up. Testing this right now, looks great. Our designer is taking a look, should give me feedback on Monday.

@4shutosh
Copy link
Contributor Author

Thank you for the update 🙌🏻

@cmonfortep
Copy link
Contributor

@4shutosh thank you for your patience.

Feedback from the design team was really positive, that's really cool! They only asked if we can take the user back to the edit screen when the user created the new folder (same as in chrome).

Feedback is optional and I haven't checked how complex it is, so let me know if you are interested (and if you have time, it's ok if you can't) or not. In case you want to contribute on that, you can do it here or in another PR.

@4shutosh
Copy link
Contributor Author

That's great!

I'm interested in working on the feedback.

But I'll be able to do that (or any test related progress of this PR: as some tests are failing) after a week.

Please proceed with the tests fix if this feature is of priority for upcoming release within a week. In that case, I'll be continuing the feedback work on a new PR.

@cmonfortep
Copy link
Contributor

Sounds good, I will review this PR as it is now, and further improvements can be done on a separated PR.

Copy link
Contributor

@cmonfortep cmonfortep left a comment

Choose a reason for hiding this comment

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

Thanks @4shutosh, haven't reviewed all the changes. I've only focused on the dialogs and the browsertabviewmodel. Left some comments bellow.

While testing this, I've noticed an unexpected behavior: After editing a bookmark (changing folder), a snackbar saying "bookmark added" appears. Testing our latest app, the behavior is different. We only show the snackbar when the user adds a new bookmark, not after editing the bookmark.

@4shutosh
Copy link
Contributor Author

Sorry for the delay. @cmonfortep
I've done the improvements in the code as mentioned by you. Also removed the unnecessary snackbar behaviour after edit of bookmark.

This is getting stretched more than expected. I'll try my best to complete the changes related to this PR as early as possible now. Please help me with the review.

Thank you again. 🙌🏻

@malmstein
Copy link
Contributor

@cmonfortep can you check on this?

@cmonfortep
Copy link
Contributor

@4shutosh sorry for the delay here, Christmas break + workload got me busy.

I'm going to review this ASAP.

Copy link
Contributor

@cmonfortep cmonfortep left a comment

Choose a reason for hiding this comment

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

Thanks and sorry for the delay in the review. As you said, this is taking longer than we expected and it was difficult to remember what was missing here.

I'm leaving some comments. So far it's looking good. Just something important to mention:

  • be sure new code is properly tested if the class has a test (otherwise is not necessary, e.g: activities/fragments)
  • when aligning with develop, you may get lot of conflicts. We have introduced changes in our code style, so expect some conflicts there.

Thanks.

@@ -82,6 +87,10 @@ class BookmarksDataRepository(
return bookmarksDao.getBookmarksByParentIdSync(parentId)
}

override suspend fun getBookmarkFolderByParentId(parentId: Long): BookmarkFolder? {
return bookmarkFoldersDao.getBookmarkFolders().firstOrNull()?.find { it.id == parentId }
Copy link
Contributor

Choose a reason for hiding this comment

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

Haven't checked, but I think filtering at SQL level is more efficient than getting the whole list of folders here, and then filtering. Can you create a new method in BookmarkFoldersDao, and just use it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created a new method please check.

private fun editSavedSite(savedSiteChangedViewState: SavedSiteChangedViewState) {
val addBookmarkDialog = EditSavedSiteDialogFragment.instance(
savedSiteChangedViewState.savedSite,
savedSiteChangedViewState.bookmarkFolder?.id ?: 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

I want to check with someone from the team, what's the difference between savedSiteChangedViewState.bookmarkFolder?.id vs savedSiteChangedViewState.savedSite.parentId when we have a bookmark. So maybe I will ask to double check this part.

viewState.value = currentViewState().copy(currentFolder = currentFolder, selectedFolderId = selectedFolderId)
}

fun newFolderAdded(rootFolderName: String) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Test missing for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added please check

@4shutosh
Copy link
Contributor Author

Feedback from the design team was really positive, that's really cool! They only asked if we can take the user back to the edit screen when the user created the new folder (same as in chrome).

I tried to work on this. This can be done in a couple of ways as per my understanding.

1

    override fun onBookmarkFolderAdded(bookmarkFolder: BookmarkFolder, exitAndSetSelected: Boolean) {
        viewModelScope.launch(dispatcherProvider.io()) {
            bookmarksRepository.insert(bookmarkFolder)
        }
        if (exitAndSetSelected) onItemSelected(bookmarkFolder)
        else command.value = NewFolderCreatedUpdateTheStructure
    }

But this will not give us the ideal behavior and the list will be visible for a split second.

  1. Removing the list screen (Select Location) from back stack and maybe implementing the interface of folder addition directly on the Edit Bookmark screen. But this is not possible in our case as the Select Location list screen i.e BookmarkFoldersActivity is an activity. All the screens inside the chrome bookmark flow would be Fragments.

Please take a look and let me know any other changes required.

@cmonfortep
Copy link
Contributor

Feedback was optional. If you want to work on that, it's awesome! but my proposal is to do it on another PR once this one is merged. Just to avoid delaying more this feature.

@4shutosh
Copy link
Contributor Author

Sure I'll do that.
I've done all the changes required, resolved merge conflicts and the feature is working as expected. Please let me know any other changes required.

Copy link
Contributor

@cmonfortep cmonfortep left a comment

Choose a reason for hiding this comment

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

Thanks @4shutosh. We are almost done here 🎉

I've just left one last comment to cover with a unit test the method in the repository. I've tested the functionality and it works as expected.

@@ -96,6 +100,10 @@ class BookmarksDataRepository(
return bookmarksDao.getBookmarksByParentIdSync(parentId)
}

override suspend fun getBookmarkFolderByParentId(parentId: Long): BookmarkFolder {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test to cover this method?

What will happen when parentId is not found or doesn't return any folder? Please also test that scenario.

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've added the test.

In that case, the bookmark is treated as if it is stored in the default root folder under the name "Bookmarks".

Copy link
Contributor

@cmonfortep cmonfortep 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 @4shutosh LGTM!

Please, solve the conflicts with develop (probably the test has been moved into unit tests folder), and as soon as the check is green we will merge it. :)

@cmonfortep
Copy link
Contributor

Sharing here the stacktrace of the failing test.

com.duckduckgo.app.bookmarks.model.BookmarksDataRepositoryTest > whenGetBookmarkFolderByParentIdThenReturnBookmarkFolderForParentId[test(AVD) - 5.1.1] FAILED 
	java.lang.AssertionError: expected:<BookmarkFolder(id=1, name=name, parentId=11, numBookmarks=0, numFolders=0)> but was:<null>
	at org.junit.Assert.fail(Assert.java:89)

@4shutosh
Copy link
Contributor Author

4shutosh commented Feb 1, 2022

Yes, got the problem in the test. I've pushed a commit with a change in the test. The tests should pass now.

@4shutosh
Copy link
Contributor Author

4shutosh commented Feb 1, 2022

Yayyy 🎉 thank you for your guidance @cmonfortep 🙌🏻

@cmonfortep cmonfortep merged commit 4fa7a13 into duckduckgo:develop Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants