From 78cc9d8f7fecf87b24027cb37562713c6d53de45 Mon Sep 17 00:00:00 2001 From: Fung Date: Wed, 9 Aug 2017 22:41:00 +0800 Subject: [PATCH] IStepperAdapter: Rename Signed-off-by: Fung --- .../feng/common/stepperview/demo/MainActivity.java | 10 ++++++---- .../fragment/VerticalStepperAdapterDemoFragment.java | 4 ++-- ...IStepperViewAdapter.java => IStepperAdapter.java} | 2 +- .../moe/feng/common/stepperview/IStepperView.java | 2 +- .../common/stepperview/VerticalStepperItemView.java | 4 ++++ .../feng/common/stepperview/VerticalStepperView.java | 12 ++++++++---- ...ViewAdapter.java => ViewBasedStepperAdapter.java} | 6 +++--- 7 files changed, 25 insertions(+), 15 deletions(-) rename library/src/main/java/moe/feng/common/stepperview/{IStepperViewAdapter.java => IStepperAdapter.java} (89%) rename library/src/main/java/moe/feng/common/stepperview/{StepperViewAdapter.java => ViewBasedStepperAdapter.java} (74%) diff --git a/demo/src/main/java/moe/feng/common/stepperview/demo/MainActivity.java b/demo/src/main/java/moe/feng/common/stepperview/demo/MainActivity.java index 2f0c873..64c8f75 100644 --- a/demo/src/main/java/moe/feng/common/stepperview/demo/MainActivity.java +++ b/demo/src/main/java/moe/feng/common/stepperview/demo/MainActivity.java @@ -66,12 +66,10 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) { mDrawerLayout.closeDrawer(mNavigationView); switch (item.getItemId()) { case R.id.item_vertical_stepper: - getSupportFragmentManager().beginTransaction() - .replace(R.id.container, mVerticalStepperDemoFragment).commit(); + replaceFragment(mVerticalStepperDemoFragment); return true; case R.id.item_vertical_stepper_adapter: - getSupportFragmentManager().beginTransaction() - .replace(R.id.container, mVerticalStepperAdapterDemoFragment).commit(); + replaceFragment(mVerticalStepperAdapterDemoFragment); return true; case R.id.action_alipay_donate: if (AlipayZeroSdk.hasInstalledAlipayClient(this)) { @@ -98,6 +96,10 @@ public void onClick(DialogInterface dialogInterface, int i) { } } + private void replaceFragment(Fragment fragment) { + getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment).commit(); + } + private void openWebsite(String url) { CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); builder.setToolbarColor(getResources().getColor(R.color.colorPrimary)); diff --git a/demo/src/main/java/moe/feng/common/stepperview/demo/fragment/VerticalStepperAdapterDemoFragment.java b/demo/src/main/java/moe/feng/common/stepperview/demo/fragment/VerticalStepperAdapterDemoFragment.java index 5a268f4..7e7cbc2 100644 --- a/demo/src/main/java/moe/feng/common/stepperview/demo/fragment/VerticalStepperAdapterDemoFragment.java +++ b/demo/src/main/java/moe/feng/common/stepperview/demo/fragment/VerticalStepperAdapterDemoFragment.java @@ -9,12 +9,12 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; -import moe.feng.common.stepperview.IStepperViewAdapter; +import moe.feng.common.stepperview.IStepperAdapter; import moe.feng.common.stepperview.VerticalStepperItemView; import moe.feng.common.stepperview.VerticalStepperView; import moe.feng.common.stepperview.demo.R; -public class VerticalStepperAdapterDemoFragment extends Fragment implements IStepperViewAdapter { +public class VerticalStepperAdapterDemoFragment extends Fragment implements IStepperAdapter { private VerticalStepperView mVerticalStepperView; diff --git a/library/src/main/java/moe/feng/common/stepperview/IStepperViewAdapter.java b/library/src/main/java/moe/feng/common/stepperview/IStepperAdapter.java similarity index 89% rename from library/src/main/java/moe/feng/common/stepperview/IStepperViewAdapter.java rename to library/src/main/java/moe/feng/common/stepperview/IStepperAdapter.java index dc66fa4..c688bb1 100644 --- a/library/src/main/java/moe/feng/common/stepperview/IStepperViewAdapter.java +++ b/library/src/main/java/moe/feng/common/stepperview/IStepperAdapter.java @@ -4,7 +4,7 @@ import android.view.View; import android.view.ViewGroup; -public interface IStepperViewAdapter { +public interface IStepperAdapter { String getTitle(int index); diff --git a/library/src/main/java/moe/feng/common/stepperview/IStepperView.java b/library/src/main/java/moe/feng/common/stepperview/IStepperView.java index bbd3663..31f8b65 100644 --- a/library/src/main/java/moe/feng/common/stepperview/IStepperView.java +++ b/library/src/main/java/moe/feng/common/stepperview/IStepperView.java @@ -5,7 +5,7 @@ interface IStepperView { - IStepperViewAdapter getViewAdapter(); + IStepperAdapter getViewAdapter(); int getCurrentStep(); @ColorInt int getNormalColor(); diff --git a/library/src/main/java/moe/feng/common/stepperview/VerticalStepperItemView.java b/library/src/main/java/moe/feng/common/stepperview/VerticalStepperItemView.java index 3a78f93..8f83296 100644 --- a/library/src/main/java/moe/feng/common/stepperview/VerticalStepperItemView.java +++ b/library/src/main/java/moe/feng/common/stepperview/VerticalStepperItemView.java @@ -106,6 +106,10 @@ public void addView(View child, int index, ViewGroup.LayoutParams layoutParams) } } + FrameLayout getCustomView() { + return mCustomView; + } + public void removeCustomView() { mCustomView.removeAllViews(); } diff --git a/library/src/main/java/moe/feng/common/stepperview/VerticalStepperView.java b/library/src/main/java/moe/feng/common/stepperview/VerticalStepperView.java index d85dfff..9e8d759 100644 --- a/library/src/main/java/moe/feng/common/stepperview/VerticalStepperView.java +++ b/library/src/main/java/moe/feng/common/stepperview/VerticalStepperView.java @@ -6,6 +6,7 @@ import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; +import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import moe.feng.common.stepperview.internal.VerticalSpaceItemDecoration; @@ -15,7 +16,7 @@ public class VerticalStepperView extends FrameLayout implements IStepperView { private RecyclerView mListView; private ItemAdapter mAdapter; - private IStepperViewAdapter mViewAdapter; + private IStepperAdapter mViewAdapter; private int mCurrentStep = 0; private boolean mAnimationEnabled; @@ -74,7 +75,7 @@ private void prepareListView(Context context) { addView(mListView, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); } - public void setViewAdapter(IStepperViewAdapter viewAdapter) { + public void setViewAdapter(IStepperAdapter viewAdapter) { mViewAdapter = viewAdapter; mAdapter.notifyDataSetChanged(); } @@ -118,7 +119,7 @@ public boolean prevStep() { } @Override - public IStepperViewAdapter getViewAdapter() { + public IStepperAdapter getViewAdapter() { return mViewAdapter; } @@ -193,7 +194,10 @@ public void onBindViewHolder(ItemHolder holder, int position) { holder.mItemView.setState(VerticalStepperItemView.STATE_SELECTED); } holder.mItemView.removeCustomView(); - holder.mItemView.addView(getViewAdapter().onCreateCustomView(position, getContext(), holder.mItemView)); + View customView = getViewAdapter().onCreateCustomView(position, getContext(), holder.mItemView); + if (customView != null) { + holder.mItemView.addView(customView); + } } @Override diff --git a/library/src/main/java/moe/feng/common/stepperview/StepperViewAdapter.java b/library/src/main/java/moe/feng/common/stepperview/ViewBasedStepperAdapter.java similarity index 74% rename from library/src/main/java/moe/feng/common/stepperview/StepperViewAdapter.java rename to library/src/main/java/moe/feng/common/stepperview/ViewBasedStepperAdapter.java index a6b1ac8..8fa2727 100644 --- a/library/src/main/java/moe/feng/common/stepperview/StepperViewAdapter.java +++ b/library/src/main/java/moe/feng/common/stepperview/ViewBasedStepperAdapter.java @@ -3,15 +3,15 @@ import android.content.Context; import android.view.View; -public abstract class StepperViewAdapter implements IStepperViewAdapter { +public abstract class ViewBasedStepperAdapter implements IStepperAdapter { private View mViews[]; - public StepperViewAdapter() { + public ViewBasedStepperAdapter() { } - public StepperViewAdapter(View[] views) { + public ViewBasedStepperAdapter(View[] views) { mViews = views; }