rx.android.app.AppObservable Java Examples

The following examples show how to use rx.android.app.AppObservable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MePageFragment.java    From android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mSubscriptions.add(AppObservable.bindFragment(this, mSettingsProducer.themeStream())
            .subscribe(new Action1<Theme>() {
                @Override
                public void call(Theme theme) {
                    mPublicKey.setVisibility(theme.isInternalsVisible ? View.VISIBLE : View.GONE);
                }
            }));

    mSubscriptions.add(AppObservable.bindFragment(this, mMeProducer.stream())
            .subscribe(new Action1<Node.Me>() {
                @Override
                public void call(Node.Me me) {
                    mNameTextView.setText(me.name);
                    mAddressTextView.setText(me.address);
                    mPublicKeyTextView.setText(me.publicKey);
                }
            }));
}
 
Example #2
Source File: AlbumListFragment.java    From Sky31Radio with Apache License 2.0 5 votes vote down vote up
public void loadData(int page){
    if(!hasLoaded){
        AppObservable.bindFragment(this,
                Observable.create(new Observable.OnSubscribe<Pagination<Album>>() {
            @Override
            public void call(Subscriber<? super Pagination<Album>> subscriber) {
                if (cacheManager.exits(DiskCacheManager.KEY_ALBUM)) {
                    Type type = new TypeToken<Pagination<Album>>() {}.getType();
                    Pagination<Album> cachedData = cacheManager.get(DiskCacheManager.KEY_ALBUM, type);
                    if(cachedData!=null){
                        subscriber.onNext(cachedData);
                    }
                }
            }
        })).subscribe(observer);
    }
    AppObservable.bindFragment(this, apiService.listAlbums(page))
            .map(new Func1<Pagination<Album>, Pagination<Album>>() {
                @Override
                public Pagination<Album> call(Pagination<Album> pagination) {
                    cacheManager.put(DiskCacheManager.KEY_ALBUM, pagination);
                    return pagination;
                }
            })
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(observer);
}
 
Example #3
Source File: PeersPageFragment.java    From android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mPeersRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            super.getItemOffsets(outRect, view, parent, state);
            int childPosition = parent.getChildPosition(view);
            if (childPosition == 0) {
                outRect.top = view.getResources().getDimensionPixelSize(R.dimen.global_margin);
            }
            if (childPosition == parent.getAdapter().getItemCount() - 1) {
                outRect.bottom = view.getResources().getDimensionPixelSize(R.dimen.global_margin);
            }
        }
    });
    mPeersRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    mAdapter = new PeerListAdapter(mBus,
            AppObservable.bindFragment(this, mSettingsProducer.themeStream()),
            AppObservable.bindFragment(this, mPeersProducer.createStream()),
            AppObservable.bindFragment(this, mPeersProducer.updateStream()),
            AppObservable.bindFragment(this, mPeersProducer.removeStream()));
    mPeersRecyclerView.setAdapter(mAdapter);

    IconDrawable addIcon = new IconDrawable(getActivity(), Iconify.IconValue.fa_plus)
            .colorRes(R.color.my_primary)
            .actionBarSize();
    addIcon.setStyle(Paint.Style.FILL);
    mAdd.setImageDrawable(addIcon);
    mAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mBus.post(new PeerEvents.Create());
        }
    });
}
 
Example #4
Source File: MainActivity.java    From android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_main, menu);

    // Set initial state of toggle and click behaviour.
    final SwitchCompat cjdnsServiceSwitch = (SwitchCompat) MenuItemCompat.getActionView(menu.findItem(R.id.switch_cjdns_service));
    mSubscriptions.add(AppObservable.bindActivity(this, Cjdroute.running(this)
            .subscribeOn(Schedulers.io()))
            .subscribe(new Action1<Integer>() {
                @Override
                public void call(Integer pid) {
                    // Change toggle check state if there is a currently running cjdroute process.
                    cjdnsServiceSwitch.setChecked(true);
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                    // Do nothing.
                }
            }, new Action0() {
                @Override
                public void call() {
                    // Configure toggle click behaviour.
                    cjdnsServiceSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                        @Override
                        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                            if (isChecked) {
                                mBus.post(new ApplicationEvents.StartCjdnsService());
                            } else {
                                mBus.post(new ApplicationEvents.StopCjdnsService());
                            }
                        }
                    });
                }
            }));

    return super.onCreateOptionsMenu(menu);
}
 
Example #5
Source File: ConnectionsDialogFragment.java    From android with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    ((CjdnsApplication) getActivity().getApplication()).inject(this);

    Bundle args = getArguments();
    final int peerId = args.getInt(FRAGMENT_BUNDLE_KEY_PEER_ID);

    final Observable<Node.Peer> peerStream = mPeersProducer.createStream()
            .mergeWith(mPeersProducer.updateStream())
            .filter(new Func1<Node.Peer, Boolean>() {
                @Override
                public Boolean call(Node.Peer peer) {
                    return peer.id == peerId;
                }
            });

    mAdapter = new ConnectionAdapter(getActivity(), mBus,
            AppObservable.bindFragment(this, mSettingsProducer.themeStream()),
            AppObservable.bindFragment(this, peerStream));
    mAdapter.registerDataSetObserver(new DataSetObserver() {
        @Override
        public void onChanged() {
            super.onChanged();
            if (mAdapter.hasData() && mAdapter.getCount() <= 0) {
                dismiss();
            }
        }
    });

    return new MaterialDialog.Builder(getActivity())
            .title(R.string.connections_list_title)
            .adapter(mAdapter, null)
            .listSelector(R.drawable.md_transparent)
            .build();
}
 
Example #6
Source File: WeatherListActivity.java    From rain-or-shine with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);

    Injector.inject(this);

    subscription = AppObservable.bindActivity(this, networkActivity)
            .subscribe(this);
}
 
Example #7
Source File: ProgramListFragment.java    From Sky31Radio with Apache License 2.0 5 votes vote down vote up
public void loadData(int page) {
    if(!hasLoaded && conditions.size()==0){
        AppObservable.bindFragment(this,
                Observable.create(new Observable.OnSubscribe<Pagination<Program>>() {
                    @Override
                    public void call(Subscriber<? super Pagination<Program>> subscriber) {
                        if (cacheManager.exits(DiskCacheManager.KEY_PROGRAM)) {
                            Type type = new TypeToken<Pagination<Program>>() {
                            }.getType();
                            Pagination<Program> cachedData = cacheManager.get(DiskCacheManager.KEY_PROGRAM, type);
                            Timber.d("load data from cached file successful!");
                            if (cachedData != null) {
                                subscriber.onNext(cachedData);
                            }
                        }
                    }
                })
        ).subscribe(observer);
    }
    AppObservable.bindFragment(this, apiService.listPrograms(page, conditions))
            .map(new Func1<Pagination<Program>, Pagination<Program>>() {
                @Override
                public Pagination<Program> call(Pagination<Program> pagination) {
                    if(pagination.getCurrentPage() == 1  && conditions.size()==0){
                        cacheManager.put(DiskCacheManager.KEY_PROGRAM, pagination);
                    }
                    return pagination;
                }
            }).subscribe(observer);
}
 
Example #8
Source File: AnchorListFragment.java    From Sky31Radio with Apache License 2.0 5 votes vote down vote up
public void loadData(final int page){
    if(!hasLoaded){
        AppObservable.bindFragment(this,
                Observable.create(new Observable.OnSubscribe<Pagination<Anchor>>() {
                @Override
                public void call(Subscriber<? super Pagination<Anchor>> subscriber) {
                    if (cacheManager.exits(DiskCacheManager.KEY_ANCHOR)) {
                        Type type = new TypeToken<Pagination<Anchor>>() { }.getType();
                        Pagination<Anchor> cachedData = cacheManager.get(DiskCacheManager.KEY_ANCHOR, type);
                        Timber.d("load data from cached file successful!");
                        if(cachedData!=null) {
                            subscriber.onNext(cachedData);
                        }
                    }
                }
            })
        )
        .subscribe(observer);
    }
    AppObservable.bindFragment(this, apiService.listAnchor(page))
            .map(new Func1<Pagination<Anchor>, Pagination<Anchor>>() {
                @Override
                public Pagination<Anchor> call(Pagination<Anchor> pagination) {
                    cacheManager.put(DiskCacheManager.KEY_ANCHOR, pagination);
                    return pagination;
                }
            })
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(observer);
}
 
Example #9
Source File: SettingsFragment.java    From Sky31Radio with Apache License 2.0 5 votes vote down vote up
private void checkVersion() {
    final ProgressDialog dialog = new ProgressDialog(getActivity());
    dialog.setMessage(getString(R.string.msg_checking_version));
    dialog.show();
    AppObservable.bindFragment(this, firService.checkVersion(BuildConfig.APPLICATION_ID))
    .subscribe(new Subscriber<FirVersion>() {
        @Override
        public void onCompleted() {
        }

        @Override
        public void onError(Throwable e) {
            Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();

            dialog.dismiss();
        }

        @Override
        public void onNext(FirVersion firVersion) {
            if(firVersion.getVersion()> BuildConfig.VERSION_CODE){
                dialog.dismiss();
                showNewVersionFoundDialog(firVersion);
            }else{
                Toast.makeText(getActivity(), R.string.msg_no_new_version, Toast.LENGTH_SHORT).show();
            }
        }
    });
}
 
Example #10
Source File: MainActivity.java    From githot with Apache License 2.0 5 votes vote down vote up
private void getAccessToken(String code) {
    String client_id = GitHubApiConstants.GITHUB_APP_CLIENT_ID;
    String client_secret = GitHubApiConstants.GITHUB_APP_CLIENT_SECRET;

    AppObservable.bindActivity(this, oAuthGitHubWebFlow.getOAuthToken(client_id, client_secret, code))
            .map(new Func1<AccessTokenResponse, AccessTokenResponse>() {
                @Override
                public AccessTokenResponse call(AccessTokenResponse accessTokenResponse) {
                    return accessTokenResponse;
                }
            })
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(tokenObservable);
}
 
Example #11
Source File: MainActivity.java    From githot with Apache License 2.0 5 votes vote down vote up
private void getUserInfo() {
    String token = sharedPreferences.getString("token", "");
    if (!TextUtils.isEmpty(token))
        AppObservable.bindActivity(this, apiService.getUserInfoWithToken(token))
                .map(new Func1<User, Object>() {
                    @Override
                    public Object call(User user) {
                        return user;
                    }
                }).observeOn(AndroidSchedulers.mainThread())
                .subscribe(userInfoObservable);
}
 
Example #12
Source File: TrendingReposFragment.java    From githot with Apache License 2.0 5 votes vote down vote up
private void fetchData(String language, String since) {
        setRefreshing(true);
        AppObservable.bindFragment(this, apiService.getTrendingRepositories(language, since))
                .map(new Func1<List<Repository>, List<Repository>>() {
                    @Override
                    public List<Repository> call(List<Repository> repositories) {
//                        L.json(JSON.toJSONString(repositories));
                        L.i("=====loaddata=="+mTimeSpan);
                        return repositories;
                    }
                }).subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(repositoryObserver);
    }
 
Example #13
Source File: SettingsFragment.java    From githot with Apache License 2.0 5 votes vote down vote up
private void checkVersion() {
    final ProgressDialog dialog = new ProgressDialog(getActivity());
    dialog.setMessage(getString(R.string.msg_checking_version));
    dialog.show();
    AppObservable.bindFragment(this, firService.checkVersion(BuildConfig.FIR_APPLICATION_ID, BuildConfig.FIR_API_TOKEN))
            .subscribe(new Subscriber<FirVersion>() {
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {
                    Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
                    dialog.dismiss();
                }

                @Override
                public void onNext(FirVersion firVersion) {
                    if (firVersion.getVersion() > BuildConfig.VERSION_CODE) {
                        dialog.dismiss();
                        showNewVersionFoundDialog(firVersion);
                    } else {
                        Toast.makeText(getActivity(), R.string.msg_this_is_latest_version, Toast.LENGTH_SHORT).show();
                        dialog.dismiss();
                    }
                }
            });
}
 
Example #14
Source File: ReposDetailsActivity.java    From githot with Apache License 2.0 5 votes vote down vote up
private void initStarFlowButtonStatus() {
        // 查看本人是否star过本项目
        String reposOwner = mRepository.getOwner().getLogin();
        String reposName = mRepository.getName();
        String accessToken = this.getSharedPreferences("githot_sp", MODE_PRIVATE).getString("token", "");

        if (TextUtils.isEmpty(accessToken)) {
            Toast.makeText(this, "please login first", Toast.LENGTH_SHORT).show();
            return;
        }


        // 检查状态
        AppObservable.bindActivity(ReposDetailsActivity.this, oAuthApiService.checkIfReposStarred(reposOwner, reposName, accessToken))
                .map(new Func1<Response, Object>() {
                    @Override
                    public Object call(Response response) {
                        L.json(response);
                        return response;
                    }
                })
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(checkStarObservable);
        // FB 实例
//        mStarFB

        //设置状态


    }
 
Example #15
Source File: MainActivity.java    From Leaderboards with Apache License 2.0 5 votes vote down vote up
private void setDataFromService(boolean forceUpdate) {
    leaderboardSubscription = AppObservable.bindActivity(this,
            LeaderboardDataService.getInstance().getLeaderboard(Constants.BRACKET_LIST[currentBracket], forceUpdate))
            .delay(500, TimeUnit.MILLISECONDS)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.newThread())
            .subscribe(this);
}
 
Example #16
Source File: CharacterActivity.java    From Leaderboards with Apache License 2.0 5 votes vote down vote up
private void getCharacterProfile(boolean forceUpdate) {
    profileSubscription = AppObservable.bindActivity(
        this, LeaderboardDataService.getInstance().getCharacterProfile(realmName, name, forceUpdate))
        .observeOn(AndroidSchedulers.mainThread())
        .subscribeOn(Schedulers.newThread())
        .subscribe(this);
}
 
Example #17
Source File: BaseFragment.java    From lockit with Apache License 2.0 4 votes vote down vote up
protected <T> Observable<T> bindObservable(Observable<T> in) {
    return AppObservable.bindFragment(this, in).takeUntil(detached);
}
 
Example #18
Source File: MainFragment.java    From RxParse with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_main, container, false);
    ButterKnife.inject(this, view);

    listAdapter = ListRecyclerAdapter.create();

    listAdapter.createViewHolder(new Func2<ViewGroup, Integer, ParseUserViewHolder>() {
        @Override
        public ParseUserViewHolder call(@Nullable ViewGroup viewGroup, Integer position) {
            android.util.Log.d("RxParse", "ParseUserViewHolder");
            return new ParseUserViewHolder(inflater.inflate(R.layout.item_parse_user, viewGroup, false));
        }
    });

    listView.setLayoutManager(new android.support.v7.widget.LinearLayoutManager(getActivity()));
    listView.setAdapter(listAdapter);

    refresher = new SwipeRefreshLayout.OnRefreshListener() {
        @Override public void onRefresh() {
            loading.setRefreshing(true);
            AppObservable.bindFragment(MainFragment.this, ParseObservable.find(ParseUser.getQuery()))
                    .doOnNext(new Action1<ParseUser>() {
                        @Override
                        public void call(final ParseUser user) {
                            android.util.Log.d("RxParse", "onNext: " + user.getObjectId());
                        }
                    })
                    .toList()
                    .subscribe(new Action1<List<ParseUser>>() {
                        @Override
                        public void call(final List<ParseUser> users) {
                            loading.setRefreshing(false);
                            android.util.Log.d("RxParse", "subscribe: " + users);
                            handler.post(new Runnable() {
                                @Override
                                public void run() {
                                    listAdapter.getList().clear();
                                    listAdapter.getList().addAll(users);
                                    listAdapter.notifyDataSetChanged();
                                }
                            });
                        }
                    });
        }
    };

    loading.setOnRefreshListener(refresher);

    handler.post(new Runnable() {
        @Override
        public void run() {
            refresher.onRefresh();
        }
    });
    return view;
}
 
Example #19
Source File: RxAndroidFragment.java    From AsyncExamples with Apache License 2.0 4 votes vote down vote up
private <T> Observable<T> bindLifecycle(Observable<T> observable, LifecycleEvent lifecycleEvent) {
    Observable<T> boundObservable = AppObservable.bindFragment(this, observable);
    return LifecycleObservable.bindUntilLifecycleEvent(lifecycle(), boundObservable, lifecycleEvent);
}
 
Example #20
Source File: RxAndroidFragment.java    From AsyncExamples with Apache License 2.0 4 votes vote down vote up
private <T> Observable<T> bindLifecycle(Observable<T> observable) {
    Observable<T> boundObservable = AppObservable.bindFragment(this, observable);
    return LifecycleObservable.bindFragmentLifecycle(lifecycle(), boundObservable);
}
 
Example #21
Source File: ReposDetailsActivity.java    From githot with Apache License 2.0 4 votes vote down vote up
private void initView() {
    Toolbar mToolbar = (Toolbar) findViewById(R.id.id_repos_details_toobar);
    setSupportActionBar(mToolbar);

    ActionBar ab = getSupportActionBar();
    if (ab != null) {
        ab.setHomeAsUpIndicator(R.mipmap.ic_back_arrow);
        ab.setDisplayHomeAsUpEnabled(true);
        ab.setTitle(mRepository.getName());
    }

    adapter = new HotReposDetailsListAdapterHolder(this, mReposData);
    mRecyclerView = (RecyclerView) findViewById(R.id.id_repos_details_recycler_view);
    mRecyclerView.setAdapter(adapter);
    linearLayoutManager = new LinearLayoutManager(this);
    mRecyclerView.setLayoutManager(linearLayoutManager);

    float paddingStart = getResources().getDimension(R.dimen.repos_hot_divider_padding_start);
    mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST, paddingStart, false));


    mStarFB = (FloatingActionButton) findViewById(R.id.id_repos_details_fb);
    mStarFB.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            //判断是否登录
            String token = ReposDetailsActivity.this.getSharedPreferences("githot_sp", MODE_PRIVATE).getString("token", "");
            if (TextUtils.isEmpty(token)) {
                Toast.makeText(ReposDetailsActivity.this, "please login first", Toast.LENGTH_SHORT).show();
                return;
            }

            AppObservable.bindActivity(ReposDetailsActivity.this, oAuthApiService.starRepo(mRepository.getOwner().getLogin(), mRepository.getName(), token))
                    .map(new Func1<Object, Object>() {
                        @Override
                        public Object call(Object object) {
                            return object;
                        }
                    })
                    .subscribeOn(AndroidSchedulers.mainThread())
                    .subscribe(observable);
        }
    });

}