Skip to content

Commit ef2e661

Browse files
author
JulesG10
committed
update folder architecture + add new shortcut
1 parent fb247e8 commit ef2e661

File tree

15 files changed

+254
-132
lines changed

15 files changed

+254
-132
lines changed

android/app/src/main/java/com/fouflix/julesg10/FlouFlixPlugin.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class FlouFlixPlugin extends Plugin {
1717
private String EVENT_SHARE_TEXT_DATA = "onTextDataShared";
1818
private String EVENT_READY_CREATE = "onReadyCreate";
1919
private String EVENT_PLAY_LAST = "onPlayLast";
20+
private String EVENT_PLAY_NEXT = "onPlayNext";
2021

2122
private FlouFlixData data;
2223

@@ -50,6 +51,10 @@ protected void handleOnNewIntent(Intent intent) {
5051
{
5152
return;
5253
}
54+
if(this.checkIntentAction(intent,"next", EVENT_PLAY_NEXT))
55+
{
56+
return;
57+
}
5358

5459
if(this.checkIntentAction(intent,"last", EVENT_PLAY_LAST))
5560
{

android/app/src/main/java/com/fouflix/julesg10/MainActivity.java

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
import android.content.Context;
44
import android.content.Intent;
5+
import android.graphics.Color;
56
import android.os.Bundle;
7+
import android.webkit.CookieManager;
8+
import android.webkit.WebSettings;
9+
import android.webkit.WebView;
610

11+
import androidx.annotation.Nullable;
712
import androidx.core.content.pm.ShortcutInfoCompat;
813
import androidx.core.content.pm.ShortcutManagerCompat;
914
import androidx.core.graphics.drawable.IconCompat;
@@ -14,8 +19,11 @@
1419

1520
import org.json.JSONException;
1621

22+
import java.util.ArrayList;
23+
1724
public class MainActivity extends BridgeActivity {
1825

26+
private ArrayList<ShortcutInfoCompat> shortcuts = new ArrayList<>();
1927

2028
@Override
2129
protected void onCreate(Bundle savedInstanceState) {
@@ -24,9 +32,30 @@ protected void onCreate(Bundle savedInstanceState) {
2432
super.onCreate(savedInstanceState);
2533
CastContext.getSharedInstance(this);
2634

27-
ShortcutManagerCompat.removeAllDynamicShortcuts(this.getApplicationContext());
28-
this.createShortcutWatch("id1");
29-
this.createShortcutAdd("id2");
35+
if(getIntent().getAction().equals(Intent.ACTION_MAIN))
36+
{
37+
this.updateShortcuts();
38+
}
39+
}
40+
41+
private void updateShortcuts()
42+
{
43+
this.shortcuts.clear();
44+
this.createShortcutWatch("id1", "id2");
45+
this.createShortcutAdd("id3");
46+
ShortcutManagerCompat.setDynamicShortcuts(this.getApplicationContext(), this.shortcuts);
47+
}
48+
49+
@Override
50+
public void onPause() {
51+
super.onPause();
52+
this.updateShortcuts();
53+
}
54+
55+
@Override
56+
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
57+
super.onPostCreate(savedInstanceState);
58+
getBridge().getWebView().setBackgroundColor(Color.parseColor("#161616"));
3059
}
3160

3261
private Intent createIntent()
@@ -37,7 +66,7 @@ private Intent createIntent()
3766
return intent;
3867
}
3968

40-
private void createShortcutWatch(String id)
69+
private void createShortcutWatch(String id, String id2)
4170
{
4271
FlouFlixData data = new FlouFlixData(this.getApplicationContext());
4372
try{
@@ -52,6 +81,15 @@ private void createShortcutWatch(String id)
5281

5382
this.shortcutCreate(lasti,"Regarder "+lastTitle, lastTitle, R.drawable.play_icon, id);
5483
}
84+
85+
String nextTitle = obj.getString("next_title", "");
86+
if(nextTitle.length() != 0)
87+
{
88+
Intent nexti = this.createIntent();
89+
nexti.putExtra("next", true);
90+
91+
this.shortcutCreate(nexti,"Regarder "+nextTitle, nextTitle, R.drawable.play_icon, id2);
92+
}
5593
} catch (JSONException e) {}
5694

5795
}
@@ -73,6 +111,6 @@ private void shortcutCreate(Intent intent, String title, String shorttitle,int i
73111
.setIntent(intent)
74112
.build();
75113

76-
ShortcutManagerCompat.pushDynamicShortcut(this.getApplicationContext(), shortcut);
114+
this.shortcuts.add(shortcut);
77115
}
78116
}

src/pages/Home.jsx

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
import React from "react";
2-
import { Avatar, Box, Flex, Heading } from "@chakra-ui/react";
3-
import { AddIcon } from "@chakra-ui/icons";
2+
import { useNavigate } from "react-router-dom";
3+
4+
import { Box } from "@chakra-ui/react";
45

56
import { StatusBar } from "@capacitor/status-bar";
67
import { NavigationBar } from "@hugotomazi/capacitor-navigation-bar";
78
import { Capacitor } from "@capacitor/core";
89
import { Toast } from "@capacitor/toast";
910
import { Network } from '@capacitor/network';
11+
1012
import { FlouFlix } from '../plugin/index';
11-
import { storage } from "../storage";
12-
import { isUrlValid, parseFile } from "../utility";
1313

14-
import { ContentCards } from './components/ContentCards';
15-
import { DrawerAddCard } from "./components/DrawerAddCard";
16-
import { DrawerAddSerieItem } from "./components/DrawerAddSerieItem";
14+
import { isUrlResponding, isUrlValid, parseFile, runAsync } from "./components/api/utility";
15+
import { storage } from "./components/api/storage";
16+
1717
import { TopBar } from './components/TopBar';
18-
import { useNavigate } from "react-router-dom";
18+
import { DrawerAddCard } from "./components/drawer/DrawerAddCard";
19+
import { DrawerAddSerieItem } from './components/drawer/DrawerAddSerieItem';
20+
import { ContentCards } from './components/card/ContentCards';
21+
1922

2023

2124

@@ -92,20 +95,55 @@ export default function Home() {
9295
setDrawerNewCardOpen(true);
9396
})
9497

95-
FlouFlix.addListener("onPlayLast", (evt) => {
96-
(async () => {
98+
const playVideo = (selid, selindex) =>{
99+
runAsync(async () => {
97100
const obj = await FlouFlix.getData();
98101
if (obj.value == null) {
99102
return;
100103
}
104+
101105
const data = JSON.parse(obj.value);
102-
if (data.last_index < 0) {
103-
navigate("/video/" + data.last_id);
104-
} else {
105-
navigate("/video/" + data.last_id + "?index=" + data.last_index);
106+
if (data[selid] === undefined)
107+
{
108+
return;
109+
}
110+
111+
const item = await storage.get(data[selid]);
112+
if(item == null)
113+
{
114+
return;
106115
}
107116

108-
})()
117+
if (item.is_movie) {
118+
const state = await isUrlResponding(item.data.video.url, item.data.video.referer)
119+
if (state) {
120+
navigate("/video/" + data[selid]);
121+
} else {
122+
Toast.show({
123+
text: "Il semble que cette video n'existe pas..."
124+
})
125+
}
126+
} else if (data[selindex] < item.list.length) {
127+
const state = await isUrlResponding(item.list[data[selindex]].video.url, item.list[data[selindex]].video.referer)
128+
if (state) {
129+
navigate("/video/" + data[selid] + "?index=" + data[selindex]);
130+
} else {
131+
Toast.show({
132+
text: "Il semble que cette video n'existe pas..."
133+
})
134+
}
135+
}
136+
137+
})
138+
}
139+
140+
141+
FlouFlix.addListener("onPlayNext", (evt) => {
142+
playVideo('next_id', 'next_index')
143+
})
144+
145+
FlouFlix.addListener("onPlayLast", (evt) => {
146+
playVideo('last_id','last_index')
109147
})
110148

111149
Network.addListener('networkStatusChange', (status) => {
@@ -128,7 +166,7 @@ export default function Home() {
128166

129167
const onCreateNewCard = React.useCallback(
130168
(title, type, url = "", list = []) => {
131-
(async () => {
169+
runAsync(async () => {
132170
if (type == "movie") {
133171
const item = await storage.createMovieItem(title, url)
134172
await storage.set(item.id, item);
@@ -139,7 +177,7 @@ export default function Home() {
139177
}
140178
const values = await storage.getAll();
141179
setItems(values);
142-
})();
180+
});
143181
}, [setItems]);
144182

145183
const setSerieDrawerOpen = React.useCallback(

src/pages/Video.jsx

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import React from "react";
22
import { useLocation, useNavigate, useParams } from "react-router-dom";
3-
import { storage } from "../storage";
4-
53
import { App } from "@capacitor/app";
64
import { CapacitorVideoPlayer } from "capacitor-video-player";
75
import { Toast } from "@capacitor/toast";
86
import { StatusBar } from "@capacitor/status-bar";
97
import { NavigationBar } from "@hugotomazi/capacitor-navigation-bar";
108
import { ScreenOrientation, OrientationType } from '@capawesome/capacitor-screen-orientation';
9+
1110
import { FlouFlix } from "../plugin";
11+
import { storage } from "./components/api/storage";
12+
import { runAsync } from "./components/api/utility";
1213

1314
function InitPlayer(id, title, video, callback, smtitle = undefined) {
1415
CapacitorVideoPlayer.initPlayer({
@@ -27,17 +28,31 @@ function InitPlayer(id, title, video, callback, smtitle = undefined) {
2728
})
2829
.then((player) => {
2930
if (!player.result) {
30-
callback(false);
31+
callback({
32+
state: false,
33+
error: undefined,
34+
data: undefined
35+
});
3136
} else {
3237

33-
callback(player);
38+
callback({
39+
state: true,
40+
error: undefined,
41+
data: player
42+
});
3443
}
3544
})
3645
.catch((err) => {
37-
callback(false);
46+
47+
callback({
48+
state: false,
49+
error: err,
50+
data: undefined
51+
});
3852
});
3953
}
4054

55+
4156
export default function Video() {
4257
const { id } = useParams();
4358
const location = useLocation();
@@ -47,41 +62,35 @@ export default function Video() {
4762
const init = React.useCallback(
4863
(id, title, video, smtitle = undefined) => {
4964
InitPlayer(id, title, video, (state) => {
50-
if (state === false) {
65+
if (state.state == false)
66+
{
5167
exit("Nous n'avons pas réussi à lire la vidéo...");
5268
} else {
53-
54-
(async ()=>{
55-
try {
56-
await StatusBar.hide();
57-
await NavigationBar.hide();
58-
await ScreenOrientation.lock({ type: OrientationType.LANDSCAPE });
59-
60-
61-
}catch {
62-
exit("Nous n'avons pas réussi à lire la vidéo...");
63-
}
64-
})()
69+
runAsync(async ()=>{
70+
await StatusBar.hide();
71+
await NavigationBar.hide();
72+
await ScreenOrientation.lock({ type: OrientationType.LANDSCAPE });
73+
}).catch(()=>{
74+
exit("Nous n'avons pas réussi à lire la vidéo...");
75+
})
6576
}
6677
}, smtitle);
6778
},
6879
[]);
6980

7081
const exit = React.useCallback((error = "") => {
71-
72-
(async ()=>{
73-
try{
74-
if (error.length != 0) {
75-
await Toast.show({
76-
text: error
77-
});
78-
}
79-
await ScreenOrientation.lock({ type: OrientationType.PORTRAIT })
80-
await CapacitorVideoPlayer.stopAllPlayers();
81-
}catch{}
82+
runAsync(async ()=>{
83+
if (error.length != 0) {
84+
await Toast.show({
85+
text: error
86+
});
87+
}
88+
await ScreenOrientation.lock({ type: OrientationType.PORTRAIT })
89+
await CapacitorVideoPlayer.stopAllPlayers();
90+
}).then(()=>{
8291
navigate("/");
83-
})()
84-
}, [navigate]);
92+
})
93+
}, [navigate]);
8594

8695
React.useEffect(() => {
8796
storage.get(id).then((value) => {
@@ -94,11 +103,17 @@ export default function Video() {
94103

95104
exit("Il semble que cette video n'existe pas...");
96105
} else {
106+
let hasNext = index + 1 < value.list.length
107+
97108
FlouFlix.setData({
98109
value: JSON.stringify({
99110
last_id: value.id,
100111
last_title: value.list[index].title + " - " + value.data.title,
101-
last_index: index
112+
last_index: index,
113+
114+
next_id: hasNext ? value.id : "",
115+
next_index: hasNext ? index + 1 : -1,
116+
next_title: hasNext ? value.list[index + 1].title + " - " + value.data.title : ""
102117
})
103118
})
104119
init(value.id, value.data.title, video, value.list[index].title);
@@ -112,11 +127,16 @@ export default function Video() {
112127
if (video.url.length == 0) {
113128
exit("Il semble que cette video n'existe pas...");
114129
} else {
130+
let next = {}
115131
FlouFlix.setData({
116132
value: JSON.stringify({
117133
last_id: value.id,
118134
last_title: value.data.title,
119-
last_index: -1
135+
last_index: -1,
136+
137+
next_id: "",
138+
next_index: -1,
139+
next_title: ""
120140
})
121141
})
122142
init(value.id, value.data.title, video);

0 commit comments

Comments
 (0)