11package org .wordpress .android .ui .posts ;
22
3- import java .io .BufferedReader ;
4- import java .io .InputStreamReader ;
5- import java .net .HttpURLConnection ;
6- import java .net .URL ;
7- import java .util .Iterator ;
8- import java .util .HashMap ;
9- import java .util .Map ;
10-
113import android .app .AlertDialog ;
124import android .app .Dialog ;
135import android .app .ProgressDialog ;
146import android .content .DialogInterface ;
157import android .content .Intent ;
168import android .content .SharedPreferences ;
9+ import android .net .Uri ;
1710import android .os .AsyncTask ;
1811import android .os .Bundle ;
1912import android .preference .PreferenceManager ;
2619import com .actionbarsherlock .view .MenuInflater ;
2720import com .actionbarsherlock .view .MenuItem ;
2821
29- import org .xmlrpc .android .ApiHelper ;
30- import org .xmlrpc .android .XMLRPCClient ;
31- import org .xmlrpc .android .XMLRPCException ;
32-
3322import org .wordpress .android .R ;
3423import org .wordpress .android .WordPress ;
35- import org .wordpress .passcodelock .AppLockManager ;
3624import org .wordpress .android .models .Post ;
3725import org .wordpress .android .ui .MenuDrawerItem ;
3826import org .wordpress .android .ui .WPActionBarActivity ;
3927import org .wordpress .android .ui .comments .AddCommentActivity ;
40- import org .wordpress .android .ui .posts . ViewPostFragment . OnDetailPostActionListener ;
28+ import org .wordpress .android .ui .notifications . NotificationsActivity ;
4129import org .wordpress .android .ui .posts .PostsListFragment .OnPostActionListener ;
4230import org .wordpress .android .ui .posts .PostsListFragment .OnPostSelectedListener ;
4331import org .wordpress .android .ui .posts .PostsListFragment .OnRefreshListener ;
32+ import org .wordpress .android .ui .posts .ViewPostFragment .OnDetailPostActionListener ;
4433import org .wordpress .android .util .WPAlertDialogFragment .OnDialogConfirmListener ;
45- import org .wordpress .android .ui .notifications .NotificationsActivity ;
34+ import org .wordpress .passcodelock .AppLockManager ;
35+ import org .xmlrpc .android .ApiHelper ;
36+ import org .xmlrpc .android .XMLRPCClient ;
37+ import org .xmlrpc .android .XMLRPCException ;
38+
39+ import java .io .BufferedReader ;
40+ import java .io .InputStreamReader ;
41+ import java .net .HttpURLConnection ;
42+ import java .net .URL ;
43+ import java .util .HashMap ;
44+ import java .util .Iterator ;
45+ import java .util .Map ;
4646
4747public class PostsActivity extends WPActionBarActivity implements OnPostSelectedListener ,
4848 OnRefreshListener , OnPostActionListener , OnDetailPostActionListener , OnDialogConfirmListener {
@@ -75,7 +75,7 @@ public void onCreate(Bundle savedInstanceState) {
7575 startNotificationsActivity (extras );
7676 return ;
7777 }
78-
78+
7979 // Restore last selection on app creation
8080 if (WordPress .shouldRestoreSelectedActivity && WordPress .getCurrentBlog () != null
8181 && !(this instanceof PagesActivity )) {
@@ -123,9 +123,7 @@ public void onFailure() {
123123
124124 if (extras != null ) {
125125 isPage = extras .getBoolean ("viewPages" );
126- String errorMessage = extras .getString ("errorMessage" );
127- if (errorMessage != null )
128- showPostUploadErrorAlert (errorMessage );
126+ showErrorDialogIfNeeded (extras );
129127 }
130128
131129 if (isPage )
@@ -151,20 +149,25 @@ public void OnPostUploaded() {
151149 popPostDetail ();
152150 }
153151
154- private void showPostUploadErrorAlert (String errorMessage ) {
155-
156- AlertDialog .Builder dialogBuilder = new AlertDialog .Builder (
157- PostsActivity .this );
158- dialogBuilder .setTitle (getResources ().getText (
159- R .string .error ));
152+ private void showPostUploadErrorAlert (String errorMessage , String infoTitle ,
153+ final String infoURL ) {
154+ AlertDialog .Builder dialogBuilder = new AlertDialog .Builder (PostsActivity .this );
155+ dialogBuilder .setTitle (getResources ().getText (R .string .error ));
160156 dialogBuilder .setMessage (errorMessage );
161157 dialogBuilder .setPositiveButton ("OK" ,
162158 new DialogInterface .OnClickListener () {
163- public void onClick (DialogInterface dialog ,
164- int whichButton ) {
159+ public void onClick (DialogInterface dialog , int whichButton ) {
165160 // Just close the window.
166161 }
167162 });
163+ if (infoTitle != null && infoURL != null ) {
164+ dialogBuilder .setNeutralButton (infoTitle ,
165+ new DialogInterface .OnClickListener () {
166+ public void onClick (DialogInterface dialog , int whichButton ) {
167+ startActivity (new Intent (Intent .ACTION_VIEW , Uri .parse (infoURL )));
168+ }
169+ });
170+ }
168171 dialogBuilder .setCancelable (true );
169172 if (!isFinishing ())
170173 dialogBuilder .create ().show ();
@@ -181,12 +184,19 @@ protected void onNewIntent(Intent intent) {
181184 startNotificationsActivity (extras );
182185 return ;
183186 }
184-
185- String errorMessage = extras .getString ("errorMessage" );
186- if (errorMessage != null )
187- showPostUploadErrorAlert (errorMessage );
188187 }
189-
188+ }
189+
190+ private void showErrorDialogIfNeeded (Bundle extras ) {
191+ if (extras == null ) {
192+ return ;
193+ }
194+ String errorMessage = extras .getString ("errorMessage" );
195+ String errorInfoTitle = extras .getString ("errorInfoTitle" );
196+ String errorInfoLink = extras .getString ("errorInfoLink" );
197+ if (errorMessage != null ) {
198+ showPostUploadErrorAlert (errorMessage , errorInfoTitle , errorInfoLink );
199+ }
190200 }
191201
192202 private void startNotificationsActivity (Bundle extras ) {
@@ -345,7 +355,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
345355 if (!returnText .equals ("CANCEL" )) {
346356 // Add comment to the server if user didn't cancel.
347357 final String postID = extras .getString ("postID" );
348- new PostsActivity . addCommentTask ().execute (postID , returnText );
358+ new addCommentTask ().execute (postID , returnText );
349359 }
350360 }
351361 }
@@ -709,7 +719,7 @@ protected String doInBackground(Post... params) {
709719 }
710720
711721 private void refreshComments () {
712- new PostsActivity . refreshCommentsTask ().execute ();
722+ new refreshCommentsTask ().execute ();
713723 }
714724
715725 private String getShortlinkTagHref (String urlString ) {
@@ -813,7 +823,7 @@ public void onClick(DialogInterface dialog,
813823 new DialogInterface .OnClickListener () {
814824 public void onClick (DialogInterface dialog ,
815825 int whichButton ) {
816- new PostsActivity . deletePostTask ().execute (post );
826+ new deletePostTask ().execute (post );
817827 }
818828 });
819829 dialogBuilder .setNegativeButton (
@@ -832,7 +842,7 @@ public void onClick(DialogInterface dialog,
832842
833843 }
834844 } else if (action == POST_SHARE ) {
835- new PostsActivity . shareURLTask ().execute (post );
845+ new shareURLTask ().execute (post );
836846 } else if (action == POST_CLEAR ) {
837847 FragmentManager fm = getSupportFragmentManager ();
838848 ViewPostFragment f = (ViewPostFragment ) fm
0 commit comments