6
6
import android .content .SharedPreferences ;
7
7
import android .net .Uri ;
8
8
import android .os .Bundle ;
9
+ import android .preference .ListPreference ;
9
10
import android .preference .PreferenceManager ;
10
11
import android .support .v4 .app .Fragment ;
11
12
import android .text .Editable ;
19
20
import android .view .View ;
20
21
import android .view .ViewGroup ;
21
22
import android .view .inputmethod .InputMethodManager ;
23
+ import android .widget .AdapterView ;
24
+ import android .widget .ArrayAdapter ;
22
25
import android .widget .Button ;
23
26
import android .widget .EditText ;
27
+ import android .widget .Spinner ;
24
28
import android .widget .TextView ;
25
29
30
+ import java .util .ArrayList ;
31
+ import java .util .List ;
32
+
26
33
import fr .free .nrw .commons .Prefs ;
27
34
import fr .free .nrw .commons .R ;
28
35
import fr .free .nrw .commons .Utils ;
@@ -36,6 +43,7 @@ public interface OnUploadActionInitiated {
36
43
private EditText titleEdit ;
37
44
private EditText descEdit ;
38
45
private TextView licenseSummaryView ;
46
+ private Spinner licenseSpinner ;
39
47
40
48
private OnUploadActionInitiated uploadActionInitiatedHandler ;
41
49
@@ -79,6 +87,57 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
79
87
titleEdit = (EditText )rootView .findViewById (R .id .titleEdit );
80
88
descEdit = (EditText )rootView .findViewById (R .id .descEdit );
81
89
Button titleDescButton = (Button ) rootView .findViewById (R .id .titleDescButton );
90
+ licenseSpinner = (Spinner ) rootView .findViewById (R .id .licenseSpinner );
91
+ licenseSummaryView = (TextView )rootView .findViewById (R .id .share_license_summary );
92
+
93
+ ArrayList <String > licenseItems = new ArrayList <>();
94
+ licenseItems .add (getString (R .string .license_name_cc0 ));
95
+ licenseItems .add (getString (R .string .license_name_cc_by ));
96
+ licenseItems .add (getString (R .string .license_name_cc_by_sa ));
97
+ licenseItems .add (getString (R .string .license_name_cc_by_four ));
98
+ licenseItems .add (getString (R .string .license_name_cc_by_sa_four ));
99
+
100
+ final SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences (getActivity ());
101
+ final String license = prefs .getString (Prefs .DEFAULT_LICENSE , Prefs .Licenses .CC_BY_SA_3 );
102
+
103
+ Log .d ("Single Upload fragment" , license );
104
+
105
+ ArrayAdapter <String > adapter = new ArrayAdapter <>(getActivity (), android .R .layout .simple_spinner_dropdown_item , licenseItems );
106
+ licenseSpinner .setAdapter (adapter );
107
+
108
+ int position = licenseItems .indexOf (getString (Utils .licenseNameFor (license )));
109
+ Log .d ("Single Upload fragment" , "Position:" +position +" " +getString (Utils .licenseNameFor (license )));
110
+ licenseSpinner .setSelection (position );
111
+
112
+ licenseSpinner .setOnItemSelectedListener (new AdapterView .OnItemSelectedListener () {
113
+ @ Override
114
+ public void onItemSelected (AdapterView <?> parent , View view , int position , long id ) {
115
+ String licenseName = parent .getItemAtPosition (position ).toString ();
116
+
117
+ String license = Prefs .Licenses .CC_BY_SA_3 ; // default value
118
+ if (getString (R .string .license_name_cc0 ).equals (licenseName )) {
119
+ license = Prefs .Licenses .CC0 ;
120
+ } else if (getString (R .string .license_name_cc_by ).equals (licenseName )) {
121
+ license = Prefs .Licenses .CC_BY_3 ;
122
+ } else if (getString (R .string .license_name_cc_by_sa ).equals (licenseName )) {
123
+ license = Prefs .Licenses .CC_BY_SA_3 ;
124
+ } else if (getString (R .string .license_name_cc_by_four ).equals (licenseName )) {
125
+ license = Prefs .Licenses .CC_BY_4 ;
126
+ } else if (getString (R .string .license_name_cc_by_sa_four ).equals (licenseName )) {
127
+ license = Prefs .Licenses .CC_BY_SA_4 ;
128
+ }
129
+
130
+ setLicenseSummary (license );
131
+ SharedPreferences .Editor editor = prefs .edit ();
132
+ editor .putString (Prefs .DEFAULT_LICENSE , license );
133
+ editor .commit ();
134
+ }
135
+
136
+ @ Override
137
+ public void onNothingSelected (AdapterView <?> parent ) {
138
+
139
+ }
140
+ });
82
141
83
142
titleDescButton .setOnClickListener (new View .OnClickListener ()
84
143
{
@@ -96,8 +155,6 @@ public void onClick(View v)
96
155
}
97
156
});
98
157
99
- licenseSummaryView = (TextView )rootView .findViewById (R .id .share_license_summary );
100
-
101
158
TextWatcher uploadEnabler = new TextWatcher () {
102
159
@ Override
103
160
public void beforeTextChanged (CharSequence charSequence , int i , int i2 , int i3 ) { }
@@ -115,9 +172,7 @@ public void afterTextChanged(Editable editable) {
115
172
116
173
titleEdit .addTextChangedListener (uploadEnabler );
117
174
118
- SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences (getActivity ());
119
- final String license = prefs .getString (Prefs .DEFAULT_LICENSE , Prefs .Licenses .CC_BY_SA_3 );
120
- licenseSummaryView .setText (getString (R .string .share_license_summary , getString (Utils .licenseNameFor (license ))));
175
+ setLicenseSummary (license );
121
176
122
177
// Open license page on touch
123
178
licenseSummaryView .setOnTouchListener (new View .OnTouchListener () {
@@ -138,6 +193,10 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
138
193
return rootView ;
139
194
}
140
195
196
+ private void setLicenseSummary (String license ) {
197
+ licenseSummaryView .setText (getString (R .string .share_license_summary , getString (Utils .licenseNameFor (license ))));
198
+ }
199
+
141
200
@ Override
142
201
public void onAttach (Activity activity ) {
143
202
super .onAttach (activity );
0 commit comments