Reporting statuses is now possible!
This commit is contained in:
parent
0a32c58801
commit
4b8573a82f
15 changed files with 273 additions and 6 deletions
|
@ -39,6 +39,9 @@
|
|||
<activity android:name=".PreferencesActivity" />
|
||||
<activity android:name=".FavouritesActivity" />
|
||||
<activity android:name=".BlocksActivity" />
|
||||
<activity
|
||||
android:name=".ReportActivity"
|
||||
android:windowSoftInputMode="stateVisible|adjustResize" />
|
||||
<service
|
||||
android:name=".PullNotificationService"
|
||||
android:description="@string/notification_service_description"
|
||||
|
|
|
@ -37,6 +37,7 @@ import android.os.Bundle;
|
|||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.provider.OpenableColumns;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
|
@ -363,6 +364,9 @@ public class ComposeActivity extends BaseActivity {
|
|||
waitForMediaLatch = new CountUpDownLatch();
|
||||
|
||||
contentWarningBar = findViewById(R.id.compose_content_warning_bar);
|
||||
@DrawableRes int drawableId = ThemeUtils.getDrawableId(this,
|
||||
R.attr.compose_content_warning_bar_background, R.drawable.border_background_dark);
|
||||
contentWarningBar.setBackgroundResource(drawableId);
|
||||
final EditText contentWarningEditor = (EditText) findViewById(R.id.field_content_warning);
|
||||
showContentWarning(false);
|
||||
|
||||
|
|
|
@ -39,4 +39,14 @@ class HtmlUtils {
|
|||
* all status contents do, so it should be trimmed. */
|
||||
return (Spanned) trimTrailingWhitespace(result);
|
||||
}
|
||||
|
||||
static String toHtml(Spanned text) {
|
||||
String result;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
result = Html.toHtml(text, Html.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE);
|
||||
} else {
|
||||
result = Html.toHtml(text);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
158
app/src/main/java/com/keylesspalace/tusky/ReportActivity.java
Normal file
158
app/src/main/java/com/keylesspalace/tusky/ReportActivity.java
Normal file
|
@ -0,0 +1,158 @@
|
|||
/* Copyright 2017 Andrew Dawson
|
||||
*
|
||||
* This file is part of Tusky.
|
||||
*
|
||||
* Tusky is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Tusky. If not, see
|
||||
* <http://www.gnu.org/licenses/>. */
|
||||
|
||||
package com.keylesspalace.tusky;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.AuthFailureError;
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.android.volley.toolbox.JsonObjectRequest;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ReportActivity extends BaseActivity {
|
||||
private static final String TAG = "ReportActivity"; // Volley request tag
|
||||
|
||||
private String domain;
|
||||
private String accessToken;
|
||||
private View anyView; // what Snackbar will use to find the root view
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_report);
|
||||
|
||||
Intent intent = getIntent();
|
||||
final String accountId = intent.getStringExtra("account_id");
|
||||
String accountUsername = intent.getStringExtra("account_username");
|
||||
final String statusId = intent.getStringExtra("status_id");
|
||||
String statusContent = intent.getStringExtra("status_content");
|
||||
|
||||
SharedPreferences preferences = getSharedPreferences(
|
||||
getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
|
||||
domain = preferences.getString("domain", null);
|
||||
accessToken = preferences.getString("accessToken", null);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
ActionBar bar = getSupportActionBar();
|
||||
if (bar != null) {
|
||||
String title = String.format(getString(R.string.report_username_format),
|
||||
accountUsername);
|
||||
bar.setTitle(title);
|
||||
}
|
||||
anyView = toolbar;
|
||||
|
||||
TextView content = (TextView) findViewById(R.id.report_status_content);
|
||||
content.setText(HtmlUtils.fromHtml(statusContent));
|
||||
|
||||
final EditText comment = (EditText) findViewById(R.id.report_comment);
|
||||
Button send = (Button) findViewById(R.id.report_send);
|
||||
send.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String[] statusIds = new String[] { statusId };
|
||||
sendReport(accountId, statusIds, comment.getText().toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* JSONArray has a constructor to take primitive arrays but it's restricted to API level 19 and
|
||||
* above, so this is an alternative. */
|
||||
private static JSONArray makeStringArrayCompat(String[] stringArray) throws JSONException {
|
||||
JSONArray result = new JSONArray();
|
||||
for (int i = 0; i < stringArray.length; i++) {
|
||||
result.put(i, stringArray[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void sendReport(final String accountId, final String[] statusIds,
|
||||
final String comment) {
|
||||
JSONObject parameters = new JSONObject();
|
||||
try {
|
||||
parameters.put("account_id", accountId);
|
||||
parameters.put("status_ids", makeStringArrayCompat(statusIds));
|
||||
parameters.put("comment", comment);
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, "Not all the report parameters have been properly set. "
|
||||
+ e.getMessage());
|
||||
onSendFailure(accountId, statusIds, comment);
|
||||
return;
|
||||
}
|
||||
String endpoint = getString(R.string.endpoint_reports);
|
||||
String url = "https://" + domain + endpoint;
|
||||
JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, parameters,
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
onSendSuccess();
|
||||
}
|
||||
},
|
||||
new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
onSendFailure(accountId, statusIds, comment);
|
||||
}
|
||||
}) {
|
||||
@Override
|
||||
public Map<String, String> getHeaders() throws AuthFailureError {
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Authorization", "Bearer " + accessToken);
|
||||
return headers;
|
||||
}
|
||||
};
|
||||
request.setTag(TAG);
|
||||
VolleySingleton.getInstance(this).addToRequestQueue(request);
|
||||
}
|
||||
|
||||
private void onSendSuccess() {
|
||||
Toast.makeText(this, getString(R.string.confirmation_reported), Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
finish();
|
||||
}
|
||||
|
||||
private void onSendFailure(final String accountId, final String[] statusIds,
|
||||
final String comment) {
|
||||
Snackbar.make(anyView, R.string.error_report_unsent, Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.action_retry, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
sendReport(accountId, statusIds, comment);
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ import android.support.v4.app.Fragment;
|
|||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Spanned;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
|
@ -180,6 +181,8 @@ public class SFragment extends Fragment {
|
|||
final int position) {
|
||||
final String id = status.getId();
|
||||
final String accountId = status.getAccountId();
|
||||
final String accountUsename = status.getUsername();
|
||||
final Spanned content = status.getContent();
|
||||
PopupMenu popup = new PopupMenu(getContext(), view);
|
||||
// Give a different menu depending on whether this is the user's own toot or not.
|
||||
if (loggedInAccountId == null || !loggedInAccountId.equals(accountId)) {
|
||||
|
@ -200,6 +203,10 @@ public class SFragment extends Fragment {
|
|||
block(accountId);
|
||||
return true;
|
||||
}
|
||||
case R.id.status_report: {
|
||||
openReportPage(accountId, accountUsename, id, content);
|
||||
return true;
|
||||
}
|
||||
case R.id.status_delete: {
|
||||
delete(id);
|
||||
adapter.removeItem(position);
|
||||
|
@ -266,4 +273,14 @@ public class SFragment extends Fragment {
|
|||
intent.putExtra("username", username);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
protected void openReportPage(String accountId, String accoundUsername, String statusId,
|
||||
Spanned statusContent) {
|
||||
Intent intent = new Intent(getContext(), ReportActivity.class);
|
||||
intent.putExtra("account_id", accountId);
|
||||
intent.putExtra("account_username", accoundUsername);
|
||||
intent.putExtra("status_id", statusId);
|
||||
intent.putExtra("status_content", HtmlUtils.toHtml(statusContent));
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,14 +18,18 @@ package com.keylesspalace.tusky;
|
|||
import android.content.Context;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.AttrRes;
|
||||
import android.support.annotation.ColorRes;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.TypedValue;
|
||||
import android.widget.ImageView;
|
||||
|
||||
class ThemeUtils {
|
||||
static Drawable getDrawable(Context context, int attribute, int fallbackDrawable) {
|
||||
static Drawable getDrawable(Context context, @AttrRes int attribute,
|
||||
@DrawableRes int fallbackDrawable) {
|
||||
TypedValue value = new TypedValue();
|
||||
int resourceId;
|
||||
@DrawableRes int resourceId;
|
||||
if (context.getTheme().resolveAttribute(attribute, value, true)) {
|
||||
resourceId = value.resourceId;
|
||||
} else {
|
||||
|
@ -34,7 +38,8 @@ class ThemeUtils {
|
|||
return ContextCompat.getDrawable(context, resourceId);
|
||||
}
|
||||
|
||||
static int getDrawableId(Context context, int attribute, int fallbackDrawableId) {
|
||||
static @DrawableRes int getDrawableId(Context context, @AttrRes int attribute,
|
||||
@DrawableRes int fallbackDrawableId) {
|
||||
TypedValue value = new TypedValue();
|
||||
if (context.getTheme().resolveAttribute(attribute, value, true)) {
|
||||
return value.resourceId;
|
||||
|
@ -43,7 +48,7 @@ class ThemeUtils {
|
|||
}
|
||||
}
|
||||
|
||||
static int getColor(Context context, int attribute) {
|
||||
static @ColorRes int getColor(Context context, @AttrRes int attribute) {
|
||||
TypedValue value = new TypedValue();
|
||||
if (context.getTheme().resolveAttribute(attribute, value, true)) {
|
||||
return value.data;
|
||||
|
@ -52,7 +57,7 @@ class ThemeUtils {
|
|||
}
|
||||
}
|
||||
|
||||
static void setImageViewTint(ImageView view, int attribute) {
|
||||
static void setImageViewTint(ImageView view, @AttrRes int attribute) {
|
||||
view.setColorFilter(getColor(view.getContext(), attribute), PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
}
|
||||
|
|
5
app/src/main/res/drawable/border_background_dark.xml
Normal file
5
app/src/main/res/drawable/border_background_dark.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners android:radius="3dp" />
|
||||
<stroke android:color="#ffffffff" android:width="1dp" />
|
||||
</shape>
|
|
@ -33,7 +33,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/compose_content_warning_bar"
|
||||
android:background="@drawable/border_background"
|
||||
android:layout_margin="8dp"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="8dp">
|
||||
|
|
49
app/src/main/res/layout/activity_report.xml
Normal file
49
app/src/main/res/layout/activity_report.xml
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?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:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:elevation="4dp"
|
||||
android:background="?attr/toolbar_background_color" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/report_status_content"
|
||||
android:padding="8dp"
|
||||
android:background="?attr/report_status_background_color" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:id="@+id/report_comment"
|
||||
android:inputType="textMultiLine"
|
||||
android:gravity="top|start"
|
||||
android:ems="10"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:hint="@string/report_comment_hint" />
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="8dp" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:id="@+id/report_send"
|
||||
android:text="@string/action_report" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -5,4 +5,6 @@
|
|||
android:title="@string/action_follow" />
|
||||
<item android:title="@string/action_block"
|
||||
android:id="@+id/status_block" />
|
||||
<item android:title="@string/action_report"
|
||||
android:id="@+id/status_report" />
|
||||
</menu>
|
|
@ -31,5 +31,7 @@
|
|||
<attr name="compose_media_button_tint" format="reference|color" />
|
||||
<attr name="compose_media_button_disabled_tint" format="reference|color" />
|
||||
<attr name="compose_mention_color" format="reference|color" />
|
||||
<attr name="compose_content_warning_bar_background" format="reference" />
|
||||
<attr name="report_status_background_color" format="reference|color" />
|
||||
|
||||
</resources>
|
|
@ -36,6 +36,7 @@
|
|||
<color name="compose_mention_dark">#AFBFCF</color>
|
||||
<color name="notification_content_faded_dark">#9F9F9F</color>
|
||||
<color name="notification_icon_tint_dark">#CFCFCF</color>
|
||||
<color name="report_status_background_dark">#000000</color>
|
||||
<!--Light Theme Colors-->
|
||||
<color name="color_primary_light">#44A673</color>
|
||||
<color name="color_primary_dark_light">#2C996E</color>
|
||||
|
@ -69,4 +70,5 @@
|
|||
<color name="compose_mention_light">#2F5F6F</color>
|
||||
<color name="notification_content_faded_light">#7F7F7F</color>
|
||||
<color name="notification_icon_tint_light">#1F1F1F</color>
|
||||
<color name="report_status_background_light">#EFEFEF</color>
|
||||
</resources>
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
<string name="endpoint_unfollow">/api/v1/accounts/%s/unfollow</string>
|
||||
<string name="endpoint_block">/api/v1/accounts/%s/block</string>
|
||||
<string name="endpoint_unblock">/api/v1/accounts/%s/unblock</string>
|
||||
<string name="endpoint_reports">/api/v1/reports</string>
|
||||
<string name="endpoint_apps">/api/v1/apps</string>
|
||||
<string name="endpoint_authorize">/oauth/authorize</string>
|
||||
<string name="endpoint_token">/oauth/token</string>
|
||||
|
@ -57,6 +58,7 @@
|
|||
<string name="error_unblocking">That user wasn\'t unblocked.</string>
|
||||
<string name="error_view_thread">Couldn\'t fetch that thread.</string>
|
||||
<string name="error_obtain_account">Failed to obtain that account.</string>
|
||||
<string name="error_report_unsent">The report could not be sent.</string>
|
||||
|
||||
<string name="title_home">Home</string>
|
||||
<string name="title_notifications">Notifications</string>
|
||||
|
@ -87,6 +89,9 @@
|
|||
<string name="notification_favourite_format">%s favourited your status</string>
|
||||
<string name="notification_follow_format">%s followed you</string>
|
||||
|
||||
<string name="report_username_format">Reporting @%s</string>
|
||||
<string name="report_comment_hint">Additional Comments?</string>
|
||||
|
||||
<string name="action_compose">Compose</string>
|
||||
<string name="action_login">Ask Site To Log In</string>
|
||||
<string name="action_logout">Log Out</string>
|
||||
|
@ -94,6 +99,7 @@
|
|||
<string name="action_unfollow">Unfollow</string>
|
||||
<string name="action_block">Block</string>
|
||||
<string name="action_unblock">Unblock</string>
|
||||
<string name="action_report">Report</string>
|
||||
<string name="action_delete">Delete</string>
|
||||
<string name="action_send">TOOT</string>
|
||||
<string name="action_retry">Retry</string>
|
||||
|
@ -111,6 +117,7 @@
|
|||
<string name="action_set_time">Set</string>
|
||||
|
||||
<string name="confirmation_send">Toot!</string>
|
||||
<string name="confirmation_reported">Sent!</string>
|
||||
|
||||
<string name="hint_domain">Which Site?</string>
|
||||
<string name="hint_compose">What\'s Happening?</string>
|
||||
|
|
|
@ -46,8 +46,10 @@
|
|||
<item name="compose_media_button_tint">@color/compose_media_button_dark</item>
|
||||
<item name="compose_media_button_disabled_tint">@color/compose_media_button_disabled_dark</item>
|
||||
<item name="compose_mention_color">@color/compose_mention_dark</item>
|
||||
<item name="compose_content_warning_bar_background">@drawable/border_background_dark</item>
|
||||
<item name="notification_content">@color/notification_content_faded_dark</item>
|
||||
<item name="notification_icon_tint">@color/notification_icon_tint_dark</item>
|
||||
<item name="report_status_background_color">@color/report_status_background_dark</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.ImageButton.Dark" parent="@style/Widget.AppCompat.Button.Borderless.Colored">
|
||||
|
@ -97,8 +99,10 @@
|
|||
<item name="compose_media_button_tint">@color/compose_media_button_light</item>
|
||||
<item name="compose_media_button_disabled_tint">@color/compose_media_button_disabled_light</item>
|
||||
<item name="compose_mention_color">@color/compose_mention_light</item>
|
||||
<item name="compose_content_warning_bar_background">@drawable/border_background_light</item>
|
||||
<item name="notification_content">@color/notification_content_faded_light</item>
|
||||
<item name="notification_icon_tint">@color/notification_icon_tint_light</item>
|
||||
<item name="report_status_background_color">@color/report_status_background_light</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.ImageButton.Light" parent="Widget.AppCompat.Button.Borderless.Colored">
|
||||
|
|
Loading…
Reference in a new issue