PackageInfo: Added setting rating summary before any ratings are known.
Fleshed out RatingSummary.
This commit is contained in:
@@ -374,6 +374,62 @@ UserRating::operator!=(const UserRating& other) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - RatingSummary
|
||||||
|
|
||||||
|
|
||||||
|
RatingSummary::RatingSummary()
|
||||||
|
:
|
||||||
|
averageRating(0.0f),
|
||||||
|
ratingCount(0)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 5; i++)
|
||||||
|
ratingCountByStar[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RatingSummary::RatingSummary(const RatingSummary& other)
|
||||||
|
{
|
||||||
|
*this = other;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RatingSummary&
|
||||||
|
RatingSummary::operator=(const RatingSummary& other)
|
||||||
|
{
|
||||||
|
averageRating = other.averageRating;
|
||||||
|
ratingCount = other.ratingCount;
|
||||||
|
|
||||||
|
for (int i = 0; i < 5; i++)
|
||||||
|
ratingCountByStar[i] = other.ratingCountByStar[i];
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
RatingSummary::operator==(const RatingSummary& other) const
|
||||||
|
{
|
||||||
|
if (averageRating != other.averageRating
|
||||||
|
|| ratingCount != other.ratingCount) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
if (ratingCountByStar[i] != other.ratingCountByStar[i])
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
RatingSummary::operator!=(const RatingSummary& other) const
|
||||||
|
{
|
||||||
|
return !(*this == other);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - PublisherInfo
|
// #pragma mark - PublisherInfo
|
||||||
|
|
||||||
|
|
||||||
@@ -508,6 +564,7 @@ PackageInfo::PackageInfo()
|
|||||||
fFullDescription(),
|
fFullDescription(),
|
||||||
fChangelog(),
|
fChangelog(),
|
||||||
fUserRatings(),
|
fUserRatings(),
|
||||||
|
fCachedRatingSummary(),
|
||||||
fScreenshots(),
|
fScreenshots(),
|
||||||
fState(NONE),
|
fState(NONE),
|
||||||
fDownloadProgress(0.0),
|
fDownloadProgress(0.0),
|
||||||
@@ -531,6 +588,7 @@ PackageInfo::PackageInfo(const BString& title,
|
|||||||
fChangelog(),
|
fChangelog(),
|
||||||
fCategories(),
|
fCategories(),
|
||||||
fUserRatings(),
|
fUserRatings(),
|
||||||
|
fCachedRatingSummary(),
|
||||||
fScreenshots(),
|
fScreenshots(),
|
||||||
fState(NONE),
|
fState(NONE),
|
||||||
fDownloadProgress(0.0),
|
fDownloadProgress(0.0),
|
||||||
@@ -551,6 +609,7 @@ PackageInfo::PackageInfo(const PackageInfo& other)
|
|||||||
fChangelog(other.fChangelog),
|
fChangelog(other.fChangelog),
|
||||||
fCategories(other.fCategories),
|
fCategories(other.fCategories),
|
||||||
fUserRatings(other.fUserRatings),
|
fUserRatings(other.fUserRatings),
|
||||||
|
fCachedRatingSummary(other.fCachedRatingSummary),
|
||||||
fScreenshots(other.fScreenshots),
|
fScreenshots(other.fScreenshots),
|
||||||
fState(other.fState),
|
fState(other.fState),
|
||||||
fInstallationLocations(other.fInstallationLocations),
|
fInstallationLocations(other.fInstallationLocations),
|
||||||
@@ -573,6 +632,7 @@ PackageInfo::operator=(const PackageInfo& other)
|
|||||||
fChangelog = other.fChangelog;
|
fChangelog = other.fChangelog;
|
||||||
fCategories = other.fCategories;
|
fCategories = other.fCategories;
|
||||||
fUserRatings = other.fUserRatings;
|
fUserRatings = other.fUserRatings;
|
||||||
|
fCachedRatingSummary = other.fCachedRatingSummary;
|
||||||
fScreenshots = other.fScreenshots;
|
fScreenshots = other.fScreenshots;
|
||||||
fState = other.fState;
|
fState = other.fState;
|
||||||
fInstallationLocations = other.fInstallationLocations;
|
fInstallationLocations = other.fInstallationLocations;
|
||||||
@@ -595,6 +655,7 @@ PackageInfo::operator==(const PackageInfo& other) const
|
|||||||
&& fChangelog == other.fChangelog
|
&& fChangelog == other.fChangelog
|
||||||
&& fCategories == other.fCategories
|
&& fCategories == other.fCategories
|
||||||
&& fUserRatings == other.fUserRatings
|
&& fUserRatings == other.fUserRatings
|
||||||
|
&& fCachedRatingSummary == other.fCachedRatingSummary
|
||||||
&& fScreenshots == other.fScreenshots
|
&& fScreenshots == other.fScreenshots
|
||||||
&& fState == other.fState
|
&& fState == other.fState
|
||||||
&& fFlags == other.fFlags
|
&& fFlags == other.fFlags
|
||||||
@@ -697,9 +758,24 @@ PackageInfo::AddUserRating(const UserRating& rating)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PackageInfo::SetRatingSummary(const RatingSummary& summary)
|
||||||
|
{
|
||||||
|
if (fCachedRatingSummary == summary)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fCachedRatingSummary = summary;
|
||||||
|
|
||||||
|
_NotifyListeners(PKG_CHANGED_RATINGS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
RatingSummary
|
RatingSummary
|
||||||
PackageInfo::CalculateRatingSummary() const
|
PackageInfo::CalculateRatingSummary() const
|
||||||
{
|
{
|
||||||
|
if (fUserRatings.CountItems() == 0)
|
||||||
|
return fCachedRatingSummary;
|
||||||
|
|
||||||
RatingSummary summary;
|
RatingSummary summary;
|
||||||
summary.ratingCount = fUserRatings.CountItems();
|
summary.ratingCount = fUserRatings.CountItems();
|
||||||
summary.averageRating = 0.0f;
|
summary.averageRating = 0.0f;
|
||||||
|
|||||||
@@ -127,6 +127,14 @@ typedef List<UserRating, false> UserRatingList;
|
|||||||
|
|
||||||
|
|
||||||
class RatingSummary {
|
class RatingSummary {
|
||||||
|
public:
|
||||||
|
RatingSummary();
|
||||||
|
RatingSummary(const RatingSummary& other);
|
||||||
|
|
||||||
|
RatingSummary& operator=(const RatingSummary& other);
|
||||||
|
bool operator==(const RatingSummary& other) const;
|
||||||
|
bool operator!=(const RatingSummary& other) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
float averageRating;
|
float averageRating;
|
||||||
int ratingCount;
|
int ratingCount;
|
||||||
@@ -269,6 +277,7 @@ public:
|
|||||||
bool AddUserRating(const UserRating& rating);
|
bool AddUserRating(const UserRating& rating);
|
||||||
const UserRatingList& UserRatings() const
|
const UserRatingList& UserRatings() const
|
||||||
{ return fUserRatings; }
|
{ return fUserRatings; }
|
||||||
|
void SetRatingSummary(const RatingSummary& summary);
|
||||||
RatingSummary CalculateRatingSummary() const;
|
RatingSummary CalculateRatingSummary() const;
|
||||||
|
|
||||||
bool AddScreenshot(const BitmapRef& screenshot);
|
bool AddScreenshot(const BitmapRef& screenshot);
|
||||||
@@ -293,6 +302,7 @@ private:
|
|||||||
BString fChangelog;
|
BString fChangelog;
|
||||||
CategoryList fCategories;
|
CategoryList fCategories;
|
||||||
UserRatingList fUserRatings;
|
UserRatingList fUserRatings;
|
||||||
|
RatingSummary fCachedRatingSummary;
|
||||||
BitmapList fScreenshots;
|
BitmapList fScreenshots;
|
||||||
PackageState fState;
|
PackageState fState;
|
||||||
PackageInstallationLocationSet
|
PackageInstallationLocationSet
|
||||||
|
|||||||
Reference in New Issue
Block a user