Skip to content

Commit 3744cb6

Browse files
authored
Merge pull request #737 from LoxiaLiSA/master
aa
2 parents ae2e8cc + 44a27fc commit 3744cb6

109 files changed

Lines changed: 2416 additions & 584 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/build.gradle

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ android {
1313

1414
defaultConfig {
1515
applicationId "ceui.lisa.pixiv"
16-
minSdkVersion 21
16+
minSdkVersion 23
1717
targetSdkVersion 34
1818
versionCode 506
1919
versionName "5.0.6"
@@ -131,7 +131,7 @@ dependencies {
131131

132132
implementation 'com.github.lzyzsd:circleprogress:1.2.1'
133133

134-
def refresh_version = "2.1.0"
134+
def refresh_version = "3.0.0-alpha"
135135
implementation "io.github.scwang90:refresh-layout-kernel:$refresh_version" //核心必须依赖
136136
implementation "io.github.scwang90:refresh-header-classics:$refresh_version" //经典刷新头
137137
implementation "io.github.scwang90:refresh-header-falsify:$refresh_version" //虚拟刷新头
@@ -146,6 +146,8 @@ dependencies {
146146
implementation 'com.github.ybq:Android-SpinKit:1.4.0'
147147
implementation 'androidx.room:room-runtime:2.5.0'
148148
implementation "androidx.room:room-ktx:2.5.0"
149+
implementation "androidx.room:room-paging:2.5.0"
150+
149151
kapt 'androidx.room:room-compiler:2.5.0'
150152
implementation 'com.github.Justson.AgentWeb:agentweb-core:v4.1.9-androidx'
151153
implementation 'com.github.Justson.AgentWeb:agentweb-filechooser:v4.1.9-androidx'
@@ -195,15 +197,21 @@ dependencies {
195197
implementation project(path: ':progressmanager')
196198
implementation project(path: ':flowlayout-lib')
197199
implementation 'com.waynejo:androidndkgif:0.3.3'
198-
implementation 'com.tencent:mmkv-static:1.3.9'
200+
201+
implementation 'com.tencent:mmkv-static:2.2.2'
199202
implementation 'com.github.tbruyelle:RxPermissions:0.12'
200203

204+
201205
implementation 'androidx.webkit:webkit:1.12.1'
202206
implementation 'org.jsoup:jsoup:1.18.1'
203207

204208
implementation 'com.hjq:toast:8.8'
205209
implementation 'com.jakewharton.timber:timber:5.0.1'
206210

211+
212+
def paging_version = "3.3.6"
213+
implementation "androidx.paging:paging-runtime-ktx:$paging_version"
214+
207215
testImplementation 'junit:junit:4.13.2'
208216

209217
implementation 'com.github.yalantis:ucrop:2.2.10'

app/src/main/java/ceui/lisa/activities/Shaft.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import ceui.pixiv.db.EntityWrapper;
4141
import ceui.pixiv.session.SessionManager;
4242
import ceui.pixiv.ui.background.AppBackground;
43+
import ceui.pixiv.ui.task.TaskPool;
4344
import ceui.pixiv.utils.NetworkStateManager;
4445
import me.jessyan.progressmanager.ProgressManager;
4546
import okhttp3.OkHttpClient;
@@ -80,6 +81,7 @@ public class Shaft extends Application implements ServicesProvider {
8081
private OkHttpClient mOkHttpClient;
8182
private EntityWrapper entityWrapper;
8283
private AppBackground appBackground;
84+
private TaskPool taskPool;
8385

8486
public static Context getContext() {
8587
return sContext;
@@ -130,6 +132,7 @@ public void onCreate() {
130132

131133
networkStateManager = new NetworkStateManager(this);
132134
appBackground = new AppBackground();
135+
taskPool = new TaskPool();
133136
sUserModel = Local.getUser();
134137

135138
sSettings = Local.getSettings();
@@ -263,4 +266,9 @@ public void onConfigurationChanged(@NonNull Configuration newConfig) {
263266
public @NotNull AppBackground getAppBackground() {
264267
return appBackground;
265268
}
269+
270+
@Override
271+
public @NotNull TaskPool getTaskPool() {
272+
return taskPool;
273+
}
266274
}

app/src/main/java/ceui/lisa/database/AppDatabase.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
import androidx.room.Database;
77
import androidx.room.Room;
88
import androidx.room.RoomDatabase;
9-
109
import androidx.room.migration.Migration;
1110
import androidx.sqlite.db.SupportSQLiteDatabase;
11+
1212
import ceui.lisa.feature.FeatureEntity;
1313
import ceui.pixiv.db.GeneralDao;
1414
import ceui.pixiv.db.GeneralEntity;
15+
import ceui.pixiv.db.RemoteKey;
16+
import ceui.pixiv.db.RemoteKeyDao;
1517

1618
@Database(
1719
entities = {
@@ -26,30 +28,26 @@
2628
FeatureEntity.class, //记录用户收藏的精华列表
2729
DownloadingEntity.class, //记录用户正在下载中的列表
2830
GeneralEntity.class, // 新增的 GeneralEntity
31+
RemoteKey.class,
2932
},
30-
version = 26,
33+
version = 27,
3134
exportSchema = false
3235
)
3336
public abstract class AppDatabase extends RoomDatabase {
3437

3538
public static final String DATABASE_NAME = "roomDemo-database";
36-
37-
private static AppDatabase INSTANCE;
38-
3939
private static final Migration MIGRATION_23_24 = new Migration(23, 24) {
4040
@Override
4141
public void migrate(@NonNull SupportSQLiteDatabase database) {
4242
database.execSQL("ALTER TABLE feature_table ADD COLUMN seriesId INTEGER NOT NULL DEFAULT 0");
4343
}
4444
};
45-
4645
private static final Migration MIGRATION_24_25 = new Migration(24, 25) {
4746
@Override
4847
public void migrate(@NonNull SupportSQLiteDatabase database) {
4948
database.execSQL("ALTER TABLE search_table ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0");
5049
}
5150
};
52-
5351
// 迁移 25 -> 26 (创建 general_table)
5452
private static final Migration MIGRATION_25_26 = new Migration(25, 26) {
5553
@Override
@@ -66,7 +64,21 @@ public void migrate(@NonNull SupportSQLiteDatabase database) {
6664
);
6765
}
6866
};
67+
private static final Migration MIGRATION_26_27 = new Migration(26, 27) {
68+
@Override
69+
public void migrate(@NonNull SupportSQLiteDatabase database) {
70+
// 创建 remote_keys 表
71+
database.execSQL(
72+
"CREATE TABLE IF NOT EXISTS remote_keys (" +
73+
"recordType INTEGER NOT NULL PRIMARY KEY, " +
74+
"nextPageUrl TEXT" +
75+
")"
76+
);
77+
}
78+
};
79+
6980

81+
private static AppDatabase INSTANCE;
7082

7183
public static AppDatabase getAppDatabase(Context context) {
7284
if (INSTANCE == null) {
@@ -79,6 +91,7 @@ public static AppDatabase getAppDatabase(Context context) {
7991
.addMigrations(MIGRATION_23_24)
8092
.addMigrations(MIGRATION_24_25)
8193
.addMigrations(MIGRATION_25_26) // 注册 25 -> 26 迁移
94+
.addMigrations(MIGRATION_26_27)
8295
.build();
8396
}
8497
return INSTANCE;
@@ -96,5 +109,7 @@ public static void destroyInstance() {
96109

97110
public abstract GeneralDao generalDao();
98111

112+
public abstract RemoteKeyDao remoteKeyDao();
113+
99114
}
100115

app/src/main/java/ceui/lisa/fragments/FragmentIllust.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ class FragmentIllust : SwipeFragment<FragmentIllustBinding>() {
180180
}
181181

182182
override fun updateDrawState(ds: TextPaint) {
183-
ds.color = Common.resolveThemeAttribute(mContext, androidx.appcompat.R.attr.colorPrimary)
183+
ds.color = Common.resolveThemeAttribute(
184+
mContext,
185+
androidx.appcompat.R.attr.colorPrimary
186+
)
184187
}
185188
}
186189
val spannableString: SpannableString
@@ -286,7 +289,7 @@ class FragmentIllust : SwipeFragment<FragmentIllustBinding>() {
286289
val intent = Intent(mContext, TemplateActivity::class.java)
287290
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "举报插画")
288291
intent.putExtra(FlagDescFragment.FlagObjectIdKey, illust.id)
289-
intent.putExtra(FlagDescFragment.FlagObjectTypeKey, ObjectSpec.POST)
292+
intent.putExtra(FlagDescFragment.FlagObjectTypeKey, ObjectSpec.JAVA_ILLUST)
290293
startActivity(intent)
291294
return@OnMenuItemClickListener true
292295
}
@@ -374,8 +377,8 @@ class FragmentIllust : SwipeFragment<FragmentIllustBinding>() {
374377
baseBind.coreLinear.viewTreeObserver.addOnGlobalLayoutListener(object :
375378
OnGlobalLayoutListener {
376379
override fun onGlobalLayout() {
377-
val v = view ?: return
378-
val ctx = context ?: return
380+
view ?: return
381+
context ?: return
379382
val realHeight = baseBind.bottomBar.height +
380383
baseBind.viewDivider.height +
381384
baseBind.secondLinear.height

app/src/main/java/ceui/lisa/fragments/FragmentImageDetail.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import ceui.lisa.databinding.FragmentImageDetailBinding
1111
import ceui.lisa.download.IllustDownload
1212
import ceui.lisa.models.IllustsBean
1313
import ceui.lisa.utils.Params
14+
import ceui.loxia.requireTaskPool
1415
import ceui.pixiv.ui.common.setUpWithTaskStatus
1516
import ceui.pixiv.ui.task.NamedUrl
16-
import ceui.pixiv.ui.task.TaskPool
1717
import ceui.pixiv.ui.works.ToggleToolnarViewModel
1818
import ceui.pixiv.utils.setOnClick
1919
import com.github.panpf.sketch.loadImage
@@ -59,7 +59,10 @@ class FragmentImageDetail : BaseFragment<FragmentImageDetailBinding?>() {
5959
}
6060

6161
if (imageUrl?.isNotEmpty() == true) {
62-
val task = TaskPool.getLoadTask(NamedUrl("", imageUrl), requireActivity().lifecycleScope)
62+
val task = requireTaskPool().getLoadTask(
63+
NamedUrl("", imageUrl),
64+
requireActivity().lifecycleScope
65+
)
6366
task.result.observe(viewLifecycleOwner) { file ->
6467
baseBind.image.loadImage(file)
6568
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package ceui.lisa.view
2+
3+
import android.graphics.Rect
4+
import android.view.View
5+
import androidx.recyclerview.widget.RecyclerView
6+
import androidx.recyclerview.widget.StaggeredGridLayoutManager
7+
8+
class StaggeredGridSpacingItemDecoration(
9+
private val spacing: Int,
10+
) : RecyclerView.ItemDecoration() {
11+
12+
override fun getItemOffsets(
13+
outRect: Rect, view: View,
14+
parent: RecyclerView,
15+
state: RecyclerView.State
16+
) {
17+
val position = parent.getChildAdapterPosition(view)
18+
if (position == RecyclerView.NO_POSITION) return
19+
20+
val layoutParams = view.layoutParams as StaggeredGridLayoutManager.LayoutParams
21+
val spanIndex = layoutParams.spanIndex
22+
23+
// Top spacing for all items except the first row
24+
outRect.top = spacing
25+
26+
// Horizontal spacing based on column
27+
if (spanIndex == 0) {
28+
// Left column (A)
29+
outRect.left = spacing
30+
outRect.right = spacing / 2
31+
} else {
32+
// Right column (B)
33+
outRect.left = spacing / 2
34+
outRect.right = spacing
35+
}
36+
37+
// Bottom spacing can also be added if needed
38+
// outRect.bottom = spacing
39+
}
40+
}

app/src/main/java/ceui/loxia/FragmentUtils.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ import android.view.View
1010
import android.view.Window
1111
import android.view.inputmethod.InputMethodManager
1212
import android.widget.EditText
13+
import android.widget.Toast
1314
import androidx.core.content.FileProvider
1415
import androidx.fragment.app.DialogFragment
1516
import androidx.fragment.app.Fragment
1617
import com.blankj.utilcode.util.Utils
1718
import org.json.JSONArray
1819
import org.json.JSONException
1920
import org.json.JSONObject
21+
import timber.log.Timber
2022
import java.io.File
2123
import java.io.FileOutputStream
2224
import java.io.IOException
25+
import java.security.MessageDigest
2326

2427
fun Context.showKeyboard(editText: EditText?) {
2528
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
@@ -35,6 +38,28 @@ fun Context.hideKeyboard(window: Window?) {
3538
}
3639
}
3740

41+
42+
fun stableHash(input: String): Int {
43+
val digest = MessageDigest.getInstance("SHA-256")
44+
val hashBytes = digest.digest(input.toByteArray(Charsets.UTF_8))
45+
// 使用前两个字节生成 0 ~ 65535 的正整数,然后取模 10000
46+
val hashInt = ((hashBytes[0].toInt() and 0xFF) shl 8) or (hashBytes[1].toInt() and 0xFF)
47+
val ret = hashInt % 10000
48+
Timber.d("sadasdsw2 ${ret}")
49+
return ret
50+
}
51+
52+
53+
fun openClashApp(context: Context) {
54+
val packageName = "com.github.kr328.clash"
55+
val launchIntent = context.packageManager.getLaunchIntentForPackage(packageName)
56+
if (launchIntent != null) {
57+
context.startActivity(launchIntent)
58+
} else {
59+
Toast.makeText(context, "未安装 Clash", Toast.LENGTH_SHORT).show()
60+
}
61+
}
62+
3863
fun Fragment.showKeyboard(editText: EditText?) {
3964
context?.showKeyboard(editText)
4065
}

app/src/main/java/ceui/loxia/Models.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ data class Illust(
180180
override val objectUniqueId: Long
181181
get() = id
182182
override val objectType: Int
183-
get() = ObjectSpec.Illust
183+
get() = ObjectSpec.KOTLIN_ILLUST
184184

185185
fun displayCreateDate(): String {
186186
return DateParse.displayCreateDate(create_date)
@@ -272,7 +272,7 @@ data class User(
272272
override val objectUniqueId: Long
273273
get() = if (id > 0L) id else user_id
274274
override val objectType: Int
275-
get() = ObjectSpec.KUser
275+
get() = ObjectSpec.KOTLIN_USER
276276

277277
fun isOfficial(): Boolean {
278278
return ConstantUser.officialUsers.contains(id)
@@ -449,7 +449,12 @@ data class UserPreview(
449449
val is_muted: Boolean? = null,
450450
val novels: List<Any>? = null,
451451
val user: User? = null
452-
) : Serializable
452+
) : Serializable, ModelObject {
453+
override val objectUniqueId: Long
454+
get() = hashCode().toLong()
455+
override val objectType: Int
456+
get() = ObjectSpec.USER_PREVIEW
457+
}
453458

454459
data class UserPreviewResponse(
455460
val user_previews: List<UserPreview> = listOf(),
@@ -473,10 +478,15 @@ data class TrendingTag(
473478
val tag: String? = null,
474479
val translated_name: String? = null,
475480
val illust: Illust? = null,
476-
) : Serializable {
481+
) : Serializable, ModelObject {
477482
fun buildTag(): Tag {
478483
return Tag(name = tag, translated_name = translated_name)
479484
}
485+
486+
override val objectUniqueId: Long
487+
get() = illust?.id ?: 0L
488+
override val objectType: Int
489+
get() = ObjectSpec.TRENDING_TAG
480490
}
481491

482492
data class NotificationResponse(
@@ -741,7 +751,7 @@ data class Novel(
741751
override val objectUniqueId: Long
742752
get() = id
743753
override val objectType: Int
744-
get() = ObjectSpec.POST
754+
get() = ObjectSpec.KOTLIN_NOVEL
745755
}
746756

747757
data class Series(

0 commit comments

Comments
 (0)