Skip to content

Commit

Permalink
Fix issue #36, metadata doesn't update when changing device
Browse files Browse the repository at this point in the history
  • Loading branch information
wseemann committed Sep 25, 2024
1 parent 88e58a2 commit 6c91e83
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
}

if (mStoreFragment != null) {
if (mStoreFragment.onKeyDown(keyCode, event)) {
if (mStoreFragment.onKeyDown(keyCode)) {
return true;
}
}
Expand Down Expand Up @@ -277,7 +277,7 @@ private void performSearch(String searchText) {
String url = commandHelper.getDeviceURL();

SearchRequest searchRequest = new SearchRequest(url, searchText, null, null, null, null, null, null, null, null, null);
searchRequest.sendAsync(new ResponseCallback<Void>() {
searchRequest.sendAsync(new ResponseCallback<>() {
@Override
public void onSuccess(@Nullable Void unused) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import wseemann.media.romote.adapter.ChannelAdapter;
import wseemann.media.romote.tasks.ChannelTask;
import wseemann.media.romote.util.Utils;
import wseemann.media.romote.utils.BroadcastUtils;
import wseemann.media.romote.utils.CommandHelper;
import wseemann.media.romote.utils.Constants;

Expand Down Expand Up @@ -135,7 +136,7 @@ public void onRefresh() {
Channel channel = (Channel) parent.getItemAtPosition(position);

performLaunch(channel.getId());
getContext().sendBroadcast(new Intent(Constants.UPDATE_DEVICE_BROADCAST));
BroadcastUtils.Companion.sendUpdateDeviceBroadcast(requireContext());
});

// This listener is used to get the final width of the GridView and then calculate the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class ConfigureDeviceFragment extends Fragment {

private Handler mHandler;

private CompositeDisposable bin = new CompositeDisposable();
private final CompositeDisposable bin = new CompositeDisposable();

@Override
public void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -94,14 +94,11 @@ public void onActivityCreated(Bundle savedInstanceState) {
public void onResume() {
super.onResume();

mWirelessNextworkTextview.setText(getWirelessNetworkName(getActivity()));
mWirelessNextworkTextview.setText(getWirelessNetworkName(requireContext()));

mHandler.postDelayed(new Runnable() {
@Override
public void run() {
setListShown(false);
loadAvailableDevices();
}
mHandler.postDelayed(() -> {
setListShown(false);
loadAvailableDevices();
}, 1000);
}

Expand All @@ -124,7 +121,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode == 0 && resultCode == Activity.RESULT_OK) {
startActivity(new Intent(ConfigureDeviceFragment.this.getActivity(), MainActivity.class));
ConfigureDeviceFragment.this.getActivity().finish();
ConfigureDeviceFragment.this.requireActivity().finish();
}
}

Expand Down Expand Up @@ -162,12 +159,9 @@ private void loadAvailableDevices() {
}

private void onLoadFinished(List<Device> devices) {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
setListShown(false);
loadAvailableDevices();
}
mHandler.postDelayed(() -> {
setListShown(false);
loadAvailableDevices();
}, 5000);

if (devices.size() == 0) {
Expand All @@ -178,7 +172,7 @@ public void run() {
// Set the new devices in the adapter.
for (int i = 0; i < devices.size(); i++) {
if (!containDevice(devices.get(i))) {
RelativeLayout view = (RelativeLayout) getActivity().getLayoutInflater().inflate(R.layout.configure_device_list_item, null, false);
RelativeLayout view = (RelativeLayout) requireActivity().getLayoutInflater().inflate(R.layout.configure_device_list_item, null, false);

TextView text1 = view.findViewById(android.R.id.text1);
TextView text2 = view.findViewById(android.R.id.text2);
Expand Down Expand Up @@ -234,7 +228,7 @@ private boolean containDevice(Device device) {
return found;
}

private View.OnClickListener mClickListener = new View.OnClickListener() {
private final View.OnClickListener mClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Device device = (Device) v.getTag();
Expand All @@ -247,7 +241,7 @@ public void onClick(View v) {
editor.commit();

startActivity(new Intent(ConfigureDeviceFragment.this.getActivity(), MainActivity.class));
ConfigureDeviceFragment.this.getActivity().finish();
ConfigureDeviceFragment.this.requireActivity().finish();
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class ConnectivityDialog extends DialogFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setCancelable(false);
}

Expand All @@ -28,14 +27,12 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(getString(R.string.connectivity_dialog_title));
builder.setMessage(getString(R.string.connectivity_dialog_message));
builder.setNeutralButton(R.string.connectivity_dialog_button, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
try {
// In some cases, a matching Activity may not exist,so ensure you safeguard against this.
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
} catch (ActivityNotFoundException ex) {
startActivity(new Intent(Settings.ACTION_SETTINGS));
}
builder.setNeutralButton(R.string.connectivity_dialog_button, (dialog, id) -> {
try {
// In some cases, a matching Activity may not exist,so ensure you safeguard against this.
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
} catch (ActivityNotFoundException ex) {
startActivity(new Intent(Settings.ACTION_SETTINGS));
}
});

Expand Down
50 changes: 24 additions & 26 deletions app/src/main/java/wseemann/media/romote/fragment/MainFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import wseemann.media.romote.model.Device;
import wseemann.media.romote.tasks.AvailableDevicesTask;
import wseemann.media.romote.tasks.UpdatePairedDeviceTask;
import wseemann.media.romote.utils.BroadcastUtils;
import wseemann.media.romote.utils.Constants;
import wseemann.media.romote.utils.DBUtils;
import wseemann.media.romote.utils.PreferenceUtils;
Expand Down Expand Up @@ -136,39 +137,36 @@ public void onRefresh() {
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Device device = (Device) parent.getItemAtPosition(position);
mList.setOnItemClickListener((parent, view, position, id) -> {
Device device = (Device) parent.getItemAtPosition(position);

DBUtils.insertDevice(getActivity(), device);
preferenceUtils.setConnectedDevice(device.getSerialNumber());
DBUtils.insertDevice(getActivity(), device);
preferenceUtils.setConnectedDevice(device.getSerialNumber());

SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("first_use", false);
editor.commit();
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("first_use", false);
editor.commit();

Toast.makeText(getActivity(), "Device " + device.getSerialNumber() + " " + getString(R.string.connected), Toast.LENGTH_SHORT).show();
Toast.makeText(getActivity(), "Device " + device.getSerialNumber() + " " + getString(R.string.connected), Toast.LENGTH_SHORT).show();

MainFragment.this.getActivity().sendBroadcast(new Intent(Constants.UPDATE_DEVICE_BROADCAST));
BroadcastUtils.Companion.sendUpdateDeviceBroadcast(requireContext());

AppWidgetManager widgetManager = AppWidgetManager.getInstance(getActivity());
ComponentName widgetComponent = new ComponentName(getActivity(), RokuAppWidgetProvider.class);
int[] widgetIds = widgetManager.getAppWidgetIds(widgetComponent);
Intent update = new Intent();
update.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds);
update.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
getActivity().sendBroadcast(update);
AppWidgetManager widgetManager = AppWidgetManager.getInstance(getActivity());
ComponentName widgetComponent = new ComponentName(getActivity(), RokuAppWidgetProvider.class);
int[] widgetIds = widgetManager.getAppWidgetIds(widgetComponent);
Intent update = new Intent();
update.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds);
update.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
getActivity().sendBroadcast(update);

if (mListener != null) {
mListener.onDeviceSelected();
}
if (mListener != null) {
mListener.onDeviceSelected();
}

mAvailableDeviceAdapter.clear();
mAdapter.notifyDataSetChanged();
mAvailableDeviceAdapter.clear();
mAdapter.notifyDataSetChanged();

loadPairedDevices();
}
loadPairedDevices();
});

mFab.setOnClickListener(new View.OnClickListener() {
Expand Down Expand Up @@ -290,7 +288,7 @@ public boolean onMenuItemClick(MenuItem item) {
mAvailableDeviceAdapter.clear();
mAdapter.notifyDataSetChanged();
loadPairedDevices();
getContext().sendBroadcast(new Intent(Constants.UPDATE_DEVICE_BROADCAST));
BroadcastUtils.Companion.sendUpdateDeviceBroadcast(requireContext());
});
fragment.show(MainFragment.this.getFragmentManager(), EditDeviceNameDialog.class.getName());
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,23 @@ public class ManualConnectionDialog extends DialogFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setCancelable(true);
}

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = getActivity().getLayoutInflater();
LayoutInflater inflater = requireActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.dialog_fragment_manual_connection, null);
mIpAddressText = (EditText) view.findViewById(R.id.ip_address_text);
Button connectButton = (Button) view.findViewById(R.id.connect_button);
mProgressLayout = (LinearLayout) view.findViewById(R.id.progress_layout);
mErrorText = (TextView) view.findViewById(R.id.error_text);
mIpAddressText = view.findViewById(R.id.ip_address_text);
Button connectButton = view.findViewById(R.id.connect_button);
mProgressLayout = view.findViewById(R.id.progress_layout);
mErrorText = view.findViewById(R.id.error_text);

connectButton.setOnClickListener(v -> {

String ipAddress = mIpAddressText.getText().toString();
String mHost = "http://" + ipAddress + ":8060";
mHost = "http://" + ipAddress + ":8060";

mErrorText.setVisibility(View.GONE);
mProgressLayout.setVisibility(View.VISIBLE);
Expand All @@ -84,19 +84,14 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
public void onClick(DialogInterface dialog, int id) {
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
builder.setNegativeButton(android.R.string.cancel, (dialog, id) -> { });

return builder.create();
}

private void sendCommand(String command) {
String url = command;

QueryDeviceInfoRequest queryActiveAppRequest = new QueryDeviceInfoRequest(url);
queryActiveAppRequest.sendAsync(new ResponseCallbackWrapper<>(new ResponseCallback<com.wseemann.ecp.model.Device>() {
QueryDeviceInfoRequest queryActiveAppRequest = new QueryDeviceInfoRequest(command);
queryActiveAppRequest.sendAsync(new ResponseCallbackWrapper<>(new ResponseCallback<>() {
@Override
public void onSuccess(@Nullable com.wseemann.ecp.model.Device device) {
mProgressLayout.setVisibility(View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import wseemann.media.romote.audio.IRemoteAudioInterface;
import wseemann.media.romote.model.Device;
import wseemann.media.romote.tasks.ResponseCallbackWrapper;
import wseemann.media.romote.utils.BroadcastUtils;
import wseemann.media.romote.utils.CommandHelper;
import wseemann.media.romote.utils.Constants;
import wseemann.media.romote.utils.PreferenceUtils;
Expand Down Expand Up @@ -152,7 +153,7 @@ public void onClick(View v) {

IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Constants.UPDATE_DEVICE_BROADCAST);
getActivity().registerReceiver(mUpdateReceiver, intentFilter, ContextCompat.RECEIVER_NOT_EXPORTED);
requireActivity().registerReceiver(mUpdateReceiver, intentFilter, ContextCompat.RECEIVER_NOT_EXPORTED);
}

@Override
Expand Down Expand Up @@ -186,7 +187,7 @@ private void linkButton(final KeyPressKeyValues keypressKeyValue, int id) {
if (id == R.id.back_button ||
id == R.id.home_button ||
id == R.id.ok_button) {
getContext().sendBroadcast(new Intent(Constants.UPDATE_DEVICE_BROADCAST));
BroadcastUtils.Companion.sendUpdateDeviceBroadcast(requireContext());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SearchDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
super.onCreateDialog(savedInstanceState)

val inflater = activity!!.layoutInflater
val inflater = requireActivity().layoutInflater

val view: View = inflater.inflate(R.layout.dialog_fragment_search, null)
val searchEditText: EditText = view.findViewById(R.id.ip_address_text)
Expand All @@ -50,7 +50,7 @@ class SearchDialog : DialogFragment() {
dismiss()
}

var builder: AlertDialog.Builder = AlertDialog.Builder(activity)
val builder = AlertDialog.Builder(activity)
builder.setView(view)
builder.setTitle(getString(R.string.action_search))
//builder.setMessage(getString(R.string.search_help))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package wseemann.media.romote.fragment

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.KeyEvent
import android.view.LayoutInflater
Expand All @@ -23,6 +24,7 @@ class StoreFragment : Fragment() {
return view
}

@SuppressLint("SetJavaScriptEnabled")
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
mWebView.loadUrl("https://channelstore.roku.com/browse")
Expand All @@ -31,7 +33,7 @@ class StoreFragment : Fragment() {
mWebView.settings.javaScriptCanOpenWindowsAutomatically = true
}

fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
fun onKeyDown(keyCode: Int): Boolean {
// Check if the key event was the Back button and if there's history
if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {
mWebView.goBack()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public void onCreate(Bundle savedInstanceState) {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = getActivity().getLayoutInflater();
LayoutInflater inflater = requireActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.dialog_fragment_test_input, null);
mTextBox = (EditText) view.findViewById(R.id.text_box);
mTextBox = view.findViewById(R.id.text_box);

setupTextBox();

Expand All @@ -72,7 +72,7 @@ public void onStart() {
private void showSoftKeyboard(final View view) {
if (view.requestFocus()) {
final InputMethodManager imm = (InputMethodManager)
getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
requireContext().getSystemService(Context.INPUT_METHOD_SERVICE);

view.postDelayed(() -> {
view.requestFocus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public void onReceive(Context context, Intent intent) {
if (intent != null) {
String url = commandHelper.getDeviceURL();
KeyPressKeyValues keypressKeyValues = (KeyPressKeyValues) intent.getSerializableExtra("keypress");

if (keypressKeyValues == null) {
return;
}

KeyPressRequest keypressRequest = new KeyPressRequest(url, keypressKeyValues.getValue());
keypressRequest.sendAsync(new ResponseCallback<>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import java.util.List;
import java.util.concurrent.Callable;

import wseemann.media.romote.fragment.MainFragment;
import wseemann.media.romote.model.Device;
import wseemann.media.romote.utils.BroadcastUtils;
import wseemann.media.romote.utils.Constants;
import wseemann.media.romote.utils.DBUtils;
import wseemann.media.romote.utils.PreferenceUtils;
Expand Down Expand Up @@ -51,7 +53,7 @@ public Boolean call() {
for (Device device: devices) {
if (device.getSerialNumber().equals(connectedDevice.getSerialNumber())) {
DBUtils.updateDevice(context, device);
context.sendBroadcast(new Intent(Constants.UPDATE_DEVICE_BROADCAST));
BroadcastUtils.Companion.sendUpdateDeviceBroadcast(context);
break;
}
}
Expand Down
Loading

0 comments on commit 6c91e83

Please sign in to comment.