B3nedikt / restring

Restring is a android library to replace string resources dynamically
Apache License 2.0
317 stars 31 forks source link

Restring not working in multi(2) level menu in a navigation drawer #120

Closed brsgina closed 1 year ago

brsgina commented 1 year ago

If I have a one level menu like below, restring works fine.

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <group
        android:id="@+id/group_6"
        android:checkableBehavior="single">
        <item
            android:id="@+id/nav_logout"
            android:background="@drawable/custom_navdrawer_item_color_state"
            android:icon="@drawable/exit_icon"
            android:title="@string/logout"
            app:actionLayout="@layout/menu_counter" />
    </group>
</menu>

But, if i create a two level menu like below, when I have a menu inside a menu, restrings works on only the items in the deeper menu tag.

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
 <item android:title="@string/administration">
        <menu>
            <group
                android:id="@+id/group_5"
                android:checkableBehavior="single">
                <item
                    android:id="@+id/nav_accounts"
                    android:background="@drawable/custom_navdrawer_item_color_state"
                    android:icon="@drawable/account_icon"
                    android:title="@string/account"
                    app:actionLayout="@layout/menu_counter" />
                <item
                    android:id="@+id/nav_settings"
                    android:background="@drawable/custom_navdrawer_item_color_state"
                    android:icon="@drawable/settings_icon"
                    android:title="@string/settings"
                    app:actionLayout="@layout/menu_counter" />
            </group>
        </menu>
    </item>
</menu>

So in @string/administration the default value will remain there, it will not be overwritten.

B3nedikt commented 1 year ago

I never used such a nested menu, and I am not sure why this would be useful. So in short, this is not supported by my library Reword at the moment. If you want you can fork this library and modify its example app so that it reproduces your issue, and then post a link to your fork here. I could then look how much effort it would be to support this. If you want you can of course also just implement it yourself, and create a PR for my Reword library :)

brsgina commented 1 year ago

Thank you for your quick answer!

Actually, you use such nested menus too, exactly in reword>example>main>res>menu>navigation_drawer_menu.xml and it is working fine in your example project.

So I am sorry for creating this issue, it's my bad, my item with the title @string/administration didn't have id, that's why it wasn't working in my project.

brsgina commented 1 year ago

Finally i reopened this issue, because it is reproducible.

Here is my fork.

In reword>example>main>res>menu>navigation_drawer_menu.xml I made a second sub menu, but reword only works well for the first group.

Screenshot_20230203-150134_Reword

B3nedikt commented 1 year ago

I just checked it, the problem is that the PopupMenuHelper class used in the NavigationViewViewTransformer does not support groups correctly. This should not be hard to fix, I don't have time for it now though. I may find time for it next week ;) If you need a faster solution feel free to implement it yourself and create a PR :)

B3nedikt commented 1 year ago

@brsgina Or well I just fixed it with Reword 4.0.3 ;)