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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
ash / glanceables / classroom / glanceables_classroom_student_view.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_GLANCEABLES_CLASSROOM_GLANCEABLES_CLASSROOM_STUDENT_VIEW_H_
#define ASH_GLANCEABLES_CLASSROOM_GLANCEABLES_CLASSROOM_STUDENT_VIEW_H_
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "ash/ash_export.h"
#include "ash/glanceables/common/glanceables_time_management_bubble_view.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "ui/base/metadata/metadata_header_macros.h"
class GURL;
class PrefRegistrySimple;
class PrefService;
namespace views {
class Label;
} // namespace views
namespace ash {
struct GlanceablesClassroomAssignment;
// This enum is used for metrics, so enum values should not be changed. New enum
// values can be added, but existing enums must never be renumbered or deleted
// and reused.
enum class StudentAssignmentsListType {
kAssigned = 0,
kNoDueDate = 1,
kMissing = 2,
kDone = 3,
kMaxValue = kDone
};
class ASH_EXPORT GlanceablesClassroomStudentView
: public GlanceablesTimeManagementBubbleView {
METADATA_HEADER(GlanceablesClassroomStudentView,
GlanceablesTimeManagementBubbleView)
public:
GlanceablesClassroomStudentView();
GlanceablesClassroomStudentView(const GlanceablesClassroomStudentView&) =
delete;
GlanceablesClassroomStudentView& operator=(
const GlanceablesClassroomStudentView&) = delete;
~GlanceablesClassroomStudentView() override;
// Registers syncable user profile prefs with the specified `registry`.
static void RegisterUserProfilePrefs(PrefRegistrySimple* registry);
// Clears any student glanceables state from user `pref_services`.
static void ClearUserStatePrefs(PrefService* pref_service);
// Invalidates any pending assignments requests. Called when the
// glanceables bubble widget starts closing to avoid unnecessary UI updates.
void CancelUpdates();
private:
// GlanceablesTimeManagementBubbleView:
void OnHeaderIconPressed() override;
void OnFooterButtonPressed() override;
void SelectedListChanged() override;
void AnimateResize(ResizeAnimation::Type resize_type) override;
// Opens classroom url.
void OpenUrl(const GURL& url) const;
// Called when an item view is pressed/clicked on.
void OnItemViewPressed(bool initial_list_selected, const GURL& url);
// Handle switching between assignment lists.
void SelectedAssignmentListChanged(bool initial_update);
// Handles received assignments by rendering them in `list_container_view_`.
void OnGetAssignments(
const std::u16string& list_name,
bool initial_update,
bool success,
std::vector<std::unique_ptr<GlanceablesClassroomAssignment>> assignments);
// Owned by views hierarchy.
raw_ptr<views::Label> empty_list_label_ = nullptr;
// Total number of assignments in the selected assignment list.
size_t total_assignments_ = 0u;
// Time stamp of when the view was created.
const base::Time shown_time_;
// Records the time when the bubble was about to request an assignment list.
// Used for metrics.
base::TimeTicks assignments_requested_time_;
// The start time that a selected assignment list is shown.
std::optional<base::TimeTicks> list_shown_start_time_;
// Whether the first assignment list has been shown in this view's lifetime.
bool first_assignment_list_shown_ = false;
// The number of times that the selected list has changed during the lifetime
// of this view.
int selected_list_change_count_ = 0;
// The currently selected assignment list.
StudentAssignmentsListType selected_list_type_ =
StudentAssignmentsListType::kAssigned;
base::WeakPtrFactory<GlanceablesClassroomStudentView> weak_ptr_factory_{this};
};
} // namespace ash
#endif // ASH_GLANCEABLES_CLASSROOM_GLANCEABLES_CLASSROOM_STUDENT_VIEW_H_