Merge branch 'Gargron-master'

This commit is contained in:
Vavassor 2017-03-13 14:49:40 -04:00
commit 64da1329b9
9 changed files with 74 additions and 19 deletions

3
app/.gitignore vendored
View file

@ -1,2 +1,3 @@
/build /build
app-release.apk app-release.apk
google-services.json

View file

@ -1,35 +1,35 @@
{ {
"project_info": { "project_info": {
"project_number": "268851337880", "project_number": "1050186150447",
"firebase_url": "https://tusky-62772.firebaseio.com", "firebase_url": "https://tusky-fc880.firebaseio.com",
"project_id": "tusky-62772", "project_id": "tusky-fc880",
"storage_bucket": "tusky-62772.appspot.com" "storage_bucket": "tusky-fc880.appspot.com"
}, },
"client": [ "client": [
{ {
"client_info": { "client_info": {
"mobilesdk_app_id": "1:268851337880:android:fc4111b1d145a00e", "mobilesdk_app_id": "1:1050186150447:android:fc4111b1d145a00e",
"android_client_info": { "android_client_info": {
"package_name": "com.keylesspalace.tusky" "package_name": "com.keylesspalace.tusky"
} }
}, },
"oauth_client": [ "oauth_client": [
{ {
"client_id": "268851337880-eie2ssto2d21bfihn9d1qupcrke8oebf.apps.googleusercontent.com", "client_id": "1050186150447-fg4nj4vlekpa9bcl8q8290hqln1s048e.apps.googleusercontent.com",
"client_type": 1, "client_type": 1,
"android_info": { "android_info": {
"package_name": "com.keylesspalace.tusky", "package_name": "com.keylesspalace.tusky",
"certificate_hash": "18d196307d6e928e99c2e0bb9818c01c38aff2f9" "certificate_hash": "a3bb387437e149dd7763107e8da83ad6b421264f"
} }
}, },
{ {
"client_id": "268851337880-n19d05m282nirs1fc9kdd5n4of6je4fk.apps.googleusercontent.com", "client_id": "1050186150447-4u9m96ub04cuppmnkfdk7ua51o9r7pf3.apps.googleusercontent.com",
"client_type": 3 "client_type": 3
} }
], ],
"api_key": [ "api_key": [
{ {
"current_key": "AIzaSyD6erhkj_KOB7WrhdunV1uN29QOoLJHTaQ" "current_key": "AIzaSyBTWsu3Z5EjCnm3nUoWamuMLmGvM0nGq7o"
} }
], ],
"services": { "services": {
@ -40,7 +40,7 @@
"status": 2, "status": 2,
"other_platform_oauth_client": [ "other_platform_oauth_client": [
{ {
"client_id": "268851337880-n19d05m282nirs1fc9kdd5n4of6je4fk.apps.googleusercontent.com", "client_id": "1050186150447-4u9m96ub04cuppmnkfdk7ua51o9r7pf3.apps.googleusercontent.com",
"client_type": 3 "client_type": 3
} }
] ]

View file

@ -21,8 +21,6 @@ class ConversationLineItemDecoration extends RecyclerView.ItemDecoration {
@Override @Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { 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 dividerLeft = parent.getPaddingLeft() + mContext.getResources().getDimensionPixelSize(R.dimen.status_left_line_margin);
int dividerRight = dividerLeft + mDivider.getIntrinsicWidth(); int dividerRight = dividerLeft + mDivider.getIntrinsicWidth();

View file

@ -39,6 +39,8 @@ import java.util.Map;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
import retrofit2.Response; import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class LoginActivity extends BaseActivity { public class LoginActivity extends BaseActivity {
private static String OAUTH_SCOPES = "read write follow"; private static String OAUTH_SCOPES = "read write follow";
@ -94,6 +96,15 @@ public class LoginActivity extends BaseActivity {
startActivity(viewIntent); 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 * 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 * 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<String> redirectUris = new ArrayList<>(); getApiFor(domain).authenticateApp(getString(R.string.app_name), getOauthRedirectUri(), OAUTH_SCOPES,
redirectUris.add(getOauthRedirectUri());
mastodonAPI.authenticateApp(getString(R.string.app_name), redirectUris, OAUTH_SCOPES,
getString(R.string.app_website)).enqueue(callback); getString(R.string.app_website)).enqueue(callback);
} }
@ -245,7 +254,7 @@ public class LoginActivity extends BaseActivity {
editText.setError(t.getMessage()); editText.setError(t.getMessage());
} }
}; };
mastodonAPI.fetchOAuthToken(clientId, clientSecret, redirectUri, code, getApiFor(domain).fetchOAuthToken(clientId, clientSecret, redirectUri, code,
"authorization_code").enqueue(callback); "authorization_code").enqueue(callback);
} else if (error != null) { } else if (error != null) {
/* Authorization failed. Put the error response where the user can read it and they /* Authorization failed. Put the error response where the user can read it and they

View file

@ -175,7 +175,7 @@ public interface MastodonAPI {
@POST("api/v1/apps") @POST("api/v1/apps")
Call<AppCredentials> authenticateApp( Call<AppCredentials> authenticateApp(
@Field("client_name") String clientName, @Field("client_name") String clientName,
@Field("redirect_uris[]") List<String> redirectUris, @Field("redirect_uris") String redirectUris,
@Field("scopes") String scopes, @Field("scopes") String scopes,
@Field("website") String website); @Field("website") String website);

View file

@ -160,6 +160,7 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
Picasso.with(this) Picasso.with(this)
.load(body.account.avatar) .load(body.account.avatar)
.placeholder(R.drawable.avatar_default) .placeholder(R.drawable.avatar_default)
.transform(new RoundedTransformation(7, 0))
.into(mTarget); .into(mTarget);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

View file

@ -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";
}
}

View file

@ -158,6 +158,7 @@ class StatusViewHolder extends RecyclerView.ViewHolder {
.load(url) .load(url)
.placeholder(R.drawable.avatar_default) .placeholder(R.drawable.avatar_default)
.error(R.drawable.avatar_error) .error(R.drawable.avatar_error)
.transform(new RoundedTransformation(7, 0))
.into(avatar); .into(avatar);
} }

View file

@ -40,7 +40,7 @@
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:id="@+id/status_avatar" android:id="@+id/status_avatar"
android:layout_below="@+id/status_reblogged_bar" android:layout_below="@+id/status_reblogged_bar"
android:layout_marginTop="10dp" android:layout_marginTop="11dp"
android:layout_marginRight="10dp" /> android:layout_marginRight="10dp" />
<RelativeLayout <RelativeLayout