how do you pass arguments to fragment called from NavigationDrawer using NavigationUI? - android-architecture-navigation

I've converted my app to use NavigationUI. But setupWithNavController() replaces my setNavigationItemSelectedListener().
In my listener I was passing a (type safe) argument to the fragment.

If I understand your question correct what you are looking for is:
Navigation parameters documentation
Briefly:
In your navigation graph, on the fragment you want the value sent to, you will add an argument.
<fragment android:id="#+id/myFragment" >
<argument
android:name="amount"
app:argType="integer"
android:defaultValue="0" />
</fragment>
When you then reference that fragment as an action, the library will generate a Directories class, which will look something like this:
val action = SpecifyAmountFragmentDirections.confirmationAction(amount)
v.findNavController().navigate(action)
The names are generated based upon what you named the Fragment and actions.
Also note that it is possible to send whole objects if they are Parcelable as well.
If the Fragment in question is the startDestination of your graph I am not sure if you can do it right away. A work around might be to load the data in the Fragment? Or maybe into a shared ViewModel from the Activity?
Good luck!

If anyone is still looking for an answer to this question. I've found a usefull workaround with the NavigationUI Global actions (working with alpha-09)
You can provide a top level action to your navigation graph:
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_nav"
app:startDestination="#id/mainFragment">
...
<action android:id="#+id/action_global_mainFragment"
app:destination="#id/mainFragment"/>
</navigation>
And use it with your navigation controller to navigate with the correct bundle when a user click on a menu item. Be carefull to remove .setupWithNavController(navController) call from your NavigationView, or it will override your behavior.

Related

Changing default base URL of Sitecore ServiceApiController, Is it possible?

when we implement SitecoreApiController, for each action method we make using Sitecore.Services.Core.ServicesController("namespace") attribute, we get a url like this:
/sitecore/api/ssc/{namespace}/{controller}/{id}/{action}
I wonder if we could change this default pattern, somehow in config files. I particularly interested in /sitecore/api/ part, because sometimes in the sense of security concerns, certain clients don't like to reveal that much about CMS platform behind the scene. Sometimes they even ask us to hide anything in HTTP header that tells about Microsoft ASP.NET explicitly.
Is this possible here?
Edit
this link shows a way to customize it using pipelines but I wonder if we could change the base url just through config files without needing a custom pipeline
I had a look at it, and I think I found out how - although I haven't tested it.
It looks for a setting named Sitecore.Services.RouteBase and if it can't find it, it uses sitecore/api/ssc/ as the default value.
You should be able to change it with a config patch like this in the App_Config/Include folder:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<settings>
<setting name="Sitecore.Services.RouteBase" value="custom/api/" />
</settings>
</sitecore>
</configuration>

Magento - left.ptml not showing on all product list pages

left.phtml the file that displays the left navigation on a magento page is only showing on one list view page and not the others does anyone have a solution to get that file to show in all list views
If you are tasking left.phtml,
Then According magento structure left.phtml are only show for Non-Anchor category in it left side of category.
And layer navigation are only showing for Anchor category.for anchor left.phtml is not showing.
For non-Anchor categories
see catalog.xml code
<catalog_category_default translate="label">
<label>Catalog Category (Non-Anchor)</label>
<reference name="left">
<block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
</reference>
Also for
Anchor categories
see at catalog.xml
<catalog_category_layered translate="label">
<label>Catalog Category (Anchor)</label>
<reference name="left">
<block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/>
</reference>
Hope ,you will understand.
Check the layout in folder theme/package (it can be in default/default, when your theme is in another folder)
Check if layout is plugged (use in your layout.xml something like <remove name="header">). If header will be removed - you use correct layout
Check the handle and reference name, where you are adding block. For example: you are adding layered navigation block. On one page it placed in handle <catalog_category_layered>, but your page there no this handle. Try to add to <catalog_category_default> or even in <default>.
Open your template and check if the block was added there. Look for
<?php $this->getChildHtml('blockName'); ?>
Try to change your block name (maybe on this page already exist block with the same name)
(this option can be useless for you) Please check the block output in system / configuration / advanced
Maybe there is a conflict between two navigation modules (for example module A and module B). The module A can use it for rewrite. But the module B will use it only for investigation and use on this page it's own calls. In that case the module A will not work (to resolve this issue you need to change rewrite. class A should rewrite class B)
If you are trying to add navigation to CMS page - try to google this topic (how to add navigation to CMS page). There are many examples and I don't want to duplicate them.

Magento - Inject custom module on product info page

I've searched on web for how to add "block" with my template on the product page. I build my custom module that displays some sort of information and I would like to show that, let's say under the long description of my product.
I've been trying to format the xml layout of my module but without luck.
After some search I've found this: Programatically create Magento blocks and inject them into layout which I can not make it work for me. But it is probably because I've missed something.
My module is structured like this:
CODE: app/code/local/deveti/Countrypurchase
DESIGN: app/design/frontend/default/default/template/Countrypurchase/index.phtml
LAYOUT: app/design/frontend/default/default/layout/countrypurchase.xml
I know the correct way is to edit main layout file, manually add a block, but I'd like to do that on the fly.
EDIT: this works!
So I would do in my module layout xml countrypurchase.xml something like this:
<?xml version="1.0"?>
<layout version="1.0">
<catalog_product_view>
<reference name="product.info">
<block type="core/template" name="product.countrypurchase" as="countrypurchase" template="countrypurchase/index.phtml" />
</reference>
</catalog_product_view>
</layout>
And I've added a call to catalog/product/view.phtml:
<?php echo $this->getChildHtml('countrypurchase'); ?>
And it works ;)
Thank you for your help!
The problem with the product view page is that it's output is mainly controlled by the PHP code in the template catalog/product/view.phtml. Magento doesn't offer much extensibility points out of the box. You could add it to the content block but that would put your custom content either completely at the top or completely at the bottom.
I think you are required to modify the template and add PHP code to render your custom block at the position you want, like:
<?php
echo $this->getChildHtml('product.countrypurchase');
?>
With this in place you can either add your block with the name product.countrypurchase via the XML layout or programmatically.

web service pattern that supports lazy loading of all properties

I am trying to design an endpoint template for a web service. My main requirement is that the caller is able to specify which properties should be populated in the returned result set.
My service returns large lists (up to 1M records) of partial objects as well as individual full objects such as (rough example XML, sorry it's a little verbose)
List:
<items>
<item>
<a>aaa</a>
<b>bbb</b>
</item>
<item>
<a>aaaA</a>
<b>bbbB</b>
</item>
</items>
Detail:
<item>
<a>aaa</a>
<b>bbb</b>
<c>ccc</c>
...
<w>
<x>xxx</x>
<y>yyy</y>
</w>
<z>zzz</z>
</item>
I have considered the following ideas:
Returning the full detail items in the list
Creating a 'list' item type that is shorter
passing a string array of property names that the caller wants to be returned
I am leaning towards the 3rd option but I want something different to that it doesn't support sub objects, I have considered passing the xml schema that you want returned instead of an array.
I would like the API to support lazy loading which is why the 3rd way seems viable as well.
Here's an example of what a function for 3. would look like:
public User GetUser(long ID, string[] properties)
And then the caller could just go:
User.Email = GetUser(User.ID, "Email").Email
Through extensive use of default values and hiding nulls, the returned XML for that would be:
<User>
<ID>123</ID>
<Email>example#example.com</Email>
</User>
Now the problem as mentioned above is trying to make it play nice with things like <w> far above, which itself has sub items as well as the possibility for lists to have sub items.
As I have far too many properties, I cannot have just a ws method for each property.
I am considering option 3. but using an xml schema instead of a string[].. But I can't think of an easy way to define this, I would also like to not have to use String names for properties such as "Email".
The final plan is to have a series of pre-defined schemas that are used commonly and only in advanced cases would we need to actually define the requested properties. But I have no idea of all the systems that will be talking to my API, let alone what properties they might each want (it's not going to be feasible for us to tailor the API for every caller).
Or am I over complicating everything too much?
I found the documentation for the Google APIs on Partial Responses and Partial Updates:
http://googlecode.blogspot.com/2011/07/lightning-fast-performance-tips-for.html
This seems to answer my question.

Magento - catalog.xml not using correct template

Noob developing a Magento theme and I can't seem to figure out why Magento is not using the path I specify in the setTemplate action on catalog.xml.
I've got my own theme in /app/design/frontend/default/mycustomtheme and I've been patching files over from the base and making changes.
I've copied over /app/design/frontend/base/default/layout/catalog.xml to my custom theme at /app/design/frontend/default/mycustomtheme/layout/catalog.xml. I've set the template to be a specific phtml file...
<catalog_product_view translate="label">
<label>Catalog Product View (Any)</label>
<!-- Mage_Catalog -->
<reference name="root">
<action method="setTemplate"><template>page/2column.phtml</template></action>
</reference>
Yet it's not working. Can someone spot what the problem might be? I've got all cache disabled and other changes I make I can see immediately, just not this one.
edit: I should note, if I change something else in the catalog_product_view xml node I see those changes are reflected. For instance if I remove <action method="addJs"><script>varien/product.js</script></action> then I see the reference is removed in the rendered html file.
edit2: Adding images to address questions ...
did you setup-up / configured the theme from your store backend?
Yes, and it's actually loading the correct header and footer, and it's properly styled.
Are you sure you have such template under /app/design/frontend/default/mycustomtheme/template/page/ directory?
Yes, I can confirm the file is there
OMG. The (one and only) product I was testing on had a specific layout set under the "Design" section. So I guess that was overriding anything I had set in catalog.xml
I'd like to have the 3 hours of my life back.