Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TianqinYu by main #46

Merged
merged 10 commits into from
Oct 22, 2024
Merged
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
26 changes: 26 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build

on:
push:
branches:
- main


jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
# If you wish to fail your job when the Quality Gate is red, uncomment the
# following lines. This would typically be used to fail a deployment.
# - uses: sonarsource/sonarqube-quality-gate-action@master
# timeout-minutes: 5
# env:
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions Project/Sprint2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
1 change: 1 addition & 0 deletions Project/Sprint2/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
50 changes: 50 additions & 0 deletions Project/Sprint2/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
plugins {
alias(libs.plugins.android.application)
id 'com.google.gms.google-services'
}

android {
namespace 'com.example.sprint1'
compileSdk 34

defaultConfig {
applicationId "com.example.sprint1"
minSdk 24
targetSdk 34
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
}

dependencies {

implementation libs.appcompat
implementation libs.material
implementation libs.constraintlayout
implementation libs.navigation.fragment
implementation libs.navigation.ui
implementation libs.firebase.database
testImplementation libs.junit
androidTestImplementation libs.ext.junit
androidTestImplementation libs.espresso.core

implementation platform('com.google.firebase:firebase-bom:33.4.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
}
29 changes: 29 additions & 0 deletions Project/Sprint2/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"project_info": {
"project_number": "386074328572",
"project_id": "sprint2-f2646",
"storage_bucket": "sprint2-f2646.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:386074328572:android:6057a9a2f9299c3edcc679",
"android_client_info": {
"package_name": "com.example.sprint1"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyC9OF-YDrpgFcGMrQvMTrhYSs7h_X4MnYM"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}
21 changes: 21 additions & 0 deletions Project/Sprint2/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.sprint1;

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.example.sprint1", appContext.getPackageName());
}
}
48 changes: 48 additions & 0 deletions Project/Sprint2/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Sprint1"
tools:targetApi="31">
<activity
android:name=".view.HomeTra"
android:exported="false" />
<activity
android:name=".view.HomeAcc"
android:exported="false" />
<activity
android:name=".view.HomeDin"
android:exported="false" />
<activity
android:name=".view.HomeLog"
android:exported="false" />
<activity
android:name=".view.HomeDes"
android:exported="false" />
<activity
android:name=".view.UserSignUp"
android:exported="false" />
<activity
android:name=".view.UserSignIn"
android:exported="false" />
<activity
android:name=".view.Welcome"
android:exported="true"
android:theme="@style/Theme.Sprint1">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.example.sprint1.model;

import androidx.annotation.NonNull;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import java.util.HashMap;


public class DestDatabase {

private final DatabaseReference destDatabase;
private String usernameCurr;

public DestDatabase() {
this.destDatabase = FirebaseDatabase.getInstance().getReference("destination");
}

public void setUsernameCurr(String username) {
this.usernameCurr = username;
}

public void addDestination(
String travelLocation, String startDate, String endDate, String duration,
MainModel.CallbackBool callback
) {
DatabaseReference refer = this.destDatabase.child(this.usernameCurr).child(travelLocation);
refer.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
callback.onResult(false);
} else {
HashMap<String, String> value = new HashMap<>();
value.put("travelLocation", travelLocation);
value.put("startDate", startDate);
value.put("endDate", endDate);
value.put("duration", duration);
destDatabase.child(usernameCurr).child(travelLocation).setValue(value);
callback.onResult(true);
}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {
callback.onResult(false);
}
});
}

public void getDestinations(MainModel.CallbackDestination callback) {
DatabaseReference refer = this.destDatabase.child(this.usernameCurr);
refer.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
HashMap<String, HashMap<String, String>> dest = new HashMap<>();
for (DataSnapshot destinationSnapshot : dataSnapshot.getChildren()) {
String travelLocation = destinationSnapshot.getKey();
HashMap<String, String> destinationDetails = new HashMap<>();
for (DataSnapshot detailSnapshot : destinationSnapshot.getChildren()) {
String key = detailSnapshot.getKey();
String value = detailSnapshot.getValue(String.class);
destinationDetails.put(key, value);
}
dest.put(travelLocation, destinationDetails);
}
callback.onResult(dest);
} else {
callback.onResult(null);
}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {
callback.onResult(null);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.example.sprint1.model;


import java.util.HashMap;

public class MainModel {

private static MainModel instance;
private final UserDatabase userDatabase = new UserDatabase();
private final DestDatabase destDatabase = new DestDatabase();

/* Singleton Design */

private MainModel() {

}

public static synchronized MainModel getInstance() {
if (instance == null) {
instance = new MainModel();
}
return instance;
}

/* Main Features */

public void userSignUp(String username, String password, CallbackBool callback) {
this.userDatabase.userSignUp(username, password, callback);
}

public void userSignIn(String username, String password, CallbackBool callback) {
this.userDatabase.userSignIn(username, password, success -> {
if (success) {
this.destDatabase.setUsernameCurr(this.userDatabase.getUsernameCurr());
}
callback.onResult(success);
});
}

public void addDestination(
String travelLocation, String startDate, String endDate, String duration,
CallbackBool callback
) {
this.destDatabase.addDestination(travelLocation, startDate, endDate, duration, callback);
}

public void getDestinations(CallbackDestination callback) {
this.destDatabase.getDestinations(callback);
}

public void setVacation(
String startDate, String endDate, String duration, CallbackBool callback) {
this.userDatabase.setVacation(startDate, endDate, duration, callback);
}

public void getVacation(CallbackVacation callback) {
this.userDatabase.getVacation(callback);
}

/* Callbacks */

public interface CallbackBool {
void onResult(boolean callback);
}

public interface CallbackDestination {
void onResult(HashMap<String, HashMap<String, String>> callback);
}

public interface CallbackVacation {
void onResult(HashMap<String, String> callback);
}
}
Loading
Loading