From dd68e79a93180107b2c7ef5a765f917a4b7821a8 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 13 Mar 2017 15:41:17 +0100 Subject: [PATCH 1/3] Removed google-services.json from repository --- app/.gitignore | 3 ++- .../keylesspalace/tusky/ConversationLineItemDecoration.java | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/.gitignore b/app/.gitignore index e493cfc4..7c176a4e 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1,2 +1,3 @@ /build -app-release.apk \ No newline at end of file +app-release.apk +google-services.json diff --git a/app/src/main/java/com/keylesspalace/tusky/ConversationLineItemDecoration.java b/app/src/main/java/com/keylesspalace/tusky/ConversationLineItemDecoration.java index 9dbce756..6c156541 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ConversationLineItemDecoration.java +++ b/app/src/main/java/com/keylesspalace/tusky/ConversationLineItemDecoration.java @@ -21,8 +21,6 @@ class ConversationLineItemDecoration extends RecyclerView.ItemDecoration { @Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { - // Fun fact: this method draws in pixels, but all layouts are in DP, so I'm using the divider's - // own 2dp width to calculate what I want int dividerLeft = parent.getPaddingLeft() + mContext.getResources().getDimensionPixelSize(R.dimen.status_left_line_margin); int dividerRight = dividerLeft + mDivider.getIntrinsicWidth(); From 9fdd14b722a62403e2e35dcd8e25feb84b95cd2a Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 13 Mar 2017 16:19:34 +0100 Subject: [PATCH 2/3] Rounded corners on avatars in statuses --- .../tusky/MyFirebaseMessagingService.java | 1 + .../tusky/RoundedTransformation.java | 45 +++++++++++++++++++ .../keylesspalace/tusky/StatusViewHolder.java | 1 + app/src/main/res/layout/item_status.xml | 2 +- 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/keylesspalace/tusky/RoundedTransformation.java diff --git a/app/src/main/java/com/keylesspalace/tusky/MyFirebaseMessagingService.java b/app/src/main/java/com/keylesspalace/tusky/MyFirebaseMessagingService.java index 31060869..785f02e0 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MyFirebaseMessagingService.java +++ b/app/src/main/java/com/keylesspalace/tusky/MyFirebaseMessagingService.java @@ -160,6 +160,7 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService { Picasso.with(this) .load(body.account.avatar) .placeholder(R.drawable.avatar_default) + .transform(new RoundedTransformation(7, 0)) .into(mTarget); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { diff --git a/app/src/main/java/com/keylesspalace/tusky/RoundedTransformation.java b/app/src/main/java/com/keylesspalace/tusky/RoundedTransformation.java new file mode 100644 index 00000000..0ac1a4ac --- /dev/null +++ b/app/src/main/java/com/keylesspalace/tusky/RoundedTransformation.java @@ -0,0 +1,45 @@ +package com.keylesspalace.tusky; + +import android.graphics.Bitmap; +import android.graphics.BitmapShader; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.RectF; +import android.graphics.Shader; + +import com.squareup.picasso.Transformation; + +public class RoundedTransformation implements Transformation { + + private final int radius; + private final int margin; + + public RoundedTransformation(final int radius, final int margin) { + this.radius = radius; + this.margin = margin; + } + + @Override + public Bitmap transform(Bitmap source) { + final Paint paint = new Paint(); + + paint.setAntiAlias(true); + paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); + + Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(output); + + canvas.drawRoundRect(new RectF(margin, margin, source.getWidth() - margin, source.getHeight() - margin), radius, radius, paint); + + if (source != output) { + source.recycle(); + } + + return output; + } + + @Override + public String key() { + return "rounded"; + } +} diff --git a/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java index 35168d04..619b187c 100644 --- a/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java @@ -158,6 +158,7 @@ class StatusViewHolder extends RecyclerView.ViewHolder { .load(url) .placeholder(R.drawable.avatar_default) .error(R.drawable.avatar_error) + .transform(new RoundedTransformation(7, 0)) .into(avatar); } diff --git a/app/src/main/res/layout/item_status.xml b/app/src/main/res/layout/item_status.xml index b6bde113..5525477f 100644 --- a/app/src/main/res/layout/item_status.xml +++ b/app/src/main/res/layout/item_status.xml @@ -40,7 +40,7 @@ android:scaleType="fitCenter" android:id="@+id/status_avatar" android:layout_below="@+id/status_reblogged_bar" - android:layout_marginTop="10dp" + android:layout_marginTop="11dp" android:layout_marginRight="10dp" /> Date: Mon, 13 Mar 2017 19:13:49 +0100 Subject: [PATCH 3/3] Fix usage of Retrofit in LoginActivity - baseUrl wasn't being set correctly since BaseActivity relies on the already saved preference LoginActivity instantiated its own, trimmed down MastodonAPI instance --- .../com/keylesspalace/tusky/LoginActivity.java | 17 +++++++++++++---- .../com/keylesspalace/tusky/MastodonAPI.java | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java index 32b3374f..07758956 100644 --- a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java @@ -39,6 +39,8 @@ import java.util.Map; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; +import retrofit2.Retrofit; +import retrofit2.converter.gson.GsonConverterFactory; public class LoginActivity extends BaseActivity { private static String OAUTH_SCOPES = "read write follow"; @@ -94,6 +96,15 @@ public class LoginActivity extends BaseActivity { startActivity(viewIntent); } + private MastodonAPI getApiFor(String domain) { + Retrofit retrofit = new Retrofit.Builder() + .baseUrl("https://" + domain) + .addConverterFactory(GsonConverterFactory.create()) + .build(); + + return retrofit.create(MastodonAPI.class); + } + /** * Obtain the oauth client credentials for this app. This is only necessary the first time the * app is run on a given server instance. So, after the first authentication, they are @@ -134,9 +145,7 @@ public class LoginActivity extends BaseActivity { } }; - List redirectUris = new ArrayList<>(); - redirectUris.add(getOauthRedirectUri()); - mastodonAPI.authenticateApp(getString(R.string.app_name), redirectUris, OAUTH_SCOPES, + getApiFor(domain).authenticateApp(getString(R.string.app_name), getOauthRedirectUri(), OAUTH_SCOPES, getString(R.string.app_website)).enqueue(callback); } @@ -245,7 +254,7 @@ public class LoginActivity extends BaseActivity { editText.setError(t.getMessage()); } }; - mastodonAPI.fetchOAuthToken(clientId, clientSecret, redirectUri, code, + getApiFor(domain).fetchOAuthToken(clientId, clientSecret, redirectUri, code, "authorization_code").enqueue(callback); } else if (error != null) { /* Authorization failed. Put the error response where the user can read it and they diff --git a/app/src/main/java/com/keylesspalace/tusky/MastodonAPI.java b/app/src/main/java/com/keylesspalace/tusky/MastodonAPI.java index e881f996..da42829f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MastodonAPI.java +++ b/app/src/main/java/com/keylesspalace/tusky/MastodonAPI.java @@ -175,7 +175,7 @@ public interface MastodonAPI { @POST("api/v1/apps") Call authenticateApp( @Field("client_name") String clientName, - @Field("redirect_uris[]") List redirectUris, + @Field("redirect_uris") String redirectUris, @Field("scopes") String scopes, @Field("website") String website);