6
6
import android .content .SharedPreferences ;
7
7
import android .support .v4 .app .Fragment ;
8
8
import android .support .transition .TransitionManager ;
9
+ import android .support .v7 .app .AlertDialog ;
9
10
import android .support .v7 .widget .PopupMenu ;
10
11
import android .util .Log ;
11
12
import android .view .LayoutInflater ;
27
28
import butterknife .ButterKnife ;
28
29
import fr .free .nrw .commons .R ;
29
30
import fr .free .nrw .commons .Utils ;
31
+ import fr .free .nrw .commons .auth .LoginActivity ;
30
32
import fr .free .nrw .commons .contributions .ContributionController ;
31
33
import fr .free .nrw .commons .di .ApplicationlessInjection ;
32
34
import timber .log .Timber ;
33
35
36
+ import static fr .free .nrw .commons .theme .NavigationBaseActivity .startActivityWithFlags ;
37
+
34
38
public class PlaceRenderer extends Renderer <Place > {
35
39
40
+ @ Inject
41
+ @ Named ("application_preferences" ) SharedPreferences applicationPrefs ;
36
42
@ BindView (R .id .tvName ) TextView tvName ;
37
43
@ BindView (R .id .tvDesc ) TextView tvDesc ;
38
44
@ BindView (R .id .distance ) TextView distance ;
@@ -88,9 +94,9 @@ protected void hookListeners(View view) {
88
94
Log .d ("Renderer" , "clicked" );
89
95
TransitionManager .beginDelayedTransition (buttonLayout );
90
96
91
- if (buttonLayout .isShown ()){
97
+ if (buttonLayout .isShown ()) {
92
98
closeLayout (buttonLayout );
93
- }else {
99
+ } else {
94
100
openLayout (buttonLayout );
95
101
}
96
102
@@ -106,18 +112,46 @@ protected void hookListeners(View view) {
106
112
});
107
113
108
114
cameraButton .setOnClickListener (view2 -> {
109
- Timber .d ("Camera button tapped. Image title: " + place .getName () + "Image desc: " + place .getLongDescription ());
110
- DirectUpload directUpload = new DirectUpload (fragment , controller );
111
- storeSharedPrefs ();
112
- directUpload .initiateCameraUpload ();
115
+ if (applicationPrefs .getBoolean ("login_skipped" , true )) {
116
+ // prompt the user to login
117
+ new AlertDialog .Builder (getContext ())
118
+ .setMessage (R .string .login_alert_message )
119
+ .setPositiveButton (R .string .login , (dialog , which ) -> {
120
+ startActivityWithFlags ( getContext (), LoginActivity .class , Intent .FLAG_ACTIVITY_CLEAR_TOP ,
121
+ Intent .FLAG_ACTIVITY_SINGLE_TOP );
122
+ prefs .edit ().putBoolean ("login_skipped" , false ).apply ();
123
+ fragment .getActivity ().finish ();
124
+ })
125
+ .show ();
126
+ } else {
127
+ Timber .d ("Camera button tapped. Image title: " + place .getName () + "Image desc: " + place .getLongDescription ());
128
+ DirectUpload directUpload = new DirectUpload (fragment , controller );
129
+ storeSharedPrefs ();
130
+ directUpload .initiateCameraUpload ();
131
+ }
113
132
});
114
133
134
+
115
135
galleryButton .setOnClickListener (view3 -> {
116
- Timber .d ("Gallery button tapped. Image title: " + place .getName () + "Image desc: " + place .getLongDescription ());
117
- DirectUpload directUpload = new DirectUpload (fragment , controller );
118
- storeSharedPrefs ();
119
- directUpload .initiateGalleryUpload ();
136
+ if (applicationPrefs .getBoolean ("login_skipped" , true )) {
137
+ // prompt the user to login
138
+ new AlertDialog .Builder (getContext ())
139
+ .setMessage (R .string .login_alert_message )
140
+ .setPositiveButton (R .string .login , (dialog , which ) -> {
141
+ startActivityWithFlags ( getContext (), LoginActivity .class , Intent .FLAG_ACTIVITY_CLEAR_TOP ,
142
+ Intent .FLAG_ACTIVITY_SINGLE_TOP );
143
+ prefs .edit ().putBoolean ("login_skipped" , false ).apply ();
144
+ fragment .getActivity ().finish ();
145
+ })
146
+ .show ();
147
+ }else {
148
+ Timber .d ("Gallery button tapped. Image title: " + place .getName () + "Image desc: " + place .getLongDescription ());
149
+ DirectUpload directUpload = new DirectUpload (fragment , controller );
150
+ storeSharedPrefs ();
151
+ directUpload .initiateGalleryUpload ();
152
+ }
120
153
});
154
+
121
155
}
122
156
123
157
private void storeSharedPrefs () {
0 commit comments