Skip to content

Commit

Permalink
New Api used for Languages
Browse files Browse the repository at this point in the history
Now, Language name along with Number of programs in each language.
  • Loading branch information
amanmehara committed Dec 22, 2015
1 parent 56b8b48 commit 35ce095
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -51,6 +51,8 @@ protected void onCreate(Bundle savedInstanceState) {
e.printStackTrace();
}



languageRecyclerView = (RecyclerView) findViewById(R.id.language_recycler_view);
languageRecyclerView.setHasFixedSize(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<LanguageAdapter.ViewHolder> {

private String language;

private String programCount;

private JSONArray mDataset;

private ListClickListener listClickListener;
Expand All @@ -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);

}

Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
// }
}
Expand Down
5 changes: 0 additions & 5 deletions android/src/main/res/layout/activity_language.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.amanmehara.programming.android.LanguageActivity">

<!--<TextView-->
<!--android:text="@string/hello_world"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"/>-->

<android.support.v7.widget.RecyclerView
android:id="@+id/language_recycler_view"
android:scrollbars="vertical"
Expand Down
16 changes: 13 additions & 3 deletions android/src/main/res/layout/language_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,26 @@
<ImageView android:id="@+id/language_image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:layout_gravity="center_vertical|center_horizontal"/>
android:layout_weight="0.25"
android:layout_gravity="center_vertical"/>
<TextView
android:id="@+id/language_name"
android:layout_width="0dp"
android:layout_weight="0.7"
android:layout_weight="0.45"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textSize="24sp"
android:paddingLeft="8sp"/>

<TextView android:id="@+id/language_count"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="right"
android:textSize="48sp"
android:textColor="@color/primary_light"
android:layout_gravity="center_vertical"
android:text="999"/>
</LinearLayout>


Expand Down
6 changes: 3 additions & 3 deletions android/src/main/res/layout/programs_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:background="?android:attr/selectableItemBackground"
Expand All @@ -19,8 +19,8 @@
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="?android:attr/selectableItemBackground"
android:gravity="center"
android:textSize="16dp"/>
android:textSize="16dp"
android:padding="16dp"/>

</android.support.v7.widget.CardView>
</LinearLayout>

0 comments on commit 35ce095

Please sign in to comment.