From 9dceb7a226ce6e664572f3f5c138d2399259a62a Mon Sep 17 00:00:00 2001 From: Vavassor Date: Sun, 26 Feb 2017 19:14:50 -0500 Subject: [PATCH] TODO's have been erradicated. --- README.md | 2 +- .../keylesspalace/tusky/AccountActivity.java | 19 ++++++---- .../keylesspalace/tusky/LoginActivity.java | 24 +++--------- .../com/keylesspalace/tusky/MainActivity.java | 1 - .../tusky/PullNotificationService.java | 1 - .../com/keylesspalace/tusky/SFragment.java | 27 ++++++++------ .../tusky/ViewThreadFragment.java | 37 ++++++++++++++----- app/src/main/res/layout/item_blocked_user.xml | 5 ++- app/src/main/res/values/strings.xml | 6 ++- 9 files changed, 69 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index a129162a..c64fd013 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This is an android client for [Mastodon, a GNU Social-compatible microblogging server](https://mastodon.social). Presently, it is in active development and its current state does not represent the features or design of the final program. -It is currently available for alpha testing on the [Tusky Google Play store page](https://play.google.com/store/apps/details?id=com.keylesspalace.tusky). +It is currently available for alpha testing on the Tusky [Google Play store page](https://play.google.com/store/apps/details?id=com.keylesspalace.tusky). You can also find it on F-Droid or at its [F-Droid page](https://f-droid.org/repository/browse/?fdid=com.keylesspalace.tusky). Also, [my mastodon account is Vavassor@mastodon.social](https://mastodon.social/users/Vavassor). diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java index 32d05ac3..a5faefe9 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java @@ -210,8 +210,14 @@ public class AccountActivity extends BaseActivity { } private void onObtainAccountFailure() { - //TODO: help - Log.e(TAG, "Failed to obtain that account."); + Snackbar.make(tabLayout, R.string.error_obtain_account, Snackbar.LENGTH_LONG) + .setAction(R.string.action_retry, new View.OnClickListener() { + @Override + public void onClick(View v) { + obtainAccount(); + } + }) + .show(); } private void obtainRelationships() { @@ -228,7 +234,7 @@ public class AccountActivity extends BaseActivity { following = object.getBoolean("following"); blocking = object.getBoolean("blocking"); } catch (JSONException e) { - onObtainRelationshipsFailure(); + onObtainRelationshipsFailure(e); return; } onObtainRelationshipsSuccess(following, blocking); @@ -237,7 +243,7 @@ public class AccountActivity extends BaseActivity { new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { - onObtainRelationshipsFailure(); + onObtainRelationshipsFailure(error); } }) { @Override @@ -259,9 +265,8 @@ public class AccountActivity extends BaseActivity { } } - private void onObtainRelationshipsFailure() { - //TODO: help - Log.e(TAG, "Could not obtain relationships?"); + private void onObtainRelationshipsFailure(Exception exception) { + Log.e(TAG, "Could not obtain relationships. " + exception.getMessage()); } @Override diff --git a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java index aa320796..88c042b3 100644 --- a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java @@ -37,7 +37,6 @@ import org.json.JSONException; import org.json.JSONObject; import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; import java.util.HashMap; import java.util.Map; @@ -54,15 +53,14 @@ public class LoginActivity extends BaseActivity { * Chain together the key-value pairs into a query string, for either appending to a URL or * as the content of an HTTP request. */ - private String toQueryString(Map parameters) - throws UnsupportedEncodingException { + private String toQueryString(Map parameters) { StringBuilder s = new StringBuilder(); String between = ""; for (Map.Entry entry : parameters.entrySet()) { s.append(between); - s.append(URLEncoder.encode(entry.getKey(), "UTF-8")); + s.append(entry.getKey()); s.append("="); - s.append(URLEncoder.encode(entry.getValue(), "UTF-8")); + s.append(entry.getValue()); between = "&"; } return s.toString(); @@ -91,15 +89,7 @@ public class LoginActivity extends BaseActivity { parameters.put("redirect_uri", redirectUri); parameters.put("response_type", "code"); parameters.put("scope", OAUTH_SCOPES); - String queryParameters; - try { - queryParameters = toQueryString(parameters); - } catch (UnsupportedEncodingException e) { - //TODO: No clue how to handle this error case?? - Log.e(TAG, "Was not able to build the authorization URL."); - return; - } - String url = "https://" + domain + endpoint + "?" + queryParameters; + String url = "https://" + domain + endpoint + "?" + toQueryString(parameters); Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse(url)); startActivity(viewIntent); } @@ -269,9 +259,8 @@ public class LoginActivity extends BaseActivity { parameters.put("code", code); parameters.put("grant_type", "authorization_code"); } catch (JSONException e) { - errorText.setText("Heck."); + errorText.setText(e.getMessage()); return; - //TODO: I don't even know how to handle this error state. } String endpoint = getString(R.string.endpoint_token); String url = "https://" + domain + endpoint; @@ -284,9 +273,8 @@ public class LoginActivity extends BaseActivity { try { accessToken = response.getString("access_token"); } catch(JSONException e) { - errorText.setText("Heck."); + errorText.setText(e.getMessage()); return; - //TODO: I don't even know how to handle this error state. } onLoginSuccess(accessToken); } diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java index 5e9201de..38f90c93 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java @@ -158,7 +158,6 @@ public class MainActivity extends BaseActivity { } private void onFetchUserInfoFailure(Exception exception) { - //TODO: help Log.e(TAG, "Failed to fetch user info. " + exception.getMessage()); } diff --git a/app/src/main/java/com/keylesspalace/tusky/PullNotificationService.java b/app/src/main/java/com/keylesspalace/tusky/PullNotificationService.java index 6cad1c17..d562275a 100644 --- a/app/src/main/java/com/keylesspalace/tusky/PullNotificationService.java +++ b/app/src/main/java/com/keylesspalace/tusky/PullNotificationService.java @@ -142,7 +142,6 @@ public class PullNotificationService extends IntentService { } private void onCheckNotificationsFailure(Exception exception) { - //TODO: not sure if just logging here is enough? Log.e(TAG, "Failed to check notifications. " + exception.getMessage()); } diff --git a/app/src/main/java/com/keylesspalace/tusky/SFragment.java b/app/src/main/java/com/keylesspalace/tusky/SFragment.java index 7f9e1767..ede25fbe 100644 --- a/app/src/main/java/com/keylesspalace/tusky/SFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/SFragment.java @@ -74,7 +74,8 @@ public class SFragment extends Fragment { protected void sendRequest( int method, String endpoint, JSONObject parameters, - @Nullable Response.Listener responseListener) { + @Nullable Response.Listener responseListener, + @Nullable Response.ErrorListener errorListener) { if (responseListener == null) { // Use a dummy listener if one wasn't specified so the request can be constructed. responseListener = new Response.Listener() { @@ -82,15 +83,17 @@ public class SFragment extends Fragment { public void onResponse(JSONObject response) {} }; } + if (errorListener == null) { + errorListener = new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + Log.e(TAG, "Request Failed: " + error.getMessage()); + } + }; + } String url = "https://" + domain + endpoint; JsonObjectRequest request = new JsonObjectRequest( - method, url, parameters, responseListener, - new Response.ErrorListener() { - @Override - public void onErrorResponse(VolleyError error) { - Log.e(TAG, "Request Failed: " + error.getMessage()); - } - }) { + method, url, parameters, responseListener, errorListener) { @Override public Map getHeaders() throws AuthFailureError { Map headers = new HashMap<>(); @@ -103,7 +106,7 @@ public class SFragment extends Fragment { } protected void postRequest(String endpoint) { - sendRequest(Request.Method.POST, endpoint, null, null); + sendRequest(Request.Method.POST, endpoint, null, null, null); } protected void reply(Status status) { @@ -137,7 +140,7 @@ public class SFragment extends Fragment { status.setReblogged(reblog); adapter.notifyItemChanged(position); } - }); + }, null); } protected void favourite(final Status status, final boolean favourite, @@ -155,7 +158,7 @@ public class SFragment extends Fragment { status.setFavourited(favourite); adapter.notifyItemChanged(position); } - }); + }, null); } private void follow(String id) { @@ -170,7 +173,7 @@ public class SFragment extends Fragment { private void delete(String id) { String endpoint = String.format(getString(R.string.endpoint_delete), id); - sendRequest(Request.Method.DELETE, endpoint, null, null); + sendRequest(Request.Method.DELETE, endpoint, null, null, null); } protected void more(Status status, View view, final AdapterItemRemover adapter, diff --git a/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java b/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java index d3aeebb3..546ab74d 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java @@ -19,6 +19,7 @@ import android.content.Context; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.design.widget.Snackbar; import android.support.v4.content.ContextCompat; import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; @@ -29,6 +30,7 @@ import android.view.ViewGroup; import com.android.volley.Request; import com.android.volley.Response; +import com.android.volley.VolleyError; import org.json.JSONException; import org.json.JSONObject; @@ -36,8 +38,6 @@ import org.json.JSONObject; import java.util.List; public class ViewThreadFragment extends SFragment implements StatusActionListener { - private static final String TAG = "ViewThread"; // logging tag - private RecyclerView recyclerView; private ThreadAdapter adapter; @@ -75,7 +75,7 @@ public class ViewThreadFragment extends SFragment implements StatusActionListene return rootView; } - private void sendStatusRequest(String id) { + private void sendStatusRequest(final String id) { String endpoint = String.format(getString(R.string.endpoint_get_status), id); super.sendRequest(Request.Method.GET, endpoint, null, new Response.Listener() { @@ -85,16 +85,22 @@ public class ViewThreadFragment extends SFragment implements StatusActionListene try { status = Status.parse(response, false); } catch (JSONException e) { - onThreadRequestFailure(); + onThreadRequestFailure(id); return; } int position = adapter.insertStatus(status); recyclerView.scrollToPosition(position); } + }, + new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + onThreadRequestFailure(id); + } }); } - private void sendThreadRequest(String id) { + private void sendThreadRequest(final String id) { String endpoint = String.format(getString(R.string.endpoint_context), id); super.sendRequest(Request.Method.GET, endpoint, null, new Response.Listener() { @@ -108,15 +114,28 @@ public class ViewThreadFragment extends SFragment implements StatusActionListene adapter.addAncestors(ancestors); adapter.addDescendants(descendants); } catch (JSONException e) { - onThreadRequestFailure(); + onThreadRequestFailure(id); } } + }, + new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + onThreadRequestFailure(id); + } }); } - private void onThreadRequestFailure() { - Log.e(TAG, "The request to fetch the thread has failed."); - //TODO: no + private void onThreadRequestFailure(final String id) { + Snackbar.make(recyclerView, R.string.error_view_thread, Snackbar.LENGTH_LONG) + .setAction(R.string.action_retry, new View.OnClickListener() { + @Override + public void onClick(View v) { + sendThreadRequest(id); + sendStatusRequest(id); + } + }) + .show(); } public void onReply(int position) { diff --git a/app/src/main/res/layout/item_blocked_user.xml b/app/src/main/res/layout/item_blocked_user.xml index 6ee406fe..90c7f56e 100644 --- a/app/src/main/res/layout/item_blocked_user.xml +++ b/app/src/main/res/layout/item_blocked_user.xml @@ -26,7 +26,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/blocked_user_display_name" - android:text="Display Name" /> + android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small" + android:textStyle="normal|bold" /> + android:textColor="?attr/status_text_color_secondary" /> That user wasn\'t unfollowed. That user wasn\'t blocked. That user wasn\'t unblocked. + Couldn\'t fetch that thread. + Failed to obtain that account. Home Notifications @@ -86,7 +88,7 @@ %s followed you Compose - Log In + Ask Site To Log In Log Out Follow Unfollow @@ -110,7 +112,7 @@ Toot! - example.com + Which Site? What\'s Happening? Beware, folks