Search in sources :

Example 1 with NavController

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);
            }
        }
    });
}
Also used : NavDestination(androidx.navigation.NavDestination) Bundle(android.os.Bundle) NavController(androidx.navigation.NavController) ActivityMainBinding(com.google.firebase.quickstart.database.databinding.ActivityMainBinding) View(android.view.View)

Example 2 with NavController

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);
}
Also used : FirebaseRecyclerOptions(com.firebase.ui.database.FirebaseRecyclerOptions) PostViewHolder(com.google.firebase.quickstart.database.java.viewholder.PostViewHolder) Query(com.google.firebase.database.Query) DatabaseReference(com.google.firebase.database.DatabaseReference) Post(com.google.firebase.quickstart.database.java.models.Post) ViewGroup(android.view.ViewGroup) Bundle(android.os.Bundle) NavController(androidx.navigation.NavController) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) LayoutInflater(android.view.LayoutInflater)

Example 3 with NavController

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);
}
Also used : LifecycleDisposable(org.thoughtcrime.securesms.util.LifecycleDisposable) Disposable(io.reactivex.rxjava3.disposables.Disposable) NavController(androidx.navigation.NavController)

Example 4 with NavController

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));
    }
}
Also used : NavController(androidx.navigation.NavController)

Example 5 with NavController

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);
}
Also used : NavController(androidx.navigation.NavController)

Aggregations

NavController (androidx.navigation.NavController)6 Bundle (android.os.Bundle)3 View (android.view.View)2 LayoutInflater (android.view.LayoutInflater)1 ViewGroup (android.view.ViewGroup)1 NavDestination (androidx.navigation.NavDestination)1 NavDirections (androidx.navigation.NavDirections)1 NavGraph (androidx.navigation.NavGraph)1 NavHostFragment (androidx.navigation.fragment.NavHostFragment)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 FirebaseRecyclerOptions (com.firebase.ui.database.FirebaseRecyclerOptions)1 DatabaseReference (com.google.firebase.database.DatabaseReference)1 Query (com.google.firebase.database.Query)1 ActivityMainBinding (com.google.firebase.quickstart.database.databinding.ActivityMainBinding)1 Post (com.google.firebase.quickstart.database.java.models.Post)1 PostViewHolder (com.google.firebase.quickstart.database.java.viewholder.PostViewHolder)1 Disposable (io.reactivex.rxjava3.disposables.Disposable)1 LifecycleDisposable (org.thoughtcrime.securesms.util.LifecycleDisposable)1