mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-22 20:24:03 -04:00
Refactor: Remove changeDeviceName() and related code
Device name for WiFi Direct is supposed to be changed manually (from the advanced wifi settings) by the user. This solution used reflection to access the hidden method used by the system to perform the same. However use of non-SDK interfaces (fields/methods accessed using reflection) will be restricted and subsequently lead to exceptions, hence the feature needs to be removed. For more: developer.android.com/distribute/best-practices/develop/restrictions-non-sdk-interfaces
This commit is contained in:
parent
26c92ee64e
commit
7759a4eb47
@ -92,32 +92,6 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
this.setListAdapter(new WifiPeerListAdapter(getActivity(), R.layout.row_peer_device, peerDevices));
|
||||
|
||||
ImageButton editUserDeviceName = getActivity().findViewById(R.id.btn_edit_device_name);
|
||||
editUserDeviceName.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if(userDevice != null) {
|
||||
//TODO: Dialog to take input & call this method:
|
||||
//((DeviceActionListener) getActivity()).changeDeviceName("Sood");
|
||||
|
||||
if(((LocalFileTransferActivity) getActivity()).isWifiP2pEnabled()) {
|
||||
FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction();
|
||||
Fragment prev = getActivity().getSupportFragmentManager().findFragmentByTag("EditDeviceNameDialog");
|
||||
if (prev != null) {
|
||||
fragmentTransaction.remove(prev); // To prevent multiple instances of the DialogFragment
|
||||
}
|
||||
fragmentTransaction.addToBackStack(null);
|
||||
|
||||
EditDeviceNameDialog dialogFragment = new EditDeviceNameDialog();
|
||||
// For DialogFragments, show() handles the fragment commit and display
|
||||
dialogFragment.show(fragmentTransaction, "EditDeviceNameDialog");
|
||||
} else {
|
||||
Toast.makeText(getActivity(), "Enable WiFi P2P to change device name", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(((LocalFileTransferActivity) getActivity()).isFileSender()) {
|
||||
fileSender = true;
|
||||
fileUriList = ((LocalFileTransferActivity) getActivity()).getFileURIArrayList();
|
||||
@ -359,7 +333,7 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
|
||||
public interface DeviceActionListener {
|
||||
|
||||
void changeDeviceName(String deviceNewName);
|
||||
/*void changeDeviceName(String deviceNewName);*/
|
||||
|
||||
/*void showDetails(WifiP2pDevice device);*/
|
||||
|
||||
@ -372,41 +346,6 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
||||
void closeLocalFileTransferActivity();
|
||||
}
|
||||
|
||||
public static class EditDeviceNameDialog extends DialogFragment {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
|
||||
builder.setView(R.layout.dialog_edit_device_name)
|
||||
.setPositiveButton("Update", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
EditText changeDeviceName = EditDeviceNameDialog.this.getDialog().findViewById(R.id.edit_text_change_device_name);
|
||||
String deviceNewName = changeDeviceName.getText().toString();
|
||||
//Toast.makeText(getActivity(), "Changing name to: " + deviceNewName.getText().toString(), Toast.LENGTH_SHORT).show();
|
||||
|
||||
if(deviceNewName != null && !deviceNewName.equals("")) {
|
||||
((DeviceActionListener) getActivity()).changeDeviceName(deviceNewName);
|
||||
} else {
|
||||
Toast.makeText(getActivity(), "Error: Empty name field", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
//dialog.cancel();
|
||||
}
|
||||
})
|
||||
.setNeutralButton("Dismiss", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return builder.create();
|
||||
}
|
||||
}
|
||||
|
||||
public static class PeerGroupHandshakeAsyncTask extends AsyncTask<Void, Void, InetAddress> {
|
||||
|
||||
private DeviceListFragment deviceListFragment;
|
||||
|
@ -519,30 +519,6 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove this feature since reflection of hidden methods/fields is restricted from Pie (& will subsequently lead to exceptions)
|
||||
@Override
|
||||
public void changeDeviceName(String deviceNewName) {
|
||||
try {
|
||||
Method method = manager.getClass().getMethod("setDeviceName", WifiP2pManager.Channel.class, String.class, WifiP2pManager.ActionListener.class);
|
||||
method.invoke(manager, channel, deviceNewName, new WifiP2pManager.ActionListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
Toast.makeText(LocalFileTransferActivity.this, "Name successfully changed", Toast.LENGTH_LONG).show();
|
||||
resetPeers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int reason) {
|
||||
Toast.makeText(LocalFileTransferActivity.this, "Request failed: " + reason, Toast.LENGTH_SHORT).show();
|
||||
Log.d(TAG, "Name change failed: " + getErrorMessage(reason));
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFileSender() {
|
||||
return fileSendingDevice;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
android:textStyle="italic"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toLeftOf="@id/btn_edit_device_name"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
@ -28,7 +28,7 @@
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintTop_toBottomOf="@+id/text_view_your_device"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toLeftOf="@id/btn_edit_device_name"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
android:text="Device Name"
|
||||
android:textStyle="bold"
|
||||
android:textSize="17sp"
|
||||
@ -43,7 +43,7 @@
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintTop_toBottomOf="@+id/text_view_device_name"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toLeftOf="@id/btn_edit_device_name"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
android:text="Status"
|
||||
android:textSize="15sp"
|
||||
android:layout_marginLeft="15dp"
|
||||
@ -62,23 +62,6 @@
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginRight="5dp"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btn_edit_device_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:srcCompat="@drawable/ic_baseline_edit_24px"
|
||||
android:tooltipText="Edit Name"
|
||||
android:background="@android:color/transparent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/view_device_list_boundary"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingStart="15dp"
|
||||
android:paddingRight="5dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginEnd="20dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_view_available_device"
|
||||
android:layout_width="match_parent"
|
||||
|
Loading…
x
Reference in New Issue
Block a user