mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2025-01-07 00:20:08 +02:00
Fix issue #617
This commit is contained in:
parent
7fc8f96eef
commit
bd66462968
5 changed files with 105 additions and 8 deletions
|
@ -188,6 +188,16 @@ public class ProfileActivity extends BaseActivity {
|
||||||
LocalBroadcastManager.getInstance(ProfileActivity.this).registerReceiver(broadcast_data, new IntentFilter(Helper.BROADCAST_DATA));
|
LocalBroadcastManager.getInstance(ProfileActivity.this).registerReceiver(broadcast_data, new IntentFilter(Helper.BROADCAST_DATA));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void updateViewWithNewData(Account account) {
|
||||||
|
if (account != null) {
|
||||||
|
if (account.role != null && account.role.highlighted) {
|
||||||
|
binding.accountRole.setText(account.role.name);
|
||||||
|
binding.accountRole.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void initializeView(Account account) {
|
private void initializeView(Account account) {
|
||||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ProfileActivity.this);
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ProfileActivity.this);
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
|
@ -497,7 +507,9 @@ public class ProfileActivity extends BaseActivity {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (accountInstance != null) {
|
||||||
|
accountsVM.lookUpAccount(accountInstance, account.username).observe(ProfileActivity.this, this::updateViewWithNewData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,12 @@ public interface MastodonAccountsService {
|
||||||
@Path("id") String id
|
@Path("id") String id
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//Get Account
|
||||||
|
@GET("accounts/lookup")
|
||||||
|
Call<Account> lookUpAccount(
|
||||||
|
@Query("acct") String acct
|
||||||
|
);
|
||||||
|
|
||||||
//Get Account statuses
|
//Get Account statuses
|
||||||
@GET("accounts/{id}/statuses")
|
@GET("accounts/{id}/statuses")
|
||||||
Call<List<Status>> getAccountStatuses(
|
Call<List<Status>> getAccountStatuses(
|
||||||
|
|
|
@ -73,12 +73,40 @@ public class Account implements Serializable {
|
||||||
public List<Field> fields;
|
public List<Field> fields;
|
||||||
@SerializedName("suspended")
|
@SerializedName("suspended")
|
||||||
public boolean suspended;
|
public boolean suspended;
|
||||||
|
@SerializedName("limited")
|
||||||
|
public boolean limited;
|
||||||
@SerializedName("discoverable")
|
@SerializedName("discoverable")
|
||||||
public boolean discoverable;
|
public boolean discoverable;
|
||||||
|
@SerializedName("group")
|
||||||
|
public boolean group;
|
||||||
@SerializedName("mute_expires_at")
|
@SerializedName("mute_expires_at")
|
||||||
public Date mute_expires_at;
|
public Date mute_expires_at;
|
||||||
@SerializedName("moved")
|
@SerializedName("moved")
|
||||||
public Account moved;
|
public Account moved;
|
||||||
|
@SerializedName("role")
|
||||||
|
public Role role;
|
||||||
|
|
||||||
|
|
||||||
|
public static class Role implements Serializable {
|
||||||
|
@SerializedName("id")
|
||||||
|
public String id;
|
||||||
|
@SerializedName("name")
|
||||||
|
public String name;
|
||||||
|
@SerializedName("color")
|
||||||
|
public String color;
|
||||||
|
@SerializedName("position")
|
||||||
|
public int position;
|
||||||
|
@SerializedName("permissions")
|
||||||
|
public int permissions;
|
||||||
|
@SerializedName("highlighted")
|
||||||
|
public boolean highlighted;
|
||||||
|
@SerializedName("created_at")
|
||||||
|
public Date created_at;
|
||||||
|
@SerializedName("updated_at")
|
||||||
|
public Date updated_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public transient RelationShip relationShip;
|
public transient RelationShip relationShip;
|
||||||
|
|
||||||
public synchronized Spannable getSpanDisplayName(Context context, WeakReference<View> viewWeakReference) {
|
public synchronized Spannable getSpanDisplayName(Context context, WeakReference<View> viewWeakReference) {
|
||||||
|
|
|
@ -296,6 +296,36 @@ public class AccountsVM extends AndroidViewModel {
|
||||||
return accountMutableLiveData;
|
return accountMutableLiveData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param acct The acct of the account
|
||||||
|
* @return {@link LiveData} containing an {@link Account}
|
||||||
|
*/
|
||||||
|
public LiveData<Account> lookUpAccount(@NonNull String instance, @NonNull String acct) {
|
||||||
|
accountMutableLiveData = new MutableLiveData<>();
|
||||||
|
MastodonAccountsService mastodonAccountsService = init(instance);
|
||||||
|
new Thread(() -> {
|
||||||
|
Account account = null;
|
||||||
|
Call<Account> accountCall = mastodonAccountsService.lookUpAccount(acct);
|
||||||
|
if (accountCall != null) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Response<Account> accountResponse = accountCall.execute();
|
||||||
|
if (accountResponse.isSuccessful()) {
|
||||||
|
account = accountResponse.body();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Account finalAccount = account;
|
||||||
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
|
Runnable myRunnable = () -> accountMutableLiveData.setValue(finalAccount);
|
||||||
|
mainHandler.post(myRunnable);
|
||||||
|
}).start();
|
||||||
|
return accountMutableLiveData;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id The id of the account
|
* @param id The id of the account
|
||||||
* @return {@link LiveData} containing an {@link Account}
|
* @return {@link LiveData} containing an {@link Account}
|
||||||
|
|
|
@ -142,17 +142,38 @@
|
||||||
app:layout_constraintTop_toBottomOf="@id/avatar_container"
|
app:layout_constraintTop_toBottomOf="@id/avatar_container"
|
||||||
tools:text="@tools:sample/first_names" />
|
tools:text="@tools:sample/first_names" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
<androidx.appcompat.widget.LinearLayoutCompat
|
||||||
android:id="@+id/account_un"
|
android:id="@+id/account_un_container"
|
||||||
style="@style/TextAppearance.AppCompat.Caption"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="3dp"
|
android:layout_marginTop="3dp"
|
||||||
android:singleLine="true"
|
android:gravity="center"
|
||||||
app:layout_constraintEnd_toEndOf="@id/banner_container"
|
app:layout_constraintEnd_toEndOf="@id/banner_container"
|
||||||
app:layout_constraintStart_toStartOf="@id/banner_container"
|
app:layout_constraintStart_toStartOf="@id/banner_container"
|
||||||
app:layout_constraintTop_toBottomOf="@id/account_dn"
|
app:layout_constraintTop_toBottomOf="@id/account_dn">
|
||||||
tools:text="\@username\@instance.test" />
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
|
android:id="@+id/account_un"
|
||||||
|
style="@style/TextAppearance.AppCompat.Caption"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:singleLine="true"
|
||||||
|
tools:text="\@username\@instance.test" />
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
|
android:id="@+id/account_role"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
|
||||||
|
android:layout_marginStart="5dp"
|
||||||
|
android:background="@drawable/blue_border"
|
||||||
|
android:textColor="?colorPrimary"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:text="Owner"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||||
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.LinearLayoutCompat
|
<androidx.appcompat.widget.LinearLayoutCompat
|
||||||
android:id="@+id/names_container"
|
android:id="@+id/names_container"
|
||||||
|
@ -163,7 +184,7 @@
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/account_un">
|
app:layout_constraintTop_toBottomOf="@+id/account_un_container">
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
Loading…
Reference in a new issue