Skip to content

Commit aa587c8

Browse files
author
smhdk
committed
-Code review
1 parent c6d7349 commit aa587c8

File tree

8 files changed

+100
-35
lines changed

8 files changed

+100
-35
lines changed

.idea/misc.xml

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/hololo/tutorial/sample/MainActivity.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.os.Bundle;
66
import android.support.annotation.Nullable;
77
import android.view.View;
8+
import android.widget.TextView;
89
import android.widget.Toast;
910

1011
import com.hololo.tutorial.library.PermissionStep;
@@ -13,8 +14,6 @@
1314

1415
public class MainActivity extends TutorialActivity {
1516

16-
private View currentFragmentView;
17-
private String currentFragmentTag;
1817

1918
@Override
2019
protected void onCreate(Bundle savedInstanceState) {
@@ -37,15 +36,18 @@ protected void onCreate(Bundle savedInstanceState) {
3736
.build());
3837

3938
addFragment(new Step.Builder()
39+
.setTitle(getString(R.string.choose_the_song))
40+
.setContent(getString(R.string.swap_to_the_tab))
41+
.setBackgroundColor(Color.parseColor("#00D4BA"))
42+
.setDrawable(R.drawable.ss_2)
43+
.setSummary(getString(R.string.continue_and_update)).build());
4044

41-
.build());
4245

4346
addFragment(new Step.Builder()
44-
.setTitle(getString(R.string.edit_data))
45-
.setContent(getString(R.string.update_easily))
47+
.setTitle("Custom Layout Sample")
4648
.setBackgroundColor(Color.parseColor("#1098FE"))
47-
.setDrawable(R.drawable.ss_3)
48-
.setSummary(getString(R.string.continue_and_result))
49+
.setView(R.layout.layout_sample)
50+
.setTag("sampleTag")
4951
.build());
5052

5153
addFragment(new Step.Builder()
@@ -69,15 +71,17 @@ public void cancelTutorial() {
6971
}
7072

7173
@Override
72-
public void currentFragmentPosition(int position) {
73-
Toast.makeText(this, "Position : " + position, Toast.LENGTH_SHORT).show();
74-
}
75-
76-
@Override
77-
public void currentFragmentView(@Nullable View view, @Nullable String tag) {
78-
currentFragmentView = view;
79-
currentFragmentTag = tag;
74+
public void currentFragment(@Nullable final View view, Integer position) {
75+
if (view != null && position == 3) {
76+
TextView contentTextview = view.findViewById(R.id.content);
77+
contentTextview.setText("Click This");
78+
79+
contentTextview.setOnClickListener(new View.OnClickListener() {
80+
@Override
81+
public void onClick(View v) {
82+
Toast.makeText(view.getContext(), "You can get current view and implementation it", Toast.LENGTH_LONG).show();
83+
}
84+
});
85+
}
8086
}
81-
82-
8387
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent">
5+
6+
<TextView
7+
android:id="@+id/title"
8+
android:layout_width="match_parent"
9+
android:layout_height="wrap_content"
10+
android:layout_above="@+id/content"
11+
android:layout_centerInParent="true"
12+
android:layout_margin="16dp"
13+
android:padding="16dp"
14+
android:textAlignment="center"
15+
android:textSize="18sp" />
16+
17+
<TextView
18+
android:id="@+id/content"
19+
android:layout_width="match_parent"
20+
android:layout_height="wrap_content"
21+
android:layout_centerInParent="true"
22+
android:layout_margin="16dp"
23+
android:padding="16dp"
24+
android:textAlignment="center" />
25+
26+
</RelativeLayout>

library/src/main/java/com/hololo/tutorial/library/CurrentFragmentListener.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@
44
import android.view.View;
55

66
public interface CurrentFragmentListener {
7-
void currentFragmentPosition(int position);
8-
9-
void currentFragmentView(@Nullable View view, @Nullable String tag);
7+
void currentFragment(@Nullable View view, @Nullable Integer position);
108
}

library/src/main/java/com/hololo/tutorial/library/StepFragment.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,17 @@
1010

1111
public class StepFragment extends StepView {
1212

13-
private static CurrentFragmentListener currentFragmentListener;
1413
private TextView title;
1514
private TextView content;
1615
private TextView summary;
1716
private ImageView imageView;
1817
private View layout;
1918

20-
static StepFragment createFragment(Step step, CurrentFragmentListener listener, int pos) {
19+
static StepFragment createFragment(Step step, int pos) {
2120
StepFragment fragment = new StepFragment();
2221
Bundle bundle = new Bundle();
2322
bundle.putParcelable("step", step);
2423
fragment.setArguments(bundle);
25-
currentFragmentListener = listener;
2624
return fragment;
2725
}
2826

@@ -39,7 +37,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
3937
int layout = step.getViewType() > 0 ? step.getViewType() : R.layout.fragment_step;
4038

4139
View view = inflater.inflate(layout, container, false);
42-
currentFragmentListener.currentFragmentView(view, step.getTag());
40+
view.setTag(step.getTag());
4341
initViews(view);
4442
initData();
4543

library/src/main/java/com/hololo/tutorial/library/StepPagerAdapter.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88

99
public class StepPagerAdapter extends FragmentPagerAdapter {
1010
private List<Step> stepList;
11-
private CurrentFragmentListener currentFragmentListener;
1211

13-
public StepPagerAdapter(FragmentManager fm, List<Step> stepList, CurrentFragmentListener listener) {
12+
public StepPagerAdapter(FragmentManager fm, List<Step> stepList) {
1413
super(fm);
1514
this.stepList = stepList;
16-
this.currentFragmentListener = listener;
1715
}
1816

1917

@@ -25,7 +23,6 @@ public int getCount() {
2523
@Override
2624
public Fragment getItem(int position) {
2725
Step step = stepList.get(position);
28-
29-
return StepFragment.createFragment(step, currentFragmentListener, position);
26+
return StepFragment.createFragment(step, position);
3027
}
3128
}

library/src/main/java/com/hololo/tutorial/library/TutorialActivity.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.support.annotation.NonNull;
88
import android.support.annotation.Nullable;
99
import android.support.annotation.RequiresApi;
10+
import android.support.v4.app.Fragment;
1011
import android.support.v4.view.ViewPager;
1112
import android.support.v7.app.AppCompatActivity;
1213
import android.view.MotionEvent;
@@ -22,7 +23,7 @@
2223
import java.util.ArrayList;
2324
import java.util.List;
2425

25-
public abstract class TutorialActivity extends AppCompatActivity implements View.OnClickListener, CurrentFragmentListener {
26+
public abstract class TutorialActivity extends AppCompatActivity implements View.OnClickListener {
2627

2728
private List<Step> steps;
2829
private StepPagerAdapter adapter;
@@ -32,8 +33,6 @@ public abstract class TutorialActivity extends AppCompatActivity implements View
3233
private LinearLayout indicatorLayout;
3334
private FrameLayout containerLayout;
3435
private RelativeLayout buttonContainer;
35-
private CurrentFragmentListener currentFragmentListener;
36-
3736
private int currentItem;
3837

3938
private String prevText, nextText, finishText, cancelText, givePermissionText;
@@ -44,7 +43,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
4443
setTheme(R.style.TutorialStyle);
4544
super.onCreate(savedInstanceState);
4645
setContentView(R.layout.activity_tutorial);
47-
currentFragmentListener = this;
4846
init();
4947
}
5048

@@ -64,7 +62,7 @@ private void initTexts() {
6462
}
6563

6664
private void initAdapter() {
67-
adapter = new StepPagerAdapter(getSupportFragmentManager(), steps, this);
65+
adapter = new StepPagerAdapter(getSupportFragmentManager(), steps);
6866
pager.setAdapter(adapter);
6967
pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
7068
@Override
@@ -75,7 +73,7 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse
7573
@Override
7674
public void onPageSelected(int position) {
7775
currentItem = position;
78-
currentFragmentListener.currentFragmentPosition(position);
76+
currentFragment(((Fragment) adapter.instantiateItem(pager, position)).getView(), position);
7977
controlPosition(position);
8078
}
8179

@@ -251,6 +249,10 @@ public void finishTutorial() {
251249
public void cancelTutorial() {
252250
}
253251

252+
public void currentFragment(@Nullable View view, Integer position) {
253+
254+
}
255+
254256
public void setPrevText(String text) {
255257
prevText = text;
256258
}

0 commit comments

Comments
 (0)