Skip to content

Commit

Permalink
remove json deps and prepare for hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludwig committed Aug 28, 2019
1 parent c668f16 commit ff29bca
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 81 deletions.
12 changes: 5 additions & 7 deletions lib/blocs/drop_table/table_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:bloc/bloc.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:navis/global_keys.dart';
import 'package:navis/models/slim_drop_table.dart';
import 'package:navis/services/repository.dart';
import 'package:navis/utils/worldstate_utils.dart';
import 'package:rxdart/rxdart.dart';
Expand Down Expand Up @@ -33,7 +32,7 @@ class TableSearchBloc extends Bloc<SearchEvent, SearchState> {
}
}

static List<Drop> _table;
static List<Map<String, dynamic>> _table;

@override
Stream<SearchState> transformEvents(
Expand Down Expand Up @@ -86,16 +85,15 @@ class TableSearchBloc extends Bloc<SearchEvent, SearchState> {
}
}

List<Drop> _search(SearchTable drops) {
List<Map<String, dynamic>> _search(SearchTable drops) {
return drops.rewards
.where((r) => r.item.toLowerCase().contains(drops.term.toLowerCase()))
.toList()
..sort((a, b) => a.chance.compareTo(b.chance));
.where((r) => r['item'].toLowerCase().contains(drops.term.toLowerCase()))
.toList();
}

class SearchTable {
SearchTable(this.term, this.rewards);

final String term;
final List<Drop> rewards;
final List<Map<String, dynamic>> rewards;
}
3 changes: 1 addition & 2 deletions lib/blocs/drop_table/table_state.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:equatable/equatable.dart';
import 'package:navis/models/slim_drop_table.dart';

abstract class SearchState extends Equatable {
SearchState([List props = const []]) : super(props);
Expand All @@ -12,7 +11,7 @@ class SearchStateLoading extends SearchState {}
class SearchStateSuccess extends SearchState {
SearchStateSuccess(this.results) : super([results]);

final List<Drop> results;
final List<Map<String, dynamic>> results;
}

class SearchStateError extends SearchState {
Expand Down
25 changes: 0 additions & 25 deletions lib/models/drop_table_info.dart

This file was deleted.

21 changes: 0 additions & 21 deletions lib/models/slim_drop_table.dart

This file was deleted.

19 changes: 10 additions & 9 deletions lib/screens/drops/components/search_results.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:html/parser.dart';
import 'package:navis/blocs/bloc.dart';
import 'package:navis/models/slim_drop_table.dart';

class SearchResults extends StatelessWidget {
const SearchResults({Key key}) : super(key: key);
Expand All @@ -11,28 +10,30 @@ class SearchResults extends StatelessWidget {
return parse(document.body.text).documentElement.text;
}

Color _chance(num chance) {
if (chance < 25) return Colors.yellow;
if (chance > 25 && chance < 50) return const Color(0xFFc0c0c0);
Color _chance(dynamic chance) {
final number = chance is String ? double.parse(chance) : chance;

if (number < 25) return Colors.yellow;
if (number > 25 && number < 50) return const Color(0xFFc0c0c0);

return Colors.brown;
}

Widget _result(BuildContext context, Drop drop) {
Widget _result(BuildContext context, Map<String, dynamic> drop) {
final theme = Theme.of(context);

return Container(
padding: const EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(drop.item, style: theme.textTheme.subhead),
Text(drop['item'], style: theme.textTheme.subhead),
const SizedBox(height: 4),
Text('${drop.chance}% Drop Chance',
Text('${drop['chance']}% Drop Chance',
style: theme.textTheme.caption
.copyWith(color: _chance(drop.chance))),
.copyWith(color: _chance(drop['chance']))),
const SizedBox(height: 4),
Text(_parseHtmlString(drop.place))
Text(_parseHtmlString(drop['place']))
],
),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/drops/drops_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DropTableList extends StatelessWidget {
child: Text(
'Type what you\'re looking for into the search above!')),
if (state is SearchStateError)
const Center(child: Text('An unknown error has occured'))
Center(child: Text('An unknown error has occured: ${state.error}'))
]);
},
);
Expand Down
12 changes: 6 additions & 6 deletions lib/services/repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'notification_service.dart';

class Repository {
Repository({
@required this.client,
@required this.api,
@required this.storageService,
@required this.packageInfo,
@required this.notificationService,
Expand All @@ -30,14 +30,14 @@ class Repository {
final PackageInfo _info = await PackageInfo.fromPlatform();

return Repository(
client: client ?? MetricHttpClient(http.Client()),
api: WorldstateApiWrapper(client ?? MetricHttpClient(http.Client())),
storageService: _storageService,
packageInfo: _info,
notificationService: NotificationService.initialize(),
);
}

final http.Client client;
final WorldstateApiWrapper api;
final LocalStorageService storageService;
final PackageInfo packageInfo;
final NotificationService notificationService;
Expand All @@ -49,9 +49,9 @@ class Repository {

try {
platform ??= storageService.platform ?? Platforms.pc;
final response = await WorldstateApiWrapper.getInstance(platform, client);
final response = await api.getWorldstate(platform);

worldstate = cleanState(response.worldstate);
worldstate = cleanState(response);
} catch (e) {
if (await _checkFile('/worldstate.json')) {
final cached = await _getFile('/worldstate.json');
Expand Down Expand Up @@ -81,7 +81,7 @@ class Repository {
if (timestamp.difference(storageService.tableTimestamp) <
const Duration(days: 7) ||
!await _checkFile('/drop_table.json')) {
final response = await client.get('$dropTable/data/all.slim.json');
final response = await api.client.get('$dropTable/data/all.slim.json');

if (response?.statusCode != 200)
throw Exception(
Expand Down
7 changes: 2 additions & 5 deletions lib/utils/worldstate_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:math';

import 'package:collection/collection.dart';
import 'package:flutter/widgets.dart';
import 'package:navis/models/slim_drop_table.dart';
import 'package:worldstate_model/worldstate_models.dart';

Worldstate cleanState(Worldstate state) {
Expand Down Expand Up @@ -33,10 +32,8 @@ Worldstate cleanState(Worldstate state) {
return state;
}

List<Drop> jsonToRewards(String response) {
final drops = json.decode(response).cast<Map<String, dynamic>>();

return drops.map<Drop>((d) => Drop.fromJson(d)).toList();
List<Map<String, dynamic>> jsonToRewards(String response) {
return json.decode(response).cast<Map<String, dynamic>>();
}

bool _checkBackground(BuildContext context, String node) {
Expand Down
6 changes: 1 addition & 5 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: navis
description: Cephalon Navis is an Android app inspired by Warframe Hub.
version: 1.2.25+48
version: 1.2.26+49

dependencies:
flutter:
Expand All @@ -19,7 +19,6 @@ dependencies:
flutter_svg: ^0.14.0
simple_animations: ^1.3.3
floating_search_bar: ^0.2.0
json_annotation: ^3.0.0
worldstate_model:
git: https://github.com/SlayerOrnstein/worldstate_model.git
wfcd_api_wrapper:
Expand All @@ -36,9 +35,6 @@ dev_dependencies:
test: ^1.6.1
mockito: ^4.1.0

builders:
json_serializable: ^3.2.0

flutter:
uses-material-design: true
fonts:
Expand Down

0 comments on commit ff29bca

Please sign in to comment.