{"action":"opened","issue":{"url":"https://api.github.com/repos/lTBeL/notes/issues/5","repository_url":"https://api.github.com/repos/lTBeL/notes","labels_url":"https://api.github.com/repos/lTBeL/notes/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/lTBeL/notes/issues/5/comments","events_url":"https://api.github.com/repos/lTBeL/notes/issues/5/events","html_url":"https://github.com/lTBeL/notes/issues/5","id":346845574,"node_id":"MDU6SXNzdWUzNDY4NDU1NzQ=","number":5,"title":"fragment操作封装","user":{"login":"lTBeL","id":15243969,"node_id":"MDQ6VXNlcjE1MjQzOTY5","avatar_url":"https://avatars0.githubusercontent.com/u/15243969?v=4","gravatar_id":"","url":"https://api.github.com/users/lTBeL","html_url":"https://github.com/lTBeL","followers_url":"https://api.github.com/users/lTBeL/followers","following_url":"https://api.github.com/users/lTBeL/following{/other_user}","gists_url":"https://api.github.com/users/lTBeL/gists{/gist_id}","starred_url":"https://api.github.com/users/lTBeL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lTBeL/subscriptions","organizations_url":"https://api.github.com/users/lTBeL/orgs","repos_url":"https://api.github.com/users/lTBeL/repos","events_url":"https://api.github.com/users/lTBeL/events{/privacy}","received_events_url":"https://api.github.com/users/lTBeL/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-02T03:27:23Z","updated_at":"2018-08-02T03:27:23Z","closed_at":null,"author_association":"OWNER","body":"```kotlin\r\nimport android.support.annotation.IdRes\r\nimport android.support.v4.app.Fragment\r\nimport android.support.v4.app.FragmentTransaction\r\nimport android.support.v7.app.AppCompatActivity\r\n\r\ninline fun <reified T : Fragment> AppCompatActivity.addFragment(@IdRes containerId: Int, tag: String, init: T.() -> Unit = {}): T {\r\n    return fragment<T>(containerId, tag, init, FragmentTransaction::add)\r\n}\r\n\r\ninline fun <reified T : Fragment> AppCompatActivity.fragment(@IdRes containerId: Int, tag: String, init: T.() -> Unit = {}, operate: FragmentTransaction.(Int, T, String) -> FragmentTransaction): T {\r\n    var fragment = supportFragmentManager.findFragmentByTag(tag)\r\n    if (fragment == null) {\r\n        fragment = T::class.java.newInstance()\r\n        fragment.init()\r\n        supportFragmentManager.beginTransaction().operate(containerId, fragment, tag).commit()\r\n    }\r\n    return fragment as T\r\n}\r\n```"}}
{"actor":{"display_login":"lTBeL"}}