Esempio n. 1
0
  private void updateComputer(ComputerDetails details) {
    ComputerObject existingEntry = null;

    for (int i = 0; i < pcGridAdapter.getCount(); i++) {
      ComputerObject computer = (ComputerObject) pcGridAdapter.getItem(i);

      // Check if this is the same computer
      if (details.uuid.equals(computer.details.uuid)) {
        existingEntry = computer;
        break;
      }
    }

    if (existingEntry != null) {
      // Replace the information in the existing entry
      existingEntry.details = details;
    } else {
      // Add a new entry
      pcGridAdapter.addComputer(new ComputerObject(details));

      // Remove the "Discovery in progress" view
      noPcFoundLayout.setVisibility(View.INVISIBLE);
    }

    // Notify the view that the data has changed
    pcGridAdapter.notifyDataSetChanged();
  }
Esempio n. 2
0
  private void removeComputer(ComputerDetails details) {
    for (int i = 0; i < pcGridAdapter.getCount(); i++) {
      ComputerObject computer = (ComputerObject) pcGridAdapter.getItem(i);

      if (details.equals(computer.details)) {
        pcGridAdapter.removeComputer(computer);
        pcGridAdapter.notifyDataSetChanged();

        if (pcGridAdapter.getCount() == 0) {
          // Show the "Discovery in progress" view
          noPcFoundLayout.setVisibility(View.VISIBLE);
        }

        break;
      }
    }
  }
Esempio n. 3
0
  private void initializeViews() {
    setContentView(R.layout.activity_pc_view);

    UiHelper.notifyNewRootView(this);

    // Set default preferences if we've never been run
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    // Setup the list view
    ImageButton settingsButton = (ImageButton) findViewById(R.id.settingsButton);
    ImageButton addComputerButton = (ImageButton) findViewById(R.id.manuallyAddPc);

    settingsButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            startActivity(new Intent(PcView.this, StreamSettings.class));
          }
        });
    addComputerButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent i = new Intent(PcView.this, AddComputerManually.class);
            startActivity(i);
          }
        });

    getFragmentManager()
        .beginTransaction()
        .replace(R.id.pcFragmentContainer, new AdapterFragment())
        .commitAllowingStateLoss();

    noPcFoundLayout = (RelativeLayout) findViewById(R.id.no_pc_found_layout);
    if (pcGridAdapter.getCount() == 0) {
      noPcFoundLayout.setVisibility(View.VISIBLE);
    } else {
      noPcFoundLayout.setVisibility(View.INVISIBLE);
    }
    pcGridAdapter.notifyDataSetChanged();
  }