|
15 | 15 | import fr.free.nrw.commons.R;
|
16 | 16 | import fr.free.nrw.commons.Utils;
|
17 | 17 | import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
| 18 | +import fr.free.nrw.commons.mwapi.Revision; |
18 | 19 |
|
19 | 20 | /**
|
20 | 21 | * Created by root on 19.05.2018.
|
21 | 22 | */
|
22 | 23 |
|
23 | 24 | public class ReviewImageFragment extends CommonsDaggerSupportFragment {
|
24 | 25 |
|
25 |
| - public static final int SPAM = 0; |
26 |
| - public static final int COPYRIGHT = 1; |
27 |
| - public static final int CATEGORY = 2; |
28 |
| - public static final int THANKS = 3; |
| 26 | + public static final int SPAM = 0; |
| 27 | + public static final int COPYRIGHT = 1; |
| 28 | + public static final int CATEGORY = 2; |
| 29 | + public static final int THANKS = 3; |
29 | 30 |
|
30 |
| - private int position; |
31 |
| - private String fileName; |
32 |
| - private String catString; |
| 31 | + private int position; |
| 32 | + private String fileName; |
| 33 | + private String catString; |
33 | 34 |
|
34 |
| - private View textViewQuestionContext; |
35 |
| - private View imageCaption; |
36 |
| - private View textViewQuestion; |
37 |
| - private SimpleDraweeView simpleDraweeView; |
| 35 | + private View textViewQuestionContext; |
| 36 | + private View imageCaption; |
| 37 | + private View textViewQuestion; |
| 38 | + private SimpleDraweeView simpleDraweeView; |
38 | 39 |
|
39 |
| - private Button yesButton; |
40 |
| - private Button noButton; |
| 40 | + private Button yesButton; |
| 41 | + private Button noButton; |
41 | 42 |
|
42 |
| - public ProgressBar progressBar; |
| 43 | + public ProgressBar progressBar; |
| 44 | + private Revision revision; |
43 | 45 |
|
44 | 46 |
|
45 |
| - public void update(int position, String fileName) { |
46 |
| - this.position = position; |
47 |
| - this.fileName = fileName; |
| 47 | + public void update(int position, String fileName, Revision revision) { |
| 48 | + this.position = position; |
| 49 | + this.fileName = fileName; |
| 50 | + this.revision = revision; |
48 | 51 |
|
49 |
| - if (simpleDraweeView!=null) { |
50 |
| - simpleDraweeView.setImageURI(Utils.makeThumbBaseUrl(fileName)); |
51 |
| - progressBar.setVisibility(View.GONE); |
52 |
| - } |
53 |
| - } |
| 52 | + fillImageCaption(); |
54 | 53 |
|
55 |
| - public void updateCategories(Iterable<String> categories) { |
56 |
| - if (categories!=null && isAdded()) { |
57 |
| - catString = TextUtils.join(", ", categories); |
58 |
| - if (catString != null && !catString.equals("") && textViewQuestionContext != null) { |
59 |
| - catString = "<b>"+catString+"</b>"; |
60 |
| - String stringToConvertHtml = String.format(getResources().getString(R.string.review_category_explanation), catString); |
61 |
| - ((TextView) textViewQuestionContext).setText(Html.fromHtml(stringToConvertHtml)); |
62 |
| - } else if (textViewQuestionContext != null) { |
63 |
| - ((TextView)textViewQuestionContext).setText(getResources().getString(R.string.review_no_category)); |
64 |
| - } |
| 54 | + if (simpleDraweeView != null) { |
| 55 | + simpleDraweeView.setImageURI(Utils.makeThumbBaseUrl(fileName)); |
| 56 | + progressBar.setVisibility(View.GONE); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + public void updateCategories(Iterable<String> categories) { |
| 61 | + if (categories != null && isAdded()) { |
| 62 | + catString = TextUtils.join(", ", categories); |
| 63 | + if (catString != null && !catString.equals("") && textViewQuestionContext != null) { |
| 64 | + catString = "<b>" + catString + "</b>"; |
| 65 | + String stringToConvertHtml = String.format(getResources().getString(R.string.review_category_explanation), catString); |
| 66 | + ((TextView) textViewQuestionContext).setText(Html.fromHtml(stringToConvertHtml)); |
| 67 | + } else if (textViewQuestionContext != null) { |
| 68 | + ((TextView) textViewQuestionContext).setText(getResources().getString(R.string.review_no_category)); |
65 | 69 | }
|
66 | 70 | }
|
67 |
| - |
68 |
| - @Override |
69 |
| - public void onCreate(Bundle savedInstanceState) { |
70 |
| - super.onCreate(savedInstanceState); |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public void onCreate(Bundle savedInstanceState) { |
| 75 | + super.onCreate(savedInstanceState); |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 80 | + Bundle savedInstanceState) { |
| 81 | + position = getArguments().getInt("position"); |
| 82 | + View layoutView = inflater.inflate(R.layout.fragment_review_image, container, |
| 83 | + false); |
| 84 | + progressBar = layoutView.findViewById(R.id.progressBar); |
| 85 | + textViewQuestion = layoutView.findViewById(R.id.reviewQuestion); |
| 86 | + textViewQuestionContext = layoutView.findViewById(R.id.reviewQuestionContext); |
| 87 | + imageCaption = layoutView.findViewById(R.id.imageCaption); |
| 88 | + yesButton = layoutView.findViewById(R.id.yesButton); |
| 89 | + noButton = layoutView.findViewById(R.id.noButton); |
| 90 | + |
| 91 | + fillImageCaption(); |
| 92 | + |
| 93 | + String question, explanation; |
| 94 | + switch (position) { |
| 95 | + case COPYRIGHT: |
| 96 | + question = getString(R.string.review_copyright); |
| 97 | + explanation = getString(R.string.review_copyright_explanation); |
| 98 | + yesButton.setOnClickListener(view -> { |
| 99 | + ((ReviewActivity) getActivity()).reviewController.reportPossibleCopyRightViolation(); |
| 100 | + }); |
| 101 | + break; |
| 102 | + case CATEGORY: |
| 103 | + question = getString(R.string.review_category); |
| 104 | + explanation = getString(R.string.review_no_category); |
| 105 | + updateCategories(ReviewController.categories); |
| 106 | + yesButton.setOnClickListener(view -> { |
| 107 | + ((ReviewActivity) getActivity()).reviewController.reportWrongCategory(); |
| 108 | + }); |
| 109 | + break; |
| 110 | + case SPAM: |
| 111 | + question = getString(R.string.review_spam); |
| 112 | + explanation = getString(R.string.review_spam_explanation); |
| 113 | + yesButton.setOnClickListener(view -> { |
| 114 | + ((ReviewActivity) getActivity()).reviewController.reportSpam(); |
| 115 | + }); |
| 116 | + break; |
| 117 | + case THANKS: |
| 118 | + question = getString(R.string.review_thanks); |
| 119 | + explanation = getString(R.string.review_thanks_explanation, ((ReviewActivity) getActivity()).reviewController.firstRevision.username); |
| 120 | + yesButton.setOnClickListener(view -> { |
| 121 | + ((ReviewActivity) getActivity()).reviewController.sendThanks(); |
| 122 | + }); |
| 123 | + break; |
| 124 | + default: |
| 125 | + question = "How did we get here?"; |
| 126 | + explanation = "No idea."; |
71 | 127 | }
|
72 | 128 |
|
73 |
| - @Override |
74 |
| - public View onCreateView(LayoutInflater inflater, ViewGroup container, |
75 |
| - Bundle savedInstanceState) { |
76 |
| - position = getArguments().getInt("position"); |
77 |
| - View layoutView = inflater.inflate(R.layout.fragment_review_image, container, |
78 |
| - false); |
79 |
| - progressBar = layoutView.findViewById(R.id.progressBar); |
80 |
| - textViewQuestion = layoutView.findViewById(R.id.reviewQuestion); |
81 |
| - textViewQuestionContext = layoutView.findViewById(R.id.reviewQuestionContext); |
82 |
| - imageCaption = layoutView.findViewById(R.id.imageCaption); |
83 |
| - yesButton = layoutView.findViewById(R.id.yesButton); |
84 |
| - noButton = layoutView.findViewById(R.id.noButton); |
85 |
| - String question, explanation; |
86 |
| - switch(position) { |
87 |
| - case COPYRIGHT: |
88 |
| - question = getString(R.string.review_copyright); |
89 |
| - explanation = getString(R.string.review_copyright_explanation); |
90 |
| - yesButton.setOnClickListener(view -> { |
91 |
| - ((ReviewActivity)getActivity()).reviewController.reportPossibleCopyRightViolation(); |
92 |
| - }); |
93 |
| - break; |
94 |
| - case CATEGORY: |
95 |
| - question = getString(R.string.review_category); |
96 |
| - explanation = getString(R.string.review_no_category); |
97 |
| - updateCategories(ReviewController.categories); |
98 |
| - yesButton.setOnClickListener(view -> { |
99 |
| - ((ReviewActivity)getActivity()).reviewController.reportWrongCategory(); |
100 |
| - }); |
101 |
| - break; |
102 |
| - case SPAM: |
103 |
| - question = getString(R.string.review_spam); |
104 |
| - explanation = getString(R.string.review_spam_explanation); |
105 |
| - yesButton.setOnClickListener(view -> { |
106 |
| - ((ReviewActivity)getActivity()).reviewController.reportSpam(); |
107 |
| - }); |
108 |
| - break; |
109 |
| - case THANKS: |
110 |
| - question = getString(R.string.review_thanks); |
111 |
| - explanation = getString(R.string.review_thanks_explanation); |
112 |
| - yesButton.setOnClickListener(view -> { |
113 |
| - ((ReviewActivity)getActivity()).reviewController.sendThanks(); |
114 |
| - }); |
115 |
| - break; |
116 |
| - default: |
117 |
| - question = "How did we get here?"; |
118 |
| - explanation = "No idea."; |
119 |
| - } |
120 |
| - |
121 |
| - noButton.setOnClickListener(view -> { |
122 |
| - ((ReviewActivity)getActivity()).reviewController.swipeToNext(); |
123 |
| - }); |
| 129 | + noButton.setOnClickListener(view -> { |
| 130 | + ((ReviewActivity) getActivity()).reviewController.swipeToNext(); |
| 131 | + }); |
124 | 132 |
|
125 |
| - ((TextView) textViewQuestion).setText(question); |
126 |
| - ((TextView) textViewQuestionContext).setText(explanation); |
| 133 | + ((TextView) textViewQuestion).setText(question); |
| 134 | + ((TextView) textViewQuestionContext).setText(explanation); |
127 | 135 |
|
128 |
| - simpleDraweeView = layoutView.findViewById(R.id.imageView); |
| 136 | + simpleDraweeView = layoutView.findViewById(R.id.imageView); |
129 | 137 |
|
130 |
| - if (fileName != null) { |
131 |
| - simpleDraweeView.setImageURI(Utils.makeThumbBaseUrl(fileName)); |
132 |
| - progressBar.setVisibility(View.GONE); |
133 |
| - } |
134 |
| - return layoutView; |
| 138 | + if (fileName != null) { |
| 139 | + simpleDraweeView.setImageURI(Utils.makeThumbBaseUrl(fileName)); |
| 140 | + progressBar.setVisibility(View.GONE); |
135 | 141 | }
|
| 142 | + return layoutView; |
| 143 | + } |
136 | 144 |
|
137 |
| - public void updateImageCaption() { |
138 |
| - ((TextView)imageCaption).setText(fileName+" is uploaded by: "+ReviewController.firstRevision.username); |
| 145 | + private void fillImageCaption() { |
| 146 | + if (imageCaption != null && fileName != null && revision != null) { |
| 147 | + ((TextView) imageCaption).setText(fileName + " is uploaded by: " + revision.username); |
139 | 148 | }
|
| 149 | + } |
140 | 150 | }
|
0 commit comments