Commits

Juha Kuitunen committed a5e88d2

localized typeSpinners in NewIssueActivity and UpdateIssueActivity with help of our new shiny tool TwoWayMap ;)

Comments (0)

Files changed (4)

res/layout/new_issue.xml

             <Spinner
                 android:id="@+id/new_issue_type"
                 android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:entries="@array/type_of_issue" >
+                android:layout_height="wrap_content" >
             </Spinner>
 
             <!-- Issue priority -->

res/values/strings.xml

     <string name="type">Type</string>
     <string name="username">Username</string>
     <string name="password">Password</string>
-    <string-array name="type_of_issue">
-        <item>bug</item>
-        <item>enhancement</item>
-        <item>proposal</item>
-        <item >task</item>
-    </string-array>
     <string name="submit_new_issue">Submit new issue</string>
     <string name="hint">"Note: You don't need to login to use the search function!"</string>
     <string name="issue_filter_prompt">Filter issues</string>

src/com/saibotd/bitbeaker/NewIssueActivity.java

 
 import android.app.Activity;
 import android.os.Bundle;
+import android.widget.ArrayAdapter;
 import android.widget.EditText;
 import android.widget.Spinner;
 
 
 	public String slug;
 	public String owner;
+	private Spinner typeSpinner;
 
 	@Override
 	public void onCreate(Bundle savedInstanceState) {
 		setContentView(R.layout.new_issue);
 		setTitle(slug);
 		getSupportActionBar().setSubtitle(this.getString(R.string.report_new_issue));
+
+		typeSpinner = (Spinner) findViewById(R.id.new_issue_type);
+		String[] typeOptions = {
+				Helper.translatedApiStrings.getByKey("bug"),
+				Helper.translatedApiStrings.getByKey("enhancement"),
+				Helper.translatedApiStrings.getByKey("proposal"),
+				Helper.translatedApiStrings.getByKey("task")
+		};
+		ArrayAdapter<String> typeSpinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, typeOptions);
+		typeSpinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+		typeSpinner.setAdapter(typeSpinnerArrayAdapter);
 	}
 
 	@Override
 			String title = ((EditText) findViewById(R.id.new_issue_title)).getText().toString();
 			String content = ((EditText) findViewById(R.id.new_issue_content)).getText().toString();
 
-			String type;
-			switch (((Spinner) findViewById(R.id.new_issue_type)).getSelectedItemPosition()) {
-				case 0:
-					type = "bug";
-					break;
-				case 1:
-					type = "enhancement";
-					break;
-				case 2:
-					type = "proposal";
-					break;
-				case 3:
-					type = "task";
-					break;
-				default:
-					type = "bug";
-			}
+			String type = Helper.translatedApiStrings.getByValue(typeSpinner.getSelectedItem().toString());
+
 			String priority;
 			switch (((Spinner) findViewById(R.id.new_issue_priority)).getSelectedItemPosition()) {
 				case 0:

src/com/saibotd/bitbeaker/UpdateIssueActivity.java

 
 import android.app.Activity;
 import android.os.Bundle;
+import android.widget.ArrayAdapter;
 import android.widget.EditText;
 import android.widget.Spinner;
 
 			// Issue type.
 			initialType = issueJson.getJSONObject("metadata").getString("kind");
 			typeSpinner = (Spinner) findViewById(R.id.new_issue_type);
-			String[] typeOptions = getResources().getStringArray(R.array.type_of_issue);
+			String[] typeOptions = {
+					Helper.translatedApiStrings.getByKey("bug"),
+					Helper.translatedApiStrings.getByKey("enhancement"),
+					Helper.translatedApiStrings.getByKey("proposal"),
+					Helper.translatedApiStrings.getByKey("task")
+			};
+			ArrayAdapter<String> typeSpinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, typeOptions);
+			typeSpinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+			typeSpinner.setAdapter(typeSpinnerArrayAdapter);
 			int type_index = 0;
 			for (String type : typeOptions) {
 				if (type.equalsIgnoreCase(initialType)) {
 				postParams += Helper.encode(contentEditor.getText().toString());
 			}
 
-			if (!initialType.equalsIgnoreCase(typeSpinner.getSelectedItem().toString())) {
+			if (!initialType.equalsIgnoreCase(Helper.translatedApiStrings.getByValue(typeSpinner.getSelectedItem().toString()))) {
 
 				if (0 < postParams.length()) {
 					postParams += "&kind=";
 				} else {
 					postParams = "kind=";
 				}
-				postParams += typeSpinner.getSelectedItem();
+				postParams += Helper.translatedApiStrings.getByValue(typeSpinner.getSelectedItem().toString());
 
 			}
 			
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.