Skip to content

Commit 038da0c

Browse files
committed
Improved search view for more visual clarity & better i18n pull script
1 parent 89f534a commit 038da0c

File tree

13 files changed

+163
-187
lines changed

13 files changed

+163
-187
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,5 +237,5 @@ sample/src/main/assets/products.major
237237
sample/src/main/assets/products.minor
238238
sample/src/main/assets/products.sqlite3
239239
sample/src/main/assets/metadata.json
240-
ui/src/main/res/values/strings.xml
240+
241241
maven-repository

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ allprojects {
2424
}
2525

2626
project.ext {
27-
sdkVersion='0.8.0'
27+
sdkVersion='0.8.1'
2828
versionCode=1
2929

3030
compileSdkVersion=27

core/src/main/java/io/snabble/sdk/Checkout.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,6 @@ public void onResponse(Call call, Response response) throws IOException {
327327
String json = IOUtils.toString(inputStream, Charset.forName("UTF-8"));
328328
signedCheckoutInfo = gson.fromJson(json, SignedCheckoutInfo.class);
329329

330-
Logger.d("Local price: " + shoppingCart.getTotalPrice()
331-
+ ", Remote price: " + signedCheckoutInfo.checkoutInfo.get("price"));
332-
333330
if(signedCheckoutInfo.checkoutInfo.has("price")
334331
&& signedCheckoutInfo.checkoutInfo.get("price").getAsJsonObject().has("price")) {
335332
priceToPay = signedCheckoutInfo.checkoutInfo
@@ -343,7 +340,7 @@ public void onResponse(Call call, Response response) throws IOException {
343340

344341
if(priceToPay != shoppingCart.getTotalPrice()){
345342
Logger.w("Warning local price is different from remotely calculated price! (Local: "
346-
+ shoppingCart.getTotalPrice() + ", Remote: " + priceToPay);
343+
+ shoppingCart.getTotalPrice() + ", Remote: " + priceToPay + ")");
347344
}
348345

349346
PaymentMethod[] availablePaymentMethods = getAvailablePaymentMethods();

i18n/Snabble.twine

Lines changed: 0 additions & 118 deletions
This file was deleted.

pull-i18n.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
#!/bin/bash
2-
git subtree pull --prefix i18n https://github.com/snabble/SDK-i18n master --squash
2+
git clone --depth=1 [email protected]:snabble/SDK-i18n.git i18ntemp
3+
4+
twine generate-all-localization-files i18ntemp/Snabble.twine ui/src/main/res/ --tags android --untagged --format android
5+
6+
rm -rf i18ntemp
7+
git add ui/src/main/res/values/strings.xml

scripts/i18n.gradle

Lines changed: 0 additions & 25 deletions
This file was deleted.

ui/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
apply plugin: 'com.android.library'
22
apply from: '../scripts/findbugs.gradle'
3-
apply from: '../scripts/i18n.gradle'
43

54
android {
65
compileSdkVersion project.compileSdkVersion

ui/src/main/java/io/snabble/sdk/ui/search/ProductSearchView.java

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import android.view.KeyEvent;
1010
import android.view.View;
1111
import android.view.inputmethod.EditorInfo;
12-
import android.view.inputmethod.InputMethodManager;
1312
import android.widget.EditText;
1413
import android.widget.FrameLayout;
1514
import android.widget.TextView;
@@ -21,10 +20,11 @@
2120
import io.snabble.sdk.ui.telemetry.Telemetry;
2221

2322
public class ProductSearchView extends FrameLayout {
24-
private RecyclerView recyclerView;
2523
private SearchableProductAdapter searchableProductAdapter;
2624
private EditText searchBar;
2725
private boolean searchBarEnabled;
26+
private TextView addCodeAsIs;
27+
private String lastSearchQuery;
2828

2929
public ProductSearchView(Context context) {
3030
super(context);
@@ -44,7 +44,9 @@ public ProductSearchView(Context context, AttributeSet attrs, int defStyleAttr)
4444
private void inflateView() {
4545
inflate(getContext(), R.layout.view_search_product, this);
4646

47-
recyclerView = findViewById(R.id.recycler_view);
47+
SnabbleSdk sdkInstance = SnabbleUI.getSdkInstance();
48+
49+
RecyclerView recyclerView = findViewById(R.id.recycler_view);
4850
searchBar = findViewById(R.id.search_bar);
4951
searchBar.addTextChangedListener(new TextWatcher() {
5052
@Override
@@ -59,7 +61,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
5961

6062
@Override
6163
public void afterTextChanged(Editable s) {
62-
searchableProductAdapter.search(s.toString());
64+
search(s.toString());
6365
}
6466
});
6567

@@ -84,13 +86,7 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
8486
}
8587
});
8688

87-
setSdkInstance(SnabbleUI.getSdkInstance());
88-
}
89-
90-
public void setSdkInstance(SnabbleSdk sdkInstance) {
91-
if (sdkInstance == null) {
92-
return;
93-
}
89+
addCodeAsIs = findViewById(R.id.add_code_as_is);
9490

9591
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
9692
searchableProductAdapter = new SearchableProductAdapter(sdkInstance.getProductDatabase());
@@ -99,17 +95,36 @@ public void setSdkInstance(SnabbleSdk sdkInstance) {
9995
searchableProductAdapter.setOnProductSelectedListener(new OnProductSelectedListener() {
10096
@Override
10197
public void onProductSelected(String scannableCode) {
102-
Telemetry.event(Telemetry.Event.ManuallyEnteredProduct, scannableCode);
98+
showScannerWithCode(scannableCode);
99+
}
100+
});
103101

104-
SnabbleUICallback callback = SnabbleUI.getUiCallback();
105-
if (callback != null) {
106-
callback.showScannerWithCode(scannableCode);
107-
}
102+
searchableProductAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
103+
@Override
104+
public void onChanged() {
105+
onSearchUpdated();
106+
}
107+
});
108+
109+
addCodeAsIs.setOnClickListener(new OnClickListener() {
110+
@Override
111+
public void onClick(View v) {
112+
showScannerWithCode(lastSearchQuery);
108113
}
109114
});
115+
110116
recyclerView.setAdapter(searchableProductAdapter);
111117
}
112118

119+
private void showScannerWithCode(String scannableCode) {
120+
Telemetry.event(Telemetry.Event.ManuallyEnteredProduct, scannableCode);
121+
122+
SnabbleUICallback callback = SnabbleUI.getUiCallback();
123+
if (callback != null) {
124+
callback.showScannerWithCode(scannableCode);
125+
}
126+
}
127+
113128
public void setSearchBarEnabled(boolean searchBarEnabled) {
114129
this.searchBarEnabled = searchBarEnabled;
115130

@@ -125,22 +140,17 @@ public void search(String searchQuery) {
125140
searchBar.setText(searchQuery);
126141
}
127142

143+
lastSearchQuery = searchQuery;
128144
searchableProductAdapter.search(searchQuery);
129145
}
130146

131-
132-
public void show() {
133-
setVisibility(View.VISIBLE);
134-
searchBar.setText("");
135-
136-
if (searchBar.requestFocus()) {
137-
InputMethodManager imm = (InputMethodManager) getContext()
138-
.getSystemService(Context.INPUT_METHOD_SERVICE);
139-
imm.showSoftInput(searchBar, InputMethodManager.SHOW_IMPLICIT);
147+
private void onSearchUpdated() {
148+
if(searchableProductAdapter.getItemCount() == 0
149+
&& lastSearchQuery != null && lastSearchQuery.length() > 0){
150+
addCodeAsIs.setText(getResources().getString(R.string.Snabble_Scanner_addCodeAsIs, lastSearchQuery));
151+
addCodeAsIs.setVisibility(View.VISIBLE);
152+
} else {
153+
addCodeAsIs.setVisibility(View.GONE);
140154
}
141155
}
142-
143-
public void hide() {
144-
setVisibility(View.GONE);
145-
}
146156
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="rectangle">
4+
<corners android:radius="15dp" />
5+
<size
6+
android:width="343dp"
7+
android:height="57dp" />
8+
<solid android:color="#FFFFFFFF" />
9+
</shape>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="rectangle">
4+
<corners android:radius="15dp" />
5+
<size
6+
android:width="343dp"
7+
android:height="57dp" />
8+
<solid android:color="#FFFFFFFF" />
9+
<stroke
10+
android:color="#1A000000"
11+
android:width="1.25dp" />
12+
</shape>

0 commit comments

Comments
 (0)