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

Hyerijang #3

Draft
wants to merge 19 commits into
base: bhlee
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ dependencies {
implementation 'com.google.firebase:firebase-database:19.5.1'
implementation 'com.google.firebase:firebase-storage:19.2.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="kr.hongik.mbti">

<!-- 인터넷 사용 권한 -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- 외부 저장소 사용 권한 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<permission android:name="kr.hongik.mbti.MatchingActivity.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
Expand All @@ -22,18 +21,19 @@
android:required="true"/>



<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MBTI">
<activity android:name=".MatchingActivity"></activity>
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity android:name=".FriendListActivity"></activity>
<activity android:name=".MyprofileActivity" />
<activity android:name=".SearchingPersonActivity" />
<activity android:name=".UpdateActivity" />
<activity android:name=".MatchingActivity" />
<activity android:name=".SearchingActivity" />
<activity android:name=".JoinActivity" />
<activity android:name=".MainActivity" />
Expand All @@ -45,6 +45,7 @@
</intent-filter>
</activity>


<uses-library android:name="com.google.android.maps" />
<uses-library android:name="org.apache.http.legacy"
android:required="false"/>
Expand All @@ -56,7 +57,6 @@
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
Expand Down
172 changes: 172 additions & 0 deletions app/src/main/java/kr/hongik/mbti/FriendList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
package kr.hongik.mbti;

import android.util.Log;

import androidx.annotation.NonNull;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.QueryDocumentSnapshot;
import com.google.firebase.firestore.QuerySnapshot;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;


/**
* 친구 목록 클래스. 친구목록과 관련있는 함수 구현함.
* @author 장혜리
**/

// TODO: firebase의 데이터 업로드 다운로드 매우 느림. 추후 Cache 저장 구현할 것.
// TODO: 클릭시 유저 프로필 띄워지는 기능 추가할 것.

public class FriendList{

final static String TAG = FriendList.class.getName();
final static Map<String, Object> emptyObject = new HashMap<>();

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
FirebaseFirestore db = FirebaseFirestore.getInstance();
String UserNum = user.getUid();

public ArrayList<FriendVO> Friends = new ArrayList<FriendVO>();
public ArrayList<FriendVO> friendRequets = new ArrayList<FriendVO>();
public ArrayList<FriendVO> sentFriendRequests = new ArrayList<FriendVO>();

public FriendList(){

}

/**
* 파이어베이스에서 친구목록을 가져온다.
* @param adapter
*/
public void getFriends(FriendListAdapter adapter ){
CollectionReference colRef = db.collection("friendList/"+user.getUid()+"/friends");
colRef.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
String friendUserNum =document.getId();
getUserinfo(friendUserNum, Friends,adapter);
}
} else {
Log.d(TAG, "Error getting documents: ", task.getException());
}
}
});
}

/**
* 파이어베이스에서 내게 온 친구신청을 가져온다.
* @param adapter
*/
public void getFriendRequets(FriendListAdapter adapter ){
CollectionReference colRef = db.collection("friendList/"+user.getUid()+"/friendRequets");
colRef.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
String friendUserNum =document.getId();
getUserinfo(friendUserNum, Friends,adapter);
}
} else {
Log.d(TAG, "Error getting documents: ", task.getException());
}
}
});
Log.d(TAG, "getFriendRequets: 친구 목록을 가져왔습니다.");
}


/**
* 친구의 userNum으로 친구 정보를 가져오는 함수
* @param userNum
* @param myFriendList
* @param adapter
*/
public void getUserinfo(String userNum, ArrayList<FriendVO> myFriendList , FriendListAdapter adapter ){
DocumentReference docRef = db.document("users/"+userNum);
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if(task.isSuccessful()){
DocumentSnapshot document = task.getResult();
if (document.exists()) {
myFriendList.add(new FriendVO(userNum, document.getString("nickname"), document.getString("stateMessage"), document.getString("mbti")));
adapter.notifyDataSetChanged();
Log.d(TAG, "current Friendlist size : "+ myFriendList.size());
}
}
}
});
}


/**
* otherUserNum에게 친구신청한다.
* @param otherUserNum
*/
public void sendFriendRequest(String otherUserNum){

if(otherUserNum == UserNum)
return;

//내가 친구 신청한 목록(sentFriendRequests)에 추가
CollectionReference colRef = db.collection("friendList/"+ UserNum +"/sentFriendRequests");
colRef.document(otherUserNum).set(emptyObject);

//상대방 친구 요청 목록(friendingList)에 나 추가
CollectionReference colRef2 = db.collection("friendList/"+otherUserNum+"/friendRequets");
colRef2.document(UserNum).set(emptyObject);
}

/**
* otherUserNum의 친구신청 수락
* @param otherUserNum
*/
public void acceptFriendRequest(String otherUserNum){

if(otherUserNum == UserNum)
return;

//내 친구 목록(friends)에 상대방 추가
CollectionReference colRef = db.collection("friendList/"+ UserNum +"/friends");
colRef.document(otherUserNum).set(emptyObject);

colRef = db.collection("friendList/"+ UserNum +"/friendRequets");
colRef.document(otherUserNum).delete();

//상대방 친구 목록에 나 추가
CollectionReference colRef2 = db.collection("friendList/"+otherUserNum+"/friends");
colRef2.document(UserNum).set(emptyObject);

colRef2 = db.collection("friendList/"+otherUserNum+"/sentFriendRequests");
colRef2.document(UserNum).delete();


}

//데모 시연용 데이터 만듦
public void makeSampleData(String OtherUserNum){
CollectionReference colRef = db.collection("friendList/"+ UserNum +"/friendRequets");
if(OtherUserNum != null)
colRef.document(OtherUserNum).set(emptyObject);

colRef.document("4MEeO638oeZqTzaQ545suXEOgF82").set(emptyObject);
colRef.document("YP6jS2oqzPc4gSaAGXBGJB5aWIf1").set(emptyObject);
colRef.document("rwH4ZolyfHTUscod2gs49sWRqu33").set(emptyObject);

}

}
73 changes: 73 additions & 0 deletions app/src/main/java/kr/hongik/mbti/FriendListActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package kr.hongik.mbti;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import java.util.HashMap;
import java.util.Map;

/**
* FriendListActivity는 FriendsFragment,FriendRequetsFragment, 총두개의 Fragment로 구성됩니다.
* @author 장혜리
**/

public class FriendListActivity extends AppCompatActivity {

final String TAG = FriendListActivity.class.getName();

Button btn_my_friend_list;

final Map<String, Object> emptyObject = new HashMap<>();

private boolean isFreindsFragment = true ;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_friend_list);

FragmentManager fm = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fm.beginTransaction();
fragmentTransaction.add(R.id.fragmentLayout, new FriendsFragment());
fragmentTransaction.commit();

btn_my_friend_list= findViewById(R.id.btn_my_friend_list);
btn_my_friend_list.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
switchFragment(new FriendsFragment());
}
});

btn_my_friend_list= findViewById(R.id.btn_friending);
btn_my_friend_list.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
switchFragment(new FriendRequetsFragment() );
}
});

}


/**
* fragment 전환해주는 함수
* @param fr
*/
public void switchFragment(Fragment fr) {

FragmentManager fm = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fm.beginTransaction();
fragmentTransaction.replace(R.id.fragmentLayout, fr);
fragmentTransaction.commit();
}


}

Loading