stashed
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import 'dart:async';
|
||||
import "package:imagini/api/auth_client/base_auth_client.dart";
|
||||
import 'package:flutter/material.dart' show BoxFit, Center, SizedBox;
|
||||
|
||||
import 'package:imagini/api/cookie_client/cookie_client.dart'
|
||||
if (dart.library.html) 'package:imagini/api/cookie_client/browser_cookie_client.dart'
|
||||
if (dart.library.io) 'package:imagini/api/cookie_client/io_cookie_client.dart';
|
||||
import 'package:imagini/api/auth_client/auth_client.dart'
|
||||
if (dart.library.html) 'package:imagini/api/auth_client/browser_auth_client.dart'
|
||||
if (dart.library.io) 'package:imagini/api/auth_client/io_auth_client.dart';
|
||||
|
||||
import 'package:imagini/core/storage_client/base_storage_client.dart';
|
||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||
@@ -15,6 +16,7 @@ class APIProvider{
|
||||
static const String _GRAPHQL_ENDPOINT = "/query";
|
||||
|
||||
BaseStorageClient _storage;
|
||||
BaseAuthClient _authClient;
|
||||
GraphQLClient _client;
|
||||
HttpLink httpLink;
|
||||
|
||||
@@ -23,16 +25,22 @@ class APIProvider{
|
||||
}
|
||||
|
||||
Future<void> init() async {
|
||||
// Initialize Server
|
||||
String _server = await _storage.get("server");
|
||||
|
||||
// Initialize
|
||||
if (_server == null)
|
||||
if (_server == null) {
|
||||
_server = "http://localhost";
|
||||
await _storage.set("server", _server);
|
||||
}
|
||||
|
||||
// Initialize Auth Client
|
||||
_authClient = getAuthClient(_storage);
|
||||
|
||||
// Initialize HTTP Link
|
||||
httpLink = HttpLink(_server + _GRAPHQL_ENDPOINT,
|
||||
httpClient: getCookieClient(_storage),
|
||||
httpClient: _authClient,
|
||||
);
|
||||
|
||||
// Initialize GraphQL Client
|
||||
_client = GraphQLClient(
|
||||
cache: GraphQLCache(),
|
||||
link: httpLink,
|
||||
@@ -64,11 +72,8 @@ class APIProvider{
|
||||
return response;
|
||||
}
|
||||
|
||||
Future<CachedNetworkImage> getImage(String fileName, int width, int height) async {
|
||||
String server = await _storage.get("server");
|
||||
String accessToken = await _storage.get("accessToken");
|
||||
String refreshToken = await _storage.get("refreshToken");
|
||||
|
||||
CachedNetworkImage getImage(String fileName, int width, int height) {
|
||||
String server = _authClient.getServer();
|
||||
String fullURL = "$server/media/$fileName?width=$width";
|
||||
print(fullURL);
|
||||
return CachedNetworkImage(
|
||||
@@ -81,14 +86,36 @@ class APIProvider{
|
||||
),
|
||||
),
|
||||
imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet,
|
||||
httpHeaders: {
|
||||
"X-Imagini-AccessToken": accessToken,
|
||||
"X-Imagini-RefreshToken": refreshToken,
|
||||
},
|
||||
httpHeaders: _authClient.getHeaders(),
|
||||
fit: BoxFit.contain,
|
||||
);
|
||||
}
|
||||
|
||||
// Future<CachedNetworkImage> getImage(String fileName, int width, int height) async {
|
||||
// String server = await _storage.get("server");
|
||||
// String accessToken = await _storage.get("accessToken");
|
||||
// String refreshToken = await _storage.get("refreshToken");
|
||||
|
||||
// String fullURL = "$server/media/$fileName?width=$width";
|
||||
// print(fullURL);
|
||||
// return CachedNetworkImage(
|
||||
// imageUrl: fullURL,
|
||||
// placeholder: (context, url) => Center(
|
||||
// child: SizedBox(
|
||||
// width: width.toDouble() / 3.5,
|
||||
// height: height.toDouble() / 3.5,
|
||||
// child: new PlatformCircularProgressIndicator(),
|
||||
// ),
|
||||
// ),
|
||||
// imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet,
|
||||
// httpHeaders: {
|
||||
// "X-Imagini-AccessToken": accessToken,
|
||||
// "X-Imagini-RefreshToken": refreshToken,
|
||||
// },
|
||||
// fit: BoxFit.contain,
|
||||
// );
|
||||
// }
|
||||
|
||||
Future<QueryResult> me() async {
|
||||
QueryResult response = await _client.query(
|
||||
QueryOptions(
|
||||
|
||||
4
web_native/lib/api/auth_client/auth_client.dart
Normal file
4
web_native/lib/api/auth_client/auth_client.dart
Normal file
@@ -0,0 +1,4 @@
|
||||
import "package:imagini/api/auth_client/base_auth_client.dart";
|
||||
|
||||
BaseAuthClient getAuthClient(storage) => throw UnsupportedError(
|
||||
'Cannot create a client without dart:html or dart:io.');
|
||||
6
web_native/lib/api/auth_client/base_auth_client.dart
Normal file
6
web_native/lib/api/auth_client/base_auth_client.dart
Normal file
@@ -0,0 +1,6 @@
|
||||
import 'package:http/http.dart';
|
||||
|
||||
abstract class BaseAuthClient implements BaseClient {
|
||||
String getServer();
|
||||
Map<String, String> getHeaders();
|
||||
}
|
||||
56
web_native/lib/api/auth_client/browser_auth_client.dart
Normal file
56
web_native/lib/api/auth_client/browser_auth_client.dart
Normal file
@@ -0,0 +1,56 @@
|
||||
import "package:http/http.dart";
|
||||
import 'package:http/browser_client.dart';
|
||||
import "package:imagini/api/auth_client/base_auth_client.dart";
|
||||
import "package:imagini/core/storage_client/base_storage_client.dart";
|
||||
|
||||
BaseClient getAuthClient(storage) => BrowserAuthClient(storage);
|
||||
|
||||
class BrowserAuthClient extends BrowserClient implements BaseAuthClient {
|
||||
BaseStorageClient _storage;
|
||||
String _cachedServer;
|
||||
String _cachedAccessToken;
|
||||
String _cachedRefreshToken;
|
||||
|
||||
BrowserAuthClient(BaseStorageClient storage) {
|
||||
_storage = storage;
|
||||
}
|
||||
|
||||
@override
|
||||
String getServer() {
|
||||
return _cachedServer;
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, String> getHeaders() {
|
||||
return {
|
||||
'X-Imagini-AccessToken': _cachedAccessToken,
|
||||
'X-Imagini-RefreshToken': _cachedRefreshToken,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Future<StreamedResponse> send(BaseRequest request) async {
|
||||
String _accessToken = await _storage.get("accessToken");
|
||||
String _refreshToken = await _storage.get("refreshToken");
|
||||
|
||||
_cachedAccessToken = _accessToken;
|
||||
_cachedRefreshToken = _refreshToken;
|
||||
|
||||
request.headers.addAll({
|
||||
'X-Imagini-AccessToken': _accessToken,
|
||||
'X-Imagini-RefreshToken': _refreshToken,
|
||||
});
|
||||
|
||||
return super.send(request).then((response) async {
|
||||
if (response.headers.containsKey("x-imagini-accesstoken")) {
|
||||
_cachedAccessToken = response.headers["x-imagini-accesstoken"];
|
||||
await _storage.set("accessToken", response.headers["x-imagini-accesstoken"]);
|
||||
}
|
||||
if (response.headers.containsKey("x-imagini-refreshtoken")) {
|
||||
_cachedRefreshToken = response.headers["x-imagini-refreshtoken"];
|
||||
await _storage.set("refreshToken", response.headers["x-imagini-refreshtoken"]);
|
||||
}
|
||||
return response;
|
||||
});
|
||||
}
|
||||
}
|
||||
56
web_native/lib/api/auth_client/io_auth_client.dart
Normal file
56
web_native/lib/api/auth_client/io_auth_client.dart
Normal file
@@ -0,0 +1,56 @@
|
||||
import "package:http/http.dart";
|
||||
import 'package:http/io_client.dart';
|
||||
import "package:imagini/api/auth_client/base_auth_client.dart";
|
||||
import "package:imagini/core/storage_client/base_storage_client.dart";
|
||||
|
||||
BaseClient getAuthClient(storage) => IOAuthClient(storage);
|
||||
|
||||
class IOAuthClient extends IOClient implements BaseAuthClient {
|
||||
BaseStorageClient _storage;
|
||||
String _cachedServer;
|
||||
String _cachedAccessToken;
|
||||
String _cachedRefreshToken;
|
||||
|
||||
IOAuthClient(BaseStorageClient storage) {
|
||||
_storage = storage;
|
||||
}
|
||||
|
||||
@override
|
||||
String getServer() {
|
||||
return _cachedServer;
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, String> getHeaders() {
|
||||
return {
|
||||
'X-Imagini-AccessToken': _cachedAccessToken,
|
||||
'X-Imagini-RefreshToken': _cachedRefreshToken,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Future<IOStreamedResponse> send(BaseRequest request) async {
|
||||
String _accessToken = await _storage.get("accessToken");
|
||||
String _refreshToken = await _storage.get("refreshToken");
|
||||
|
||||
_cachedAccessToken = _accessToken;
|
||||
_cachedRefreshToken = _refreshToken;
|
||||
|
||||
request.headers.addAll({
|
||||
'X-Imagini-AccessToken': _accessToken,
|
||||
'X-Imagini-RefreshToken': _refreshToken,
|
||||
});
|
||||
|
||||
return super.send(request).then((response) async {
|
||||
if (response.headers.containsKey("x-imagini-accesstoken")) {
|
||||
_cachedAccessToken = response.headers["x-imagini-accesstoken"];
|
||||
await _storage.set("accessToken", response.headers["x-imagini-accesstoken"]);
|
||||
}
|
||||
if (response.headers.containsKey("x-imagini-refreshtoken")) {
|
||||
_cachedRefreshToken = response.headers["x-imagini-refreshtoken"];
|
||||
await _storage.set("refreshToken", response.headers["x-imagini-refreshtoken"]);
|
||||
}
|
||||
return response;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ class ImaginiAPIRepository {
|
||||
}));
|
||||
}
|
||||
|
||||
Future<CachedNetworkImage> getImage(String fileName, int width, int height) {
|
||||
CachedNetworkImage getImage(String fileName, int width, int height) {
|
||||
return _apiProvider.getImage(fileName, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import 'dart:io';
|
||||
import 'dart:async';
|
||||
import 'package:imagini/core/imagini_application.dart';
|
||||
import 'package:imagini/api/imagini_api_repository.dart';
|
||||
import 'package:imagini/graphql/imagini_graphql.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
|
||||
import 'package:photo_manager/photo_manager.dart';
|
||||
|
||||
class HomeBloc{
|
||||
|
||||
final ImaginiApplication _application;
|
||||
@@ -27,6 +30,31 @@ class HomeBloc{
|
||||
|
||||
void _init(){
|
||||
_imaginiAPI = _application.imaginiAPI;
|
||||
_init_photo_manager();
|
||||
}
|
||||
|
||||
void _init_photo_manager() async {
|
||||
var result = await PhotoManager.requestPermission();
|
||||
if (!result) {
|
||||
PhotoManager.openSetting();
|
||||
return;
|
||||
}
|
||||
|
||||
// Gets list of "Albums"
|
||||
List<AssetPathEntity> list = await PhotoManager.getAssetPathList();
|
||||
|
||||
// iOS - Select Gallery (predefined settings?)
|
||||
// TODO: Filters: https://pub.dev/packages/photo_manager#filteroption
|
||||
final assetList = await list[0].getAssetListPaged(0, 50);
|
||||
|
||||
// Example entity. This should be done through a loop
|
||||
AssetEntity currEntity = assetList[0];
|
||||
|
||||
// File, Create, Modified, Title
|
||||
File file = await currEntity.file;
|
||||
DateTime createDt = currEntity.createDateTime;
|
||||
DateTime modifiedDt = currEntity.modifiedDateTime;
|
||||
String title = await currEntity.titleAsync;
|
||||
}
|
||||
|
||||
void dispose(){
|
||||
@@ -34,7 +62,7 @@ class HomeBloc{
|
||||
_authenticatedController.close();
|
||||
}
|
||||
|
||||
Future<CachedNetworkImage> getMedia(int index, derivedContentWidth) async {
|
||||
CachedNetworkImage getMedia(int index, derivedContentWidth) {
|
||||
MediaItems$Query$MediaItemResponse$MediaItem mediaDetails = await getMediaDetails(index);
|
||||
if (mediaDetails == null)
|
||||
return null;
|
||||
|
||||
@@ -4,6 +4,8 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:photo_view/photo_view_gallery.dart';
|
||||
import 'package:photo_view/photo_view.dart';
|
||||
|
||||
import 'package:imagini/blocs/home_bloc.dart';
|
||||
import 'package:imagini/core/app_provider.dart';
|
||||
@@ -111,6 +113,36 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
// Widget _buildPhotoPreview(){
|
||||
// return Container(
|
||||
// child: PhotoViewGallery.builder(
|
||||
// scrollPhysics: const BouncingScrollPhysics(),
|
||||
// builder: (BuildContext context, int index) {
|
||||
// return PhotoViewGalleryPageOptions(
|
||||
// imageProvider: AssetImage(widget.galleryItems[index].image),
|
||||
// initialScale: PhotoViewComputedScale.contained * 0.8,
|
||||
// heroAttributes: PhotoViewHeroAttributes(tag: galleryItems[index].id),
|
||||
// );
|
||||
// },
|
||||
// itemCount: _totalLength,
|
||||
// loadingBuilder: (context, event) => Center(
|
||||
// child: Container(
|
||||
// width: 20.0,
|
||||
// height: 20.0,
|
||||
// child: CircularProgressIndicator(
|
||||
// value: event == null
|
||||
// ? 0
|
||||
// : event.cumulativeBytesLoaded / event.expectedTotalBytes,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// // backgroundDecoration: widget.backgroundDecoration,
|
||||
// // pageController: widget.pageController,
|
||||
// // onPageChanged: onPageChanged,
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
|
||||
Widget _appLoading(){
|
||||
return Center(
|
||||
child: ConstrainedBox(
|
||||
@@ -141,7 +173,8 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
maxCrossAxisExtent: 500 / queryData.devicePixelRatio,
|
||||
staggeredTileBuilder: (int index) => new StaggeredTile.fit(1),
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return _buildCard(index, desiredContentWidth);
|
||||
return bloc.getMedia(index, desiredContentWidth);
|
||||
// return _buildCard(index, desiredContentWidth);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user