Skip to content

Commit

Permalink
Point emote references to new component
Browse files Browse the repository at this point in the history
  • Loading branch information
douglascdev committed May 21, 2024
1 parent 48b6689 commit b94390a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 58 deletions.
52 changes: 4 additions & 48 deletions components/emote_gif.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package components

import (
"bytes"
"errors"
"image"
"image/draw"
"image/gif"
Expand All @@ -13,11 +12,10 @@ import (
"time"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/storage"
"fyne.io/fyne/v2/widget"
"github.com/Hashy-Software/hasherino-go/hasherino"
)

// EmoteGif widget shows a Gif image with many frames.
Expand All @@ -33,59 +31,17 @@ type EmoteGif struct {
runLock sync.RWMutex

// custom attributes
emote *Emote
emote *hasherino.Emote
clickCallback func(string) error
lazyLoad bool
}

type EmoteSourceEnum int64

const (
Twitch EmoteSourceEnum = iota
SevenTV
)

type Emote struct {
Id string
Source EmoteSourceEnum
Name string
Animated bool
TempFile string
}

func (e *Emote) GetUrl() (string, error) {
var result string
switch e.Source {
case Twitch:
result = "https://static-cdn.jtvnw.net/emoticons/v2/" + e.Id + "/default/dark/2.0"
case SevenTV:
result = "https://cdn.7tv.app/emote/" + e.Id + "/2x"
default:
return "", errors.New("Unknown emote source")
}
return result + e.getUrlExtension(), nil
}

func (e *Emote) getUrlExtension() string {
switch e.Source {
case Twitch:
return ""
case SevenTV:
if e.Animated {
return ".gif"
}
return ".png"
default:
return ".png"
}
}

var emptyImageResource = &fyne.StaticResource{StaticName: "empty.png", StaticContent: []byte{}}

// NewEmoteGif creates a new widget loaded to show the specified image resource.
// If there is an error loading the image it will be returned in the error value.
// If lazyLoad is true, only load the real image when Start() is called
func NewEmoteGif(emote *Emote, clickCallback func(string) error, lazyLoad bool) (*EmoteGif, error) {
func NewEmoteGif(emote *hasherino.Emote, clickCallback func(string) error, lazyLoad bool) (*EmoteGif, error) {
ret := newGif()
ret.emote = emote
ret.clickCallback = clickCallback
Expand All @@ -102,7 +58,7 @@ func NewEmoteGif(emote *Emote, clickCallback func(string) error, lazyLoad bool)
return ret, ret.LoadResource(res)
}

func tempFileResource(emote *Emote) (*fyne.StaticResource, error) {
func tempFileResource(emote *hasherino.Emote) (*fyne.StaticResource, error) {
s, err := os.Stat(emote.TempFile)
if err != nil {
return nil, err
Expand Down
14 changes: 6 additions & 8 deletions fyne_ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"

"github.com/Hashy-Software/hasherino-go/components"
"github.com/Hashy-Software/hasherino-go/hasherino"
)

Expand Down Expand Up @@ -198,12 +199,6 @@ func NewSettingsTabs(hc *hasherino.HasherinoController, w fyne.Window) *containe
return tabs
}

// type EmoteWidget struct {
// fyne.Tappable
//
// Emote *fyne.CanvasObject
// }

func NewEmoteCanvasObject(emote *hasherino.Emote) (*fyne.CanvasObject, error) {
url, err := emote.GetUrl()
if err != nil {
Expand Down Expand Up @@ -352,13 +347,16 @@ func NewChatTab(
defer wg.Done()

for _, emote := range emoteSlice {
imgCanvas, err := NewEmoteCanvasObject(emote)
imgCanvas, err := components.NewEmoteGif(emote, func(text string) error {
msgEntry.SetText(text + msgEntry.Text + " ")
return nil
}, true)
if err != nil {
log.Println(err)
continue
}
mutex.Lock()
images = append(images, *imgCanvas)
images = append(images, imgCanvas)
mutex.Unlock()
}
}(emoteSlice)
Expand Down
4 changes: 2 additions & 2 deletions hasherino/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ func (e *Emote) GetUrl() (string, error) {
default:
return "", errors.New("Unknown emote source")
}
return result + e.getUrlExtension(), nil
return result + e.GetUrlExtension(), nil
}

func (e *Emote) getUrlExtension() string {
func (e *Emote) GetUrlExtension() string {
switch e.Source {
case Twitch:
return ""
Expand Down

0 comments on commit b94390a

Please sign in to comment.