Skip to content

Commit

Permalink
manual load image
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbxyyx committed Oct 29, 2024
1 parent b39e489 commit a76f96e
Show file tree
Hide file tree
Showing 23 changed files with 423 additions and 304 deletions.
384 changes: 192 additions & 192 deletions app/src/main/java/com/github/jsbxyyx/xbook/DetailActivity.java

Large diffs are not rendered by default.

190 changes: 95 additions & 95 deletions app/src/main/java/com/github/jsbxyyx/xbook/LifecycleApplication.java
Original file line number Diff line number Diff line change
@@ -1,95 +1,95 @@
package com.github.jsbxyyx.xbook;

import android.app.Application;
import android.os.Looper;

import androidx.annotation.NonNull;

import com.github.jsbxyyx.xbook.common.Common;
import com.github.jsbxyyx.xbook.common.DataCallback;
import com.github.jsbxyyx.xbook.common.LogUtil;
import com.github.jsbxyyx.xbook.common.SPUtils;
import com.github.jsbxyyx.xbook.common.UiUtils;
import com.github.jsbxyyx.xbook.data.BookNetHelper;
import com.github.jsbxyyx.xbook.data.bean.MLog;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.CountDownLatch;

/**
* @author jsbxyyx
* @since 1.0
*/
public class LifecycleApplication extends Application {

private BookNetHelper bookNetHelper;

@Override
public void onCreate() {
super.onCreate();

UiUtils.initContext(getApplicationContext());

bookNetHelper = new BookNetHelper();

String languages = "chinese,japanese,traditional chinese,english,korean,";
String languagesData = SPUtils.getData(getBaseContext(), Common.search_language_key, null);
if (Common.isNull(languagesData)) {
SPUtils.putData(getBaseContext(), Common.search_language_key, languages);
}

String extData = SPUtils.getData(getBaseContext(), Common.search_ext_key, null);
if (Common.isNull(extData)) {
extData = "EPUB,";
SPUtils.putData(getBaseContext(), Common.search_ext_key, extData);
}

String syncData = SPUtils.getData(getBaseContext(), Common.sync_key, null);
if (Common.isNull(syncData)) {
syncData = Common.sync_key_checked;
SPUtils.putData(getBaseContext(), Common.sync_key, syncData);
}

Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(@NonNull Thread t, @NonNull Throwable e) {

MLog mLog = new MLog();
mLog.setTitle(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) + Common.log_suffix);
mLog.setRaw(("[OS : " + android.os.Build.MODEL + " | " + android.os.Build.VERSION.RELEASE + "]"
+ "[APP : " + UiUtils.getVersionName() + "]\n\n")
+ LogUtil.getStackTraceString(e));
CountDownLatch latch = new CountDownLatch(1);
bookNetHelper.cloudLog(mLog, new DataCallback() {
@Override
public void call(Object o, Throwable err) {
try {
if (err != null) {
LogUtil.e(getClass().getSimpleName(), "异常上报失败. %s", LogUtil.getStackTraceString(err));
} else {
new Thread(() -> {
Looper.prepare();
UiUtils.showToast("闪退异常上报成功");
Looper.loop();
}).start();
Thread.sleep(2000);
}
} catch (InterruptedException ignore) {
} finally {
latch.countDown();
}
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}
});
try {
latch.await();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
});

}
}
package com.github.jsbxyyx.xbook;

import android.app.Application;
import android.os.Looper;

import androidx.annotation.NonNull;

import com.github.jsbxyyx.xbook.common.Common;
import com.github.jsbxyyx.xbook.common.DataCallback;
import com.github.jsbxyyx.xbook.common.LogUtil;
import com.github.jsbxyyx.xbook.common.SPUtils;
import com.github.jsbxyyx.xbook.common.UiUtils;
import com.github.jsbxyyx.xbook.data.BookNetHelper;
import com.github.jsbxyyx.xbook.data.bean.MLog;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.CountDownLatch;

/**
* @author jsbxyyx
* @since 1.0
*/
public class LifecycleApplication extends Application {

private BookNetHelper bookNetHelper;

@Override
public void onCreate() {
super.onCreate();

UiUtils.initContext(getApplicationContext());

bookNetHelper = new BookNetHelper();

String languages = "chinese,japanese,traditional chinese,english,korean,";
String languagesData = SPUtils.getData(getBaseContext(), Common.search_language_key, null);
if (Common.isNull(languagesData)) {
SPUtils.putData(getBaseContext(), Common.search_language_key, languages);
}

String extData = SPUtils.getData(getBaseContext(), Common.search_ext_key, null);
if (Common.isNull(extData)) {
extData = "EPUB,";
SPUtils.putData(getBaseContext(), Common.search_ext_key, extData);
}

String syncData = SPUtils.getData(getBaseContext(), Common.sync_key, null);
if (Common.isNull(syncData)) {
syncData = Common.checked;
SPUtils.putData(getBaseContext(), Common.sync_key, syncData);
}

Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(@NonNull Thread t, @NonNull Throwable e) {

MLog mLog = new MLog();
mLog.setTitle(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) + Common.log_suffix);
mLog.setRaw(("[OS : " + android.os.Build.MODEL + " | " + android.os.Build.VERSION.RELEASE + "]"
+ "[APP : " + UiUtils.getVersionName() + "]\n\n")
+ LogUtil.getStackTraceString(e));
CountDownLatch latch = new CountDownLatch(1);
bookNetHelper.cloudLog(mLog, new DataCallback() {
@Override
public void call(Object o, Throwable err) {
try {
if (err != null) {
LogUtil.e(getClass().getSimpleName(), "异常上报失败. %s", LogUtil.getStackTraceString(err));
} else {
new Thread(() -> {
Looper.prepare();
UiUtils.showToast("闪退异常上报成功");
Looper.loop();
}).start();
Thread.sleep(2000);
}
} catch (InterruptedException ignore) {
} finally {
latch.countDown();
}
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}
});
try {
latch.await();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ public class ListBookDownloadAdapter extends BaseAdapter {
private Context context;
private ListItemClickListener listItemClickListener;
private List<Book> dataList;
private boolean imageShow;

private String TAG = "xbook";

public ListBookDownloadAdapter(Context context, List<Book> dataList,
public ListBookDownloadAdapter(Context context, List<Book> dataList, boolean imageShow,
ListItemClickListener listItemClickListener) {
this.context = context;
this.dataList = (dataList == null) ? new ArrayList<>() : dataList;
this.imageShow = imageShow;
this.listItemClickListener = listItemClickListener;
}

Expand All @@ -48,6 +50,7 @@ private static class ViewHolder {
public Button book_reader_btn_upload;
public Button book_reader_btn_download_meta;
public Button book_reader_btn_file_download;
public ImageView book_reader_image_hide;
}

@Override
Expand Down Expand Up @@ -79,6 +82,7 @@ public View getView(final int position, View convertView, ViewGroup parent) {
holder.book_reader_btn_upload = convertView.findViewById(R.id.book_reader_btn_upload);
holder.book_reader_btn_download_meta = convertView.findViewById(R.id.book_reader_btn_download_meta);
holder.book_reader_btn_file_download = convertView.findViewById(R.id.book_reader_btn_file_download);
holder.book_reader_image_hide = convertView.findViewById(R.id.book_reader_image_hide);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
Expand All @@ -88,6 +92,9 @@ public View getView(final int position, View convertView, ViewGroup parent) {

Picasso.get().load(book.getCoverImage()).into(holder.book_image);
holder.book_image.setScaleType(ImageView.ScaleType.FIT_CENTER);
if (!imageShow) {
holder.book_image.setVisibility(View.GONE);
}
holder.book_title.setText(book.getTitle());
holder.book_file.setText(book.getFile());
if (bookReader != null) {
Expand Down Expand Up @@ -149,6 +156,19 @@ public void onClick(View v) {
}
}
});

holder.book_reader_image_hide.setTag(position);
holder.book_reader_image_hide.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listItemClickListener != null) {
int position = (int) v.getTag();
LogUtil.d(TAG, "onClick image view hide : %d", position);
listItemClickListener.onClick(v, Common.action_image_hide, position);
}
}
});

return convertView;
}

Expand Down
17 changes: 15 additions & 2 deletions app/src/main/java/com/github/jsbxyyx/xbook/ProfileFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -39,6 +38,7 @@
import com.github.jsbxyyx.xbook.data.bean.Book;
import com.github.jsbxyyx.xbook.data.bean.BookReader;
import com.github.jsbxyyx.xbook.data.bean.Profile;
import com.squareup.picasso.Picasso;

import java.io.File;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -176,9 +176,12 @@ public void call(Profile profile, Throwable err) {
}
});

String readerImageShow = SPUtils.getData(mActivity, Common.reader_image_show_key, "1");

List<Book> dataList = bookDbHelper.findAllBook();
lv_download_book = mView.findViewById(R.id.lv_download_book);
mBookDownloadAdapter = new ListBookDownloadAdapter(mActivity, dataList, new ListItemClickListener() {
mBookDownloadAdapter = new ListBookDownloadAdapter(mActivity, dataList,
Common.checked.equals(readerImageShow), new ListItemClickListener() {
@Override
public void onClick(View view, String type, int position) {
if (Common.action_delete.equals(type)) {
Expand Down Expand Up @@ -273,6 +276,16 @@ public void onProgress(long bytesRead, long total) {
}
});
}
} else if (Common.action_image_hide.equals(type)) {
Book book = mBookDownloadAdapter.getDataList().get(position);
View parent = (View) view.getParent();
ImageView iv = parent.findViewById(R.id.book_reader_image);
if (iv.getVisibility() == View.GONE) {
Picasso.get().load(book.getCoverImage()).into(iv);
iv.setVisibility(View.VISIBLE);
} else {
iv.setVisibility(View.GONE);
}
}
}
});
Expand Down
24 changes: 21 additions & 3 deletions app/src/main/java/com/github/jsbxyyx/xbook/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class SettingsActivity extends AppCompatActivity {
Common.search_ext_key,
Common.search_language_key,
Common.sync_key,
Common.reader_image_show_key,
};

@Override
Expand Down Expand Up @@ -243,21 +244,38 @@ public void call(JsonNode jsonNode, Throwable err) {

String sync_data = SPUtils.getData(getBaseContext(), Common.sync_key);
CheckBox cb_sync = findViewById(R.id.cb_sync);
if (Common.sync_key_checked.equals(sync_data)) {
if (Common.checked.equals(sync_data)) {
cb_sync.setChecked(true);
} else {
cb_sync.setChecked(false);
}
cb_sync.setOnClickListener((v) -> {
CheckBox cb = (CheckBox) v;
if (cb.isChecked()) {
SPUtils.putData(getBaseContext(), Common.sync_key, Common.sync_key_checked);
SPUtils.putData(getBaseContext(), Common.sync_key, Common.checked);
} else {
SPUtils.putData(getBaseContext(), Common.sync_key, Common.sync_key_unchecked);
SPUtils.putData(getBaseContext(), Common.sync_key, Common.unchecked);
}
LogUtil.d(getClass().getSimpleName(), "sync checked : %s", cb.isChecked());
});

String reader_image_show_data = SPUtils.getData(getBaseContext(), Common.reader_image_show_key, Common.checked);
CheckBox cb_show_image = findViewById(R.id.cb_show_image);
if (Common.checked.equals(reader_image_show_data)) {
cb_show_image.setChecked(true);
} else {
cb_show_image.setChecked(false);
}
cb_show_image.setOnClickListener((v) -> {
CheckBox cb = (CheckBox) v;
if (cb.isChecked()) {
SPUtils.putData(getBaseContext(), Common.reader_image_show_key, Common.checked);
} else {
SPUtils.putData(getBaseContext(), Common.reader_image_show_key, Common.unchecked);
}
LogUtil.d(getClass().getSimpleName(), "reader image show checked : %s", cb.isChecked());
});

Button btn_clear_settings = findViewById(R.id.btn_clear_settings);
btn_clear_settings.setOnClickListener((v) -> {
for (String key : clearKeys) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ protected void onDestroy() {
}

String syncData = SPUtils.getData(getBaseContext(), Common.sync_key);
if (Common.sync_key_checked.equals(syncData)) {
if (Common.checked.equals(syncData)) {
Book book = bookDbHelper.findBookById(bookId);
if (book != null) {
bookNetHelper.cloudSyncMeta(book, new DataCallback<JsonNode>() {
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/github/jsbxyyx/xbook/common/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public class Common {
public static String search_ext_key = "search_ext";
public static String search_language_key = "search_language";
public static String sync_key = "sync";
public static String sync_key_checked = "1";
public static String sync_key_unchecked = "0";
public static String reader_image_show_key = "reader_image_show";
public static String checked = "1";
public static String unchecked = "0";

public static String log_suffix = ".exception";
public static String book_metadata_suffix = ".meta";
Expand All @@ -41,6 +42,7 @@ public class Common {
public static String action_upload = "upload";
public static String action_download_meta = "download_meta";
public static String action_file_download = "file_download";
public static String action_image_hide = "image_hide";

public static String x_message = "X-message";
public static String serv_userid = "remix_userid";
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/eye_foreground.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#000000">
<group android:scaleX="0.58"
android:scaleY="0.58"
android:translateX="5.04"
android:translateY="5.04">
<path
android:fillColor="@android:color/white"
android:pathData="M12,4.5C7,4.5 2.73,7.61 1,12c1.73,4.39 6,7.5 11,7.5s9.27,-3.11 11,-7.5c-1.73,-4.39 -6,-7.5 -11,-7.5zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5zM12,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3z"/>
</group>
</vector>
Loading

0 comments on commit a76f96e

Please sign in to comment.