Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aa #676

Merged
merged 17 commits into from
Dec 30, 2024
Merged

aa #676

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
applicationId "ceui.lisa.pixiv"
minSdkVersion 21
targetSdkVersion 34
versionCode 324
versionName "4.2.2"
versionCode 328
versionName "4.2.4"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

javaCompileOptions {
Expand All @@ -42,8 +42,14 @@ android {
}

buildTypes {
debug {
minifyEnabled false
buildConfigField "boolean", "IS_DEBUG_MODE", "true" // 在 debug 模式下为 true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled false
buildConfigField "boolean", "IS_DEBUG_MODE", "false" // 在 release 模式下为 false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
Expand All @@ -65,6 +71,7 @@ android {
buildFeatures {
dataBinding true
viewBinding true
buildConfig = true // 启用 BuildConfig
}
packagingOptions {
resources {
Expand Down Expand Up @@ -95,7 +102,7 @@ dependencies {


//=============== Navigation
def nav_version = "2.8.4"
def nav_version = "2.8.5"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/ceui/lisa/activities/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.io.File;

import ceui.lisa.BuildConfig;
import ceui.lisa.R;
import ceui.lisa.core.Manager;
import ceui.lisa.databinding.ActivityCoverBinding;
Expand Down Expand Up @@ -80,7 +81,6 @@ public boolean hideStatusBar() {

@Override
protected void initView() {
Dev.isDev = false;
baseBind.drawerLayout.setScrimColor(Color.TRANSPARENT);
baseBind.navView.setNavigationItemSelectedListener(this);
userHead = baseBind.navView.getHeaderView(0).findViewById(R.id.user_head);
Expand Down Expand Up @@ -225,7 +225,7 @@ protected void initData() {
if (!SessionManager.INSTANCE.isLoggedIn()) {
SessionManager.INSTANCE.updateSession(sUserModel);
}
if (Dev.isDev) {
if (BuildConfig.IS_DEBUG_MODE) {
startActivity(new Intent(this, HomeActivity.class));
finish();
} else {
Expand Down
17 changes: 16 additions & 1 deletion app/src/main/java/ceui/lisa/activities/Shaft.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@
import ceui.lisa.viewmodel.AppLevelViewModel;
import ceui.loxia.ServicesProvider;
import ceui.pixiv.session.SessionManager;
import ceui.pixiv.utils.NetworkStateManager;
import me.jessyan.progressmanager.ProgressManager;
import okhttp3.OkHttpClient;
import timber.log.Timber;
import timber.log.Timber.DebugTree;

import static ceui.lisa.utils.Local.LOCAL_DATA;

import org.jetbrains.annotations.NotNull;

/**
* Where the app code starts.
* */
Expand All @@ -53,6 +57,7 @@ public class Shaft extends Application implements ServicesProvider {
public static Gson sGson;
public static SharedPreferences sPreferences;
protected NetWorkStateReceiver netWorkStateReceiver;
private NetworkStateManager networkStateManager;
private OkHttpClient mOkHttpClient;
private static MMKV mmkv;
public static AppLevelViewModel appViewModel;
Expand Down Expand Up @@ -97,7 +102,7 @@ public void onCreate() {
Timber.plant(new Timber.DebugTree());

MMKV.initialize(this);

networkStateManager = new NetworkStateManager(this);
sUserModel = Local.getUser();

sSettings = Local.getSettings();
Expand Down Expand Up @@ -232,4 +237,14 @@ public void onConfigurationChanged(@NonNull Configuration newConfig) {
break;
}
}

@Override
public @NotNull MMKV getPrefStore() {
return getMMKV();
}

@Override
public @NotNull NetworkStateManager getNetworkStateManager() {
return networkStateManager;
}
}
6 changes: 2 additions & 4 deletions app/src/main/java/ceui/lisa/core/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,8 @@ public File whichFile() {
}, throwable -> {
//下载失败,处理相关逻辑
throwable.printStackTrace();
if (!Dev.isDev) {
if (Shaft.sSettings.isToastDownloadResult()) {
Common.showToast("下载失败,原因:" + throwable.toString());
}
if (Shaft.sSettings.isToastDownloadResult()) {
Common.showToast("下载失败,原因:" + throwable.toString());
}
Common.showLog("下载失败,原因:" + throwable.toString());
complete(downloadItem, false);
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/ceui/lisa/fragments/FragmentAboutApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class FragmentAboutApp : SwipeFragment<FragmentAboutBinding>() {
}
}
baseBind.goQq.setOnClickListener {
val choices = arrayOf(getString(R.string.string_385), getString(R.string.string_386), getString(R.string.string_387), getString(R.string.string_411))
val choices = arrayOf(getString(R.string.string_385), getString(R.string.string_386), getString(R.string.string_387), getString(R.string.string_411), getString(R.string.qq_group_5), getString(R.string.qq_group_6))
MenuDialogBuilder(mActivity)
.addItems(choices) { dialog, which ->
val intent = Intent()
Expand All @@ -93,6 +93,16 @@ class FragmentAboutApp : SwipeFragment<FragmentAboutBinding>() {
"mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26jump_from%3Dwebapi%26k%3D" + "8WwEAkjbS4yOYMtNR17TS-Wghwv8xjNK"
)
}
4 -> {
intent.data = Uri.parse(
"mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26jump_from%3Dwebapi%26k%3D" + "sWRT0mSWFEiNlkPRtVwK8LmHGStPK9Op"
)
}
5 -> {
intent.data = Uri.parse(
"mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26jump_from%3Dwebapi%26k%3D" + "tBP0SrzxprYrVMadXxJq2KouWxDrcdle"
)
}
}
try {
startActivity(intent)
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/ceui/lisa/fragments/FragmentImageDetail.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import android.text.TextUtils
import android.view.View
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import ceui.lisa.R
import ceui.lisa.activities.Shaft
import ceui.lisa.databinding.FragmentImageDetailBinding
Expand Down Expand Up @@ -58,7 +59,7 @@ class FragmentImageDetail : BaseFragment<FragmentImageDetailBinding?>() {
}

if (imageUrl?.isNotEmpty() == true) {
val task = TaskPool.getLoadTask(NamedUrl("", imageUrl), requireActivity())
val task = TaskPool.getLoadTask(NamedUrl("", imageUrl), requireActivity().lifecycleScope)
task.result.observe(viewLifecycleOwner) { file ->
baseBind.image.loadImage(file)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import ceui.lisa.R;
import ceui.lisa.activities.BaseActivity;
import ceui.lisa.activities.SearchActivity;
Expand Down Expand Up @@ -447,11 +449,9 @@ private void setNovelAdapter() {
holderList.add(new TextDescHolder(getString(R.string.string_107)));
holderList.add(new SpaceHolder());
CommonAdapter commonAdapter = new CommonAdapter(getViewLifecycleOwner());
baseBind.viewPager.addItemDecoration(new LinearItemDecoration(DensityUtil.dp2px(16)));
baseBind.viewPager.setAdapter(commonAdapter);
commonAdapter.submitList(holderList);
} else {
baseBind.viewPager.addItemDecoration(new LinearItemDecoration(DensityUtil.dp2px(16)));
baseBind.viewPager.setAdapter(new VNewAdapter(novelDetail.getParsedChapters(), mContext));
}
if(novelDetail.getNovel_marker() != null){
Expand Down
16 changes: 7 additions & 9 deletions app/src/main/java/ceui/lisa/utils/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,13 @@ public static void hideKeyboard(Activity activity) {

public static void logOut(Context context, boolean deleteUser) {
if (Shaft.sUserModel != null) {
if (!Dev.isDev) { //测试状态,不要真的退出登录,只是跳转到登录页面
Shaft.sUserModel.getUser().setIs_login(false);
Local.saveUser(Shaft.sUserModel);
if(deleteUser){
UserEntity userEntity = new UserEntity();
userEntity.setUserID(Shaft.sUserModel.getUserId());
AppDatabase.getAppDatabase(context)
.downloadDao().deleteUser(userEntity);
}
Shaft.sUserModel.getUser().setIs_login(false);
Local.saveUser(Shaft.sUserModel);
if(deleteUser){
UserEntity userEntity = new UserEntity();
userEntity.setUserID(Shaft.sUserModel.getUserId());
AppDatabase.getAppDatabase(context)
.downloadDao().deleteUser(userEntity);
}
Intent intent = new Intent(context, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "登录注册");
Expand Down
9 changes: 0 additions & 9 deletions app/src/main/java/ceui/lisa/utils/Dev.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,10 @@

public class Dev {

//是否是开发状态
public static boolean isDev = false;
public static boolean refreshUser = false;

public static boolean hideMainActivityStatus = true;

/**
* 测试账号:哪位大佬,希望自己去注册账号,别改我密码,别改我密码,别改我密码
*
* 申请了N个测试账号了,好不容易造的数据,会被改密码,被改邮箱,然后登不上
*/
public static final String USER_ACCOUNT = "user_shaft2";
public static final String USER_PWD = "Mercis09bv";

public static boolean use_weiss = false;
public static boolean show_url_detail = false;
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/ceui/lisa/utils/Local.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import ceui.lisa.activities.Shaft;
import ceui.lisa.models.UserModel;
import timber.log.Timber;

/**
* A class deal with the {@link UserModel} and APP {@link Settings}
* */
Expand All @@ -25,10 +27,10 @@ public static void saveUser(UserModel userModel) {
}

public static UserModel getUser() {
return Shaft.sGson.fromJson(
Shaft.sPreferences
.getString(USER, ""),
UserModel.class);
String json = Shaft.sPreferences
.getString(USER, "");
Timber.d("getUserJson%s", json);
return Shaft.sGson.fromJson(json, UserModel.class);
}

public static Settings getSettings() {
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/ceui/lisa/view/LinearItemDecorationKt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ceui.lisa.view

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView

class LinearItemDecorationKt(private val space: Int, private val offset: Int) : RecyclerView.ItemDecoration() {

override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
val position = parent.getChildAdapterPosition(view) // 获取子项的适配器位置

// 清空所有偏移量
outRect.set(0, 0, 0, 0)

// 如果位置大于或等于 offset,才应用边距
if (position >= offset) {
outRect.left = space
outRect.right = space
outRect.bottom = space

// 只有在 offset 位置后的第一个 item 上添加顶部边距
if (position == offset) {
outRect.top = space
}
}
}
}
3 changes: 2 additions & 1 deletion app/src/main/java/ceui/loxia/HeaderInterceptor.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ceui.loxia

import ceui.lisa.activities.Shaft
import ceui.lisa.helper.LanguageHelper
import ceui.pixiv.session.SessionManager
import ceui.pixiv.ui.task.TaskPool
import okhttp3.Interceptor
Expand All @@ -20,7 +21,7 @@ class HeaderInterceptor : Interceptor {
private fun addHeader(before: Request.Builder): Request.Builder {
val requestNonce = RequestNonce.build()
before.addHeader(ClientManager.HEADER_AUTH, ClientManager.TOKEN_HEAD + SessionManager.getAccessToken())
.addHeader("accept-language", "zh-cn")
.addHeader("accept-language", LanguageHelper.getRequestHeaderAcceptLanguageFromAppLanguage())
.addHeader("app-os", "ios")
.addHeader("app-version", "7.13.4")
.addHeader("x-client-time", requestNonce.xClientTime)
Expand Down
42 changes: 42 additions & 0 deletions app/src/main/java/ceui/loxia/RefreshState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ceui.loxia

import android.content.Context
import androidx.core.view.isVisible
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.RecyclerView
import ceui.lisa.R
Expand Down Expand Up @@ -123,6 +124,47 @@ fun ItemLoadingBinding.setUpRefreshState(
}
}

fun ItemLoadingBinding.setUpHolderRefreshState(
refreshState: LiveData<RefreshState>,
viewLifecycleOwner: LifecycleOwner,
retryBlock: () -> Unit,
) {
val context = root.context
emptyActionButton.setOnClick {
retryBlock.invoke()
}
refreshState.observe(viewLifecycleOwner) { refreshState ->
if (refreshState is RefreshState.LOADED) {
progressCircular.hideProgress()
loadingFrame.isVisible = false

if (refreshState.hasContent) {
emptyFrame.isVisible = false
} else {
emptyFrame.isVisible = true
emptyActionButton.text = context.getString(R.string.refresh)
emptyTitle.text = context.getString(R.string.empty_content_here)
}
} else if (refreshState is RefreshState.LOADING) {
emptyFrame.isVisible = false
if (refreshState.refreshHint == RefreshHint.PullToRefresh) {
loadingFrame.isVisible = false
progressCircular.hideProgress()
} else if (refreshState.refreshHint == RefreshHint.InitialLoad) {
loadingFrame.isVisible = true
progressCircular.showProgress()
}
} else if (refreshState is RefreshState.ERROR) {
progressCircular.hideProgress()
loadingFrame.isVisible = false

emptyFrame.isVisible = true
emptyActionButton.text = context.getString(R.string.retry)
emptyTitle.text = refreshState.exception.getHumanReadableMessage(context)
}
}
}

fun Throwable.getHumanReadableMessage(context: Context): String {
return if (this is SSLHandshakeException || this is TimeoutException || this is SocketTimeoutException) {
"${context.getString(R.string.connection_error)}: ${this.javaClass.simpleName}"
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/ceui/loxia/ServiceProvider.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package ceui.loxia

import ceui.pixiv.utils.NetworkStateManager
import com.tencent.mmkv.MMKV

interface ServicesProvider {

interface ServicesProvider {
val prefStore: MMKV
val networkStateManager: NetworkStateManager
}
3 changes: 2 additions & 1 deletion app/src/main/java/ceui/loxia/WebHeaderInterceptor.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ceui.loxia

import ceui.lisa.helper.LanguageHelper
import ceui.lisa.utils.Common
import ceui.pixiv.session.SessionManager
import ceui.pixiv.ui.settings.SettingsFragment
Expand Down Expand Up @@ -31,7 +32,7 @@ class WebHeaderInterceptor : Interceptor {
// val end = cookies.substring(1, cookies.length - 1)
// val end2 = end.replace("first_visit_datetime", "first_visit_datetime_pc")
Common.showLog("dsaadsdsaaww2 get ${cookies}")
before.addHeader("accept-language", "zh-CN,zh;q=0.9")
before.addHeader("accept-language", LanguageHelper.getRequestHeaderAcceptLanguageFromAppLanguage())
.addHeader("Host", "www.pixiv.net")
// .addHeader("Cookie", "first_visit_datetime_pc=2023-08-29%2011%3A18%3A36; p_ab_id=3; p_ab_id_2=0; p_ab_d_id=488794011; yuid_b=KIUHKVQ; privacy_policy_notification=0; a_type=0; login_ever=yes; _gcl_au=1.1.1589565743.1706238528; _im_vid=01HSA975DT21AG0E8C4Z7KQNV6; device_token=88d8a17289eb672e1e5deaf9118e04d7; PHPSESSID=31660292_ByvXUOYCfHCUtF97MjBan4p2oHGdQti8; privacy_policy_agreement=6; _ga_MZ1NL4PHH0=GS1.1.1711599851.7.0.1711599853.0.0.0; c_type=30; b_type=1; __utmc=235335808; cf_clearance=xko7RmBNHP1sB8DwXdGQz37ziHLQPBfEU1Bto0FY8bw-1712458701-1.0.1.1-Q_zVD_Ogdb8EreKgus.FAXRl1YWF02L7hCgVM.dFVnH61U6QLt7mqLJf.ZL9ZoLvWApHjnIs.v.HIUpG5ROiSg; QSI_S_ZN_5hF4My7Ad6VNNAi=v:0:0; _gid=GA1.2.921747741.1712458705; FCNEC=%5B%5B%22AKsRol-lCQJAg59fClTyi9swNt7kbFKms5xxTNO6tB7_rQNEjO181niKSaw15LknvKPUZi0wzOiOQccrked7QnBJq8gBurHfFb_dA0NEw-HboJg_fnTDLUakXTu-neyS5-fdI0tkChtJ2-UWIxFpvIP0QYmKHk9M9w%3D%3D%22%5D%5D; __utmv=235335808.|2=login%20ever=yes=1^3=plan=normal=1^5=gender=male=1^6=user_id=31660292=1^9=p_ab_id=3=1^10=p_ab_id_2=0=1^11=lang=zh=1; __cf_bm=Xw2w0_5OAkqEzaqIB9upbW1fjOH4sGhPMmRPGuuaaoQ-1712468986-1.0.1.1-bMB8ZolgqD353nE5ToW.KjlovBcDfkH9ACQdhUkekutEADYdCrILSeDPMSgTcY0I.IIRxSXBKOn.tGrOB6PNBZbuX5Hfps_TcLODg7WmXuY; __utma=235335808.1777699323.1693275529.1712458700.1712468987.24; __utmz=235335808.1712468987.24.21.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided); __utmt=1; _gat_UA-1830249-3=1; __utmb=235335808.2.10.1712468987; _ga=GA1.1.1777699323.1693275529; _ga_75BBYNYN9J=GS1.1.1712468987.34.1.1712469002.0.0.0")
.addHeader("Cookie", cookies)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/ceui/pixiv/session/SessionManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ object SessionManager {

private const val USER_KEY = "LoggedInUserJsonKey"
const val COOKIE_KEY = "web-api-cookie"
const val CONTENT_LANGUAGE_KEY = "content-language"

private val _loggedInAccount = MutableLiveData<AccountResponse>()
private val gson = Gson()
Expand Down
Loading
Loading