29
29
30
30
import java .util .ArrayList ;
31
31
32
+ import butterknife .BindView ;
33
+ import butterknife .ButterKnife ;
34
+ import butterknife .OnClick ;
35
+ import butterknife .OnItemSelected ;
36
+ import butterknife .OnTouch ;
32
37
import fr .free .nrw .commons .Prefs ;
33
38
import fr .free .nrw .commons .R ;
34
39
import fr .free .nrw .commons .Utils ;
35
40
36
41
public class SingleUploadFragment extends Fragment {
42
+ private SharedPreferences prefs ;
43
+ private String license ;
37
44
38
45
public interface OnUploadActionInitiated {
39
46
void uploadActionInitiated (String title , String description );
40
47
}
41
48
42
- private EditText titleEdit ;
43
- private EditText descEdit ;
44
- private TextView licenseSummaryView ;
45
- private Spinner licenseSpinner ;
49
+ @ BindView (R .id .titleEdit ) EditText titleEdit ;
50
+ @ BindView (R .id .descEdit ) EditText descEdit ;
51
+ @ BindView (R .id .titleDescButton ) Button titleDescButton ;
52
+ @ BindView (R .id .share_license_summary ) TextView licenseSummaryView ;
53
+ @ BindView (R .id .licenseSpinner ) Spinner licenseSpinner ;
46
54
47
55
private OnUploadActionInitiated uploadActionInitiatedHandler ;
48
56
@@ -82,12 +90,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
82
90
@ Override
83
91
public View onCreateView (LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState ) {
84
92
View rootView = inflater .inflate (R .layout .fragment_single_upload , null );
85
-
86
- titleEdit = (EditText )rootView .findViewById (R .id .titleEdit );
87
- descEdit = (EditText )rootView .findViewById (R .id .descEdit );
88
- Button titleDescButton = (Button ) rootView .findViewById (R .id .titleDescButton );
89
- licenseSpinner = (Spinner ) rootView .findViewById (R .id .licenseSpinner );
90
- licenseSummaryView = (TextView )rootView .findViewById (R .id .share_license_summary );
93
+ ButterKnife .bind (this , rootView );
91
94
92
95
ArrayList <String > licenseItems = new ArrayList <>();
93
96
licenseItems .add (getString (R .string .license_name_cc0 ));
@@ -96,8 +99,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
96
99
licenseItems .add (getString (R .string .license_name_cc_by_four ));
97
100
licenseItems .add (getString (R .string .license_name_cc_by_sa_four ));
98
101
99
- final SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences (getActivity ());
100
- final String license = prefs .getString (Prefs .DEFAULT_LICENSE , Prefs .Licenses .CC_BY_SA_3 );
102
+ prefs = PreferenceManager .getDefaultSharedPreferences (getActivity ());
103
+ license = prefs .getString (Prefs .DEFAULT_LICENSE , Prefs .Licenses .CC_BY_SA_3 );
101
104
102
105
Log .d ("Single Upload fragment" , license );
103
106
@@ -108,59 +111,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
108
111
Log .d ("Single Upload fragment" , "Position:" +position +" " +getString (Utils .licenseNameFor (license )));
109
112
licenseSpinner .setSelection (position );
110
113
111
- licenseSpinner .setOnItemSelectedListener (new AdapterView .OnItemSelectedListener () {
112
- @ Override
113
- public void onItemSelected (AdapterView <?> parent , View view , int position , long id ) {
114
-
115
- //Set selected color to white because it should be readable on random images.
116
- TextView selectedText = (TextView ) licenseSpinner .getChildAt (0 );
117
- if (selectedText != null ) {
118
- selectedText .setTextColor (Color .WHITE );
119
- }
120
-
121
- String licenseName = parent .getItemAtPosition (position ).toString ();
122
-
123
- String license = Prefs .Licenses .CC_BY_SA_3 ; // default value
124
- if (getString (R .string .license_name_cc0 ).equals (licenseName )) {
125
- license = Prefs .Licenses .CC0 ;
126
- } else if (getString (R .string .license_name_cc_by ).equals (licenseName )) {
127
- license = Prefs .Licenses .CC_BY_3 ;
128
- } else if (getString (R .string .license_name_cc_by_sa ).equals (licenseName )) {
129
- license = Prefs .Licenses .CC_BY_SA_3 ;
130
- } else if (getString (R .string .license_name_cc_by_four ).equals (licenseName )) {
131
- license = Prefs .Licenses .CC_BY_4 ;
132
- } else if (getString (R .string .license_name_cc_by_sa_four ).equals (licenseName )) {
133
- license = Prefs .Licenses .CC_BY_SA_4 ;
134
- }
135
-
136
- setLicenseSummary (license );
137
- SharedPreferences .Editor editor = prefs .edit ();
138
- editor .putString (Prefs .DEFAULT_LICENSE , license );
139
- editor .apply ();
140
- }
141
-
142
- @ Override
143
- public void onNothingSelected (AdapterView <?> parent ) {
144
-
145
- }
146
- });
147
-
148
- titleDescButton .setOnClickListener (new View .OnClickListener ()
149
- {
150
- @ Override
151
- public void onClick (View v )
152
- {
153
- //Retrieve last title and desc entered
154
- SharedPreferences titleDesc = PreferenceManager .getDefaultSharedPreferences (getActivity ());
155
- String title = titleDesc .getString ("Title" , "" );
156
- String desc = titleDesc .getString ("Desc" , "" );
157
- Log .d (TAG , "Title: " + title + ", Desc: " + desc );
158
-
159
- titleEdit .setText (title );
160
- descEdit .setText (desc );
161
- }
162
- });
163
-
164
114
TextWatcher uploadEnabler = new TextWatcher () {
165
115
@ Override
166
116
public void beforeTextChanged (CharSequence charSequence , int i , int i2 , int i3 ) { }
@@ -180,25 +130,54 @@ public void afterTextChanged(Editable editable) {
180
130
181
131
setLicenseSummary (license );
182
132
183
- // Open license page on touch
184
- licenseSummaryView .setOnTouchListener (new View .OnTouchListener () {
185
- @ Override
186
- public boolean onTouch (View view , MotionEvent motionEvent ) {
187
- if (motionEvent .getActionMasked () == MotionEvent .ACTION_DOWN ) {
188
- Intent intent = new Intent ();
189
- intent .setAction (Intent .ACTION_VIEW );
190
- intent .setData (Uri .parse (Utils .licenseUrlFor (license )));
191
- startActivity (intent );
192
- return true ;
193
- } else {
194
- return false ;
195
- }
196
- }
197
- });
198
-
199
133
return rootView ;
200
134
}
201
135
136
+ @ OnItemSelected (R .id .licenseSpinner ) void onLicenseSelected (AdapterView <?> parent , View view , int position , long id ) {
137
+ String licenseName = parent .getItemAtPosition (position ).toString ();
138
+
139
+ String license = Prefs .Licenses .CC_BY_SA_3 ; // default value
140
+ if (getString (R .string .license_name_cc0 ).equals (licenseName )) {
141
+ license = Prefs .Licenses .CC0 ;
142
+ } else if (getString (R .string .license_name_cc_by ).equals (licenseName )) {
143
+ license = Prefs .Licenses .CC_BY_3 ;
144
+ } else if (getString (R .string .license_name_cc_by_sa ).equals (licenseName )) {
145
+ license = Prefs .Licenses .CC_BY_SA_3 ;
146
+ } else if (getString (R .string .license_name_cc_by_four ).equals (licenseName )) {
147
+ license = Prefs .Licenses .CC_BY_4 ;
148
+ } else if (getString (R .string .license_name_cc_by_sa_four ).equals (licenseName )) {
149
+ license = Prefs .Licenses .CC_BY_SA_4 ;
150
+ }
151
+
152
+ setLicenseSummary (license );
153
+ SharedPreferences .Editor editor = prefs .edit ();
154
+ editor .putString (Prefs .DEFAULT_LICENSE , license );
155
+ editor .commit ();
156
+ }
157
+
158
+ @ OnTouch (R .id .share_license_summary ) boolean showLicence (View view , MotionEvent motionEvent ) {
159
+ if (motionEvent .getActionMasked () == MotionEvent .ACTION_DOWN ) {
160
+ Intent intent = new Intent ();
161
+ intent .setAction (Intent .ACTION_VIEW );
162
+ intent .setData (Uri .parse (Utils .licenseUrlFor (license )));
163
+ startActivity (intent );
164
+ return true ;
165
+ } else {
166
+ return false ;
167
+ }
168
+ }
169
+
170
+ @ OnClick (R .id .titleDescButton ) void setTitleDescButton () {
171
+ //Retrieve last title and desc entered
172
+ SharedPreferences titleDesc = PreferenceManager .getDefaultSharedPreferences (getActivity ());
173
+ String title = titleDesc .getString ("Title" , "" );
174
+ String desc = titleDesc .getString ("Desc" , "" );
175
+ Log .d (TAG , "Title: " + title + ", Desc: " + desc );
176
+
177
+ titleEdit .setText (title );
178
+ descEdit .setText (desc );
179
+ }
180
+
202
181
private void setLicenseSummary (String license ) {
203
182
licenseSummaryView .setText (getString (R .string .share_license_summary , getString (Utils .licenseNameFor (license ))));
204
183
}
0 commit comments