Skip to content

Commit

Permalink
added app icon, lists functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayman-Barghout committed Nov 4, 2019
1 parent 1f08d6f commit b97ae88
Show file tree
Hide file tree
Showing 38 changed files with 180 additions and 24 deletions.
3 changes: 2 additions & 1 deletion android/app/src/main/AndroidManifest.xml
@@ -1,14 +1,15 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pocean.urban_dict_slang">

<uses-permission android:name="android.permission.INTERNET" />
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="urban_dict_slang"
android:label="Urban Dictionary"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
Expand Down
Binary file modified android/app/src/main/res/mipmap-hdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-mdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png
1 change: 1 addition & 0 deletions lib/main.dart
Expand Up @@ -52,6 +52,7 @@ class UrbanDictApp extends StatelessWidget {
),
],
child: MaterialApp(
title: 'Urban Dictionary',
theme: ThemeData(primaryColor: customStyles.primaryColor),
routes: {
'/': (context) => SplashScreen(
Expand Down
5 changes: 5 additions & 0 deletions lib/providers/favorites_provider.dart
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';

import 'package:urban_dict_slang/models/terms.dart';
import 'package:urban_dict_slang/services/db/database.dart' as db;
import 'package:urban_dict_slang/services/repository/terms_repository.dart';

class FavoritesProvider with ChangeNotifier {
Expand All @@ -16,6 +17,10 @@ class FavoritesProvider with ChangeNotifier {
loading = false;
}

void toggleFavorite(db.Term term) async {
await repository.toggleFavorite(term);
}

Terms get favorites => _favorites;

set favorites(Terms newTerm) {
Expand Down
4 changes: 4 additions & 0 deletions lib/providers/terms_provider.dart
Expand Up @@ -16,6 +16,10 @@ class TermsProvider with ChangeNotifier {
loading = false;
}

void deleteTerm(String term) async {
await repository.deleteTerm(term);
}

Terms get terms => _terms;

set terms(Terms newTerm) {
Expand Down
49 changes: 40 additions & 9 deletions lib/screens/home_page/favorites_view.dart
@@ -1,14 +1,21 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:urban_dict_slang/providers/definitions_provider.dart';
import 'package:urban_dict_slang/providers/favorites_provider.dart';
import 'package:urban_dict_slang/providers/term_provider.dart';
import 'package:urban_dict_slang/services/db/database.dart';
import 'package:urban_dict_slang/utils/styles.dart' as customStyles;

class FavoritesView extends StatelessWidget {
const FavoritesView({Key key}) : super(key: key);

@override
Widget build(BuildContext context) {
FavoritesProvider termsProvider = Provider.of<FavoritesProvider>(context);
FavoritesProvider favoritesProvider =
Provider.of<FavoritesProvider>(context);
TermProvider termProvider = Provider.of<TermProvider>(context);
DefinitionsProvider definitionsProvider =
Provider.of<DefinitionsProvider>(context);
return Container(
color: customStyles.primaryColor,
child: Column(
Expand All @@ -33,24 +40,48 @@ class FavoritesView extends StatelessWidget {
topRight: Radius.circular(20.0),
),
),
child: termsProvider.favorites == null
child: favoritesProvider.favorites == null
? Center(
child: CircularProgressIndicator(),
)
: termsProvider.favorites.message == null
: favoritesProvider.favorites.message == null
? ListView.builder(
itemCount: termsProvider.favorites.terms.length,
itemCount: favoritesProvider.favorites.terms.length,
itemBuilder: (BuildContext context, int index) {
Term favoriteTerm =
favoritesProvider.favorites.terms[index];
return ListTile(
onTap: () async {
termProvider.updateTerm(favoriteTerm.term);
definitionsProvider
.updateDefinitions(favoriteTerm.term);
var nav = await Navigator.of(context)
.pushNamed('/result');
if (nav == null || nav == true) {
favoritesProvider.getFavorites();
}
},
title: Text(
termsProvider.favorites.terms[index].term),
trailing: Text(termsProvider
.favorites.terms[index].lastViewed
.toString()),
favoriteTerm.term[0].toUpperCase() +
favoriteTerm.term.substring(1),
style: customStyles.definitionTextStyle,
),
trailing: IconButton(
icon: Icon(
Icons.star,
color: customStyles.primaryColorLight,
),
onPressed: () {
favoritesProvider
.toggleFavorite(favoriteTerm);
favoritesProvider.getFavorites();
},
),
);
},
)
: Center(child: Text(termsProvider.favorites.message)),
: Center(
child: Text(favoritesProvider.favorites.message)),
),
)
],
Expand Down
14 changes: 2 additions & 12 deletions lib/screens/home_page/terms_view.dart
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:urban_dict_slang/providers/terms_provider.dart';
import 'package:urban_dict_slang/screens/home_page/widgets/terms_list.dart';
import 'package:urban_dict_slang/utils/styles.dart' as customStyles;

class TermsView extends StatelessWidget {
Expand Down Expand Up @@ -38,18 +39,7 @@ class TermsView extends StatelessWidget {
child: CircularProgressIndicator(),
)
: termsProvider.terms.message == null
? ListView.builder(
itemCount: termsProvider.terms.terms.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title:
Text(termsProvider.terms.terms[index].term),
trailing: Text(termsProvider
.terms.terms[index].lastViewed
.toString()),
);
},
)
? TermsListWithHeaders()
: Center(child: Text(termsProvider.terms.message)),
),
)
Expand Down
73 changes: 73 additions & 0 deletions lib/screens/home_page/widgets/terms_list.dart
@@ -0,0 +1,73 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:urban_dict_slang/providers/definitions_provider.dart';
import 'package:urban_dict_slang/providers/term_provider.dart';
import 'package:urban_dict_slang/providers/terms_provider.dart';
import 'package:urban_dict_slang/services/db/database.dart';

import 'package:urban_dict_slang/utils/styles.dart' as customStyles;

class TermsListWithHeaders extends StatelessWidget {
int getDaysDifference(DateTime viewed) =>
DateTime.now().difference(viewed).inDays;

@override
Widget build(BuildContext context) {
TermsProvider termsProvider = Provider.of<TermsProvider>(context);
TermProvider termProvider = Provider.of<TermProvider>(context);
DefinitionsProvider definitionsProvider =
Provider.of<DefinitionsProvider>(context);
List<int> _days = [];

return ListView.builder(
itemCount: termsProvider.terms.terms.length,
itemBuilder: (BuildContext context, int index) {
Term currentTerm = termsProvider.terms.terms[index];
int daysDifference = getDaysDifference(currentTerm.lastViewed);
if (!_days.contains(daysDifference)) {
_days.add(daysDifference);
index -= 1;
return Container(
padding: EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: customStyles.primaryColorLight,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10.0),
topRight: Radius.circular(10.0),
bottomLeft: Radius.circular(10.0),
),
),
child: Text(
daysDifference > 1
? '$daysDifference days ago'
: daysDifference == 0 ? 'Today' : 'Yesterday',
style: TextStyle(color: Colors.white, fontSize: 16.0),
),
);
} else {
return ListTile(
onTap: () async {
termProvider.updateTerm(currentTerm.term);
definitionsProvider.updateDefinitions(currentTerm.term);
var nav = await Navigator.of(context).pushNamed('/result');
if (nav == true || nav == null) {
termsProvider.getTerms();
}
},
title: Text(
currentTerm.term[0].toUpperCase() + currentTerm.term.substring(1),
style: customStyles.definitionTextStyle,
),
trailing: IconButton(
icon: Icon(Icons.delete, color: Colors.red),
onPressed: () {
termsProvider.deleteTerm(currentTerm.term);
termsProvider.getTerms();
},
),
);
}
},
);
}
}
3 changes: 3 additions & 0 deletions lib/services/db/database.dart
Expand Up @@ -68,6 +68,9 @@ class TermDao extends DatabaseAccessor<AppDatabase> with _$TermDaoMixin {

Future<Term> getTerm(String term) =>
(select(terms)..where((t) => t.term.equals(term))).getSingle();

Future deleteTerm(String term) =>
(delete(terms)..where((t) => t.term.equals(term))).go();
}

@UseDao(tables: [Definitions])
Expand Down
8 changes: 8 additions & 0 deletions lib/services/repository/terms_repository.dart
Expand Up @@ -23,4 +23,12 @@ class TermsRepository {
return models.Terms(favorites, null);
}
}

Future toggleFavorite(Term term) async {
await db.termDao.toggleFavorite(term);
}

Future deleteTerm(String term) async {
await db.termDao.deleteTerm(term);
}
}
35 changes: 35 additions & 0 deletions pubspec.lock
Expand Up @@ -15,6 +15,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.1"
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.10"
args:
dependency: transitive
description:
Expand Down Expand Up @@ -195,6 +202,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_launcher_icons:
dependency: "direct dev"
description:
name: flutter_launcher_icons
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.4"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -249,6 +263,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.3"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.7"
io:
dependency: transitive
description:
Expand Down Expand Up @@ -368,6 +389,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0+1"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
pool:
dependency: transitive
description:
Expand Down Expand Up @@ -541,6 +569,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.5.0"
yaml:
dependency: transitive
description:
Expand Down
9 changes: 7 additions & 2 deletions pubspec.yaml
Expand Up @@ -11,7 +11,7 @@ description: An urban dictionary app showing urban definitions for slang
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
version: 1.0.1+1

environment:
sdk: ">=2.4.0 <3.0.0"
Expand All @@ -35,7 +35,12 @@ dev_dependencies:

moor_generator: ^2.0.1
build_runner: ^1.7.1
flutter_launcher_icons: "^0.7.3"

flutter_icons:
android: true
ios: true
image_path: "assets/icons/icon.png"
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

Expand All @@ -50,7 +55,7 @@ flutter:
# To add assets to your application, add an assets section, like this:
assets:
- assets/flare/splash.flr
# - images/a_dot_burr.jpeg
- assets/icons/
# - images/a_dot_ham.jpeg

# An image asset can refer to one or more resolution-specific "variants", see
Expand Down

0 comments on commit b97ae88

Please sign in to comment.