Skip to content

Commit

Permalink
ask user first time for syncronization service to be used
Browse files Browse the repository at this point in the history
  • Loading branch information
thrillfall committed Jul 2, 2021
1 parent 0ddf911 commit 0011604
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 59 deletions.
Expand Up @@ -30,7 +30,6 @@
import de.danoeh.antennapod.fragment.preferences.NotificationPreferencesFragment;
import de.danoeh.antennapod.fragment.preferences.PlaybackPreferencesFragment;
import de.danoeh.antennapod.fragment.preferences.StoragePreferencesFragment;
import de.danoeh.antennapod.fragment.preferences.SynchronizationPreferencesFragment;
import de.danoeh.antennapod.fragment.preferences.UserInterfacePreferencesFragment;

/**
Expand Down Expand Up @@ -78,11 +77,9 @@ private PreferenceFragmentCompat getPreferenceScreen(int screen) {
prefFragment = new ImportExportPreferencesFragment();
} else if (screen == R.xml.preferences_autodownload) {
prefFragment = new AutoDownloadPreferencesFragment();
} else if (screen == R.xml.preferences_synchronization) {
prefFragment = new SynchronizationPreferencesFragment();
} else if (screen == R.xml.preferences_gpodder) {
prefFragment = new GpodderPreferencesFragment();
} else if (screen == R.xml.preferences_nextcloud_gpodder) {
} else if (screen == R.xml.preferences_nextcloud) {
prefFragment = new NextcloudPreferencesFragment();
} else if (screen == R.xml.preferences_playback) {
prefFragment = new PlaybackPreferencesFragment();
Expand Down
@@ -1,8 +1,13 @@
package de.danoeh.antennapod.fragment.preferences;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
Expand All @@ -16,6 +21,7 @@
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.fragment.preferences.about.AboutFragment;


public class MainPreferencesFragment extends PreferenceFragmentCompat {
private static final String TAG = "MainPreferencesFragment";

Expand All @@ -32,6 +38,9 @@ public class MainPreferencesFragment extends PreferenceFragmentCompat {
private static final String PREF_ABOUT = "prefAbout";
private static final String PREF_NOTIFICATION = "notifications";
private static final String PREF_CONTRIBUTE = "prefContribute";
private static final String SYNC_SERVICE_CHOICE_GPODDER_NET = "GPodder.net";
private static final String SHARED_PREFERENCES_SYNCHRONIZATION = "synchronization";
private static final String SELECTED_SERVICE = "selected_service";

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
Expand Down Expand Up @@ -75,7 +84,37 @@ private void setupMainScreen() {
return true;
});
findPreference(PREF_SCREEN_SYNCHRONIZATION).setOnPreferenceClickListener(preference -> {
((PreferenceActivity) getActivity()).openScreen(R.xml.preferences_synchronization);
SharedPreferences preferences = getActivity().getSharedPreferences(SHARED_PREFERENCES_SYNCHRONIZATION, Activity.MODE_PRIVATE);
String selectedService = preferences.getString(SELECTED_SERVICE, null);
if (selectedService == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(R.string.dialog_choose_sync_service_title);
String[] syncServiceNames = {SYNC_SERVICE_CHOICE_GPODDER_NET, "Nextcloud"};
builder.setItems(syncServiceNames, (dialog, which) -> {
String userSelect = SYNC_SERVICE_CHOICE_GPODDER_NET;
switch (which) {
case 0: break;
case 1:
userSelect = "Nextcloud";
break;
}
preferences.edit().putString(SELECTED_SERVICE, userSelect).apply();
if (userSelect.equals(SYNC_SERVICE_CHOICE_GPODDER_NET)) {
((PreferenceActivity) getActivity()).openScreen(R.xml.preferences_gpodder);
return;
}
((PreferenceActivity) getActivity()).openScreen(R.xml.preferences_nextcloud);
});
AlertDialog dialog = builder.create();
dialog.show();
return true;
}

if (selectedService.equals(SYNC_SERVICE_CHOICE_GPODDER_NET)) {
((PreferenceActivity) getActivity()).openScreen(R.xml.preferences_gpodder);
return true;
}
((PreferenceActivity) getActivity()).openScreen(R.xml.preferences_nextcloud);
return true;
});
findPreference(PREF_SCREEN_STORAGE).setOnPreferenceClickListener(preference -> {
Expand Down
Expand Up @@ -30,15 +30,15 @@ public class NextcloudPreferencesFragment extends PreferenceFragmentCompat {

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.preferences_nextcloud_gpodder);
setupGpodderScreen();
addPreferencesFromResource(R.xml.preferences_nextcloud);
setupNextcloudScreen();
}

@Override
public void onStart() {
super.onStart();
((PreferenceActivity) getActivity()).getSupportActionBar().setTitle("Nextcloud GPodder");
updateGpodnetPreferenceScreen();
updateNextcloudPreferenceScreen();
EventBus.getDefault().register(this);
}

Expand All @@ -51,7 +51,7 @@ public void onStop() {

@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
public void syncStatusChanged(SyncServiceEvent event) {
updateGpodnetPreferenceScreen();
updateNextcloudPreferenceScreen();
if (event.getMessageResId() == R.string.sync_status_error
|| event.getMessageResId() == R.string.sync_status_success) {
updateLastGpodnetSyncReport(SyncService.isLastSyncSuccessful(getContext()),
Expand All @@ -61,10 +61,10 @@ public void syncStatusChanged(SyncServiceEvent event) {
}
}

private void setupGpodderScreen() {
private void setupNextcloudScreen() {
findPreference(PREF_GPODNET_LOGIN).setOnPreferenceClickListener(preference -> {
openAccountChooser();
updateGpodnetPreferenceScreen();
updateNextcloudPreferenceScreen();
return true;
});
findPreference(PREF_GPODNET_SYNC).setOnPreferenceClickListener(preference -> {
Expand All @@ -76,14 +76,13 @@ private void setupGpodderScreen() {
return true;
});
findPreference(PREF_GPODNET_LOGOUT).setOnPreferenceClickListener(preference -> {
//@todo unset nextcloud account
SingleAccountHelper.setCurrentAccount(getContext(), null);
updateGpodnetPreferenceScreen();
updateNextcloudPreferenceScreen();
return true;
});
}

private void updateGpodnetPreferenceScreen() {
private void updateNextcloudPreferenceScreen() {
boolean loggedIn = false;
String ssoAccountName = "n/a";
try {
Expand Down

This file was deleted.

12 changes: 12 additions & 0 deletions app/src/main/res/layout/sync_service_selection_textview.xml
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sync_service_selection_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="?android:attr/textColorAlertDialogListItem" />
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name" translate="false">AntennaPod</string>
<string name="dialog_choose_sync_service_title">Choose syncronization service</string>
</resources>
6 changes: 3 additions & 3 deletions app/src/main/res/xml/preferences_synchronization.xml
Expand Up @@ -10,9 +10,9 @@
android:icon="@drawable/gpodder_icon" />

<Preference
android:key="prefScreenNextcloudGpodder"
android:title="Nextcloud GPodder app"
android:summary="Synchronize with Nextcloud GPodder app"
android:key="prefScreenNextcloud"
android:title="Nextcloud"
android:summary="Synchronize with Nextcloud"
android:icon="@drawable/nextcloud_logo_svg" />

</PreferenceScreen>

0 comments on commit 0011604

Please sign in to comment.