V1.0.1(2) 添加Firebase

This commit is contained in:
lihongwei 2024-11-13 15:21:57 +08:00
parent 132f7989a8
commit b83e5b229e
7 changed files with 67 additions and 18 deletions

View File

@ -3,6 +3,8 @@ import java.util.Date
plugins {
alias(libs.plugins.android.application)
id("com.google.gms.google-services")
id("com.google.firebase.crashlytics")
}
val timestamp = SimpleDateFormat("MM_dd_HH_mm").format(Date())
android {
@ -13,8 +15,8 @@ android {
applicationId = "com.lock.arcanvasart"
minSdk = 23
targetSdk = 34
versionCode = 1
versionName = "1.0.0"
versionCode = 2
versionName = "1.0.1"
setProperty("archivesBaseName", "AR Canvas Art_V" + versionName + "(${versionCode})_$timestamp")
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
@ -59,4 +61,13 @@ dependencies {
implementation ("androidx.camera:camera-extensions:1.4.0")
implementation ("androidx.camera:camera-camera2:1.4.0")
// Import the BoM for the Firebase platform
implementation(platform("com.google.firebase:firebase-bom:33.5.1"))
// Add the dependencies for the Crashlytics and Analytics libraries
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation("com.google.firebase:firebase-crashlytics")
implementation("com.google.firebase:firebase-analytics")
implementation("com.google.firebase:firebase-config")
}

29
app/google-services.json Normal file
View File

@ -0,0 +1,29 @@
{
"project_info": {
"project_number": "490252788816",
"project_id": "ar-canvas-art",
"storage_bucket": "ar-canvas-art.firebasestorage.app"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:490252788816:android:607835a15af070ea989d55",
"android_client_info": {
"package_name": "com.lock.arcanvasart"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyDv-cMovN3KYmocQ7C8HxnWzrnM38L-Nq0"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import com.google.firebase.FirebaseApp;
import com.lock.arcanvasart.Utils.ImageRepository;
import java.io.IOException;
@ -25,6 +26,16 @@ public class MyApplication extends Application {
super.onCreate();
mContext = getApplicationContext();
// // 确保Firebase初始化
// FirebaseApp.initializeApp(this);
//
// // 输出日志以确认Firebase初始化
// if (!FirebaseApp.getApps(this).isEmpty()) {
// Log.d("TAG", "Firebase 初始化成功");
// } else {
// Log.e("TAG", "Firebase 初始化失败");
// }
// 检查是否需要初始化数据库
SharedPreferences preferences = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
boolean isDatabaseInitialized = preferences.getBoolean(KEY_INITIALIZED, false);

View File

@ -161,13 +161,13 @@ public class CameraActivity extends AppCompatActivity implements View.OnTouchLis
if (PermissionUtils.handlePermissionsResult(grantResults)) {
startCamera();
} else {
Toast.makeText(this, "相机权限被拒绝,请在设置中启用权限", Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Camera permissions denied, please enable permissions in Settings", Toast.LENGTH_SHORT).show();
}
} else if (requestCode == STORAGE_PERMISSION_REQUEST_CODE) {
if (PermissionUtils.handlePermissionsResult(grantResults)) {
openImagePicker();
} else {
Toast.makeText(this, "存储权限被拒绝,请在设置中启用权限", Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Storage permission is denied. Please enable the permission in the Settings", Toast.LENGTH_SHORT).show();
}
}
}
@ -175,7 +175,7 @@ public class CameraActivity extends AppCompatActivity implements View.OnTouchLis
private void takePhoto() {
// 确保 imageCapture 实例已初始化
if (imageCapture == null) {
Toast.makeText(this, "拍照功能未初始化", Toast.LENGTH_SHORT).show();
Toast.makeText(this, "The photo function is not initialized", Toast.LENGTH_SHORT).show();
return;
}
@ -199,12 +199,12 @@ public class CameraActivity extends AppCompatActivity implements View.OnTouchLis
new ImageCapture.OnImageSavedCallback() {
@Override
public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) {
Toast.makeText(CameraActivity.this, "照片已保存到相册", Toast.LENGTH_SHORT).show();
Toast.makeText(CameraActivity.this, "The photo has been saved to the album", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(@NonNull ImageCaptureException exception) {
Toast.makeText(CameraActivity.this, "拍照失败: " + exception.getMessage(), Toast.LENGTH_SHORT).show();
Toast.makeText(CameraActivity.this, "Photo failure: " + exception.getMessage(), Toast.LENGTH_SHORT).show();
}
}
);
@ -334,7 +334,7 @@ public class CameraActivity extends AppCompatActivity implements View.OnTouchLis
if (bitmap != null) {
imageView.setImageBitmap(bitmap);
} else {
Toast.makeText(this, "加载图片失败", Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Image loading failed", Toast.LENGTH_SHORT).show();
}
}
@ -351,7 +351,7 @@ public class CameraActivity extends AppCompatActivity implements View.OnTouchLis
imageView.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, "加载图片失败: " + e.getMessage(), Toast.LENGTH_SHORT).show(); // 显示错误信息
Toast.makeText(this, "Image loading failed: " + e.getMessage(), Toast.LENGTH_SHORT).show(); // 显示错误信息
}
}

View File

@ -46,9 +46,5 @@ public class SplashActivity extends AppCompatActivity {
countDownTimer.start();
}
}

View File

@ -119,11 +119,11 @@ public class ProfileFragment extends Fragment implements ProfileAdapter.OnHeader
if (isImageSizeAcceptable(selectedImageUri)) {
saveImageToInternalStorage(selectedImageUri); // 保存图片到内部存储
} else {
Toast.makeText(getContext(), "图片大小超过限制", Toast.LENGTH_SHORT).show();
Toast.makeText(getContext(), "The image size is out of limit", Toast.LENGTH_SHORT).show();
}
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getContext(), "无法获取图片大小: " + e.getMessage(), Toast.LENGTH_SHORT).show();
Toast.makeText(getContext(), "Could not get image size: " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
@ -164,7 +164,7 @@ public class ProfileFragment extends Fragment implements ProfileAdapter.OnHeader
Bitmap bitmap = BitmapFactory.decodeStream(inputStream); // 解码图片
if (bitmap == null) {
Toast.makeText(getContext(), "无法加载图片", Toast.LENGTH_SHORT).show();
Toast.makeText(getContext(), "Unable to load image", Toast.LENGTH_SHORT).show();
return;
}
@ -181,7 +181,7 @@ public class ProfileFragment extends Fragment implements ProfileAdapter.OnHeader
// 检查图片是否已经存在
new Thread(() -> {
if (isImageAlreadyExists(imagePath)) {
requireActivity().runOnUiThread(() -> Toast.makeText(getContext(), "该图片已经存在", Toast.LENGTH_SHORT).show());
requireActivity().runOnUiThread(() -> Toast.makeText(getContext(), "The image already exists", Toast.LENGTH_SHORT).show());
imageFile.delete(); // 删除重复的文件
return;
}
@ -194,7 +194,7 @@ public class ProfileFragment extends Fragment implements ProfileAdapter.OnHeader
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getContext(), "保存图片失败: " + e.getMessage(), Toast.LENGTH_SHORT).show();
Toast.makeText(getContext(), "Failed to save picture: " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
}

View File

@ -1,4 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.android.application) apply false
id("com.google.gms.google-services") version "4.3.15" apply false
id ("com.google.firebase.crashlytics") version "2.9.2" apply false
}