Search in sources :

Example 1 with SynchronizationProviderViewData

use of de.danoeh.antennapod.core.sync.SynchronizationProviderViewData in project AntennaPod by AntennaPod.

the class SynchronizationPreferencesFragment method chooseProviderAndLogin.

private void chooseProviderAndLogin() {
    AlertDialog.Builder builder = new AlertDialog.Builder(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) {

        ViewHolder holder;

        class ViewHolder {

            ImageView icon;

            TextView title;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            final LayoutInflater inflater = LayoutInflater.from(getContext());
            if (convertView == null) {
                convertView = inflater.inflate(R.layout.alertdialog_sync_provider_chooser, null);
                holder = new ViewHolder();
                holder.icon = (ImageView) convertView.findViewById(R.id.icon);
                holder.title = (TextView) convertView.findViewById(R.id.title);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            SynchronizationProviderViewData synchronizationProviderViewData = getItem(position);
            holder.title.setText(synchronizationProviderViewData.getSummaryResource());
            holder.icon.setImageResource(synchronizationProviderViewData.getIconResource());
            return convertView;
        }
    };
    builder.setAdapter(adapter, (dialog, which) -> {
        switch(providers[which]) {
            case GPODDER_NET:
                new GpodderAuthenticationFragment().show(getChildFragmentManager(), GpodderAuthenticationFragment.TAG);
                break;
            case NEXTCLOUD_GPODDER:
                new NextcloudAuthenticationFragment().show(getChildFragmentManager(), NextcloudAuthenticationFragment.TAG);
                break;
            default:
                break;
        }
        updateScreen();
    });
    AlertDialog dialog = builder.create();
    dialog.show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) ViewGroup(android.view.ViewGroup) SynchronizationProviderViewData(de.danoeh.antennapod.core.sync.SynchronizationProviderViewData) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ListAdapter(android.widget.ListAdapter) ArrayAdapter(android.widget.ArrayAdapter)

Example 2 with SynchronizationProviderViewData

use of de.danoeh.antennapod.core.sync.SynchronizationProviderViewData in project AntennaPod by AntennaPod.

the class SynchronizationPreferencesFragment method updateScreen.

private void updateScreen() {
    final boolean loggedIn = SynchronizationSettings.isProviderConnected();
    Preference preferenceHeader = findPreference(PREFERENCE_SYNCHRONIZATION_DESCRIPTION);
    if (loggedIn) {
        SynchronizationProviderViewData selectedProvider = SynchronizationProviderViewData.fromIdentifier(getSelectedSyncProviderKey());
        preferenceHeader.setTitle("");
        preferenceHeader.setSummary(selectedProvider.getSummaryResource());
        preferenceHeader.setIcon(selectedProvider.getIconResource());
        preferenceHeader.setOnPreferenceClickListener(null);
    } else {
        preferenceHeader.setTitle(R.string.synchronization_choose_title);
        preferenceHeader.setSummary(R.string.synchronization_summary_unchoosen);
        preferenceHeader.setIcon(R.drawable.ic_cloud);
        preferenceHeader.setOnPreferenceClickListener((preference) -> {
            chooseProviderAndLogin();
            return true;
        });
    }
    Preference gpodnetSetLoginPreference = findPreference(PREFERENCE_GPODNET_SETLOGIN_INFORMATION);
    gpodnetSetLoginPreference.setVisible(isProviderSelected(SynchronizationProviderViewData.GPODDER_NET));
    gpodnetSetLoginPreference.setEnabled(loggedIn);
    findPreference(PREFERENCE_SYNC).setEnabled(loggedIn);
    findPreference(PREFERENCE_FORCE_FULL_SYNC).setEnabled(loggedIn);
    findPreference(PREFERENCE_LOGOUT).setEnabled(loggedIn);
    if (loggedIn) {
        String summary = getString(R.string.synchronization_login_status, SynchronizationCredentials.getUsername(), SynchronizationCredentials.getHosturl());
        Spanned formattedSummary = HtmlCompat.fromHtml(summary, HtmlCompat.FROM_HTML_MODE_LEGACY);
        findPreference(PREFERENCE_LOGOUT).setSummary(formattedSummary);
        updateLastSyncReport(SynchronizationSettings.isLastSyncSuccessful(), SynchronizationSettings.getLastSyncAttempt());
    } else {
        findPreference(PREFERENCE_LOGOUT).setSummary(null);
        ((PreferenceActivity) getActivity()).getSupportActionBar().setSubtitle(null);
    }
}
Also used : Preference(androidx.preference.Preference) SynchronizationProviderViewData(de.danoeh.antennapod.core.sync.SynchronizationProviderViewData) Spanned(android.text.Spanned)

Aggregations

SynchronizationProviderViewData (de.danoeh.antennapod.core.sync.SynchronizationProviderViewData)2 Spanned (android.text.Spanned)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 ArrayAdapter (android.widget.ArrayAdapter)1 ImageView (android.widget.ImageView)1 ListAdapter (android.widget.ListAdapter)1 TextView (android.widget.TextView)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 Preference (androidx.preference.Preference)1