Skip to content

Other Features

Lee-Gahyun edited this page May 1, 2023 · 37 revisions

Join-in & Log-in

MainActivity.kt

When running the app, check the user's login status and show the appropriate screen.

If user is not logged in, start LoginActivity.
If user is logged in, run main()

LoginActivity.kt

Type user's email and password.

Check that it matches the stored in firestore.

MyApplication.auth.signInWithEmailAndPassword(email, password)

If isSuccessful and check.Auth(), it success log-in.
If isSuccessful and fail to check.Auth(), user didn't do email authentication.
If fail task, user didn't join-in or insert incorrect email or password.

JoinActivity.kt

We use Firebase authentication system by user's email authentication.

MyApplication.auth.createUserWithEmailAndPassword(email, password)

Insert email and password, do email authentication. Then user can do log-in.

If it isSuccessful to join-in, run

SetAI() to create AI chat room,
documentCreate(email) to create user's document in user collection,
and notiCreate(email) to create notofication collection in users > email


Writing Post

Tab2.kt

It shows the board list about user's interests on tab2Recyclerview from Tab2Adapter.

   ...binding.tab2Recyclerview.adapter = Tab2Adapter(requireContext(), itemList)

Tab2Adapter.kt

If user clicks recycler's item, go to FavdetailActivity, sending clicked board's name by intent.

holder.itemView.setOnClickListener{
        var intent = Intent(holder.itemView?.context, FavdetailActivity::class.java)
        intent.putExtra("favName", itemList[position].favName)
        ContextCompat.startActivity(holder.itemView.context,intent,null)
        }

FavDeatailActivity.kt

It shows board's main screen with recent 4 posts and users who can enter this board -it means that have same interest-.

Save board's name to favName by intent.

val intent = Intent(this, BoardViewActivity::class.java)
        intent.putExtra("favName", favName)
        val intent2 = Intent(this, FriendViewActivity::class.java)
        intent2.putExtra("favName", favName)

And move activity when click btnViewMore or btnFriendMore.

binding.btnViewMore.setOnClickListener{
            startActivity(intent)
        }
        binding.btnFriendMore.setOnClickListener{
            startActivity(intent2)
        }

Run functions getFavUsers(), joinFriendList(...), exceptMyFriend(...), makeUsersRecyclerView(...) and saveItemList(...) to get users list who are not friend with this user.

And shows users list on mainUserRecyclerView from UserAdapter

binding.mainUsersRecyclerView.adapter = UserAdapter(this, itemList)

UserAdapter.kt

If click requestBtn, run request(email.toString()) to send request and favDetailActivity.getFavUsers() to update users list.

BoardViewActivity.kt

Recieve intent favName, it means name of the clicked board. Get posts from firestore Board > favName > post. They are shown on moreBoardRecyclerView from BoardAdapter`.

binding.moreBoardRecyclerView.adapter = BoardAdapter(this, itemSort)

BoardAdpater.kt

If user click item, puts information about that post to intent, and calls ViewDetailActivity to open the post sending intent.

holder.itemView.setOnClickListener{
            val intent = Intent(holder.itemView?.context, ViewDetailActivity::class.java)
            intent.putExtra("title", itemList[position].title)
            ...
            ContextCompat.startActivity(holder.itemView.context, intent, null)
        }

There are two option menus to click. One is finish this activity and go back previous page. The other is menu_add, it runs writing() and go to BoardWritingActivity with intent.

ViewDetailActivity.kt

Recieves intent about the post from BoardAdapter and shows on layout. If the post has image, it gets image from firebase storage using image's reference.

val imgRef = MyApplication.storage.reference.child("images/${docId}.jpg")

If the post is that user's, the addFriendBtn isn't activated.
If it isn't, the button is activated and user can request writer for a friend.

Also, it shows different popup message when already request.
If already they are friend, user can start chats with writer.

BoardWritingActivity.kt

User can write post with image, and upload. There are three action bar menus.

If clicks home, is go back.
If clicks menu_image, user can open gallery and select an image which user wants to upload.

val intent = Intent(Intent.ACTION_PICK)
intent.setDataAndType(
    MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
    "image/*"
)

If clicks menu_writing, when title and content isn't empty, the post is uploaded.

To save and upload the post, runs function saveWriting(). In saveWriting(), maps data about the post.

If binding.writingImage.drawable != null, runs uploadImage(...).
Else, there is no need to save image.

To save image in storage, get the post's docId and it is be image's reference in storage.

Making Friend

UserAdapter.kt

In FavdetailActivity.kt and FriendViewActivity.kt, user can request to be friend to other users.
When user click button requestBtn, runs request(...).
Saves each other's email to user > email > request both users' collection.
And sends notification message to user who get request.
The user can accept request in notification screen from MainActivity.

MainActivity.kt

The button is on side of action bar. If clicks, it starts NotificationActivity.

UserMoreAdapter.kt

It works same in UserAdapter.kt.

Notification

NotificationActivity.kt

Get items from user > email > notification collection.
And it shows on notiRecyclerView from NotificationAdapter.

NotificationAdapter.kt

User can accept this notification layout. If click acceptBtn, updates requester and accepter each other's email to both's user > email > friend field. And delete that notification by deleting message from collection. Also sends two users a message about now they are friend.