Fix issue with sharedpref
This commit is contained in:
parent
3ee5d00812
commit
9d40901631
|
@ -19,6 +19,8 @@ import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import app.fedilab.android.client.API;
|
import app.fedilab.android.client.API;
|
||||||
import app.fedilab.android.client.APIResponse;
|
import app.fedilab.android.client.APIResponse;
|
||||||
|
@ -46,6 +48,9 @@ public class PostSubscriptionAsyncTask {
|
||||||
protected void doInBackground() {
|
protected void doInBackground() {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
apiResponse = new API(contextReference.get(), account.getInstance(), account.getToken()).pushSubscription(account, endpoint);
|
apiResponse = new API(contextReference.get(), account.getInstance(), account.getToken()).pushSubscription(account, endpoint);
|
||||||
|
List<Account> accountList = new ArrayList<>();
|
||||||
|
accountList.add(account);
|
||||||
|
apiResponse.setAccounts(accountList);
|
||||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
Runnable myRunnable = () -> listener.onSubscription(apiResponse);
|
Runnable myRunnable = () -> listener.onSubscription(apiResponse);
|
||||||
mainHandler.post(myRunnable);
|
mainHandler.post(myRunnable);
|
||||||
|
|
|
@ -74,12 +74,10 @@ class handler implements MessagingReceiverHandler, OnPostSubscription {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSubscription(APIResponse apiResponse) {
|
public void onSubscription(APIResponse apiResponse) {
|
||||||
if (apiResponse != null && apiResponse.getPushSubscription() != null) {
|
if (apiResponse != null && apiResponse.getPushSubscription() != null && apiResponse.getAccounts() != null) {
|
||||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
||||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
|
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
editor.putString(Helper.SERVER_KEY + userId + instance, apiResponse.getPushSubscription().getServer_key());
|
editor.putString(Helper.SERVER_KEY + apiResponse.getAccounts().get(0).getId() + apiResponse.getAccounts().get(0).getInstance(), apiResponse.getPushSubscription().getServer_key());
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue