{"action":"opened","issue":{"url":"https://api.github.com/repos/android-cn/android-discuss/issues/380","repository_url":"https://api.github.com/repos/android-cn/android-discuss","labels_url":"https://api.github.com/repos/android-cn/android-discuss/issues/380/labels{/name}","comments_url":"https://api.github.com/repos/android-cn/android-discuss/issues/380/comments","events_url":"https://api.github.com/repos/android-cn/android-discuss/issues/380/events","html_url":"https://github.com/android-cn/android-discuss/issues/380","id":135976154,"number":380,"title":"[问答]rx里怎么处理if else判断呢（请看参考代码）？","user":{"login":"snowjade","id":11959369,"avatar_url":"https://avatars.githubusercontent.com/u/11959369?v=3","gravatar_id":"","url":"https://api.github.com/users/snowjade","html_url":"https://github.com/snowjade","followers_url":"https://api.github.com/users/snowjade/followers","following_url":"https://api.github.com/users/snowjade/following{/other_user}","gists_url":"https://api.github.com/users/snowjade/gists{/gist_id}","starred_url":"https://api.github.com/users/snowjade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snowjade/subscriptions","organizations_url":"https://api.github.com/users/snowjade/orgs","repos_url":"https://api.github.com/users/snowjade/repos","events_url":"https://api.github.com/users/snowjade/events{/privacy}","received_events_url":"https://api.github.com/users/snowjade/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-24T06:56:42Z","updated_at":"2016-02-24T06:56:42Z","closed_at":null,"body":"我想做的事情，大概是这样的：\r\n有个全局 boolean值 once_opened；\r\nif(once_opened){\r\n            mMainView.removeGuideView();\r\n        }else {\r\n            once_opened = true;\r\n        }\r\n\r\n用rxjava写是这样的：\r\nObservable.just(\"once_opened\").flatMap(new Func1<String, Observable<Boolean>>() {\r\n            @Override\r\n            public Observable<Boolean> call(String s) {\r\n                if(PreferenceManager.getDefaultSharedPreferences(mMainView\r\n                        .getContext()).getBoolean(s, false)) {\r\n                    return Observable.just(true);\r\n                }else {\r\n                    return Observable.just(false);\r\n                }\r\n            }\r\n        }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())\r\n                .subscribe(new Action1<Boolean>() {\r\n                    @Override\r\n                    public void call(Boolean aBoolean) {\r\n                        if(aBoolean){\r\n                            mMainView.removeGuideView();\r\n                        }else {\r\n                            PreferenceManager.getDefaultSharedPreferences(mMainView.getContext())\r\n                                    .edit().putBoolean(\"once_opened\", true).apply();\r\n                        }\r\n                    }\r\n                });\r\n\r\n但是我觉得我用rxjava的姿势不对，写的好麻烦，并且存在两个if else 判断，正确的姿势该是什么样的呢？"}}