1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60

ash / system / phonehub / phone_hub_more_apps_button.h [blame]

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_SYSTEM_PHONEHUB_PHONE_HUB_MORE_APPS_BUTTON_H_
#define ASH_SYSTEM_PHONEHUB_PHONE_HUB_MORE_APPS_BUTTON_H_

#include <optional>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "chromeos/ash/components/phonehub/app_stream_launcher_data_model.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/layout/table_layout.h"

namespace ash {

class AppLoadingIcon;

// A view in phone hub that displays the first three apps in a user's app
// drawer, as well as a count of how many apps they have on their phone.
class VIEWS_EXPORT PhoneHubMoreAppsButton
    : public views::Button,
      phonehub::AppStreamLauncherDataModel::Observer {
  METADATA_HEADER(PhoneHubMoreAppsButton, views::Button)

 public:
  // Only use this constructor to create a skeleton view for the LoadingView.
  // Does not process click events or load app icons.
  PhoneHubMoreAppsButton();

  PhoneHubMoreAppsButton(
      phonehub::AppStreamLauncherDataModel* app_stream_launcher_data_model,
      views::Button::PressedCallback callback);

  PhoneHubMoreAppsButton(const PhoneHubMoreAppsButton&) = delete;
  PhoneHubMoreAppsButton& operator=(const PhoneHubMoreAppsButton&) = delete;
  ~PhoneHubMoreAppsButton() override;

  void StartLoadingAnimation(std::optional<base::TimeDelta> initial_delay);
  void StopLoadingAnimation();

  // phonehub::AppStreamLauncherDataModel::Observer:
  void OnShouldShowMiniLauncherChanged() override;
  void OnAppListChanged() override;

 private:
  void InitLayout();
  void LoadAppList();

  base::TimeTicks load_app_list_latency_ = base::TimeTicks();
  raw_ptr<views::TableLayout> table_layout_ = nullptr;
  raw_ptr<phonehub::AppStreamLauncherDataModel>
      app_stream_launcher_data_model_ = nullptr;
  std::vector<raw_ptr<AppLoadingIcon, VectorExperimental>> app_loading_icons_;
};

}  // namespace ash

#endif  // ASH_SYSTEM_PHONEHUB_PHONE_HUB_MORE_APPS_BUTTON_H_