Skip to content

Add Android status mode controls#3316

Open
computertech1012 wants to merge 5 commits into
BearWare:masterfrom
computertech1012:add-android-status-mode
Open

Add Android status mode controls#3316
computertech1012 wants to merge 5 commits into
BearWare:masterfrom
computertech1012:add-android-status-mode

Conversation

@computertech1012
Copy link
Copy Markdown

This adds status mode controls to the Android client after connecting to a server.

Changes included:

  • add a Change Status action to the main menu
  • add Available, Away, and Question status mode selection
  • allow editing the current status message from the same dialog
  • keep the current server entry status message in sync when it is changed

Local verification:

  • gradlew.bat assembleDebug completed successfully for Client/TeamTalkAndroid

@amirmahdifard
Copy link
Copy Markdown
Contributor

@computertech1012 a lot of unneeded checks are here. why you check for server type etc? you can just follow my patten and just add it to settings, or if you really want to do it from here, just aply the status message to the server entry because the one I Added in settings edits the globel status message.

@amirmahdifard
Copy link
Copy Markdown
Contributor

@computertech1012 Actually, You did something That I really wanted to do at some point, let me explane it and I have a request at the end.
so as you know, We can set a nickname and a status message per each server by going to edit server dialog of that server. But Once we set a nickname and a status message for a server, if we are inside that server and we want to edit our nickname and status message for that server, we had to log out, edit from server edit dialog, and log back in.
But now, please add One more editbox to this dialog, called nickname, That edits the serverentry.nickname
so the dialog should become like this.
nickname editbox in this dialog. Only edit the serverentry.nickname, not the globel nickname
status message editbox in this dialog. Only edit serverentry.statusmsg, not the globel status message.
Status mode radio buttons. Those should edit the globel status mode because we don't have serverentry.statusmode. We only have one globel status mode that aplys to every server. But if you want to add status mode per server as well like I added status message per server feel free to do that. But if not, changing this dialog as I said would exactly match the desktop client.
Change the action name from change status to change nickname and status.
if user wants to edit their globel nickname and globel status message they will go to settings, But this dialog allowes them to change serverentry.nickname and serverentry.statusmsg within the server and without needing to log out from the server to edit these
And remove the extra checks for servertyp local. Thanks!

@computertech1012
Copy link
Copy Markdown
Author

Hi,
@amirmahdifard That makes sense, and I agree with what you are saying here.
I will work on this.
Thanks for reading!

@computertech1012
Copy link
Copy Markdown
Author

Hi,
@amirmahdifard I updated this now based on what you suggested.
When you have time, please feel free to review it.
I appreciate the help.
Thanks for reading!

@amirmahdifard
Copy link
Copy Markdown
Contributor

@computertech1012 it's grate! exactly as How as I would implement such a thing. Just a small thing. Update these 2 helper strings to the ones I give you here.

private String getCurrentNickname(User myself) {
    ServerEntry serverEntry = getService().getServerEntry();
    if (serverEntry != null && !TextUtils.isEmpty(serverEntry.nickname))
        return serverEntry.nickname;
}

private String getCurrentStatusMessage(User myself) {
    ServerEntry serverEntry = getService().getServerEntry();
    if (serverEntry != null && !TextUtils.isEmpty(serverEntry.statusmsg))
        return serverEntry.statusmsg;
}
Like desktop client, these 2 editboxes should only fild with serverentry.nickname and serverentry.statusmsg and only update those too. If those are empty, these text boxes should also be empty and not be fild with our current nickname and current status or general nickname and status
The desktop clients also behaves exactly like this. Also, change the action id to something like
        } else if (itemId == R.id.action_statusnick) {
        The rest is great, absolutely great! Thanks so much for this! thanks so much!

@computertech1012
Copy link
Copy Markdown
Author

Hi,
@amirmahdifard I made those last changes now.
I appreciate you pointing that out.
Thanks for reading!

@amirmahdifard
Copy link
Copy Markdown
Contributor

@computertech1012 thanks bro it's now completely ready, just I think you forgot to change the title in main.xml, it's stil actionstatus, you changed the id. Fix that as well, and this pull request is completely ready! then wait 3 years for your pull request to be merged🤣

@computertech1012
Copy link
Copy Markdown
Author

Hi,
Really thanks for your help @amirmahdifard you have no idea how much it means to me. I will fix that now. about the time it takes, yes I know about it, but yet someone who just started working on this project is already an organization owner. I guess bearware has favorites, just like how someone is admin in an official server who doesn't even use the latest client :).
Thanks for reading!

@amirmahdifard
Copy link
Copy Markdown
Contributor

@computertech1012 hi. I want to address the last real cleanup to this feature.
Change the dialog handler to
private void showChangeNicknameStatusDialog() {
User myself = getService().getUsers().get(getClient().getMyUserID());
if (myself == null) {
Toast.makeText(this, R.string.text_con_cmderr, Toast.LENGTH_SHORT).show();
return;
}

final int[] modeValues = {
        TeamTalkConstants.STATUSMODE_AVAILABLE,
        TeamTalkConstants.STATUSMODE_AWAY,
        TeamTalkConstants.STATUSMODE_QUESTION
};

int checkedItem = 0;
int currentMode = myself.nStatusMode & TeamTalkConstants.STATUSMODE_MODE;
for (int i = 0; i < modeValues.length; i++) {
    if (modeValues[i] == currentMode) {
        checkedItem = i;
        break;
    }
}

LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
int padding = (int) (getResources().getDisplayMetrics().density * 20);
layout.setPadding(padding, padding / 2, padding, 0);

TextView nicknameLabel = new TextView(this);
nicknameLabel.setText(R.string.pref_title_nickname);
layout.addView(nicknameLabel);

EditText nicknameInput = new EditText(this);
nicknameInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
nicknameInput.setSingleLine();
nicknameInput.setText(getCurrentNickname(myself));
nicknameInput.setSelection(nicknameInput.getText().length());
layout.addView(nicknameInput);

TextView messageLabel = new TextView(this);
messageLabel.setText(R.string.text_status_message);
layout.addView(messageLabel);

EditText statusMessageInput = new EditText(this);
statusMessageInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
statusMessageInput.setSingleLine();
statusMessageInput.setText(getCurrentStatusMessage(myself));
statusMessageInput.setSelection(statusMessageInput.getText().length());
layout.addView(statusMessageInput);

TextView modeLabel = new TextView(this);
modeLabel.setText(R.string.text_status_mode);
layout.addView(modeLabel);

RadioGroup modeGroup = new RadioGroup(this);
modeGroup.setOrientation(RadioGroup.VERTICAL);

RadioButton availableButton = new RadioButton(this);
availableButton.setId(View.generateViewId());
availableButton.setText(R.string.status_mode_available);
modeGroup.addView(availableButton);

RadioButton awayButton = new RadioButton(this);
awayButton.setId(View.generateViewId());
awayButton.setText(R.string.status_mode_away);
modeGroup.addView(awayButton);

RadioButton questionButton = new RadioButton(this);
questionButton.setId(View.generateViewId());
questionButton.setText(R.string.status_mode_question);
modeGroup.addView(questionButton);

modeGroup.check(modeGroup.getChildAt(checkedItem).getId());

layout.addView(modeGroup);

new AlertDialog.Builder(this)
        .setTitle(R.string.action_statusnick)
        .setView(layout)
        .setPositiveButton(android.R.string.ok, (dialog, which) -> {
            int selectedIndex = modeGroup.indexOfChild(
                    modeGroup.findViewById(modeGroup.getCheckedRadioButtonId()));

            applyNicknameStatusChange(
                    nicknameInput.getText().toString(),
                    modeValues[selectedIndex],
                    statusMessageInput.getText().toString());
        })
        .setNegativeButton(android.R.string.cancel, null)
        .show();

}
There was a real cleanup. Removed an extra double workaround. Android remembers the selection so the work is not double

Removed the OnCheckedChangeListener.

Removed the mutable checkedItem[] workaround.

Determine the selected radio button only when the user presses OK using:
modeGroup.getCheckedRadioButtonId()
and
modeGroup.indexOfChild(...)

Reduced code complexity and state tracking while keeping identical behavior.
Simplified status mode selection dialog by removing RadioGroup selection tracking and resolving the selected status mode directly when the dialog is confirmed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants