219 lines
9.4 KiB
Java
219 lines
9.4 KiB
Java
package com.google.zxing.client.android.book;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Intent;
|
|
import android.os.AsyncTask;
|
|
import android.os.Bundle;
|
|
import android.util.Log;
|
|
import android.view.KeyEvent;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.EditText;
|
|
import android.widget.ListAdapter;
|
|
import android.widget.ListView;
|
|
import android.widget.TextView;
|
|
import com.google.zxing.client.android.HttpHelper;
|
|
import com.google.zxing.client.android.LocaleManager;
|
|
import com.google.zxing.client.android.R$id;
|
|
import com.google.zxing.client.android.R$layout;
|
|
import com.google.zxing.client.android.R$string;
|
|
import com.tencent.bugly.Bugly;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.regex.Pattern;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class SearchBookContentsActivity extends Activity {
|
|
private static final String i = SearchBookContentsActivity.class.getSimpleName();
|
|
private static final Pattern j = Pattern.compile("<.*?>");
|
|
private static final Pattern k = Pattern.compile("<");
|
|
private static final Pattern l = Pattern.compile(">");
|
|
private static final Pattern m = Pattern.compile("'");
|
|
private static final Pattern n = Pattern.compile(""");
|
|
private String a;
|
|
private EditText b;
|
|
private View c;
|
|
private ListView d;
|
|
private TextView e;
|
|
private AsyncTask<String, ?, ?> f;
|
|
private final View.OnClickListener g = new View.OnClickListener() { // from class: com.google.zxing.client.android.book.SearchBookContentsActivity.1
|
|
@Override // android.view.View.OnClickListener
|
|
public void onClick(View view) {
|
|
SearchBookContentsActivity.this.h();
|
|
}
|
|
};
|
|
private final View.OnKeyListener h = new View.OnKeyListener() { // from class: com.google.zxing.client.android.book.SearchBookContentsActivity.2
|
|
@Override // android.view.View.OnKeyListener
|
|
public boolean onKey(View view, int i2, KeyEvent keyEvent) {
|
|
if (i2 != 66 || keyEvent.getAction() != 0) {
|
|
return false;
|
|
}
|
|
SearchBookContentsActivity.this.h();
|
|
return true;
|
|
}
|
|
};
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void h() {
|
|
String obj = this.b.getText().toString();
|
|
if (obj == null || obj.isEmpty()) {
|
|
return;
|
|
}
|
|
AsyncTask<String, ?, ?> asyncTask = this.f;
|
|
if (asyncTask != null) {
|
|
asyncTask.cancel(true);
|
|
}
|
|
this.f = new NetworkTask();
|
|
this.f.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, obj, this.a);
|
|
this.e.setText(R$string.msg_sbc_searching_book);
|
|
this.d.setAdapter((ListAdapter) null);
|
|
this.b.setEnabled(false);
|
|
this.c.setEnabled(false);
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
public void onCreate(Bundle bundle) {
|
|
super.onCreate(bundle);
|
|
Intent intent = getIntent();
|
|
if (intent == null || !"com.google.zxing.client.android.SEARCH_BOOK_CONTENTS".equals(intent.getAction())) {
|
|
finish();
|
|
return;
|
|
}
|
|
this.a = intent.getStringExtra("ISBN");
|
|
if (LocaleManager.a(this.a)) {
|
|
setTitle(getString(R$string.sbc_name));
|
|
} else {
|
|
setTitle(getString(R$string.sbc_name) + ": ISBN " + this.a);
|
|
}
|
|
setContentView(R$layout.search_book_contents);
|
|
this.b = (EditText) findViewById(R$id.query_text_view);
|
|
String stringExtra = intent.getStringExtra("QUERY");
|
|
if (stringExtra != null && !stringExtra.isEmpty()) {
|
|
this.b.setText(stringExtra);
|
|
}
|
|
this.b.setOnKeyListener(this.h);
|
|
this.c = findViewById(R$id.query_button);
|
|
this.c.setOnClickListener(this.g);
|
|
this.d = (ListView) findViewById(R$id.result_list_view);
|
|
this.e = (TextView) LayoutInflater.from(this).inflate(R$layout.search_book_contents_header, (ViewGroup) this.d, false);
|
|
this.d.addHeaderView(this.e);
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
protected void onPause() {
|
|
AsyncTask<String, ?, ?> asyncTask = this.f;
|
|
if (asyncTask != null) {
|
|
asyncTask.cancel(true);
|
|
this.f = null;
|
|
}
|
|
super.onPause();
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
protected void onResume() {
|
|
super.onResume();
|
|
this.b.selectAll();
|
|
}
|
|
|
|
String a() {
|
|
return this.a;
|
|
}
|
|
|
|
private final class NetworkTask extends AsyncTask<String, Object, JSONObject> {
|
|
private NetworkTask() {
|
|
}
|
|
|
|
private void b(JSONObject jSONObject) {
|
|
try {
|
|
int i = jSONObject.getInt("number_of_results");
|
|
SearchBookContentsActivity.this.e.setText(SearchBookContentsActivity.this.getString(R$string.msg_sbc_results) + " : " + i);
|
|
if (i <= 0) {
|
|
if (Bugly.SDK_IS_DEV.equals(jSONObject.optString("searchable"))) {
|
|
SearchBookContentsActivity.this.e.setText(R$string.msg_sbc_book_not_searchable);
|
|
}
|
|
SearchBookContentsActivity.this.d.setAdapter((ListAdapter) null);
|
|
return;
|
|
}
|
|
JSONArray jSONArray = jSONObject.getJSONArray("search_results");
|
|
SearchBookContentsResult.a(SearchBookContentsActivity.this.b.getText().toString());
|
|
ArrayList arrayList = new ArrayList(i);
|
|
for (int i2 = 0; i2 < i; i2++) {
|
|
arrayList.add(c(jSONArray.getJSONObject(i2)));
|
|
}
|
|
SearchBookContentsActivity.this.d.setOnItemClickListener(new BrowseBookListener(SearchBookContentsActivity.this, arrayList));
|
|
SearchBookContentsActivity.this.d.setAdapter((ListAdapter) new SearchBookContentsAdapter(SearchBookContentsActivity.this, arrayList));
|
|
} catch (JSONException e) {
|
|
Log.w(SearchBookContentsActivity.i, "Bad JSON from book search", e);
|
|
SearchBookContentsActivity.this.d.setAdapter((ListAdapter) null);
|
|
SearchBookContentsActivity.this.e.setText(R$string.msg_sbc_failed);
|
|
}
|
|
}
|
|
|
|
private SearchBookContentsResult c(JSONObject jSONObject) {
|
|
String str;
|
|
String str2;
|
|
boolean z = false;
|
|
try {
|
|
String string = jSONObject.getString("page_id");
|
|
String optString = jSONObject.optString("page_number");
|
|
String optString2 = jSONObject.optString("snippet_text");
|
|
if (optString == null || optString.isEmpty()) {
|
|
str = "";
|
|
} else {
|
|
str = SearchBookContentsActivity.this.getString(R$string.msg_sbc_page) + ' ' + optString;
|
|
}
|
|
if (optString2 != null && !optString2.isEmpty()) {
|
|
z = true;
|
|
}
|
|
if (z) {
|
|
str2 = SearchBookContentsActivity.n.matcher(SearchBookContentsActivity.m.matcher(SearchBookContentsActivity.l.matcher(SearchBookContentsActivity.k.matcher(SearchBookContentsActivity.j.matcher(optString2).replaceAll("")).replaceAll("<")).replaceAll(">")).replaceAll("'")).replaceAll("\"");
|
|
} else {
|
|
str2 = '(' + SearchBookContentsActivity.this.getString(R$string.msg_sbc_snippet_unavailable) + ')';
|
|
}
|
|
return new SearchBookContentsResult(string, str, str2, z);
|
|
} catch (JSONException e) {
|
|
Log.w(SearchBookContentsActivity.i, e);
|
|
return new SearchBookContentsResult(SearchBookContentsActivity.this.getString(R$string.msg_sbc_no_page_returned), "", "", false);
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: protected */
|
|
@Override // android.os.AsyncTask
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public JSONObject doInBackground(String... strArr) {
|
|
String str;
|
|
try {
|
|
String str2 = strArr[0];
|
|
String str3 = strArr[1];
|
|
if (LocaleManager.a(str3)) {
|
|
str = "http://www.google.com/books?id=" + str3.substring(str3.indexOf(61) + 1) + "&jscmd=SearchWithinVolume2&q=" + str2;
|
|
} else {
|
|
str = "http://www.google.com/books?vid=isbn" + str3 + "&jscmd=SearchWithinVolume2&q=" + str2;
|
|
}
|
|
return new JSONObject(HttpHelper.a(str, HttpHelper.ContentType.JSON).toString());
|
|
} catch (IOException | JSONException e) {
|
|
Log.w(SearchBookContentsActivity.i, "Error accessing book search", e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: protected */
|
|
@Override // android.os.AsyncTask
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public void onPostExecute(JSONObject jSONObject) {
|
|
if (jSONObject == null) {
|
|
SearchBookContentsActivity.this.e.setText(R$string.msg_sbc_failed);
|
|
} else {
|
|
b(jSONObject);
|
|
}
|
|
SearchBookContentsActivity.this.b.setEnabled(true);
|
|
SearchBookContentsActivity.this.b.selectAll();
|
|
SearchBookContentsActivity.this.c.setEnabled(true);
|
|
}
|
|
}
|
|
}
|