Skip to content

Commit

Permalink
Merge pull request #261 from Manuito83/feat-new-navigator
Browse files Browse the repository at this point in the history
Feat new navigator
  • Loading branch information
Manuito83 committed May 31, 2024
2 parents 143f2bf + fb7eda1 commit 005fa60
Show file tree
Hide file tree
Showing 51 changed files with 706 additions and 237 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if (localPropertiesFile.exists()) {

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '417'
flutterVersionCode = '426'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
Expand Down
16 changes: 14 additions & 2 deletions android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-keep class io.flutter.plugins.** { *; }
-dontwarn io.flutter.embedding.**

## Gson rules
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
Expand All @@ -19,9 +19,12 @@
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { <fields>; }

# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapter
-keep class * extends com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
Expand All @@ -31,8 +34,17 @@
@com.google.gson.annotations.SerializedName <fields>;
}

# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0 and higher.
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken

##---------------End: proguard configuration for Gson ----------

## flutter_local_notification plugin rules
-keep class com.dexterous.** { *; }

-keepattributes SourceFile,LineNumberTable # Keep file names and line numbers.
-keep public class * extends java.lang.Exception # Optional: Keep custom exceptions.

## Added after Flutter 3.22
-dontwarn com.google.android.play.core.splitcompat.SplitCompatApplication
10 changes: 5 additions & 5 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@
"${BUILT_PRODUCTS_DIR}/path_provider_foundation/path_provider_foundation.framework",
"${BUILT_PRODUCTS_DIR}/quick_actions_ios/quick_actions_ios.framework",
"${BUILT_PRODUCTS_DIR}/share_plus/share_plus.framework",
"${BUILT_PRODUCTS_DIR}/shared_preferences_ios/shared_preferences_ios.framework",
"${BUILT_PRODUCTS_DIR}/shared_preferences_foundation/shared_preferences_foundation.framework",
"${BUILT_PRODUCTS_DIR}/url_launcher_ios/url_launcher_ios.framework",
"${BUILT_PRODUCTS_DIR}/vibration/vibration.framework",
"${BUILT_PRODUCTS_DIR}/wakelock_plus/wakelock_plus.framework",
Expand Down Expand Up @@ -331,7 +331,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/path_provider_foundation.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/quick_actions_ios.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/share_plus.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/shared_preferences_ios.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/shared_preferences_foundation.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/url_launcher_ios.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/vibration.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/wakelock_plus.framework",
Expand Down Expand Up @@ -527,7 +527,7 @@
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 417;
CURRENT_PROJECT_VERSION = 426;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 53KVJRJS99;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -671,7 +671,7 @@
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 417;
CURRENT_PROJECT_VERSION = 426;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 53KVJRJS99;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -709,7 +709,7 @@
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 417;
CURRENT_PROJECT_VERSION = 426;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 53KVJRJS99;
ENABLE_BITCODE = NO;
Expand Down
2 changes: 1 addition & 1 deletion lib/drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,7 @@ class DrawerPageState extends State<DrawerPage> with WidgetsBindingObserver, Aut

_webViewProvider = Provider.of<WebViewProvider>(context, listen: false);
// Join a stream which will receive a callback from main if applicable whenever the back button is pressed
_willPopShouldOpenDrawer = _settingsProvider.willPopShouldOpenDrawer.stream;
_willPopShouldOpenDrawer = _settingsProvider.willPopShouldOpenDrawerStream.stream;
_willPopSubscription = _willPopShouldOpenDrawer.listen((event) {
_openDrawer();
});
Expand Down
148 changes: 70 additions & 78 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import 'package:get/get.dart';
import 'package:home_widget/home_widget.dart';
import 'package:provider/provider.dart';
import 'package:timezone/data/latest.dart' as tz;
import 'package:toastification/toastification.dart';
// Project imports:
import 'package:torn_pda/drawer.dart';
import 'package:torn_pda/firebase_options.dart';
Expand Down Expand Up @@ -58,8 +59,8 @@ import 'package:workmanager/workmanager.dart';

// TODO (App release)
const String appVersion = '3.4.2';
const String androidCompilation = '417';
const String iosCompilation = '417';
const String androidCompilation = '426';
const String iosCompilation = '426';

// TODO (App release)
const bool pointFunctionsEmulatorToLocal = false;
Expand Down Expand Up @@ -250,6 +251,7 @@ class MyApp extends StatefulWidget {
class MyAppState extends State<MyApp> with WidgetsBindingObserver {
late ThemeProvider _themeProvider;
late WebViewProvider _webViewProvider;
late Widget _mainBrowser;

@override
void initState() {
Expand All @@ -272,6 +274,16 @@ class MyAppState extends State<MyApp> with WidgetsBindingObserver {
_webViewProvider.setCurrentUiMode(UiMode.fullScreen, context);
}
});

_mainBrowser = Consumer<WebViewProvider>(
builder: (context, w, child) {
return Visibility(
maintainState: true,
visible: w.browserShowInForeground || w.webViewSplitActive,
child: w.stackView,
);
},
);
}

@override
Expand Down Expand Up @@ -337,110 +349,90 @@ class MyAppState extends State<MyApp> with WidgetsBindingObserver {
),
);

return MaterialApp(
title: 'Torn PDA',
navigatorKey: navigatorKey,
theme: theme,
debugShowCheckedModeBanner: false,
builder: BotToastInit(),
navigatorObservers: [BotToastNavigatorObserver()],
home: WillPopScope(
onWillPop: () async {
final WebViewProvider w = Provider.of<WebViewProvider>(context, listen: false);

if (w.browserShowInForeground) {
// Browser is in front, delegate the call
w.tryGoBack();
return false;
} else {
// App is in front
//_webViewProvider.willPopCallbackStream.add(true);
final bool shouldPop = await _willPopFromApp();
if (shouldPop) return true;
return false;
}
},
child: Consumer<WebViewProvider>(builder: (context, wProvider, child) {
// Inside of Navigator so that even if DrawerPage is replaced (we push another route), the
// reference to this widget is not lost
final homeDrawer = Navigator(
onGenerateRoute: (_) {
return MaterialPageRoute(builder: (BuildContext _) => DrawerPage());
},
);

return ToastificationWrapper(
child: MaterialApp(
title: 'Torn PDA',
navigatorKey: navigatorKey,
theme: theme,
debugShowCheckedModeBanner: false,
builder: BotToastInit(),
navigatorObservers: [BotToastNavigatorObserver()],
home: Consumer2<SettingsProvider, WebViewProvider>(builder: (context, sProvider, wProvider, child) {
// Build standard or split-screen home
Widget home = Stack(
children: [
homeDrawer,
_mainBrowser,
const AppBorder(),
],
);

if (wProvider.splitScreenPosition == WebViewSplitPosition.right &&
_webViewProvider.webViewSplitActive &&
wProvider.webViewSplitActive &&
screenIsWide) {
return Stack(
home = Stack(
children: [
Row(
children: [
Flexible(
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: theme,
home: DrawerPage(),
),
),
Flexible(
child: wProvider.stackView,
),
Flexible(child: homeDrawer),
Flexible(child: _mainBrowser),
],
),
const AppBorder(),
],
);
} else if (wProvider.splitScreenPosition == WebViewSplitPosition.left &&
_webViewProvider.webViewSplitActive &&
wProvider.webViewSplitActive &&
screenIsWide) {
return Stack(
home = Stack(
children: [
Row(
children: [
Flexible(
child: wProvider.stackView,
),
Flexible(
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: theme,
home: DrawerPage(),
),
),
Flexible(child: _mainBrowser),
Flexible(child: homeDrawer),
],
),
const AppBorder(),
],
);
} else {
return Stack(
children: [
MaterialApp(
debugShowCheckedModeBanner: false,
theme: theme,
home: DrawerPage(),
),
Visibility(
maintainState: true,
visible: wProvider.browserShowInForeground,
child: wProvider.stackView,
),
const AppBorder(),
],
);
}

return PopScope(
// Only exit app if user allows and we are not in the browser
canPop: sProvider.onBackButtonAppExit == "exit" && !wProvider.browserShowInForeground,
onPopInvoked: (didPop) async {
if (didPop) return;
// If we can't pop, decide if we open the drawer or go backwards in the browser
final WebViewProvider w = Provider.of<WebViewProvider>(context, listen: false);
if (w.browserShowInForeground) {
// Browser is in front, delegate the call
w.tryGoBack();
} else {
_openDrawerIfPossible();
}
},
child: home,
);
}),
),
);
}

Future<bool> _willPopFromApp() async {
_openDrawerIfPossible() async {
final SettingsProvider s = Provider.of<SettingsProvider>(context, listen: false);
final appExit = s.onAppExit;
if (appExit == 'exit') {
return true;
if (routeWithDrawer) {
// Open drawer instead
s.willPopShouldOpenDrawerStream.add(true);
} else {
if (routeWithDrawer) {
// Open drawer instead
s.willPopShouldOpenDrawer.add(true);
return false;
} else {
s.willPopShouldGoBack.add(true);
return false;
}
s.willPopShouldGoBackStream.add(true);
}
}
}
Expand Down
49 changes: 49 additions & 0 deletions lib/models/profile/external/torn_stats_chart_update.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// To parse this JSON data, do
//
// final tornStatsChartUpdate = tornStatsChartUpdateFromJson(jsonString);

import 'dart:convert';

TornStatsChartUpdate tornStatsChartUpdateFromJson(String str) => TornStatsChartUpdate.fromJson(json.decode(str));

String tornStatsChartUpdateToJson(TornStatsChartUpdate data) => json.encode(data.toJson());

class TornStatsChartUpdate {
String? age;
bool? status;
String? message;
int? deltaStrength;
int? deltaDefense;
int? deltaDexterity;
int? deltaSpeed;

TornStatsChartUpdate({
this.age,
this.status,
this.message,
this.deltaStrength,
this.deltaDefense,
this.deltaDexterity,
this.deltaSpeed,
});

factory TornStatsChartUpdate.fromJson(Map<String, dynamic> json) => TornStatsChartUpdate(
age: json["age"],
status: json["status"],
message: json["message"],
deltaStrength: json["deltaStrength"],
deltaDefense: json["deltaDefense"],
deltaDexterity: json["deltaDexterity"],
deltaSpeed: json["deltaSpeed"],
);

Map<String, dynamic> toJson() => {
"age": age,
"status": status,
"message": message,
"deltaStrength": deltaStrength,
"deltaDefense": deltaDefense,
"deltaDexterity": deltaDexterity,
"deltaSpeed": deltaSpeed,
};
}
5 changes: 3 additions & 2 deletions lib/models/profile/shortcuts_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:convert';

// Flutter imports:
import 'package:flutter/material.dart';
import 'package:torn_pda/utils/color_json.dart';

Shortcut shortcutFromJson(String str) => Shortcut.fromJson(json.decode(str));

Expand Down Expand Up @@ -55,7 +56,7 @@ class Shortcut {
originalNickname: json["originalNickname"],
originalUrl: json["originalUrl"],
iconUrl: json["iconUrl"],
color: json["color"] == null ? null : Color(int.parse(json["color"].split('(0x')[1].split(')')[0], radix: 16)),
color: getColorFromJson(json["color"]),
isCustom: json["isCustom"],
addPlayerId: json["addPlayerId"],
addFactionId: json["addFactionId"],
Expand All @@ -72,7 +73,7 @@ class Shortcut {
"originalNickname": originalNickname,
"originalUrl": originalUrl,
"iconUrl": iconUrl,
"color": color?.toString(),
"color": color?.value,
"isCustom": isCustom,
"addPlayerId": addPlayerId,
"addFactionId": addFactionId,
Expand Down
Loading

0 comments on commit 005fa60

Please sign in to comment.