summaryrefslogtreecommitdiff
path: root/ui/preferences/src/main/java
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2024-04-05 20:08:25 +0200
committerGitHub <noreply@github.com>2024-04-05 20:08:25 +0200
commit687db0f5ed13ab0ee4e3a9c09f85359d987a13c0 (patch)
tree0c2894e2a4abaec08eef2d6e2fd8047127a05d57 /ui/preferences/src/main/java
parentb6a4049ff4a792cbed826320064ccca72fc3e6e5 (diff)
downloadAntennaPod-687db0f5ed13ab0ee4e3a9c09f85359d987a13c0.zip
Merge :net:sync:model and :net:sync:service-interface (#7063)
Diffstat (limited to 'ui/preferences/src/main/java')
-rw-r--r--ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/synchronization/GpodderAuthenticationFragment.java4
-rw-r--r--ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/synchronization/NextcloudAuthenticationFragment.java4
-rw-r--r--ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/synchronization/SynchronizationPreferencesFragment.java49
3 files changed, 40 insertions, 17 deletions
diff --git a/ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/synchronization/GpodderAuthenticationFragment.java b/ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/synchronization/GpodderAuthenticationFragment.java
index 204287207..a2f210f2e 100644
--- a/ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/synchronization/GpodderAuthenticationFragment.java
+++ b/ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/synchronization/GpodderAuthenticationFragment.java
@@ -20,7 +20,7 @@ import androidx.fragment.app.DialogFragment;
import com.google.android.material.button.MaterialButton;
import de.danoeh.antennapod.net.common.AntennapodHttpClient;
import de.danoeh.antennapod.net.sync.service.SyncService;
-import de.danoeh.antennapod.net.sync.serviceinterface.SynchronizationProviderViewData;
+import de.danoeh.antennapod.net.sync.serviceinterface.SynchronizationProvider;
import de.danoeh.antennapod.net.sync.serviceinterface.SynchronizationQueueSink;
import de.danoeh.antennapod.storage.preferences.SynchronizationCredentials;
import de.danoeh.antennapod.storage.preferences.SynchronizationSettings;
@@ -257,7 +257,7 @@ public class GpodderAuthenticationFragment extends DialogFragment {
throw new IllegalStateException("Device must not be null here");
} else {
SynchronizationSettings.setSelectedSyncProvider(
- SynchronizationProviderViewData.GPODDER_NET.getIdentifier());
+ SynchronizationProvider.GPODDER_NET.getIdentifier());
SynchronizationCredentials.setUsername(username);
SynchronizationCredentials.setPassword(password);
SynchronizationCredentials.setDeviceId(selectedDevice.getId());
diff --git a/ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/synchronization/NextcloudAuthenticationFragment.java b/ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/synchronization/NextcloudAuthenticationFragment.java
index c503ccef1..5df85efe2 100644
--- a/ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/synchronization/NextcloudAuthenticationFragment.java
+++ b/ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/synchronization/NextcloudAuthenticationFragment.java
@@ -10,7 +10,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import androidx.fragment.app.DialogFragment;
import de.danoeh.antennapod.net.common.AntennapodHttpClient;
import de.danoeh.antennapod.net.sync.service.SyncService;
-import de.danoeh.antennapod.net.sync.serviceinterface.SynchronizationProviderViewData;
+import de.danoeh.antennapod.net.sync.serviceinterface.SynchronizationProvider;
import de.danoeh.antennapod.net.sync.serviceinterface.SynchronizationQueueSink;
import de.danoeh.antennapod.storage.preferences.SynchronizationCredentials;
import de.danoeh.antennapod.storage.preferences.SynchronizationSettings;
@@ -89,7 +89,7 @@ public class NextcloudAuthenticationFragment extends DialogFragment
@Override
public void onNextcloudAuthenticated(String server, String username, String password) {
SynchronizationSettings.setSelectedSyncProvider(
- SynchronizationProviderViewData.NEXTCLOUD_GPODDER.getIdentifier());
+ SynchronizationProvider.NEXTCLOUD_GPODDER.getIdentifier());
SynchronizationCredentials.clear();
SynchronizationQueueSink.clearQueue(getContext());
SynchronizationCredentials.setPassword(password);
diff --git a/ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/synchronization/SynchronizationPreferencesFragment.java b/ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/synchronization/SynchronizationPreferencesFragment.java
index c8c993cbc..709f3e43b 100644
--- a/ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/synchronization/SynchronizationPreferencesFragment.java
+++ b/ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/synchronization/SynchronizationPreferencesFragment.java
@@ -12,7 +12,9 @@ import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;
+import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
+import androidx.annotation.StringRes;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import androidx.core.text.HtmlCompat;
@@ -22,7 +24,7 @@ import androidx.preference.PreferenceFragmentCompat;
import com.google.android.material.snackbar.Snackbar;
import de.danoeh.antennapod.net.sync.service.SyncService;
-import de.danoeh.antennapod.net.sync.serviceinterface.SynchronizationProviderViewData;
+import de.danoeh.antennapod.net.sync.serviceinterface.SynchronizationProvider;
import de.danoeh.antennapod.net.sync.serviceinterface.SynchronizationQueueSink;
import de.danoeh.antennapod.ui.preferences.R;
import org.greenrobot.eventbus.EventBus;
@@ -114,11 +116,11 @@ public class SynchronizationPreferencesFragment extends PreferenceFragmentCompat
final boolean loggedIn = SynchronizationSettings.isProviderConnected();
Preference preferenceHeader = findPreference(PREFERENCE_SYNCHRONIZATION_DESCRIPTION);
if (loggedIn) {
- SynchronizationProviderViewData selectedProvider =
- SynchronizationProviderViewData.fromIdentifier(getSelectedSyncProviderKey());
+ SynchronizationProvider selectedProvider =
+ SynchronizationProvider.fromIdentifier(getSelectedSyncProviderKey());
preferenceHeader.setTitle("");
- preferenceHeader.setSummary(selectedProvider.getSummaryResource());
- preferenceHeader.setIcon(selectedProvider.getIconResource());
+ preferenceHeader.setSummary(getProviderSummary(selectedProvider));
+ preferenceHeader.setIcon(getProviderIcon(selectedProvider));
preferenceHeader.setOnPreferenceClickListener(null);
} else {
preferenceHeader.setTitle(R.string.synchronization_choose_title);
@@ -131,7 +133,7 @@ public class SynchronizationPreferencesFragment extends PreferenceFragmentCompat
}
Preference gpodnetSetLoginPreference = findPreference(PREFERENCE_GPODNET_SETLOGIN_INFORMATION);
- gpodnetSetLoginPreference.setVisible(isProviderSelected(SynchronizationProviderViewData.GPODDER_NET));
+ gpodnetSetLoginPreference.setVisible(isProviderSelected(SynchronizationProvider.GPODDER_NET));
gpodnetSetLoginPreference.setEnabled(loggedIn);
findPreference(PREFERENCE_SYNC).setEnabled(loggedIn);
findPreference(PREFERENCE_FORCE_FULL_SYNC).setEnabled(loggedIn);
@@ -153,9 +155,8 @@ public class SynchronizationPreferencesFragment extends PreferenceFragmentCompat
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getContext());
builder.setTitle(R.string.dialog_choose_sync_service_title);
- SynchronizationProviderViewData[] providers = SynchronizationProviderViewData.values();
- ListAdapter adapter = new ArrayAdapter<SynchronizationProviderViewData>(
- getContext(), R.layout.alertdialog_sync_provider_chooser, providers) {
+ SynchronizationProvider[] providers = SynchronizationProvider.values();
+ ListAdapter adapter = new ArrayAdapter<>(getContext(), R.layout.alertdialog_sync_provider_chooser, providers) {
ViewHolder holder;
@@ -177,9 +178,9 @@ public class SynchronizationPreferencesFragment extends PreferenceFragmentCompat
} else {
holder = (ViewHolder) convertView.getTag();
}
- SynchronizationProviderViewData synchronizationProviderViewData = getItem(position);
- holder.title.setText(synchronizationProviderViewData.getSummaryResource());
- holder.icon.setImageResource(synchronizationProviderViewData.getIconResource());
+ SynchronizationProvider synchronizationProvider = getItem(position);
+ holder.title.setText(getProviderSummary(synchronizationProvider));
+ holder.icon.setImageResource(getProviderIcon(synchronizationProvider));
return convertView;
}
};
@@ -203,7 +204,7 @@ public class SynchronizationPreferencesFragment extends PreferenceFragmentCompat
builder.show();
}
- private boolean isProviderSelected(@NonNull SynchronizationProviderViewData provider) {
+ private boolean isProviderSelected(@NonNull SynchronizationProvider provider) {
String selectedSyncProviderKey = getSelectedSyncProviderKey();
return provider.getIdentifier().equals(selectedSyncProviderKey);
}
@@ -219,4 +220,26 @@ public class SynchronizationPreferencesFragment extends PreferenceFragmentCompat
lastTime, DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, DateUtils.FORMAT_SHOW_TIME));
((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(status);
}
+
+ private @StringRes int getProviderSummary(SynchronizationProvider provider) {
+ switch (provider) {
+ case GPODDER_NET:
+ return R.string.gpodnet_description;
+ case NEXTCLOUD_GPODDER:
+ return R.string.synchronization_summary_nextcloud;
+ default:
+ return R.string.sync_status_error;
+ }
+ }
+
+ private @DrawableRes int getProviderIcon(SynchronizationProvider provider) {
+ switch (provider) {
+ case GPODDER_NET:
+ return R.drawable.gpodder_icon;
+ case NEXTCLOUD_GPODDER:
+ return R.drawable.nextcloud_logo;
+ default:
+ return R.drawable.ic_error;
+ }
+ }
}