Skip to content

Commit 6665519

Browse files
committed
feats: add support for photo and photoalbum
1 parent 412f093 commit 6665519

File tree

5 files changed

+119
-1
lines changed

5 files changed

+119
-1
lines changed
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// Created by fang on 2023/4/26.
3+
//
4+
5+
#pragma once
6+
7+
#include <borealis/core/activity.hpp>
8+
#include <borealis/core/bind.hpp>
9+
10+
class GalleryView;
11+
12+
class GalleryActivity : public brls::Activity {
13+
public:
14+
// Declare that the content of this activity is the given XML file
15+
CONTENT_FROM_XML_RES("activity/gallery.xml");
16+
17+
explicit GalleryActivity(const std::vector<std::string>& data);
18+
19+
bool isTranslucent() override;
20+
21+
void onContentAvailable() override;
22+
23+
~GalleryActivity() override;
24+
25+
private:
26+
BRLS_BIND(GalleryView, gallery, "hint/gallery");
27+
28+
std::vector<std::string> galleryData;
29+
};

app/include/api/jellyfin/media.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const std::string apiBackdropImage = "/Items/{}/Images/Backdrop?format=Png&{}";
3030
// danmu plugin
3131
const std::string apiDanmuku = "/api/danmu/{}/raw";
3232

33+
const std::string apiDownload = "/Items/{}/Download?{}";
3334
const std::string apiPlayback = "/Items/{}/PlaybackInfo";
3435
const std::string apiStream = "/Videos/{}/stream?{}";
3536
const std::string apiAudio = "/Audio/{}/stream?{}";
@@ -48,6 +49,8 @@ const std::string mediaTypeMovie = "Movie";
4849
const std::string mediaTypeBoxSet = "BoxSet";
4950
const std::string mediaTypeAudio = "Audio";
5051
const std::string mediaTypeVideo = "Video";
52+
const std::string mediaTypePhoto = "Photo";
53+
const std::string mediaTypePhotoAlbum = "PhotoAlbum";
5154
const std::string mediaTypeMusicAlbum = "MusicAlbum";
5255
const std::string mediaTypeMusicVideo = "MusicVideo";
5356
const std::string mediaTypePlaylist = "Playlist";

app/src/activity/gallery_activity.cpp

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// Created by fang on 2023/4/26.
3+
//
4+
5+
#include <borealis/views/image.hpp>
6+
7+
#include "activity/gallery_activity.hpp"
8+
#include "view/gallery_view.hpp"
9+
#include "utils/image.hpp"
10+
11+
const std::string ImageGalleryItemXML = R"xml(
12+
<brls:Box
13+
width="100%"
14+
height="100%"
15+
axis="row"
16+
grow="1"
17+
justifyContent="center"
18+
alignItems="center">
19+
20+
<brls:Image
21+
margin="40"
22+
id="gallery/image"/>
23+
</brls:Box>
24+
)xml";
25+
26+
class NetImageGalleryItem : public GalleryItem {
27+
public:
28+
explicit NetImageGalleryItem(const std::string& url) {
29+
this->inflateFromXMLString(ImageGalleryItemXML);
30+
this->image->setImageFromRes("img/video-card-bg.png");
31+
Image::with(this->image, url);
32+
}
33+
34+
~NetImageGalleryItem() override { Image::cancel(this->image); }
35+
36+
private:
37+
BRLS_BIND(brls::Image, image, "gallery/image");
38+
};
39+
40+
GalleryActivity::GalleryActivity(const std::vector<std::string>& data) : galleryData(data) {
41+
brls::Logger::debug("GalleryActivity: create");
42+
}
43+
44+
void GalleryActivity::onContentAvailable() {
45+
brls::Logger::debug("GalleryActivity: onContentAvailable");
46+
gallery->setIndicatorPosition(0.97);
47+
for (auto& i : galleryData) {
48+
gallery->addCustomView(new NetImageGalleryItem(i));
49+
}
50+
}
51+
52+
GalleryActivity::~GalleryActivity() { brls::Logger::debug("GalleryActivity: delete"); }
53+
54+
bool GalleryActivity::isTranslucent() { return true; }

app/src/view/video_source.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "activity/player_view.hpp"
2+
#include "activity/gallery_activity.hpp"
23
#include "tab/media_collection.hpp"
34
#include "tab/media_series.hpp"
45
#include "tab/music_album.hpp"
@@ -62,7 +63,8 @@ void VideoDataSource::onItemSelected(brls::Box* recycler, size_t index) {
6263

6364
if (item.Type == jellyfin::mediaTypeSeries) {
6465
recycler->present(new MediaSeries(item.Id));
65-
} else if (item.Type == jellyfin::mediaTypeFolder || item.Type == jellyfin::mediaTypeBoxSet) {
66+
} else if (item.Type == jellyfin::mediaTypeFolder || item.Type == jellyfin::mediaTypeBoxSet ||
67+
item.Type == jellyfin::mediaTypePhotoAlbum) {
6668
recycler->present(new MediaCollection(item.Id));
6769
} else if (item.Type == jellyfin::mediaTypeMovie || item.Type == jellyfin::mediaTypeMusicVideo ||
6870
item.Type == jellyfin::mediaTypeVideo) {
@@ -76,6 +78,15 @@ void VideoDataSource::onItemSelected(brls::Box* recycler, size_t index) {
7678
recycler->present(new MusicAlbum(item));
7779
} else if (item.Type == jellyfin::mediaTypePlaylist) {
7880
recycler->present(new Playlist(item));
81+
} else if (item.Type == jellyfin::mediaTypePhoto) {
82+
auto& conf = AppConfig::instance();
83+
std::string query = HTTP::encode_form({
84+
{"api_key", conf.getToken()},
85+
});
86+
std::vector<std::string> photos = {
87+
conf.getUrl() + fmt::format(fmt::runtime(jellyfin::apiDownload), item.Id, query),
88+
};
89+
brls::Application::pushActivity(new GalleryActivity(photos));
7990
} else {
8091
auto dialog = new brls::Dialog(fmt::format("Unsupported media type: {}", item.Type));
8192
dialog->addButton("hints/cancel"_i18n, []() {});

resources/xml/activity/gallery.xml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<brls:AppletFrame
2+
iconInterpolation="linear"
3+
backgroundColor="@theme/brls/backdrop"
4+
headerHidden="true"
5+
footerHidden="true">
6+
<brls:Box
7+
width="100%"
8+
height="100%">
9+
<GalleryView
10+
wireframe="false"
11+
width="100%"
12+
height="100%"
13+
hideHighlight="true"
14+
id="hint/gallery" />
15+
<ButtonClose
16+
textColor="#FFFFFF"
17+
positionType="absolute"
18+
positionTop="10"
19+
positionRight="10" />
20+
</brls:Box>
21+
</brls:AppletFrame>

0 commit comments

Comments
 (0)