-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CMM-802 create taxonomies data view #22258
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
Merged
Merged
Changes from 24 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
f00d50e
Updating library
adalpari dc07310
Porting the terms fetching
adalpari 9358243
Porting create
adalpari 9bb9e35
Porting delete term
adalpari 5e62ed7
porting update term
adalpari 726a4d3
Update term fix
adalpari 3a0639b
Creating the new isHierarchical cocal field
adalpari 6bce343
Parent fix
adalpari c39d8fb
Fixing tests
adalpari 630a7b1
detekt
adalpari 10b8ab2
Minor fix
adalpari 03b8a91
Fixing tests
adalpari 7347ee2
Adding the taxonomies menu view model
adalpari 1a3a864
Adding show mechanism
adalpari 025c3ea
Showing taxoniomies
adalpari a7de2e3
Adding a LiveData
adalpari d37d8a2
Call categories and tags screens
adalpari 6f2bcd1
detekt and style
adalpari bbdc79f
Adding tests
adalpari 8ec9ecc
Creating dataview
adalpari ba3efae
Style adjustments
adalpari b3e623b
Merge branch 'trunk' into task/cmm-814-hide-or-show-taxonomies-in-the…
adalpari 417152b
Adjustments and setHierarchical
adalpari a249c0a
Proper indentation
adalpari 543d686
Handling parent and description in details
adalpari d4386c9
Sorting hierarchically
adalpari cd96e04
Adding tests
adalpari c715f55
Title fix
adalpari e4d10fe
Removing unused string
adalpari 13f26fc
Using server query
adalpari 75d074d
Using server sorting
adalpari a6fe5ce
Merge branch 'trunk' into task/cmm-814-hide-or-show-taxonomies-in-the…
adalpari 69ce363
Merge remote-tracking branch 'origin/task/cmm-814-hide-or-show-taxono…
adalpari da89442
Merge remote-tracking branch 'origin/trunk' into feature/CMM-802-Crea…
adalpari d2e9f03
Handling indentation in the UI style layer
adalpari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
58 changes: 58 additions & 0 deletions
58
...ess/src/main/java/org/wordpress/android/ui/prefs/taxonomies/TaxonomiesNavMenuViewModel.kt
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.wordpress.android.ui.prefs.taxonomies | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.launch | ||
import org.wordpress.android.fluxc.model.SiteModel | ||
import org.wordpress.android.fluxc.network.rest.wpapi.rs.WpApiClientProvider | ||
import org.wordpress.android.fluxc.utils.AppLogWrapper | ||
import org.wordpress.android.util.AppLog | ||
import rs.wordpress.api.kotlin.WpRequestResult | ||
import uniffi.wp_api.TaxonomyListParams | ||
import uniffi.wp_api.TaxonomyTypeDetailsWithEditContext | ||
import javax.inject.Inject | ||
|
||
class TaxonomiesNavMenuViewModel @Inject constructor( | ||
private val wpApiClientProvider: WpApiClientProvider, | ||
private val appLogWrapper: AppLogWrapper, | ||
) : ViewModel() { | ||
// LiveData because this is observed from Java | ||
private val _taxonomies = MutableLiveData<List<TaxonomyTypeDetailsWithEditContext>>() | ||
val taxonomies: LiveData<List<TaxonomyTypeDetailsWithEditContext>> = _taxonomies | ||
|
||
fun fetchTaxonomies(site: SiteModel) { | ||
if (!site.isUsingSelfHostedRestApi) { | ||
appLogWrapper.d( | ||
AppLog.T.API, | ||
"Taxonomies - Taxonomies cannot be fetched: Application Password not available" | ||
) | ||
return | ||
} | ||
viewModelScope.launch { | ||
val client = wpApiClientProvider.getWpApiClient(site) | ||
val response = client.request { requestBuilder -> | ||
requestBuilder.taxonomies().listWithEditContext(TaxonomyListParams()) | ||
} | ||
when (response) { | ||
is WpRequestResult.Success -> { | ||
val list = response.response.data | ||
appLogWrapper.d(AppLog.T.API, "Taxonomies - Fetched taxonomies ${list.taxonomyTypes.size}") | ||
val taxonomies = mutableListOf<TaxonomyTypeDetailsWithEditContext>() | ||
list.taxonomyTypes.forEach { type -> | ||
appLogWrapper.d(AppLog.T.API, "Taxonomies - Taxonomy ${type.value.name}") | ||
if (type.value.visibility.showInNavMenus) { | ||
taxonomies.add(type.value) | ||
} | ||
} | ||
_taxonomies.value = taxonomies | ||
} | ||
|
||
else -> { | ||
appLogWrapper.e(AppLog.T.API, "Taxonomies - Error fetching taxonomies") | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.