Skip to content

Commit 6ce76b9

Browse files
committed
fix : some type issues
1 parent 33153be commit 6ce76b9

11 files changed

Lines changed: 218 additions & 193 deletions

File tree

app/src/main/java/me/jerryhanks/stepviewapp/MainActivity.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.support.v7.app.AppCompatActivity;
44
import android.os.Bundle;
55
import android.view.Gravity;
6-
import android.view.LayoutInflater;
76
import android.view.View;
87
import android.view.ViewGroup;
98
import android.widget.FrameLayout;
@@ -12,9 +11,11 @@
1211
import java.util.ArrayList;
1312
import java.util.List;
1413

15-
import me.jerryhanks.stepview.VerticalStepView;
14+
import me.jerryhanks.stepview.IndicatorAdapter;
15+
import me.jerryhanks.stepview.TimeLineView;
1616
import me.jerryhanks.stepview.interfaces.TimeLineViewCallback;
1717
import me.jerryhanks.stepview.model.Status;
18+
import me.jerryhanks.stepview.model.TimeLine;
1819

1920
public class MainActivity extends AppCompatActivity {
2021

@@ -23,7 +24,7 @@ protected void onCreate(Bundle savedInstanceState) {
2324
super.onCreate(savedInstanceState);
2425
setContentView(R.layout.activity_main);
2526

26-
VerticalStepView timeLineView = findViewById(R.id.timeline_view);
27+
TimeLineView timeLineView = findViewById(R.id.timeline_view);
2728

2829
List<MyTimeLine> timeLines = new ArrayList<>();
2930
timeLines.add(new MyTimeLine(Status.COMPLETED, "Sample Title 1", "Sample content 1"));
@@ -35,20 +36,19 @@ protected void onCreate(Bundle savedInstanceState) {
3536
timeLines.add(new MyTimeLine(Status.UN_COMPLETED, "Sample Title 7", "Sample content 7 sdpfjdfpdfjpdjpojdpofm;dfpmpmdpkdk[k[kdfm;dfm[l[dfl][kdf[omd[pkfkdkf'mdmf';mmvwejfopj2wpowmlskbokr"));
3637

3738

38-
timeLineView.setTimeLines(timeLines);
39-
timeLineView.setTimelineCallback(new TimeLineViewCallback<MyTimeLine>() {
39+
IndicatorAdapter<MyTimeLine> adapter = new IndicatorAdapter<>(timeLines, this, new TimeLineViewCallback<MyTimeLine>() {
4040
@Override
41-
public void onBindView(MyTimeLine model, FrameLayout container) {
41+
public View onBindView(MyTimeLine model, FrameLayout container, int position) {
4242
View view = getLayoutInflater()
4343
.inflate(me.jerryhanks.stepview.R.layout.sample_time_line,
4444
container, false);
4545
((TextView) view.findViewById(R.id.tv_title)).setText(model.getTitle());
4646
((TextView) view.findViewById(R.id.tv_content)).setText(model.getContent());
47-
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
48-
view.setLayoutParams(params);
49-
container.addView(view);
50-
params.gravity = Gravity.CENTER_VERTICAL | Gravity.START;
47+
48+
return view;
5149
}
5250
});
51+
timeLineView.setIndicatorAdapter(adapter);
52+
adapter.swapItems(timeLines);
5353
}
5454
}

app/src/main/res/layout/activity_main.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
android:layout_height="match_parent"
77
tools:context="me.jerryhanks.stepviewapp.MainActivity">
88

9-
<me.jerryhanks.stepview.VerticalStepView
9+
<me.jerryhanks.stepview.TimeLineView
1010
android:id="@+id/timeline_view"
1111
android:layout_width="0dp"
1212
android:layout_height="0dp"
@@ -19,6 +19,6 @@
1919
app:layout_constraintRight_toRightOf="parent"
2020
app:layout_constraintTop_toTopOf="parent">
2121

22-
</me.jerryhanks.stepview.VerticalStepView>
22+
</me.jerryhanks.stepview.TimeLineView>
2323

2424
</android.support.constraint.ConstraintLayout>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
google()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.0.0-rc1'
9+
classpath 'com.android.tools.build:gradle:3.0.1'
1010
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
1111

1212
// NOTE: Do not place your application dependencies here; they belong
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package me.jerryhanks.stepview;
2+
3+
import android.content.Context;
4+
import android.support.v4.content.ContextCompat;
5+
import android.support.v7.widget.RecyclerView;
6+
import android.view.Gravity;
7+
import android.view.LayoutInflater;
8+
import android.view.View;
9+
import android.view.ViewGroup;
10+
import android.widget.FrameLayout;
11+
12+
import java.util.ArrayList;
13+
import java.util.List;
14+
15+
import me.jerryhanks.stepview.interfaces.TimeLineViewCallback;
16+
import me.jerryhanks.stepview.model.TimeLine;
17+
18+
public class IndicatorAdapter<T extends TimeLine> extends RecyclerView.Adapter<IndicatorHolder> {
19+
20+
private List<T> timeLines = new ArrayList<>();
21+
private Context context;
22+
private TimeLineViewCallback<T> _callback;
23+
24+
public IndicatorAdapter(List<T> timeLines, Context context, TimeLineViewCallback<T> callback) {
25+
this.timeLines = timeLines;
26+
this.context = context;
27+
this._callback = callback;
28+
}
29+
30+
@Override
31+
public IndicatorHolder onCreateViewHolder(ViewGroup parent, int viewType) {
32+
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.vertical_step_indicator, parent, false);
33+
34+
IndicatorHolder holder = new IndicatorHolder(view);
35+
holder.setContext(parent.getContext());
36+
return holder;
37+
}
38+
39+
@Override
40+
public void onBindViewHolder(IndicatorHolder holder, int position) {
41+
T prevTimeline = position > 0 ? timeLines.get(position - 1) : null;
42+
if (prevTimeline != null) {
43+
switch (prevTimeline.getStatus()) {
44+
case COMPLETED:
45+
holder.topLineIndicator.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.box_enabled));
46+
break;
47+
case UN_COMPLETED:
48+
case ATTENTION:
49+
holder.topLineIndicator.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.box_disabled));
50+
break;
51+
}
52+
53+
}
54+
T timeLine = timeLines.get(position);
55+
switch (timeLine.getStatus()) {
56+
case COMPLETED:
57+
break;
58+
case UN_COMPLETED:
59+
case ATTENTION:
60+
holder.dotIndicator.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.dot_disabled));
61+
holder.bottomLineIndicator.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.box_disabled));
62+
break;
63+
}
64+
if (position == 0) {
65+
holder.topLineIndicator.setVisibility(View.INVISIBLE);
66+
}
67+
if (position == getItemCount() - 1) {
68+
holder.bottomLineIndicator.setVisibility(View.INVISIBLE);
69+
}
70+
71+
if (_callback != null) {
72+
View child = _callback.onBindView(timeLine, holder.container, position);
73+
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
74+
child.setLayoutParams(params);
75+
holder.container.addView(child);
76+
params.gravity = Gravity.CENTER_VERTICAL | Gravity.START;
77+
return;
78+
}
79+
80+
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
81+
View view = LayoutInflater.from(holder.getContext()).inflate(R.layout.sample_time_line, holder.container, false);
82+
view.setLayoutParams(params);
83+
holder.container.addView(view);
84+
params.gravity = Gravity.CENTER_VERTICAL | Gravity.START;
85+
86+
87+
}
88+
89+
@Override
90+
public int getItemCount() {
91+
return this.timeLines.size();
92+
}
93+
94+
public void swapItems(List<T> timeLines) {
95+
this.timeLines = timeLines;
96+
notifyDataSetChanged();
97+
}
98+
99+
private Context getContext() {
100+
return context;
101+
}
102+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package me.jerryhanks.stepview;
2+
3+
import android.content.Context;
4+
import android.support.v7.widget.RecyclerView;
5+
import android.view.View;
6+
import android.widget.FrameLayout;
7+
8+
class IndicatorHolder extends RecyclerView.ViewHolder {
9+
10+
final View topLineIndicator;
11+
final View dotIndicator;
12+
final View bottomLineIndicator;
13+
final FrameLayout container;
14+
private Context context;
15+
16+
17+
IndicatorHolder(View itemView) {
18+
super(itemView);
19+
this.container = itemView.findViewById(R.id.content);
20+
this.topLineIndicator = itemView.findViewById(R.id.line_indicator_top);
21+
this.dotIndicator = itemView.findViewById(R.id.dot_indicator);
22+
this.bottomLineIndicator = itemView.findViewById(R.id.line_indicator_bottom);
23+
24+
}
25+
26+
void setContext(Context context) {
27+
this.context = context;
28+
}
29+
30+
Context getContext() {
31+
return context;
32+
}
33+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package me.jerryhanks.stepview;
2+
3+
import android.content.Context;
4+
import android.support.v4.content.ContextCompat;
5+
import android.support.v7.widget.LinearLayoutManager;
6+
import android.support.v7.widget.RecyclerView;
7+
import android.util.AttributeSet;
8+
import android.view.Gravity;
9+
import android.view.LayoutInflater;
10+
import android.view.View;
11+
import android.view.ViewGroup;
12+
import android.widget.FrameLayout;
13+
import android.widget.RelativeLayout;
14+
15+
import java.util.ArrayList;
16+
import java.util.Collections;
17+
import java.util.List;
18+
19+
import me.jerryhanks.stepview.interfaces.TimeLineViewCallback;
20+
import me.jerryhanks.stepview.model.TimeLine;
21+
22+
/**
23+
* @author <@Po10cio> on 10/17/17 for StepViewApp
24+
* <p>
25+
* Copyright (c) 2017 MAX. All rights reserved.
26+
*/
27+
28+
public class TimeLineView extends RelativeLayout {
29+
private RecyclerView recyclerView;
30+
31+
public TimeLineView(Context context) {
32+
super(context);
33+
init();
34+
}
35+
36+
37+
public TimeLineView(Context context, AttributeSet attrs) {
38+
super(context, attrs);
39+
init();
40+
}
41+
42+
public TimeLineView(Context context, AttributeSet attrs, int defStyleAttr) {
43+
super(context, attrs, defStyleAttr);
44+
init();
45+
}
46+
47+
private void init() {
48+
inflate(getContext(), R.layout.vertical_step_view, this);
49+
recyclerView = findViewById(R.id.recycler);
50+
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
51+
}
52+
53+
public void setIndicatorAdapter(IndicatorAdapter adapter) {
54+
recyclerView.setAdapter(adapter);
55+
}
56+
57+
}
58+
59+
60+

0 commit comments

Comments
 (0)