added cargo files
This commit is contained in:
45
PinePods-0.8.2/mobile/lib/state/bloc_state.dart
Normal file
45
PinePods-0.8.2/mobile/lib/state/bloc_state.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright 2020 Ben Hills and the project contributors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
/// The BLoCs in this application share common states, such as loading, error
|
||||
/// or populated.
|
||||
///
|
||||
/// Rather than having a separate selection of state classes, we create this generic one.
|
||||
enum BlocErrorType { unknown, connectivity, timeout }
|
||||
|
||||
abstract class BlocState<T> {}
|
||||
|
||||
class BlocDefaultState<T> extends BlocState<T> {}
|
||||
|
||||
class BlocLoadingState<T> extends BlocState<T> {
|
||||
final T? data;
|
||||
|
||||
BlocLoadingState([this.data]);
|
||||
}
|
||||
|
||||
class BlocBackgroundLoadingState<T> extends BlocState<T> {
|
||||
final T? data;
|
||||
|
||||
BlocBackgroundLoadingState([this.data]);
|
||||
}
|
||||
|
||||
class BlocSuccessfulState<T> extends BlocState<T> {}
|
||||
|
||||
class BlocEmptyState<T> extends BlocState<T> {}
|
||||
|
||||
class BlocErrorState<T> extends BlocState<T> {
|
||||
final BlocErrorType error;
|
||||
|
||||
BlocErrorState({
|
||||
this.error = BlocErrorType.unknown,
|
||||
});
|
||||
}
|
||||
|
||||
class BlocNoInputState<T> extends BlocState<T> {}
|
||||
|
||||
class BlocPopulatedState<T> extends BlocState<T> {
|
||||
final T? results;
|
||||
|
||||
BlocPopulatedState({this.results});
|
||||
}
|
||||
19
PinePods-0.8.2/mobile/lib/state/episode_state.dart
Normal file
19
PinePods-0.8.2/mobile/lib/state/episode_state.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright 2020 Ben Hills and the project contributors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:pinepods_mobile/entities/episode.dart';
|
||||
|
||||
abstract class EpisodeState {
|
||||
final Episode episode;
|
||||
|
||||
EpisodeState(this.episode);
|
||||
}
|
||||
|
||||
class EpisodeUpdateState extends EpisodeState {
|
||||
EpisodeUpdateState(super.episode);
|
||||
}
|
||||
|
||||
class EpisodeDeleteState extends EpisodeState {
|
||||
EpisodeDeleteState(super.episode);
|
||||
}
|
||||
95
PinePods-0.8.2/mobile/lib/state/persistent_state.dart
Normal file
95
PinePods-0.8.2/mobile/lib/state/persistent_state.dart
Normal file
@@ -0,0 +1,95 @@
|
||||
// Copyright 2020 Ben Hills. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:pinepods_mobile/entities/persistable.dart';
|
||||
import 'package:path/path.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class PersistentState {
|
||||
static Future<void> persistState(Persistable persistable) async {
|
||||
var d = await getApplicationSupportDirectory();
|
||||
|
||||
var file = File(join(d.path, 'state.json'));
|
||||
var sink = file.openWrite();
|
||||
var json = jsonEncode(persistable.toMap());
|
||||
|
||||
sink.write(json);
|
||||
await sink.flush();
|
||||
await sink.close();
|
||||
}
|
||||
|
||||
static Future<Persistable> fetchState() async {
|
||||
var d = await getApplicationSupportDirectory();
|
||||
|
||||
var file = File(join(d.path, 'state.json'));
|
||||
var p = Persistable.empty();
|
||||
|
||||
if (file.existsSync()) {
|
||||
var result = file.readAsStringSync();
|
||||
|
||||
if (result.isNotEmpty) {
|
||||
var data = jsonDecode(result) as Map<String, dynamic>;
|
||||
|
||||
p = Persistable.fromMap(data);
|
||||
}
|
||||
}
|
||||
|
||||
return Future.value(p);
|
||||
}
|
||||
|
||||
static Future<void> clearState() async {
|
||||
var file = await _getFile();
|
||||
|
||||
if (file.existsSync()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> writeInt(String name, int value) async {
|
||||
return _writeValue(name, value.toString());
|
||||
}
|
||||
|
||||
static Future<int> readInt(String name) async {
|
||||
var result = await _readValue(name);
|
||||
|
||||
return result.isEmpty ? 0 : int.parse(result);
|
||||
}
|
||||
|
||||
static Future<void> writeString(String name, String value) async {
|
||||
return _writeValue(name, value);
|
||||
}
|
||||
|
||||
static Future<String> readString(String name) async {
|
||||
return _readValue(name);
|
||||
}
|
||||
|
||||
static Future<String> _readValue(String name) async {
|
||||
var d = await getApplicationSupportDirectory();
|
||||
|
||||
var file = File(join(d.path, name));
|
||||
var result = file.readAsStringSync();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static Future<void> _writeValue(String name, String value) async {
|
||||
var d = await getApplicationSupportDirectory();
|
||||
|
||||
var file = File(join(d.path, name));
|
||||
var sink = file.openWrite();
|
||||
|
||||
sink.write(value.toString());
|
||||
await sink.flush();
|
||||
await sink.close();
|
||||
}
|
||||
|
||||
static Future<File> _getFile() async {
|
||||
var d = await getApplicationSupportDirectory();
|
||||
|
||||
return File(join(d.path, 'state.json'));
|
||||
}
|
||||
}
|
||||
58
PinePods-0.8.2/mobile/lib/state/queue_event_state.dart
Normal file
58
PinePods-0.8.2/mobile/lib/state/queue_event_state.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
// Copyright 2020 Ben Hills and the project contributors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:pinepods_mobile/entities/episode.dart';
|
||||
|
||||
abstract class QueueEvent {
|
||||
Episode? episode;
|
||||
int? position;
|
||||
|
||||
QueueEvent({
|
||||
this.episode,
|
||||
this.position,
|
||||
});
|
||||
}
|
||||
|
||||
class QueueAddEvent extends QueueEvent {
|
||||
QueueAddEvent({required Episode super.episode, super.position});
|
||||
}
|
||||
|
||||
class QueueRemoveEvent extends QueueEvent {
|
||||
QueueRemoveEvent({required Episode episode}) : super(episode: episode);
|
||||
}
|
||||
|
||||
class QueueMoveEvent extends QueueEvent {
|
||||
final int oldIndex;
|
||||
final int newIndex;
|
||||
|
||||
QueueMoveEvent({
|
||||
required Episode episode,
|
||||
required this.oldIndex,
|
||||
required this.newIndex,
|
||||
}) : super(episode: episode);
|
||||
}
|
||||
|
||||
class QueueClearEvent extends QueueEvent {}
|
||||
|
||||
abstract class QueueState {
|
||||
final Episode? playing;
|
||||
final List<Episode> queue;
|
||||
|
||||
QueueState({
|
||||
required this.playing,
|
||||
required this.queue,
|
||||
});
|
||||
}
|
||||
|
||||
class QueueListState extends QueueState {
|
||||
QueueListState({
|
||||
required super.playing,
|
||||
required super.queue,
|
||||
});
|
||||
}
|
||||
|
||||
class QueueEmptyState extends QueueState {
|
||||
QueueEmptyState()
|
||||
: super(playing: Episode(guid: '', pguid: '', podcast: '', title: '', description: ''), queue: <Episode>[]);
|
||||
}
|
||||
35
PinePods-0.8.2/mobile/lib/state/transcript_state_event.dart
Normal file
35
PinePods-0.8.2/mobile/lib/state/transcript_state_event.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright 2020 Ben Hills and the project contributors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:pinepods_mobile/entities/transcript.dart';
|
||||
|
||||
/// Events
|
||||
abstract class TranscriptEvent {}
|
||||
|
||||
class TranscriptClearEvent extends TranscriptEvent {}
|
||||
|
||||
class TranscriptFilterEvent extends TranscriptEvent {
|
||||
final String search;
|
||||
|
||||
TranscriptFilterEvent({required this.search});
|
||||
}
|
||||
|
||||
/// State
|
||||
abstract class TranscriptState {
|
||||
final Transcript? transcript;
|
||||
final bool isFiltered;
|
||||
|
||||
TranscriptState({
|
||||
this.transcript,
|
||||
this.isFiltered = false,
|
||||
});
|
||||
}
|
||||
|
||||
class TranscriptUnavailableState extends TranscriptState {}
|
||||
|
||||
class TranscriptLoadingState extends TranscriptState {}
|
||||
|
||||
class TranscriptUpdateState extends TranscriptState {
|
||||
TranscriptUpdateState({required Transcript transcript}) : super(transcript: transcript);
|
||||
}
|
||||
Reference in New Issue
Block a user