|
14 | 14 | import android.widget.ScrollView;
|
15 | 15 | import android.widget.TextView;
|
16 | 16 |
|
| 17 | +import butterknife.BindView; |
| 18 | +import butterknife.ButterKnife; |
| 19 | +import butterknife.OnClick; |
17 | 20 | import java.io.IOException;
|
18 | 21 | import java.text.SimpleDateFormat;
|
19 | 22 | import java.util.ArrayList;
|
@@ -48,24 +51,35 @@ public static MediaDetailFragment forMedia(int index, boolean editable) {
|
48 | 51 | return mf;
|
49 | 52 | }
|
50 | 53 |
|
51 |
| - private MediaWikiImageView image; |
52 |
| - private MediaDetailSpacer spacer; |
53 | 54 | private int initialListTop = 0;
|
54 | 55 |
|
55 |
| - private TextView title; |
56 |
| - private TextView desc; |
57 |
| - private TextView license; |
58 |
| - private TextView coordinates; |
59 |
| - private TextView uploadedDate; |
60 |
| - private LinearLayout categoryContainer; |
61 |
| - private ScrollView scrollView; |
| 56 | + //Changed the access specifiers of these view as well [ButterKnife wont let us bind private variables] |
| 57 | + @BindView(R.id.mediaDetailImage) |
| 58 | + MediaWikiImageView image; |
| 59 | + @BindView(R.id.mediaDetailSpacer) |
| 60 | + MediaDetailSpacer spacer; |
| 61 | + @BindView(R.id.mediaDetailTitle) |
| 62 | + TextView title; |
| 63 | + @BindView(R.id.mediaDetailDesc) |
| 64 | + TextView desc; |
| 65 | + @BindView(R.id.mediaDetailLicense) |
| 66 | + TextView license; |
| 67 | + @BindView(R.id.mediaDetailCoordinates) |
| 68 | + TextView coordinates; |
| 69 | + @BindView(R.id.mediaDetailuploadeddate) |
| 70 | + TextView uploadedDate; |
| 71 | + @BindView(R.id.mediaDetailCategoryContainer) |
| 72 | + LinearLayout categoryContainer; |
| 73 | + @BindView(R.id.mediaDetailScrollView) |
| 74 | + ScrollView scrollView; |
| 75 | + |
62 | 76 | private ArrayList<String> categoryNames;
|
63 | 77 | private boolean categoriesLoaded = false;
|
64 | 78 | private boolean categoriesPresent = false;
|
65 | 79 | private ViewTreeObserver.OnGlobalLayoutListener layoutListener; // for layout stuff, only used once!
|
66 | 80 | private ViewTreeObserver.OnScrollChangedListener scrollListener;
|
67 | 81 | DataSetObserver dataObserver;
|
68 |
| - private AsyncTask<Void,Void,Boolean> detailFetchTask; |
| 82 | + private AsyncTask<Void, Void, Boolean> detailFetchTask; |
69 | 83 | private LicenseList licenseList;
|
70 | 84 |
|
71 | 85 | @Override
|
@@ -100,17 +114,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
|
100 | 114 |
|
101 | 115 | final View view = inflater.inflate(R.layout.fragment_media_detail, container, false);
|
102 | 116 |
|
103 |
| - image = (MediaWikiImageView) view.findViewById(R.id.mediaDetailImage); |
104 |
| - scrollView = (ScrollView) view.findViewById(R.id.mediaDetailScrollView); |
105 |
| - |
106 |
| - // Detail consists of a list view with main pane in header view, plus category list. |
107 |
| - spacer = (MediaDetailSpacer) view.findViewById(R.id.mediaDetailSpacer); |
108 |
| - title = (TextView) view.findViewById(R.id.mediaDetailTitle); |
109 |
| - desc = (TextView) view.findViewById(R.id.mediaDetailDesc); |
110 |
| - license = (TextView) view.findViewById(R.id.mediaDetailLicense); |
111 |
| - coordinates = (TextView) view.findViewById(R.id.mediaDetailCoordinates); |
112 |
| - uploadedDate = (TextView) view.findViewById(R.id.mediaDetailuploadeddate); |
113 |
| - categoryContainer = (LinearLayout) view.findViewById(R.id.mediaDetailCategoryContainer); |
| 117 | + ButterKnife.bind(this, view); |
114 | 118 |
|
115 | 119 | licenseList = new LicenseList(getActivity());
|
116 | 120 |
|
@@ -271,22 +275,10 @@ private void rebuildCatList() {
|
271 | 275 |
|
272 | 276 | private View buildCatLabel(String cat) {
|
273 | 277 | final String catName = cat;
|
274 |
| - final View item = getLayoutInflater(null).inflate(R.layout.detail_category_item, null, false); |
275 |
| - final TextView textView = (TextView)item.findViewById(R.id.mediaDetailCategoryItemText); |
276 |
| - |
277 |
| - textView.setText(cat); |
278 |
| - if (categoriesLoaded && categoriesPresent) { |
279 |
| - textView.setOnClickListener(new View.OnClickListener() { |
280 |
| - @Override |
281 |
| - public void onClick(View view) { |
282 |
| - String selectedCategoryTitle = "Category:" + catName; |
283 |
| - Intent viewIntent = new Intent(); |
284 |
| - viewIntent.setAction(Intent.ACTION_VIEW); |
285 |
| - viewIntent.setData(Utils.uriForWikiPage(selectedCategoryTitle)); |
286 |
| - startActivity(viewIntent); |
287 |
| - } |
288 |
| - }); |
289 |
| - } |
| 278 | + final View item = getLayoutInflater(null) |
| 279 | + .inflate(R.layout.detail_category_item, null, false); |
| 280 | + CategoryItemViewHolder categoryItemViewHolder = new CategoryItemViewHolder(item); |
| 281 | + categoryItemViewHolder.init(catName); |
290 | 282 | return item;
|
291 | 283 | }
|
292 | 284 |
|
@@ -343,4 +335,34 @@ private String prettyUploadedDate(Media media) {
|
343 | 335 | private String prettyCoordinates(Media media) {
|
344 | 336 | return media.getCoordinates();
|
345 | 337 | }
|
| 338 | + |
| 339 | + /** |
| 340 | + * Holds the individual category item views |
| 341 | + */ |
| 342 | + |
| 343 | + public class CategoryItemViewHolder { |
| 344 | + |
| 345 | + @BindView(R.id.mediaDetailCategoryItemText) |
| 346 | + TextView mediaDetailCategoryItemText; |
| 347 | + |
| 348 | + private String categoryTitle; |
| 349 | + |
| 350 | + public CategoryItemViewHolder(View item) { |
| 351 | + ButterKnife.bind(this, item); |
| 352 | + } |
| 353 | + |
| 354 | + public void init(String categoryName) { |
| 355 | + this.categoryTitle = categoryName; |
| 356 | + mediaDetailCategoryItemText.setText(categoryName); |
| 357 | + } |
| 358 | + |
| 359 | + @OnClick(R.id.mediaDetailCategoryItemText) |
| 360 | + public void onCategoryItemClicked() { |
| 361 | + String selectedCategoryTitle = "Category:" + categoryTitle; |
| 362 | + Intent viewIntent = new Intent(); |
| 363 | + viewIntent.setAction(Intent.ACTION_VIEW); |
| 364 | + viewIntent.setData(Utils.uriForWikiPage(selectedCategoryTitle)); |
| 365 | + startActivity(viewIntent); |
| 366 | + } |
| 367 | + } |
346 | 368 | }
|
0 commit comments