Skip to content

Commit

Permalink
app updater fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HemantKArya committed Mar 17, 2024
1 parent 4335eb6 commit fadf7be
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/blocs/mediaPlayer/bloomee_player_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BloomeePlayerCubit extends Cubit<BloomeePlayerState> {
bloomeePlayer = await AudioService.init(
builder: () => BloomeeMusicPlayer(),
config: const AudioServiceConfig(
androidStopForegroundOnPause: true,
androidStopForegroundOnPause: false,
androidNotificationChannelId: 'com.BloomeePlayer.notification.status',
androidNotificationChannelName: 'BloomeTunes',
androidResumeOnClick: true,
Expand Down
2 changes: 0 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:Bloomee/model/youtube_vid_model.dart';
import 'package:Bloomee/repository/Youtube/youtube_api.dart';
import 'package:Bloomee/routes_and_consts/global_str_consts.dart';
import 'package:Bloomee/screens/widgets/snackbar.dart';
import 'package:Bloomee/services/bloomeePlayer.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:Bloomee/blocs/add_to_playlist/cubit/add_to_playlist_cubit.dart';
Expand All @@ -19,7 +18,6 @@ import 'package:Bloomee/screens/screen/library_views/cubit/current_playlist_cubi
import 'package:Bloomee/screens/screen/library_views/cubit/import_playlist_cubit.dart';
import 'package:Bloomee/services/db/cubit/mediadb_cubit.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:go_router/go_router.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
import 'blocs/mediaPlayer/bloomee_player_cubit.dart';

Expand Down
17 changes: 16 additions & 1 deletion lib/screens/screen/explore_screen.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:Bloomee/utils/app_updater.dart';
import 'package:flutter/material.dart';
import 'package:Bloomee/screens/screen/home_views/notification_view.dart';
import 'package:Bloomee/screens/screen/home_views/setting_view.dart';
Expand All @@ -7,8 +8,22 @@ import 'package:icons_plus/icons_plus.dart';
import '../widgets/carousal_widget.dart';
import '../widgets/tabList_widget.dart';

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

@override
State<ExploreScreen> createState() => _ExploreScreenState();
}

class _ExploreScreenState extends State<ExploreScreen> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
updateDialog(context);
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down
105 changes: 105 additions & 0 deletions lib/screens/widgets/gradient_alert_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import 'package:Bloomee/theme_data/default.dart';
import 'package:flutter/material.dart';

class GradientDialog extends StatefulWidget {
String message;
Future<void> Function(String)? onOk;
String? okText;
String downloadURL = "";
GradientDialog(
this.message, {
this.onOk,
this.okText,
required this.downloadURL,
super.key,
});

@override
State<StatefulWidget> createState() {
return _GradientDialogState();
}
}

class _GradientDialogState extends State<GradientDialog> {
@override
Widget build(BuildContext context) {
return AlertDialog(
backgroundColor: Colors.transparent,
content: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Container(
height: 200.0,
constraints: const BoxConstraints(),
padding: const EdgeInsets.all(8.0),
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [Colors.blue, Colors.pink],
begin: Alignment.topLeft,
end: Alignment.bottomCenter,
// stops: [0.5, 1.9],
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(
top: 10.0, right: 8, left: 8, bottom: 10.0),
child: Text(
widget.message,
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.white,
fontFamily: "ReThink-Sans",
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
),
const Spacer(),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Padding(
padding: EdgeInsets.only(right: 5),
child: Text('Cancel',
style: TextStyle(
color: Colors.white,
fontFamily: "ReThink-Sans",
fontSize: 15,
fontWeight: FontWeight.w600)),
),
),
OutlinedButton(
onPressed: () {
if (widget.onOk != null) {
widget.onOk!(widget.downloadURL);
}
Navigator.of(context).pop();
},
style: OutlinedButton.styleFrom(
backgroundColor: Default_Theme.accentColor1,
side: const BorderSide(
color: Default_Theme.accentColor1),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0)),
),
child: Text(widget.okText ?? "OK",
style: const TextStyle(
color: Colors.white,
fontFamily: "ReThink-Sans",
fontSize: 15,
))),
],
)
],
)),
),
contentPadding: const EdgeInsets.all(0.0),
);
}
}
83 changes: 83 additions & 0 deletions lib/utils/app_updater.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import 'dart:io';

import 'package:Bloomee/screens/widgets/gradient_alert_widget.dart';
import 'package:Bloomee/services/bloomeeUpdaterTools.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

Future<void> updateDialog(BuildContext context) async {
if (Platform.isAndroid) {
Map<String, dynamic> _updateData = await getLatestVersion();
if (_updateData["results"]) {
if (int.parse(_updateData["currBuild"]) <
int.parse(_updateData["newBuild"])) {
showDialog(
context: context,
builder: (BuildContext context) {
return GradientDialog(
"New Version of Bloomee🌸 is now available!!\n\nVersion: ${_updateData["newVer"]} + ${_updateData["newBuild"]}",
onOk: openURL,
okText: "Update Now!",
downloadURL: _updateData["download_url"],
);
},
);
}
}
}
}

Future<void> openURL(String url) async {
launchUrl(Uri.parse(url));
}

// Future<void> downloadApk(String url) async {
// ReceivePort receivePort = ReceivePort();

// bool isSuccess = IsolateNameServer.registerPortWithName(
// receivePort.sendPort, "update_port");
// if (!isSuccess) {
// IsolateNameServer.removePortNameMapping("update_port");
// IsolateNameServer.registerPortWithName(receivePort.sendPort, "update_port");
// }
// FlutterDownloader.registerCallback(callback);
// final taskId = await FlutterDownloader.enqueue(
// url: url,
// headers: {}, // optional: header send with url (auth token etc)
// savedDir: (await getExternalStorageDirectory())!.path,
// saveInPublicStorage: true,
// showNotification:
// true, // show download progress in status bar (for Android)
// openFileFromNotification:
// true, // click on notification to open downloaded file (for Android)
// );

// receivePort.listen((dynamic data) async {
// String id = data[0];
// // DownloadTaskStatus status = DownloadTaskStatus.fromInt(data[1]);
// int status = data[1];
// int progress = data[2];
// print("=============================");
// if (status == 3) {
// final tasks = await FlutterDownloader.loadTasksWithRawQuery(
// query: "SELECT * FROM task WHERE task_id='" + taskId.toString() + "'",
// );
// // print(tasks![0].filename.toString());
// String full_path =
// tasks![0].savedDir.toString() + "/" + tasks[0].filename.toString();
// print(full_path);
// if (Platform.isAndroid) {
// await FlutterDownloader.open(taskId: taskId.toString());
// }
// }
// print(
// 'Background Isolate Callback: task ($taskId) is in status ($status) and process ($progress)',
// );
// });
// }

// @pragma('vm:entry-point')
// Future callback(String taskId, int status, int progress) async {
// final SendPort? send = IsolateNameServer.lookupPortByName('update_port');
// send?.send([taskId, status, progress]);
// }

0 comments on commit fadf7be

Please sign in to comment.