Skip to content

Commit

Permalink
Communities - user can join communities
Browse files Browse the repository at this point in the history
  • Loading branch information
xFallingDuskx committed Aug 11, 2021
1 parent b793433 commit 1a47d93
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ public void run() {
public void setCommunityInformation() {
tvName.setText(community.getName());
tvDescription.setText(community.getDescription());
tvMembers.setText(community.getNumberOfMembers() + " Members");
int numberOfMembers = community.getNumberOfMembers();
if (numberOfMembers == 1) {
tvMembers.setText(numberOfMembers + " Member");
} else {
tvMembers.setText(numberOfMembers + " Members");
}

if (members.contains(currentUser)) {
ivParticipationStatus.setImageResource(R.drawable.ic_following_true);
Expand Down Expand Up @@ -410,7 +415,7 @@ public void handleJoinAction() throws JSONException {
public void onClick(View v){
// If the user is part of the community and wishes to leave it
if (joined) {
SweetAlertDialog sweetAlertDialog = new SweetAlertDialog(context, SweetAlertDialog.WARNING_TYPE);
SweetAlertDialog sweetAlertDialog = new SweetAlertDialog(CommunityDetailsActivity.this, SweetAlertDialog.WARNING_TYPE);
sweetAlertDialog.setTitleText("Are you sure?")
.setContentText("If you leave this community, you will no longer be able to make post with your fellow Platform users.")
.setCancelText("Nevermind")
Expand All @@ -430,8 +435,12 @@ public void onClick(SweetAlertDialog sweetAlertDialog) {
members.remove(members.indexOf(currentUser));
joined = false;
rlMakePost.setVisibility(View.GONE);
String updatedMembersDisplay = (Integer.valueOf(tvMembers.getText().toString().substring(0, 1)) - 1) + " Members";
tvMembers.setText(updatedMembersDisplay);
int numberOfMembers = community.getNumberOfMembers() - 1;
if (numberOfMembers == 1) {
tvMembers.setText(numberOfMembers + " Member");
} else {
tvMembers.setText(numberOfMembers + " Members");
}
sweetAlertDialog.changeAlertType(SweetAlertDialog.SUCCESS_TYPE);
sweetAlertDialog.setTitleText("Change successful")
.setContentText("You are no longer are member of " + community.getName())
Expand All @@ -446,9 +455,13 @@ public void onClick(SweetAlertDialog sweetAlertDialog) {
members.add(currentUser);
joined = true;
rlMakePost.setVisibility(View.VISIBLE);
String updatedMembersDisplay = (Integer.valueOf(tvMembers.getText().toString().substring(0, 1)) + 1) + " Members";
tvMembers.setText(updatedMembersDisplay);
SweetAlertDialog sweetAlertDialog = new SweetAlertDialog(context, SweetAlertDialog.SUCCESS_TYPE);
int numberOfMembers = community.getNumberOfMembers() + 1;
if (numberOfMembers == 1) {
tvMembers.setText(numberOfMembers + " Member");
} else {
tvMembers.setText(numberOfMembers + " Members");
}
SweetAlertDialog sweetAlertDialog = new SweetAlertDialog(CommunityDetailsActivity.this, SweetAlertDialog.SUCCESS_TYPE);
sweetAlertDialog.setTitleText("Successfully joined")
.setContentText("You are now a member of " + community.getName())
.setConfirmClickListener(null)
Expand All @@ -475,17 +488,25 @@ public void onClick(SweetAlertDialog sweetAlertDialog) {
members.remove(members.indexOf(currentUser));
joined = false;
rlMakePost.setVisibility(View.GONE);
String updatedMembersDisplay = (Integer.valueOf(tvMembers.getText().toString().substring(0, 1)) - 1) + " Members";
tvMembers.setText(updatedMembersDisplay);
int numberOfMembers = community.getNumberOfMembers() - 1;
if (numberOfMembers == 1) {
tvMembers.setText(numberOfMembers + " Member");
} else {
tvMembers.setText(numberOfMembers + " Members");
}
} else {
Log.i(TAG, "User was unable to leave the community due to issue");
ivParticipationStatus.setImageResource(R.drawable.ic_following_true);
tvParticipationStatus.setText(R.string.joined);
members.add(currentUser);
joined = true;
rlMakePost.setVisibility(View.VISIBLE);
String updatedMembersDisplay = (Integer.valueOf(tvMembers.getText().toString().substring(0, 1)) + 1) + " Members";
tvMembers.setText(updatedMembersDisplay);
int numberOfMembers = community.getNumberOfMembers() + 1;
if (numberOfMembers == 1) {
tvMembers.setText(numberOfMembers + " Member");
} else {
tvMembers.setText(numberOfMembers + " Members");
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import androidx.core.view.MenuItemCompat;
import androidx.fragment.app.Fragment;

import android.os.Handler;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -99,13 +100,14 @@ public void onClick(View v) {
});

// Handle searches
// Source: https://www.bragitoff.com/2017/04/trigger-button-click-press-doneenter-key-keyboard-solved/
etSearchInput = (EditText) view.findViewById(R.id.etSearchInput);
etSearchInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Intent intent = new Intent(getContext(), CommunitiesActivity_Display.class);
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE) || actionId == EditorInfo.IME_ACTION_SEARCH) {
Intent intent = new Intent(getContext(), CommunitiesActivity_Display.class);
String search = etSearchInput.getText().toString();
if (search.isEmpty()) {
Toast.makeText(getContext(), "Search cannot be empty", Toast.LENGTH_SHORT).show();
Expand All @@ -114,7 +116,12 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
intent.putExtra("objective", "search");
intent.putExtra("query", search);
startActivity(intent);
etSearchInput.setText("");
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
etSearchInput.setText("");
}
}, 2000);
handled = true;
}
return handled;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_communities.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
android:fontFamily="@font/pt_sans"
android:hint="Find your community"
android:imeOptions="actionSearch"
android:inputType="text"
android:inputType="textShortMessage"
android:textColor="@color/black_light"
android:textColorHint="@color/grey_medium"
android:textSize="18sp" />
Expand Down

0 comments on commit 1a47d93

Please sign in to comment.