Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/1.0.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitletondor committed Jun 19, 2018
2 parents 7a23cdc + 971cd15 commit 96f2eb0
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 35 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ android {
applicationId "com.benoitletondor.beermeup"
minSdkVersion 21
targetSdkVersion 27
versionCode 6
versionName "1.0.6"
versionCode 7
versionName "1.0.7"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
Expand Down
4 changes: 2 additions & 2 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.6</string>
<string>1.0.7</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand All @@ -31,7 +31,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>7</string>
<string>8</string>
<key>FacebookAppID</key>
<string>204596980298393</string>
<key>FacebookDisplayName</key>
Expand Down
1 change: 1 addition & 0 deletions lib/localization/localization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ abstract class Localization {

String get homeHistoryWelcomeStart;

String get checkInEmptyHistoryHeader;
String get checkInEmptyResult;
String get checkInEmptyResultAdvice;
String get checkInHint;
Expand Down
3 changes: 2 additions & 1 deletion lib/localization/localization_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class LocalizationEN implements Localization {
@override String get homeCheckIn => "Check-in";
@override String get homeWelcome => "Welcome into your own beer museum";

@override String get homeProfileWelcomeContinue => "Continue to check the beers you have to build your profile.";
@override String get homeProfileWelcomeContinue => "Continue to check-in: One more to access your profile.";
@override String get homeProfileWelcomeStart => "Check the next beer you have into the app to build your profile.";
@override String get homeProfileThisWeek => "This week";
@override String get homeProfileOneBeerStart => "You only had ";
Expand All @@ -70,6 +70,7 @@ class LocalizationEN implements Localization {

@override String get homeHistoryWelcomeStart => "Check the next beer you have into the app to start your history";

@override String get checkInEmptyHistoryHeader => "Recently checked-in:";
@override String get checkInEmptyResult => "Can't find any beer matching your search";
@override String get checkInEmptyResultAdvice => "Try to type more or check the spelling";
@override String get checkInHint => "Type a beer name";
Expand Down
3 changes: 2 additions & 1 deletion lib/localization/localization_fr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ class LocalizationFR implements Localization {
@override String get homeCheckIn => "Check-in";
@override String get homeWelcome => "Bienvenue dans ton musée personnel de la bière";

@override String get checkInEmptyHistoryHeader => "Check-in récents:";
@override String get checkInEmptyResult => "Aucune bière avec ce nom";
@override String get checkInEmptyResultAdvice => "Essaye de compléter ou de vérifier l'orthographe";
@override String get checkInHint => "Tape un nom de bière";

@override String get homeProfileWelcomeContinue => "Continue de check-in les bières que tu bois pour construire ton profil.";
@override String get homeProfileWelcomeContinue => "Continue de check-in: Encore 1 pour accéder à ton profil.";
@override String get homeProfileWelcomeStart => "Check-in la prochaine bière que tu bois pour construire ton profil.";
@override String get homeProfileThisWeek => "Cette semaine";
@override String get homeProfileOneBeerStart => "Tu as bu seulement ";
Expand Down
33 changes: 30 additions & 3 deletions lib/page/checkin/checkinpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class _CheckInPageState extends ViewState<CheckInPage, CheckInViewModel, CheckIn

return snapshot.data.join(
(empty) => _buildEmptyScreen(),
(emptyLastBeers) => _buildEmptyScreenWithLastBeers(emptyLastBeers.beers),
(searching) => _buildEmptyLoadingScreen(),
(searchingWithPredictions) => _buildLoadingScreen(searchingWithPredictions.previousPredictions),
(predictions) => _buildResultScreen(predictions.predictions),
Expand Down Expand Up @@ -180,6 +181,26 @@ class _CheckInPageState extends ViewState<CheckInPage, CheckInViewModel, CheckIn
);
}

Widget _buildEmptyScreenWithLastBeers(List<Beer> beers) {
return Scaffold(
appBar: _buildAppBar(),
body: _BeersListView(
beers: beers,
onTap: (beer) => intent.beerSelected(beer),
header: Container(
padding: const EdgeInsets.only(left: 16.0, right: 16.0, bottom: 10.0, top: 20.0),
child: Text(
Localization.of(context).checkInEmptyHistoryHeader,
style: const TextStyle(
fontSize: 17.0,
fontFamily: "Google Sans",
),
),
),
),
);
}

Widget _buildErrorScreen(String error) {
return Scaffold(
appBar: _buildAppBar(),
Expand Down Expand Up @@ -229,12 +250,14 @@ class _AppBarPlacesAutoCompleteTextField extends StatelessWidget {
}

class _BeersListView extends StatelessWidget {
final Widget header;
final List<Beer> beers;
final ValueChanged<Beer> onTap;

_BeersListView({
@required this.beers,
this.onTap,
this.header,
});

@override
Expand All @@ -243,13 +266,17 @@ class _BeersListView extends StatelessWidget {
children: <Widget>[
Expanded(
child: ListView.builder(
itemCount: beers.length + 1,
itemCount: beers.length + 1 + (this.header == null ? 0 : 1),
itemBuilder: (BuildContext context, int index) {
if( index == beers.length ) {
if( index == 0 && this.header != null ) {
return this.header;
}

if( index == beers.length + (this.header == null ? 0 : 1)) {
return const _BeerContentProviderAttributionWidget();
}

final Beer beer = beers[index];
final Beer beer = beers[index - (this.header == null ? 0 : 1)];

return BeerTile(
beer: beer,
Expand Down
46 changes: 38 additions & 8 deletions lib/page/checkin/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import 'package:beer_me_up/model/beer.dart';
class CheckInViewModel extends BaseViewModel<CheckInState> {
final UserDataService _dataService;

final List<Beer> currentPredictions = List();
String _currentUserInput;

final List<Beer> _lastBeersCheckedIn = List();
final List<Beer> _currentPredictions = List();

CheckInViewModel(
this._dataService,
Expand All @@ -24,36 +27,63 @@ class CheckInViewModel extends BaseViewModel<CheckInState> {
onBeerSelected.listen(_onBeerSelected);
}

@override
Stream<CheckInState> bind(BuildContext context) {
_loadLastBeersCheckedIn();

return super.bind(context);
}

@override
CheckInState initialState() => CheckInState.empty();

_loadLastBeersCheckedIn() async {
try {
this._lastBeersCheckedIn.addAll(await _dataService.fetchLastCheckedInBeers());

if( this._lastBeersCheckedIn.isNotEmpty && (_currentUserInput == null || _currentUserInput.trim().isEmpty) ) {
setState(CheckInState.emptyLastBeers(this._lastBeersCheckedIn));
}
} catch (e, stackTrace) {
printException(e, stackTrace, "Error loading last beers checked-in");
}
}

_onUserInput(String userInput) async {
_currentUserInput = userInput;

if( userInput == null || userInput.trim().isEmpty ) {
currentPredictions.clear();
setState(CheckInState.empty());
_currentPredictions.clear();

if( _lastBeersCheckedIn.isEmpty ) {
setState(CheckInState.empty());
} else {
setState(CheckInState.emptyLastBeers(_lastBeersCheckedIn));
}

return;
}

if( currentPredictions.isNotEmpty ) {
setState(CheckInState.searchingWithPredictions(currentPredictions));
if( _currentPredictions.isNotEmpty ) {
setState(CheckInState.searchingWithPredictions(_currentPredictions));
} else {
setState(CheckInState.searching());
}

try {
final matchingBeers = await _dataService.findBeersMatching(userInput);

currentPredictions.clear();
_currentPredictions.clear();

if( matchingBeers.isNotEmpty ) {
currentPredictions.addAll(matchingBeers);
_currentPredictions.addAll(matchingBeers);
setState(CheckInState.predictions(matchingBeers));
} else {
setState(CheckInState.noPredictions());
}
} catch( e, stackTrace ) {
printException(e, stackTrace, "Error looking for beers matching $userInput");
currentPredictions.clear();
_currentPredictions.clear();

if( e is HttpException ) {
setState(CheckInState.error("An error occurred while processing the request."));
Expand Down
41 changes: 32 additions & 9 deletions lib/page/checkin/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,69 @@ import 'package:beer_me_up/common/mvi/state.dart';

import 'package:beer_me_up/model/beer.dart';

class CheckInState extends Union6Impl<
class CheckInState extends Union7Impl<
CheckInStateInputEmpty,
CheckInStateInputEmptyLastBeerCheckIns,
CheckInStateSearching,
CheckInStateSearchingWithPredictions,
CheckInStatePredictionsAvailable,
CheckInStateNoPredictionsAvailable,
CheckInStateError> {

static final Sextet<
static final Septet<
CheckInStateInputEmpty,
CheckInStateInputEmptyLastBeerCheckIns,
CheckInStateSearching,
CheckInStateSearchingWithPredictions,
CheckInStatePredictionsAvailable,
CheckInStateNoPredictionsAvailable,
CheckInStateError> factory = Sextet<
CheckInStateError> factory = Septet<
CheckInStateInputEmpty,
CheckInStateInputEmptyLastBeerCheckIns,
CheckInStateSearching,
CheckInStateSearchingWithPredictions,
CheckInStatePredictionsAvailable,
CheckInStateNoPredictionsAvailable,
CheckInStateError>();

CheckInState._(Union6<
CheckInState._(Union7<
CheckInStateInputEmpty,
CheckInStateInputEmptyLastBeerCheckIns,
CheckInStateSearching,
CheckInStateSearchingWithPredictions,
CheckInStatePredictionsAvailable,
CheckInStateNoPredictionsAvailable,
CheckInStateError> union) : super(union);

factory CheckInState.empty() => CheckInState._(factory.first(CheckInStateInputEmpty()));
factory CheckInState.searching() => CheckInState._(factory.second(CheckInStateSearching()));
factory CheckInState.searchingWithPredictions(List<Beer> previousPredictions) => CheckInState._(factory.third(CheckInStateSearchingWithPredictions(previousPredictions)));
factory CheckInState.predictions(List<Beer> predictions) => CheckInState._(factory.fourth(CheckInStatePredictionsAvailable(predictions)));
factory CheckInState.noPredictions() => CheckInState._(factory.fifth(CheckInStateNoPredictionsAvailable()));
factory CheckInState.error(String error) => CheckInState._(factory.sixth(CheckInStateError(error)));
factory CheckInState.emptyLastBeers(List<Beer> beers) => CheckInState._(factory.second(CheckInStateInputEmptyLastBeerCheckIns(beers)));
factory CheckInState.searching() => CheckInState._(factory.third(CheckInStateSearching()));
factory CheckInState.searchingWithPredictions(List<Beer> previousPredictions) => CheckInState._(factory.fourth(CheckInStateSearchingWithPredictions(previousPredictions)));
factory CheckInState.predictions(List<Beer> predictions) => CheckInState._(factory.fifth(CheckInStatePredictionsAvailable(predictions)));
factory CheckInState.noPredictions() => CheckInState._(factory.sixth(CheckInStateNoPredictionsAvailable()));
factory CheckInState.error(String error) => CheckInState._(factory.seventh(CheckInStateError(error)));
}

class CheckInStateInputEmpty extends State {}

class CheckInStateInputEmptyLastBeerCheckIns extends State {
final List<Beer> beers;

CheckInStateInputEmptyLastBeerCheckIns(this.beers);

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is CheckInStateInputEmptyLastBeerCheckIns &&
runtimeType == other.runtimeType &&
beers == other.beers;

@override
int get hashCode =>
super.hashCode ^
beers.hashCode;
}

class CheckInStateSearching extends State {}

class CheckInStateSearchingWithPredictions extends State {
Expand Down
Loading

0 comments on commit 96f2eb0

Please sign in to comment.