3
3
import static fr .free .nrw .commons .utils .ImageUtils .getErrorMessageForResult ;
4
4
5
5
import android .annotation .SuppressLint ;
6
- import android .content .Context ;
7
6
import android .os .Bundle ;
8
- import android .text .TextUtils ;
9
- import android .util .DisplayMetrics ;
10
7
import android .view .LayoutInflater ;
11
- import android .view .MotionEvent ;
12
8
import android .view .View ;
13
9
import android .view .ViewGroup ;
14
- import android .widget .EditText ;
15
10
import android .widget .LinearLayout ;
16
11
import android .widget .TextView ;
17
12
import androidx .annotation .NonNull ;
24
19
import butterknife .ButterKnife ;
25
20
import butterknife .OnClick ;
26
21
import com .github .chrisbanes .photoview .PhotoView ;
27
- import com .jakewharton .rxbinding2 .widget .RxTextView ;
28
22
import fr .free .nrw .commons .R ;
29
23
import fr .free .nrw .commons .Utils ;
30
24
import fr .free .nrw .commons .filepicker .UploadableFile ;
34
28
import fr .free .nrw .commons .settings .Prefs ;
35
29
import fr .free .nrw .commons .upload .ImageCoordinates ;
36
30
import fr .free .nrw .commons .upload .SimilarImageDialogFragment ;
37
- import fr .free .nrw .commons .upload .Title ;
38
31
import fr .free .nrw .commons .upload .UploadBaseFragment ;
39
32
import fr .free .nrw .commons .upload .UploadMediaDetail ;
40
33
import fr .free .nrw .commons .upload .UploadMediaDetailAdapter ;
43
36
import fr .free .nrw .commons .utils .DialogUtil ;
44
37
import fr .free .nrw .commons .utils .ImageUtils ;
45
38
import fr .free .nrw .commons .utils .ViewUtil ;
46
- import io .reactivex .disposables .Disposable ;
47
39
import java .util .ArrayList ;
48
40
import java .util .Arrays ;
49
41
import java .util .List ;
@@ -66,8 +58,6 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
66
58
AppCompatImageButton ibExpandCollapse ;
67
59
@ BindView (R .id .ll_container_media_detail )
68
60
LinearLayout llContainerMediaDetail ;
69
- @ BindView (R .id .et_title )
70
- EditText etTitle ;
71
61
@ BindView (R .id .rv_descriptions )
72
62
RecyclerView rvDescriptions ;
73
63
@ BindView (R .id .backgroundImage )
@@ -94,7 +84,6 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
94
84
private String source ;
95
85
private Place place ;
96
86
97
- private Title title ;
98
87
private boolean isExpanded = true ;
99
88
100
89
private UploadMediaDetailFragmentCallback callback ;
@@ -131,24 +120,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
131
120
private void init () {
132
121
tvTitle .setText (getString (R .string .step_count , callback .getIndexInViewFlipper (this ) + 1 ,
133
122
callback .getTotalNumberOfSteps ()));
134
- title = new Title ();
135
123
initRecyclerView ();
136
124
initPresenter ();
137
- Disposable disposable = RxTextView .textChanges (etTitle )
138
- .subscribe (text -> {
139
- if (!TextUtils .isEmpty (text )) {
140
- btnNext .setEnabled (true );
141
- btnNext .setClickable (true );
142
- btnNext .setAlpha (1.0f );
143
- title .setTitleText (text .toString ());
144
- uploadItem .setTitle (title );
145
- } else {
146
- btnNext .setAlpha (0.5f );
147
- btnNext .setEnabled (false );
148
- btnNext .setClickable (false );
149
- }
150
- });
151
- compositeDisposable .add (disposable );
152
125
presenter .receiveImage (uploadableFile , source , place );
153
126
154
127
if (callback .getIndexInViewFlipper (this ) == 0 ) {
@@ -168,36 +141,6 @@ private void init() {
168
141
169
142
attachImageViewScaleChangeListener ();
170
143
171
- addEtTitleTouchListener ();
172
- }
173
-
174
- /**
175
- * Handles the drawable click listener for Edit Text
176
- */
177
- private void addEtTitleTouchListener () {
178
- etTitle .setOnTouchListener ((v , event ) -> {
179
- //2 is for drawable right
180
- float twelveDpInPixels = convertDpToPixel (12 , getContext ());
181
- if (event .getAction () == MotionEvent .ACTION_UP && etTitle .getCompoundDrawables () != null
182
- && etTitle .getCompoundDrawables ().length > 2 && etTitle
183
- .getCompoundDrawables ()[2 ].getBounds ()
184
- .contains ((int ) (etTitle .getWidth () - (event .getX () + twelveDpInPixels )),
185
- (int ) (event .getY () - twelveDpInPixels ))) {
186
- showInfoAlert (R .string .media_detail_title , R .string .title_info );
187
- return true ;
188
- }
189
- return false ;
190
- });
191
- }
192
-
193
- /**
194
- * converts dp to pixel
195
- * @param dp
196
- * @param context
197
- * @return
198
- */
199
- private float convertDpToPixel (float dp , Context context ) {
200
- return dp * ((float ) context .getResources ().getDisplayMetrics ().densityDpi / DisplayMetrics .DENSITY_DEFAULT );
201
144
}
202
145
203
146
/**
@@ -224,7 +167,7 @@ private void initPresenter() {
224
167
private void initRecyclerView () {
225
168
uploadMediaDetailAdapter = new UploadMediaDetailAdapter (defaultKvStore .getString (Prefs .KEY_LANGUAGE_VALUE , "" ));
226
169
uploadMediaDetailAdapter .setCallback (this ::showInfoAlert );
227
- uploadMediaDetailAdapter .setEventListener (this :: onEvent );
170
+ uploadMediaDetailAdapter .setEventListener (this );
228
171
rvDescriptions .setLayoutManager (new LinearLayoutManager (getContext ()));
229
172
rvDescriptions .setAdapter (uploadMediaDetailAdapter );
230
173
}
@@ -301,8 +244,7 @@ public void onNearbyPlaceFound(UploadItem uploadItem, Place place) {
301
244
getString (R .string .upload_nearby_place_found_description ),
302
245
place .getName ()),
303
246
() -> {
304
- etTitle .setText (place .getName ());
305
- descriptions = new ArrayList <>(Arrays .asList (new UploadMediaDetail ()));
247
+ descriptions = new ArrayList <>(Arrays .asList (new UploadMediaDetail (place )));
306
248
setDescriptionsInAdapter (descriptions );
307
249
},
308
250
() -> {
@@ -368,8 +310,7 @@ public void showBadImagePopup(Integer errorCode) {
368
310
}
369
311
370
312
@ Override
371
- public void setTitleAndDescription (String title , List <UploadMediaDetail > uploadMediaDetails ) {
372
- etTitle .setText (title );
313
+ public void setCaptionsAndDescriptions (List <UploadMediaDetail > uploadMediaDetails ) {
373
314
setDescriptionsInAdapter (uploadMediaDetails );
374
315
}
375
316
@@ -405,10 +346,10 @@ private void expandCollapseLlMediaDetail(boolean shouldExpand){
405
346
}
406
347
407
348
@ Override
408
- public void onEvent ( Boolean data ) {
409
- btnNext .setEnabled (data );
410
- btnNext .setClickable (data );
411
- btnNext .setAlpha (data ? 1.0f : 0.5f );
349
+ public void onPrimaryCaptionTextChange ( boolean isNotEmpty ) {
350
+ btnNext .setEnabled (isNotEmpty );
351
+ btnNext .setClickable (isNotEmpty );
352
+ btnNext .setAlpha (isNotEmpty ? 1.0f : 0.5f );
412
353
}
413
354
414
355
0 commit comments