use of androidx.navigation.NavController in project quickstart-android by firebase.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
fab = binding.fab;
navController = Navigation.findNavController(this, R.id.nav_host_fragment);
navController.setGraph(R.navigation.nav_graph_java);
navController.addOnDestinationChangedListener(new NavController.OnDestinationChangedListener() {
@Override
public void onDestinationChanged(@NonNull NavController controller, @NonNull NavDestination destination, @Nullable Bundle arguments) {
if (destination.getId() == R.id.MainFragment) {
fab.setVisibility(View.VISIBLE);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
navController.navigate(R.id.action_MainFragment_to_NewPostFragment);
}
});
} else {
fab.setVisibility(View.GONE);
}
}
});
}
use of androidx.navigation.NavController in project quickstart-android by firebase.
the class PostListFragment method onActivityCreated.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Set up Layout Manager, reverse layout
mManager = new LinearLayoutManager(getActivity());
mManager.setReverseLayout(true);
mManager.setStackFromEnd(true);
mRecycler.setLayoutManager(mManager);
// Set up FirebaseRecyclerAdapter with the Query
Query postsQuery = getQuery(mDatabase);
FirebaseRecyclerOptions options = new FirebaseRecyclerOptions.Builder<Post>().setQuery(postsQuery, Post.class).build();
mAdapter = new FirebaseRecyclerAdapter<Post, PostViewHolder>(options) {
@Override
public PostViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
return new PostViewHolder(inflater.inflate(R.layout.item_post, viewGroup, false));
}
@Override
protected void onBindViewHolder(PostViewHolder viewHolder, int position, final Post model) {
final DatabaseReference postRef = getRef(position);
// Set click listener for the whole post view
final String postKey = postRef.getKey();
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Launch PostDetailFragment
NavController navController = Navigation.findNavController(requireActivity(), R.id.nav_host_fragment);
Bundle args = new Bundle();
args.putString(PostDetailFragment.EXTRA_POST_KEY, postKey);
navController.navigate(R.id.action_MainFragment_to_PostDetailFragment, args);
}
});
// Determine if the current user has liked this post and set UI accordingly
if (model.stars.containsKey(getUid())) {
viewHolder.starView.setImageResource(R.drawable.ic_toggle_star_24);
} else {
viewHolder.starView.setImageResource(R.drawable.ic_toggle_star_outline_24);
}
// Bind Post to ViewHolder, setting OnClickListener for the star button
viewHolder.bindToPost(model, new View.OnClickListener() {
@Override
public void onClick(View starView) {
// Need to write to both places the post is stored
DatabaseReference globalPostRef = mDatabase.child("posts").child(postRef.getKey());
DatabaseReference userPostRef = mDatabase.child("user-posts").child(model.uid).child(postRef.getKey());
// Run two transactions
onStarClicked(globalPostRef);
onStarClicked(userPostRef);
}
});
}
};
mRecycler.setAdapter(mAdapter);
}
use of androidx.navigation.NavController in project Signal-Android by WhisperSystems.
the class EnterPhoneNumberFragment method requestVerificationCode.
private void requestVerificationCode(@NonNull Mode mode) {
NavController navController = NavHostFragment.findNavController(this);
Disposable request = viewModel.requestVerificationCode(mode).doOnSubscribe(unused -> SignalStore.account().setRegistered(false)).observeOn(AndroidSchedulers.mainThread()).subscribe(processor -> {
if (processor.hasResult()) {
SafeNavigation.safeNavigate(navController, EnterPhoneNumberFragmentDirections.actionEnterVerificationCode());
} else if (processor.localRateLimit()) {
Log.i(TAG, "Unable to request sms code due to local rate limit");
SafeNavigation.safeNavigate(navController, EnterPhoneNumberFragmentDirections.actionEnterVerificationCode());
} else if (processor.captchaRequired()) {
Log.i(TAG, "Unable to request sms code due to captcha required");
SafeNavigation.safeNavigate(navController, EnterPhoneNumberFragmentDirections.actionRequestCaptcha());
} else if (processor.rateLimit()) {
Log.i(TAG, "Unable to request sms code due to rate limit");
Toast.makeText(register.getContext(), R.string.RegistrationActivity_rate_limited_to_service, Toast.LENGTH_LONG).show();
} else if (processor.isImpossibleNumber()) {
Log.w(TAG, "Impossible number", processor.getError());
Dialogs.showAlertDialog(requireContext(), getString(R.string.RegistrationActivity_invalid_number), String.format(getString(R.string.RegistrationActivity_the_number_you_specified_s_is_invalid), viewModel.getNumber().getFullFormattedNumber()));
} else if (processor.isNonNormalizedNumber()) {
handleNonNormalizedNumberError(processor.getOriginalNumber(), processor.getNormalizedNumber(), mode);
} else {
Log.i(TAG, "Unknown error during verification code request", processor.getError());
Toast.makeText(register.getContext(), R.string.RegistrationActivity_unable_to_connect_to_service, Toast.LENGTH_LONG).show();
}
cancelSpinning(register);
enableAllEntries();
});
disposables.add(request);
}
use of androidx.navigation.NavController in project Signal-Android by WhisperSystems.
the class PaymentsActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState, boolean ready) {
dynamicTheme.onCreate(this);
setContentView(R.layout.payments_activity);
NavController controller = Navigation.findNavController(this, R.id.nav_host_fragment);
controller.setGraph(R.navigation.payments_preferences);
int startingAction = getIntent().getIntExtra(EXTRA_PAYMENTS_STARTING_ACTION, R.id.paymentsHome);
if (startingAction != R.id.paymentsHome) {
SafeNavigation.safeNavigate(controller, startingAction, getIntent().getBundleExtra(EXTRA_STARTING_ARGUMENTS));
}
}
use of androidx.navigation.NavController in project Signal-Android by WhisperSystems.
the class OldDeviceTransferActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState, boolean ready) {
dynamicTheme.onCreate(this);
setContentView(R.layout.old_device_transfer_activity);
NavController controller = Navigation.findNavController(this, R.id.nav_host_fragment);
controller.setGraph(R.navigation.old_device_transfer);
}
Aggregations