Compare commits

..

7 Commits

Author SHA1 Message Date
4e8cf9837f v0.2.13 (#34)
* fixed #32 and #33

* fall back to default browser #31

* fixed story tile.

* fixed version.

* use Listview.builder instead of listview.

* updated link utls.
2022-06-03 00:26:30 -07:00
f73269404a updated README.md 2022-06-01 09:13:35 -07:00
c4c109e4a3 v0.2.12 (#30)
* added metadata to story tile.

* bumped version

* fixed metadata tile

* bumped version.

* fixed pinned stories not being refreshed.
2022-06-01 01:34:21 -07:00
b7720d0584 v0.2.12 (#29)
* added metadata to story tile.

* bumped version

* fixed metadata tile

* bumped version.
2022-06-01 01:13:21 -07:00
7d5788dec3 updated README.md 2022-05-28 00:03:46 -07:00
80a836c6b9 updated README.md 2022-05-28 00:02:03 -07:00
913be9fc5d v0.2.11 (#27)
* fixed pinned story tile.

* bumped version.
2022-05-27 16:18:36 -07:00
38 changed files with 535 additions and 344 deletions

View File

@ -3,7 +3,7 @@
A simple noiseless [Hacker News](https://news.ycombinator.com/) client made with Flutter that is just enough.
[![App Store](https://img.shields.io/itunes/v/1602043763?label=App%20Store)](https://apps.apple.com/us/app/hacki/id1602043763)
[![App Store](https://img.shields.io/itunes/v/1602043763?label=App%20Store)](https://apps.apple.com/us/app/hacki/id1602043763?platform=iphone)
[![Play Store](https://img.shields.io/badge/Play%20Store--yellow)](https://play.google.com/store/apps/details?id=com.jiaqifeng.hacki&hl=en_US&gl=US)
[![Visits Badge](https://badges.pufler.dev/visits/livinglist/Hacki)](https://badges.pufler.dev)
[![GitHub](https://img.shields.io/github/stars/livinglist/Hacki?style=social)](https://img.shields.io/github/stars/livinglist/Hacki?style=social)
@ -11,7 +11,7 @@ A simple noiseless [Hacker News](https://news.ycombinator.com/) client made with
<noscript><a href="https://liberapay.com/jfeng_for_open_source/donate"><img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg"></a></noscript>
[<img src="assets/images/app_store_badge.png" height="50">](https://apps.apple.com/us/app/hacki/id1602043763) [<img src="assets/images/google_play_badge.png" height="50">](https://play.google.com/store/apps/details?id=com.jiaqifeng.hacki&hl=en_US&gl=US) [<img src="assets/images/f_droid_badge.png" height="50">](https://f-droid.org/en/packages/com.jiaqifeng.hacki/)
[<img src="assets/images/app_store_badge.png" height="50">](https://apps.apple.com/us/app/hacki/id1602043763?platform=iphone) [<img src="assets/images/google_play_badge.png" height="50">](https://play.google.com/store/apps/details?id=com.jiaqifeng.hacki&hl=en_US&gl=US) [<img src="assets/images/f_droid_badge.png" height="50">](https://f-droid.org/en/packages/com.jiaqifeng.hacki/)
Features:
@ -34,20 +34,19 @@ Features:
- Launch from system share sheet.
- And more...
<p align="center">
<img width="200" alt="Screen Shot 2020-03-03 at 1 22 57 PM" src="https://user-images.githubusercontent.com/7277662/159799288-6e98352a-fe89-4a2e-8a74-c5782463a1e1.png">
<img width="200" alt="Screen Shot 2020-03-03 at 1 22 57 PM" src="https://user-images.githubusercontent.com/7277662/159799297-75b52eac-2066-4df9-bdfc-7c82bf7b81c8.png">
<img width="200" alt="Screen Shot 2020-03-03 at 1 22 57 PM" src="https://user-images.githubusercontent.com/7277662/159799302-860c61b8-abba-486a-9592-bc84a6af3232.png">
<img width="200" alt="Screen Shot 2020-03-03 at 1 22 57 PM" src="https://user-images.githubusercontent.com/7277662/159799305-308743d3-1c89-45de-9645-3b6ec789c282.png">
<img width="200" alt="Screen Shot 2020-03-03 at 1 22 57 PM" src="https://user-images.githubusercontent.com/7277662/159798176-5212e9bf-296d-4d9b-ab48-19b741684c8a.png">
<img width="200" alt="Screen Shot 2020-03-03 at 1 22 57 PM" src="https://user-images.githubusercontent.com/7277662/171450528-02c561ed-0ebb-4c1b-9ee0-a935211db0f2.png">
<img width="200" alt="Screen Shot 2020-03-03 at 1 22 57 PM" src="https://user-images.githubusercontent.com/7277662/171450536-ea61c176-37d7-4744-8674-4668e0e7e774.png">
<img width="200" alt="Screen Shot 2020-03-03 at 1 22 57 PM" src="https://user-images.githubusercontent.com/7277662/171450541-a9af3417-526f-4dbd-96d7-781c95c886d3.png">
<img width="200" alt="Screen Shot 2020-03-03 at 1 22 57 PM" src="https://user-images.githubusercontent.com/7277662/171450543-fb631b02-5f46-4455-b8ff-9ef119a486f1.png">
<img width="200" alt="Screen Shot 2020-03-03 at 1 22 57 PM" src="https://user-images.githubusercontent.com/7277662/171450548-38e98b02-6201-48c9-9674-87bdfc61f456.png">
<img width="200" alt="Screen Shot 2020-03-03 at 1 22 57 PM" src="https://user-images.githubusercontent.com/7277662/159798179-72edbe49-7444-4e54-a07c-fc1244447a74.png">
<img width="200" alt="Screen Shot 2020-03-03 at 1 22 57 PM" src="https://user-images.githubusercontent.com/7277662/159798182-28397805-a7cc-4124-b65b-c02c80afbbec.png">
<img width="200" alt="Screen Shot 2020-03-03 at 1 22 57 PM" src="https://user-images.githubusercontent.com/7277662/159798183-c2984270-ee99-4419-841e-65e98890464f.png">
<img width="200" alt="Screen Shot 2020-03-03 at 1 22 57 PM" src="https://user-images.githubusercontent.com/7277662/159798184-2fce5d97-710e-44a7-b99a-3296ebcf273b.png">
<img width="200" alt="Screen Shot 2020-03-03 at 1 22 57 PM" src="https://user-images.githubusercontent.com/7277662/159798185-d7c81348-956e-483c-a1bc-5cd872bdad62.png">
<img width="200" alt="Screen Shot 2020-03-03 at 1 22 57 PM" src="https://user-images.githubusercontent.com/7277662/159798186-1457ae21-f1aa-40a4-9206-0f3a1e24653e.png">
<img width="200" alt="Screen Shot 2020-03-03 at 1 22 57 PM" src="https://user-images.githubusercontent.com/7277662/159798187-4404adea-b2bc-472e-8568-2379e6db01a4.png">
<img width="200" alt="Screen Shot 2020-03-03 at 1 22 57 PM" src="https://user-images.githubusercontent.com/7277662/171450557-ab038e72-78c4-4daf-9b77-3873be1700db.png">
<img width="400" alt="Screen Shot 2020-03-03 at 1 22 57 PM" src="https://user-images.githubusercontent.com/7277662/160162711-a9146326-9645-4db6-a04e-1f82e6133e40.png">
<img width="400" alt="Screen Shot 2020-03-03 at 1 22 57 PM" src="https://user-images.githubusercontent.com/7277662/160162726-ef1d3f2a-5179-417c-8a5f-0cddb52249da.png">

View File

@ -9,6 +9,10 @@
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="*/*" />
</intent>
</queries>
<application

View File

@ -0,0 +1,4 @@
- You can now participate in polls.
- Pick up where you left off.
- Swipe left on comment tile to view its parents without scrolling all the way up.
- Huge performance boost.

View File

@ -0,0 +1,4 @@
- You can now participate in polls.
- Pick up where you left off.
- Swipe left on comment tile to view its parents without scrolling all the way up.
- Huge performance boost.

View File

@ -0,0 +1,4 @@
- You can now participate in polls.
- Pick up where you left off.
- Swipe left on comment tile to view its parents without scrolling all the way up.
- Huge performance boost.

View File

@ -0,0 +1,5 @@
- You can now participate in polls.
- Pick up where you left off.
- Swipe left on comment tile to view its parents without scrolling all the way up.
- Huge performance boost.
- Bugfixes.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 393 KiB

After

Width:  |  Height:  |  Size: 422 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 696 KiB

After

Width:  |  Height:  |  Size: 712 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 250 KiB

After

Width:  |  Height:  |  Size: 252 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 231 KiB

After

Width:  |  Height:  |  Size: 262 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 903 KiB

After

Width:  |  Height:  |  Size: 672 KiB

View File

@ -568,7 +568,7 @@
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = QMWX3X2NF7;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
@ -577,7 +577,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.2.10;
MARKETING_VERSION = 0.2.13;
PRODUCT_BUNDLE_IDENTIFIER = com.jiaqi.hacki;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@ -705,7 +705,7 @@
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = QMWX3X2NF7;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
@ -714,7 +714,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.2.10;
MARKETING_VERSION = 0.2.13;
PRODUCT_BUNDLE_IDENTIFIER = com.jiaqi.hacki;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@ -736,7 +736,7 @@
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = QMWX3X2NF7;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
@ -745,7 +745,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.2.10;
MARKETING_VERSION = 0.2.13;
PRODUCT_BUNDLE_IDENTIFIER = com.jiaqi.hacki;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";

View File

@ -39,6 +39,12 @@
</array>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>https</string>
<string>http</string>
<string>mailto</string>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIBackgroundModes</key>

View File

@ -55,21 +55,21 @@ class CollapseCubit extends Cubit<CollapseState> {
}
void hiddenCommentsStreamListener(Map<int, Set<int>> event) {
int collapsedCount = 0;
for (final int key in event.keys) {
if (key == _commentId && !isClosed) {
emit(
state.copyWith(
collapsedCount: event[key]?.length ?? 0,
),
);
return;
collapsedCount = event[key]?.length ?? 0;
break;
}
}
for (final Set<int> val in event.values) {
if (val.contains(_commentId) && !isClosed) {
emit(
state.copyWith(hidden: true),
state.copyWith(
hidden: true,
collapsedCount: collapsedCount,
),
);
return;
}
@ -77,7 +77,10 @@ class CollapseCubit extends Cubit<CollapseState> {
if (!isClosed) {
emit(
state.copyWith(hidden: false),
state.copyWith(
hidden: false,
collapsedCount: collapsedCount,
),
);
}
}

View File

@ -52,6 +52,8 @@ class PinCubit extends Cubit<PinState> {
_preferenceRepository.updatePinnedStoriesIds(state.pinnedStoriesIds);
}
void refresh() => init();
void _onStoryFetched(Story story) {
emit(state.copyWith(pinnedStories: <Story>[...state.pinnedStories, story]));
}

View File

@ -31,6 +31,8 @@ class PreferenceCubit extends Cubit<PreferenceState> {
.then((bool value) => emit(state.copyWith(useReader: value)));
_preferenceRepository.markReadStories
.then((bool value) => emit(state.copyWith(markReadStories: value)));
_preferenceRepository.shouldShowMetadata
.then((bool value) => emit(state.copyWith(showMetadata: value)));
}
void toggleNotificationMode() {
@ -67,4 +69,9 @@ class PreferenceCubit extends Cubit<PreferenceState> {
emit(state.copyWith(markReadStories: !state.markReadStories));
_preferenceRepository.toggleMarkReadStoriesMode();
}
void toggleMetadataMode() {
emit(state.copyWith(showMetadata: !state.showMetadata));
_preferenceRepository.toggleMetadataMode();
}
}

View File

@ -9,6 +9,7 @@ class PreferenceState extends Equatable {
required this.useTrueDark,
required this.useReader,
required this.markReadStories,
required this.showMetadata,
});
const PreferenceState.init()
@ -18,7 +19,8 @@ class PreferenceState extends Equatable {
showEyeCandy = false,
useTrueDark = false,
useReader = false,
markReadStories = false;
markReadStories = false,
showMetadata = false;
final bool showNotification;
final bool showComplexStoryTile;
@ -27,6 +29,7 @@ class PreferenceState extends Equatable {
final bool useTrueDark;
final bool useReader;
final bool markReadStories;
final bool showMetadata;
PreferenceState copyWith({
bool? showNotification,
@ -36,6 +39,7 @@ class PreferenceState extends Equatable {
bool? useTrueDark,
bool? useReader,
bool? markReadStories,
bool? showMetadata,
}) {
return PreferenceState(
showNotification: showNotification ?? this.showNotification,
@ -45,6 +49,7 @@ class PreferenceState extends Equatable {
useTrueDark: useTrueDark ?? this.useTrueDark,
useReader: useReader ?? this.useReader,
markReadStories: markReadStories ?? this.markReadStories,
showMetadata: showMetadata ?? this.showMetadata,
);
}
@ -57,5 +62,6 @@ class PreferenceState extends Equatable {
useTrueDark,
useReader,
markReadStories,
showMetadata,
];
}

View File

@ -4,4 +4,11 @@ extension StringExtension on String {
final String match = regex.stringMatch(this) ?? '';
return int.tryParse(match);
}
String removeAllEmojis() {
final RegExp regex = RegExp(
r'(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])',
);
return replaceAllMapped(regex, (_) => '');
}
}

View File

@ -70,6 +70,12 @@ class Story extends Item {
parent: 0,
);
String get metadata =>
'''$score point${score > 1 ? 's' : ''} by $by $postedDate | $descendants comment${descendants > 1 ? 's' : ''}''';
String get simpleMetadata =>
'''$score point${score > 1 ? 's' : ''} $descendants comment${descendants > 1 ? 's' : ''} $postedDate''';
String get postedDate =>
DateTime.fromMillisecondsSinceEpoch(time * 1000).toReadableString();

View File

@ -21,6 +21,7 @@ class PreferenceRepository {
static const String _unreadCommentsIdsKey = 'unreadCommentsIds';
static const String _lastReadStoryIdKey = 'lastReadStoryId';
static const String _isFirstLaunchKey = 'isFirstLaunch';
static const String _metadataModeKey = 'metadataMode';
static const String _notificationModeKey = 'notificationMode';
static const String _readerModeKey = 'readerMode';
@ -46,6 +47,7 @@ class PreferenceRepository {
static const bool _readerModeDefaultValue = true;
static const bool _markReadStoriesModeDefaultValue = true;
static const bool _isFirstLaunchKeyDefaultValue = true;
static const bool _metadataModeDefaultValue = true;
final SyncedSharedPreferences _syncedPrefs;
final Future<SharedPreferences> _prefs;
@ -67,29 +69,6 @@ class PreferenceRepository {
return val;
}
Future<List<String>> get blocklist async => _prefs.then(
(SharedPreferences prefs) =>
prefs.getStringList(_blocklistKey) ?? <String>[],
);
Future<List<int>> get pinnedStoriesIds async {
if (Platform.isIOS) {
final List<String>? favList = await _syncedPrefs.getStringList(
key: _pinnedStoriesIdsKey,
);
return favList?.map(int.parse).toList() ?? <int>[];
} else {
return _prefs.then(
(SharedPreferences prefs) =>
prefs
.getStringList(_pinnedStoriesIdsKey)
?.map(int.parse)
.toList() ??
<int>[],
);
}
}
Future<bool> get shouldShowNotification async => _prefs.then(
(SharedPreferences prefs) =>
prefs.getBool(_notificationModeKey) ??
@ -111,6 +90,11 @@ class PreferenceRepository {
prefs.getBool(_eyeCandyModeKey) ?? _eyeCandyModeDefaultValue,
);
Future<bool> get shouldShowMetadata async => _prefs.then(
(SharedPreferences prefs) =>
prefs.getBool(_metadataModeKey) ?? _metadataModeDefaultValue,
);
Future<bool> get trueDarkMode async => _prefs.then(
(SharedPreferences prefs) =>
prefs.getBool(trueDarkModeKey) ?? _trueDarkModeDefaultValue,
@ -127,24 +111,6 @@ class PreferenceRepository {
_markReadStoriesModeDefaultValue,
);
Future<List<int>> get unreadCommentsIds async => _prefs.then(
(SharedPreferences prefs) =>
prefs
.getStringList(_unreadCommentsIdsKey)
?.map(int.parse)
.toList() ??
<int>[],
);
Future<int?> get lastReadStoryId async =>
_prefs.then((SharedPreferences prefs) {
final String? val = prefs.getString(_lastReadStoryIdKey);
if (val == null) return null;
return int.tryParse(val);
});
Future<bool> hasPushed(int commentId) async =>
_prefs.then((SharedPreferences prefs) {
final bool? val = prefs.getBool(_getPushNotificationKey(commentId));
@ -170,53 +136,6 @@ class PreferenceRepository {
}
}
Future<List<int>> favList({required String of}) async {
final SharedPreferences prefs = await _prefs;
if (Platform.isIOS) {
final List<String> previousList =
((prefs.getStringList(_getFavKey('')) ?? <String>[])
..addAll(prefs.getStringList(_getFavKey(of)) ?? <String>[]))
.toList();
/// Since v0.2.5, fav list will be stored in [NSUbiquitousKeyValueStore]
/// instead of [UserDefaults] on iOS.
if (previousList.isNotEmpty) {
for (final String fav in previousList) {
await addFav(username: of, id: int.parse(fav));
}
await prefs.remove(_getFavKey(''));
await prefs.remove(_getFavKey(of));
}
final List<String>? initialList =
await _syncedPrefs.getStringList(key: _getFavKey(''));
final List<String>? userList =
await _syncedPrefs.getStringList(key: _getFavKey(of));
return <String>{
...?initialList,
...?userList,
}.map(int.parse).toList();
} else {
final List<int> favList =
((prefs.getStringList(_getFavKey('')) ?? <String>[])
..addAll(prefs.getStringList(_getFavKey(of)) ?? <String>[]))
.map(int.parse)
.toSet()
.toList();
return favList;
}
}
Future<bool?> vote({required int submittedTo, required String from}) async {
final SharedPreferences prefs = await _prefs;
final String key = _getVoteKey(from, submittedTo);
final bool? vote = prefs.getBool(key);
return vote;
}
Future<void> setAuth({
required String username,
required String password,
@ -279,6 +198,55 @@ class PreferenceRepository {
await prefs.setBool(_markReadStoriesModeKey, !currentMode);
}
Future<void> toggleMetadataMode() async {
final SharedPreferences prefs = await _prefs;
final bool currentMode =
prefs.getBool(_metadataModeKey) ?? _metadataModeDefaultValue;
await prefs.setBool(_metadataModeKey, !currentMode);
}
//#region fav
Future<List<int>> favList({required String of}) async {
final SharedPreferences prefs = await _prefs;
if (Platform.isIOS) {
final List<String> previousList =
((prefs.getStringList(_getFavKey('')) ?? <String>[])
..addAll(prefs.getStringList(_getFavKey(of)) ?? <String>[]))
.toList();
/// Since v0.2.5, fav list will be stored in [NSUbiquitousKeyValueStore]
/// instead of [UserDefaults] on iOS.
if (previousList.isNotEmpty) {
for (final String fav in previousList) {
await addFav(username: of, id: int.parse(fav));
}
await prefs.remove(_getFavKey(''));
await prefs.remove(_getFavKey(of));
}
final List<String>? initialList =
await _syncedPrefs.getStringList(key: _getFavKey(''));
final List<String>? userList =
await _syncedPrefs.getStringList(key: _getFavKey(of));
return <String>{
...?initialList,
...?userList,
}.map(int.parse).toList();
} else {
final List<int> favList =
((prefs.getStringList(_getFavKey('')) ?? <String>[])
..addAll(prefs.getStringList(_getFavKey(of)) ?? <String>[]))
.map(int.parse)
.toSet()
.toList();
return favList;
}
}
Future<void> addFav({required String username, required int id}) async {
final String key = _getFavKey(username);
@ -331,6 +299,19 @@ class PreferenceRepository {
}
}
static String _getFavKey(String username) => 'fav_$username';
//#endregion
//#region vote
Future<bool?> vote({required int submittedTo, required String from}) async {
final SharedPreferences prefs = await _prefs;
final String key = _getVoteKey(from, submittedTo);
final bool? vote = prefs.getBool(key);
return vote;
}
Future<void> addVote({
required String username,
required int id,
@ -350,11 +331,44 @@ class PreferenceRepository {
await prefs.remove(key);
}
String _getVoteKey(String username, int id) => 'vote_$username-$id';
//#endregion
//#region blocklist
Future<List<String>> get blocklist async => _prefs.then(
(SharedPreferences prefs) =>
prefs.getStringList(_blocklistKey) ?? <String>[],
);
Future<void> updateBlocklist(List<String> usernames) async {
final SharedPreferences prefs = await _prefs;
await prefs.setStringList(_blocklistKey, usernames);
}
//#endregion
//#region pins
Future<List<int>> get pinnedStoriesIds async {
if (Platform.isIOS) {
final List<String>? favList = await _syncedPrefs.getStringList(
key: _pinnedStoriesIdsKey,
);
return favList?.map(int.parse).toList() ?? <int>[];
} else {
return _prefs.then(
(SharedPreferences prefs) =>
prefs
.getStringList(_pinnedStoriesIdsKey)
?.map(int.parse)
.toList() ??
<int>[],
);
}
}
Future<void> updatePinnedStoriesIds(List<int> ids) async {
if (Platform.isIOS) {
await _syncedPrefs.setStringList(
@ -370,6 +384,19 @@ class PreferenceRepository {
}
}
//#endregion
//#region unread comment ids
Future<List<int>> get unreadCommentsIds async => _prefs.then(
(SharedPreferences prefs) =>
prefs
.getStringList(_unreadCommentsIdsKey)
?.map(int.parse)
.toList() ??
<int>[],
);
Future<void> updateUnreadCommentsIds(List<int> ids) async {
final SharedPreferences prefs = await _prefs;
await prefs.setStringList(
@ -378,6 +405,19 @@ class PreferenceRepository {
);
}
//#endregion
//#region reminder
Future<int?> get lastReadStoryId async =>
_prefs.then((SharedPreferences prefs) {
final String? val = prefs.getString(_lastReadStoryIdKey);
if (val == null) return null;
return int.tryParse(val);
});
Future<void> updateLastReadStoryId(int? id) async {
final SharedPreferences prefs = await _prefs;
await prefs.setString(
@ -386,6 +426,8 @@ class PreferenceRepository {
);
}
//#endregion
Future<void> updateHasPushed(int commentId) async {
final SharedPreferences prefs = await _prefs;
await prefs.setBool(
@ -422,11 +464,7 @@ class PreferenceRepository {
}
}
String _getPushNotificationKey(int commentId) => 'pushed_$commentId';
static String _getPushNotificationKey(int commentId) => 'pushed_$commentId';
String _getFavKey(String username) => 'fav_$username';
String _getVoteKey(String username, int id) => 'vote_$username-$id';
String _getHasReadKey(int storyId) => 'hasRead_$storyId';
static String _getHasReadKey(int storyId) => 'hasRead_$storyId';
}

View File

@ -28,6 +28,8 @@ class SearchRepository {
final String by = hit['author'] as String? ?? '';
final String title = hit['title'] as String? ?? '';
final int createdAt = hit['created_at_i'] as int? ?? 0;
final int score = hit['points'] as int? ?? 0;
final int descendants = hit['num_comments'] as int? ?? 0;
// Getting rid of comments, only keeping stories for convenience.
// Don't judge me.
@ -46,9 +48,9 @@ class SearchRepository {
final int id = int.parse(hit['objectID'] as String? ?? '0');
final Story story = Story(
descendants: 0,
descendants: descendants,
id: id,
score: 0,
score: score,
time: createdAt,
by: by,
title: title,

View File

@ -140,7 +140,8 @@ class _HomeScreenState extends State<HomeScreen>
final BlocBuilder<PreferenceCubit, PreferenceState> homeScreen =
BlocBuilder<PreferenceCubit, PreferenceState>(
buildWhen: (PreferenceState previous, PreferenceState current) =>
previous.showComplexStoryTile != current.showComplexStoryTile,
previous.showComplexStoryTile != current.showComplexStoryTile ||
previous.showMetadata != current.showMetadata,
builder: (BuildContext context, PreferenceState preferenceState) {
final BlocBuilder<PinCubit, PinState> pinnedStories =
BlocBuilder<PinCubit, PinState>(
@ -172,8 +173,9 @@ class _HomeScreenState extends State<HomeScreen>
child: StoryTile(
key: ObjectKey(story),
story: story,
onTap: () => onStoryTapped(story),
onTap: () => onStoryTapped(story, isPin: true),
showWebPreview: preferenceState.showComplexStoryTile,
showMetadata: preferenceState.showMetadata,
),
),
),
@ -408,13 +410,13 @@ class _HomeScreenState extends State<HomeScreen>
return Future<bool>.value(false);
}
void onStoryTapped(Story story) {
void onStoryTapped(Story story, {bool isPin = false}) {
final bool showWebFirst =
context.read<PreferenceCubit>().state.showWebFirst;
final bool useReader = context.read<PreferenceCubit>().state.useReader;
final bool offlineReading =
context.read<StoriesBloc>().state.offlineReading;
final bool hasRead = context.read<StoriesBloc>().hasRead(story);
final bool hasRead = isPin || context.read<StoriesBloc>().hasRead(story);
final bool splitViewEnabled = context.read<SplitViewCubit>().state.enabled;
// If a story is a job story and it has a link to the job posting,
@ -443,7 +445,7 @@ class _HomeScreenState extends State<HomeScreen>
}
if (!offlineReading && (isJobWithLink || (showWebFirst && !hasRead))) {
LinkUtil.launchUrl(story.url, useReader: useReader);
LinkUtil.launch(story.url, useReader: useReader);
}
context.read<StoriesBloc>().add(

View File

@ -119,6 +119,7 @@ class _ProfileScreenState extends State<ProfileScreen>
return ItemsListView<Item>(
showWebPreview: false,
showMetadata: false,
useConsistentFontSize: true,
refreshController: refreshControllerHistory,
items: historyState.submittedItems
@ -170,6 +171,7 @@ class _ProfileScreenState extends State<ProfileScreen>
return ItemsListView<Story>(
showWebPreview:
preferenceState.showComplexStoryTile,
showMetadata: preferenceState.showMetadata,
refreshController: refreshControllerFav,
items: favState.favStories,
onRefresh: () {
@ -292,6 +294,21 @@ class _ProfileScreenState extends State<ProfileScreen>
},
activeColor: Colors.orange,
),
SwitchListTile(
title: const Text('Show Metadata'),
subtitle: const Text(
'show number of comments and post date'
' in story tile.',
),
value: preferenceState.showMetadata,
onChanged: (bool val) {
HapticFeedback.lightImpact();
context
.read<PreferenceCubit>()
.toggleMetadataMode();
},
activeColor: Colors.orange,
),
SwitchListTile(
title: const Text('Show Web Page First'),
subtitle: const Text(
@ -390,7 +407,7 @@ class _ProfileScreenState extends State<ProfileScreen>
showAboutDialog(
context: context,
applicationName: 'Hacki',
applicationVersion: 'v0.2.10',
applicationVersion: 'v0.2.13',
applicationIcon: ClipRRect(
borderRadius: const BorderRadius.all(
Radius.circular(12),
@ -403,7 +420,7 @@ class _ProfileScreenState extends State<ProfileScreen>
),
children: <Widget>[
ElevatedButton(
onPressed: () => LinkUtil.launchUrl(
onPressed: () => LinkUtil.launch(
Constants.portfolioLink,
),
child: Row(
@ -419,7 +436,7 @@ class _ProfileScreenState extends State<ProfileScreen>
),
),
ElevatedButton(
onPressed: () => LinkUtil.launchUrl(
onPressed: () => LinkUtil.launch(
Constants.githubLink,
),
child: Row(
@ -435,7 +452,7 @@ class _ProfileScreenState extends State<ProfileScreen>
),
),
ElevatedButton(
onPressed: () => LinkUtil.launchUrl(
onPressed: () => LinkUtil.launch(
Platform.isIOS
? Constants.appStoreLink
: Constants.googlePlayLink,
@ -806,7 +823,7 @@ class _ProfileScreenState extends State<ProfileScreen>
child: Transform.translate(
offset: const Offset(0, 1),
child: TapDownWrapper(
onTap: () => LinkUtil.launchUrl(
onTap: () => LinkUtil.launch(
Constants.endUserAgreementLink,
),
child: const Text(

View File

@ -107,7 +107,7 @@ class InboxView extends StatelessWidget {
),
maxLines: 4,
onOpen: (LinkableElement link) =>
LinkUtil.launchUrl(link.url),
LinkUtil.launch(link.url),
),
),
),

View File

@ -102,6 +102,7 @@ class _SearchScreenState extends State<SearchScreen> {
child: StoryTile(
showWebPreview:
prefState.showComplexStoryTile,
showMetadata: prefState.showMetadata,
story: e,
onTap: () => goToStoryScreen(
args: StoryScreenArgs(story: e),

View File

@ -140,6 +140,7 @@ class _StoryScreenState extends State<StoryScreen> {
delay: _featureDiscoveryDismissThrottleDelay,
);
static const int _extraItemsCount = 2;
static const Duration _storyLinkTapThrottleDelay = Duration(seconds: 2);
static const Duration _featureDiscoveryDismissThrottleDelay =
Duration(seconds: 1);
@ -269,209 +270,229 @@ class _StoryScreenState extends State<StoryScreen> {
onLoading: () {
context.read<CommentsCubit>().loadMore();
},
child: ListView(
child: ListView.builder(
primary: false,
children: <Widget>[
SizedBox(
height: topPadding,
),
if (!widget.splitViewEnabled)
const Padding(
padding: EdgeInsets.only(bottom: 6),
child: OfflineBanner(),
),
Slidable(
startActionPane: ActionPane(
motion: const BehindMotion(),
itemCount: state.comments.length + _extraItemsCount,
itemBuilder: (BuildContext context, int index) {
if (index == 0) {
return Column(
children: <Widget>[
SlidableAction(
onPressed: (_) {
HapticFeedback.lightImpact();
if (widget.story !=
context.read<EditCubit>().state.replyingTo) {
commentEditingController.clear();
}
context
.read<EditCubit>()
.onReplyTapped(widget.story);
focusNode.requestFocus();
},
backgroundColor: Colors.orange,
foregroundColor: Colors.white,
icon: Icons.message,
SizedBox(
height: topPadding,
),
SlidableAction(
onPressed: (_) => onMorePressed(widget.story),
backgroundColor: Colors.orange,
foregroundColor: Colors.white,
icon: Icons.more_horiz,
),
],
),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(
left: 6,
right: 6,
if (!widget.splitViewEnabled)
const Padding(
padding: EdgeInsets.only(bottom: 6),
child: OfflineBanner(),
),
child: Row(
Slidable(
startActionPane: ActionPane(
motion: const BehindMotion(),
children: <Widget>[
Text(
widget.story.by,
style: const TextStyle(
color: Colors.orange,
),
SlidableAction(
onPressed: (_) {
HapticFeedback.lightImpact();
if (widget.story !=
context
.read<EditCubit>()
.state
.replyingTo) {
commentEditingController.clear();
}
context
.read<EditCubit>()
.onReplyTapped(widget.story);
focusNode.requestFocus();
},
backgroundColor: Colors.orange,
foregroundColor: Colors.white,
icon: Icons.message,
),
const Spacer(),
Text(
widget.story.postedDate,
style: const TextStyle(
color: Colors.grey,
),
SlidableAction(
onPressed: (_) => onMorePressed(widget.story),
backgroundColor: Colors.orange,
foregroundColor: Colors.white,
icon: Icons.more_horiz,
),
],
),
),
InkWell(
onTap: () => LinkUtil.launchUrl(
widget.story.url,
useReader: context
.read<PreferenceCubit>()
.state
.useReader,
),
child: Padding(
padding: const EdgeInsets.only(
left: 6,
right: 6,
bottom: 12,
top: 12,
),
child: Text(
widget.story.title,
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
color: widget.story.url.isNotEmpty
? Colors.orange
: null,
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(
left: 6,
right: 6,
),
child: Row(
children: <Widget>[
Text(
widget.story.by,
style: const TextStyle(
color: Colors.orange,
),
),
const Spacer(),
Text(
widget.story.postedDate,
style: const TextStyle(
color: Colors.grey,
),
),
],
),
),
),
InkWell(
onTap: () => LinkUtil.launch(
widget.story.url,
useReader: context
.read<PreferenceCubit>()
.state
.useReader,
),
child: Padding(
padding: const EdgeInsets.only(
left: 6,
right: 6,
bottom: 12,
top: 12,
),
child: Text(
widget.story.title,
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
color: widget.story.url.isNotEmpty
? Colors.orange
: null,
),
),
),
),
if (widget.story.text.isNotEmpty)
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 10,
),
child: SelectableLinkify(
text: widget.story.text,
style: TextStyle(
fontSize: MediaQuery.of(context)
.textScaleFactor *
15,
),
linkStyle: TextStyle(
fontSize: MediaQuery.of(context)
.textScaleFactor *
15,
color: Colors.orange,
),
onOpen: (LinkableElement link) {
if (link.url.contains(
'news.ycombinator.com/item',
)) {
onStoryLinkTapped(link.url);
} else {
LinkUtil.launch(link.url);
}
},
),
),
if (widget.story.isPoll)
PollView(
onLoginTapped: onLoginTapped,
),
],
),
),
if (widget.story.text.isNotEmpty)
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 10,
),
child: SelectableLinkify(
text: widget.story.text,
style: TextStyle(
fontSize:
MediaQuery.of(context).textScaleFactor *
15,
),
linkStyle: TextStyle(
fontSize:
MediaQuery.of(context).textScaleFactor *
15,
color: Colors.orange,
),
onOpen: (LinkableElement link) {
if (link.url.contains(
'news.ycombinator.com/item',
)) {
onStoryLinkTapped(link.url);
} else {
LinkUtil.launchUrl(link.url);
}
},
const SizedBox(
height: 8,
),
const Divider(
height: 0,
),
if (state.onlyShowTargetComment) ...<Widget>[
TextButton(
onPressed: () => context
.read<CommentsCubit>()
.loadAll(widget.story),
child: const Text('View all comments'),
),
const Divider(
height: 0,
),
],
if (state.comments.isEmpty &&
state.status ==
CommentsStatus.allLoaded) ...<Widget>[
const SizedBox(
height: 240,
),
const Center(
child: Text(
'Nothing yet',
style: TextStyle(color: Colors.grey),
),
),
if (widget.story.isPoll)
PollView(
onLoginTapped: onLoginTapped,
),
],
],
),
),
if (widget.story.text.isNotEmpty)
const SizedBox(
height: 8,
),
const Divider(
height: 0,
),
if (state.onlyShowTargetComment) ...<Widget>[
TextButton(
onPressed: () =>
context.read<CommentsCubit>().loadAll(widget.story),
child: const Text('View all comments'),
),
const Divider(
height: 0,
),
],
if (state.comments.isEmpty &&
state.status == CommentsStatus.allLoaded) ...<Widget>[
const SizedBox(
height: 240,
),
const Center(
child: Text(
'Nothing yet',
style: TextStyle(color: Colors.grey),
),
),
],
for (final Comment e in state.comments)
FadeIn(
child: CommentTile(
comment: e,
level: e.level,
myUsername:
authState.isLoggedIn ? authState.username : null,
opUsername: widget.story.by,
onReplyTapped: (Comment cmt) {
HapticFeedback.lightImpact();
if (cmt.deleted || cmt.dead) {
return;
}
);
} else if (index ==
state.comments.length + _extraItemsCount - 1) {
if ((state.status == CommentsStatus.allLoaded &&
state.comments.isNotEmpty) ||
state.onlyShowTargetComment) {
return SizedBox(
height: 240,
child: Center(
child: Text(happyFace),
),
);
}
if (cmt !=
context.read<EditCubit>().state.replyingTo) {
commentEditingController.clear();
}
return const SizedBox.shrink();
}
context.read<EditCubit>().onReplyTapped(cmt);
focusNode.requestFocus();
},
onEditTapped: (Comment cmt) {
HapticFeedback.lightImpact();
if (cmt.deleted || cmt.dead) {
return;
}
final Comment comment = state.comments.elementAt(index - 1);
return FadeIn(
key: ValueKey<int>(comment.id),
child: CommentTile(
comment: comment,
level: comment.level,
myUsername:
authState.isLoggedIn ? authState.username : null,
opUsername: widget.story.by,
onReplyTapped: (Comment cmt) {
HapticFeedback.lightImpact();
if (cmt.deleted || cmt.dead) {
return;
}
if (cmt !=
context.read<EditCubit>().state.replyingTo) {
commentEditingController.clear();
context.read<EditCubit>().onEditTapped(cmt);
focusNode.requestFocus();
},
onMoreTapped: onMorePressed,
onStoryLinkTapped: onStoryLinkTapped,
onTimeMachineActivated: onTimeMachineActivated,
),
}
context.read<EditCubit>().onReplyTapped(cmt);
focusNode.requestFocus();
},
onEditTapped: (Comment cmt) {
HapticFeedback.lightImpact();
if (cmt.deleted || cmt.dead) {
return;
}
commentEditingController.clear();
context.read<EditCubit>().onEditTapped(cmt);
focusNode.requestFocus();
},
onMoreTapped: onMorePressed,
onStoryLinkTapped: onStoryLinkTapped,
onTimeMachineActivated: onTimeMachineActivated,
),
if ((state.status == CommentsStatus.allLoaded &&
state.comments.isNotEmpty) ||
state.onlyShowTargetComment)
SizedBox(
height: 240,
child: Center(
child: Text(happyFace),
),
),
],
);
},
),
);
@ -674,7 +695,7 @@ class _StoryScreenState extends State<StoryScreen> {
});
});
} else {
LinkUtil.launchUrl(link);
LinkUtil.launch(link);
}
}
@ -1093,7 +1114,7 @@ class _StoryScreenState extends State<StoryScreen> {
child: Transform.translate(
offset: const Offset(0, 1),
child: TapDownWrapper(
onTap: () => LinkUtil.launchUrl(
onTap: () => LinkUtil.launch(
Constants.endUserAgreementLink,
),
child: const Text(

View File

@ -47,7 +47,7 @@ class LinkIconButton extends StatelessWidget {
),
),
onPressed: () =>
LinkUtil.launchUrl('https://news.ycombinator.com/item?id=$storyId'),
LinkUtil.launch('https://news.ycombinator.com/item?id=$storyId'),
);
}
}

View File

@ -124,7 +124,7 @@ class PollView extends StatelessWidget {
option.text,
),
Text(
'${option.score} votes',
'''${option.score} vote${option.score > 1 ? 's' : ''}''',
style: const TextStyle(
color: Colors.grey,
fontSize: 12,

View File

@ -273,7 +273,7 @@ class _ReplyBoxState extends State<ReplyBox> {
color: Colors.orange,
),
onOpen: (LinkableElement link) =>
LinkUtil.launchUrl(link.url),
LinkUtil.launch(link.url),
text: replyingTo?.text ?? '',
),
),

View File

@ -229,7 +229,7 @@ class CommentTile extends StatelessWidget {
)) {
onStoryLinkTapped.call(link.url);
} else {
LinkUtil.launchUrl(link.url);
LinkUtil.launch(link.url);
}
},
),

View File

@ -14,6 +14,7 @@ class ItemsListView<T extends Item> extends StatelessWidget {
const ItemsListView({
super.key,
required this.showWebPreview,
required this.showMetadata,
required this.items,
required this.onTap,
required this.refreshController,
@ -32,6 +33,7 @@ class ItemsListView<T extends Item> extends StatelessWidget {
);
final bool showWebPreview;
final bool showMetadata;
final bool enablePullDown;
final bool markReadStories;
final bool showOfflineBanner;
@ -89,6 +91,7 @@ class ItemsListView<T extends Item> extends StatelessWidget {
story: e,
onTap: () => onTap(e),
showWebPreview: showWebPreview,
showMetadata: showMetadata,
hasRead: markReadStories && hasRead,
simpleTileFontSize: useConsistentFontSize ? 14 : 16,
),
@ -138,7 +141,7 @@ class ItemsListView<T extends Item> extends StatelessWidget {
color: Colors.orange,
),
onOpen: (LinkableElement link) =>
LinkUtil.launchUrl(link.url),
LinkUtil.launch(link.url),
),
),
),

View File

@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:hacki/config/constants.dart';
@ -13,6 +12,7 @@ class LinkPreview extends StatefulWidget {
super.key,
required this.link,
required this.story,
required this.showMetadata,
this.cache = const Duration(days: 30),
this.titleStyle,
this.bodyStyle,
@ -99,6 +99,8 @@ class LinkPreview extends StatefulWidget {
/// `[BoxShadow(blurRadius: 3, color: Colors.grey)]`
final List<BoxShadow>? boxShadow;
final bool showMetadata;
@override
_LinkPreviewState createState() => _LinkPreviewState();
}
@ -184,6 +186,7 @@ class _LinkPreviewState extends State<LinkPreview> {
height: _height,
child: LinkView(
key: widget.key ?? Key(widget.link),
metadata: widget.story.simpleMetadata,
url: widget.link,
title: title!,
description: desc!,
@ -198,6 +201,7 @@ class _LinkPreviewState extends State<LinkPreview> {
isIcon: isIcon,
bgColor: widget.backgroundColor,
radius: widget.borderRadius ?? 12,
showMetadata: widget.showMetadata,
),
);
}
@ -205,11 +209,11 @@ class _LinkPreviewState extends State<LinkPreview> {
@override
Widget build(BuildContext context) {
final double screenWidth = MediaQuery.of(context).size.width;
final bool showSmallerPreviewPic =
Platform.isIOS && screenWidth > 428.0 && screenWidth < 850;
final bool showSmallerPreviewPic = screenWidth > 428.0 && screenWidth < 850;
final double _height = showSmallerPreviewPic
? 100.0
: (MediaQuery.of(context).size.height * 0.14).clamp(118.0, 140.0);
final Widget loadingWidget = widget.placeholderWidget ??
Container(
height: _height,

View File

@ -5,10 +5,12 @@ import 'package:hacki/config/constants.dart';
class LinkView extends StatelessWidget {
const LinkView({
super.key,
required this.metadata,
required this.url,
required this.title,
required this.description,
required this.onTap,
required this.showMetadata,
this.imageUri,
this.imagePath,
this.titleTextStyle,
@ -25,6 +27,7 @@ class LinkView extends StatelessWidget {
'imageUri or imagePath cannot be null when showMultiMedia is true',
);
final String metadata;
final String url;
final String title;
final String description;
@ -39,6 +42,7 @@ class LinkView extends StatelessWidget {
final bool isIcon;
final double radius;
final Color? bgColor;
final bool showMetadata;
double computeTitleFontSize(double width) {
double size = width * 0.13;
@ -166,6 +170,20 @@ class LinkView extends StatelessWidget {
padding: const EdgeInsets.fromLTRB(5, 3, 5, 0),
child: Column(
children: <Widget>[
if (showMetadata)
Container(
alignment: Alignment.topLeft,
child: Text(
metadata,
textAlign: TextAlign.left,
style: _bodyTS.copyWith(
fontSize:
_bodyTS.fontSize == null ? 12 : _bodyTS.fontSize! - 2,
),
overflow: bodyTextOverflow ?? TextOverflow.ellipsis,
maxLines: 1,
),
),
Expanded(
child: Container(
alignment: Alignment.topLeft,
@ -174,7 +192,8 @@ class LinkView extends StatelessWidget {
textAlign: TextAlign.left,
style: _bodyTS,
overflow: bodyTextOverflow ?? TextOverflow.ellipsis,
maxLines: bodyMaxLines ?? _maxLines,
maxLines:
(bodyMaxLines ?? _maxLines) - (showMetadata ? 1 : 0),
),
),
),

View File

@ -6,6 +6,7 @@ import 'package:collection/collection.dart' show IterableExtension;
import 'package:fast_gbk/fast_gbk.dart';
import 'package:flutter/foundation.dart';
import 'package:hacki/config/locator.dart';
import 'package:hacki/extensions/extensions.dart';
import 'package:hacki/models/models.dart';
import 'package:hacki/repositories/repositories.dart';
import 'package:html/dom.dart' hide Text, Comment;
@ -208,7 +209,8 @@ class WebAnalyzer {
if (res[0] == '0') {
info = WebInfo(
title: res[1] as String?,
description: res[2] as String?,
description:
res[2] == null ? null : (res[2] as String).removeAllEmojis(),
icon: res[3] as String?,
image: res[4] as String?,
);

View File

@ -40,7 +40,8 @@ class _StoriesListViewState extends State<StoriesListView> {
return BlocBuilder<PreferenceCubit, PreferenceState>(
buildWhen: (PreferenceState previous, PreferenceState current) =>
previous.showComplexStoryTile != current.showComplexStoryTile,
previous.showComplexStoryTile != current.showComplexStoryTile ||
previous.showMetadata != current.showMetadata,
builder: (BuildContext context, PreferenceState preferenceState) {
return BlocConsumer<StoriesBloc, StoriesState>(
listenWhen: (StoriesState previous, StoriesState current) =>
@ -66,6 +67,7 @@ class _StoriesListViewState extends State<StoriesListView> {
markReadStories:
context.read<PreferenceCubit>().state.markReadStories,
showWebPreview: preferenceState.showComplexStoryTile,
showMetadata: preferenceState.showMetadata,
refreshController: refreshController,
items: state.storiesByType[storyType]!,
onRefresh: () {
@ -73,6 +75,7 @@ class _StoriesListViewState extends State<StoriesListView> {
context
.read<StoriesBloc>()
.add(StoriesRefresh(type: storyType));
context.read<PinCubit>().refresh();
},
onLoadMore: () {
context

View File

@ -1,5 +1,3 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_fadein/flutter_fadein.dart';
import 'package:hacki/config/constants.dart';
@ -12,12 +10,14 @@ class StoryTile extends StatelessWidget {
super.key,
this.hasRead = false,
required this.showWebPreview,
required this.showMetadata,
required this.story,
required this.onTap,
this.simpleTileFontSize = 16,
});
final bool showWebPreview;
final bool showMetadata;
final bool hasRead;
final Story story;
final VoidCallback onTap;
@ -28,7 +28,7 @@ class StoryTile extends StatelessWidget {
if (showWebPreview) {
final double screenWidth = MediaQuery.of(context).size.width;
final bool showSmallerPreviewPic =
Platform.isIOS && screenWidth > 428.0 && screenWidth < 850;
screenWidth > 428.0 && screenWidth < 850;
final double height = showSmallerPreviewPic
? 100.0
: (MediaQuery.of(context).size.height * 0.14).clamp(118.0, 140.0);
@ -129,6 +129,7 @@ class StoryTile extends StatelessWidget {
: Theme.of(context).textTheme.subtitle1!.color,
fontWeight: FontWeight.bold,
),
showMetadata: showMetadata,
),
),
),
@ -157,6 +158,21 @@ class StoryTile extends StatelessWidget {
),
],
),
if (showMetadata)
Row(
children: <Widget>[
Expanded(
child: Text(
story.metadata,
style: TextStyle(
color: Colors.grey,
fontSize: simpleTileFontSize - 2,
),
maxLines: 1,
),
),
],
),
const SizedBox(
height: 8,
),

View File

@ -5,10 +5,10 @@ import 'package:url_launcher/url_launcher.dart';
abstract class LinkUtil {
static final ChromeSafariBrowser _browser = ChromeSafariBrowser();
static void launchUrl(String link, {bool useReader = false}) {
static void launch(String link, {bool useReader = false}) {
Uri rinseLink(String link) {
if (link.contains(')')) {
final RegExp regex = RegExp(r'\).*$');
final RegExp regex = RegExp(r'\)|].*$');
if (!link.contains('en.wikipedia.org') && link.contains(regex)) {
final String match = regex.stringMatch(link) ?? '';
return Uri.parse(link.replaceAll(match, ''));
}
@ -19,15 +19,21 @@ abstract class LinkUtil {
final Uri uri = rinseLink(link);
canLaunchUrl(uri).then((bool val) {
if (val) {
_browser.open(
url: uri,
options: ChromeSafariBrowserClassOptions(
ios: IOSSafariOptions(
entersReaderIfAvailable: useReader,
preferredControlTintColor: Colors.orange,
),
),
);
if (link.contains('http')) {
_browser
.open(
url: uri,
options: ChromeSafariBrowserClassOptions(
ios: IOSSafariOptions(
entersReaderIfAvailable: useReader,
preferredControlTintColor: Colors.orange,
),
),
)
.onError((_, __) => launchUrl(uri));
} else {
launchUrl(uri);
}
}
});
}

View File

@ -1,6 +1,6 @@
name: hacki
description: A Hacker News reader.
version: 0.2.10+48
version: 0.2.13+52
publish_to: none
environment:
@ -12,7 +12,7 @@ dependencies:
bloc: ^8.0.3
cached_network_image: ^3.2.1
clipboard: ^0.1.3
collection:
collection: ^1.16.0
connectivity_plus: ^2.2.1
dio: ^4.0.4
equatable: 2.0.3