33import android .util .SparseArray ;
44
55import com .google .gson .JsonObject ;
6- import com .google .gson .annotations .SerializedName ;
76
87import io .snabble .sdk .Project ;
98import io .snabble .sdk .utils .JsonUtils ;
109
1110public class EncodedCodesOptions {
11+ public interface Sorter {
12+ int compare (EncodedCodesGenerator .ProductInfo productInfo1 ,
13+ EncodedCodesGenerator .ProductInfo productInfo2 );
14+ }
15+
1216 public static final int DEFAULT_MAX_CHARS = 2953 ;
1317 public static final int DEFAULT_MAX_CODES = 100 ;
1418
@@ -25,12 +29,14 @@ public class EncodedCodesOptions {
2529 public final String countSeparator ;
2630 public final int maxSizeMm ;
2731 public final Project project ;
32+ public final Sorter sorter ;
2833
2934 private EncodedCodesOptions (String prefix , SparseArray <String > prefixMap , String separator , String suffix , int maxChars ,
3035 int maxCodes , String finalCode , String nextCode ,
3136 String nextCodeWithCheck , boolean repeatCodes , String countSeparator ,
3237 int maxSizeMm ,
33- Project project ) {
38+ Project project ,
39+ Sorter sorter ) {
3440 this .prefix = prefix ;
3541 this .prefixMap = prefixMap ;
3642 this .separator = separator ;
@@ -44,6 +50,7 @@ private EncodedCodesOptions(String prefix, SparseArray<String> prefixMap, String
4450 this .countSeparator = countSeparator ;
4551 this .maxSizeMm = maxSizeMm ;
4652 this .project = project ;
53+ this .sorter = sorter ;
4754 }
4855
4956 public static class Builder {
@@ -60,6 +67,7 @@ public static class Builder {
6067 private boolean repeatCodes = true ;
6168 private String countSeparator = ";" ;
6269 private int maxSizeMm ;
70+ private Sorter sorter ;
6371
6472 public Builder (Project project ) {
6573 this .project = project ;
@@ -125,9 +133,15 @@ public Builder maxSizeMm(int maxSizeMm) {
125133 return this ;
126134 }
127135
136+ public Builder maxSizeMm (Sorter sorter ) {
137+ this .sorter = sorter ;
138+ return this ;
139+ }
140+
128141 public EncodedCodesOptions build () {
129142 return new EncodedCodesOptions (prefix , prefixMap , separator , suffix , maxChars , maxCodes ,
130- finalCode , nextCode , nextCodeWithCheck , repeatCodes , countSeparator , maxSizeMm , project );
143+ finalCode , nextCode , nextCodeWithCheck , repeatCodes , countSeparator ,
144+ maxSizeMm , project , sorter );
131145 }
132146 }
133147
@@ -178,7 +192,7 @@ public static EncodedCodesOptions fromJsonObject(Project project, JsonObject jso
178192 .build ();
179193 case "simple" :
180194 default :
181- return new EncodedCodesOptions .Builder (project )
195+ EncodedCodesOptions . Builder builder = new EncodedCodesOptions .Builder (project )
182196 .prefix (JsonUtils .getStringOpt (jsonObject , "prefix" , "" ))
183197 .suffix (JsonUtils .getStringOpt (jsonObject , "suffix" , "" ))
184198 .separator (separator )
@@ -187,8 +201,35 @@ public static EncodedCodesOptions fromJsonObject(Project project, JsonObject jso
187201 .finalCode (finalCode )
188202 .nextCode (JsonUtils .getStringOpt (jsonObject , "nextCode" , "" ))
189203 .nextCodeWithCheck (JsonUtils .getStringOpt (jsonObject , "nextCodeWithCheck" , "" ))
190- .maxSizeMm (JsonUtils .getIntOpt (jsonObject , "maxSizeMM" , -1 ))
191- .build ();
204+ .maxSizeMm (JsonUtils .getIntOpt (jsonObject , "maxSizeMM" , -1 ));
205+
206+ if (project .getId ().contains ("knauber" )) {
207+ builder .sorter = new Sorter () {
208+ @ Override
209+ public int compare (EncodedCodesGenerator .ProductInfo productInfo1 ,
210+ EncodedCodesGenerator .ProductInfo productInfo2 ) {
211+ final String catchAll = "2030801009887" ;
212+
213+ String tc1 = productInfo1 .product .getTransmissionCode (
214+ productInfo1 .scannedCode .getTemplateName (),
215+ productInfo1 .scannedCode .getLookupCode ());
216+
217+ String tc2 = productInfo2 .product .getTransmissionCode (
218+ productInfo2 .scannedCode .getTemplateName (),
219+ productInfo2 .scannedCode .getLookupCode ());
220+
221+ if (catchAll .equals (tc1 )) {
222+ return 1 ;
223+ } else if (catchAll .equals (tc2 )) {
224+ return -1 ;
225+ } else {
226+ return 0 ;
227+ }
228+ }
229+ };
230+ }
231+
232+ return builder .build ();
192233 }
193234 }
194235}
0 commit comments