Skip to content

Commit

Permalink
Communities - User can view communities through catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
xFallingDuskx committed Aug 10, 2021
1 parent f62a66f commit e6d98a9
Show file tree
Hide file tree
Showing 11 changed files with 674 additions and 60 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
android:roundIcon="@drawable/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Platform">
<activity android:name=".activities.CommunitiesActivity_Create"></activity>
<activity android:name=".activities.CommunityDetailsActivity"></activity>
<activity android:name=".activities.CommunitiesActivity_Create" />
<activity android:name=".activities.CommunitiesActivity_ByGenre" />
<activity
android:name=".activities.CommunitiesActivity_Display"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;

import com.example.platform.R;

public class CommunitiesActivity_ByGenre extends AppCompatActivity {

public static final String TAG = "CommunitiesActivity_ByGenre";
Context context;
RelativeLayout rlAction, rlAdventure, rlAnimation, rlComedy, rlCrime, rlDocumentary, rlDrama, rlFamily, rlFantasy, rlHistory, rlHorror, rlMusic, rlReality, rlRomance, rlScienceFiction, rlSoap, rlTalk, rlThriller, rlWar, rlWestern;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_communities_by_genre);
context = getApplicationContext();

rlAction = findViewById(R.id.rlAction_Genre);
rlAdventure = findViewById(R.id.rlAdventure_Genre);
Expand All @@ -38,6 +43,204 @@ protected void onCreate(Bundle savedInstanceState) {
rlWar = findViewById(R.id.rlWar_Genre);
rlWestern = findViewById(R.id.rlWestern_Genre);

//todo
rlAction.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CommunitiesActivity_Display.class);
intent.putExtra("objective", "genre");
intent.putExtra("genreName", "action");
startActivity(intent);
}
});

rlAdventure.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CommunitiesActivity_Display.class);
intent.putExtra("objective", "genre");
intent.putExtra("genreName", "adventure");
startActivity(intent);
}
});

rlAnimation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CommunitiesActivity_Display.class);
intent.putExtra("objective", "genre");
intent.putExtra("genreName", "animation");
startActivity(intent);
}
});

rlComedy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CommunitiesActivity_Display.class);
intent.putExtra("objective", "genre");
intent.putExtra("genreName", "comedy");
startActivity(intent);
}
});

rlCrime.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CommunitiesActivity_Display.class);
intent.putExtra("objective", "genre");
intent.putExtra("genreName", "crime");
startActivity(intent);
}
});

rlDocumentary.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CommunitiesActivity_Display.class);
intent.putExtra("objective", "genre");
intent.putExtra("genreName", "documentary");
startActivity(intent);
}
});

rlDrama.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CommunitiesActivity_Display.class);
intent.putExtra("objective", "genre");
intent.putExtra("genreName", "drama");
startActivity(intent);
}
});

rlFamily.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CommunitiesActivity_Display.class);
intent.putExtra("objective", "genre");
intent.putExtra("genreName", "family");
startActivity(intent);
}
});

rlFantasy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CommunitiesActivity_Display.class);
intent.putExtra("objective", "genre");
intent.putExtra("genreName", "fantasy");
startActivity(intent);
}
});

rlHistory.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CommunitiesActivity_Display.class);
intent.putExtra("objective", "genre");
intent.putExtra("genreName", "history");
startActivity(intent);
}
});

rlHorror.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CommunitiesActivity_Display.class);
intent.putExtra("objective", "genre");
intent.putExtra("genreName", "horror");
startActivity(intent);
}
});

rlMusic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CommunitiesActivity_Display.class);
intent.putExtra("objective", "genre");
intent.putExtra("genreName", "music");
startActivity(intent);
}
});

rlReality.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CommunitiesActivity_Display.class);
intent.putExtra("objective", "genre");
intent.putExtra("genreName", "reality");
startActivity(intent);
}
});

rlRomance.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CommunitiesActivity_Display.class);
intent.putExtra("objective", "genre");
intent.putExtra("genreName", "romance");
startActivity(intent);
}
});

rlScienceFiction.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CommunitiesActivity_Display.class);
intent.putExtra("objective", "genre");
intent.putExtra("genreName", "science fiction");
startActivity(intent);
}
});

rlSoap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CommunitiesActivity_Display.class);
intent.putExtra("objective", "genre");
intent.putExtra("genreName", "soap");
startActivity(intent);
}
});

rlTalk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CommunitiesActivity_Display.class);
intent.putExtra("objective", "genre");
intent.putExtra("genreName", "talk");
startActivity(intent);
}
});

rlThriller.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CommunitiesActivity_Display.class);
intent.putExtra("objective", "genre");
intent.putExtra("genreName", "thriller");
startActivity(intent);
}
});

rlWar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CommunitiesActivity_Display.class);
intent.putExtra("objective", "genre");
intent.putExtra("genreName", "war");
startActivity(intent);
}
});

rlWestern.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CommunitiesActivity_Display.class);
intent.putExtra("objective", "genre");
intent.putExtra("genreName", "western");
startActivity(intent);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

import com.example.platform.R;
import com.example.platform.models.Community;
import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;

import org.json.JSONArray;
Expand Down Expand Up @@ -155,7 +158,12 @@ public void onClick(SweetAlertDialog sweetAlertDialog) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
createCommunity();
try {
createCommunity();
} catch (ParseException e) {
Log.d(TAG, "Issue creating community for the user");
e.printStackTrace();
}
}
}, 4000);
}
Expand All @@ -164,48 +172,67 @@ public void run() {
}


public void createCommunity() {
// Get keywords
String[] keywordsArray = etKeywords.getText().toString().split(", ");
List<String> keywords = new ArrayList<>();
for (String s : keywordsArray) {
String keyword = s.toLowerCase();
keywords.add(keyword);
}

String currentUser = ParseUser.getCurrentUser().getUsername();
Community community = new Community();
community.setName(etName.getText().toString());
community.setDescription(etDescription.getText().toString());
community.setCreator(currentUser);
community.setMembers(Arrays.asList(currentUser));
community.setGenres(new ArrayList<>(genresSelected));
community.setKeywords(keywords);

// Saves the new object.
// Notice that the SaveCallback is totally optional!
community.saveInBackground(e -> {
if (e==null){
Log.i(TAG, "Community was saved successfully");
sweetAlertDialogMain.setTitleText("Create!")
.setContentText("Your Platform community has been successfully created!")
.setConfirmText("OK")
.setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog sweetAlertDialog) {
finish();
}
})
.changeAlertType(SweetAlertDialog.SUCCESS_TYPE);
}else{
Log.d(TAG, "Issue saving community /Error: " + e.getMessage());
sweetAlertDialogMain.setTitleText("Sorry!")
.setContentText("There was an issue creating your community")
.setConfirmText("OK")
.setConfirmClickListener(null)
.changeAlertType(SweetAlertDialog.ERROR_TYPE);
public void createCommunity() throws ParseException {
// Ensure this community does not already exist
String name = etName.getText().toString();
ParseQuery<Community> parseQuery = ParseQuery.getQuery(Community.class);
parseQuery.whereEqualTo(Community.KEY_NAME, name);
if (parseQuery.count() != 0) {
Log.i(TAG, "Community has already been created");
sweetAlertDialogMain.setTitleText("Unable to Create")
.setContentText("A community with this name already exist. Please pick a different name.")
.setConfirmText("OK")
.setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog sweetAlertDialog) {
finish();
}
})
.changeAlertType(SweetAlertDialog.WARNING_TYPE);
} else {
// Get keywords
String[] keywordsArray = etKeywords.getText().toString().split(", ");
List<String> keywords = new ArrayList<>();
for (String s : keywordsArray) {
String keyword = s.toLowerCase();
keywords.add(keyword);
}
});

String currentUser = ParseUser.getCurrentUser().getUsername();
Community community = new Community();
community.setName(name);
community.setDescription(etDescription.getText().toString());
community.setCreator(currentUser);
community.setMembers(Arrays.asList(currentUser));
community.setGenres(new ArrayList<>(genresSelected));
community.setKeywords(keywords);
community.setNumberOfMembers(1);

// Saves the new object.
// Notice that the SaveCallback is totally optional!
community.saveInBackground(e -> {
if (e == null) {
Log.i(TAG, "Community was saved successfully");
sweetAlertDialogMain.setTitleText("Create!")
.setContentText("Your Platform community has been successfully created!")
.setConfirmText("OK")
.setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog sweetAlertDialog) {
finish();
}
})
.changeAlertType(SweetAlertDialog.SUCCESS_TYPE);
} else {
Log.d(TAG, "Issue saving community /Error: " + e.getMessage());
sweetAlertDialogMain.setTitleText("Sorry!")
.setContentText("There was an issue creating your community")
.setConfirmText("OK")
.setConfirmClickListener(null)
.changeAlertType(SweetAlertDialog.ERROR_TYPE);
}
});
}
}

@Override
Expand Down
Loading

0 comments on commit e6d98a9

Please sign in to comment.