Skip to content

Commit

Permalink
Fixing the "invalid offset" error from the new pagination from BTTV
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakota committed Feb 18, 2023
1 parent 9941923 commit d83db82
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 26 deletions.
25 changes: 13 additions & 12 deletions .github/workflows/flutter-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: Flutter CI
on:
push:
tags:
- 'v*'
workflow_dispatch:
- "v*"
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -16,18 +16,18 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v1
with:
java-version: '12.x'
java-version: "12.x"

- name: Download signing key
id: signing_key
uses: timheuer/base64-to-file@master
uses: timheuer/base64-to-file@main
with:
fileName: key.jks
encodedString: ${{ secrets.SIGNING_KEY }}

- name: Download Google services file
id: google_services_file
uses: timheuer/base64-to-file@master
uses: timheuer/base64-to-file@main
with:
fileName: google-services.json
encodedString: ${{ secrets.GOOGLE_SERVICES_FILE }}
Expand All @@ -40,7 +40,8 @@ jobs:
- name: Setup Flutter actions
uses: subosito/flutter-action@v1
with:
channel: 'stable'
flutter-version: "2.0.3"
channel: "stable"

- name: Download pub dependencies
run: flutter pub get
Expand All @@ -50,7 +51,7 @@ jobs:

- name: Run analyzer
run: flutter analyze .

- name: Run tests
run: flutter test

Expand All @@ -66,8 +67,8 @@ jobs:
uses: actions/upload-artifact@v2
with:
name: release-apks
path: 'build/app/outputs/apk/release/*.apk'
path: "build/app/outputs/apk/release/*.apk"

- name: Build release appbundle
run: flutter build appbundle
env:
Expand All @@ -80,4 +81,4 @@ jobs:
uses: actions/upload-artifact@v2
with:
name: release-appbundle
path: 'build/app/outputs/bundle/release/app-release.aab'
path: "build/app/outputs/bundle/release/app-release.aab"
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if (keystorePropertiesFile.exists()) {
}

android {
compileSdkVersion 30
compileSdkVersion 31

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -53,7 +53,7 @@ android {
defaultConfig {
applicationId "com.drakota.bttvstickers"
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
Expand Down
3 changes: 3 additions & 0 deletions lib/models/emote.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ import 'package:bttvstickers/models/json_serializable.dart';

class Emote implements JsonSerializable {
final String id;
final String? paginationId;
final String code;
final String imageType;
final String imageUrl;

Emote({
required this.id,
required this.code,
this.paginationId,
required this.imageType,
required this.imageUrl,
});

factory Emote.fromJson(Map<String, dynamic> json) {
return Emote(
id: json['id'],
paginationId: json['paginationId'],
code: json['code'],
imageType: json['imageType'],
imageUrl: "$kEmoteCdnUrl/${json['id']}/3x.${json['imageType']}",
Expand Down
17 changes: 13 additions & 4 deletions lib/services/fetch_emotes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,21 @@ Future<List<Emote>> fetchEmotes({
final response = await http.get(Uri.parse("$url?$queryString"));
if (response.statusCode == 200) {
var result = jsonDecode(response.body) as List;
// Global emotes return the emote directly so if the value in the object's
// key emote is null we just take the whole object
return result.map((item) => Emote.fromJson(item['emote'] ?? item)).toList();
return result.map((item) {
// Global emotes return the emote directly so if the value in the object's
// key emote is null we just take the whole object
if (item['emote'] == null) {
return Emote.fromJson(item);
}

var emote = item['emote'];
// Offset doesn't work anymore for global emotes so we use the id
emote['paginationId'] = item['id'];
return Emote.fromJson(emote);
}).toList();
} else {
throw Exception(
'Failed to while fetching emotes...\nError: ${response.body}',
'Failure while fetching emotes...\nError: ${response.body}',
);
}
}
10 changes: 7 additions & 3 deletions lib/widgets/network_emote_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ class _NetworkEmoteListState extends State<NetworkEmoteList> {
setState(() {
_loading = true;
});
var before = (widget.category == Category.shared && _emotes.isNotEmpty)
? _emotes.last.id
var before = _emotes.isNotEmpty
? (widget.category == Category.shared)
? _emotes.last.id
: _emotes.last.paginationId
: null;
var query = (widget.query != null && widget.query!.length >= 3)
? widget.query
: null;
var result = await fetchEmotes(
category: widget.category,
query: query,
offset: _offset,
// Pagination with offset seems to only work for
// shared emotes with a query
offset: query != null ? _offset : null,
// The API for shared needs to know the last id of our
// list of emotes to paginate
before: before,
Expand Down
8 changes: 3 additions & 5 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Use any BetterTTV emotes in messaging apps with stickers.

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
publish_to: "none" # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
Expand All @@ -15,16 +15,16 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# 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: 2.1.0+10
version: 2.1.1+11

environment:
sdk: ">=2.12.0 <3.0.0"
flutter: "^2.0.3"

dependencies:
flutter:
sdk: flutter


# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
http: ^0.13.0
Expand All @@ -49,7 +49,6 @@ dev_dependencies:

# The following section is specific to Flutter.
flutter:

# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
Expand Down Expand Up @@ -123,7 +122,6 @@ flutter:
- family: CascadiaMono
fonts:
- asset: assets/fonts/CascadiaMono.ttf


# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages

0 comments on commit d83db82

Please sign in to comment.