From 892e9aa9d8346a3db3476b836e345b5a4f309367 Mon Sep 17 00:00:00 2001 From: nayanesh Date: Wed, 23 Mar 2016 14:53:50 +0530 Subject: [PATCH] exception handling --- .idea/encodings.xml | 6 ++++ .idea/gradle.xml | 8 +++++ .idea/modules.xml | 3 +- .idea/vcs.xml | 1 + TwitterCrashlytics.iml => VolleyExample.iml | 2 +- app/app.iml | 31 +++++++++++++------ app/build.gradle | 3 +- .../Utils/DataInitilizer.java | 5 ++- .../adapter/CommentsListAdapter.java | 10 +++--- .../adapter/IssuesListAdapter.java | 22 +++++-------- .../network/LruBitmapCache.java | 3 ++ app/src/main/res/menu/menu_main.xml | 7 ----- app/src/main/res/values/strings.xml | 5 +-- settings.gradle | 1 + volley | 1 + 15 files changed, 62 insertions(+), 46 deletions(-) create mode 100644 .idea/encodings.xml rename TwitterCrashlytics.iml => VolleyExample.iml (70%) delete mode 100644 app/src/main/res/menu/menu_main.xml create mode 160000 volley diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 1bbc21d..23c0b41 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -10,6 +10,14 @@ + + diff --git a/.idea/modules.xml b/.idea/modules.xml index 82d4bc2..5056762 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,8 +2,9 @@ - + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..555bd48 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/TwitterCrashlytics.iml b/VolleyExample.iml similarity index 70% rename from TwitterCrashlytics.iml rename to VolleyExample.iml index 2a3f222..2c7df07 100644 --- a/TwitterCrashlytics.iml +++ b/VolleyExample.iml @@ -1,5 +1,5 @@ - + diff --git a/app/app.iml b/app/app.iml index c75b8d8..6c7eb46 100644 --- a/app/app.iml +++ b/app/app.iml @@ -1,5 +1,5 @@ - + @@ -12,10 +12,7 @@ - + @@ -50,6 +47,13 @@ + + + + + + + @@ -57,6 +61,13 @@ + + + + + + + @@ -75,6 +86,7 @@ + @@ -85,13 +97,12 @@ - - - - + + + - + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 82926c0..a52f2fa 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,7 +24,6 @@ dependencies { compile 'com.android.support:appcompat-v7:23.0.1' compile 'com.android.support:cardview-v7:23.0.1' compile 'com.android.support:recyclerview-v7:23.0.1' - compile 'com.mcxiaoke.volley:library:1.0.19' compile 'com.google.code.gson:gson:2.5' - compile 'com.jakewharton:butterknife:7.0.1' + compile project(':volley') } diff --git a/app/src/main/java/com/twittercrashlytics/Utils/DataInitilizer.java b/app/src/main/java/com/twittercrashlytics/Utils/DataInitilizer.java index 2e1fe84..b5daa31 100644 --- a/app/src/main/java/com/twittercrashlytics/Utils/DataInitilizer.java +++ b/app/src/main/java/com/twittercrashlytics/Utils/DataInitilizer.java @@ -1,9 +1,11 @@ package com.twittercrashlytics.Utils; import android.content.Context; +import android.widget.Toast; import com.android.volley.Response; import com.android.volley.VolleyError; +import com.twittercrashlytics.R; import com.twittercrashlytics.TwitterCrashlyticsApplication; import com.twittercrashlytics.network.GsonRequest; import com.twittercrashlytics.network.model.Comment; @@ -13,7 +15,7 @@ import java.util.List; /** - * Created by Nayanesh Gupte + * */ public class DataInitilizer implements Response.Listener, Response.ErrorListener { @@ -48,6 +50,7 @@ public void getCommentsList(String commentsUrl) { TwitterCrashlyticsApplication.getInstance().addToRequestQueue(myReq, TAG); } else { + Toast.makeText(context, context.getString(R.string.no_network), Toast.LENGTH_SHORT).show(); } } diff --git a/app/src/main/java/com/twittercrashlytics/adapter/CommentsListAdapter.java b/app/src/main/java/com/twittercrashlytics/adapter/CommentsListAdapter.java index ab2c6e5..14992c0 100644 --- a/app/src/main/java/com/twittercrashlytics/adapter/CommentsListAdapter.java +++ b/app/src/main/java/com/twittercrashlytics/adapter/CommentsListAdapter.java @@ -17,12 +17,11 @@ * */ public class CommentsListAdapter extends RecyclerView.Adapter { + private List data = new ArrayList<>(); private LayoutInflater inflater; - private Context context; public CommentsListAdapter(Context context) { - this.context = context; inflater = LayoutInflater.from(context); } @@ -37,8 +36,7 @@ public void add(List data) { @Override public CommentsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = inflater.inflate(R.layout.row_comments, parent, false); - CommentsViewHolder holder = new CommentsViewHolder(view); - return holder; + return new CommentsViewHolder(view); } @Override @@ -61,9 +59,9 @@ public int getItemCount() { static class CommentsViewHolder extends RecyclerView.ViewHolder { - TextView txtvTitle; + final TextView txtvTitle; - TextView txtvIssue; + final TextView txtvIssue; public CommentsViewHolder(View itemView) { super(itemView); diff --git a/app/src/main/java/com/twittercrashlytics/adapter/IssuesListAdapter.java b/app/src/main/java/com/twittercrashlytics/adapter/IssuesListAdapter.java index 1baf00f..e8e4204 100644 --- a/app/src/main/java/com/twittercrashlytics/adapter/IssuesListAdapter.java +++ b/app/src/main/java/com/twittercrashlytics/adapter/IssuesListAdapter.java @@ -17,23 +17,18 @@ import java.util.ArrayList; import java.util.List; -import butterknife.Bind; -import butterknife.ButterKnife; - /** * */ public class IssuesListAdapter extends RecyclerView.Adapter { List data = new ArrayList<>(); private LayoutInflater inflater; - private Context context; private OnItemClickListener onItemClickListener; private ImageLoader imageLoader; public IssuesListAdapter(Context context) { - this.context = context; inflater = LayoutInflater.from(context); imageLoader = TwitterCrashlyticsApplication.getInstance().getImageLoader(); @@ -96,25 +91,24 @@ public int getItemCount() { static class IssuesViewHolder extends RecyclerView.ViewHolder { - @Bind(R.id.txtvTitle) - TextView txtvTitle; + final TextView txtvTitle; - @Bind(R.id.txtvIssue) - TextView txtvIssue; + final TextView txtvIssue; - @Bind(R.id.imgUser) - NetworkImageView imgUser; + final NetworkImageView imgUser; - @Bind(R.id.cardView) - View view; + final View view; public IssuesViewHolder(View itemView) { super(itemView); + view = itemView; - ButterKnife.bind(this, itemView); + txtvTitle = (TextView) itemView.findViewById(R.id.txtvTitle); + txtvIssue = (TextView) itemView.findViewById(R.id.txtvIssue); + imgUser = (NetworkImageView) itemView.findViewById(R.id.imgUser); } } } \ No newline at end of file diff --git a/app/src/main/java/com/twittercrashlytics/network/LruBitmapCache.java b/app/src/main/java/com/twittercrashlytics/network/LruBitmapCache.java index 7167392..64e60c2 100644 --- a/app/src/main/java/com/twittercrashlytics/network/LruBitmapCache.java +++ b/app/src/main/java/com/twittercrashlytics/network/LruBitmapCache.java @@ -5,6 +5,9 @@ import com.android.volley.toolbox.ImageLoader.ImageCache; +/** + * + */ public class LruBitmapCache extends LruCache implements ImageCache { public static int getDefaultLruCacheSize() { diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml deleted file mode 100644 index 0dd1538..0000000 --- a/app/src/main/res/menu/menu_main.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4d3137b..7b299f7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,8 +1,5 @@ - TwitterCrashlytics - Hello world! - Settings + Github REST API "Issue # " No Network Available - MainActivity diff --git a/settings.gradle b/settings.gradle index e7b4def..c727258 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,2 @@ include ':app' +include ':volley' diff --git a/volley b/volley new file mode 160000 index 0000000..f605da3 --- /dev/null +++ b/volley @@ -0,0 +1 @@ +Subproject commit f605da3d9e6590351cb0bb26bb6ba5146952777c