}
public static final class id {
public static final int ScrollView01=0x7f050000;
- public static final int addShelf=0x7f050008;
- public static final int catalogueBookListView=0x7f050004;
+ public static final int addShelf=0x7f05000c;
+ public static final int catalogueBookListView=0x7f050005;
public static final int catalogueListView=0x7f050002;
+ public static final int cataloguePrompt=0x7f050003;
public static final int catalogueSearch=0x7f050001;
- public static final int catalogueShelvesBookListView=0x7f050009;
- public static final int catalogueShelvesListView=0x7f050007;
- public static final int putOnShelf=0x7f050006;
- public static final int read_online=0x7f050003;
- public static final int sign_in=0x7f05000a;
- public static final int webview=0x7f050005;
+ public static final int catalogueShelvesBookListView=0x7f05000d;
+ public static final int catalogueShelvesListView=0x7f05000b;
+ public static final int icon=0x7f050007;
+ public static final int id=0x7f050008;
+ public static final int name=0x7f050009;
+ public static final int putOnShelf=0x7f05000a;
+ public static final int read_online=0x7f050004;
+ public static final int sign_in=0x7f05000e;
+ public static final int webview=0x7f050006;
}
public static final class layout {
public static final int about=0x7f030000;
public static final int catalogue_item_details=0x7f030004;
public static final int catalogue_list_item=0x7f030005;
public static final int catalogue_read_online=0x7f030006;
- public static final int catalogue_shelves=0x7f030007;
- public static final int catalogue_shelves_item=0x7f030008;
- public static final int catalogue_shelves_list_item=0x7f030009;
- public static final int settings=0x7f03000a;
- public static final int signin=0x7f03000b;
+ public static final int catalogue_row=0x7f030007;
+ public static final int catalogue_shelves=0x7f030008;
+ public static final int catalogue_shelves_item=0x7f030009;
+ public static final int catalogue_shelves_list_item=0x7f03000a;
+ public static final int settings=0x7f03000b;
+ public static final int signin=0x7f03000c;
}
public static final class string {
public static final int app_name=0x7f040000;
<ListView
android:id="@+id/catalogueListView"
android:layout_width="fill_parent"
- android:layout_height="wrap_content"
+ android:layout_height="wrap_content"
/>
+ <EditText
+ android:id="@+id/cataloguePrompt"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="Please type in author, book title, epoch, kind, genre or theme. (At least 2 characters)"
+ />
</LinearLayout>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:padding="6dip">
+ <ImageView
+ android:id="@+id/icon"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_marginRight="6dip"
+ android:src="@drawable/icon" />
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="20dip"
+ android:layout_weight="1"
+ android:layout_height="fill_parent">
+ <TextView
+ android:id="@+id/id"
+ android:layout_width="fill_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1"
+ android:gravity="center_vertical"
+ />
+ <TextView
+ android:layout_width="fill_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1"
+ android:id="@+id/name"
+ android:singleLine="true"
+ />
+ </LinearLayout>
+</LinearLayout>
\ No newline at end of file
private OAuthProvider mProvider;
private String mCallbackUrl;
private String authURL;
- private String apiURL = "http://192.168.148.129/api/";
+ private String apiURL = "http://epsilon.nowoczesnapolska.org.pl/api/";
@Override
public void onResume(){
Log.d("resume", "token0: "+token[0]);
Log.d("resume", "token1: "+token[1]);
- String accessToken[] = AuthHelper.getAccessToken(token[1]);
+ //String accessToken[] = AuthHelper.getAccessToken(token[1]);
- Log.d("resume", "token0: " + accessToken[0]);
- Log.d("resume", "token1: " + accessToken[1]);
- mConsumer = new CommonsHttpOAuthConsumer(accessToken[0], accessToken[1]);
+ Log.d("resume", "token0: " + token[0]);
+ Log.d("resume", "token1: " + token[1]);
+ mConsumer = new CommonsHttpOAuthConsumer(token[0], token[1]);
final URL url = new URL(apiURL+"tags/abc.json");
Log.d("url", "token1: "+url.toString());
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
-
} catch (OAuthMessageSignerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
- } catch (OAuthNotAuthorizedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
- // TODO Auto-generated catch block
+ // TODO Auto-generated catch block11
e.printStackTrace();
} catch (OAuthCommunicationException e) {
// TODO Auto-generated catch block
private static OAuthConsumer mConsumer;
private static OAuthProvider mProvider;
private static String mCallbackUrl;
- private static String apiURL = "http://192.168.148.129/api/";
+ private static String apiURL = "http://epsilon.nowoczesnapolska.org.pl/api/";
public static void OAuthHelper(String consumerKey, String consumerSecret, String callbackUrl)
throws UnsupportedEncodingException {
apiURL+"oauth/access_token/",
apiURL+"oauth/authorize/");
mProvider.setOAuth10a(true);
- mCallbackUrl = (callbackUrl == null ? OAuth.OUT_OF_BAND : callbackUrl);
+ mCallbackUrl = "wl://";
}
package pl.org.nowoczesnapolska;
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import android.app.Activity;
+import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
+import android.content.res.AssetFileDescriptor;
+import android.content.res.AssetManager;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.graphics.Paint.Join;
+import android.opengl.Visibility;
import android.os.Bundle;
+import android.os.ParcelFileDescriptor;
import android.text.Editable;
import android.text.TextWatcher;
+import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
static final private int MENU_SIGNIN = Menu.FIRST;
static final private int MENU_SETTINGS = Menu.FIRST+1;
static final private int MENU_ABOUT = Menu.FIRST+2;
-
- static final String[] AUTHORS = new String[] {
- "Władysław Anczyc",
- "Hans Christian Andersen",
- "Adam Asnyk",
- "Autor nieznany",
- "Honoré de Balzac",
- "Michał Bałucki",
- "Charles Baudelaire",
- "Władysław Bełza",
- "Miłosz Biedrzycki",
- "August Bielowski",
- "George Gordon Byron",
- "Joseph Conrad",
- "Anton Czechow",
- "Józef Czechowicz",
- "Daniel Defoe",
- "Casimir Delavigne",
- "Antonina Domańska",
- "Alojzy Feliński",
- "Aleksander Fredro",
- "Johann Wolfgang von Goethe",
- "Bruno Jasieński",
- "Franciszek Karpiński",
- "Jan Kasprowicz",
- "Rudyard Kipling",
- "Jan Kochanowski",
- "Maria Konopnicka",
- "Franciszek Kowalski",
- "Ignacy Krasicki",
- "Zygmunt Krasiński",
- "Teofil Lenartowicz",
- "Bolesław Leśmian",
- "Adam Mickiewicz",
- "Molière",
- "Jan Andrzej Morsztyn",
- "Julian Ursyn Niemcewicz",
- "Cyprian Kamil Norwid",
- "Artur Oppman",
- "Eliza Orzeszkowa",
- "Edgar Allan Poe",
- "Wincenty Pol",
- "Ludwik Ksawery Pomian-Łubiński",
- "Bolesław Prus",
- "Kazimierz Przerwa-Tetmajer",
- "Władysław Stanisław Reymont",
- "Mikołaj Sęp Szarzyński",
- "William Shakespeare",
- "Henryk Sienkiewicz",
- "Juliusz Słowacki",
- "Sofokles",
- "Rajnold Suchodolski",
- "Wacław Święcicki",
- "Władysław Tarnowski",
- "Stanisław Ignacy Witkiewicz",
- "Stefan Witwicki",
- "Józef Wybicki",
- "Stanisław Wyspiański",
- "Gabriela Zapolska",
- "Stefan Żeromski"
- };
+ SQLiteDatabase db;
+ public ArrayList<CatalogueEntry> searchList;
Context ctx;
+ public static ListView lv;
+ public CatalogueAdapter adapter;
+ int first = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.catalogue);
ctx = this;
- final ListView lv = (ListView) findViewById(R.id.catalogueListView);
+ lv = (ListView) findViewById(R.id.catalogueListView);
final EditText search = (EditText) findViewById(R.id.catalogueSearch);
+ final EditText prompt = (EditText) findViewById(R.id.cataloguePrompt);
- lv.setAdapter(new ArrayAdapter<String>(this, R.layout.catalogue_list_item, AUTHORS));
+ CatalogueDbHelper dbHelper = new CatalogueDbHelper(ctx);
+ db = dbHelper.getWritableDatabase();
+ searchList = new ArrayList();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
- startActivity(new Intent(ctx, CatalogueItem.class));
+ Log.d("selected id", id+"");
+ Log.d("selected id", this+"");
+ Log.d("selected type", searchList.get(position).getType()+"");
+ Log.d("selected name", searchList.get(position).getName()+"");
+ Intent selectedIntent = new Intent(ctx, CatalogueItem.class);
+ selectedIntent.putExtra("id", id);
+ selectedIntent.putExtra("type", searchList.get(position).getType());
+ startActivity(selectedIntent);
}
});
-
+
search.addTextChangedListener(new TextWatcher() {
-
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
- lv.setFilterText(s.toString());
+ if(s.toString().length() > 1) {
+ lv.setVisibility(0); // == VISIBLE
+
+ String[] filter = new String[2];
+ String term = s.toString()+"%";
+ Log.d("char str:",term);
+ filter[0] = term;
+ filter[1] = term;
+ Cursor cur = db.rawQuery("select name, id, type from (select title as name, id, 0 as type from books where title like '"+term+"%' UNION ALL select name, id, 1 as type from tags where name like '"+term+"%') order by name", null);
+ cur.moveToFirst();
+ int i = 0;
+ searchList.clear();
+ while(i < cur.getCount()){
+ try {
+ Log.d("query result", cur.getString(0));
+ searchList.add(new CatalogueEntry(cur.getInt(2), cur.getInt(1), cur.getString(0)));
+ } catch (Exception e) {
+ Log.d("query result count", cur.getColumnCount() + " " + cur.getPosition());
+ }
+ cur.moveToNext();
+ i++;
+ Log.d("test listy ctx", ctx.toString());
+ Log.d("test listy r.", R.layout.catalogue_list_item+"");
+ Log.d("test listy list", searchList.size() + "");
+ Log.d("test listy lv", lv.toString());
+ }
+ if(searchList.size() > 0) {
+ if(first == 1) {
+ adapter = new CatalogueAdapter(ctx, R.layout.catalogue_row, searchList);
+ lv.setAdapter(adapter);
+ first = 0;
+ }
+ adapter.notifyDataSetChanged();
+ }
+ } else {
+ searchList.clear();
+ if(adapter != null) {
+ adapter.notifyDataSetChanged();
+ }
+ }
}
@Override
}
});
+
+
+ Cursor c = db.rawQuery("select id from tags limit 2", null);// do zmiany
+ Log.d("db", c.getCount()+"");
+
+ /* this is memory consuming and should be optimized. it is first-run only, though */
+ if(c.getCount() == 0) {
+ AssetManager assetManager = getAssets();
+ try {
+ Log.d("assets", assetManager.list("/assets").length+"");
+ for(String s: assetManager.list("/assets")){
+ Log.d("assets", s);
+ }
+ InputStream is = assetManager.open("catalogue.jpg", AssetManager.ACCESS_BUFFER);
+ String catalogueString = readInputStreamAsString(is);
+ JSONObject jObject = null;
+ try {
+ //new JSONOBj
+ jObject = new JSONObject(catalogueString);
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Log.d("assets", catalogueString.length()+"");
+ JSONObject added = jObject.getJSONObject("added");
+ JSONArray books = added.getJSONArray("books"); // books
+ JSONArray tags = added.getJSONArray("tags"); // tags
+
+ Log.d("json array books length", books.length()+"");
+ Log.d("json array tags length", tags.length()+"");
+ Log.d("json array length", added.length()+"");
+
+ for(int i = 0; i < books.length(); i++){
+ JSONObject book = books.getJSONObject(i);
+ Log.d("json-test", book.get("id").toString() + book.get("title").toString() + book.get("slug").toString());
+ // JSONException
+ ContentValues bookMap = new ContentValues();
+ bookMap.put("id", book.get("id").toString());
+ bookMap.put("title", book.get("title").toString());
+ bookMap.put("slug", book.get("slug").toString());
+ bookMap.put("epub", "epub");
+ bookMap.put("html", "html");
+ bookMap.put("mp3", "mp3");
+
+ long id = db.insert("books", null, bookMap);
+ Log.d("sql", id+"");
+ }
+
+ for(int i = 0; i < tags.length(); i++){
+ JSONObject tag = tags.getJSONObject(i);
+ Log.d("json-test", tag.get("id").toString() + tag.get("name").toString() + tag.get("slug").toString()+ tag.get("sort_key").toString()+ tag.get("category").toString());
+ // JSONException
+
+ //String bookData[] = {book.get("id").toString(), book.get("title").toString(), book.get("slug").toString()};
+ ContentValues tagMap = new ContentValues();
+ tagMap.put("id", tag.get("id").toString());
+ tagMap.put("name", tag.get("name").toString());
+ tagMap.put("slug", tag.get("slug").toString());
+ tagMap.put("sort_key", tag.get("sort_key").toString());
+ tagMap.put("category", tag.get("category").toString());
+ tagMap.put("description", "description");
+ long id = db.insert("tags", null, tagMap);
+ Log.d("sql", id+"");
+ }
+
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
}
@Override
return false;
}
+ public static String readInputStreamAsString(InputStream is)
+ throws IOException {
+
+ if (is != null) {
+ Writer writer = new StringWriter();
+
+ /* be careful if tempted to change buffer size, OutOfMemory exception is watching you */
+ char[] buffer = new char[1024];
+ try {
+ Reader reader = new BufferedReader(
+ new InputStreamReader(is, "UTF-8"));
+ int n;
+ while ((n = reader.read(buffer)) != -1) {
+ writer.write(buffer, 0, n);
+ }
+ } finally {
+ is.close();
+ }
+ return writer.toString();
+ } else {
+ return "";
+ }
+ }
+
}
\ No newline at end of file
--- /dev/null
+package pl.org.nowoczesnapolska;
+
+import java.util.ArrayList;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.BaseAdapter;
+import android.widget.TextView;
+
+class CatalogueAdapter extends BaseAdapter {
+ private ArrayList<CatalogueEntry> items;
+ private Context ctx;
+
+ public CatalogueAdapter(Context context, int textViewResourceId, ArrayList<CatalogueEntry> items) {
+ this.items = items;
+ this.ctx = context;
+ }
+
+ @Override
+ public int getCount() {
+ // TODO Auto-generated method stub
+ return items.size();
+ }
+ @Override
+ public Object getItem(int position) {
+ // TODO Auto-generated method stub
+ return items.get(position);
+ }
+ @Override
+ public long getItemId(int position) {
+ return items.get(position).getId();
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View v = convertView;
+ if (v == null) {
+ LayoutInflater vi = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ v = vi.inflate(R.layout.catalogue_row, null);
+ }
+ CatalogueEntry o = items.get(position);
+ if (o != null) {
+ Log.d("not null", "not null");
+ TextView tt = (TextView) v.findViewById(R.id.id);
+ TextView bt = (TextView) v.findViewById(R.id.name);
+ if (tt != null) {
+ tt.setText("Name: "+o.getName()); }
+ if(bt != null){
+ bt.setText("Type: "+ o.getType());
+ }
+ }
+ Log.d("dalej", "dalej");
+ return v;
+ }
+}
\ No newline at end of file
--- /dev/null
+package pl.org.nowoczesnapolska;
+import android.content.Context;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteDatabase.CursorFactory;
+import android.database.sqlite.SQLiteOpenHelper;
+
+public class CatalogueDbHelper extends SQLiteOpenHelper {
+
+ public CatalogueDbHelper(Context context, String name,
+ CursorFactory factory, int version) {
+ super(context, name, factory, version);
+ // TODO Auto-generated constructor stub
+ }
+
+ private static final int DATABASE_VERSION = 2;
+ private static final String TAGS_TABLE = "tags";
+ private static final String BOOKS_TABLE = "books";
+
+ private static final String TAGS_TABLE_CREATE =
+ "CREATE TABLE " + TAGS_TABLE + " (" +
+ "id INTEGER, " +
+ "name TEXT, " +
+ "slug TEXT, " +
+ "sort_key TEXT, " +
+ "category TEXT, " +
+ "description TEXT " +
+ ");";
+
+ private static final String BOOKS_TABLE_CREATE =
+ "CREATE TABLE " + BOOKS_TABLE + " (" +
+ "id INTEGER, " +
+ "title TEXT, " +
+ "slug TEXT, " +
+ "epub TEXT, " +
+ "html TEXT, " +
+ "mp3 TEXT " +
+ ");";
+ private static final String DATABASE_NAME = "wl-mobile";
+
+ CatalogueDbHelper(Context context) {
+ super(context, DATABASE_NAME, null, DATABASE_VERSION);
+ }
+
+ @Override
+ public void onCreate(SQLiteDatabase db) {
+ db.execSQL(BOOKS_TABLE_CREATE);
+ db.execSQL(TAGS_TABLE_CREATE);
+ }
+
+ @Override
+ public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
+ // TODO Auto-generated method stub
+ }
+}
\ No newline at end of file
--- /dev/null
+package pl.org.nowoczesnapolska;
+
+public class CatalogueEntry {
+ // type: 0 -- book, 1 -- tag
+ private int type;
+ private int id;
+ private String name;
+ public CatalogueEntry(int type, int id, String name){
+ setType(type);
+ setId(id);
+ setName(name);
+ }
+ public void setType(int type) {
+ this.type = type;
+ }
+ public int getType() {
+ return type;
+ }
+ public void setId(int id) {
+ this.id = id;
+ }
+ public int getId() {
+ return id;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public String getName() {
+ return name;
+ }
+}
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
static final private int MENU_SETTINGS = Menu.FIRST+2;
static final private int MENU_ABOUT = Menu.FIRST+3;
+ private SQLiteDatabase db;
+
Context ctx;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.catalogue_item_details);
ctx = this;
+
+ int id = getIntent().getIntExtra("id", 0);
+ int type = getIntent().getIntExtra("type", 0);
+ String[] options = new String[2];
+ options[0] = new String(id+"");
+ options[1] = new String(type+"");
+
+ /*if(type == 0){
+ // books
+ Cursor c = db.rawQuery("select * from books where id = ?", options);
+ } else {
+ // tags
+ }*/
+
+ CatalogueDbHelper dbHelper = new CatalogueDbHelper(ctx);
+ db = dbHelper.getWritableDatabase();
final ListView lv = (ListView) findViewById(R.id.catalogueBookListView);