This commit is contained in:
Thomas 2022-12-11 11:36:39 +01:00
parent 7fc8f96eef
commit bd66462968
5 changed files with 105 additions and 8 deletions

View File

@ -188,6 +188,16 @@ public class ProfileActivity extends BaseActivity {
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) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ProfileActivity.this);
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);
}
}

View File

@ -105,6 +105,12 @@ public interface MastodonAccountsService {
@Path("id") String id
);
//Get Account
@GET("accounts/lookup")
Call<Account> lookUpAccount(
@Query("acct") String acct
);
//Get Account statuses
@GET("accounts/{id}/statuses")
Call<List<Status>> getAccountStatuses(

View File

@ -73,12 +73,40 @@ public class Account implements Serializable {
public List<Field> fields;
@SerializedName("suspended")
public boolean suspended;
@SerializedName("limited")
public boolean limited;
@SerializedName("discoverable")
public boolean discoverable;
@SerializedName("group")
public boolean group;
@SerializedName("mute_expires_at")
public Date mute_expires_at;
@SerializedName("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 synchronized Spannable getSpanDisplayName(Context context, WeakReference<View> viewWeakReference) {

View File

@ -296,6 +296,36 @@ public class AccountsVM extends AndroidViewModel {
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
* @return {@link LiveData} containing an {@link Account}

View File

@ -142,17 +142,38 @@
app:layout_constraintTop_toBottomOf="@id/avatar_container"
tools:text="@tools:sample/first_names" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/account_un"
style="@style/TextAppearance.AppCompat.Caption"
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/account_un_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:singleLine="true"
android:gravity="center"
app:layout_constraintEnd_toEndOf="@id/banner_container"
app:layout_constraintStart_toStartOf="@id/banner_container"
app:layout_constraintTop_toBottomOf="@id/account_dn"
tools:text="\@username\@instance.test" />
app:layout_constraintTop_toBottomOf="@id/account_dn">
<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
android:id="@+id/names_container"
@ -163,7 +184,7 @@
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="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
android:layout_width="wrap_content"