15
15
*/
16
16
package com .gh4a .fragment ;
17
17
18
- import android .content .Context ;
19
18
import android .content .Intent ;
20
- import android .graphics .Typeface ;
21
- import android .os .AsyncTask ;
22
19
import android .os .Bundle ;
23
20
import android .support .v4 .content .Loader ;
24
- import android .support .v4 .os .AsyncTaskCompat ;
25
21
import android .text .SpannableStringBuilder ;
26
22
import android .view .LayoutInflater ;
27
23
import android .view .View ;
28
24
import android .view .View .OnClickListener ;
29
25
import android .view .ViewGroup ;
26
+ import android .webkit .WebView ;
30
27
import android .widget .LinearLayout ;
31
28
import android .widget .TextView ;
32
-
33
29
import com .gh4a .R ;
34
30
import com .gh4a .activities .CollaboratorListActivity ;
35
31
import com .gh4a .activities .ContributorListActivity ;
46
42
import com .gh4a .loader .PullRequestCountLoader ;
47
43
import com .gh4a .loader .ReadmeLoader ;
48
44
import com .gh4a .utils .ApiHelpers ;
49
- import com .gh4a .utils .HttpImageGetter ;
50
45
import com .gh4a .utils .StringUtils ;
51
46
import com .gh4a .utils .UiUtils ;
52
47
import com .gh4a .widget .IntentSpan ;
53
48
import com .vdurmont .emoji .EmojiParser ;
54
-
55
49
import org .eclipse .egit .github .core .Permissions ;
56
50
import org .eclipse .egit .github .core .Repository ;
57
51
@@ -70,7 +64,6 @@ public static RepositoryFragment newInstance(Repository repository, String ref)
70
64
private Repository mRepository ;
71
65
private View mContentView ;
72
66
private String mRef ;
73
- private HttpImageGetter mImageGetter ;
74
67
75
68
private final LoaderCallbacks <String > mReadmeCallback = new LoaderCallbacks <String >(this ) {
76
69
@ Override
@@ -80,13 +73,23 @@ protected Loader<LoaderResult<String>> onCreateLoader() {
80
73
}
81
74
@ Override
82
75
protected void onResultReady (String result ) {
83
- TextView readmeView = (TextView ) mContentView .findViewById (R .id .readme );
84
76
View progress = mContentView .findViewById (R .id .pb_readme );
85
- AsyncTaskCompat .executeParallel (new FillReadmeTask (
86
- mRepository .getId (), readmeView , progress , mImageGetter ), result );
77
+ loadHtmlContent (result );
87
78
}
88
79
};
89
80
81
+ public void loadHtmlContent (String html ) {
82
+ WebView webView = (WebView ) mContentView .findViewById (R .id .webView );
83
+ webView .setVerticalScrollBarEnabled (false );
84
+ webView .setHorizontalScrollBarEnabled (true );
85
+
86
+ String mime = "text/html" ;
87
+ String encoding = "utf-8" ;
88
+
89
+ webView .getSettings ().setJavaScriptEnabled (true );
90
+ webView .loadDataWithBaseURL (null , html , mime , encoding , null );
91
+ }
92
+
90
93
private final LoaderCallbacks <Integer > mPullRequestsCallback = new LoaderCallbacks <Integer >(this ) {
91
94
@ Override
92
95
protected Loader <LoaderResult <Integer >> onCreateLoader () {
@@ -120,57 +123,33 @@ protected View onCreateContentView(LayoutInflater inflater, ViewGroup parent) {
120
123
return mContentView ;
121
124
}
122
125
123
- @ Override
124
- public void onDestroyView () {
125
- super .onDestroyView ();
126
- mImageGetter .destroy ();
127
- mImageGetter = null ;
128
- }
129
-
130
126
@ Override
131
127
public void onRefresh () {
132
128
if (mContentView != null ) {
133
- mContentView .findViewById (R .id .readme ).setVisibility (View .GONE );
134
129
mContentView .findViewById (R .id .pb_readme ).setVisibility (View .VISIBLE );
135
130
mContentView .findViewById (R .id .pull_requests_progress ).setVisibility (View .VISIBLE );
136
131
}
137
- if (mImageGetter != null ) {
138
- mImageGetter .clearHtmlCache ();
139
- }
132
+
140
133
hideContentAndRestartLoaders (0 , 1 );
141
134
}
142
135
143
136
@ Override
144
137
public void onActivityCreated (Bundle savedInstanceState ) {
145
138
super .onActivityCreated (savedInstanceState );
146
139
147
- mImageGetter = new HttpImageGetter (getActivity ());
148
140
fillData ();
149
141
setContentShown (true );
150
142
151
143
getLoaderManager ().initLoader (0 , null , mReadmeCallback );
152
144
getLoaderManager ().initLoader (1 , null , mPullRequestsCallback );
153
145
}
154
146
155
- @ Override
156
- public void onResume () {
157
- super .onResume ();
158
- mImageGetter .resume ();
159
- }
160
-
161
- @ Override
162
- public void onPause () {
163
- super .onPause ();
164
- mImageGetter .pause ();
165
- }
166
-
167
147
public void setRef (String ref ) {
168
148
mRef = ref ;
169
149
getArguments ().putString ("ref" , ref );
170
150
// reload readme
171
151
getLoaderManager ().restartLoader (0 , null , mReadmeCallback );
172
152
if (mContentView != null ) {
173
- mContentView .findViewById (R .id .readme ).setVisibility (View .GONE );
174
153
mContentView .findViewById (R .id .pb_readme ).setVisibility (View .VISIBLE );
175
154
}
176
155
}
@@ -207,12 +186,17 @@ protected Intent getIntent() {
207
186
fillTextView (R .id .tv_url , 0 , !StringUtils .isBlank (mRepository .getHomepage ())
208
187
? mRepository .getHomepage () : mRepository .getHtmlUrl ());
209
188
210
- mContentView .findViewById (R .id .cell_stargazers ).setOnClickListener (this );
211
- mContentView .findViewById (R .id .cell_forks ).setOnClickListener (this );
212
- mContentView .findViewById (R .id .cell_pull_requests ).setOnClickListener (this );
213
- mContentView .findViewById (R .id .tv_contributors_label ).setOnClickListener (this );
214
- mContentView .findViewById (R .id .other_info ).setOnClickListener (this );
215
- mContentView .findViewById (R .id .tv_releases_label ).setOnClickListener (this );
189
+ // Setting Click listeners
190
+ int [] viewIds = new int []{
191
+ R .id .cell_stargazers ,
192
+ R .id .cell_forks ,
193
+ R .id .cell_pull_requests ,
194
+ R .id .tv_contributors_label ,
195
+ R .id .other_info ,
196
+ R .id .tv_releases_label
197
+ };
198
+ for (int id : viewIds )
199
+ mContentView .findViewById (id ).setOnClickListener (this );
216
200
217
201
Permissions permissions = mRepository .getPermissions ();
218
202
updateClickableLabel (R .id .tv_collaborators_label ,
@@ -310,43 +294,4 @@ public void onClick(View view) {
310
294
startActivity (intent );
311
295
}
312
296
}
313
-
314
- private static class FillReadmeTask extends AsyncTask <String , Void , String > {
315
- private final Long mId ;
316
- private final Context mContext ;
317
- private final TextView mReadmeView ;
318
- private final View mProgressView ;
319
- private final HttpImageGetter mImageGetter ;
320
-
321
- public FillReadmeTask (long id , TextView readmeView , View progressView ,
322
- HttpImageGetter imageGetter ) {
323
- mId = id ;
324
- mContext = readmeView .getContext ();
325
- mReadmeView = readmeView ;
326
- mProgressView = progressView ;
327
- mImageGetter = imageGetter ;
328
- }
329
-
330
- @ Override
331
- protected String doInBackground (String ... params ) {
332
- String readme = params [0 ];
333
- if (readme != null ) {
334
- mImageGetter .encode (mContext , mId , readme );
335
- }
336
- return readme ;
337
- }
338
-
339
- @ Override
340
- protected void onPostExecute (String result ) {
341
- if (result != null ) {
342
- mReadmeView .setMovementMethod (UiUtils .CHECKING_LINK_METHOD );
343
- mImageGetter .bind (mReadmeView , result , mId );
344
- } else {
345
- mReadmeView .setText (R .string .repo_no_readme );
346
- mReadmeView .setTypeface (Typeface .DEFAULT , Typeface .ITALIC );
347
- }
348
- mReadmeView .setVisibility (View .VISIBLE );
349
- mProgressView .setVisibility (View .GONE );
350
- }
351
- }
352
297
}
0 commit comments