Skip to content

Added #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.abhishek.starwars">

<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
38 changes: 38 additions & 0 deletions MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.example.abhishek.starwars;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.swapi.models.Starship;
import com.swapi.sw.StarWarsApi;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

private List<Starship> starsList = new ArrayList<>();
RecyclerView recycler;
RecyclerAdapter adapter;
Starship[] mStars;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StarWarsApi.init();

mStars = new Starship[starsList.size()];
adapter = new RecyclerAdapter(mStars);
recycler =(RecyclerView) findViewById(R.id.recyclerView);
recycler.setAdapter(adapter);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this);
recycler.setLayoutManager(mLayoutManager);




}
}
55 changes: 55 additions & 0 deletions RecyclerAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.example.abhishek.starwars;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.swapi.models.Starship;

/**
* Created by Abhishek on 05/10/2016.
*/
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.RecyclerViewHolder> {

private Starship[] mStarship;

public RecyclerAdapter(Starship[] starships){
mStarship = starships;
}

@Override
public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.starships,parent,false);
RecyclerViewHolder viewHolder = new RecyclerViewHolder(view);
return viewHolder;
}

@Override
public void onBindViewHolder(RecyclerViewHolder holder, int position) {
holder.bindView(mStarship[position]);
}

@Override
public int getItemCount() {
return mStarship.length;
}

public class RecyclerViewHolder extends RecyclerView.ViewHolder{

public TextView mName;
public TextView mCost;

public RecyclerViewHolder(View itemView) {
super(itemView);
mName = (TextView) itemView.findViewById(R.id.name);
mCost = (TextView) itemView.findViewById(R.id.cost);
}
public void bindView(Starship ships){
mName.setText(ships.name);
mCost.setText(ships.costInCredits);
}
}
}
19 changes: 19 additions & 0 deletions activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.abhishek.starwars.MainActivity"
android:background="@drawable/bg_gradient">

<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/recyclerView"/>


</RelativeLayout>
33 changes: 33 additions & 0 deletions starships.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:background="@drawable/bg_gradient"
android:orientation="vertical">

<TextView
android:id="@+id/name"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#ffffffff"
tools:text="StarWars Galaxy"
android:textSize="20sp"/>

<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
tools:text="Cost"
android:textSize="20sp"
android:textColor="#ffffff"
android:id="@+id/cost"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/name" />



</RelativeLayout>