Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if (flutterVersionName == null) {
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'

android {
compileSdkVersion flutter.compileSdkVersion
Expand All @@ -44,13 +45,14 @@ android {

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.tinder"
applicationId "com.tinder"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion flutter.minSdkVersion
minSdkVersion 19
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}

buildTypes {
Expand All @@ -68,4 +70,5 @@ flutter {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation platform('com.google.firebase:firebase-bom:30.1.0')
}
39 changes: 39 additions & 0 deletions android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"project_info": {
"project_number": "12384404765",
"project_id": "tinder-af728",
"storage_bucket": "tinder-af728.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:12384404765:android:21128f6e7c33e5eeeecdf4",
"android_client_info": {
"package_name": "com.tinder"
}
},
"oauth_client": [
{
"client_id": "12384404765-44t2opis1um3imshe6u8n09hnb30tpgg.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCFQ90dEVIgvXYC9PowiA5vxfuR703G_dY"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "12384404765-44t2opis1um3imshe6u8n09hnb30tpgg.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tinder">
<application
android:label="tinder"
android:label="Tinder"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
Expand Down
Binary file modified android/app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.10'
}
}

Expand Down
8 changes: 8 additions & 0 deletions assets/first_users.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fKwHocBmTKauoGPCuHvMuzFGLEu1 assets/images/1.jpg
YZybD7jSLbYzF9aiWnADt3DnfdH2 assets/images/2.jpg
zdvKzipQltUTKFatRuOitXNIVYM2 assets/images/3.jpg
dv39uN3q3pWVzLem2HFNN4kHcgy1 assets/images/4.jpg
IFlEGxWZxkQUhjYBngnGjEXSCP82 assets/images/5.jpg
ubFD9AgeGEgm9TRvhz4pcsjVQui2 assets/images/6.jpg
P5XOny7VPmew6daGatowtfNWJTM2 assets/images/7.jpg
bvL4TK5HJZgCAtBJcSqOfaPHOFs1 assets/images/8.jpg
File renamed without changes
Binary file added assets/images/10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/11.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/12.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/13.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/14.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/15.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/16.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/17.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/18.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/19.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added assets/images/20.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added assets/images/6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/9.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
113 changes: 113 additions & 0 deletions lib/cubit/app_cubit.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import 'package:bloc/bloc.dart';
import 'package:flutter/material.dart';
import 'package:tinder/models/app_user.dart';
import 'package:tinder/services/database_service.dart';
import 'package:tinder/services/user_service.dart';
import 'package:tuple/tuple.dart';

part 'app_state.dart';

class AppCubit extends Cubit<AppState> {
final DatabaseService _databaseService;
final UserService _userService;
final List<Tuple2<String, String>> _idsAndImages = [];

AppCubit(this._databaseService, this._userService) : super(AppInitial());

void setInitial() {
emit(AppInitial());
}

// Инициализация юзера во время авторизации
Future<void> initUserAuth(
{required String id,
required String login,
required String password}) async {
Map<String, dynamic> data = await _databaseService.getUserData(id);
String name = data['name'];
List<String> likes = [];
if (data['likes'] != null) {
for (var element in data['likes']) {
likes.add(element.toString());
}
}
List<String> dislikes = [];
if (data['dislikes'] != null) {
for (var element in data['dislikes']) {
dislikes.add(element.toString());
}
}
String image = data['image'];
_userService.user = AppUser(
id: id,
login: login,
password: password,
name: name,
likes: likes,
dislikes: dislikes,
image: image);
}

// Инициализация юзера во время регистрации
Future<void> initUserRegister(
{required String id,
required String name,
required String login,
required String password}) async {
int usersCount = await _databaseService.getUsersCount();
_userService.user = AppUser(
id: id,
login: login,
password: password,
name: name,
likes: [],
dislikes: [],
image: 'assets/images/${usersCount + 1}.jpg');
_databaseService.setUserData(_userService.user!);
}

Future<void> addLike(String id) async {
_userService.user!.likes.add(id);
await _databaseService.setUserData(_userService.user!);
}

Future<void> addDislike(String id) async {
_userService.user!.dislikes.add(id);
await _databaseService.setUserData(_userService.user!);
}

// Инициализация списка всех юзеров
Future<void> initUsers() async {
_userService.users ??= await _databaseService.getUsers();
}

// Инициализация списка айди и изображений юзеров
Future<void> initIdsAndImages() async {
await initUsers();
final Map<String, String> usersImages = {};
for (Map<String, String> map in _userService.users!) {
usersImages[map['id']!] = map['image']!;
}
Iterable<String> usersIds = usersImages.keys;
for (String id in usersIds) {
if (!_userService.user!.likes.contains(id) &&
!_userService.user!.dislikes.contains(id) &&
_userService.user!.id != id) {
_idsAndImages.add(Tuple2(id, usersImages[id]!));
}
}
if (_idsAndImages.isEmpty) {
emit(AppFinish());
} else {
emit(AppCards());
}
}

List<Tuple2<String, String>> get idsAndImages {
return _idsAndImages;
}

void clear() {
_idsAndImages.clear();
}
}
10 changes: 10 additions & 0 deletions lib/cubit/app_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
part of 'app_cubit.dart';

@immutable
abstract class AppState {}

class AppInitial extends AppState {}

class AppCards extends AppState {}

class AppFinish extends AppState {}
111 changes: 100 additions & 11 deletions lib/cubit/auth_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,116 @@
import 'package:bloc/bloc.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:tinder/services/storage.dart';

part 'auth_state.dart';

class AuthCubit extends Cubit<AuthState> {
int counter = 0;
final FirebaseAuth _auth;
final Storage _storage;

AuthCubit() : super(AuthInitial());
AuthCubit(this._auth, this._storage) : super(AuthInitialState());

void login() async {
if (counter == 0) {
emit(AuthInProgress());
await Future.delayed(const Duration(seconds: 1));
emit(AuthError());
counter++;
// Future<void> initStorage() async {
// _storage = Storage(await SharedPreferences.getInstance());
// }

Future<Map<String, String>?> automaticAuth() async {
String? login = _storage.getEmail();
String? password = _storage.getPassword();
if (login != null && password != null) {
Map<String, String>? data = await logIn(login, password);
if (data == null) {
emit(AuthPage());
}
return data;
} else {
emit(AuthPage());
return null;
}
}

Future<Map<String, String>?> logIn(String login, String password) async {
try {
emit(AuthInProgress());
await Future.delayed(const Duration(seconds: 2));
emit(AuthSuccess());
UserCredential result = await _auth.signInWithEmailAndPassword(
email: login, password: password);
User? user = result.user;
if (user != null) {
await _storage.setData(login, password);
emit(AuthSuccess());
return {'id': user.uid, 'login': login, 'password': password};
} else {
emit(AuthError());
return null;
}
} catch (error) {
print(error);
emit(AuthError());
return null;
}
}

void registration() {
bool isEmptyFieldsAuth(String login, String password) {
if (login.isEmpty || password.isEmpty) {
emit(AuthEmptyFields());
return true;
}
return false;
}

// bool isEmptyFieldsRegister(String name, String login, String password) {
// if (name.isEmpty || login.isEmpty || password.isEmpty) {
// emit(RegistrationEmptyFields());
// return true;
// }
// return false;
// }

void setRegistration() {
emit(AuthRegistration());
}

// Future<Map<String, String>?> register(
// String name, String login, String password) async {
// try {
// UserCredential result = await _auth.createUserWithEmailAndPassword(
// email: login, password: password);
// User? user = result.user;
// if (user != null) {
// await _storage.setData(login, password);
// emit(RegistrationSuccess());
// return {
// 'id': user.uid,
// 'name': name,
// 'email': login,
// 'password': password
// };
// } else {
// emit(RegistrationError());
// return null;
// }
// } on FirebaseAuthException catch (error) {
// print(error);
// if (error.code == 'email-already-in-use') {
// emit(RegErrorEmailInUse()); // ошибка: почта уже используется
// } else if (error.code == 'invalid-email') {
// emit(RegErrorInvalidEmail()); // ошибка: неккоректная почта
// } else if (error.code == 'operation-not-allowed') {
// emit(RegErrorDisabledAccount()); // ошибка: аккаунт отключен
// } else {
// emit(RegErrorShortPassword()); // ошибка: короткий пароль
// }
// return null;
// } catch (error) {
// print(error);
// emit(RegistrationError());
// return null;
// }
// }

Future<void> logOut() async {
await _storage.clear();
await _auth.signOut();
}
}
26 changes: 24 additions & 2 deletions lib/cubit/auth_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,34 @@ part of 'auth_cubit.dart';
@immutable
abstract class AuthState {}

class AuthInitial extends AuthState {}
class AuthInitialState extends AuthState {}

class AuthPage extends AuthState {}

class AuthError extends AuthState {}

class AuthEmptyFields extends AuthState {}

class AuthSuccess extends AuthState {}

class AuthInProgress extends AuthState {}

class AuthRegistration extends AuthState{}
class AuthRegistration extends AuthState {}

// class RegistrationInitial extends AuthState {}

// class RegistrationError extends AuthState {}

// class RegErrorEmailInUse extends AuthState {}

// class RegErrorInvalidEmail extends AuthState {}

// class RegErrorDisabledAccount extends AuthState {}

// class RegErrorShortPassword extends AuthState {}

// class RegistrationEmptyFields extends AuthState {}

// class RegistrationSuccess extends AuthState {}

// class RegistrationInProgress extends AuthState {}
Loading