Skip to content

Commit 9628af5

Browse files
committed
use showBottomSheetDialog
Signed-off-by: alperozturk <[email protected]>
1 parent 48d1e9c commit 9628af5

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020

2121
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
2222

23+
import java.util.concurrent.ExecutorService;
24+
import java.util.concurrent.Executors;
25+
2326
import it.niedermann.owncloud.notes.NotesApplication;
2427
import it.niedermann.owncloud.notes.R;
2528
import it.niedermann.owncloud.notes.accountswitcher.repository.UserStatusRepository;
26-
import it.niedermann.owncloud.notes.branding.BrandedBottomSheetDialogFragment;
2729
import it.niedermann.owncloud.notes.branding.BrandedDialogFragment;
2830
import it.niedermann.owncloud.notes.branding.BrandingUtil;
2931
import it.niedermann.owncloud.notes.databinding.DialogAccountSwitcherBinding;
@@ -45,6 +47,7 @@ public class AccountSwitcherDialog extends BrandedDialogFragment {
4547
private DialogAccountSwitcherBinding binding;
4648
private AccountSwitcherListener accountSwitcherListener;
4749
private long currentAccountId;
50+
private final ExecutorService executor = Executors.newSingleThreadExecutor();
4851

4952
@Override
5053
public void onAttach(@NonNull Context context) {
@@ -81,15 +84,11 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
8184
binding.accountLayout.setOnClickListener((v) -> dismiss());
8285

8386
binding.onlineStatus.setOnClickListener(v -> {
84-
final var setOnlineStatusBottomSheet = new SetOnlineStatusBottomSheet();
85-
setOnlineStatusBottomSheet.show(requireActivity().getSupportFragmentManager(), "fragment_set_status");
86-
dismiss();
87+
showBottomSheetDialog(AccountSwitcherBottomSheetTag.ONLINE_STATUS);
8788
});
8889

8990
binding.statusMessage.setOnClickListener(v -> {
90-
final var setStatusMessageDialog = new SetStatusMessageBottomSheet();
91-
setStatusMessageDialog.show(requireActivity().getSupportFragmentManager(), "fragment_set_status_message");
92-
dismiss();
91+
showBottomSheetDialog(AccountSwitcherBottomSheetTag.MESSAGE_STATUS);
9392
});
9493

9594
final var adapter = new AccountSwitcherAdapter((localAccount -> {
@@ -134,10 +133,18 @@ private void showBottomSheetDialog(@NonNull AccountSwitcherBottomSheetTag tag) {
134133
return Unit.INSTANCE;
135134
}
136135
final var repository = new UserStatusRepository(requireContext(), account);
136+
executor.execute(() -> {
137+
final var currentStatus = repository.fetchUserStatus();
138+
if (currentStatus == null) {
139+
return;
140+
}
137141

138-
final var fragment = tag.fragment(repository, )
139-
fragment.show(requireActivity().getSupportFragmentManager(), tag.name());
140-
dismiss();
142+
requireActivity().runOnUiThread(() -> {
143+
final var fragment = tag.fragment(repository, currentStatus);
144+
fragment.show(requireActivity().getSupportFragmentManager(), tag.name());
145+
dismiss();
146+
});
147+
});
141148
return Unit.INSTANCE;
142149
});
143150
}

app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/repository/UserStatusRepository.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ class UserStatusRepository(
105105
}
106106
}
107107

108-
suspend fun fetchUserStatus(): Status? = withContext(Dispatchers.IO) {
108+
fun fetchUserStatus(): Status? {
109109
val offlineStatus = Status(StatusType.OFFLINE, "", "", -1)
110-
try {
110+
return try {
111111
val call = api.fetchUserStatus()
112112
val response = call.execute()
113113
if (response.isSuccessful) {

app/src/main/java/it/niedermann/owncloud/notes/util/ActivityExtensions.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@ import kotlinx.coroutines.Dispatchers
99
import kotlinx.coroutines.launch
1010
import kotlinx.coroutines.withContext
1111

12+
/**
13+
* Retrieves the currently active Single Sign-On (SSO) account associated with this [ComponentActivity].
14+
*
15+
* This function runs asynchronously using a coroutine:
16+
* - The SSO account lookup is performed on the **IO dispatcher** (background thread).
17+
* - Once the result is available, the [onCompleted] callback is invoked on the **main thread**.
18+
*
19+
* If fetching the account fails for any reason (e.g., no account found, SSO error, etc.),
20+
* the callback will receive `null` and an error will be logged.
21+
*
22+
* @param onCompleted A callback that receives the retrieved [SingleSignOnAccount],
23+
* or `null` if no valid account was found.
24+
*/
1225
fun ComponentActivity.ssoAccount(onCompleted: (SingleSignOnAccount?) -> Unit) {
1326
lifecycleScope.launch(Dispatchers.IO) {
1427
val result = try {

0 commit comments

Comments
 (0)