@Override public void onBackPressed() { int currentItem = viewPager.getCurrentItem(); if (listFragments != null && currentItem >= 0 && currentItem < listFragments.size()) { Fragment fragment = listFragments.get(currentItem); if (fragment != null && fragment instanceof BackManager) { if (((BackManager) fragment).onBackPressed()) { super.onBackPressed(); } } } else { super.onBackPressed(); } }
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.repo_detail_activity, menu); return true; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.generic_toolbar); String user = getIntent().getStringExtra(USER); setTitle(getString(R.string.title_activity_repos_starred, user)); StarredReposFragment reposFragment = StarredReposFragment.newInstance(user); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.content, reposFragment); ft.commit(); }
public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); if (getToolbar() != null) { getToolbar().inflateMenu(R.menu.search_activity_menu); MenuItem searchItem = menu.findItem(R.id.action_search); IconicsDrawable searchIcon = new IconicsDrawable(getApplicationContext(), Octicons.Icon.oct_search) .actionBar() .colorRes(R.color.gray_github_medium); searchItem.setIcon(searchIcon); } return true; }
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); MenuItem item = menu.findItem(R.id.share_repo); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { item.setIcon(getResources().getDrawable(R.drawable.abc_ic_menu_share_mtrl_alpha, getTheme())); } else { item.setIcon(getResources().getDrawable(R.drawable.abc_ic_menu_share_mtrl_alpha)); } if (currentRepo == null || currentRepo.parent == null) { MenuItem parentItem = menu.findItem(R.id.action_show_parent); if (parentItem != null) { menu.removeItem(parentItem.getItemId()); } } if (repoStarred != null) { MenuItem starredItem = menu.findItem(R.id.action_repo_star); if (starredItem != null) { starredItem.setTitle(repoStarred ? R.string.menu_unstar : R.string.menu_star); } } if (repoWatched != null) { MenuItem watchedItem = menu.findItem(R.id.action_repo_watch); if (watchedItem != null) { watchedItem.setTitle(repoWatched ? R.string.menu_unwatch : R.string.menu_watch); } } MenuItem menuChangeBranch = menu.findItem(R.id.action_repo_change_branch); Drawable changeBranch = new IconicsDrawable(this, Octicons.Icon.oct_git_branch).actionBar().colorRes(R.color.white); if (menuChangeBranch != null) { menuChangeBranch.setIcon(changeBranch); } return true; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.github_enterprise_login); ButterKnife.bind(this); enterpriseToken.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { enterpriseLogin.setEnabled(true); } @Override public void afterTextChanged(Editable editable) {} }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_repo_detail); if (getIntent().getExtras() != null) { RepoInfo repoInfo = getIntent().getExtras().getParcelable(REPO_INFO); setTitle(repoInfo.name); slidingTabLayout = (SlidingTabLayout) findViewById(R.id.tabStrip); slidingTabLayout.setSelectedIndicatorColors(AttributesUtils.getAccentColor(this)); slidingTabLayout.setDividerColors(getResources().getColor(R.color.primary_dark_alpha)); viewPager = (ViewPager) findViewById(R.id.pager); load(repoInfo); } else { finish(); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { super.onOptionsItemSelected(item); if (item.getItemId() == R.id.action_show_parent) { if (currentRepo != null && currentRepo.parent != null) { startActivity(new UrlsManager(this).manageRepos(Uri.parse(currentRepo.parent.html_url))); } } else if (item.getItemId() == R.id.share_repo) { if (currentRepo != null) { Intent intent = getShareIntent(); startActivity(intent); } } else if (item.getItemId() == R.id.action_repo_watch) { changeWatchedStatus(); } else if (item.getItemId() == R.id.action_repo_star) { changeStarStatus(); } else if (item.getItemId() == R.id.action_repo_change_branch) { changeBranch(); } return false; }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); setTitle(""); searchView = (EditText) findViewById(R.id.searchView); final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabStrip); ViewPager viewPager = (ViewPager) findViewById(R.id.pager); searchReposFragment = SearchReposFragment.newInstance(null); searchUsersFragment = SearchUsersFragment.newInstance(null); List<Fragment> listFragments = new ArrayList<>(); listFragments.add(searchReposFragment); listFragments.add(searchUsersFragment); viewPager.setAdapter( new NavigationPagerAdapter(getSupportFragmentManager(), getResources(), listFragments)); tabLayout.setupWithViewPager(viewPager); searchView.setOnEditorActionListener( new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) { if (textView.length() > 0) { switch (actionId) { case EditorInfo.IME_ACTION_DONE: case EditorInfo.IME_ACTION_SEARCH: case EditorInfo.IME_ACTION_SEND: case EditorInfo.IME_ACTION_NEXT: case EditorInfo.IME_ACTION_GO: if (textView.getText() != null) { search(textView.getText().toString()); } break; } } return false; } }); subscription = RxTextView.textChanges(searchView) .filter( new Func1<CharSequence, Boolean>() { @Override public Boolean call(CharSequence s) { return s.length() >= 3; } }) .throttleLast(100, TimeUnit.MILLISECONDS) .debounce(250, TimeUnit.MILLISECONDS) .subscribeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( new Subscriber<CharSequence>() { @Override public void onCompleted() {} @Override public void onError(Throwable e) {} @Override public void onNext(CharSequence charSequence) { search(charSequence.toString()); } }); }
@Override protected void onDestroy() { subscription.unsubscribe(); super.onDestroy(); }