File tree Expand file tree Collapse file tree 5 files changed +51
-5
lines changed
src/main/java/com/zaaach/linematchingview Expand file tree Collapse file tree 5 files changed +51
-5
lines changed Original file line number Diff line number Diff line change @@ -8,8 +8,8 @@ android {
88 defaultConfig {
99 minSdk 16
1010 targetSdk 30
11- versionCode 1
12- versionName " 1.0 "
11+ versionCode 2
12+ versionName " 1.1 "
1313
1414 testInstrumentationRunner " androidx.test.runner.AndroidJUnitRunner"
1515 consumerProguardFiles " consumer-rules.pro"
Original file line number Diff line number Diff line change @@ -83,9 +83,34 @@ public LineMatchingView<T> init(@NonNull LinkableAdapter<T> adapter){
8383 return this ;
8484 }
8585
86+ public void restore (){
87+ finished = false ;
88+ oldLines .addAll (newLines );
89+ newLines .clear ();
90+ invalidate ();
91+ if (leftItems != null ){
92+ for (int i = 0 ; i < leftItems .size (); i ++) {
93+ leftItems .get (i ).lined = false ;
94+ leftItems .get (i ).line = null ;
95+ notifyItemStateChanged (i , NORMAL , true );
96+ }
97+ }
98+ if (rightItems != null ){
99+ for (int i = 0 ; i < rightItems .size (); i ++) {
100+ rightItems .get (i ).lined = false ;
101+ rightItems .get (i ).line = null ;
102+ notifyItemStateChanged (i , NORMAL , false );
103+ }
104+ }
105+ }
106+
107+ public boolean isFinished (){
108+ return finished ;
109+ }
110+
86111 public void setItems (@ NonNull List <T > left , @ NonNull List <T > right ){
87112 if (linkableAdapter == null ) {
88- throw new IllegalStateException ("LinkableAdapter must not be null, please see method setLinkableAdapter ()" );
113+ throw new IllegalStateException ("LinkableAdapter must not be null, please see method init ()" );
89114 }
90115 leftItems = new ArrayList <>();
91116 rightItems = new ArrayList <>();
Original file line number Diff line number Diff line change @@ -9,8 +9,8 @@ android {
99 applicationId " com.zaaach.demo"
1010 minSdk 16
1111 targetSdk 30
12- versionCode 1
13- versionName " 1.0 "
12+ versionCode 2
13+ versionName " 1.1 "
1414
1515 testInstrumentationRunner " androidx.test.runner.AndroidJUnitRunner"
1616 }
Original file line number Diff line number Diff line change 77import android .view .LayoutInflater ;
88import android .view .View ;
99import android .view .ViewGroup ;
10+ import android .widget .Button ;
1011import android .widget .ImageView ;
1112import android .widget .TextView ;
13+ import android .widget .Toast ;
1214
1315import com .zaaach .linematchingview .LineMatchingView ;
1416
@@ -24,6 +26,17 @@ protected void onCreate(Bundle savedInstanceState) {
2426 setContentView (R .layout .activity_main );
2527
2628 lineMatchingView = findViewById (R .id .line_matching_view );
29+ Button btnRetry = findViewById (R .id .btn_retry );
30+ btnRetry .setOnClickListener (new View .OnClickListener () {
31+ @ Override
32+ public void onClick (View v ) {
33+ if (lineMatchingView .isFinished ()){
34+ lineMatchingView .restore ();
35+ }else {
36+ Toast .makeText (MainActivity .this , "连线未完成" , Toast .LENGTH_SHORT ).show ();
37+ }
38+ }
39+ });
2740
2841 List <ItemInfo > left = new ArrayList <>();
2942 left .add (new ItemInfo (ItemInfo .TEXT , "草莓" ));
Original file line number Diff line number Diff line change 55 android : layout_height =" match_parent"
66 xmlns : app =" http://schemas.android.com/apk/res-auto"
77 android : gravity =" center"
8+ android : orientation =" vertical"
89 tools : context =" .MainActivity" >
910
1011 <com .zaaach.linematchingview.LineMatchingView
2223 app : lmv_line_color_correct =" @color/correct_color"
2324 app : lmv_line_color_error =" @color/error_color" />
2425
26+ <Button
27+ android : id =" @+id/btn_retry"
28+ android : layout_width =" wrap_content"
29+ android : layout_height =" wrap_content"
30+ android : layout_marginTop =" 16dp"
31+ android : text =" 重做" />
32+
2533</LinearLayout >
You can’t perform that action at this time.
0 commit comments