{"action":"closed","issue":{"url":"https://api.github.com/repos/Arello-Mobile/Moxy/issues/156","repository_url":"https://api.github.com/repos/Arello-Mobile/Moxy","labels_url":"https://api.github.com/repos/Arello-Mobile/Moxy/issues/156/labels{/name}","comments_url":"https://api.github.com/repos/Arello-Mobile/Moxy/issues/156/comments","events_url":"https://api.github.com/repos/Arello-Mobile/Moxy/issues/156/events","html_url":"https://github.com/Arello-Mobile/Moxy/issues/156","id":263158928,"number":156,"title":"[HELP NEEDED] Menu not updated during recreation","user":{"login":"AlexShafir","id":3159171,"avatar_url":"https://avatars0.githubusercontent.com/u/3159171?v=4","gravatar_id":"","url":"https://api.github.com/users/AlexShafir","html_url":"https://github.com/AlexShafir","followers_url":"https://api.github.com/users/AlexShafir/followers","following_url":"https://api.github.com/users/AlexShafir/following{/other_user}","gists_url":"https://api.github.com/users/AlexShafir/gists{/gist_id}","starred_url":"https://api.github.com/users/AlexShafir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AlexShafir/subscriptions","organizations_url":"https://api.github.com/users/AlexShafir/orgs","repos_url":"https://api.github.com/users/AlexShafir/repos","events_url":"https://api.github.com/users/AlexShafir/events{/privacy}","received_events_url":"https://api.github.com/users/AlexShafir/received_events","type":"User","site_admin":false},"labels":[{"id":325077444,"url":"https://api.github.com/repos/Arello-Mobile/Moxy/labels/question","name":"question","color":"cc317c","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-10-05T15:01:39Z","updated_at":"2018-03-20T16:53:48Z","closed_at":"2018-03-20T16:53:48Z","author_association":"NONE","body":"Hi,\r\n\r\nWhile using Moxy faced task to defer view state recreation in Fragment to certain point (in my case when menu is loaded).\r\n\r\nIn order to achieve this, I created AttachableMvpFragment, which allows subclasses to attach at certain point (code in the end).\r\n\r\nNow, when I make recreation, methods that manipulate menu are re-called as needed, however Menu is not updated. Despite this, when these methods are called when user clicks UI button, menu is changed correctly.\r\n\r\nI know this is not direct issue with Moxy, however you may have witnessed it before and may have solution?\r\n\r\nIn case of code below, manipulateMenu is recalled after orientation change, but menu is not getting updated.\r\n\r\n**BarView.java**\r\n```java\r\npublic interface BarView extends MvpView {\r\n   void manipulateMenu();\r\n}\r\n```\r\n\r\n**FooFragment.java**\r\n```java\r\npublic class FooFragment extends AttachableMvpFragment implements BarView {\r\nprivate Menu menu;\r\n@InjectPresenter RandomPresenter presenter;\r\n\r\npublic void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {\r\n   this.menu = menu;\r\n   onCustomAttachPointReached();\r\n   ... \r\n}\r\n\r\n// called from presenter\r\npublic void manipulateMenu() {\r\n   menu.findItem(R.id.some_item).setDrawable(null);\r\n}\r\n}\r\n```\r\n\r\n**AttachableMvpFragment.java**\r\n```java\r\nimport android.app.Fragment;\r\nimport android.os.Build;\r\nimport android.os.Bundle;\r\n\r\nimport com.arellomobile.mvp.MvpDelegate;\r\nimport com.arellomobile.mvp.MvpFragment;\r\n\r\n/**\r\n * Date: 19-Dec-15\r\n * Time: 13:25\r\n *\r\n * @author Yuri Shmakov\r\n * @author Alexander Blinov\r\n * @author Konstantin Tckhovrebov\r\n */\r\n@SuppressWarnings(\"ConstantConditions\")\r\npublic class AttachableMvpFragment extends Fragment {\r\n\r\n    private boolean mIsStateSaved;\r\n    private MvpDelegate<? extends MvpFragment> mMvpDelegate;\r\n\r\n    private boolean isCustomAttachPointReached;\r\n\r\n    public void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n\r\n        getMvpDelegate().onCreate(savedInstanceState);\r\n    }\r\n\r\n\r\n    public void onCustomAttachPointReached() {\r\n        mIsStateSaved = false;\r\n\r\n        getMvpDelegate().onAttach();\r\n        isCustomAttachPointReached = true;\r\n    }\r\n\r\n    public void onSaveInstanceState(Bundle outState) {\r\n        super.onSaveInstanceState(outState);\r\n\r\n        mIsStateSaved = true;\r\n\r\n        getMvpDelegate().onSaveInstanceState(outState);\r\n        getMvpDelegate().onDetach();\r\n    }\r\n\r\n    @Override\r\n    public void onStart() {\r\n        super.onStart();\r\n        if (isCustomAttachPointReached && isDetached()) {\r\n            mIsStateSaved = false;\r\n\r\n            getMvpDelegate().onAttach();\r\n        }\r\n    }\r\n\r\n    @Override\r\n    public void onResume() {\r\n        super.onResume();\r\n        if (isCustomAttachPointReached && isDetached()) {\r\n            mIsStateSaved = false;\r\n\r\n            getMvpDelegate().onAttach();\r\n        }\r\n    }\r\n\r\n    @Override\r\n    public void onStop() {\r\n        super.onStop();\r\n\r\n        getMvpDelegate().onDetach();\r\n    }\r\n\r\n    @Override\r\n    public void onDestroyView() {\r\n        super.onDestroyView();\r\n\r\n        getMvpDelegate().onDetach();\r\n        getMvpDelegate().onDestroyView();\r\n    }\r\n\r\n    @Override\r\n    public void onDestroy() {\r\n        super.onDestroy();\r\n\r\n        //We leave the screen and respectively all fragments will be destroyed\r\n        if (getActivity().isFinishing()) {\r\n            getMvpDelegate().onDestroy();\r\n            return;\r\n        }\r\n\r\n        // When we rotate device isRemoving() return true for fragment placed in backstack\r\n        // http://stackoverflow.com/questions/34649126/fragment-back-stack-and-isremoving\r\n        if (mIsStateSaved) {\r\n            mIsStateSaved = false;\r\n            return;\r\n        }\r\n\r\n        // See https://github.com/Arello-Mobile/Moxy/issues/24\r\n        boolean anyParentIsRemoving = false;\r\n\r\n        if (Build.VERSION.SDK_INT >= 17) {\r\n            Fragment parent = getParentFragment();\r\n            while (!anyParentIsRemoving && parent != null) {\r\n                anyParentIsRemoving = parent.isRemoving();\r\n                parent = parent.getParentFragment();\r\n            }\r\n        }\r\n\r\n        if (isRemoving() || anyParentIsRemoving) {\r\n            getMvpDelegate().onDestroy();\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @return The {@link MvpDelegate} being used by this Fragment.\r\n     */\r\n    public MvpDelegate getMvpDelegate() {\r\n        if (mMvpDelegate == null) {\r\n            mMvpDelegate = new MvpDelegate(this);\r\n        }\r\n\r\n        return mMvpDelegate;\r\n    }\r\n}\r\n```\r\n"}}
{"actor":{"display_login":"AlexShafir"}}