Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
ksh-b committed Mar 31, 2024
1 parent 7f3c470 commit e81b205
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 129 deletions.
13 changes: 6 additions & 7 deletions lib/api/simplytranslate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ class SimplyTranslate {
};

Future<String> translate(String inputText, String language) async {
if(!languages.containsKey(language)) {
if (!languages.containsKey(language)) {
return inputText;
}
String translatedText ="";
String translatedText = "";
String url = 'https://simplytranslate.org/?engine=google';
inputText = removeHtmlAttributes(inputText);
List<String> inputTextParts = splitString(inputText, 500);
Expand All @@ -154,9 +154,7 @@ class SimplyTranslate {
};
var response = await http.post(Uri.parse(url), body: payload);
var document = parse(response.body);
translatedText += document
.getElementById('output')
?.text ?? "";
translatedText += document.getElementById('output')?.text ?? "";
}
return translatedText;
}
Expand All @@ -177,12 +175,13 @@ class SimplyTranslate {

return result;
}

String removeHtmlAttributes(String htmlString) {
RegExp exp = RegExp(r'<[^>]+>');
return htmlString.replaceAllMapped(exp, (match) {
String tag = match.group(0)!;
return tag.replaceAll(RegExp(r'\s\S+?="[^"]*?"'), ''); // Removes attributes
return tag.replaceAll(
RegExp(r'\s\S+?="[^"]*?"'), ''); // Removes attributes
});
}

}
4 changes: 1 addition & 3 deletions lib/extractor/trend/apnews.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import 'package:raven/model/trends.dart';

class APNewsTrend extends Trend {

@override
String get url => "https://apnews.com/";

@override
String get locator => ".PageListTrending .PagePromoContentIcons-text";

}
}
4 changes: 1 addition & 3 deletions lib/extractor/trend/brave.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import 'package:raven/model/trends.dart';

class BraveTrend extends Trend {

@override
String get url => "https://search.brave.com/search?q=news";

@override
String get locator => "#news-topics a";

}
}
3 changes: 1 addition & 2 deletions lib/extractor/trend/none.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:raven/model/trends.dart';

class NoneTrend extends Trend {

@override
String get url => "";

Expand All @@ -10,4 +9,4 @@ class NoneTrend extends Trend {

@override
Future<List<String>> get topics async => [];
}
}
4 changes: 1 addition & 3 deletions lib/extractor/trend/yahoo.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import 'package:raven/model/trends.dart';

class YahooTrend extends Trend {

@override
String get url => "https://www.yahoo.com/";

@override
String get locator => ".trendingNowTextList a span:last-child";

}
}
2 changes: 1 addition & 1 deletion lib/model/country.dart
Original file line number Diff line number Diff line change
Expand Up @@ -587,4 +587,4 @@ Map<String, String> countryFlags = {
"Yemen": "🇾🇪",
"Zambia": "🇿🇲",
"Zimbabwe": "🇿🇼",
};
};
7 changes: 4 additions & 3 deletions lib/model/publisher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ abstract class Publisher {
: categoryArticles(category: category, page: page);
}

Future<Set<NewsArticle>> categoryArticles({String category = "All", int page = 1});
Future<Set<NewsArticle>> categoryArticles(
{String category = "All", int page = 1});

Future<Set<NewsArticle>> searchedArticles({required String searchQuery, int page = 1});
Future<Set<NewsArticle>> searchedArticles(
{required String searchQuery, int page = 1});

Future<NewsArticle> article(NewsArticle newsArticle);

Expand All @@ -62,5 +64,4 @@ abstract class Publisher {
'categories': categories,
};
}

}
5 changes: 1 addition & 4 deletions lib/model/trends.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import 'dart:convert';

import 'package:html/dom.dart';
Expand All @@ -19,7 +18,6 @@ Map<String, Trend> trends = {
};

abstract class Trend {

String get url;
String get locator;

Expand All @@ -31,5 +29,4 @@ abstract class Trend {
}
return [];
}

}
}
4 changes: 2 additions & 2 deletions lib/model/user_subscription.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:hive/hive.dart';
part 'user_subscription.g.dart';

@HiveType(typeId: 0)
class UserSubscription extends HiveObject{
class UserSubscription extends HiveObject {
@HiveField(0)
String publisher;

Expand All @@ -27,4 +27,4 @@ class UserSubscription extends HiveObject{

@override
int get hashCode => publisher.hashCode ^ category.hashCode;
}
}
16 changes: 9 additions & 7 deletions lib/pages/full_article.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,20 @@ class _ArticlePageState extends State<ArticlePage> {

TextStyle excerptStyle = TextStyle(fontSize: 16, fontWeight: FontWeight.bold);

Stream<NewsArticle> customArticle(NewsArticle newsArticle, BuildContext context) async* {
Stream<NewsArticle> customArticle(
NewsArticle newsArticle, BuildContext context) async* {
NewsArticle cArticle = await newsArticle.publisher.article(newsArticle);

if (Store.translate) {
var translator = SimplyTranslate();
cArticle.title =
await translator.translate(cArticle.title, Store.languageSetting);
await translator.translate(cArticle.title, Store.languageSetting);
yield cArticle;
cArticle.content =
await translator.translate(cArticle.content, Store.languageSetting);
await translator.translate(cArticle.content, Store.languageSetting);
yield cArticle;
cArticle.excerpt =
await translator.translate(cArticle.excerpt, Store.languageSetting);
await translator.translate(cArticle.excerpt, Store.languageSetting);
yield cArticle;
}

Expand Down Expand Up @@ -94,7 +95,9 @@ class _ArticlePageState extends State<ArticlePage> {
padding: EdgeInsets.fromLTRB(8, 8, 8, 8),
child: ListView(
children: [
snapshot.connectionState != ConnectionState.done ? LinearProgressIndicator():SizedBox.shrink(),
snapshot.connectionState != ConnectionState.done
? LinearProgressIndicator()
: SizedBox.shrink(),
textWidget("", snapshot.data!.title, titleStyle),
textWidget(
"Author", snapshot.data!.author, metadataStyle),
Expand Down Expand Up @@ -125,8 +128,7 @@ class _ArticlePageState extends State<ArticlePage> {
),
),
);
}
else if (snapshot.hasError) {
} else if (snapshot.hasError) {
String fallbackUrl =
"${widget.article.publisher.homePage}${widget.article.url}";
return Scaffold(
Expand Down
3 changes: 1 addition & 2 deletions lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:raven/pages/feed.dart';
import 'package:raven/pages/settings.dart';
import 'package:raven/pages/subscription.dart';


class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});

Expand Down Expand Up @@ -57,4 +56,4 @@ class _MyHomePageState extends State<MyHomePage> {
void dispose() {
super.dispose();
}
}
}
Loading

0 comments on commit e81b205

Please sign in to comment.