Search in sources :

Example 1 with FragmentProfile

use of com.bigyoshi.qrhunt.player.FragmentProfile in project QRHunt by CMPUT301W22T00.

the class MainActivity method onCreate.

/**
 * Sets up screen (toolbar, bottom menu), initializes player if need be
 * manages which fragment the app is in and adjusts accordingly, & passes things from
 * fragment to fragment
 *
 * @param savedInstanceState SavedInstanceState
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    binding = ActivityMainBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    db = FirebaseFirestore.getInstance();
    Toolbar toolbar = findViewById(R.id.top_navigation_view);
    setSupportActionBar(toolbar);
    ActionBar actionbar = getSupportActionBar();
    actionbar.setDisplayShowTitleEnabled(false);
    actionbar.setDisplayShowCustomEnabled(true);
    player = new Player(this);
    // This will check if the player already has an account
    if (!player.getPlayerId().matches("")) {
        player.initialize();
    }
    scoreView = toolbar.findViewById(R.id.top_scanner_score);
    updateFirebaseListeners();
    // Passing each menu ID as a set of Ids because each
    // menu should be considered as top level destinations.
    NavController navController = Navigation.findNavController(this, R.id.main_bottom_navigation_host_fragment);
    NavigationUI.setupWithNavController(binding.bottomNavigationView, navController);
    navProfile = findViewById(R.id.top_navigation_profile);
    navProfile.setOnClickListener(view -> {
        binding.bottomNavigationView.setVisibility(View.INVISIBLE);
        FragmentProfile profile = new FragmentProfile();
        Bundle bundle = new Bundle();
        bundle.putSerializable("player", player);
        profile.setArguments(bundle);
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.container, profile, "profile");
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();
    });
    navSearch = findViewById(R.id.top_navigation_search);
    navSearch.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            binding.bottomNavigationView.setVisibility(View.INVISIBLE);
            actionbar.hide();
            FragmentSearch search = new FragmentSearch(player, navController.getCurrentDestination().getId());
            FragmentManager fragmentManager = getSupportFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.container, search, "search");
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();
        }
    });
    // determines current fragment so the right button is visible
    navController.addOnDestinationChangedListener((navController1, navDestination, bundle) -> {
        if (navDestination.getId() == R.id.navigation_map) {
            actionbar.show();
            navSearch.setVisibility(View.GONE);
            // TEMPORARY
            navProfile.setVisibility(View.GONE);
        }
        if (navDestination.getId() == R.id.navigation_scanner) {
            actionbar.show();
            Bundle result = new Bundle();
            result.putSerializable("player", player);
            getSupportFragmentManager().setFragmentResult("getPlayer", result);
            navSearch.setVisibility(View.VISIBLE);
            navProfile.setVisibility(View.VISIBLE);
        }
        if (navDestination.getId() == R.id.navigation_leaderBoard) {
            actionbar.hide();
            binding.bottomNavigationView.setVisibility(View.INVISIBLE);
        }
    });
    Intent intent = this.getIntent();
    Bundle s = intent.getExtras();
    int prevFrag = -1;
    if (s != null) {
        prevFrag = (int) s.getSerializable("previous");
    }
    if (prevFrag == R.id.navigation_map) {
        actionbar.show();
        navSearch.setVisibility(View.GONE);
    // Need to figure out how to go to the Map -> currently goes to Scanner (start dest)
    // For now I made this invisible
    } else if (prevFrag == R.id.navigation_scanner) {
        actionbar.show();
        navSearch.setVisibility(View.VISIBLE);
    }
}
Also used : Player(com.bigyoshi.qrhunt.player.Player) Bundle(android.os.Bundle) NavController(androidx.navigation.NavController) Intent(android.content.Intent) FragmentProfile(com.bigyoshi.qrhunt.player.FragmentProfile) View(android.view.View) TextView(android.widget.TextView) FragmentManager(androidx.fragment.app.FragmentManager) FragmentSearch(com.bigyoshi.qrhunt.bottom_navigation.search.FragmentSearch) FragmentTransaction(androidx.fragment.app.FragmentTransaction) ActionBar(androidx.appcompat.app.ActionBar) Toolbar(androidx.appcompat.widget.Toolbar)

Example 2 with FragmentProfile

use of com.bigyoshi.qrhunt.player.FragmentProfile in project QRHunt by CMPUT301W22T00.

the class FragmentQrProfile method onCreateView.

/**
 * Creates the view for deleting a QR code
 *
 * @param inflater           Inflater
 * @param container          Where the fragment is contained
 * @param savedInstanceState SavedInstanceState
 * @return View
 */
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_qr_player_profile, container, false);
    // Display score
    TextView showScore = view.findViewById(R.id.qr_profile_qr_score);
    showScore.setText(String.valueOf(currentQR.getScore()) + " Points");
    // Display numScan
    TextView showNumScanned = view.findViewById(R.id.qr_profile_num_scanned);
    // HARD CODED FOR NOW
    showNumScanned.setText("01");
    // Display location
    TextView showLatLong = view.findViewById(R.id.qr_profile_qr_location);
    QrLocation qrLocation = currentQR.getLocation();
    if (qrLocation != null) {
        String strLatitude = Location.convert(qrLocation.getLatitude(), Location.FORMAT_DEGREES);
        String strLongitude = Location.convert(qrLocation.getLongitude(), Location.FORMAT_DEGREES);
        showLatLong.setText(strLatitude + ", " + strLongitude);
    } else {
        showLatLong.setText("LOCATION NOT GIVEN");
    }
    // attach photo
    ImageView showPic = view.findViewById(R.id.qr_profile_image_placeholder);
    if (currentQR.getImageUrl() != null) {
        Picasso.get().load(currentQR.getImageUrl()).into(showPic);
    }
    showPic.setCropToPadding(true);
    TextView userName = view.findViewById(R.id.qr_profile_player_username);
    userName.setText(player.getUsername());
    Button deleteButton = view.findViewById(R.id.button_delete);
    if (player.isAdmin() || player.getPlayerId().matches(currentQR.getPlayerId())) {
        deleteButton.setVisibility(View.VISIBLE);
    }
    deleteButton.setOnClickListener(view1 -> {
        FragmentProfile parentFrag = ((FragmentProfile) this.getParentFragment());
        parentFrag.libraryRemoveQR(pos, currentQR);
        getFragmentManager().beginTransaction().remove(this).commit();
    });
    ImageButton backButton = view.findViewById(R.id.qr_profile_back_button);
    backButton.setOnClickListener(view2 -> {
        getFragmentManager().beginTransaction().remove(FragmentQrProfile.this).commit();
    });
    return view;
}
Also used : ImageButton(android.widget.ImageButton) ImageButton(android.widget.ImageButton) Button(android.widget.Button) TextView(android.widget.TextView) ImageView(android.widget.ImageView) FragmentProfile(com.bigyoshi.qrhunt.player.FragmentProfile) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View)

Aggregations

View (android.view.View)2 TextView (android.widget.TextView)2 FragmentProfile (com.bigyoshi.qrhunt.player.FragmentProfile)2 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Button (android.widget.Button)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1 ActionBar (androidx.appcompat.app.ActionBar)1 Toolbar (androidx.appcompat.widget.Toolbar)1 FragmentManager (androidx.fragment.app.FragmentManager)1 FragmentTransaction (androidx.fragment.app.FragmentTransaction)1 NavController (androidx.navigation.NavController)1 FragmentSearch (com.bigyoshi.qrhunt.bottom_navigation.search.FragmentSearch)1 Player (com.bigyoshi.qrhunt.player.Player)1