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();
}
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);
}
}
Aggregations