Multi account feature (#490)

* basic implementation

* improve LoginActivity

* darken drawer background image

* add current avatar in ComposeActivity

* add account name to logout dialog

* multi account support for notifications

* multi account support for notifications

* bugfixes & cleanup

* fix bug where somethings notifications would open with the wrong user

* correctly set active account in SFragment

* small improvements
This commit is contained in:
Konrad Pozniak 2018-02-03 22:45:14 +01:00 committed by GitHub
commit 92ae463b38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 1293 additions and 773 deletions

View file

@ -1,11 +1,9 @@
package com.keylesspalace.tusky.network;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.keylesspalace.tusky.R;
import com.keylesspalace.tusky.TuskyApplication;
import com.keylesspalace.tusky.db.AccountEntity;
import java.io.IOException;
@ -17,37 +15,24 @@ import okhttp3.Response;
* Created by charlag on 31/10/17.
*/
public final class AuthInterceptor implements Interceptor, SharedPreferences.OnSharedPreferenceChangeListener {
public final class AuthInterceptor implements Interceptor {
private static final String TOKEN_KEY = "accessToken";
@Nullable
private String token;
public AuthInterceptor(Context context) {
SharedPreferences preferences = context.getSharedPreferences(
context.getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
token = preferences.getString(TOKEN_KEY, null);
preferences.registerOnSharedPreferenceChangeListener(this);
}
public AuthInterceptor() { }
@Override
public Response intercept(@NonNull Chain chain) throws IOException {
AccountEntity currentAccount = TuskyApplication.getAccountManager().getActiveAccount();
Request originalRequest = chain.request();
Request.Builder builder = originalRequest.newBuilder();
if (token != null) {
builder.header("Authorization", String.format("Bearer %s", token));
if (currentAccount != null) {
builder.header("Authorization", String.format("Bearer %s", currentAccount.getAccessToken()));
}
Request newRequest = builder.build();
return chain.proceed(newRequest);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals(TOKEN_KEY)) {
token = sharedPreferences.getString(TOKEN_KEY, null);
}
}
}

View file

@ -40,6 +40,7 @@ import retrofit2.http.DELETE;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Multipart;
import retrofit2.http.PATCH;
import retrofit2.http.POST;
@ -81,6 +82,9 @@ public interface MastodonApi {
@Query("max_id") String maxId,
@Query("since_id") String sinceId,
@Query("limit") Integer limit);
@GET("api/v1/notifications")
Call<List<Notification>> notificationsWithAuth(
@Header("Authorization") String auth);
@POST("api/v1/notifications/clear")
Call<ResponseBody> clearNotifications();
@GET("api/v1/notifications/{id}")