Skip to content

Commit b2ae81a

Browse files
committed
1. fix the dragGridView Error.
2. Change DragGridView to RecyclerView.
1 parent 215b4a5 commit b2ae81a

File tree

10 files changed

+101
-335
lines changed

10 files changed

+101
-335
lines changed

app/src/main/java/com/longluo/ebookreader/ui/activity/BookMarkActivity.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,4 @@ private void setTabsValue() {
104104
protected void initListener() {
105105

106106
}
107-
108107
}

app/src/main/java/com/longluo/ebookreader/ui/activity/MainActivity.java

Lines changed: 6 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@
2626
import androidx.appcompat.widget.Toolbar;
2727
import androidx.core.view.GravityCompat;
2828
import androidx.drawerlayout.widget.DrawerLayout;
29+
import androidx.recyclerview.widget.RecyclerView;
2930

3031
import com.google.android.material.floatingactionbutton.FloatingActionButton;
3132
import com.google.android.material.navigation.NavigationView;
32-
import com.longluo.ebookreader.manager.ReadSettingManager;
3333
import com.longluo.ebookreader.R;
3434
import com.longluo.ebookreader.base.BaseActivity;
3535
import com.longluo.ebookreader.db.BookMeta;
36+
import com.longluo.ebookreader.manager.ReadSettingManager;
3637
import com.longluo.ebookreader.ui.adapter.ShelfAdapter;
3738
import com.longluo.ebookreader.util.BookUtils;
3839
import com.longluo.ebookreader.util.DisplayUtils;
39-
import com.longluo.ebookreader.widget.view.DragGridView;
4040
import com.longluo.ebookreader.widget.animation.ContentScaleAnimation;
4141
import com.longluo.ebookreader.widget.animation.Rotate3DAnimation;
42-
42+
import com.longluo.ebookreader.widget.view.DragGridView;
4343

4444
import org.litepal.LitePal;
4545

@@ -67,7 +67,7 @@ public class MainActivity extends BaseActivity
6767
DrawerLayout drawer;
6868

6969
@BindView(R.id.bookShelf)
70-
DragGridView bookShelf;
70+
RecyclerView bookShelf;
7171

7272
private WindowManager mWindowManager;
7373
private AbsoluteLayout wmRootView;
@@ -119,6 +119,7 @@ protected void initData(Bundle savedInstanceState) {
119119
rootView = getWindow().getDecorView();
120120
typeface = readSettingManager.getTypeface();
121121
bookMetas = LitePal.findAll(BookMeta.class);
122+
122123
shelfAdapter = new ShelfAdapter(MainActivity.this, bookMetas);
123124
bookShelf.setAdapter(shelfAdapter);
124125
}
@@ -139,46 +140,14 @@ public void onClick(View view) {
139140
toggle.syncState();
140141

141142
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-
});
173143
}
174144

175145
@Override
176146
protected void onRestart() {
177147
super.onRestart();
178148
DragGridView.setIsShowDeleteButton(false);
179149
bookMetas = LitePal.findAll(BookMeta.class);
180-
shelfAdapter.setBookList(bookMetas);
181-
closeBookAnimation();
150+
shelfAdapter.setBookLists(bookMetas);
182151
}
183152

184153
@Override
@@ -263,35 +232,6 @@ private void initAnimation() {
263232
coverAnimation.setAnimationListener(this);
264233
}
265234

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-
295235
@Override
296236
public void onAnimationStart(Animation animation) {
297237

@@ -304,7 +244,6 @@ public void onAnimationEnd(Animation animation) {
304244
animationCount++;
305245
if (animationCount >= 2) {
306246
mIsOpen = true;
307-
shelfAdapter.setItemToFirst(itemPosition);
308247
BookMeta bookMeta = bookMetas.get(itemPosition);
309248
bookMeta.setId(bookMetas.get(0).getId());
310249
BookUtils.openBook(MainActivity.this, bookMeta);

0 commit comments

Comments
 (0)