26
26
import androidx .appcompat .widget .Toolbar ;
27
27
import androidx .core .view .GravityCompat ;
28
28
import androidx .drawerlayout .widget .DrawerLayout ;
29
+ import androidx .recyclerview .widget .RecyclerView ;
29
30
30
31
import com .google .android .material .floatingactionbutton .FloatingActionButton ;
31
32
import com .google .android .material .navigation .NavigationView ;
32
- import com .longluo .ebookreader .manager .ReadSettingManager ;
33
33
import com .longluo .ebookreader .R ;
34
34
import com .longluo .ebookreader .base .BaseActivity ;
35
35
import com .longluo .ebookreader .db .BookMeta ;
36
+ import com .longluo .ebookreader .manager .ReadSettingManager ;
36
37
import com .longluo .ebookreader .ui .adapter .ShelfAdapter ;
37
38
import com .longluo .ebookreader .util .BookUtils ;
38
39
import com .longluo .ebookreader .util .DisplayUtils ;
39
- import com .longluo .ebookreader .widget .view .DragGridView ;
40
40
import com .longluo .ebookreader .widget .animation .ContentScaleAnimation ;
41
41
import com .longluo .ebookreader .widget .animation .Rotate3DAnimation ;
42
-
42
+ import com . longluo . ebookreader . widget . view . DragGridView ;
43
43
44
44
import org .litepal .LitePal ;
45
45
@@ -67,7 +67,7 @@ public class MainActivity extends BaseActivity
67
67
DrawerLayout drawer ;
68
68
69
69
@ BindView (R .id .bookShelf )
70
- DragGridView bookShelf ;
70
+ RecyclerView bookShelf ;
71
71
72
72
private WindowManager mWindowManager ;
73
73
private AbsoluteLayout wmRootView ;
@@ -119,6 +119,7 @@ protected void initData(Bundle savedInstanceState) {
119
119
rootView = getWindow ().getDecorView ();
120
120
typeface = readSettingManager .getTypeface ();
121
121
bookMetas = LitePal .findAll (BookMeta .class );
122
+
122
123
shelfAdapter = new ShelfAdapter (MainActivity .this , bookMetas );
123
124
bookShelf .setAdapter (shelfAdapter );
124
125
}
@@ -139,46 +140,14 @@ public void onClick(View view) {
139
140
toggle .syncState ();
140
141
141
142
navigationView .setNavigationItemSelectedListener (this );
142
-
143
- bookShelf .setOnItemClickListener (new AdapterView .OnItemClickListener () {
144
- @ Override
145
- public void onItemClick (AdapterView <?> parent , View view , int position , long id ) {
146
- if (bookMetas .size () > position ) {
147
- itemPosition = position ;
148
- String bookname = bookMetas .get (itemPosition ).getBookName ();
149
- shelfAdapter .setItemToFirst (itemPosition );
150
- final BookMeta bookMeta = bookMetas .get (itemPosition );
151
- bookMeta .setId (bookMetas .get (0 ).getId ());
152
- final String path = bookMeta .getBookPath ();
153
- File file = new File (path );
154
- if (!file .exists ()) {
155
- new AlertDialog .Builder (MainActivity .this )
156
- .setTitle (MainActivity .this .getString (R .string .app_name ))
157
- .setMessage (path + "文件不存在,是否删除该书本?" )
158
- .setPositiveButton (R .string .delete , new DialogInterface .OnClickListener () {
159
- @ Override
160
- public void onClick (DialogInterface dialog , int which ) {
161
- LitePal .deleteAll (BookMeta .class , "bookPath = ?" , path );
162
- bookMetas = LitePal .findAll (BookMeta .class );
163
- shelfAdapter .setBookList (bookMetas );
164
- }
165
- }).setCancelable (true ).show ();
166
- return ;
167
- }
168
-
169
- BookUtils .openBook (MainActivity .this , bookMeta );
170
- }
171
- }
172
- });
173
143
}
174
144
175
145
@ Override
176
146
protected void onRestart () {
177
147
super .onRestart ();
178
148
DragGridView .setIsShowDeleteButton (false );
179
149
bookMetas = LitePal .findAll (BookMeta .class );
180
- shelfAdapter .setBookList (bookMetas );
181
- closeBookAnimation ();
150
+ shelfAdapter .setBookLists (bookMetas );
182
151
}
183
152
184
153
@ Override
@@ -263,35 +232,6 @@ private void initAnimation() {
263
232
coverAnimation .setAnimationListener (this );
264
233
}
265
234
266
- public void closeBookAnimation () {
267
- if (mIsOpen && wmRootView != null ) {
268
- //因为书本打开后会移动到第一位置,所以要设置新的位置参数
269
- contentAnimation .setmPivotXValue (bookShelf .getFirstLocation ()[0 ]);
270
- contentAnimation .setmPivotYValue (bookShelf .getFirstLocation ()[1 ]);
271
- coverAnimation .setmPivotXValue (bookShelf .getFirstLocation ()[0 ]);
272
- coverAnimation .setmPivotYValue (bookShelf .getFirstLocation ()[1 ]);
273
-
274
- AbsoluteLayout .LayoutParams params = new AbsoluteLayout .LayoutParams (
275
- itemTextView .getLayoutParams ());
276
- params .x = bookShelf .getFirstLocation ()[0 ];
277
- params .y = bookShelf .getFirstLocation ()[1 ];//firstLocation[1]在滑动的时候回改变,所以要在dispatchDraw的时候获取该位置值
278
- wmRootView .updateViewLayout (cover , params );
279
- wmRootView .updateViewLayout (content , params );
280
- //动画逆向运行
281
- if (!contentAnimation .getMReverse ()) {
282
- contentAnimation .reverse ();
283
- }
284
- if (!coverAnimation .getMReverse ()) {
285
- coverAnimation .reverse ();
286
- }
287
- //清除动画再开始动画
288
- content .clearAnimation ();
289
- content .startAnimation (contentAnimation );
290
- cover .clearAnimation ();
291
- cover .startAnimation (coverAnimation );
292
- }
293
- }
294
-
295
235
@ Override
296
236
public void onAnimationStart (Animation animation ) {
297
237
@@ -304,7 +244,6 @@ public void onAnimationEnd(Animation animation) {
304
244
animationCount ++;
305
245
if (animationCount >= 2 ) {
306
246
mIsOpen = true ;
307
- shelfAdapter .setItemToFirst (itemPosition );
308
247
BookMeta bookMeta = bookMetas .get (itemPosition );
309
248
bookMeta .setId (bookMetas .get (0 ).getId ());
310
249
BookUtils .openBook (MainActivity .this , bookMeta );
0 commit comments