From 5ed50dff53ccc663634019914d6027c005e11237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 19 Jul 2015 15:26:01 -0700 Subject: [PATCH] Add icon support to App --- index.go | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/index.go b/index.go index 3d16d02..653b9f5 100644 --- a/index.go +++ b/index.go @@ -31,6 +31,7 @@ type App struct { ID string `xml:"id"` Name string `xml:"name"` Summary string `xml:"summary"` + Icon string `xml:"icon"` Desc string `xml:"desc"` License string `xml:"license"` Categs CommaList `xml:"categories"` @@ -49,8 +50,49 @@ type App struct { CurApk *Apk } -func (app *App) TextDesc(w io.Writer) { - reader := strings.NewReader(app.Desc) +type IconDensity uint + +const ( + UnknownDensity IconDensity = 0 + LowDensity IconDensity = 120 + MediumDensity IconDensity = 160 + HighDensity IconDensity = 240 + XHighDensity IconDensity = 320 + XXHighDensity IconDensity = 480 + XXXHighDensity IconDensity = 640 +) + +func getIconsDir(density IconDensity) string { + if density == UnknownDensity { + return "icons" + } + for _, d := range [...]IconDensity{ + XXXHighDensity, + XXHighDensity, + XHighDensity, + HighDensity, + MediumDensity, + } { + if density >= d { + return fmt.Sprintf("icons-%d", d) + } + } + return fmt.Sprintf("icons-%d", LowDensity) +} + +func (a *App) IconURLForDensity(density IconDensity) string { + if a.CurApk == nil { + return "" + } + return fmt.Sprintf("%s/%s/%s", a.CurApk.Repo.URL, getIconsDir(density), a.Icon) +} + +func (a *App) IconURL() string { + return a.IconURLForDensity(UnknownDensity) +} + +func (a *App) TextDesc(w io.Writer) { + reader := strings.NewReader(a.Desc) decoder := xml.NewDecoder(reader) firstParagraph := true linePrefix := ""