This commit is contained in:
coco
2026-07-03 15:47:27 +08:00
commit 7846a45f2c
38575 changed files with 4736783 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
/build
+49
View File
@@ -0,0 +1,49 @@
plugins {
alias(libs.plugins.androidLibrary)
}
android {
namespace 'com.monke.firebase'
compileSdk 34
defaultConfig {
minSdk 24
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}
dependencies {
implementation project(':domain:data')
implementation project(':core:utils')
implementation libs.appcompat
implementation libs.material
testImplementation libs.junit
androidTestImplementation libs.ext.junit
androidTestImplementation libs.espresso.core
implementation platform(libs.firebase.bom)
implementation libs.firebase.auth
implementation libs.firebase.firestore
implementation libs.firebase.storage
implementation libs.dagger2
annotationProcessor libs.dagger.compiler
}
+21
View File
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
@@ -0,0 +1,26 @@
package com.monke.firebase;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.monke.firebase.test", appContext.getPackageName());
}
}
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>
@@ -0,0 +1,52 @@
package com.monke.firebase;
import android.net.Uri;
import androidx.lifecycle.LiveData;
import com.google.firebase.storage.FirebaseStorage;
import com.monke.data.FilesRemoteDataSource;
import com.monke.data.OnCompleteListener;
import com.monke.data.Result;
import com.monke.utils.ThreadUtils;
import javax.inject.Inject;
public class FilesRemoteDataSourceImpl implements FilesRemoteDataSource {
private FirebaseStorage storage;
@Inject
public FilesRemoteDataSourceImpl(FirebaseStorage storage) {
this.storage = storage;
}
@Override
public void uploadFile(Uri uri, String path, OnCompleteListener<Result<?>> onCompleteListener) {
ThreadUtils.runOnBackground(() -> {
var ref = storage.getReference(path);
ref.putFile(uri).addOnCompleteListener(task -> {
if (task.isSuccessful()) {
onCompleteListener.onComplete(new Result.Success<>());
} else {
onCompleteListener.onComplete(new Result.Failure<>(task.getException()));
}
});
});
}
@Override
public void getFileDownloadUrl(String path, OnCompleteListener<Result<String>> onCompleteListener) {
ThreadUtils.runOnBackground(() -> {
var ref = storage.getReference(path);
ref.getDownloadUrl().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
onCompleteListener.onComplete(new Result.Success<>(task.getResult().toString()));
} else {
onCompleteListener.onComplete(new Result.Failure<>(task.getException()));
}
});
});
}
}
@@ -0,0 +1,78 @@
package com.monke.firebase;
import android.net.Uri;
import androidx.lifecycle.LiveData;
import com.monke.data.FilesRemoteDataSource;
import com.monke.data.FilesRepository;
import com.monke.data.OnCompleteListener;
import com.monke.data.Result;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import javax.inject.Inject;
public class FilesRepositoryImpl implements FilesRepository {
private FilesRemoteDataSource remoteDataSource;
private volatile AtomicInteger imagesToLoad = new AtomicInteger();
@Inject
public FilesRepositoryImpl(FilesRemoteDataSource remoteDataSource ) {
this.remoteDataSource = remoteDataSource;
}
@Override
public void uploadImages(String collection, List<String> imagesUrls,
OnCompleteListener<Result<?>> listener) {
if (imagesUrls.isEmpty()) {
listener.onComplete(new Result.Success<>());
return;
}
imagesToLoad.set(imagesUrls.size());
for (String imageUrl: imagesUrls) {
var path = collection + "/" + imageUrl;
remoteDataSource.uploadFile(Uri.parse(imageUrl), path, result -> {
if (result.isFailure()) {
listener.onComplete(result);
return;
}
imagesToLoad.getAndDecrement();
if (imagesToLoad.get() == 0) listener.onComplete(new Result.Success<>());
});
}
}
@Override
public void getFileDownloadUrl(String path, OnCompleteListener<Result<String>> listener) {
remoteDataSource.getFileDownloadUrl(path, listener);
}
@Override
public void getFilesDownloadUrls(List<String> pathList,
OnCompleteListener<Result<List<String>>> listener) {
if (pathList.isEmpty()) {
listener.onComplete(new Result.Success<>(Collections.emptyList()));
return;
}
imagesToLoad.set(pathList.size());
ArrayList<String> urls = new ArrayList<>();
for (String path: pathList) {
remoteDataSource.getFileDownloadUrl(path, result -> {
if (result.isFailure()) {
listener.onComplete(new Result.Failure<>(result.getException()));
return;
}
imagesToLoad.getAndDecrement();
urls.add(result.get());
if (imagesToLoad.get() == 0) listener.onComplete(new Result.Success<>(urls));
});
}
}
}
@@ -0,0 +1,16 @@
package com.monke.firebase;
import com.monke.data.FilesRemoteDataSource;
import com.monke.data.FilesRepository;
import dagger.Binds;
import dagger.Module;
@Module
public interface RemoteBindings {
@Binds
FilesRepository bindFilesRepository(FilesRepositoryImpl i);
@Binds
FilesRemoteDataSource bindFilesRemoteDataSource(FilesRemoteDataSourceImpl i);
}
@@ -0,0 +1,31 @@
package com.monke.firebase;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.storage.FirebaseStorage;
import dagger.Binds;
import dagger.Module;
import dagger.Provides;
@Module(
includes = RemoteBindings.class
)
public class RemoteModule {
@Provides
FirebaseAuth provideFirebaseAuth() {
return FirebaseAuth.getInstance();
}
@Provides
FirebaseFirestore provideFirestore() {
return FirebaseFirestore.getInstance();
}
@Provides
FirebaseStorage provideFirebaseStorage() {
return FirebaseStorage.getInstance();
}
}
@@ -0,0 +1,17 @@
package com.monke.firebase;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}