-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForumContent.java
More file actions
135 lines (111 loc) · 4.96 KB
/
ForumContent.java
File metadata and controls
135 lines (111 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package com.example.ikoala.ui.social;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.widget.TextView;
import com.example.ikoala.adapters.ForumItemAdapter;
import com.example.ikoala.database.BaseActivity;
import com.example.ikoala.database.DatabaseManager;
import com.example.ikoala.database.ForumItem;
import com.example.ikoala.ui.ParentActivity;
import com.example.ikoala.utils.ColorUtils;
import com.firebase.ui.firestore.FirestoreRecyclerOptions;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import androidx.appcompat.app.ActionBar;
import androidx.core.text.HtmlCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.ikoala.R;
import com.google.firebase.firestore.Query;
import java.util.Locale;
public class ForumContent extends ParentActivity {
private BaseActivity mActivity;
private String forumPage;
private ForumItemAdapter adapter;
private String disclaimerDescription = "Please be encouraging towards others! Positive feedback can significantly influence others behaviour. ";
private TextView disclaimerView;
//TODO change adming district to actual admin distirct of user
String userAdminDistrict = "Bath";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_forum_content);
Intent intentRec = getIntent();
mActivity = intentRec.getParcelableExtra("activity");
forumPage = intentRec.getStringExtra("forumPage");
disclaimerView = findViewById(R.id.disclaimer_description_subforum);
disclaimerView.setText(disclaimerDescription);
//action bar
ActionBar bar = getSupportActionBar();
if (bar != null)
{
bar.show();
bar.setDisplayHomeAsUpEnabled(true);
bar.setDisplayShowHomeEnabled(true);
int color = ColorUtils.getColor(this, R.attr.themeColorHighlight);
String htmlColor = String.format(Locale.US, "#%06X", (0xFFFFFF & color));
bar.setTitle(HtmlCompat.fromHtml("<font color=\"" + htmlColor + "\">" + mActivity.getName() + " " + forumPage + " </font>", HtmlCompat.FROM_HTML_MODE_LEGACY));
bar.setBackgroundDrawable(new ColorDrawable(ColorUtils.getColor(this, R.attr.themeColorSecondary)));
}
//floating button
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(v -> {
Intent intent = new Intent(ForumContent.this, NewForumPostActivity.class);
intent.putExtra("activity", mActivity);
intent.putExtra("forumPage", forumPage);
startActivity(intent);
});
setUpRecyclerView();
}
@Override
protected void setupViewUI() { }
private void setUpRecyclerView() {
Query desiredQuery = DatabaseManager.getForum(mActivity.getName().toLowerCase(), forumPage)
.orderBy("datePosted", Query.Direction.DESCENDING);
//local opportunities is an exception as data in the database requires filtering by location
if(forumPage.equals("local_opportunities")){
desiredQuery = DatabaseManager.getForum(mActivity.getName().toLowerCase(), forumPage)
.whereEqualTo("location", userAdminDistrict).orderBy("datePosted", Query.Direction.DESCENDING);
}
FirestoreRecyclerOptions<ForumItem> options = new FirestoreRecyclerOptions.Builder<ForumItem>()
.setQuery(desiredQuery, ForumItem.class)
.build();
adapter = new ForumItemAdapter(options, this);
RecyclerView recyclerView = findViewById(R.id.forum_recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
//Setting onClickListener for when each post is clicked
adapter.setOnItemClickListener((documentSnapshot, position) -> {
ForumItem item = documentSnapshot.toObject(ForumItem.class);
String id = documentSnapshot.getId();
String path = documentSnapshot.getReference().getPath();
Intent intent = new Intent(ForumContent.this, ExpandedPostActivity.class);
intent.putExtra("post", item);
intent.putExtra("forumPage", forumPage);
intent.putExtra("postId", documentSnapshot.getId());
intent.putExtra("activity", mActivity);
startActivity(intent);
});
}
@Override
public void onStart(){
super.onStart();
adapter.startListening();
}
@Override
protected void onStop(){
super.onStop();
adapter.stopListening();
}
@Override
public void onBackPressed()
{
super.onDefaultBackPressed();
}
@Override
public boolean onSupportNavigateUp()
{
onBackPressed();
return true;
}
}