Implemented authentication process
This commit is contained in:
parent
6aaef3a285
commit
e29d117942
|
@ -367,6 +367,16 @@
|
|||
android:name=".activity.DefaultOnlineFeedViewActivity"
|
||||
android:configChanges="orientation"/>
|
||||
|
||||
<activity
|
||||
android:name=".activity.gpoddernet.GpodnetAuthenticationActivity"
|
||||
android:configChanges="orientation"
|
||||
android:label="@string/gpodnet_auth_label">
|
||||
<intent-filter>
|
||||
<action android:name=".activity.gpoddernet.GpodnetAuthenticationActivity"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<receiver android:name=".receiver.ConnectivityActionReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<ViewFlipper
|
||||
android:id="@+id/viewflipper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
</ScrollView>
|
|
@ -0,0 +1,84 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@id/txtvTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/gpodnetauth_login_title"
|
||||
android:layout_alignParentTop="true"
|
||||
android:textSize="@dimen/text_size_large"
|
||||
android:layout_margin="16dp"
|
||||
android:textColor="@color/bright_blue"
|
||||
android:textStyle="italic"/>
|
||||
|
||||
<TextView
|
||||
android:id="@id/txtvDescription"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/gpodnetauth_login_descr"
|
||||
android:layout_below="@id/txtvTitle"
|
||||
android:textSize="@dimen/text_size_medium"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:layout_margin="16dp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etxtUsername"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/gpodnet_username_label"
|
||||
android:layout_below="@id/txtvDescription"
|
||||
android:layout_margin="8dp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etxtPassword"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/gpodnet_password_label"
|
||||
android:layout_below="@id/etxtUsername"
|
||||
android:inputType="textPassword"
|
||||
android:layout_margin="8dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/butLogin"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/etxtPassword"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="@string/gpodnetauth_login_butLabel"
|
||||
android:layout_margin="8dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvError"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/etxtPassword"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignBottom="@id/butLogin"
|
||||
android:textColor="@color/download_failed_red"
|
||||
android:textSize="@dimen/text_size_medium"
|
||||
android:gravity="center"
|
||||
android:layout_margin="16dp"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progBarLogin"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toLeftOf="@id/butLogin"
|
||||
android:layout_below="@id/etxtPassword"
|
||||
android:layout_alignBottom="@id/butLogin"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="@dimen/text_size_medium"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:layout_margin="16dp"
|
||||
android:text="@string/gpodnetauth_login_register"
|
||||
android:autoLink="web"
|
||||
android:layout_below="@id/butLogin"/>
|
||||
</RelativeLayout>
|
|
@ -0,0 +1,107 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/gpodnetauth_device_title"
|
||||
android:layout_alignParentTop="true"
|
||||
android:textSize="@dimen/text_size_large"
|
||||
android:layout_margin="16dp"
|
||||
android:textColor="@color/bright_blue"
|
||||
android:textStyle="italic"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvDescription"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/gpodnetauth_device_descr"
|
||||
android:layout_below="@id/txtvTitle"
|
||||
android:textSize="@dimen/text_size_medium"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:layout_margin="16dp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etxtDeviceID"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/gpodnetauth_device_deviceID"
|
||||
android:layout_below="@id/txtvDescription"
|
||||
android:layout_margin="8dp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etxtCaption"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/gpodnetauth_device_caption"
|
||||
android:layout_below="@id/etxtDeviceID"
|
||||
android:layout_margin="8dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/butCreateNewDevice"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_below="@id/etxtCaption"
|
||||
android:text="@string/gpodnetauth_device_butCreateNewDevice"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvError"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_below="@id/etxtCaption"
|
||||
android:layout_alignBottom="@id/butCreateNewDevice"
|
||||
android:textColor="@color/download_failed_red"
|
||||
android:layout_margin="16dp"
|
||||
android:textSize="@dimen/text_size_medium"
|
||||
/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progbarCreateDevice"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_below="@id/etxtCaption"
|
||||
android:layout_alignBottom="@id/butCreateNewDevice"
|
||||
android:textColor="@color/download_failed_red"
|
||||
android:layout_margin="16dp"
|
||||
android:textSize="@dimen/text_size_medium"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvChooseExistingDevice"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/gpodnetauth_device_chooseExistingDevice"
|
||||
android:layout_below="@id/butCreateNewDevice"
|
||||
android:textSize="@dimen/text_size_medium"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:layout_margin="16dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/butChooseExistingDevice"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/txtvChooseExistingDevice"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_margin="16dp"
|
||||
android:text="@string/gpodnetauth_device_butChoose"/>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spinnerChooseDevice"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/txtvChooseExistingDevice"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_toLeftOf="@id/butChooseExistingDevice"
|
||||
|
||||
android:layout_margin="16dp"/>
|
||||
|
||||
</RelativeLayout>
|
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/gpodnetauth_finish_title"
|
||||
android:layout_alignParentTop="true"
|
||||
android:textSize="@dimen/text_size_large"
|
||||
android:layout_margin="16dp"
|
||||
android:textColor="@color/bright_blue"
|
||||
android:textStyle="italic"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvDescription"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/gpodnetauth_finish_descr"
|
||||
android:layout_below="@id/txtvTitle"
|
||||
android:textSize="@dimen/text_size_medium"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:layout_margin="16dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/butSyncNow"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/txtvDescription"
|
||||
android:layout_margin="16dp"
|
||||
android:text="@string/gpodnetauth_finish_butsyncnow"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/butGoMainscreen"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/butSyncNow"
|
||||
android:layout_margin="16dp"
|
||||
android:text="@string/gpodnetauth_finish_butgomainscreen"/>
|
||||
|
||||
</RelativeLayout>
|
|
@ -42,5 +42,4 @@
|
|||
<item>0</item>
|
||||
<item>1</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
|
@ -18,6 +18,7 @@
|
|||
<string name="download_log_label">Download log</string>
|
||||
<string name="playback_history_label">Playback history</string>
|
||||
<string name="gpodnet_main_label">gpodder.net</string>
|
||||
<string name="gpodnet_auth_label">gpodder.net login</string>
|
||||
|
||||
<!-- Webview actions -->
|
||||
<string name="open_in_browser_label">Open in browser</string>
|
||||
|
@ -154,6 +155,8 @@
|
|||
<string name="other_pref">Other</string>
|
||||
<string name="about_pref">About</string>
|
||||
<string name="queue_label">Queue</string>
|
||||
<string name="services_label">Services</string>
|
||||
<string name="flattr_label">Flattr</string>
|
||||
<string name="pref_pauseOnHeadsetDisconnect_sum">Pause playback when the headphones are disconnected</string>
|
||||
<string name="pref_followQueue_sum">Jump to next queue item when playback completes</string>
|
||||
<string name="playback_pref">Playback</string>
|
||||
|
@ -190,6 +193,8 @@
|
|||
<string name="pref_update_interval_hours_plural">hours</string>
|
||||
<string name="pref_update_interval_hours_singular">hour</string>
|
||||
<string name="pref_update_interval_hours_manual">Manual</string>
|
||||
<string name="pref_gpodnet_authenticate_title">Login</string>
|
||||
<string name="pref_gpodnet_authenticate_sum">Login with your gpodder.net account in order to sync your subscriptions.</string>
|
||||
|
||||
|
||||
<!-- Search -->
|
||||
|
@ -242,6 +247,26 @@
|
|||
<string name="gpodnet_taglist_header">CATEGORIES</string>
|
||||
<string name="gpodnet_toplist_header">TOP PODCASTS</string>
|
||||
<string name="gpodnet_search_hint">Search gpodder.net</string>
|
||||
<string name="gpodnetauth_login_title">Login</string>
|
||||
<string name="gpodnetauth_login_descr">Welcome to the gpodder.net login process. First, type in your login information:</string>
|
||||
<string name="gpodnetauth_login_butLabel">Login</string>
|
||||
<string name="gpodnetauth_login_register">If you do not have an account yet, you can create one here:\nhttps://gpodder.net/register/</string>
|
||||
<string name="gpodnet_username_label">Username</string>
|
||||
<string name="gpodnet_password_label">Password</string>
|
||||
<string name="gpodnetauth_device_title">Device Selection</string>
|
||||
<string name="gpodnetauth_device_descr">Create a new device to use for your gpodder.net account or choose an existing one:</string>
|
||||
<string name="gpodnetauth_device_deviceID">Device ID</string>
|
||||
<string name="gpodnetauth_device_caption">Caption</string>
|
||||
<string name="gpodnetauth_device_butCreateNewDevice">Create new device</string>
|
||||
<string name="gpodnetauth_device_chooseExistingDevice">Choose existring device:</string>
|
||||
<string name="gpodnetauth_device_errorEmpty">Device ID must not be empty</string>
|
||||
<string name="gpodnetauth_device_errorAlreadyUsed">Device ID already in use</string>
|
||||
|
||||
<string name="gpodnetauth_device_butChoose">Choose</string>
|
||||
<string name="gpodnetauth_finish_title">Login successful!</string>
|
||||
<string name="gpodnetauth_finish_descr">Congratulations! Your gpodder.net account is now linked with your device. AntennaPod will from now on automagically sync subscriptions on your device with your gpodder.net account.</string>
|
||||
<string name="gpodnetauth_finish_butsyncnow">Start sync now</string>
|
||||
<string name="gpodnetauth_finish_butgomainscreen">Go to main screen</string>
|
||||
|
||||
<!-- Directory chooser -->
|
||||
<string name="selected_folder_label">Selected folder:</string>
|
||||
|
|
|
@ -1,67 +1,115 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<PreferenceCategory android:title="@string/user_interface_label">
|
||||
<CheckBoxPreference android:title="@string/pref_display_only_episodes_title" android:summary="@string/pref_display_only_episodes_sum" android:key="prefDisplayOnlyEpisodes"/>
|
||||
<ListPreference android:entryValues="@array/theme_values" android:entries="@array/theme_options" android:title="@string/pref_set_theme_title" android:key="prefTheme" android:summary="@string/pref_set_theme_sum" android:defaultValue="0"/>
|
||||
</PreferenceCategory><PreferenceCategory android:title="@string/playback_pref" >
|
||||
<CheckBoxPreference
|
||||
android:title="@string/pref_display_only_episodes_title"
|
||||
android:summary="@string/pref_display_only_episodes_sum"
|
||||
android:key="prefDisplayOnlyEpisodes"/>
|
||||
<ListPreference
|
||||
android:entryValues="@array/theme_values"
|
||||
android:entries="@array/theme_options"
|
||||
android:title="@string/pref_set_theme_title"
|
||||
android:key="prefTheme"
|
||||
android:summary="@string/pref_set_theme_sum"
|
||||
android:defaultValue="0"/>
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/playback_pref">
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:enabled="true"
|
||||
android:key="prefPauseOnHeadsetDisconnect"
|
||||
android:summary="@string/pref_pauseOnHeadsetDisconnect_sum"
|
||||
android:title="@string/pref_pauseOnHeadsetDisconnect_title" />
|
||||
android:title="@string/pref_pauseOnHeadsetDisconnect_title"/>
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:enabled="true"
|
||||
android:key="prefFollowQueue"
|
||||
android:summary="@string/pref_followQueue_sum"
|
||||
android:title="@string/pref_followQueue_title" />
|
||||
android:title="@string/pref_followQueue_title"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/network_pref" >
|
||||
<PreferenceCategory android:title="@string/network_pref">
|
||||
<ListPreference
|
||||
android:defaultValue="0"
|
||||
android:entries="@array/update_intervall_values"
|
||||
android:entryValues="@array/update_intervall_values"
|
||||
android:key="prefAutoUpdateIntervall"
|
||||
android:summary="@string/pref_autoUpdateIntervall_sum"
|
||||
android:title="@string/pref_autoUpdateIntervall_title" />
|
||||
android:title="@string/pref_autoUpdateIntervall_title"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:enabled="true"
|
||||
android:key="prefMobileUpdate"
|
||||
android:summary="@string/pref_mobileUpdate_sum"
|
||||
android:title="@string/pref_mobileUpdate_title" />
|
||||
<ListPreference android:defaultValue="20" android:entries="@array/episode_cache_size_entries" android:key="prefEpisodeCacheSize" android:title="@string/pref_episode_cache_title" android:entryValues="@array/episode_cache_size_values"/><PreferenceScreen android:summary="@string/pref_automatic_download_sum" android:key="prefAutoDownloadSettings" android:title="@string/pref_automatic_download_title">
|
||||
<CheckBoxPreference android:key="prefEnableAutoDl" android:title="@string/pref_automatic_download_title" android:defaultValue="false"/><CheckBoxPreference android:key="prefEnableAutoDownloadWifiFilter" android:title="@string/pref_autodl_wifi_filter_title" android:summary="@string/pref_autodl_wifi_filter_sum"/>
|
||||
android:title="@string/pref_mobileUpdate_title"/>
|
||||
<ListPreference
|
||||
android:defaultValue="20"
|
||||
android:entries="@array/episode_cache_size_entries"
|
||||
android:key="prefEpisodeCacheSize"
|
||||
android:title="@string/pref_episode_cache_title"
|
||||
android:entryValues="@array/episode_cache_size_values"/>
|
||||
<PreferenceScreen
|
||||
android:summary="@string/pref_automatic_download_sum"
|
||||
android:key="prefAutoDownloadSettings"
|
||||
android:title="@string/pref_automatic_download_title">
|
||||
<CheckBoxPreference
|
||||
android:key="prefEnableAutoDl"
|
||||
android:title="@string/pref_automatic_download_title"
|
||||
android:defaultValue="false"/>
|
||||
<CheckBoxPreference
|
||||
android:key="prefEnableAutoDownloadWifiFilter"
|
||||
android:title="@string/pref_autodl_wifi_filter_title"
|
||||
android:summary="@string/pref_autodl_wifi_filter_sum"/>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/flattr_settings_label" >
|
||||
<PreferenceCategory android:title="@string/services_label">
|
||||
<PreferenceScreen
|
||||
android:key="prefFlattrSettings"
|
||||
android:title="@string/flattr_label">
|
||||
<PreferenceScreen
|
||||
android:key="pref_flattr_authenticate"
|
||||
android:summary="@string/pref_flattr_auth_sum"
|
||||
android:title="@string/pref_flattr_auth_title" >
|
||||
<intent android:action=".activities.FlattrAuthActivity" />
|
||||
android:title="@string/pref_flattr_auth_title">
|
||||
<intent android:action=".activities.FlattrAuthActivity"/>
|
||||
</PreferenceScreen>
|
||||
|
||||
<Preference
|
||||
android:key="prefRevokeAccess"
|
||||
android:summary="@string/pref_revokeAccess_sum"
|
||||
android:title="@string/pref_revokeAccess_title" />
|
||||
android:title="@string/pref_revokeAccess_title"/>
|
||||
</PreferenceScreen>
|
||||
<PreferenceScreen
|
||||
android:key="prefFlattrSettings"
|
||||
android:title="@string/gpodnet_main_label">
|
||||
|
||||
<PreferenceScreen
|
||||
android:key="pref_gpodnet_authenticate"
|
||||
android:title="@string/pref_gpodnet_authenticate_title"
|
||||
android:summary="@string/pref_gpodnet_authenticate_sum">
|
||||
<intent android:action=".activity.gpoddernet.GpodnetAuthenticationActivity"/>
|
||||
</PreferenceScreen>
|
||||
</PreferenceScreen>
|
||||
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/other_pref" >
|
||||
<Preference android:title="@string/choose_data_directory" android:key="prefChooseDataDir"/><Preference
|
||||
<PreferenceCategory android:title="@string/other_pref">
|
||||
<Preference
|
||||
android:title="@string/choose_data_directory"
|
||||
android:key="prefChooseDataDir"/>
|
||||
<Preference
|
||||
android:key="prefFlattrThisApp"
|
||||
android:summary="@string/pref_flattr_this_app_sum"
|
||||
android:title="@string/pref_flattr_this_app_title" >
|
||||
android:title="@string/pref_flattr_this_app_title">
|
||||
</Preference>
|
||||
<Preference android:key="prefOpmlExport" android:title="@string/opml_export_label"/><Preference
|
||||
<Preference
|
||||
android:key="prefOpmlExport"
|
||||
android:title="@string/opml_export_label"/>
|
||||
<Preference
|
||||
android:key="prefAbout"
|
||||
android:title="@string/about_pref" />
|
||||
android:title="@string/about_pref"/>
|
||||
|
||||
|
||||
</PreferenceCategory>
|
||||
|
|
|
@ -0,0 +1,329 @@
|
|||
package de.danoeh.antennapod.activity.gpoddernet;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.*;
|
||||
import de.danoeh.antennapod.AppConfig;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.MainActivity;
|
||||
import de.danoeh.antennapod.gpoddernet.GpodnetService;
|
||||
import de.danoeh.antennapod.gpoddernet.GpodnetServiceException;
|
||||
import de.danoeh.antennapod.gpoddernet.model.GpodnetDevice;
|
||||
import de.danoeh.antennapod.preferences.GpodnetPreferences;
|
||||
import de.danoeh.antennapod.preferences.UserPreferences;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* Guides the user through the authentication process
|
||||
* Step 1: Request username and password from user
|
||||
* Step 2: Choose device from a list of available devices or create a new one
|
||||
* Step 3: Choose from a list of actions
|
||||
*/
|
||||
public class GpodnetAuthenticationActivity extends ActionBarActivity {
|
||||
private static final String TAG = "GpodnetAuthenticationActivity";
|
||||
|
||||
private ViewFlipper viewFlipper;
|
||||
|
||||
private static final int STEP_DEFAULT = -1;
|
||||
private static final int STEP_LOGIN = 0;
|
||||
private static final int STEP_DEVICE = 1;
|
||||
private static final int STEP_FINISH = 2;
|
||||
|
||||
private int currentStep = -1;
|
||||
|
||||
private GpodnetService service;
|
||||
private volatile String username;
|
||||
private volatile String password;
|
||||
private volatile GpodnetDevice selectedDevice;
|
||||
|
||||
View[] views;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setTheme(UserPreferences.getTheme());
|
||||
|
||||
setContentView(R.layout.gpodnetauth_activity);
|
||||
service = new GpodnetService();
|
||||
|
||||
viewFlipper = (ViewFlipper) findViewById(R.id.viewflipper);
|
||||
LayoutInflater inflater = (LayoutInflater)
|
||||
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
views = new View[]{
|
||||
inflater.inflate(R.layout.gpodnetauth_credentials, null),
|
||||
inflater.inflate(R.layout.gpodnetauth_device, null),
|
||||
inflater.inflate(R.layout.gpodnetauth_finish, null)
|
||||
};
|
||||
for (View view : views) {
|
||||
viewFlipper.addView(view);
|
||||
}
|
||||
advance();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (service != null) {
|
||||
service.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupLoginView(View view) {
|
||||
final EditText username = (EditText) view.findViewById(R.id.etxtUsername);
|
||||
final EditText password = (EditText) view.findViewById(R.id.etxtPassword);
|
||||
final Button login = (Button) view.findViewById(R.id.butLogin);
|
||||
final TextView txtvError = (TextView) view.findViewById(R.id.txtvError);
|
||||
final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progBarLogin);
|
||||
|
||||
login.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
final String usernameStr = username.getText().toString();
|
||||
final String passwordStr = password.getText().toString();
|
||||
|
||||
if (AppConfig.DEBUG) Log.d(TAG, "Checking login credentials");
|
||||
new AsyncTask<GpodnetService, Void, Void>() {
|
||||
|
||||
volatile Exception exception;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
login.setEnabled(false);
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
txtvError.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
super.onPostExecute(aVoid);
|
||||
login.setEnabled(true);
|
||||
progressBar.setVisibility(View.GONE);
|
||||
|
||||
if (exception == null) {
|
||||
advance();
|
||||
} else {
|
||||
txtvError.setText(exception.getMessage());
|
||||
txtvError.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(GpodnetService... params) {
|
||||
try {
|
||||
params[0].authenticate(usernameStr, passwordStr);
|
||||
GpodnetAuthenticationActivity.this.username = usernameStr;
|
||||
GpodnetAuthenticationActivity.this.password = passwordStr;
|
||||
} catch (GpodnetServiceException e) {
|
||||
e.printStackTrace();
|
||||
exception = e;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}.execute(service);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupDeviceView(View view) {
|
||||
final EditText deviceID = (EditText) view.findViewById(R.id.etxtDeviceID);
|
||||
final EditText caption = (EditText) view.findViewById(R.id.etxtCaption);
|
||||
final Button createNewDevice = (Button) view.findViewById(R.id.butCreateNewDevice);
|
||||
final Button chooseDevice = (Button) view.findViewById(R.id.butChooseExistingDevice);
|
||||
final TextView txtvError = (TextView) view.findViewById(R.id.txtvError);
|
||||
final ProgressBar progBarCreateDevice = (ProgressBar) view.findViewById(R.id.progbarCreateDevice);
|
||||
final Spinner spinnerDevices = (Spinner) view.findViewById(R.id.spinnerChooseDevice);
|
||||
|
||||
|
||||
// load device list
|
||||
final AtomicReference<List<GpodnetDevice>> devices = new AtomicReference<List<GpodnetDevice>>();
|
||||
new AsyncTask<GpodnetService, Void, List<GpodnetDevice>>() {
|
||||
|
||||
private volatile Exception exception;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
chooseDevice.setEnabled(false);
|
||||
spinnerDevices.setEnabled(false);
|
||||
createNewDevice.setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<GpodnetDevice> gpodnetDevices) {
|
||||
super.onPostExecute(gpodnetDevices);
|
||||
if (gpodnetDevices != null) {
|
||||
List<String> deviceNames = new ArrayList<String>();
|
||||
for (GpodnetDevice device : gpodnetDevices) {
|
||||
deviceNames.add(device.getId());
|
||||
}
|
||||
spinnerDevices.setAdapter(new ArrayAdapter<String>(GpodnetAuthenticationActivity.this,
|
||||
android.R.layout.simple_spinner_dropdown_item, deviceNames));
|
||||
spinnerDevices.setEnabled(true);
|
||||
if (!deviceNames.isEmpty()) {
|
||||
chooseDevice.setEnabled(true);
|
||||
}
|
||||
devices.set(gpodnetDevices);
|
||||
createNewDevice.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<GpodnetDevice> doInBackground(GpodnetService... params) {
|
||||
try {
|
||||
return params[0].getDevices(username);
|
||||
} catch (GpodnetServiceException e) {
|
||||
e.printStackTrace();
|
||||
exception = e;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}.execute(service);
|
||||
|
||||
|
||||
createNewDevice.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (checkDeviceIDText(deviceID, txtvError, devices.get())) {
|
||||
final String deviceStr = deviceID.getText().toString();
|
||||
final String captionStr = caption.getText().toString();
|
||||
|
||||
new AsyncTask<GpodnetService, Void, GpodnetDevice>() {
|
||||
|
||||
private volatile Exception exception;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
createNewDevice.setEnabled(false);
|
||||
chooseDevice.setEnabled(false);
|
||||
progBarCreateDevice.setVisibility(View.VISIBLE);
|
||||
txtvError.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(GpodnetDevice result) {
|
||||
super.onPostExecute(result);
|
||||
createNewDevice.setEnabled(true);
|
||||
chooseDevice.setEnabled(true);
|
||||
progBarCreateDevice.setVisibility(View.GONE);
|
||||
if (exception == null) {
|
||||
selectedDevice = result;
|
||||
advance();
|
||||
} else {
|
||||
txtvError.setText(exception.getMessage());
|
||||
txtvError.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GpodnetDevice doInBackground(GpodnetService... params) {
|
||||
try {
|
||||
params[0].configureDevice(username, deviceStr, captionStr, GpodnetDevice.DeviceType.MOBILE);
|
||||
return new GpodnetDevice(deviceStr, captionStr, GpodnetDevice.DeviceType.MOBILE.toString(), 0);
|
||||
} catch (GpodnetServiceException e) {
|
||||
e.printStackTrace();
|
||||
exception = e;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}.execute(service);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
chooseDevice.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final int position = spinnerDevices.getSelectedItemPosition();
|
||||
selectedDevice = devices.get().get(position);
|
||||
advance();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean checkDeviceIDText(EditText deviceID, TextView txtvError, List<GpodnetDevice> devices) {
|
||||
String text = deviceID.getText().toString();
|
||||
if (text.length() == 0) {
|
||||
txtvError.setText(R.string.gpodnetauth_device_errorEmpty);
|
||||
txtvError.setVisibility(View.VISIBLE);
|
||||
return false;
|
||||
} else {
|
||||
if (devices != null) {
|
||||
for (GpodnetDevice device : devices) {
|
||||
if (device.getId().equals(text)) {
|
||||
txtvError.setText(R.string.gpodnetauth_device_errorAlreadyUsed);
|
||||
txtvError.setVisibility(View.VISIBLE);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
txtvError.setVisibility(View.GONE);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setupFinishView(View view) {
|
||||
final Button sync = (Button) view.findViewById(R.id.butSyncNow);
|
||||
final Button back = (Button) view.findViewById(R.id.butGoMainscreen);
|
||||
|
||||
back.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(GpodnetAuthenticationActivity.this, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(intent);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void writeLoginCredentials() {
|
||||
if (AppConfig.DEBUG) Log.d(TAG, "Writing login credentials");
|
||||
GpodnetPreferences.setUsername(username);
|
||||
GpodnetPreferences.setPassword(password);
|
||||
GpodnetPreferences.setDeviceID(selectedDevice.getId());
|
||||
}
|
||||
|
||||
private void advance() {
|
||||
if (currentStep < STEP_FINISH) {
|
||||
|
||||
View view = views[currentStep + 1];
|
||||
if (currentStep == STEP_DEFAULT) {
|
||||
setupLoginView(view);
|
||||
} else if (currentStep == STEP_LOGIN) {
|
||||
if (username == null || password == null) {
|
||||
throw new IllegalStateException("Username and password must not be null here");
|
||||
} else {
|
||||
setupDeviceView(view);
|
||||
}
|
||||
} else if (currentStep == STEP_DEVICE) {
|
||||
if (selectedDevice == null) {
|
||||
throw new IllegalStateException("Device must not be null here");
|
||||
} else {
|
||||
writeLoginCredentials();
|
||||
setupFinishView(view);
|
||||
}
|
||||
}
|
||||
if (currentStep != STEP_DEFAULT) {
|
||||
viewFlipper.showNext();
|
||||
}
|
||||
currentStep++;
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -453,11 +453,17 @@ public class GpodnetService {
|
|||
}
|
||||
|
||||
/**
|
||||
* Shuts down the GpodnetService's HTTP client.
|
||||
* Shuts down the GpodnetService's HTTP client. The service will be shut down in a separate thread to avoid
|
||||
* NetworkOnMainThreadExceptions.
|
||||
*/
|
||||
public void shutdown() {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
httpClient.getConnectionManager().shutdown();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
private String executeRequest(HttpRequestBase request)
|
||||
throws GpodnetServiceException {
|
||||
|
|
Loading…
Reference in New Issue