From 35ce095a03b9a8b8b56925389862f5ec0e5b4cab Mon Sep 17 00:00:00 2001 From: amanmehara Date: Tue, 22 Dec 2015 14:02:30 +0530 Subject: [PATCH] New Api used for Languages Now, Language name along with Number of programs in each language. --- .../programming/android/LanguageActivity.java | 4 +- .../programming/android/LanguageAdapter.java | 66 +++++++++++-------- .../programming/android/ProgramsActivity.java | 3 +- .../programming/android/ProgramsAdapter.java | 8 +-- .../src/main/res/layout/activity_language.xml | 5 -- android/src/main/res/layout/language_list.xml | 16 ++++- android/src/main/res/layout/programs_list.xml | 6 +- 7 files changed, 62 insertions(+), 46 deletions(-) diff --git a/android/src/main/java/com/amanmehara/programming/android/LanguageActivity.java b/android/src/main/java/com/amanmehara/programming/android/LanguageActivity.java index d5a6384..57d7c5b 100644 --- a/android/src/main/java/com/amanmehara/programming/android/LanguageActivity.java +++ b/android/src/main/java/com/amanmehara/programming/android/LanguageActivity.java @@ -37,7 +37,7 @@ protected void onCreate(Bundle savedInstanceState) { WebServiceClient webServiceClient = new WebServiceClient(); try { jsonLanguage = webServiceClient - .execute("http://programmingwebapp.azurewebsites.net/api/languages") + .execute("http://programmingwebapp.azurewebsites.net/api/languages/count") .get(); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); @@ -51,6 +51,8 @@ protected void onCreate(Bundle savedInstanceState) { e.printStackTrace(); } + + languageRecyclerView = (RecyclerView) findViewById(R.id.language_recycler_view); languageRecyclerView.setHasFixedSize(true); diff --git a/android/src/main/java/com/amanmehara/programming/android/LanguageAdapter.java b/android/src/main/java/com/amanmehara/programming/android/LanguageAdapter.java index 9d3b775..d2d80f7 100644 --- a/android/src/main/java/com/amanmehara/programming/android/LanguageAdapter.java +++ b/android/src/main/java/com/amanmehara/programming/android/LanguageAdapter.java @@ -8,11 +8,14 @@ import android.widget.TextView; import org.json.JSONArray; import org.json.JSONException; +import org.json.JSONObject; public class LanguageAdapter extends RecyclerView.Adapter { private String language; + private String programCount; + private JSONArray mDataset; private ListClickListener listClickListener; @@ -39,61 +42,64 @@ public LanguageAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) @Override public void onBindViewHolder(LanguageAdapter.ViewHolder viewHolder, int i) { try { - language = mDataset.getString(i); + JSONObject jsonObject = mDataset.getJSONObject(i); + language = jsonObject.getString("LanguageName"); + programCount = jsonObject.getString("LanguageCount"); } catch (JSONException e) { e.printStackTrace(); } switch (language) { case "c": - viewHolder.mImageView.setImageResource(R.drawable.c); - viewHolder.mTextView.setText("C"); + viewHolder.mLanguageImage.setImageResource(R.drawable.c); + viewHolder.mLanguageName.setText("C"); break; case "cpp": - viewHolder.mImageView.setImageResource(R.drawable.cpp); - viewHolder.mTextView.setText("C++"); + viewHolder.mLanguageImage.setImageResource(R.drawable.cpp); + viewHolder.mLanguageName.setText("C++"); break; case "csharp": - viewHolder.mImageView.setImageResource(R.drawable.csharp); - viewHolder.mTextView.setText("C#"); + viewHolder.mLanguageImage.setImageResource(R.drawable.csharp); + viewHolder.mLanguageName.setText("C#"); break; case "fsharp": - viewHolder.mImageView.setImageResource(R.drawable.fsharp); - viewHolder.mTextView.setText("F#"); + viewHolder.mLanguageImage.setImageResource(R.drawable.fsharp); + viewHolder.mLanguageName.setText("F#"); break; case "groovy": - viewHolder.mImageView.setImageResource(R.drawable.groovy); - viewHolder.mTextView.setText("Groovy"); + viewHolder.mLanguageImage.setImageResource(R.drawable.groovy); + viewHolder.mLanguageName.setText("Groovy"); break; case "java": - viewHolder.mImageView.setImageResource(R.drawable.java); - viewHolder.mTextView.setText("Java"); + viewHolder.mLanguageImage.setImageResource(R.drawable.java); + viewHolder.mLanguageName.setText("Java"); break; case "javascript": - viewHolder.mImageView.setImageResource(R.drawable.javascript); - viewHolder.mTextView.setText("JavaScript"); + viewHolder.mLanguageImage.setImageResource(R.drawable.javascript); + viewHolder.mLanguageName.setText("JavaScript"); break; case "php": - viewHolder.mImageView.setImageResource(R.drawable.php); - viewHolder.mTextView.setText("PHP"); + viewHolder.mLanguageImage.setImageResource(R.drawable.php); + viewHolder.mLanguageName.setText("PHP"); break; case "python": - viewHolder.mImageView.setImageResource(R.drawable.python); - viewHolder.mTextView.setText("Python"); + viewHolder.mLanguageImage.setImageResource(R.drawable.python); + viewHolder.mLanguageName.setText("Python"); break; case "scala": - viewHolder.mImageView.setImageResource(R.drawable.scala); - viewHolder.mTextView.setText("Scala"); + viewHolder.mLanguageImage.setImageResource(R.drawable.scala); + viewHolder.mLanguageName.setText("Scala"); break; case "sql": - viewHolder.mImageView.setImageResource(R.drawable.sql); - viewHolder.mTextView.setText("SQL"); + viewHolder.mLanguageImage.setImageResource(R.drawable.sql); + viewHolder.mLanguageName.setText("SQL"); break; default: - viewHolder.mImageView.setImageResource(R.drawable.ic_circle_logo); - viewHolder.mTextView.setText(language); + viewHolder.mLanguageImage.setImageResource(R.drawable.ic_circle_logo); + viewHolder.mLanguageName.setText(language); } + viewHolder.mLanguageCount.setText(programCount); } @@ -107,13 +113,15 @@ public interface ListClickListener { } public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { - public TextView mTextView; - public ImageView mImageView; + public TextView mLanguageName; + public ImageView mLanguageImage; + public TextView mLanguageCount; public ViewHolder(View v) { super(v); - mTextView = (TextView) v.findViewById(R.id.language_name); - mImageView = (ImageView) v.findViewById(R.id.language_image); + mLanguageName = (TextView) v.findViewById(R.id.language_name); + mLanguageImage = (ImageView) v.findViewById(R.id.language_image); + mLanguageCount = (TextView) v.findViewById(R.id.language_count); v.setOnClickListener(this); } diff --git a/android/src/main/java/com/amanmehara/programming/android/ProgramsActivity.java b/android/src/main/java/com/amanmehara/programming/android/ProgramsActivity.java index 8817e4a..9dfca72 100644 --- a/android/src/main/java/com/amanmehara/programming/android/ProgramsActivity.java +++ b/android/src/main/java/com/amanmehara/programming/android/ProgramsActivity.java @@ -44,7 +44,8 @@ protected void onCreate(Bundle savedInstanceState) { try { jsonPrograms = webServiceClient - .execute("http://programmingwebapp.azurewebsites.net/api/programs/language/" + language) + .execute("http://programmingwebapp.azurewebsites.net/api/programs/language/" + + language) .get(); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); diff --git a/android/src/main/java/com/amanmehara/programming/android/ProgramsAdapter.java b/android/src/main/java/com/amanmehara/programming/android/ProgramsAdapter.java index 767c0c5..7127008 100644 --- a/android/src/main/java/com/amanmehara/programming/android/ProgramsAdapter.java +++ b/android/src/main/java/com/amanmehara/programming/android/ProgramsAdapter.java @@ -45,16 +45,16 @@ public void onBindViewHolder(ProgramsAdapter.ViewHolder viewHolder, int i) { // switch (i%4) { // case 0: -// viewHolder.mTextView.setBackgroundColor(Color.RED); +// viewHolder.mLanguageName.setBackgroundColor(Color.RED); // break; // case 1: -// viewHolder.mTextView.setBackgroundColor(Color.GREEN); +// viewHolder.mLanguageName.setBackgroundColor(Color.GREEN); // break; // case 2: -// viewHolder.mTextView.setBackgroundColor(Color.BLUE); +// viewHolder.mLanguageName.setBackgroundColor(Color.BLUE); // break; // case 3: -// viewHolder.mTextView.setBackgroundColor(Color.MAGENTA); +// viewHolder.mLanguageName.setBackgroundColor(Color.MAGENTA); // break; // } } diff --git a/android/src/main/res/layout/activity_language.xml b/android/src/main/res/layout/activity_language.xml index 558513b..9078a7a 100644 --- a/android/src/main/res/layout/activity_language.xml +++ b/android/src/main/res/layout/activity_language.xml @@ -9,11 +9,6 @@ android:paddingBottom="@dimen/activity_vertical_margin" tools:context="com.amanmehara.programming.android.LanguageActivity"> - - - - - + android:layout_weight="0.25" + android:layout_gravity="center_vertical"/> + + diff --git a/android/src/main/res/layout/programs_list.xml b/android/src/main/res/layout/programs_list.xml index 7b0cf39..7c7905b 100644 --- a/android/src/main/res/layout/programs_list.xml +++ b/android/src/main/res/layout/programs_list.xml @@ -7,7 +7,7 @@ + android:textSize="16dp" + android:padding="16dp"/> \ No newline at end of file