10
10
import android .os .Bundle ;
11
11
import android .text .Editable ;
12
12
import android .text .Html ;
13
- import android .text .TextUtils ;
14
13
import android .text .TextWatcher ;
15
14
import android .util .TypedValue ;
16
15
import android .view .LayoutInflater ;
51
50
import fr .free .nrw .commons .delete .DeleteTask ;
52
51
import fr .free .nrw .commons .delete .ReasonBuilder ;
53
52
import fr .free .nrw .commons .di .CommonsDaggerSupportFragment ;
54
- import fr .free .nrw .commons .location .LatLng ;
55
53
import fr .free .nrw .commons .mwapi .MediaWikiApi ;
56
54
import fr .free .nrw .commons .ui .widget .CompatTextView ;
57
55
import fr .free .nrw .commons .utils .DateUtils ;
56
+ import fr .free .nrw .commons .utils .StringUtils ;
58
57
import io .reactivex .Single ;
59
58
import io .reactivex .android .schedulers .AndroidSchedulers ;
60
59
import io .reactivex .schedulers .Schedulers ;
61
60
import timber .log .Timber ;
62
61
63
62
import static android .view .View .GONE ;
64
63
import static android .view .View .VISIBLE ;
65
- import static android .widget .Toast .LENGTH_SHORT ;
66
64
67
65
public class MediaDetailFragment extends CommonsDaggerSupportFragment {
68
66
@@ -371,8 +369,9 @@ private void setTextFields(Media media) {
371
369
372
370
@ OnClick (R .id .mediaDetailLicense )
373
371
public void onMediaDetailLicenceClicked (){
374
- if (!TextUtils .isEmpty (licenseLink (media ))) {
375
- openWebBrowser (licenseLink (media ));
372
+ String url = licenseLink (media );
373
+ if (!StringUtils .isNullOrWhiteSpace (url ) && getActivity () != null ) {
374
+ Utils .handleWebUrl (getActivity (), Uri .parse (url ));
376
375
} else {
377
376
if (isCategoryImage ) {
378
377
Timber .d ("Unable to fetch license URL for %s" , media .getLicense ());
@@ -385,8 +384,8 @@ public void onMediaDetailLicenceClicked(){
385
384
386
385
@ OnClick (R .id .mediaDetailCoordinates )
387
386
public void onMediaDetailCoordinatesClicked (){
388
- if (media .getCoordinates () != null ) {
389
- openMap ( media .getCoordinates ());
387
+ if (media .getCoordinates () != null && getActivity () != null ) {
388
+ Utils . handleGeoCoordinates ( getActivity (), media .getCoordinates ());
390
389
}
391
390
}
392
391
@@ -484,8 +483,8 @@ private void onDeleteClicked(Spinner spinner) {
484
483
485
484
@ OnClick (R .id .seeMore )
486
485
public void onSeeMoreClicked (){
487
- if (nominatedForDeletion .getVisibility ()== VISIBLE ) {
488
- openWebBrowser ( media .getFilePageTitle ().getMobileUri (). toString ());
486
+ if (nominatedForDeletion .getVisibility () == VISIBLE && getActivity () != null ) {
487
+ Utils . handleWebUrl ( getActivity (), media .getFilePageTitle ().getMobileUri ());
489
488
}
490
489
}
491
490
@@ -623,26 +622,4 @@ String licenseLink(Media media) {
623
622
}
624
623
}
625
624
626
- private void openWebBrowser (String url ) {
627
- Intent browser = new Intent (Intent .ACTION_VIEW , Uri .parse (url ));
628
- //check if web browser available
629
- if (browser .resolveActivity (getActivity ().getPackageManager ()) != null ) {
630
- startActivity (browser );
631
- } else {
632
- Toast toast = Toast .makeText (getContext (), getString (R .string .no_web_browser ), LENGTH_SHORT );
633
- toast .show ();
634
- }
635
-
636
- }
637
-
638
- private void openMap (LatLng coordinates ) {
639
- //Open map app at given position
640
- Uri gmmIntentUri = Uri .parse (
641
- "geo:0,0?q=" + coordinates .getLatitude () + "," + coordinates .getLongitude ());
642
- Intent mapIntent = new Intent (Intent .ACTION_VIEW , gmmIntentUri );
643
-
644
- if (mapIntent .resolveActivity (getActivity ().getPackageManager ()) != null ) {
645
- startActivity (mapIntent );
646
- }
647
- }
648
625
}
0 commit comments