diff --git a/lib/Backend/hoarder.dart b/lib/Backend/hoarder.dart index a068722..99b67d9 100644 --- a/lib/Backend/hoarder.dart +++ b/lib/Backend/hoarder.dart @@ -7,20 +7,47 @@ import 'package:http/http.dart' as http; class Hoarder{ static List GamesJson = []; + static Map Settings = {}; + static List FeaturedGames = []; - static void GrabInitData() async{ - var response = null; + static Future GrabInitData() async{ try { - response = (await http.post(Uri.parse('${Brain.API_ENDPOINT}get_games.php'))); + var response = (await http.post(Uri.parse('${Brain.API_ENDPOINT}get_settings.php'))); - Debug.LogError(response.body.toString()); - GamesJson=[]; - List games = response.body.toString().split(""); - games.forEach((game) { - GamesJson.add(jsonDecode(game)); + Debug.LogResponse(response.body.toString()); + // Settings= jsonDecode(response.body.toString()); + List jsonList = jsonDecode(response.body.toString()); + jsonList.forEach((jsonItem) { + Settings[jsonItem['id']] = jsonItem['value']; }); + + } catch (e) { + Debug.LogError("Error while loading settings : $e"); + } + + try { + var response = (await http.post(Uri.parse('${Brain.API_ENDPOINT}get_games.php'))); + + Debug.LogResponse(response.body.toString()); + GamesJson=[]; + FeaturedGames = []; + List games = response.body.toString().split(""); + List featuredGames = Settings["featured_games"].toString().split(','); + games.forEach((game) { + dynamic Json = jsonDecode(game); + String id = Json['id']; + GamesJson.add(Json); + + if(featuredGames.contains(id)){ + FeaturedGames.add(Json); + } + }); + + Debug.Log("Total games ${GamesJson.length} and ${FeaturedGames.length} featured"); } catch (e) { Debug.LogError("Error while loading games : $e"); } + + } } \ No newline at end of file diff --git a/lib/home.dart b/lib/home.dart index 6bb56d6..5490219 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -1,3 +1,4 @@ +import 'package:faucethub/Backend/DebugHelper.dart'; import 'package:faucethub/Backend/brains.dart'; import 'package:faucethub/Backend/hoarder.dart'; import 'package:faucethub/Backend/login_mgr.dart'; @@ -16,7 +17,7 @@ int selectedBotNavIndex = 0; class _HomePageState extends State { static List bodyOptions = [ HomeWidget(), - Text("games"), + GamesWidget(), Text("Money!") ]; @@ -44,13 +45,17 @@ class _HomePageState extends State { child: ListView.builder( scrollDirection: Axis.horizontal, controller: _firstController, - itemCount: Hoarder.GamesJson.length, + itemCount: Hoarder.FeaturedGames.length, itemBuilder: (BuildContext context, int index) { - return Card( - child: ClipRRect( - borderRadius: BorderRadius.circular(12), - child: Image.network(Hoarder.GamesJson[index]['icon'], - width: 100, height: 100), + Debug.Log(Hoarder.FeaturedGames[index]); + return InkWell( + onTap: (){}, + child: Card( + child: ClipRRect( + borderRadius: BorderRadius.circular(12), + child: Image.network(Hoarder.FeaturedGames[index]['icon'], + width: 100, height: 100), + ), ), ); }), @@ -64,6 +69,36 @@ class _HomePageState extends State { ); } + static Widget GamesWidget(){ + final ScrollController scrollController = ScrollController(); + return Container( + child: SingleChildScrollView( + physics: ScrollPhysics(), + child: Column( + children: [ + Text("Linked", style: TextStyle(fontSize: 20,fontWeight: FontWeight.bold),), + ListView.builder( + physics: NeverScrollableScrollPhysics(), + shrinkWrap: true, + controller: scrollController, + itemCount: Hoarder.GamesJson.length, + itemBuilder: (BuildContext context, int index) { + Debug.Log(Hoarder.GamesJson[index]); + return InkWell( + onTap: (){}, + child: ListTile( + leading: Image.network(Hoarder.GamesJson[index]['icon'], + width: 25, height: 25), + title: Text(Hoarder.GamesJson[index]['name']), + ), + ); + }) + ], + ), + ), + ); + } + @override Widget build(BuildContext context) { return SafeArea( @@ -102,7 +137,9 @@ class _HomePageState extends State { title, style: TextStyle(fontSize: 17,fontWeight: FontWeight.bold), ), - Icon(Icons.arrow_right_alt) + InkWell(child: Icon(Icons.arrow_right_alt), onTap: (){ + + },) ], ), ), diff --git a/lib/splash.dart b/lib/splash.dart index 7a25310..33787be 100644 --- a/lib/splash.dart +++ b/lib/splash.dart @@ -1,3 +1,4 @@ +import 'package:faucethub/Backend/hoarder.dart'; import 'package:faucethub/Backend/login_mgr.dart'; import 'package:flutter/material.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart'; @@ -22,7 +23,7 @@ class _SplashScreenState extends State { void init () async{ int result = await LoginManager.AutoLogin(); - + await Hoarder.GrabInitData(); if(result == 0){ Navigator.of(context).pushReplacementNamed('/home'); }else{