Skip to content

Commit

Permalink
🔀 Merge release/1.3.0 into main (gitpanel)
Browse files Browse the repository at this point in the history
  • Loading branch information
adlerluiz committed Nov 1, 2023
2 parents 1f526f2 + c642c1e commit 7e363d8
Show file tree
Hide file tree
Showing 10 changed files with 360 additions and 175 deletions.
75 changes: 58 additions & 17 deletions lib/page/content/content_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,21 @@ class _ContentViewPageState extends State<ContentViewPage> {
hasScrolled.value = false;
}
});

//getParams();
//getFavoriteList();

LaunchUrlWrapper.getTypeLaunchMode(storage);

futureContent = apiContent.get(widget.ownerUsername, widget.slug);

loadItems();
}

void _onRefresh() async {
Future<void> _onRefresh() async {
futureContent = apiContent.get(widget.ownerUsername, widget.slug);
await loadItems();
_refreshController.refreshCompleted();
}

void _onLoading() async {
Future<void> _onLoading() async {
_refreshController.loadComplete();
}

Expand Down Expand Up @@ -114,7 +112,7 @@ class _ContentViewPageState extends State<ContentViewPage> {
}
}

Future<void> getFavoriteList(dynamic data) async {
Future<void> getFavoriteList(Content data) async {
final result = await storage.sharedPreferencesGet('favorite_list', '[]');

setState(() {
Expand All @@ -123,6 +121,16 @@ class _ContentViewPageState extends State<ContentViewPage> {
indexFavorite = getIndexFromFavorite(data.id!);
}

Future<void> getFavoriteListOwnerSlug(String ownerUsername, String slug) async {
final result = await storage.sharedPreferencesGet('favorite_list', '[]');

setState(() {
dataList = jsonDecode(result);
});

indexFavorite = getIndexFromFavoriteByOwnerUsernameAndSlug(ownerUsername, slug);
}

Future<void> removeFromFavorite(int index) async {
dataList.removeAt(index);

Expand Down Expand Up @@ -156,9 +164,20 @@ class _ContentViewPageState extends State<ContentViewPage> {
return -1;
}

int getIndexFromFavoriteByOwnerUsernameAndSlug(String ownerUsername, String slug) {
if (dataList.isNotEmpty) {
for (var i = 0; i < dataList.length; i++) {
final Content content = Content.fromJson(dataList[i]);
if (ownerUsername == content.ownerUsername && slug == content.slug) {
return i;
}
}
}
return -1;
}

Future<dynamic> getData() async {
try {
//dynamic result = await apiContent.get(widget.ownerUsername, widget.slug);
return await futureContent;
} catch (e) {
return Future.error(e);
Expand All @@ -170,7 +189,9 @@ class _ContentViewPageState extends State<ContentViewPage> {
final Content data = Content.fromJson(await futureContent);
await getParams(data);
await getFavoriteList(data);
} catch (e) {}
} catch (e) {
await getFavoriteListOwnerSlug(widget.ownerUsername, widget.slug);
}
}

Future<void> removeContent() async {
Expand All @@ -187,7 +208,6 @@ class _ContentViewPageState extends State<ContentViewPage> {
void selectMenuItem(Content data, int value) {
switch (value) {
case 0:
//print(widget.contentData.toJson());
if (data.title == null) {
Navigator.push(
context,
Expand Down Expand Up @@ -257,15 +277,27 @@ class _ContentViewPageState extends State<ContentViewPage> {
builder: (context, snapshot) {
if (snapshot.hasError) {
return Scaffold(
appBar: AppBar(),
appBar: AppBar(
actions: [
Visibility(
visible: indexFavorite != -1,
child: IconButton(
tooltip: 'Favorito',
onPressed: () {
removeFromFavorite(indexFavorite);
},
icon: const Icon(
Icons.star_outlined,
color: Colors.amber,
),
),
)
],
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
/*const Text(
'Conteúdo',
textAlign: TextAlign.center,
),*/
const Padding(
padding: EdgeInsets.only(bottom: 10),
),
Expand Down Expand Up @@ -296,9 +328,6 @@ class _ContentViewPageState extends State<ContentViewPage> {
isComment = true;
}

//getParams(data);
//getFavoriteList(data);

return Scaffold(
appBar: AppBar(
titleSpacing: 0,
Expand Down Expand Up @@ -407,6 +436,18 @@ class _ContentViewPageState extends State<ContentViewPage> {
showMessagePreventAccidentalTabcoinTapComment,
),
),
/*floatingActionButton: Visibility(
visible: data.childrenDeepCount! > 0,
child: FloatingActionButton(
onPressed: () {
/*final contentSize = pageScrollRefreshController.position.viewportDimension + pageScrollRefreshController.position.maxScrollExtent;
final index = 2;
final target = contentSize * index / 21;*/
pageScrollRefreshController.position.animateTo(pageScrollRefreshController.position.pixels + 300, duration: const Duration(seconds: 1), curve: Curves.easeInOut);
},
child: const Icon(Icons.keyboard_arrow_down_outlined),
),
),*/
);
}
return const Scaffold(
Expand Down
Loading

0 comments on commit 7e363d8

Please sign in to comment.