11package com .ferg .awfulapp ;
22
3+ import android .app .Activity ;
34import android .app .ProgressDialog ;
45import android .content .ContentResolver ;
56import android .content .ContentUris ;
3435import com .ferg .awfulapp .task .PMReplyRequest ;
3536import com .ferg .awfulapp .task .PMRequest ;
3637import com .ferg .awfulapp .task .SendPrivateMessageRequest ;
38+ import com .ferg .awfulapp .thread .AwfulHtmlPage ;
3739import com .ferg .awfulapp .thread .AwfulMessage ;
3840import com .ferg .awfulapp .webview .AwfulWebView ;
3941import com .ferg .awfulapp .webview .WebViewJsInterface ;
42+ import com .ferg .awfulapp .widget .ThreadIconPicker ;
43+
44+ import timber .log .Timber ;
4045
4146import static android .view .View .GONE ;
4247import static android .view .View .VISIBLE ;
@@ -57,6 +62,7 @@ public class MessageFragment extends AwfulFragment implements OnClickListener {
5762 private EditText mRecipient ;
5863 private EditText mSubject ;
5964 private View mBackground ;
65+ private ThreadIconPicker threadIconPicker ;
6066
6167 private AwfulPreferences mPrefs ;
6268
@@ -106,20 +112,23 @@ public View onCreateView(LayoutInflater aInflater, ViewGroup aContainer, Bundle
106112
107113 View result = aInflater .inflate (R .layout .private_message_fragment , aContainer , false );
108114
109- messageWebView = ( AwfulWebView ) result .findViewById (R .id .messagebody );
110- mHideButton = ( ImageButton ) result .findViewById (R .id .hide_message );
115+ messageWebView = result .findViewById (R .id .messagebody );
116+ mHideButton = result .findViewById (R .id .hide_message );
111117 mHideButton .setOnClickListener (this );
112- mRecipient = ( EditText ) result .findViewById (R .id .message_user );
113- mSubject = ( EditText ) result .findViewById (R .id .message_subject );
114- mUsername = ( TextView ) result .findViewById (R .id .username );
115- mPostdate = ( TextView ) result .findViewById (R .id .post_date );
116- mTitle = ( TextView ) result .findViewById (R .id .message_title );
118+ mRecipient = result .findViewById (R .id .message_user );
119+ mSubject = result .findViewById (R .id .message_subject );
120+ mUsername = result .findViewById (R .id .username );
121+ mPostdate = result .findViewById (R .id .post_date );
122+ mTitle = result .findViewById (R .id .message_title );
117123
118124 messageComposer = (MessageComposer ) getChildFragmentManager ().findFragmentById (R .id .message_composer_fragment );
125+ threadIconPicker = (ThreadIconPicker ) getChildFragmentManager ().findFragmentById (R .id .thread_icon_picker );
126+ threadIconPicker .usePrivateMessageIcons ();
119127
120128 mBackground = result ;
121129 updateColors (result , mPrefs );
122130 messageWebView .setJavascriptHandler (new WebViewJsInterface ());
131+ messageWebView .setContent (AwfulHtmlPage .getContainerHtml (mPrefs , null , false ));
123132
124133 if (pmId <=0 ){
125134 messageWebView .setVisibility (GONE );
@@ -174,11 +183,17 @@ public void onActivityCreated(Bundle savedState){
174183
175184
176185 private void syncPM () {
177- queueRequest (new PMRequest (getActivity (), pmId ).build (this , new AwfulRequest .AwfulResultCallback <Void >() {
186+ // TODO: rework this so we don't hold onto the activity - AwfulRequest wants to make a Toast so we can't just pass in the app context
187+ final Activity activity = getActivity ();
188+ if (activity == null ) {
189+ Timber .i ("Activity unavailable - abandoning PM load" );
190+ return ;
191+ }
192+ queueRequest (new PMRequest (activity , pmId ).build (this , new AwfulRequest .AwfulResultCallback <Void >() {
178193 @ Override
179194 public void success (Void result ) {
180195 restartLoader (pmId , null , mPMDataCallback );
181- queueRequest (new PMReplyRequest (getActivity () , pmId ).build (MessageFragment .this , new AwfulRequest .AwfulResultCallback <Void >() {
196+ queueRequest (new PMReplyRequest (activity , pmId ).build (MessageFragment .this , new AwfulRequest .AwfulResultCallback <Void >() {
182197 @ Override
183198 public void success (Void result ) {
184199 restartLoader (pmId , null , mPMDataCallback );
@@ -262,6 +277,7 @@ public void saveReply(){
262277 values .put (AwfulMessage .TYPE , AwfulMessage .TYPE_PM );
263278 values .put (AwfulMessage .RECIPIENT , mRecipient .getText ().toString ());
264279 values .put (AwfulMessage .REPLY_CONTENT , messageComposer .getText ());
280+ values .put (AwfulMessage .REPLY_ICON , threadIconPicker .getIcon ().iconId );
265281 if (content .update (ContentUris .withAppendedId (AwfulMessage .CONTENT_URI_REPLY ,pmId ), values , null , null )<1 ){
266282 content .insert (AwfulMessage .CONTENT_URI_REPLY , values );
267283 }
@@ -311,7 +327,7 @@ private void newMessage(){
311327 mUsername .setText ("" );
312328 mRecipient .setText ("" );
313329 mPostdate .setText ("" );
314- messageWebView .setContent (null );
330+ messageWebView .setBodyHtml (null );
315331 mTitle .setText ("New Message" );
316332 mSubject .setText ("" );
317333 }
@@ -361,11 +377,11 @@ public void onLoadFinished(Loader<Cursor> aLoader, Cursor aData) {
361377 if (aData != null && aData .moveToFirst ()){
362378 Log .v (TAG ,"PM load finished, populating: " +aData .getCount ());
363379 if (messageWebView != null ){
364- messageWebView .setContent (null );
380+ messageWebView .setBodyHtml (null );
365381 }
366382 String title = aData .getString (aData .getColumnIndex (AwfulMessage .TITLE ));
367383 mTitle .setText (title );
368- messageWebView .setContent (AwfulMessage .getMessageHtml (aData .getString (aData .getColumnIndex (AwfulMessage .CONTENT )), mPrefs ));
384+ messageWebView .setBodyHtml (AwfulMessage .getMessageHtml (aData .getString (aData .getColumnIndex (AwfulMessage .CONTENT ))));
369385 mPostdate .setText (aData .getString (aData .getColumnIndex (AwfulMessage .DATE )));
370386 String replyTitle = aData .getString (aData .getColumnIndex (AwfulMessage .REPLY_TITLE ));
371387 String replyContent = aData .getString (aData .getColumnIndex (AwfulMessage .REPLY_CONTENT ));
@@ -424,8 +440,4 @@ protected boolean doScroll(boolean down) {
424440 }
425441
426442
427- private String getBlankPage (){
428- return "<html><head></head><body style='{background-color:#" + ColorProvider .convertToRGB (ColorProvider .BACKGROUND .getColor ()) +";'></body></html>" ;
429- }
430-
431443}
0 commit comments