Skip to content

Commit

Permalink
Implemented Retrieving Host's Mute Status & Handling of No Audio Devi…
Browse files Browse the repository at this point in the history
…ces/Display Profiles (#94)

* Added support for retrieving host's current mute status and adjust the client's visuals accordingly. Implemented placeholders for when audio devices or display profiles from the host are empty.

* Forgot to include the UDPServerManager, which had responses updated for when lists are empty.
  • Loading branch information
Fahim-zzz authored Nov 18, 2024
1 parent aa0e5ae commit 5393869
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,34 @@ public OptionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewTy

@Override
public void onBindViewHolder(@NonNull OptionViewHolder holder, int position) {
holder.button.setText(audioDevices.get(position));

if (position == selectedPosition) {
holder.button.setBackgroundColor(Color.parseColor("#044a41"));
if ("No audio devices".equals(audioDevices.get(position))) {
holder.button.setText("No Audio Devices");
holder.button.setEnabled(false);
holder.button.setBackgroundColor(Color.GRAY);
holder.button.setOnClickListener(null); // Remove click listener
} else {
holder.button.setBackgroundColor(Color.parseColor("#077063"));
}
holder.button.setText(audioDevices.get(position));

holder.button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MainActivity.connectionManager.SendHostMessage("AudioConnect " + holder.button.getText().toString());
int previousPosition = selectedPosition;
selectedPosition = holder.getAdapterPosition();
if (position == selectedPosition) {
holder.button.setBackgroundColor(Color.parseColor("#044a41"));
} else {
holder.button.setBackgroundColor(Color.parseColor("#077063"));
}

if (previousPosition != -1) {
notifyItemChanged(previousPosition);
holder.button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MainActivity.connectionManager.SendHostMessage("AudioConnect " + holder.button.getText().toString());
int previousPosition = selectedPosition;
selectedPosition = holder.getAdapterPosition();

if (previousPosition != -1) {
notifyItemChanged(previousPosition);
}
notifyItemChanged(selectedPosition);
}
notifyItemChanged(selectedPosition);
}
});
});
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.dairemote_app;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -26,13 +27,21 @@ public OptionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewTy

@Override
public void onBindViewHolder(@NonNull OptionViewHolder holder, int position) {
holder.button.setText(displayProfiles.get(position));
holder.button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MainActivity.connectionManager.SendHostMessage("DisplayConnect " + holder.button.getText().toString());
}
});
if ("No display profiles".equals(displayProfiles.get(position))) {
holder.button.setText("No Display Profiles");
holder.button.setEnabled(false);
holder.button.setBackgroundColor(Color.GRAY);
holder.button.setOnClickListener(null); // Remove click listener
} else {
holder.button.setText(displayProfiles.get(position));
holder.button.setBackgroundColor(Color.parseColor("#077063"));
holder.button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MainActivity.connectionManager.SendHostMessage("DisplayConnect " + holder.button.getText().toString());
}
});
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class InteractionPage extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
Expand Down Expand Up @@ -71,6 +72,7 @@ public class InteractionPage extends AppCompatActivity implements NavigationView
private AudioRecyclerAdapter audioRecyclerAdapter;
private boolean audioListVisible = false;
private boolean audioMuted = false;
private ImageButton audioToggleMuteButton;

// Host Display Profiles variables
private boolean isRequestDisplayProfilesTaskRunning = false;
Expand Down Expand Up @@ -156,7 +158,7 @@ protected void onCreate(Bundle savedInstanceState) {
ImageButton previousButton = findViewById(R.id.audio_previous_button);
ImageButton nextButton = findViewById(R.id.audio_next_button);
ImageButton audioCycleButton = findViewById(R.id.audio_cycle_button);
ImageButton audioToggleMuteButton = findViewById(R.id.audio_togglemute_button);
audioToggleMuteButton = findViewById(R.id.audio_togglemute_button);
currentVolume = findViewById(R.id.audio_slider_volume);
ImageView audioButton = findViewById(R.id.audiocycle);
audioControlPanel = findViewById(R.id.audio_control_panel);
Expand Down Expand Up @@ -730,15 +732,34 @@ protected void onPostExecute(Boolean result) {
String devicesPart = parts[0].substring("AudioDevices: ".length());
List<String> deviceList = Arrays.asList(devicesPart.split(","));
Log.d("InteractionPageAudio", "Audio devices: " + deviceList);
UpdateAudioDevices(deviceList);
Log.d("InteractionPageAudio", "Audio default device: " + parts[2].substring("DefaultAudioDevice: ".length()));
SetAudioDeviceDefault(parts[2].substring("DefaultAudioDevice: ".length()));

// Set seekbar to current host volume
String volumePart = parts[1].substring("Volume: ".length());
Log.d("InteractionPageAudio", "Volume: " + Integer.parseInt(volumePart));
volumeSlider.setProgress(Integer.parseInt(volumePart));
currentVolume.setText(volumePart);

if (deviceList.isEmpty() || deviceList.get(0).isEmpty()) {
List<String> placeholder = Collections.singletonList("No audio devices");
UpdateAudioDevices(placeholder);
} else {
UpdateAudioDevices(deviceList);
Log.d("InteractionPageAudio", "Audio default device: " + parts[2].substring("DefaultAudioDevice: ".length()));
SetAudioDeviceDefault(parts[2].substring("DefaultAudioDevice: ".length()));

// Set seekbar to current host volume
String volumePart = parts[1].substring("Volume: ".length());
Log.d("InteractionPageAudio", "Volume: " + Integer.parseInt(volumePart));
volumeSlider.setProgress(Integer.parseInt(volumePart));
currentVolume.setText(volumePart);

// Get host's current mute status
String muteStatus = parts[3].substring("Mute: ".length());
Log.d("InteractionPageAudio", "Mute: " + muteStatus);
if(muteStatus.equalsIgnoreCase("true")) {
audioMuted = true;
audioToggleMuteButton.setColorFilter(getColor(R.color.black));
currentVolume.setTextColor(getColor(R.color.black));
} else {
audioMuted = false;
audioToggleMuteButton.setColorFilter(getColor(R.color.grey));
currentVolume.setTextColor(getColor(R.color.grey));
}
}
} else {
Log.e("InteractionPageAudio", "Unexpected response format: " + response);
}
Expand Down Expand Up @@ -768,8 +789,14 @@ protected void onPostExecute(Boolean result) {
// Load audio devices on recycler
String displayProfiles = response.substring("DisplayProfiles: ".length());
List<String> deviceList = Arrays.asList(displayProfiles.split(","));
Log.d("InteractionPageDisplays", "Display Profiles: " + deviceList);
UpdateDisplayProfiles(deviceList);

if (deviceList.isEmpty() || deviceList.get(0).isEmpty()) {
List<String> placeholder = Collections.singletonList("No display profiles");
UpdateDisplayProfiles(placeholder);
} else {
Log.d("InteractionPageDisplays", "Display Profiles: " + deviceList);
UpdateDisplayProfiles(deviceList);
}
} else {
Log.e("InteractionPageDisplays", "Unexpected response format: " + response);
}
Expand Down
30 changes: 25 additions & 5 deletions UDPServerManager/UDPServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,22 @@ public void RetrieveCommand(string command)
else if (parts[1] == "Devices")
{
List<string> devices = audioManager.ActiveDeviceNames;
string list = string.Join(",", devices);
if (devices.Count > 0)
{
string list = string.Join(",", devices);

SendUdpMessage("AudioDevices: " + list + "|Volume: " + audioManager.GetVolume() + "|DefaultAudioDevice: " + audioManager.GetDefaultAudioDevice().FullName);
SendUdpMessage("AudioDevices: " + list
+ "|Volume: " + audioManager.GetVolume()
+ "|DefaultAudioDevice: " + audioManager.GetDefaultAudioDevice().FullName
+ "|Mute: " + audioManager.GetDefaultAudioDevice().IsMuted);
}
else
{
SendUdpMessage("AudioDevices: "
+ "|Volume: 0"
+ "|DefaultAudioDevice: None"
+ "|Mute: true");
}
}
else if (parts[1] == "TogglePlay")
{
Expand Down Expand Up @@ -378,10 +391,17 @@ public void RetrieveCommand(string command)
{
// Get all .json files from the directory (display profiles)
string[] displayProfiles = Directory.GetFiles(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "DAIRemote/DisplayProfiles"), "*.json");
string displayProfileName = string.Join(",", Array.ConvertAll(displayProfiles, Path.GetFileNameWithoutExtension));

Debug.WriteLine(displayProfileName);
SendUdpMessage("DisplayProfiles: " + displayProfileName);
if (displayProfiles.Length > 0)
{
string displayProfileName = string.Join(",", Array.ConvertAll(displayProfiles, Path.GetFileNameWithoutExtension));
Debug.WriteLine(displayProfileName);
SendUdpMessage("DisplayProfiles: " + displayProfileName);
}
else
{
SendUdpMessage("DisplayProfiles: ");
}
}
catch (Exception ex)
{
Expand Down

0 comments on commit 5393869

Please sign in to comment.