From 61d35bba7bf1f54d48048c549f38763d1e9d4c76 Mon Sep 17 00:00:00 2001 From: longluo Date: Fri, 8 Jul 2022 18:31:33 +0800 Subject: [PATCH] fix the error --- app/src/main/AndroidManifest.xml | 6 - .../ui/activity/BookMarkActivity.java | 2 +- .../ebookreader/ui/activity/FileActivity.java | 9 +- .../ebookreader/ui/activity/MainActivity.java | 351 ------------------ ...helfAdapter.java => BookshelfAdapter.java} | 4 +- .../ui/fragment/BookshelfFragment.java | 26 +- .../ui/fragment/FileExplorerFragment.java | 2 +- .../main/res/layout/bookshelf_fragment.xml | 12 +- app/src/main/res/layout/layout_shelf_item.xml | 2 +- 9 files changed, 21 insertions(+), 393 deletions(-) delete mode 100644 app/src/main/java/com/longluo/ebookreader/ui/activity/MainActivity.java rename app/src/main/java/com/longluo/ebookreader/ui/adapter/{ShelfAdapter.java => BookshelfAdapter.java} (93%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 659710dd..2d27bdb8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -83,12 +83,6 @@ - - bookMetas; - private ShelfAdapter shelfAdapter; - - //点击书本的位置 - private int itemPosition; - private TextView itemTextView; - //点击书本在屏幕中的x,y坐标 - private int[] location = new int[2]; - - private static TextView cover; - private static ImageView content; - - //书本打开动画缩放比例 - private float scaleTimes; - //书本打开缩放动画 - private static ContentScaleAnimation contentAnimation; - private static Rotate3DAnimation coverAnimation; - //书本打开缩放动画持续时间 - public static final int ANIMATION_DURATION = 800; - //打开书本的第一个动画是否完成 - private boolean mIsOpen = false; - //动画加载计数器 0 默认 1一个动画执行完毕 2二个动画执行完毕 - private int animationCount = 0; - - private static Boolean isExit = false; - - private ReadSettingManager readSettingManager; - - @Override - public int getLayoutRes() { - return R.layout.activity_main; - } - - @Override - protected void initData(Bundle savedInstanceState) { - setSupportActionBar(toolbar); - - readSettingManager = ReadSettingManager.getInstance(); - // 删除窗口背景 - getWindow().setBackgroundDrawable(null); - mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); - wmRootView = new AbsoluteLayout(this); - rootView = getWindow().getDecorView(); - typeface = readSettingManager.getTypeface(); - bookMetas = LitePal.findAll(BookMeta.class); - - shelfAdapter = new ShelfAdapter(MainActivity.this, bookMetas); - bookShelf.setAdapter(shelfAdapter); - } - - @Override - protected void initListener() { - fab.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(MainActivity.this, FileChooserActivity.class); - MainActivity.this.startActivity(intent); - } - }); - - ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( - this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); - drawer.setDrawerListener(toggle); - toggle.syncState(); - - navigationView.setNavigationItemSelectedListener(this); - } - - @Override - protected void onRestart() { - super.onRestart(); - DragGridView.setIsShowDeleteButton(false); - bookMetas = LitePal.findAll(BookMeta.class); - shelfAdapter.setBookLists(bookMetas); - } - - @Override - protected void onResume() { - super.onResume(); - } - - @Override - protected void onStop() { - DragGridView.setIsShowDeleteButton(false); - super.onStop(); - } - - @Override - protected void onDestroy() { - DragGridView.setIsShowDeleteButton(false); - super.onDestroy(); - } - - @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) { - if (drawer.isDrawerOpen(Gravity.LEFT)) { - drawer.closeDrawers(); - } else { - exitBy2Click(); - } - return true; - } - - return super.onKeyDown(keyCode, event); - } - - /** - * 在2秒内按下返回键两次才退出 - */ - private void exitBy2Click() { - // press twice to exit - Timer tExit; - if (!isExit) { - isExit = true; // ready to exit - if (DragGridView.getShowDeleteButton()) { - DragGridView.setIsShowDeleteButton(false); - //要保证是同一个adapter对象,否则在Restart后无法notifyDataSetChanged - shelfAdapter.notifyDataSetChanged(); - } else { - Toast.makeText(this, this.getResources().getString(R.string.press_twice_to_exit), Toast.LENGTH_SHORT).show(); - } - tExit = new Timer(); - tExit.schedule(new TimerTask() { - @Override - public void run() { - isExit = false; // cancel exit - } - }, 2000); // 2 seconds cancel exit task - - } else { - finish(); - // call fragments and end streams and services - System.exit(0); - } - } - - //初始化dialog动画 - private void initAnimation() { - AccelerateInterpolator interpolator = new AccelerateInterpolator(); - - float scale1 = DisplayUtils.getScreenWidthPixels(this) / (float) itemTextView.getMeasuredWidth(); - float scale2 = DisplayUtils.getScreenHeightPixels(this) / (float) itemTextView.getMeasuredHeight(); - scaleTimes = scale1 > scale2 ? scale1 : scale2; //计算缩放比例 - - contentAnimation = new ContentScaleAnimation(location[0], location[1], scaleTimes, false); - contentAnimation.setInterpolator(interpolator); //设置插值器 - contentAnimation.setDuration(ANIMATION_DURATION); - contentAnimation.setFillAfter(true); //动画停留在最后一帧 - contentAnimation.setAnimationListener(this); - - coverAnimation = new Rotate3DAnimation(0, -180, location[0], location[1], scaleTimes, false); - coverAnimation.setInterpolator(interpolator); - coverAnimation.setDuration(ANIMATION_DURATION); - coverAnimation.setFillAfter(true); - coverAnimation.setAnimationListener(this); - } - - @Override - public void onAnimationStart(Animation animation) { - - } - - @Override - public void onAnimationEnd(Animation animation) { - //有两个动画监听会执行两次,所以要判断 - if (!mIsOpen) { - animationCount++; - if (animationCount >= 2) { - mIsOpen = true; - BookMeta bookMeta = bookMetas.get(itemPosition); - bookMeta.setId(bookMetas.get(0).getId()); - BookUtils.openBook(MainActivity.this, bookMeta); - } - - } else { - animationCount--; - if (animationCount <= 0) { - mIsOpen = false; - wmRootView.removeView(cover); - wmRootView.removeView(content); - mWindowManager.removeView(wmRootView); - } - } - } - - @Override - public void onAnimationRepeat(Animation animation) { - - } - - //获取dialog属性 - private WindowManager.LayoutParams getDefaultWindowParams() { - WindowManager.LayoutParams params = new WindowManager.LayoutParams( - WindowManager.LayoutParams.MATCH_PARENT, - WindowManager.LayoutParams.MATCH_PARENT, - 0, 0, - WindowManager.LayoutParams.TYPE_APPLICATION_PANEL,//windown类型,有层级的大的层级会覆盖在小的层级 - WindowManager.LayoutParams.FLAG_FULLSCREEN, - PixelFormat.RGBA_8888); - - return params; - } - - @Override - public void onBackPressed() { - DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); - if (drawer.isDrawerOpen(GravityCompat.START)) { - drawer.closeDrawer(GravityCompat.START); - } else { - super.onBackPressed(); - } - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.main, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); - if (id == R.id.action_select_file) { - Intent intent = new Intent(MainActivity.this, FileChooserActivity.class); - startActivity(intent); - } - - return super.onOptionsItemSelected(item); - } - - @SuppressWarnings("StatementWithEmptyBody") - @Override - public boolean onNavigationItemSelected(MenuItem item) { - // Handle navigation view item clicks here. - int id = item.getItemId(); - - if (id == R.id.nav_feedback) { -// FeedbackAgent agent = new FeedbackAgent(this); -// agent.startFeedbackActivity(); - } else if (id == R.id.nav_checkupdate) { - checkUpdate(true); - } else if (id == R.id.nav_about) { - Intent intent = new Intent(MainActivity.this, AboutActivity.class); - startActivity(intent); - } - return true; - } - - public void checkUpdate(final boolean showMessage) { - String url = "http://api.fir.im/apps/latest/57be8d56959d6960d5000327"; - } - - public static void showUpdateDialog(final String name, String version, String changelog, final String updateUrl, final Context context) { - String title = "发现新版" + name + ",版本号:" + version; - - new AlertDialog.Builder(context).setTitle(title) - .setMessage(changelog) - .setPositiveButton("下载", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - Uri uri = Uri.parse(updateUrl); //指定网址 - Intent intent = new Intent(); - intent.setAction(Intent.ACTION_VIEW); //指定Action - intent.setData(uri); //设置Uri - context.startActivity(intent); //启动Activity - } - }) - .show(); - } -} diff --git a/app/src/main/java/com/longluo/ebookreader/ui/adapter/ShelfAdapter.java b/app/src/main/java/com/longluo/ebookreader/ui/adapter/BookshelfAdapter.java similarity index 93% rename from app/src/main/java/com/longluo/ebookreader/ui/adapter/ShelfAdapter.java rename to app/src/main/java/com/longluo/ebookreader/ui/adapter/BookshelfAdapter.java index cc84dc82..22bb6041 100644 --- a/app/src/main/java/com/longluo/ebookreader/ui/adapter/ShelfAdapter.java +++ b/app/src/main/java/com/longluo/ebookreader/ui/adapter/BookshelfAdapter.java @@ -16,7 +16,7 @@ import java.util.List; -public class ShelfAdapter extends RecyclerView.Adapter { +public class BookshelfAdapter extends RecyclerView.Adapter { private Context mContext; private List mBookList; @@ -39,7 +39,7 @@ public void setOnItemLongClickListener(OnItemLongClickListener longClickListener this.longClickListener = longClickListener; } - public ShelfAdapter(Context context, List mBookList) { + public BookshelfAdapter(Context context, List mBookList) { this.mContext = context; this.mBookList = mBookList; } diff --git a/app/src/main/java/com/longluo/ebookreader/ui/fragment/BookshelfFragment.java b/app/src/main/java/com/longluo/ebookreader/ui/fragment/BookshelfFragment.java index 92601ce4..13a99d3e 100644 --- a/app/src/main/java/com/longluo/ebookreader/ui/fragment/BookshelfFragment.java +++ b/app/src/main/java/com/longluo/ebookreader/ui/fragment/BookshelfFragment.java @@ -2,22 +2,17 @@ import android.app.AlertDialog; import android.content.DialogInterface; -import android.view.View; -import android.widget.AdapterView; -import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.longluo.ebookreader.R; import com.longluo.ebookreader.app.TitleBarFragment; -import com.longluo.ebookreader.db.BookMark; import com.longluo.ebookreader.db.BookMeta; import com.longluo.ebookreader.ui.activity.HomeActivity; -import com.longluo.ebookreader.ui.adapter.BookMarkAdapter; -import com.longluo.ebookreader.ui.adapter.ShelfAdapter; +import com.longluo.ebookreader.ui.adapter.BookshelfAdapter; import com.longluo.ebookreader.util.BookUtils; import com.longluo.ebookreader.widget.itemdecoration.DividerItemDecoration; -import com.longluo.ebookreader.widget.view.DragGridView; import org.litepal.LitePal; @@ -29,13 +24,12 @@ public class BookshelfFragment extends TitleBarFragment { private RecyclerView mBookshelf; private List mBooks; - private ShelfAdapter mShelfAdapter; + + private BookshelfAdapter mBookshelfAdapter; //点击书本的位置 private int itemPosition; - private static Boolean isExit = false; - public static BookshelfFragment newInstance() { return new BookshelfFragment(); } @@ -55,18 +49,18 @@ protected void initView() { protected void initData() { mBooks = LitePal.findAll(BookMeta.class); - mShelfAdapter = new ShelfAdapter(getActivity(), mBooks); - mBookshelf.setLayoutManager(new LinearLayoutManager(getActivity())); - mBookshelf.setAdapter(mShelfAdapter); + mBookshelfAdapter = new BookshelfAdapter(getActivity(), mBooks); + mBookshelf.setLayoutManager(new GridLayoutManager(getActivity(), 3)); + mBookshelf.setAdapter(mBookshelfAdapter); mBookshelf.addItemDecoration(new DividerItemDecoration(getActivity())); - mShelfAdapter.notifyDataSetChanged(); + mBookshelfAdapter.notifyDataSetChanged(); initListener(); } private void initListener() { - mShelfAdapter.setOnItemClickListener(new ShelfAdapter.OnItemClickListener() { + mBookshelfAdapter.setOnItemClickListener(new BookshelfAdapter.OnItemClickListener() { @Override public void onClick(int position) { if (mBooks.size() > position) { @@ -95,7 +89,7 @@ public void onClick(DialogInterface dialog, int which) { } }); - mShelfAdapter.setOnItemLongClickListener(new ShelfAdapter.OnItemLongClickListener() { + mBookshelfAdapter.setOnItemLongClickListener(new BookshelfAdapter.OnItemLongClickListener() { @Override public void onClick(int position) { new AlertDialog.Builder(getActivity()) diff --git a/app/src/main/java/com/longluo/ebookreader/ui/fragment/FileExplorerFragment.java b/app/src/main/java/com/longluo/ebookreader/ui/fragment/FileExplorerFragment.java index 57262a63..51e12d70 100644 --- a/app/src/main/java/com/longluo/ebookreader/ui/fragment/FileExplorerFragment.java +++ b/app/src/main/java/com/longluo/ebookreader/ui/fragment/FileExplorerFragment.java @@ -70,7 +70,7 @@ public class FileExplorerFragment extends TitleBarFragment { private List bookMetas; private long sizeLimit = 1024 * 1024 * 1024; - private String[] chooseFileType = {".txt", ".epub", ".mobi", ".azw", ".azw3"}; + private String[] chooseFileType = {".txt", ".epub", ".mobi", ".azw", ".azw3", ".pdf"}; private class HistoryEntry { int scrollItem, scrollOffset; diff --git a/app/src/main/res/layout/bookshelf_fragment.xml b/app/src/main/res/layout/bookshelf_fragment.xml index b1872c06..43684fd0 100644 --- a/app/src/main/res/layout/bookshelf_fragment.xml +++ b/app/src/main/res/layout/bookshelf_fragment.xml @@ -17,16 +17,8 @@ + android:fadingEdge="none" /> \ No newline at end of file diff --git a/app/src/main/res/layout/layout_shelf_item.xml b/app/src/main/res/layout/layout_shelf_item.xml index d3dae281..0b894e25 100644 --- a/app/src/main/res/layout/layout_shelf_item.xml +++ b/app/src/main/res/layout/layout_shelf_item.xml @@ -1,7 +1,7 @@