Fix issue with new pitch accent representation
app/src/main/java/eu/lepiller/nani/ResultPagerAdapter.java
| 154 | 154 | ||
| 155 | 155 | // If pitch information is available, make it visible | |
| 156 | 156 | String pitch = result.getPitch(); | |
| 157 | - | if(pitch != null) { | |
| 157 | + | if(pitch != null && !pitch.isEmpty()) { | |
| 158 | + | // Try to get rid of additional characters, by finding the first number. | |
| 159 | + | // XXX: this means the result contains only the first pattern | |
| 160 | + | StringBuilder number = new StringBuilder(); | |
| 161 | + | boolean foundFirst = false; | |
| 162 | + | for(int i = 0; i<pitch.length(); i++) { | |
| 163 | + | if(pitch.charAt(i) < '0' || pitch.charAt(i) > '9') { | |
| 164 | + | if(foundFirst) | |
| 165 | + | break; | |
| 166 | + | } else { | |
| 167 | + | foundFirst = true; | |
| 168 | + | number.append(pitch.charAt(i)); | |
| 169 | + | } | |
| 170 | + | } | |
| 171 | + | String cleanPitch = number.toString(); | |
| 172 | + | int pitchInt = -1; | |
| 173 | + | if(!cleanPitch.isEmpty()) | |
| 174 | + | pitchInt = Integer.parseInt(cleanPitch); | |
| 175 | + | ||
| 158 | 176 | if(pitchStyle.compareTo("box") == 0) { | |
| 159 | 177 | pitch_view.setVisibility(View.VISIBLE); | |
| 160 | 178 | pitch_diagram.setVisibility(View.GONE); | |
| 161 | 179 | pitch_contour.setVisibility(View.GONE); | |
| 162 | 180 | } else if(pitchStyle.compareTo("diagram") == 0) { | |
| 163 | - | if(readingStyle.compareTo("kana") == 0) { | |
| 164 | - | reading_view.setVisibility(View.GONE); | |
| 165 | - | } | |
| 166 | - | pitch_diagram.setVisibility(View.VISIBLE); | |
| 167 | 181 | pitch_contour.setVisibility(View.GONE); | |
| 168 | 182 | pitch_view.setVisibility(View.GONE); | |
| 169 | - | pitch_diagram.setText(result.getReading()); | |
| 170 | - | pitch_diagram.setPitch(Integer.parseInt(pitch)); | |
| 171 | - | } else if(pitchStyle.compareTo("contour") == 0) { | |
| 172 | - | if(readingStyle.compareTo("kana") == 0) { | |
| 173 | - | reading_view.setVisibility(View.GONE); | |
| 183 | + | if(pitchInt >= 0) { | |
| 184 | + | if (readingStyle.compareTo("kana") == 0) { | |
| 185 | + | reading_view.setVisibility(View.GONE); | |
| 186 | + | } | |
| 187 | + | pitch_diagram.setVisibility(View.VISIBLE); | |
| 188 | + | pitch_diagram.setText(result.getReading()); | |
| 189 | + | pitch_diagram.setPitch(pitchInt); | |
| 190 | + | } else { | |
| 191 | + | pitch_diagram.setVisibility(View.GONE); | |
| 174 | 192 | } | |
| 175 | - | pitch_contour.setVisibility(View.VISIBLE); | |
| 193 | + | } else if(pitchStyle.compareTo("contour") == 0) { | |
| 176 | 194 | pitch_diagram.setVisibility(View.GONE); | |
| 177 | 195 | pitch_view.setVisibility(View.GONE); | |
| 178 | - | pitch_contour.setText(result.getReading()); | |
| 179 | - | pitch_contour.setPitch(Integer.parseInt(pitch)); | |
| 196 | + | if(pitchInt >= 0) { | |
| 197 | + | if (readingStyle.compareTo("kana") == 0) { | |
| 198 | + | reading_view.setVisibility(View.GONE); | |
| 199 | + | } | |
| 200 | + | pitch_contour.setVisibility(View.VISIBLE); | |
| 201 | + | pitch_contour.setText(result.getReading()); | |
| 202 | + | pitch_contour.setPitch(pitchInt); | |
| 203 | + | } else { | |
| 204 | + | pitch_contour.setVisibility(View.GONE); | |
| 205 | + | } | |
| 180 | 206 | } | |
| 181 | 207 | ||
| 182 | 208 | pitch_view.setText(pitch); |