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

Add support to report discussion thread #186

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@
android:configChanges="orientation|keyboardHidden|screenSize"
android:windowSoftInputMode="adjustResize|stateHidden"/>


<activity
android:name=".ui.ReportForumThread"
android:theme="@style/AppTheme"
android:label="Report Thread"
android:configChanges="orientation|keyboardHidden|screenSize"
android:windowSoftInputMode="adjustPan"/>

<activity
android:name=".ui.CreateForumActivity"
android:label="Create Forum Post"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import in.testpress.testpress.ui.ForumActivity;
import in.testpress.testpress.ui.ForumListActivity;
import in.testpress.testpress.ui.ForumListFragment;
import in.testpress.testpress.ui.ReportForumThread;
import in.testpress.testpress.ui.RssFeedDetailActivity;
import in.testpress.testpress.ui.SplashScreenActivity;
import in.testpress.testpress.ui.MainActivity;
Expand Down Expand Up @@ -84,7 +85,8 @@
ForumActivity.class,
CreateForumActivity.class,
WebViewActivity.class,
DashboardFragment.class
DashboardFragment.class,
ReportForumThread.class,
}
)
public class TestpressModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ Comment sendComments(
Vote<Forum> updateCommentVote(
@Path(value = "vote_id") long id,
@Body HashMap<String, Object> params);


@POST("/api/v2.5/discussions/{post_id}/report/")
Object reportPost(@Path(value="post_id") long postId, @Body Map<String, String> options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,12 @@ public Vote<Forum> updateCommentVote(Forum forum, int typeOfVote) {
return getPostService().updateCommentVote(forum.getVoteId(), params);
}

public Object reportPost(int postId, String reason) {
HashMap<String, String> params = new HashMap<>();
params.put("reason", reason);
return getPostService().reportPost(postId, params);
}

public DashboardResponse getDashboardData() {
return getAuthenticationService().getDashboardData();
}
Expand Down
25 changes: 24 additions & 1 deletion app/src/main/java/in/testpress/testpress/ui/ForumActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import android.text.Html;
import android.text.SpannableString;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
Expand Down Expand Up @@ -216,6 +218,7 @@ protected void onCreate(final Bundle savedInstanceState) {
setEmptyText(R.string.invalid_post, R.string.try_after_sometime,
R.drawable.ic_error_outline_black_18dp);
}

}

protected void initializeAnswerFragment() {
Expand Down Expand Up @@ -635,6 +638,26 @@ public void onScrollChange(NestedScrollView v, int scrollX, int scrollY,
getSupportLoaderManager().initLoader(PREVIOUS_COMMENTS_LOADER_ID, null, ForumActivity.this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.forum_action_menu, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.report:
Intent intent = new Intent(this, ReportForumThread.class);
intent.putExtra("title", forum.getTitle());
intent.putExtra("forum_id", forum.getId().intValue());
activity.startActivity(intent);
break;
}
return super.onOptionsItemSelected(item);
}

@NonNull
@Override
public Loader<List<Comment>> onCreateLoader(int loaderId, Bundle args) {
Expand Down
104 changes: 104 additions & 0 deletions app/src/main/java/in/testpress/testpress/ui/ReportForumThread.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package `in`.testpress.testpress.ui

import `in`.testpress.testpress.Injector
import `in`.testpress.testpress.R
import `in`.testpress.testpress.TestpressServiceProvider
import `in`.testpress.testpress.util.SafeAsyncTask
import android.app.Activity
import android.os.Bundle
import android.view.View
import android.widget.RadioButton
import android.widget.Toast
import kotlinx.android.synthetic.main.report_spam_thread.*
import javax.inject.Inject


class ReportForumThread: Activity() {
@Inject
lateinit var serviceProvider: TestpressServiceProvider


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Injector.inject(this)
setContentView(R.layout.report_spam_thread)
forumTitle.text = intent.getStringExtra("title")
setOnClickListeners()
}

private fun setOnClickListeners() {
toolbar.setNavigationOnClickListener {
onBackPressed()
}

cancelButton.setOnClickListener {
onBackPressed()
}

spamReasons.setOnCheckedChangeListener { group, checkedId ->
submitButton.isEnabled = true
showOrHideCustomReasonInput(checkedId)
}

submitButton.setOnClickListener {
when (spamReasons.checkedRadioButtonId) {
-1 -> Toast.makeText(this, "No option selected", Toast.LENGTH_LONG).show()
R.id.customReason -> {
if (commentBox.text.toString().length < 10) {
Toast.makeText(
this,
"Please enter atleast 10 characters",
Toast.LENGTH_LONG
).show()
} else {
reportForumThread(commentBox.text.toString())
}
}
else -> {
val selectedReason = findViewById<RadioButton>(spamReasons.checkedRadioButtonId)
reportForumThread(selectedReason.text.toString())
}
}
}
}

private fun showOrHideCustomReasonInput(checkedId: Int) {
if (checkedId == R.id.customReason) {
commentBox.visibility = View.VISIBLE
} else {
commentBox.visibility = View.GONE
}
}

fun reportForumThread(reason: String) {
val forumId = intent.getIntExtra("forum_id", -1)
object : SafeAsyncTask<Boolean>() {
override fun call(): Boolean {
serviceProvider.getService(this@ReportForumThread).reportPost(
forumId,
reason
)
return true
}

@Throws(RuntimeException::class)
override fun onException(exception: Exception) {
exception.printStackTrace()
Toast.makeText(
baseContext,
"You have already reported this post",
Toast.LENGTH_LONG
).show()
}

override fun onSuccess(t: Boolean?) {
onBackPressed()
Toast.makeText(
baseContext,
"You have successfully reported this post",
Toast.LENGTH_LONG
).show()
}
}.execute()
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/color/button_text_states.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="#9D9FA2" />
<item android:color="@color/testpress_color_primary"/>
</selector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_baseline_flag_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M14.4,6L14,4H5v17h2v-7h5.6l0.4,2h7V6z"/>
</vector>
4 changes: 2 additions & 2 deletions app/src/main/res/drawable/rounded_border_edittext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<item>
<shape android:shape="rectangle">
<solid android:color="@color/light_grey"/>
<corners android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
<corners android:bottomRightRadius="5dp"
android:bottomLeftRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />
</shape>
Expand Down
73 changes: 73 additions & 0 deletions app/src/main/res/layout/bottom_sheet_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:paddingBottom="30dp"
android:paddingTop="30dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_height="match_parent">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/report_desc"
android:textSize="16sp"
android:layout_marginBottom="10dp"
android:text="I am flagging to report this discussion as.. "
/>
<RadioGroup
android:id="@+id/reportForum"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Graphic violence"/>

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hateful or abusive content" />

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Off-Topic"/>

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Inappropriate"/>

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Spam"/>

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/customReason"
android:text="Something else"/>

</RadioGroup>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/comment_box"
android:inputType="text|textMultiLine"
android:textSize="16sp"
android:visibility="gone"
android:textColor="#000"
style="@style/Input"
android:hint="Describe your reason" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:id="@+id/reportButton"
android:text="Report"/>
</LinearLayout>
Loading