Revert back to device selection instead of linking

Until this is fixed upstream on the gpodder.net server.
This commit is contained in:
ByteHamster 2021-01-02 11:03:57 +01:00
parent 7b8208a2a7
commit 34e9c31899
5 changed files with 37 additions and 81 deletions

View File

@ -34,7 +34,6 @@ import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
@ -61,7 +60,6 @@ public class GpodderAuthenticationFragment extends DialogFragment {
private volatile String password;
private volatile GpodnetDevice selectedDevice;
private List<GpodnetDevice> devices;
private List<List<String>> synchronizedDevices;
@NonNull
@Override
@ -137,7 +135,6 @@ public class GpodderAuthenticationFragment extends DialogFragment {
Completable.fromAction(() -> {
service.authenticate(usernameStr, passwordStr);
devices = service.getDevices();
synchronizedDevices = service.getSynchronizedDevices();
GpodderAuthenticationFragment.this.username = usernameStr;
GpodderAuthenticationFragment.this.password = passwordStr;
})
@ -159,55 +156,40 @@ public class GpodderAuthenticationFragment extends DialogFragment {
private void setupDeviceView(View view) {
final EditText deviceName = view.findViewById(R.id.deviceName);
final LinearLayout deviceGroups = view.findViewById(R.id.deviceGroups);
final LinearLayout devicesContainer = view.findViewById(R.id.devicesContainer);
deviceName.setText(generateDeviceName());
MaterialButton newGroupButton = view.findViewById(R.id.startNewGroupButton);
newGroupButton.setOnClickListener(v -> createDevice(view, null));
MaterialButton createDeviceButton = view.findViewById(R.id.createDeviceButton);
createDeviceButton.setOnClickListener(v -> createDevice(view));
for (List<String> syncGroup : synchronizedDevices) {
StringBuilder devicesString = new StringBuilder();
for (int i = 0; i < syncGroup.size(); i++) {
String deviceId = syncGroup.get(i);
devicesString.append(findDevice(deviceId).getCaption());
if (i != syncGroup.size() - 1) {
devicesString.append("\n");
}
}
View groupView = View.inflate(getContext(), R.layout.gpodnetauth_device_group, null);
((TextView) groupView.findViewById(R.id.groupContents)).setText(devicesString.toString());
groupView.findViewById(R.id.selectGroupButton).setOnClickListener(v -> createDevice(view, syncGroup));
deviceGroups.addView(groupView);
for (GpodnetDevice device : devices) {
View row = View.inflate(getContext(), R.layout.gpodnetauth_device_row, null);
Button selectDeviceButton = row.findViewById(R.id.selectDeviceButton);
selectDeviceButton.setOnClickListener(v -> {
selectedDevice = device;
advance();
});
selectDeviceButton.setText(device.getCaption());
devicesContainer.addView(row);
}
}
private void createDevice(View view, List<String> group) {
private void createDevice(View view) {
final EditText deviceName = view.findViewById(R.id.deviceName);
final TextView txtvError = view.findViewById(R.id.deviceSelectError);
final ProgressBar progBarCreateDevice = view.findViewById(R.id.progbarCreateDevice);
final LinearLayout deviceGroups = view.findViewById(R.id.deviceGroups);
final MaterialButton newGroupButton = view.findViewById(R.id.startNewGroupButton);
String deviceNameStr = deviceName.getText().toString();
if (isDeviceInList(deviceNameStr)) {
return;
}
deviceGroups.setVisibility(View.GONE);
progBarCreateDevice.setVisibility(View.VISIBLE);
txtvError.setVisibility(View.GONE);
newGroupButton.setVisibility(View.GONE);
deviceName.setEnabled(false);
Observable.fromCallable(() -> {
String deviceId = generateDeviceId(deviceNameStr);
service.configureDevice(deviceId, deviceNameStr, GpodnetDevice.DeviceType.MOBILE);
if (group != null) {
List<String> newGroup = new ArrayList<>(group);
newGroup.add(deviceId);
service.linkDevices(newGroup);
}
return new GpodnetDevice(deviceId, deviceNameStr, GpodnetDevice.DeviceType.MOBILE.toString(), 0);
})
.subscribeOn(Schedulers.io())
@ -218,8 +200,6 @@ public class GpodderAuthenticationFragment extends DialogFragment {
advance();
}, error -> {
deviceName.setEnabled(true);
newGroupButton.setVisibility(View.VISIBLE);
deviceGroups.setVisibility(View.VISIBLE);
progBarCreateDevice.setVisibility(View.GONE);
txtvError.setText(error.getMessage());
txtvError.setVisibility(View.VISIBLE);

View File

@ -21,12 +21,19 @@
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/createDeviceButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|end"
android:text="@string/gpodnetauth_create_device"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/AntennaPod.TextView.Heading"
android:layout_marginTop="16dp"
android:text="@string/gpodnetauth_sync_groups"/>
android:text="@string/gpodnetauth_existing_devices"/>
<TextView
android:id="@+id/deviceSelectError"
@ -39,19 +46,11 @@
tools:background="@android:color/holo_green_dark" />
<LinearLayout
android:id="@+id/deviceGroups"
android:id="@+id/devicesContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
<Button
android:id="@+id/startNewGroupButton"
android:text="@string/gpodnetauth_sync_group_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?attr/materialButtonOutlinedStyle"
android:layout_gravity="right"/>
<ProgressBar
android:id="@+id/progbarCreateDevice"
android:layout_width="wrap_content"

View File

@ -1,35 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp">
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:strokeWidth="2dp"
app:strokeColor="?attr/currently_playing_background">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
<TextView
android:id="@+id/groupContents"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/selectGroupButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
style="?attr/borderlessButtonStyle"
android:text="@string/gpodnetauth_sync_group_select"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</FrameLayout>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp">
<Button
android:id="@+id/selectDeviceButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?attr/materialButtonOutlinedStyle" />
</FrameLayout>

View File

@ -642,9 +642,8 @@
<string name="gpodnetauth_device_name">Device name</string>
<string name="gpodnetauth_device_name_default">AntennaPod on %1$s</string>
<string name="gpodnetauth_device_caption_errorEmpty">Caption must not be empty</string>
<string name="gpodnetauth_sync_groups">Synchronization groups</string>
<string name="gpodnetauth_sync_group_select">Select</string>
<string name="gpodnetauth_sync_group_new">Use new group</string>
<string name="gpodnetauth_existing_devices">Existing devices</string>
<string name="gpodnetauth_create_device">Create device</string>
<string name="gpodnetauth_device_butChoose">Choose</string>
<string name="gpodnetauth_finish_descr">Congratulations! Your gpodder.net account is now linked with your device. AntennaPod will from now on automatically sync subscriptions on your device with your gpodder.net account.</string>