Skip to content

Commit

Permalink
Sleep timer implt. and version bumps to 2.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
HemantKArya committed Apr 5, 2024
1 parent b91f178 commit 17d9831
Show file tree
Hide file tree
Showing 9 changed files with 571 additions and 11 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ jobs:
run: jarsigner --verify --verbose build/app/outputs/flutter-apk/app-release.apk

- name: Rename APK file
run: mv build/app/outputs/flutter-apk/app-release.apk build/app/outputs/flutter-apk/bloomee_tunes_v2.4.3+${{github.run_number}}.apk
run: mv build/app/outputs/flutter-apk/app-release.apk build/app/outputs/flutter-apk/bloomee_tunes_v2.4.4+${{github.run_number}}.apk

- name: Upload Artifacts
uses: actions/upload-artifact@v2
with:
name: Release
path: |
build/app/outputs/flutter-apk/bloomee_tunes_v2.4.3+${{github.run_number}}.apk
build/app/outputs/flutter-apk/bloomee_tunes_v2.4.4+${{github.run_number}}.apk
- name: Create Release
uses: ncipollo/release-action@v1
with:
artifacts: "build/app/outputs/flutter-apk/bloomee_tunes_v2.4.3+${{github.run_number}}.apk"
tag: v2.4.3+${{github.run_number}}
artifacts: "build/app/outputs/flutter-apk/bloomee_tunes_v2.4.4+${{github.run_number}}.apk"
tag: v2.4.4+${{github.run_number}}
token: ${{secrets.SECRET_KEY}}
84 changes: 84 additions & 0 deletions lib/blocs/timer/timer_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import 'dart:async';
import 'dart:developer';

import 'package:Bloomee/blocs/mediaPlayer/bloomee_player_cubit.dart';
import 'package:Bloomee/main.dart';
import 'package:Bloomee/utils/ticker.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';

part 'timer_event.dart';
part 'timer_state.dart';

class TimerBloc extends Bloc<TimerEvent, TimerState> {
final Ticker _ticker;
static const int _duration = 0;

StreamSubscription<int>? _tickerSubscription;

TimerBloc({required Ticker ticker, required BloomeePlayerCubit bloomeePlayer})
: _ticker = ticker,
super(const TimerInitial(_duration)) {
on<TimerStarted>(_onTimerStarted);
on<_TimerTicked>(_onTimerTicked);
on<TimerPaused>(onTimerPaused);
on<TimerResumed>(onTimerResumed);
on<TimerReset>(onTimerReset);
on<TimerStopped>(onTimerStopped);
}

void _onTimerStarted(TimerStarted event, Emitter<TimerState> emit) {
emit(TimerRunInProgress(event.duration));
_tickerSubscription?.cancel();
_tickerSubscription =
_ticker.tick(ticks: event.duration).listen((duration) {
add(_TimerTicked(duration: duration));
});
}

void onTimerPaused(TimerPaused event, Emitter<TimerState> emit) {
if (state is TimerRunInProgress) {
_tickerSubscription?.pause();
emit(TimerRunPause(state.duration));
}
}

void onTimerResumed(TimerResumed event, Emitter<TimerState> emit) {
if (state is TimerRunPause) {
_tickerSubscription?.resume();
emit(TimerRunInProgress(state.duration));
}
}

void onTimerReset(TimerReset event, Emitter<TimerState> emit) {
_tickerSubscription?.cancel();
emit(const TimerInitial(_duration));
}

void onTimerStopped(TimerStopped event, Emitter<TimerState> emit) {
_tickerSubscription?.cancel();
emit(const TimerRunStopped());
}

void _onTimerTicked(_TimerTicked event, Emitter<TimerState> emit) {
// emit(event.duration > 0
// ? TimerRunInProgress(event.duration)
// : const TimerRunComplete());
if (event.duration > 0) {
emit(TimerRunInProgress(event.duration));
} else {
emit(const TimerRunComplete());
try {
bloomeePlayerCubit.bloomeePlayer.pause();
} catch (e) {
log(e.toString(), name: "TimerBloc");
}
}
}

@override
Future<void> close() {
_tickerSubscription?.cancel();
return super.close();
}
}
31 changes: 31 additions & 0 deletions lib/blocs/timer/timer_event.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
part of 'timer_bloc.dart';

sealed class TimerEvent {
const TimerEvent();
}

final class TimerStarted extends TimerEvent {
const TimerStarted({required this.duration});
final int duration;
}

final class TimerPaused extends TimerEvent {
const TimerPaused();
}

final class TimerResumed extends TimerEvent {
const TimerResumed();
}

class TimerReset extends TimerEvent {
const TimerReset();
}

class TimerStopped extends TimerEvent {
const TimerStopped();
}

class _TimerTicked extends TimerEvent {
const _TimerTicked({required this.duration});
final int duration;
}
38 changes: 38 additions & 0 deletions lib/blocs/timer/timer_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
part of 'timer_bloc.dart';

sealed class TimerState extends Equatable {
const TimerState(this.duration);
final int duration;

@override
List<Object> get props => [duration];
}

final class TimerInitial extends TimerState {
const TimerInitial(super.duration);

@override
String toString() => 'TimerInitial { duration: $duration }';
}

final class TimerRunPause extends TimerState {
const TimerRunPause(super.duration);

@override
String toString() => 'TimerRunPause { duration: $duration }';
}

final class TimerRunStopped extends TimerState {
const TimerRunStopped() : super(0);
}

final class TimerRunInProgress extends TimerState {
const TimerRunInProgress(super.duration);

@override
String toString() => 'TimerRunInProgress { duration: $duration }';
}

final class TimerRunComplete extends TimerState {
const TimerRunComplete() : super(0);
}
5 changes: 5 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import 'dart:developer';
import 'dart:io' as io;
import 'package:Bloomee/blocs/internet_connectivity/cubit/connectivity_cubit.dart';
import 'package:Bloomee/blocs/settings_cubit/cubit/settings_cubit.dart';
import 'package:Bloomee/blocs/timer/timer_bloc.dart';
import 'package:Bloomee/screens/widgets/snackbar.dart';
import 'package:Bloomee/theme_data/default.dart';
import 'package:Bloomee/services/file_manager.dart';
import 'package:Bloomee/utils/external_list_importer.dart';
import 'package:Bloomee/utils/ticker.dart';
import 'package:Bloomee/utils/url_checker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down Expand Up @@ -168,6 +170,9 @@ class _MyAppState extends State<MyApp> {
create: (context) => SettingsCubit(),
lazy: false,
),
BlocProvider(
create: (context) => TimerBloc(
ticker: const Ticker(), bloomeePlayer: bloomeePlayerCubit)),
BlocProvider(
create: (context) => ConnectivityCubit(),
lazy: false,
Expand Down
Loading

0 comments on commit 17d9831

Please sign in to comment.