From be84e7092d10127978957f2d6911f50ea68a773c Mon Sep 17 00:00:00 2001 From: write_only_memory Date: Sun, 25 Jan 2015 12:35:35 -0700 Subject: [PATCH 1/3] Very basic working custom naming. --- app/src/main/java/ca/currybox/yaya/Anime.java | 19 +++++- .../ca/currybox/yaya/ListViewAdapter.java | 2 + .../java/ca/currybox/yaya/SingleItemView.java | 67 ++++++------------- .../java/ca/currybox/yaya/customNames.java | 51 ++++++++++++++ .../main/java/ca/currybox/yaya/playMatch.java | 35 ++++++++++ 5 files changed, 125 insertions(+), 49 deletions(-) create mode 100644 app/src/main/java/ca/currybox/yaya/customNames.java diff --git a/app/src/main/java/ca/currybox/yaya/Anime.java b/app/src/main/java/ca/currybox/yaya/Anime.java index 3783b50..24f67b5 100644 --- a/app/src/main/java/ca/currybox/yaya/Anime.java +++ b/app/src/main/java/ca/currybox/yaya/Anime.java @@ -3,7 +3,7 @@ import java.io.Serializable; /** - * Created by write_only_memory on 10/3/2014. + * Created by write-only-memory on 10/3/2014. */ public class Anime implements Serializable{ @@ -17,6 +17,8 @@ public class Anime implements Serializable{ private String dateFinished; private String dateStarted; + private static final long serialVersionUID = 1L; + public String getTitle() { return title; } @@ -30,7 +32,7 @@ public String getSynonyms() { } public void setSynonyms(String synonyms) { - this.synonyms = synonyms; + this.synonyms = this.synonyms + ";" + synonyms; } public int getEpisodes() { @@ -92,4 +94,17 @@ public void setDateStarted(String date) { dateStarted = date; } + + public void copy(Anime show) + { + this.title = show.title; + this.synonyms = show.synonyms; + this.episodes = show.episodes; + this.watched = show.watched; + this.status = show.status; + this.updated = show.updated; + this.id = show.id; + this.dateStarted = show.dateStarted; + this.dateFinished = show.dateFinished; + } } diff --git a/app/src/main/java/ca/currybox/yaya/ListViewAdapter.java b/app/src/main/java/ca/currybox/yaya/ListViewAdapter.java index e14a972..8b7793b 100644 --- a/app/src/main/java/ca/currybox/yaya/ListViewAdapter.java +++ b/app/src/main/java/ca/currybox/yaya/ListViewAdapter.java @@ -101,6 +101,8 @@ public void onClick(View arg0) { //Pass all data updated intent.putExtra("updated", (animeList.get(position).getUpdated())); + intent.putExtra("show", animeList.get(position)); + //Start activity context.startActivity(intent); diff --git a/app/src/main/java/ca/currybox/yaya/SingleItemView.java b/app/src/main/java/ca/currybox/yaya/SingleItemView.java index 1b1c15a..8d254e1 100644 --- a/app/src/main/java/ca/currybox/yaya/SingleItemView.java +++ b/app/src/main/java/ca/currybox/yaya/SingleItemView.java @@ -35,6 +35,7 @@ public class SingleItemView extends ActionBarActivity implements View.OnClickLis private int watched; private int status_id; private int updated; + private Anime intentShow; @Override public void onCreate(Bundle savedInstanceState) { @@ -43,7 +44,10 @@ public void onCreate(Bundle savedInstanceState) { Intent i = getIntent(); - title = i.getStringExtra("title"); + + intentShow = (Anime) i.getSerializableExtra("show"); + + title = intentShow.getTitle(); //Get the view from singleitemview.xml setContentView(R.layout.singleitemview); @@ -58,16 +62,16 @@ public void onCreate(Bundle savedInstanceState) { write.setOnClickListener(this); Log.i("INFO", title); - synonyms = i.getStringExtra("synonyms"); -// Log.i("INFO",synonyms); - episodes = i.getIntExtra("episodes", 0); + synonyms = intentShow.getSynonyms(); - watched = i.getIntExtra("watched", 0); - status_id = i.getIntExtra("status", 0); - updated = i.getIntExtra("updated", 0); + episodes = intentShow.getEpisodes(); + watched = intentShow.getWatched(); + + status_id = intentShow.getStatus(); + updated = intentShow.getUpdated(); String date = new SimpleDateFormat("MMM dd yyyy 'at' KK:mm:ss a").format(new Date(updated * 1000L)); - String status; + String status = String.valueOf(status_id); switch (status_id) { case 1: @@ -86,6 +90,7 @@ public void onCreate(Bundle savedInstanceState) { status = "Plan to watch"; break; default: + Log.e("status unknown", status); status = "Unknown... wot"; break; } @@ -109,12 +114,13 @@ public void onCreate(Bundle savedInstanceState) { @Override public void onClick(View v) { - List shows = new ArrayList(); + List shows; + customNames customList = new customNames(); switch (v.getId()) { case R.id.read: TextView test = (TextView) findViewById(R.id.test_field); - shows = getCustomList(); + shows = customList.getCustomList(getApplicationContext()); String out = ""; Log.i("list size", "lel"); for (int i = 0; i < shows.size(); i++) @@ -124,18 +130,18 @@ public void onClick(View v) test.setText(out); break; case R.id.write: - shows = getCustomList(); + shows = customList.getCustomList(getApplicationContext()); if (shows == null) { Log.i("shows","is null"); - shows = new ArrayList(); + shows = new ArrayList<>(); } Anime show = new Anime(); - show.setTitle(title); + show.copy(intentShow); EditText syn = (EditText) findViewById(R.id.synonyms); show.setSynonyms(String.valueOf(syn.getText())); shows.add(show); - write(shows); + customList.write(shows, getApplicationContext()); break; } } @@ -154,39 +160,6 @@ public boolean onOptionsItemSelected(MenuItem item) { } - public void write (List shows) - { - try - { - FileOutputStream fos = getApplicationContext().openFileOutput("custom-names.dat", Context.MODE_PRIVATE); - ObjectOutputStream oos = new ObjectOutputStream(fos); - oos.writeObject(shows); - oos.close(); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - public List getCustomList () - { - List customList; - try - { - FileInputStream fis = openFileInput("custom-names.dat"); - ObjectInputStream ois = new ObjectInputStream(fis); - customList = (List) ois.readObject(); - ois.close(); - } - catch (Exception e) - { - customList = null; - e.printStackTrace(); - } - Log.i("reader", "done"); - return customList; - } } diff --git a/app/src/main/java/ca/currybox/yaya/customNames.java b/app/src/main/java/ca/currybox/yaya/customNames.java new file mode 100644 index 0000000..fdfd42d --- /dev/null +++ b/app/src/main/java/ca/currybox/yaya/customNames.java @@ -0,0 +1,51 @@ +package ca.currybox.yaya; + +import android.content.Context; +import android.util.Log; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.List; + +/** + * Created by Kanchana on 1/25/2015. + */ +public class customNames { + + public void write (List shows, Context ctx) + { + try + { + FileOutputStream fos = ctx.openFileOutput("custom-names.dat", Context.MODE_PRIVATE); + ObjectOutputStream oos = new ObjectOutputStream(fos); + oos.writeObject(shows); + oos.close(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public List getCustomList (Context ctx) + { + List customList; + try + { + FileInputStream fis = ctx.openFileInput("custom-names.dat"); + ObjectInputStream ois = new ObjectInputStream(fis); + customList = (List) ois.readObject(); + ois.close(); + } + catch (Exception e) + { + customList = null; + e.printStackTrace(); + } + Log.i("reader", "done"); + return customList; + + } +} diff --git a/app/src/main/java/ca/currybox/yaya/playMatch.java b/app/src/main/java/ca/currybox/yaya/playMatch.java index 06a0c08..7ec32f7 100644 --- a/app/src/main/java/ca/currybox/yaya/playMatch.java +++ b/app/src/main/java/ca/currybox/yaya/playMatch.java @@ -166,6 +166,41 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa } + if (!found) + { + customNames customList = new customNames(); + List customTitles = customList.getCustomList(view.getContext()); + + for (int i = 0; i < customTitles.size(); i++) + { + String[] synonyms = customTitles.get(i).getSynonyms().split(";"); + for (String synonym : synonyms) + { + if (title.equalsIgnoreCase(synonym)) + { + show = customTitles.get(i); + + TextView match = (TextView) view.findViewById(R.id.match_title); + match.setText("Match found: " + show.getTitle()); + updateButton.setEnabled(true); + + ((ActionBarActivity) getActivity()).getSupportActionBar().setTitle(show.getTitle()); + + TextView mal_ep = (TextView) view.findViewById(R.id.mal_last_ep); + mal_ep.setText(String.valueOf(show.getWatched())); + + TextView mal_updated = (TextView) view.findViewById(R.id.mal_last_update); + String date = new SimpleDateFormat("MMM dd yyyy 'at' KK:mm:ss a").format(new Date(show.getUpdated() * 1000L)); + mal_updated.setText(date); + + found = true; + } + } + } + + + } + if (!found) { RelativeLayout custom_name_layout = (RelativeLayout) view.findViewById(R.id.custom_naming_container); //custom_name_layout.setVisibility(View.VISIBLE); From 330c9a6ece97a4385a94cfc77da1d29affb16c36 Mon Sep 17 00:00:00 2001 From: write_only_memory Date: Sun, 25 Jan 2015 19:26:39 -0700 Subject: [PATCH 2/3] Fully working custom file naming. Lots of minor fixes, imports cleaned. --- app/src/main/java/ca/currybox/yaya/Anime.java | 39 ++++---- .../ca/currybox/yaya/ListViewAdapter.java | 21 ++-- .../yaya/NavigationDrawerFragment.java | 14 +-- .../java/ca/currybox/yaya/SingleItemView.java | 98 +++++++++++-------- .../main/java/ca/currybox/yaya/XMLParser.java | 25 +++-- .../java/ca/currybox/yaya/animeListView.java | 26 ++--- .../java/ca/currybox/yaya/customNames.java | 23 ++--- app/src/main/java/ca/currybox/yaya/main.java | 22 +---- .../java/ca/currybox/yaya/mainFragment.java | 23 +---- .../main/java/ca/currybox/yaya/playMatch.java | 82 +++++++++------- app/src/main/res/layout/singleitemview.xml | 28 ++++-- 11 files changed, 195 insertions(+), 206 deletions(-) diff --git a/app/src/main/java/ca/currybox/yaya/Anime.java b/app/src/main/java/ca/currybox/yaya/Anime.java index 24f67b5..d826409 100644 --- a/app/src/main/java/ca/currybox/yaya/Anime.java +++ b/app/src/main/java/ca/currybox/yaya/Anime.java @@ -5,10 +5,12 @@ /** * Created by write-only-memory on 10/3/2014. */ -public class Anime implements Serializable{ +public class Anime implements Serializable { + private static final long serialVersionUID = 1L; private String title; private String synonyms; + private String custom_synonyms; private int episodes; private int watched; private int status; @@ -17,8 +19,6 @@ public class Anime implements Serializable{ private String dateFinished; private String dateStarted; - private static final long serialVersionUID = 1L; - public String getTitle() { return title; } @@ -32,7 +32,15 @@ public String getSynonyms() { } public void setSynonyms(String synonyms) { - this.synonyms = this.synonyms + ";" + synonyms; + this.synonyms = synonyms; + } + + public String getCustom_synonyms() { + return custom_synonyms; + } + + public void setCustom_synonyms(String synonyms) { + this.custom_synonyms = synonyms; } public int getEpisodes() { @@ -67,36 +75,31 @@ public void setUpdated(int updated) { this.updated = updated; } - public void setId(int id) { - this.id = id; - } - public int getId() { return id; } - public String getDateFinished() - { + public void setId(int id) { + this.id = id; + } + + public String getDateFinished() { return dateFinished; } - public void setDateFinished(String date) - { + public void setDateFinished(String date) { dateFinished = date; } - public String getDateStarted() - { + public String getDateStarted() { return dateStarted; } - public void setDateStarted(String date) - { + public void setDateStarted(String date) { dateStarted = date; } - public void copy(Anime show) - { + public void copy(Anime show) { this.title = show.title; this.synonyms = show.synonyms; this.episodes = show.episodes; diff --git a/app/src/main/java/ca/currybox/yaya/ListViewAdapter.java b/app/src/main/java/ca/currybox/yaya/ListViewAdapter.java index 8b7793b..ddf44cf 100644 --- a/app/src/main/java/ca/currybox/yaya/ListViewAdapter.java +++ b/app/src/main/java/ca/currybox/yaya/ListViewAdapter.java @@ -1,14 +1,11 @@ package ca.currybox.yaya; -import android.app.PendingIntent; -import android.app.TaskStackBuilder; import android.content.Context; import android.content.Intent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; -import android.widget.ListView; import android.widget.TextView; import java.text.SimpleDateFormat; @@ -16,7 +13,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.Date; -import java.util.HashMap; import java.util.List; /** @@ -39,14 +35,6 @@ public ListViewAdapter(Context context, List animeList) { this.arraylist.addAll(animeList); } - public class ViewHolder { - TextView title; - TextView episodes; - TextView watched; - TextView updated; - TextView status; - } - @Override public int getCount() { return animeList.size(); @@ -89,7 +77,6 @@ public void onClick(View arg0) { Intent intent = new Intent(context, SingleItemView.class); - //Pass all data title intent.putExtra("title", (animeList.get(position).getTitle())); //Pass all data episodes @@ -136,5 +123,13 @@ public int compare(Anime anime, Anime anime2) { notifyDataSetChanged(); } + public class ViewHolder { + TextView title; + TextView episodes; + TextView watched; + TextView updated; + TextView status; + } + } diff --git a/app/src/main/java/ca/currybox/yaya/NavigationDrawerFragment.java b/app/src/main/java/ca/currybox/yaya/NavigationDrawerFragment.java index fd7765c..5c9221c 100644 --- a/app/src/main/java/ca/currybox/yaya/NavigationDrawerFragment.java +++ b/app/src/main/java/ca/currybox/yaya/NavigationDrawerFragment.java @@ -1,14 +1,11 @@ package ca.currybox.yaya; -import android.content.Context; -import android.content.SharedPreferences; -import android.os.Bundle; import android.app.Fragment; +import android.os.Bundle; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.widget.Toolbar; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -20,7 +17,6 @@ public class NavigationDrawerFragment extends android.support.v4.app.Fragment { - private ActionBarDrawerToggle mDrawerToggle; private DrawerLayout mDrawerLayout; @@ -47,21 +43,19 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, public void setUp(int fragmentId, DrawerLayout drawerLayout, final Toolbar toolbar, boolean firstLaunch) { containerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; - mDrawerToggle = new ActionBarDrawerToggle(getActivity(), drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) - { + mDrawerToggle = new ActionBarDrawerToggle(getActivity(), drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, slideOffset); - if (slideOffset<0.6) { + if (slideOffset < 0.6) { toolbar.setAlpha(1 - slideOffset); } } }; - if (!firstLaunch) - { + if (!firstLaunch) { mDrawerLayout.openDrawer(containerView); } diff --git a/app/src/main/java/ca/currybox/yaya/SingleItemView.java b/app/src/main/java/ca/currybox/yaya/SingleItemView.java index 8d254e1..e522073 100644 --- a/app/src/main/java/ca/currybox/yaya/SingleItemView.java +++ b/app/src/main/java/ca/currybox/yaya/SingleItemView.java @@ -1,6 +1,5 @@ package ca.currybox.yaya; -import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; @@ -13,11 +12,6 @@ import android.widget.RelativeLayout; import android.widget.TextView; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutput; -import java.io.ObjectOutputStream; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -42,7 +36,6 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Intent i = getIntent(); intentShow = (Anime) i.getSerializableExtra("show"); @@ -61,6 +54,8 @@ public void onCreate(Bundle savedInstanceState) { read.setOnClickListener(this); write.setOnClickListener(this); + read(); + Log.i("INFO", title); synonyms = intentShow.getSynonyms(); @@ -72,8 +67,7 @@ public void onCreate(Bundle savedInstanceState) { String date = new SimpleDateFormat("MMM dd yyyy 'at' KK:mm:ss a").format(new Date(updated * 1000L)); String status = String.valueOf(status_id); - switch (status_id) - { + switch (status_id) { case 1: status = "Currently watching"; break; @@ -112,44 +106,71 @@ public void onCreate(Bundle savedInstanceState) { } @Override - public void onClick(View v) - { - List shows; - customNames customList = new customNames(); - switch (v.getId()) - { + public void onClick(View v) { + + switch (v.getId()) { case R.id.read: - TextView test = (TextView) findViewById(R.id.test_field); - shows = customList.getCustomList(getApplicationContext()); - String out = ""; - Log.i("list size", "lel"); - for (int i = 0; i < shows.size(); i++) - { - out = out + shows.get(i).getTitle() + ":" + shows.get(i).getSynonyms(); - } - test.setText(out); + read(); break; case R.id.write: - shows = customList.getCustomList(getApplicationContext()); - if (shows == null) - { - Log.i("shows","is null"); - shows = new ArrayList<>(); - } - Anime show = new Anime(); - show.copy(intentShow); - EditText syn = (EditText) findViewById(R.id.synonyms); - show.setSynonyms(String.valueOf(syn.getText())); - shows.add(show); - customList.write(shows, getApplicationContext()); + write(); break; } } + public void read() { + List shows; + customNames customList = new customNames(); + + TextView customNamesList = (TextView) findViewById(R.id.list_custom_names); + customNamesList.setText("No custom titles set"); + + shows = customList.getCustomList(getApplicationContext()); + String out; + Log.i("list size", "lel"); + boolean found = false; + if (shows != null) { + for (int i = 0; i < shows.size() && found != true; i++) { + if (intentShow.getTitle().equalsIgnoreCase(shows.get(i).getTitle())) { + out = shows.get(i).getCustom_synonyms(); + found = true; + customNamesList.setText(out); + EditText editor = (EditText) findViewById(R.id.synonyms); + editor.setText(out); + } + } + } + + } + + public void write() { + List shows; + customNames customList = new customNames(); + + shows = customList.getCustomList(getApplicationContext()); + if (shows == null) { + Log.i("shows", "is null"); + shows = new ArrayList<>(); + } + Anime show = new Anime(); + show.copy(intentShow); + EditText syn = (EditText) findViewById(R.id.synonyms); + + for (int i = 0; i < shows.size(); i++) { + if (intentShow.getTitle().equalsIgnoreCase(shows.get(i).getTitle())) { + shows.remove(i); + } + } + + show.setCustom_synonyms(String.valueOf(syn.getText())); + shows.add(show); + customList.write(shows, getApplicationContext()); + read(); + } + @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) - { + switch (item.getItemId()) { case android.R.id.home: onBackPressed(); return true; @@ -161,5 +182,4 @@ public boolean onOptionsItemSelected(MenuItem item) { } - } diff --git a/app/src/main/java/ca/currybox/yaya/XMLParser.java b/app/src/main/java/ca/currybox/yaya/XMLParser.java index 1a10b97..8d54b64 100644 --- a/app/src/main/java/ca/currybox/yaya/XMLParser.java +++ b/app/src/main/java/ca/currybox/yaya/XMLParser.java @@ -3,7 +3,6 @@ import android.content.Context; import android.util.Log; -import android.widget.Toast; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -34,6 +33,17 @@ public class XMLParser { String xml = null; + private static void save(String filename, String data, Context ctx) { + FileOutputStream outputStream; + try { + outputStream = ctx.openFileOutput(filename, Context.MODE_PRIVATE); + outputStream.write(data.getBytes()); + outputStream.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + public void getXmlFromUrl(String url) { @@ -64,7 +74,7 @@ public void write(String filename, Context ctx) { } public String read(String filename, Context ctx) { - return readfile(filename, ctx); + return readfile(filename, ctx); } public Document getDomElement(String xml) { @@ -111,17 +121,6 @@ public final String getElementValue(Node elem) { return ""; } - private static void save(String filename, String data, Context ctx) { - FileOutputStream outputStream; - try { - outputStream = ctx.openFileOutput(filename, Context.MODE_PRIVATE); - outputStream.write(data.getBytes()); - outputStream.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - private String readfile(String filename, Context ctx) { StringBuffer datax = new StringBuffer(""); try { diff --git a/app/src/main/java/ca/currybox/yaya/animeListView.java b/app/src/main/java/ca/currybox/yaya/animeListView.java index 52bacda..5951a26 100644 --- a/app/src/main/java/ca/currybox/yaya/animeListView.java +++ b/app/src/main/java/ca/currybox/yaya/animeListView.java @@ -11,7 +11,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ListView; -import android.widget.TextView; import org.w3c.dom.Document; @@ -24,10 +23,10 @@ public class animeListView extends Fragment { - private List animeList = null; ListView listview; ListViewAdapter adapter; SwipeRefreshLayout swipeRefreshLayout; + private List animeList = null; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.anime_list, container, false); @@ -64,6 +63,18 @@ public void onRefresh() { return view; } + public void updateListView() { + listview = (ListView) getActivity().findViewById(R.id.shows); + + + adapter = new ListViewAdapter(getActivity(), animeList); + + listview.setAdapter(adapter); + + adapter.filter(1); //type 1 is currently watching + adapter.sortByUpdated(); //sorts the list by last updated + } + private class PopulateList extends AsyncTask { protected Void doInBackground(Void... params) { @@ -78,16 +89,8 @@ protected Void doInBackground(Void... params) { @Override protected void onPostExecute(Void result) { - listview = (ListView) getActivity().findViewById(R.id.shows); - - - adapter = new ListViewAdapter(getActivity(), animeList); - - listview.setAdapter(adapter); - - adapter.filter(1); //type 1 is currently watching - adapter.sortByUpdated(); //sorts the list by last updated + updateListView(); swipeRefreshLayout.setRefreshing(false); @@ -96,7 +99,6 @@ protected void onPostExecute(Void result) { } - private class DownloadUser extends AsyncTask { protected Void doInBackground(String... urls) { diff --git a/app/src/main/java/ca/currybox/yaya/customNames.java b/app/src/main/java/ca/currybox/yaya/customNames.java index fdfd42d..583b116 100644 --- a/app/src/main/java/ca/currybox/yaya/customNames.java +++ b/app/src/main/java/ca/currybox/yaya/customNames.java @@ -14,37 +14,32 @@ */ public class customNames { - public void write (List shows, Context ctx) - { - try - { + public void write(List shows, Context ctx) { + try { FileOutputStream fos = ctx.openFileOutput("custom-names.dat", Context.MODE_PRIVATE); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(shows); oos.close(); - } - catch (Exception e) - { + } catch (Exception e) { e.printStackTrace(); } } - public List getCustomList (Context ctx) - { + public List getCustomList(Context ctx) { List customList; - try - { + try { FileInputStream fis = ctx.openFileInput("custom-names.dat"); ObjectInputStream ois = new ObjectInputStream(fis); customList = (List) ois.readObject(); ois.close(); - } - catch (Exception e) - { + } catch (Exception e) { customList = null; e.printStackTrace(); } Log.i("reader", "done"); + if (customList == null) { + //customList = + } return customList; } diff --git a/app/src/main/java/ca/currybox/yaya/main.java b/app/src/main/java/ca/currybox/yaya/main.java index c1bb399..3e85154 100644 --- a/app/src/main/java/ca/currybox/yaya/main.java +++ b/app/src/main/java/ca/currybox/yaya/main.java @@ -3,30 +3,17 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.os.AsyncTask; import android.os.Bundle; -import android.preference.PreferenceManager; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.Toolbar; -import android.util.Log; import android.view.Menu; import android.view.MenuItem; -import android.view.View; -import android.widget.ListView; -import android.widget.TextView; -import android.widget.Toast; - -import org.w3c.dom.Document; - -import java.io.File; -import java.util.List; public class main extends ActionBarActivity { - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -54,17 +41,14 @@ protected void onCreate(Bundle savedInstanceState) { * otherwise launch the main app view */ - if (i.getAction() == "android.intent.action.VIEW") - { + if (i.getAction() == "android.intent.action.VIEW") { Bundle bundle = new Bundle(); bundle.putString("uri", i.getDataString()); playMatch play = new playMatch(); play.setArguments(bundle); getSupportFragmentManager().beginTransaction().replace(R.id.body, play).commit(); - } - else - { + } else { getSupportFragmentManager().beginTransaction().replace(R.id.body, new mainFragment()).commit(); } @@ -95,6 +79,4 @@ public boolean onOptionsItemSelected(MenuItem item) { } - - } diff --git a/app/src/main/java/ca/currybox/yaya/mainFragment.java b/app/src/main/java/ca/currybox/yaya/mainFragment.java index 621dc67..b24bcdc 100644 --- a/app/src/main/java/ca/currybox/yaya/mainFragment.java +++ b/app/src/main/java/ca/currybox/yaya/mainFragment.java @@ -1,39 +1,24 @@ package ca.currybox.yaya; -import android.app.FragmentManager; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.os.AsyncTask; import android.os.Bundle; -import android.preference.PreferenceManager; import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; -import android.widget.ListView; -import android.widget.TextView; -import android.widget.Toast; - -import org.w3c.dom.Document; import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStreamWriter; -import java.util.List; /** * Created by Kanchana on 12/19/2014. */ -public class mainFragment extends Fragment{ - +public class mainFragment extends Fragment { - - public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) - { + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.main_layout, container, false); super.getFragmentManager().beginTransaction().replace(R.id.main_list, new animeListView()).commit(); @@ -45,9 +30,7 @@ public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle s File file = new File(getActivity().getApplicationContext().getFilesDir(), "custom-names.dat"); try { file.createNewFile(); - } - catch (Exception e) - { + } catch (Exception e) { e.printStackTrace(); } Intent intent = new Intent(super.getActivity(), SettingsActivity.class); //intent for the default drop-down menu Settings button diff --git a/app/src/main/java/ca/currybox/yaya/playMatch.java b/app/src/main/java/ca/currybox/yaya/playMatch.java index 7ec32f7..e3e2aba 100644 --- a/app/src/main/java/ca/currybox/yaya/playMatch.java +++ b/app/src/main/java/ca/currybox/yaya/playMatch.java @@ -20,9 +20,7 @@ import android.view.ViewGroup; import android.view.animation.AnimationUtils; import android.widget.Button; -import android.widget.RelativeLayout; import android.widget.TextView; -import android.widget.Toast; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; @@ -46,6 +44,7 @@ public class playMatch extends Fragment implements View.OnClickListener { private Anime show; private String uri; + private View view; public playMatch() { @@ -53,7 +52,7 @@ public playMatch() { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.play_match, container, false); + view = inflater.inflate(R.layout.play_match, container, false); /** * Following block is required for onclick handlers for buttons and such @@ -75,6 +74,16 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa } + return view; + } + + @Override + public void onResume() { + super.onResume(); + parseInfo(); + } + + public void parseInfo() { uri = getArguments().getString("uri"); TextView filename = (TextView) view.findViewById(R.id.filename); //id of the textview used to show the cleaned up filename @@ -166,34 +175,39 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa } - if (!found) - { + if (!found) { customNames customList = new customNames(); List customTitles = customList.getCustomList(view.getContext()); - - for (int i = 0; i < customTitles.size(); i++) - { - String[] synonyms = customTitles.get(i).getSynonyms().split(";"); - for (String synonym : synonyms) - { - if (title.equalsIgnoreCase(synonym)) - { - show = customTitles.get(i); - - TextView match = (TextView) view.findViewById(R.id.match_title); - match.setText("Match found: " + show.getTitle()); - updateButton.setEnabled(true); - - ((ActionBarActivity) getActivity()).getSupportActionBar().setTitle(show.getTitle()); - - TextView mal_ep = (TextView) view.findViewById(R.id.mal_last_ep); - mal_ep.setText(String.valueOf(show.getWatched())); - - TextView mal_updated = (TextView) view.findViewById(R.id.mal_last_update); - String date = new SimpleDateFormat("MMM dd yyyy 'at' KK:mm:ss a").format(new Date(show.getUpdated() * 1000L)); - mal_updated.setText(date); - - found = true; + if (customTitles != null) { + for (int i = 0; i < customTitles.size(); i++) { + String[] synonyms = customTitles.get(i).getCustom_synonyms().split(";"); + for (String synonym : synonyms) { + if (title.equalsIgnoreCase(synonym)) { + String tempTitle = customTitles.get(i).getTitle(); + boolean found1 = false; + for (int j = 0; j < animeList.size() && found1 != true; j++) { + if (tempTitle.equalsIgnoreCase(animeList.get(j).getTitle())) { + show = animeList.get(j); + found1 = true; + } + } + + + TextView match = (TextView) view.findViewById(R.id.match_title); + match.setText("Match found: " + show.getTitle()); + updateButton.setEnabled(true); + + ((ActionBarActivity) getActivity()).getSupportActionBar().setTitle(show.getTitle()); + + TextView mal_ep = (TextView) view.findViewById(R.id.mal_last_ep); + mal_ep.setText(String.valueOf(show.getWatched())); + + TextView mal_updated = (TextView) view.findViewById(R.id.mal_last_update); + String date = new SimpleDateFormat("MMM dd yyyy 'at' KK:mm:ss a").format(new Date(show.getUpdated() * 1000L)); + mal_updated.setText(date); + + found = true; + } } } } @@ -201,18 +215,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa } - if (!found) { - RelativeLayout custom_name_layout = (RelativeLayout) view.findViewById(R.id.custom_naming_container); - //custom_name_layout.setVisibility(View.VISIBLE); - super.getFragmentManager().beginTransaction().replace(R.id.custom_holder, new animeListView()).commit(); - } - return view; + super.getFragmentManager().beginTransaction().replace(R.id.custom_holder, new animeListView()).commit(); } - - @Override /** @@ -223,6 +230,7 @@ public void onClick(View V) { switch (V.getId()) { case R.id.update_button: update(); + break; case R.id.play_button: playFile(); diff --git a/app/src/main/res/layout/singleitemview.xml b/app/src/main/res/layout/singleitemview.xml index c25dc37..05a0b9b 100644 --- a/app/src/main/res/layout/singleitemview.xml +++ b/app/src/main/res/layout/singleitemview.xml @@ -86,38 +86,46 @@ android:layout_below="@id/status_label"/> + android:id="@+id/list_custom_names"/>