From 687db0f5ed13ab0ee4e3a9c09f85359d987a13c0 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Fri, 5 Apr 2024 20:08:25 +0200 Subject: Merge :net:sync:model and :net:sync:service-interface (#7063) --- ui/preferences/build.gradle | 1 - .../GpodderAuthenticationFragment.java | 4 +- .../NextcloudAuthenticationFragment.java | 4 +- .../SynchronizationPreferencesFragment.java | 49 +++++++++++++++------ .../src/main/res/drawable-nodpi/gpodder_icon.png | Bin 0 -> 32098 bytes .../src/main/res/drawable-nodpi/nextcloud_logo.png | Bin 0 -> 3432 bytes 6 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 ui/preferences/src/main/res/drawable-nodpi/gpodder_icon.png create mode 100644 ui/preferences/src/main/res/drawable-nodpi/nextcloud_logo.png (limited to 'ui/preferences') diff --git a/ui/preferences/build.gradle b/ui/preferences/build.gradle index eb595da58..fd9684e56 100644 --- a/ui/preferences/build.gradle +++ b/ui/preferences/build.gradle @@ -25,7 +25,6 @@ android { dependencies { implementation project(":event") implementation project(":net:common") - implementation project(":net:sync:model") implementation project(":net:sync:gpoddernet") implementation project(":storage:preferences") implementation project(":storage:importexport") 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( - 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; + } + } } diff --git a/ui/preferences/src/main/res/drawable-nodpi/gpodder_icon.png b/ui/preferences/src/main/res/drawable-nodpi/gpodder_icon.png new file mode 100644 index 000000000..cd133aa98 Binary files /dev/null and b/ui/preferences/src/main/res/drawable-nodpi/gpodder_icon.png differ diff --git a/ui/preferences/src/main/res/drawable-nodpi/nextcloud_logo.png b/ui/preferences/src/main/res/drawable-nodpi/nextcloud_logo.png new file mode 100644 index 000000000..2164e37fb Binary files /dev/null and b/ui/preferences/src/main/res/drawable-nodpi/nextcloud_logo.png differ -- cgit v1.2.3