Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A class responsible for showing a list of use cases covered in the app. This commit also adds some UI libraries to be used in the app.
- Loading branch information
Showing
5 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
app/src/main/java/org/solovyev/android/checkout/app/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package org.solovyev.android.checkout.app; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.annotation.StringRes; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
|
||
import butterknife.BindView; | ||
import butterknife.ButterKnife; | ||
|
||
/** | ||
* Shows a list of use cases covered in the app. | ||
*/ | ||
public class MainActivity extends AppCompatActivity { | ||
|
||
@BindView(R.id.recycler) | ||
RecyclerView mRecycler; | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
ButterKnife.bind(this); | ||
|
||
mRecycler.setLayoutManager(new LinearLayoutManager(this)); | ||
mRecycler.setAdapter(new Adapter(this)); | ||
} | ||
|
||
private enum UseCase { | ||
; | ||
|
||
// activity to be started on click | ||
final Class<? extends Activity> activity; | ||
@StringRes | ||
final int title; | ||
@StringRes | ||
final int description; | ||
|
||
UseCase(Class<? extends Activity> activity, @StringRes int title, @StringRes int description) { | ||
this.activity = activity; | ||
this.title = title; | ||
this.description = description; | ||
} | ||
} | ||
|
||
static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { | ||
|
||
private final Activity mActivity; | ||
@BindView(R.id.use_case_title) | ||
TextView mTitle; | ||
@BindView(R.id.use_case_description) | ||
TextView mDescription; | ||
@Nullable | ||
private UseCase mUseCase; | ||
|
||
|
||
ViewHolder(Activity activity, View view) { | ||
super(view); | ||
mActivity = activity; | ||
ButterKnife.bind(this, view); | ||
|
||
view.setOnClickListener(this); | ||
} | ||
|
||
void onBind(UseCase useCase) { | ||
mUseCase = useCase; | ||
mTitle.setText(useCase.title); | ||
mDescription.setText(useCase.description); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
if (mUseCase == null) { | ||
return; | ||
} | ||
mActivity.startActivity(new Intent(mActivity, mUseCase.activity)); | ||
} | ||
} | ||
|
||
private static class Adapter extends RecyclerView.Adapter<ViewHolder> { | ||
|
||
private final Activity mActivity; | ||
private final UseCase[] mUseCases = UseCase.values(); | ||
private final LayoutInflater mInflater; | ||
|
||
private Adapter(Activity activity) { | ||
mActivity = activity; | ||
mInflater = LayoutInflater.from(activity); | ||
} | ||
|
||
@Override | ||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
final View view = mInflater.inflate(R.layout.use_case, parent, false); | ||
return new ViewHolder(mActivity, view); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(ViewHolder holder, int position) { | ||
holder.onBind(mUseCases[position]); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return mUseCases.length; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/recycler" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:background="?selectableItemBackground" | ||
android:gravity="center_vertical" | ||
android:minHeight="?listPreferredItemHeightLarge" | ||
android:orientation="vertical" | ||
android:paddingEnd="?listPreferredItemPaddingRight" | ||
android:paddingLeft="?listPreferredItemPaddingLeft" | ||
android:paddingRight="?listPreferredItemPaddingRight" | ||
android:paddingStart="?listPreferredItemPaddingLeft"> | ||
|
||
<TextView | ||
android:id="@+id/use_case_title" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:textAppearance="?textAppearanceListItem" /> | ||
|
||
<TextView | ||
android:id="@+id/use_case_description" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:textAppearance="?textAppearanceListItem" | ||
android:textColor="@android:color/tertiary_text_light" | ||
android:textSize="14sp" /> | ||
|
||
</LinearLayout> |