From 78639af3ed8ce637c1e1169e750a02d5ba4d5556 Mon Sep 17 00:00:00 2001 From: Silvio Date: Thu, 13 Feb 2014 11:04:57 +0100 Subject: [PATCH] Kaj sam promjenil za sad: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #1 - prebacil MySimpleArrayAdapter u novu klasu da se Lista novosti lakše čita. #2 - iz liste novosti maknul referencu na samu Activity jer je nepotrebno. #3 - LzzRestApi generateInclude metodu promjenil da koristi StringBuilder. #4 - Fiksne url-ove promjenil u private static final polja sa velikim slovima. #5 - U ListaNovosti klasi sam implementiral OnItemClickListener i napravil cleanScreen metodu. #6 - U ListaNovosti klasi sam izmjenjal malo redoslijed instanciranja Adaptera. #7 - HTTP_FEEDS_FEEDBURNER_COM_LINUXZASVE ListaNovosti. #8 - Toast sam promjenil. DONE : ------------------------------------------------------------------------------------ 1# U ListaNovosti da se kod rotiranja uređaja ne skida ponovo s neta materijal već da se spremi u bundel instancu i reloada. Ovo povlači dosta parcelable posla, nvm 3^^^ :D TO DO : ------------------------------------------------------------------------------------ 2# Isto to spremanje u Bundle napraviti za komentare. --- LinuxZaSve_mobile/.classpath | 7 +- LinuxZaSve_mobile/KajSamNapravil.txt | 20 ++ LinuxZaSve_mobile/lint.xml | 3 + LinuxZaSve_mobile/project.properties | 2 +- LinuxZaSve_mobile/res/menu/lista_novosti.xml | 3 + LinuxZaSve_mobile/res/values/strings.xml | 2 +- .../com/linuxzasve/mobile/ActivityHelper.java | 5 +- .../com/linuxzasve/mobile/ListaNovosti.java | 263 +++++++++--------- .../mobile/adapters/MySimpleArrayAdapter.java | 69 +++++ .../linuxzasve/mobile/rest/Attachment.java | 52 +++- .../com/linuxzasve/mobile/rest/Author.java | 50 +++- .../com/linuxzasve/mobile/rest/Category.java | 58 +++- .../com/linuxzasve/mobile/rest/Comment.java | 48 +++- .../linuxzasve/mobile/rest/CustomFiels.java | 38 ++- .../linuxzasve/mobile/rest/DetailedImage.java | 44 ++- .../src/com/linuxzasve/mobile/rest/Image.java | 47 +++- .../linuxzasve/mobile/rest/LzsRestApi.java | 48 ++-- .../src/com/linuxzasve/mobile/rest/Post.java | 105 ++++++- .../src/com/linuxzasve/mobile/rest/Tag.java | 56 +++- .../com/linuxzasve/mobile/rest/Thumbnail.java | 47 +++- .../linuxzasve/mobile/timthumb/TimThumb.java | 7 +- 21 files changed, 765 insertions(+), 209 deletions(-) create mode 100644 LinuxZaSve_mobile/KajSamNapravil.txt create mode 100644 LinuxZaSve_mobile/lint.xml create mode 100644 LinuxZaSve_mobile/src/com/linuxzasve/mobile/adapters/MySimpleArrayAdapter.java diff --git a/LinuxZaSve_mobile/.classpath b/LinuxZaSve_mobile/.classpath index fe99cc3..5029672 100644 --- a/LinuxZaSve_mobile/.classpath +++ b/LinuxZaSve_mobile/.classpath @@ -5,12 +5,11 @@ - - + - - + + diff --git a/LinuxZaSve_mobile/KajSamNapravil.txt b/LinuxZaSve_mobile/KajSamNapravil.txt new file mode 100644 index 0000000..fc28e97 --- /dev/null +++ b/LinuxZaSve_mobile/KajSamNapravil.txt @@ -0,0 +1,20 @@ +Kaj sam promjenil za sad: + +#1 - prebacil MySimpleArrayAdapter u novu klasu da se Lista novosti lake ita. +#2 - iz liste novosti maknul referencu na samu Activity jer je nepotrebno. +#3 - LzzRestApi generateInclude metodu promjenil da koristi StringBuilder. +#4 - Fiksne url-ove promjenil u private static final polja sa velikim slovima. +#5 - U ListaNovosti klasi sam implementiral OnItemClickListener i napravil cleanScreen metodu. +#6 - U ListaNovosti klasi sam izmjenjal malo redoslijed instanciranja Adaptera. +#7 - HTTP_FEEDS_FEEDBURNER_COM_LINUXZASVE ListaNovosti. +#8 - Toast sam promjenil. + +DONE : +------------------------------------------------------------------------------------ +1# U ListaNovosti da se kod rotiranja ureaja ne skida ponovo s neta materijal ve da se spremi u bundel instancu i reloada. + Ovo povlai dosta parcelable posla, nvm 3^^^ :D + +TO DO : +------------------------------------------------------------------------------------ +2# Isto to spremanje u Bundle napraviti za komentare. + diff --git a/LinuxZaSve_mobile/lint.xml b/LinuxZaSve_mobile/lint.xml new file mode 100644 index 0000000..ee0eead --- /dev/null +++ b/LinuxZaSve_mobile/lint.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/LinuxZaSve_mobile/project.properties b/LinuxZaSve_mobile/project.properties index 59b580a..d0628c4 100644 --- a/LinuxZaSve_mobile/project.properties +++ b/LinuxZaSve_mobile/project.properties @@ -12,4 +12,4 @@ # Project target. target=android-19 -android.library.reference.1=../../ActionBarSherlock/actionbarsherlock +android.library.reference.1=../../JakeWharton-ActionBarSherlock-5a15d92/actionbarsherlock diff --git a/LinuxZaSve_mobile/res/menu/lista_novosti.xml b/LinuxZaSve_mobile/res/menu/lista_novosti.xml index f04b8de..4f1da02 100644 --- a/LinuxZaSve_mobile/res/menu/lista_novosti.xml +++ b/LinuxZaSve_mobile/res/menu/lista_novosti.xml @@ -1,11 +1,14 @@ + + + diff --git a/LinuxZaSve_mobile/res/values/strings.xml b/LinuxZaSve_mobile/res/values/strings.xml index 740af0c..a60ef42 100644 --- a/LinuxZaSve_mobile/res/values/strings.xml +++ b/LinuxZaSve_mobile/res/values/strings.xml @@ -1,6 +1,7 @@ Linux za sve Linux za sve + Najnoviji Članci Komentari Osvježi Pretraži @@ -14,5 +15,4 @@ Komentar Pretraži Linux za sve Linux za sve - \ No newline at end of file diff --git a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/ActivityHelper.java b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/ActivityHelper.java index 4116516..3630c83 100644 --- a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/ActivityHelper.java +++ b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/ActivityHelper.java @@ -9,9 +9,10 @@ public class ActivityHelper { public static boolean isOnline(Activity activity) { ConnectivityManager cm = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); - if (netInfo != null && netInfo.isConnectedOrConnecting()) { + + if (netInfo != null && netInfo.isConnectedOrConnecting()) return true; - } + return false; } } diff --git a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/ListaNovosti.java b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/ListaNovosti.java index 730f38b..a32888c 100644 --- a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/ListaNovosti.java +++ b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/ListaNovosti.java @@ -1,22 +1,20 @@ package com.linuxzasve.mobile; import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; -import android.content.Context; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; -import android.view.LayoutInflater; +import android.os.Parcelable; +import android.util.Log; import android.view.View; -import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; -import android.widget.ArrayAdapter; -import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; -import android.widget.TextView; import android.widget.Toast; import com.actionbarsherlock.app.ActionBar; @@ -25,20 +23,103 @@ import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; import com.google.gson.Gson; -import com.koushikdutta.urlimageviewhelper.UrlImageViewHelper; +import com.linuxzasve.mobile.adapters.MySimpleArrayAdapter; import com.linuxzasve.mobile.rest.LzsRestApi; import com.linuxzasve.mobile.rest.LzsRestResponse; import com.linuxzasve.mobile.rest.Post; -import com.linuxzasve.mobile.timthumb.TimThumb; -public class ListaNovosti extends SherlockActivity { +public class ListaNovosti extends SherlockActivity implements OnItemClickListener{ - private ListView listaClanaka; - private ListaNovosti ovaAct; - public static List values; - LinearLayout novostiProgressLayout; + private static final String HTTP_FEEDS_FEEDBURNER_COM_LINUXZASVE = "http://feeds.feedburner.com/linuxzasve"; + private static final String KEY_VALUES_BUNDLE_SESSION = "valuesOfPosts"; + + private LinearLayout novostiProgressLayout; private MenuItem refresh; + public static List values; + + @Override + public void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.lista_novosti); + + ListView listaClanaka = (ListView)findViewById(R.id.mylist); + listaClanaka.setOnItemClickListener(this); + + values = new ArrayList(); + + MySimpleArrayAdapter adapter = new MySimpleArrayAdapter(this, values); + listaClanaka.setAdapter(adapter); + + novostiProgressLayout = (LinearLayout)findViewById(R.id.novostiProgressLayout); + novostiProgressLayout.setVisibility(View.VISIBLE); + + ActionBar ab = getSupportActionBar(); + ab.setSubtitle(R.string.subtitle_activity_lista_novosti); + + } + + @Override + public boolean onCreateOptionsMenu(final Menu menu) { + MenuInflater inflater = getSupportMenuInflater(); + inflater.inflate(R.menu.lista_novosti, menu); + refresh = menu.findItem(R.id.menu_refresh); + + return true; + } + + @Override + public boolean onOptionsItemSelected(final MenuItem item) { + + switch (item.getItemId()) { + + case R.id.menu_refresh: + refresh.setActionView(R.layout.actionbar_indeterminate_progress); + fetchArticles(); + return true; + + case R.id.action_search: + onSearchRequested(); + return true; + + default: + return super.onOptionsItemSelected(item); + } + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + + Log.i("test_tag", "onSaveInstance"); + // spremi listu novosti .... parcelable sve kaj se tam nalazi ! + outState.putParcelableArray(KEY_VALUES_BUNDLE_SESSION, values.toArray(new Post[values.size()])); + + } + + // The system calls onRestoreInstanceState() only if there is a saved state to restore. + @Override + protected void onRestoreInstanceState(Bundle savedInstanceState) { + super.onRestoreInstanceState(savedInstanceState); + + Log.i("test_tag", "onRestoreInstance"); + // restore liste, pa onda provjera dali je lista prazna, ako nije znai nemoj skidati s neta ! + for(Parcelable p: savedInstanceState.getParcelableArray(KEY_VALUES_BUNDLE_SESSION)) + { + Post tempPost = (Post) p; + values.add(tempPost); + } + } + + @Override + protected void onResume() + { + super.onResume(); + + if(values.isEmpty()) fetchArticles(); + else cleanScreen(); + } + private class DownloadRssFeed extends AsyncTask { @Override protected void onPreExecute() { @@ -48,7 +129,9 @@ protected void onPreExecute() { protected LzsRestResponse doInBackground(final String... urls) { LzsRestResponse obj2 = null; LzsRestApi api = null; - try { + + try + { api = new LzsRestApi(); String json = api.getRecentPosts(); @@ -57,11 +140,9 @@ protected LzsRestResponse doInBackground(final String... urls) { obj2 = gson.fromJson(json, LzsRestResponse.class); } catch (IllegalStateException e) { - // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); } @@ -70,137 +151,41 @@ protected LzsRestResponse doInBackground(final String... urls) { @Override protected void onPostExecute(final LzsRestResponse lzs_feed) { - novostiProgressLayout.setVisibility(View.GONE); - refresh.setActionView(null); - MySimpleArrayAdapter adapter = new MySimpleArrayAdapter(ovaAct, lzs_feed.getPosts()); - - listaClanaka.setAdapter(adapter); - - listaClanaka.setOnItemClickListener(new OnItemClickListener() { - - public void onItemClick(final AdapterView parent, final View view, final int position, final long id) { - - Intent i = new Intent(getApplicationContext(), Clanak.class); - - i.putExtra("naslov", values.get(position).getTitle()); - i.putExtra("sadrzaj", values.get(position).getContent()); - i.putExtra("komentari", values.get(position).getUrl()); - i.putExtra("origLink", values.get(position).getUrl()); - startActivity(i); - } - }); + cleanScreen(); + values.clear(); + values.addAll(lzs_feed.getPosts()); } } - static class ViewHolder { - TextView neki_tekst; - TextView datum; - TextView autor; - TextView broj_komentara; - ImageView thumbnail; - boolean isSet = false; - } - - public class MySimpleArrayAdapter extends ArrayAdapter { - private final Context context; - - public MySimpleArrayAdapter(final Context context, final List naslovi) { - super(context, R.layout.novosti_redak, naslovi); - this.context = context; - values = naslovi; - } - - @Override - public View getView(final int position, View convertView, final ViewGroup parent) { - ViewHolder holder; - - if (convertView == null) { - LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - convertView = inflater.inflate(R.layout.novosti_redak, parent, false); - holder = new ViewHolder(); - - holder.neki_tekst = (TextView)convertView.findViewById(R.id.neki_tekst); - holder.datum = (TextView)convertView.findViewById(R.id.datum); - holder.autor = (TextView)convertView.findViewById(R.id.autor); - holder.broj_komentara = (TextView)convertView.findViewById(R.id.broj_komentara); - holder.thumbnail = (ImageView)convertView.findViewById(R.id.thumbnail); - - convertView.setTag(holder); - } - else { - holder = (ViewHolder)convertView.getTag(); - } - holder.neki_tekst.setText(values.get(position).getTitle()); - holder.datum.setText(values.get(position).getDate("dd.MM.yyyy")); - holder.autor.setText(values.get(position).getAuthor().getNickname()); - holder.broj_komentara.setText(Integer.toString(values.get(position).getComment_count())); - - String thumbnailUrl = TimThumb.generateTimThumbUrl(values.get(position).getThumbnail_images().getFull().getUrl(), 256, 256, 1); - UrlImageViewHelper.setUrlDrawable(holder.thumbnail, thumbnailUrl); - - return convertView; + public void fetchArticles() + { + if (ActivityHelper.isOnline(this)) + new DownloadRssFeed().execute(HTTP_FEEDS_FEEDBURNER_COM_LINUXZASVE); + else + { + Toast.makeText(getBaseContext(), R.string.nedostupan_internet, Toast.LENGTH_LONG).show(); + cleanScreen(); } } @Override - public void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.lista_novosti); - - listaClanaka = (ListView)findViewById(R.id.mylist); - novostiProgressLayout = (LinearLayout)findViewById(R.id.novostiProgressLayout); - ovaAct = this; - novostiProgressLayout.setVisibility(View.VISIBLE); - - ActionBar ab = getSupportActionBar(); - ab.setSubtitle("Najnoviji članci"); + public void onItemClick(final AdapterView parent, final View view, final int position, final long id) + { + Intent i = new Intent(getApplicationContext(), Clanak.class); + + // ove key Stringove treba spremiti u neke vrijednosti... + i.putExtra("naslov", values.get(position).getTitle()); + i.putExtra("sadrzaj", values.get(position).getContent()); + i.putExtra("komentari", values.get(position).getUrl()); + i.putExtra("origLink", values.get(position).getUrl()); - fetchArticles(); - + startActivity(i); } - - @Override - public boolean onCreateOptionsMenu(final Menu menu) { - MenuInflater inflater = getSupportMenuInflater(); - inflater.inflate(R.menu.lista_novosti, menu); - refresh = menu.findItem(R.id.menu_refresh); - - return true; - } - - @Override - public boolean onOptionsItemSelected(final MenuItem item) { - - switch (item.getItemId()) { - - case R.id.menu_refresh: - refresh.setActionView(R.layout.actionbar_indeterminate_progress); - fetchArticles(); - return true; - - case R.id.action_search: - onSearchRequested(); - return true; - - default: - return super.onOptionsItemSelected(item); - } - } - - public void fetchArticles() { - if (ActivityHelper.isOnline(this)) { - new DownloadRssFeed().execute("http://feeds.feedburner.com/linuxzasve"); - } - else { - Toast toast = Toast.makeText(getBaseContext(), R.string.nedostupan_internet, Toast.LENGTH_LONG); - toast.show(); - if (novostiProgressLayout != null) { - novostiProgressLayout.setVisibility(View.GONE); - } - - if (refresh != null) { - refresh.setActionView(null); - } - } + + private void cleanScreen() + { + if (novostiProgressLayout != null) novostiProgressLayout.setVisibility(View.GONE); + if (refresh != null) refresh.setActionView(null); } + } diff --git a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/adapters/MySimpleArrayAdapter.java b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/adapters/MySimpleArrayAdapter.java new file mode 100644 index 0000000..ed7e83a --- /dev/null +++ b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/adapters/MySimpleArrayAdapter.java @@ -0,0 +1,69 @@ +package com.linuxzasve.mobile.adapters; + +import java.util.List; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.TextView; + +import com.koushikdutta.urlimageviewhelper.UrlImageViewHelper; +import com.linuxzasve.mobile.R; +import com.linuxzasve.mobile.rest.Post; +import com.linuxzasve.mobile.timthumb.TimThumb; + +public class MySimpleArrayAdapter extends ArrayAdapter { + + private final Context context; + private List naslovi; + + public MySimpleArrayAdapter(final Context context, final List naslovi) { + super(context, R.layout.novosti_redak, naslovi); + this.context = context; + this.naslovi = naslovi; + } + + static class ViewHolder + { + TextView neki_tekst; + TextView datum; + TextView autor; + TextView broj_komentara; + ImageView thumbnail; + boolean isSet = false; + } + + @Override + public View getView(final int position, View convertView, final ViewGroup parent) { + ViewHolder holder; + + if (convertView == null) { + LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + convertView = inflater.inflate(R.layout.novosti_redak, parent, false); + holder = new ViewHolder(); + + holder.neki_tekst = (TextView)convertView.findViewById(R.id.neki_tekst); + holder.datum = (TextView)convertView.findViewById(R.id.datum); + holder.autor = (TextView)convertView.findViewById(R.id.autor); + holder.broj_komentara = (TextView)convertView.findViewById(R.id.broj_komentara); + holder.thumbnail = (ImageView)convertView.findViewById(R.id.thumbnail); + + convertView.setTag(holder); + } + else { + holder = (ViewHolder)convertView.getTag(); + } + holder.neki_tekst.setText(naslovi.get(position).getTitle()); + holder.datum.setText(naslovi.get(position).getDate("dd.MM.yyyy")); + holder.autor.setText(naslovi.get(position).getAuthor().getNickname()); + holder.broj_komentara.setText(Integer.toString(naslovi.get(position).getComment_count())); + + String thumbnailUrl = TimThumb.generateTimThumbUrl(naslovi.get(position).getThumbnail_images().getFull().getUrl(), 256, 256, 1); + UrlImageViewHelper.setUrlDrawable(holder.thumbnail, thumbnailUrl); + + return convertView; + } +} diff --git a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Attachment.java b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Attachment.java index 3ec20ed..136e0e2 100644 --- a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Attachment.java +++ b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Attachment.java @@ -1,6 +1,9 @@ package com.linuxzasve.mobile.rest; -public class Attachment { +import android.os.Parcel; +import android.os.Parcelable; + +public class Attachment implements Parcelable{ private int id; private String url; private String slug; @@ -12,7 +15,6 @@ public class Attachment { private Image images; - public int getId() { return id; } @@ -121,5 +123,49 @@ public void setImages(Image images) { - public Attachment(){}; + public Attachment(){} + + // PARCELABLE + + @Override + public int describeContents() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(id); + dest.writeStringArray(new String[]{ url, slug, title, description, caption }); + dest.writeInt(parent); + dest.writeString(mime_type); + dest.writeParcelable(images, PARCELABLE_WRITE_RETURN_VALUE); + }; + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() + { + @Override + public Attachment createFromParcel(Parcel source) { + return new Attachment(source); + } + + @Override + public Attachment[] newArray(int size) { + return new Attachment[size]; + } + }; + + private Attachment(Parcel in) + { + this.id = in.readInt(); + + String[] s = new String[5]; + in.readStringArray(s); + + this.url = s[0]; + this.slug = s[1]; + this.title = s[2]; + this.description = s[3]; + this.caption = s[4]; + } } diff --git a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Author.java b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Author.java index c08cfb8..129add8 100644 --- a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Author.java +++ b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Author.java @@ -1,6 +1,9 @@ package com.linuxzasve.mobile.rest; -public class Author { +import android.os.Parcel; +import android.os.Parcelable; + +public class Author implements Parcelable{ private int id; private String slug; private String name; @@ -91,5 +94,48 @@ public void setDescription(String description) { } - public Author(){}; + public Author(){} + + + @Override + public int describeContents() { + // TODO Auto-generated method stub + return 0; + } + + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(id); + dest.writeStringArray(new String[] { slug, name, first_name, last_name, nickname, url, description }); + }; + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() + { + @Override + public Author createFromParcel(Parcel source) { + return new Author(source); + } + + @Override + public Author[] newArray(int size) { + return new Author[size]; + } + }; + + private Author(Parcel in) + { + this.id = in.readInt(); + + String[] s = new String[7]; + in.readStringArray(s); + + this.slug = s[0]; + this.name = s[1]; + this.first_name = s[2]; + this.last_name = s[3]; + this.nickname = s[4]; + this.url = s[5]; + this.description= s[6]; + } } diff --git a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Category.java b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Category.java index 888d872..1261af3 100644 --- a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Category.java +++ b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Category.java @@ -1,12 +1,15 @@ package com.linuxzasve.mobile.rest; -public class Category { +import android.os.Parcel; +import android.os.Parcelable; + +public class Category implements Parcelable{ private int id; private String slug; private String title; private String description; private int parent; - private int post_count; + private int Category_count; public int getId() { @@ -59,15 +62,58 @@ public void setParent(int parent) { } - public int getPost_count() { - return post_count; + public int getCategory_count() { + return Category_count; } - public void setPost_count(int post_count) { - this.post_count = post_count; + public void setCategory_count(int Category_count) { + this.Category_count = Category_count; } public Category() {} + + // PARCELABLE + + @Override + public int describeContents() { + // TODO Auto-generated method stub + return 0; + } + + + @Override + public void writeToParcel(Parcel dest, int flags) + { + dest.writeInt(id); + dest.writeString(slug); + dest.writeString(title); + dest.writeString(description); + dest.writeInt(parent); + dest.writeInt(Category_count); + } + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() + { + @Override + public Category createFromParcel(Parcel source) { + return new Category(source); + } + + @Override + public Category[] newArray(int size) { + return new Category[size]; + } + }; + + private Category(Parcel in) + { + this.id = in.readInt(); + this.slug = in.readString(); + this.title = in.readString(); + this.description = in.readString(); + this.parent = in.readInt(); + this.Category_count = in.readInt(); + } } diff --git a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Comment.java b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Comment.java index 06a6639..2975193 100644 --- a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Comment.java +++ b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Comment.java @@ -1,6 +1,9 @@ package com.linuxzasve.mobile.rest; -public class Comment { +import android.os.Parcel; +import android.os.Parcelable; + +public class Comment implements Parcelable{ private int id; private String name; private String url; @@ -69,5 +72,46 @@ public void setParent(String parent) { } - public Comment(){}; + public Comment(){} + + + @Override + public int describeContents() { + // TODO Auto-generated method stub + return 0; + } + + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(id); + dest.writeStringArray(new String[]{ name, url, date, content, parent }); + }; + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() + { + @Override + public Comment createFromParcel(Parcel source) { + return new Comment(source); + } + + @Override + public Comment[] newArray(int size) { + return new Comment[size]; + } + }; + + private Comment(Parcel in) + { + this.id = in.readInt(); + + String[] s = new String[5]; + in.readStringArray(s); + + this.name = s[0]; + this.url = s[1]; + this.date = s[2]; + this.content= s[3]; + this.parent = s[4]; + } } diff --git a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/CustomFiels.java b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/CustomFiels.java index 082a19f..c1b0baa 100644 --- a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/CustomFiels.java +++ b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/CustomFiels.java @@ -2,7 +2,10 @@ import java.util.List; -public class CustomFiels { +import android.os.Parcel; +import android.os.Parcelable; + +public class CustomFiels implements Parcelable{ private List views; @@ -16,5 +19,36 @@ public void setViews(List views) { } - public CustomFiels(){}; + public CustomFiels(){} + + // PARCELABLE + + @Override + public int describeContents() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeStringList(views); + }; + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() + { + @Override + public CustomFiels createFromParcel(Parcel source) { + return new CustomFiels(source); + } + + @Override + public CustomFiels[] newArray(int size) { + return new CustomFiels[size]; + } + }; + + private CustomFiels(Parcel in) + { + in.readStringList(views); + } } diff --git a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/DetailedImage.java b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/DetailedImage.java index 0e25799..520b8ef 100644 --- a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/DetailedImage.java +++ b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/DetailedImage.java @@ -1,6 +1,9 @@ package com.linuxzasve.mobile.rest; -public class DetailedImage { +import android.os.Parcel; +import android.os.Parcelable; + +public class DetailedImage implements Parcelable{ private String url; private int width; private int height; @@ -36,6 +39,43 @@ public void setHeight(int height) { } - public DetailedImage(){}; + public DetailedImage(){} + + + // PARCELABLE + + @Override + public int describeContents() { + // TODO Auto-generated method stub + return 0; + } + + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(url); + dest.writeInt(width); + dest.writeInt(height); + }; + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() + { + @Override + public DetailedImage createFromParcel(Parcel source) { + return new DetailedImage(source); + } + + @Override + public DetailedImage[] newArray(int size) { + return new DetailedImage[size]; + } + }; + + private DetailedImage(Parcel in) + { + this.url = in.readString(); + this.width = in.readInt(); + this.height = in.readInt(); + } } diff --git a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Image.java b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Image.java index ff1961d..4941387 100644 --- a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Image.java +++ b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Image.java @@ -1,6 +1,9 @@ package com.linuxzasve.mobile.rest; -public class Image { +import android.os.Parcel; +import android.os.Parcelable; + +public class Image implements Parcelable{ private DetailedImage full; private DetailedImage thumbnail; private DetailedImage medium; @@ -58,5 +61,45 @@ public void setWptouch_new_thumbnail(DetailedImage wptouch_new_thumbnail) { } - public Image(){}; + public Image(){} + + // PARCELABLE + + @Override + public int describeContents() { + // TODO Auto-generated method stub + return 0; + } + + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeParcelable(full, PARCELABLE_WRITE_RETURN_VALUE); + dest.writeParcelable(thumbnail, PARCELABLE_WRITE_RETURN_VALUE); + dest.writeParcelable(medium, PARCELABLE_WRITE_RETURN_VALUE); + dest.writeParcelable(large, PARCELABLE_WRITE_RETURN_VALUE); + dest.writeParcelable(wptouch_new_thumbnail, PARCELABLE_WRITE_RETURN_VALUE); + }; + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() + { + @Override + public Image createFromParcel(Parcel source) { + return new Image(source); + } + + @Override + public Image[] newArray(int size) { + return new Image[size]; + } + }; + + private Image(Parcel in) + { + this.full = in.readParcelable(null); + this.thumbnail = in.readParcelable(null); + this.medium = in.readParcelable(null); + this.large = in.readParcelable(null); + this.wptouch_new_thumbnail = in.readParcelable(null); + } } diff --git a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/LzsRestApi.java b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/LzsRestApi.java index 92934a7..fd2253a 100644 --- a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/LzsRestApi.java +++ b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/LzsRestApi.java @@ -20,7 +20,7 @@ public class LzsRestApi { - String baseUrl = "http://www.linuxzasve.com/api/"; + private final static String BASE_URL = "http://www.linuxzasve.com/api/"; /* number of posts to fetch */ Integer numberOfPosts = Integer.valueOf(10); @@ -42,7 +42,7 @@ public String getRecentPosts() throws IOException { nameValuePairs.add(new BasicNameValuePair("include", generateInclude(include))); /* generate request url */ - String url = generateRequestString(baseUrl, "get_recent_posts/", nameValuePairs); + String url = generateRequestString(BASE_URL, "get_recent_posts/", nameValuePairs); /* submit query, get json data */ String jsonResult = getContent(url); @@ -63,7 +63,7 @@ public String getSearchResult(final String search) throws IOException { nameValuePairs.add(new BasicNameValuePair("search", search)); /* generate request url */ - String url = generateRequestString(baseUrl, "get_search_results/", nameValuePairs); + String url = generateRequestString(BASE_URL, "get_search_results/", nameValuePairs); /* submit query, get json data */ String jsonResult = getContent(url); @@ -71,10 +71,11 @@ public String getSearchResult(final String search) throws IOException { return jsonResult; } - private String getContent(final String url) throws IOException { - + private String getContent(final String url) throws IOException + { HttpResponse response = null; - try { + try + { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(); request.setURI(new URI(url)); @@ -84,15 +85,13 @@ private String getContent(final String url) throws IOException { e.printStackTrace(); } catch (ClientProtocolException e) { - // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); } + return getStringFromInputStream(response.getEntity().getContent()); - } private static String getStringFromInputStream(final InputStream is) { @@ -134,14 +133,14 @@ private static String getStringFromInputStream(final InputStream is) { * @return */ private String generateInclude(final String includes[]) { - String result = ""; - int i; - for (i = 0; i < (includes.length - 1); i++) { - result += (includes[i] + ","); - } - result += includes[i]; - return result; + StringBuilder sb = new StringBuilder(); + + int i = 0; + for (; i < (includes.length - 1); i++) + sb.append(includes[i] + ","); + sb.append(includes[i]); + return sb.toString(); } /** @@ -154,19 +153,20 @@ private String generateInclude(final String includes[]) { * @param parameters * @return */ - private String generateRequestString(final String baseUrl, final String method, final List parameters) { - String url = ""; - + private String generateRequestString(final String baseUrl, final String method, final List parameters) + { + StringBuilder urlSB = new StringBuilder(); + /* add base url */ - url += baseUrl; - + urlSB.append(baseUrl); + /* add method */ - url += method; + urlSB.append(method); /* generate query string */ String queryString = URLEncodedUtils.format(parameters, "UTF-8"); - url += ("?" + queryString); + urlSB.append("?").append(queryString); - return url; + return urlSB.toString(); } } diff --git a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Post.java b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Post.java index 6f3cd40..f3ea517 100644 --- a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Post.java +++ b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Post.java @@ -1,19 +1,19 @@ package com.linuxzasve.mobile.rest; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Calendar; import java.util.Date; import java.util.Iterator; import java.util.List; -import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.text.ParseException; +import android.os.Parcel; +import android.os.Parcelable; import android.text.Html; -public class Post { +public class Post implements Parcelable{ private int id; private String type; private String slug; @@ -216,7 +216,8 @@ public void setThumbnail_images(final Thumbnail thumbnail_images) { public Post() { } - private String ClanakRemoveHardcodedDim(final String clanak) { + private String ClanakRemoveHardcodedDim(final String clanak) + { String filtriraniClanak = clanak; List uzorciZaIzbaciti = new ArrayList(); @@ -226,11 +227,13 @@ private String ClanakRemoveHardcodedDim(final String clanak) { uzorciZaIzbaciti.add(Pattern.compile("\"width: \\d+px\"")); Iterator it = uzorciZaIzbaciti.iterator(); - while (it.hasNext()) { + while (it.hasNext()) + { Pattern uzorak = it.next(); Matcher htmlClanka = uzorak.matcher(filtriraniClanak); - while (htmlClanka.find()) { + while (htmlClanka.find()) + { int poc = htmlClanka.start(); int kraj = htmlClanka.end(); @@ -242,7 +245,8 @@ private String ClanakRemoveHardcodedDim(final String clanak) { return filtriraniClanak; } - public String getDate(String format) { + public String getDate(String format) + { Date date; String result = ""; try { @@ -258,4 +262,89 @@ public String getDate(String format) { } return result; } + + // PARCELABLE STUFF + + @Override + public int describeContents() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(id); + dest.writeStringArray(new String[]{ type, slug, url, status, title, title_plain, content, excerpt, date, modified }); + dest.writeTypedList(categories); + dest.writeTypedList(tags); + dest.writeParcelable(author, PARCELABLE_WRITE_RETURN_VALUE); // dali ide ta maska il ne ... ? + dest.writeTypedList(comments); + dest.writeTypedList(attachments); + dest.writeInt(comment_count); + dest.writeString(comment_status); + dest.writeString(thumbnail); + dest.writeParcelable(custom_fields, PARCELABLE_WRITE_RETURN_VALUE); + dest.writeString(thumbnail_size); + dest.writeParcelable(thumbnail_images, PARCELABLE_WRITE_RETURN_VALUE); + } + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() + { + @Override + public Post createFromParcel(Parcel source) { + return new Post(source); + } + + @Override + public Post[] newArray(int size) { + return new Post[size]; + } + }; + + private Post(Parcel in) + { + initialize(); + + this.id = in.readInt(); + + String[] s = new String[10]; + in.readStringArray(s); + + this.type = s[0]; + this.slug = s[1]; + this.url = s[2]; + this.status = s[3]; + this.title = s[4]; + this.title_plain= s[5]; + this.content = s[6]; + this.excerpt = s[7]; + this.date = s[8]; + this.modified = s[9]; + + in.readTypedList(this.categories, null); // NULL POINTER EXCEPTION + in.readTypedList(this.tags, null); + + this.author = in.readParcelable(null); + + in.readTypedList(this.comments, null); + in.readTypedList(this.attachments, null); + + this.comment_count = in.readInt(); + this.comment_status = in.readString(); + this.thumbnail = in.readString(); + + this.custom_fields = in.readParcelable(null); + + this.thumbnail_size = in.readString(); + + this.thumbnail_images = in.readParcelable(null); + } + + private void initialize() + { + categories = new ArrayList(); + tags = new ArrayList(); + comments = new ArrayList(); + attachments = new ArrayList(); + } } diff --git a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Tag.java b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Tag.java index fd1d22a..f9fba26 100644 --- a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Tag.java +++ b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Tag.java @@ -1,11 +1,14 @@ package com.linuxzasve.mobile.rest; -public class Tag { +import android.os.Parcel; +import android.os.Parcelable; + +public class Tag implements Parcelable{ private int id; private String slug; private String title; private String description; - private String post_count; + private String Tag_count; public int getId() { return id; @@ -39,13 +42,54 @@ public void setDescription(String description) { this.description = description; } - public String getPost_count() { - return post_count; + public String getTag_count() { + return Tag_count; } - public void setPost_count(String post_count) { - this.post_count = post_count; + public void setTag_count(String Tag_count) { + this.Tag_count = Tag_count; } public Tag() {} + + // PARCELABLE + + @Override + public int describeContents() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(id); + dest.writeStringArray(new String[]{ slug, title, description, Tag_count }); + } + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() + { + @Override + public Tag createFromParcel(Parcel source) { + return new Tag(source); + } + + @Override + public Tag[] newArray(int size) { + return new Tag[size]; + } + }; + + private Tag(Parcel in) + { + this.id = in.readInt(); + + String[] s = new String[4]; + in.readStringArray(s); + + this.slug = s[0]; + this.title = s[1]; + this.description = s[2]; + this.Tag_count = s[3]; + } } + diff --git a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Thumbnail.java b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Thumbnail.java index 2cba8bf..99368be 100644 --- a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Thumbnail.java +++ b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/rest/Thumbnail.java @@ -1,6 +1,9 @@ package com.linuxzasve.mobile.rest; -public class Thumbnail { +import android.os.Parcel; +import android.os.Parcelable; + +public class Thumbnail implements Parcelable{ private DetailedImage full; private DetailedImage thumbnail; private DetailedImage medium; @@ -58,5 +61,45 @@ public void setWptouch_new_thumbnail(DetailedImage wptouch_new_thumbnail) { } - public Thumbnail(){}; + public Thumbnail(){} + + // PARCELABLE + + @Override + public int describeContents() { + // TODO Auto-generated method stub + return 0; + } + + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeParcelable(full, PARCELABLE_WRITE_RETURN_VALUE); + dest.writeParcelable(thumbnail, PARCELABLE_WRITE_RETURN_VALUE); + dest.writeParcelable(medium, PARCELABLE_WRITE_RETURN_VALUE); + dest.writeParcelable(large, PARCELABLE_WRITE_RETURN_VALUE); + dest.writeParcelable(wptouch_new_thumbnail, PARCELABLE_WRITE_RETURN_VALUE); + }; + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() + { + @Override + public Thumbnail createFromParcel(Parcel source) { + return new Thumbnail(source); + } + + @Override + public Thumbnail[] newArray(int size) { + return new Thumbnail[size]; + } + }; + + private Thumbnail(Parcel in) + { + this.full = in.readParcelable(null); + this.thumbnail = in.readParcelable(null); + this.medium = in.readParcelable(null); + this.large = in.readParcelable(null); + this.wptouch_new_thumbnail = in.readParcelable(null); + } } diff --git a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/timthumb/TimThumb.java b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/timthumb/TimThumb.java index 6d56bea..b68c152 100644 --- a/LinuxZaSve_mobile/src/com/linuxzasve/mobile/timthumb/TimThumb.java +++ b/LinuxZaSve_mobile/src/com/linuxzasve/mobile/timthumb/TimThumb.java @@ -9,10 +9,11 @@ public class TimThumb { - static String baseUrl = "http://www.linuxzasve.com/wp-content/themes/bigfoot/includes/timthumb.php"; + private static final String BASE_URL = "http://www.linuxzasve.com/wp-content/themes/bigfoot/includes/timthumb.php"; - public static String generateTimThumbUrl(final String imageUrl, final int height, final int width, final int mode) { - String url = baseUrl; + public static String generateTimThumbUrl(final String imageUrl, final int height, final int width, final int mode) + { + String url = BASE_URL; List nameValuePairs = new ArrayList(4); nameValuePairs.add(new BasicNameValuePair("src", imageUrl));