From da0794a840bd43f695faadd6b0dd7b34a843e956 Mon Sep 17 00:00:00 2001 From: Fishballzzz Date: Mon, 16 Aug 2021 15:10:34 -0400 Subject: [PATCH 1/5] updates dependencies --- app/build.gradle | 45 ++++++++++++++++++++++----------------------- build.gradle | 14 ++++++-------- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ee029307..b0afa377 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -114,40 +114,38 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - implementation 'androidx.core:core-ktx:1.3.2' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21" + implementation 'androidx.core:core-ktx:1.6.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'com.tencent:mmkv-static:1.2.2' testImplementation 'junit:junit:4.13.1' - androidTestImplementation 'androidx.test.ext:junit:1.1.2' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' - implementation "androidx.recyclerview:recyclerview:1.2.0" - implementation "androidx.activity:activity-ktx:1.3.0-alpha07" - implementation "androidx.fragment:fragment-ktx:1.3.3" + implementation "androidx.recyclerview:recyclerview:1.2.1" + implementation "androidx.activity:activity-ktx:1.3.1" + implementation "androidx.fragment:fragment-ktx:1.3.6" - def lifecycle_version = "2.3.1" - implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" - implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version" - implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version" - implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version" + implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1" + implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1" + implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.1" + implementation "androidx.lifecycle:lifecycle-common-java8:2.3.1" - implementation 'com.google.android.material:material:1.4.0-alpha02' + implementation 'com.google.android.material:material:1.5.0-alpha02' - def appcompat_version = "1.3.0-rc01" - implementation "androidx.appcompat:appcompat:$appcompat_version" + implementation "androidx.appcompat:appcompat:1.4.0-alpha03" - implementation "androidx.constraintlayout:constraintlayout:2.0.4" + implementation "androidx.constraintlayout:constraintlayout:2.1.0" implementation 'com.jakewharton.timber:timber:4.7.1' implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.okhttp3:okhttp:4.9.0' - implementation 'com.squareup.moshi:moshi-kotlin:1.11.0' - kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.11.0' + implementation 'com.squareup.moshi:moshi-kotlin:1.12.0' + kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.12.0' implementation 'me.jessyan:retrofit-url-manager:1.4.0' implementation 'me.jessyan:progressmanager:1.5.0' @@ -156,7 +154,7 @@ dependencies { implementation 'org.apache.commons:commons-text:1.9' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.6' - implementation 'com.github.li-xiaojun:XPopup:2.2.24' + implementation 'com.github.li-xiaojun:XPopup:2.5.8' // implementation project(path: ':XPopup') //##localized @ 2.1.7 def material_dialog_version = "3.3.0" implementation "com.afollestad.material-dialogs:core:$material_dialog_version" @@ -179,7 +177,7 @@ dependencies { implementation 'com.github.chrisbanes:PhotoView:2.3.0' - implementation 'com.github.bumptech.glide:glide:4.11.0' + implementation 'com.github.bumptech.glide:glide:4.12.0' kapt 'com.github.bumptech.glide:compiler:4.11.0' implementation 'com.github.bumptech.glide:okhttp3-integration:4.11.0' @@ -191,12 +189,12 @@ dependencies { kapt "androidx.room:room-compiler:$room_version" implementation "androidx.room:room-ktx:$room_version" - def nav_version = "2.3.5" + def nav_version = "2.4.0-alpha06" // Kotlin navigation implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" implementation "androidx.navigation:navigation-ui-ktx:$nav_version" - def dagger_version = '2.30.1' + def dagger_version = '2.38.1' implementation "com.google.dagger:dagger:$dagger_version" kapt "com.google.dagger:dagger-compiler:$dagger_version" // implementation "com.google.dagger:dagger-android:$dagger_version" @@ -207,7 +205,8 @@ dependencies { implementation platform('com.google.firebase:firebase-bom:26.3.0') implementation 'com.google.firebase:firebase-analytics-ktx' implementation 'com.google.firebase:firebase-crashlytics-ktx' - implementation 'com.google.firebase:firebase-inappmessaging-display-ktx' +// due to https://github.com/firebase/firebase-android-sdk/issues/2642 +// implementation 'com.google.firebase:firebase-inappmessaging-display-ktx' implementation 'com.google.firebase:firebase-config-ktx' implementation 'com.google.firebase:firebase-perf-ktx' diff --git a/build.gradle b/build.gradle index 0a60aec9..616ea9a7 100644 --- a/build.gradle +++ b/build.gradle @@ -18,19 +18,17 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.4.32' repositories { google() jcenter() } dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath 'com.android.tools.build:gradle:7.0.0-alpha15' - def nav_version = "2.3.0-alpha04" - classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version" - classpath 'com.google.gms:google-services:4.3.5' - classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.2' - classpath 'com.google.firebase:perf-plugin:1.3.5' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21" + classpath 'com.android.tools.build:gradle:7.0.0' + classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.4.0-alpha06" + classpath 'com.google.gms:google-services:4.3.10' + classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1' + classpath 'com.google.firebase:perf-plugin:1.4.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } From b3221b8232e07f0565efb67209ed08be245b9443 Mon Sep 17 00:00:00 2001 From: Fishballzzz Date: Sat, 21 Aug 2021 01:32:17 -0400 Subject: [PATCH 2/5] updates dependencies supports BT in db DAOs, Entities, in Views and VMs: Posts, Comments, Feeds, Trends, Histories, needs tests on everything including cache clearing --- app/build.gradle | 6 +- .../24.json | 922 ++++++++++++++++++ .../java/com/laotoua/dawnislandk/DawnApp.kt | 29 + .../data/local/ApplicationDataStore.kt | 4 +- .../dawnislandk/data/local/DawnDatabase.kt | 21 +- .../data/local/dao/BlockedIdDao.kt | 11 +- .../data/local/dao/BrowsingHistoryDao.kt | 22 +- .../dawnislandk/data/local/dao/CommentDao.kt | 25 +- .../data/local/dao/CommunityDao.kt | 9 +- .../dawnislandk/data/local/dao/CookieDao.kt | 9 +- .../dawnislandk/data/local/dao/FeedDao.kt | 33 +- .../data/local/dao/NotificationDao.kt | 25 +- .../dawnislandk/data/local/dao/PostDao.kt | 15 +- .../data/local/dao/PostHistoryDao.kt | 13 +- .../data/local/dao/ReadingPageDao.kt | 7 +- .../data/local/entity/BlockedId.kt | 8 +- .../data/local/entity/BrowsingHistory.kt | 4 +- .../dawnislandk/data/local/entity/Comment.kt | 2 + .../data/local/entity/Community.kt | 15 +- .../dawnislandk/data/local/entity/Cookie.kt | 4 +- .../dawnislandk/data/local/entity/Feed.kt | 6 +- .../data/local/entity/NoticeForum.kt | 6 +- .../data/local/entity/Notification.kt | 6 +- .../dawnislandk/data/local/entity/Post.kt | 11 +- .../data/local/entity/PostHistory.kt | 5 +- .../data/local/entity/ReadingPage.kt | 2 + .../dawnislandk/data/remote/NMBService.kt | 22 +- .../data/repository/CommentRepository.kt | 6 +- .../data/repository/FeedRepository.kt | 6 +- .../data/repository/QuoteRepository.kt | 5 + .../data/repository/TrendRepository.kt | 2 +- .../dawnislandk/di/NMBNetworkModule.kt | 2 +- .../dawnislandk/screens/MainActivity.kt | 68 +- .../dawnislandk/screens/SharedViewModel.kt | 57 +- .../adapters/BaseViewHolderConversions.kt | 3 +- .../screens/adapters/CommunityNodeAdapter.kt | 6 +- .../screens/comments/CommentsFragment.kt | 12 +- .../screens/comments/CommentsViewModel.kt | 8 +- .../screens/comments/QuotePopup.kt | 3 +- .../history/BrowsingHistoryFragment.kt | 11 + .../screens/history/PostHistoryFragment.kt | 10 + .../notification/NotificationFragment.kt | 21 +- .../notification/NotificationViewModel.kt | 11 +- .../screens/posts/PostsFragment.kt | 27 +- .../screens/posts/PostsViewModel.kt | 45 +- .../screens/profile/CommonForumsFragment.kt | 3 +- .../screens/profile/CommonPostsFragment.kt | 3 +- .../screens/subscriptions/FeedsFragment.kt | 13 + .../screens/subscriptions/FeedsViewModel.kt | 7 +- .../screens/subscriptions/TrendsFragment.kt | 18 +- .../screens/widgets/BasePagerFragment.kt | 3 +- .../widgets/popups/ForumDrawerPopup.kt | 21 + .../widgets/popups/ImageViewerPopup.kt | 4 +- .../screens/widgets/popups/PostPopup.kt | 29 +- .../laotoua/dawnislandk/util/DawnConstants.kt | 11 +- app/src/main/res/drawable/bi_21.webp | Bin 0 -> 2070 bytes app/src/main/res/drawable/bi_7.webp | Bin 0 -> 2136 bytes app/src/main/res/layout/drawer_forum.xml | 13 +- app/src/main/res/values/strings.xml | 3 +- build.gradle | 2 +- 60 files changed, 1458 insertions(+), 217 deletions(-) create mode 100644 app/schemas/com.laotoua.dawnislandk.data.local.DawnDatabase/24.json create mode 100644 app/src/main/res/drawable/bi_21.webp create mode 100644 app/src/main/res/drawable/bi_7.webp diff --git a/app/build.gradle b/app/build.gradle index b0afa377..39d5d415 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -154,7 +154,7 @@ dependencies { implementation 'org.apache.commons:commons-text:1.9' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.6' - implementation 'com.github.li-xiaojun:XPopup:2.5.8' + implementation 'com.github.li-xiaojun:XPopup:2.2.24' // implementation project(path: ':XPopup') //##localized @ 2.1.7 def material_dialog_version = "3.3.0" implementation "com.afollestad.material-dialogs:core:$material_dialog_version" @@ -178,8 +178,8 @@ dependencies { implementation 'com.github.chrisbanes:PhotoView:2.3.0' implementation 'com.github.bumptech.glide:glide:4.12.0' - kapt 'com.github.bumptech.glide:compiler:4.11.0' - implementation 'com.github.bumptech.glide:okhttp3-integration:4.11.0' + kapt 'com.github.bumptech.glide:compiler:4.12.0' + implementation 'com.github.bumptech.glide:okhttp3-integration:4.12.0' implementation 'id.zelory:compressor:3.0.0' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19' diff --git a/app/schemas/com.laotoua.dawnislandk.data.local.DawnDatabase/24.json b/app/schemas/com.laotoua.dawnislandk.data.local.DawnDatabase/24.json new file mode 100644 index 00000000..e504b9c0 --- /dev/null +++ b/app/schemas/com.laotoua.dawnislandk.data.local.DawnDatabase/24.json @@ -0,0 +1,922 @@ +{ + "formatVersion": 1, + "database": { + "version": 24, + "identityHash": "482f29dd7b4306068a37ef171b09d40a", + "entities": [ + { + "tableName": "Community", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `sort` TEXT NOT NULL, `name` TEXT NOT NULL, `status` TEXT NOT NULL, `forums` TEXT NOT NULL, `domain` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "sort", + "columnName": "sort", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "status", + "columnName": "status", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "forums", + "columnName": "forums", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "domain", + "columnName": "domain", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "Timeline", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `display_name` TEXT NOT NULL, `notice` TEXT NOT NULL, `max_page` INTEGER NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "display_name", + "columnName": "display_name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "notice", + "columnName": "notice", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "max_page", + "columnName": "max_page", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "Cookie", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`cookieHash` TEXT NOT NULL, `cookieName` TEXT NOT NULL, `cookieDisplayName` TEXT NOT NULL, `lastUsedAt` TEXT NOT NULL, `domain` TEXT NOT NULL, PRIMARY KEY(`cookieHash`))", + "fields": [ + { + "fieldPath": "cookieHash", + "columnName": "cookieHash", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "cookieName", + "columnName": "cookieName", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "cookieDisplayName", + "columnName": "cookieDisplayName", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "lastUsedAt", + "columnName": "lastUsedAt", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "domain", + "columnName": "domain", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "cookieHash" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "Comment", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `userid` TEXT NOT NULL, `name` TEXT NOT NULL, `sage` TEXT NOT NULL, `admin` TEXT NOT NULL, `status` TEXT NOT NULL, `title` TEXT NOT NULL, `email` TEXT NOT NULL, `now` TEXT NOT NULL, `content` TEXT NOT NULL, `img` TEXT NOT NULL, `ext` TEXT NOT NULL, `page` INTEGER NOT NULL, `parentId` TEXT NOT NULL, `domain` TEXT NOT NULL, `lastUpdatedAt` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "userid", + "columnName": "userid", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "sage", + "columnName": "sage", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "admin", + "columnName": "admin", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "status", + "columnName": "status", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "email", + "columnName": "email", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "now", + "columnName": "now", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "content", + "columnName": "content", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "img", + "columnName": "img", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "ext", + "columnName": "ext", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "page", + "columnName": "page", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "parentId", + "columnName": "parentId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "domain", + "columnName": "domain", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "lastUpdatedAt", + "columnName": "lastUpdatedAt", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "Post", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `fid` TEXT NOT NULL, `img` TEXT NOT NULL, `ext` TEXT NOT NULL, `now` TEXT NOT NULL, `userid` TEXT NOT NULL, `name` TEXT NOT NULL, `email` TEXT NOT NULL, `title` TEXT NOT NULL, `content` TEXT NOT NULL, `sage` TEXT NOT NULL, `admin` TEXT NOT NULL, `status` TEXT NOT NULL, `replyCount` TEXT NOT NULL, `domain` TEXT NOT NULL, `lastUpdatedAt` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "fid", + "columnName": "fid", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "img", + "columnName": "img", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "ext", + "columnName": "ext", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "now", + "columnName": "now", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "userid", + "columnName": "userid", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "email", + "columnName": "email", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "content", + "columnName": "content", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "sage", + "columnName": "sage", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "admin", + "columnName": "admin", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "status", + "columnName": "status", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "replyCount", + "columnName": "replyCount", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "domain", + "columnName": "domain", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "lastUpdatedAt", + "columnName": "lastUpdatedAt", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "DailyTrend", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`postId` TEXT NOT NULL, `po` TEXT NOT NULL, `date` TEXT NOT NULL, `trends` TEXT NOT NULL, `lastReplyCount` INTEGER NOT NULL, PRIMARY KEY(`date`))", + "fields": [ + { + "fieldPath": "postId", + "columnName": "postId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "po", + "columnName": "po", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "date", + "columnName": "date", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "trends", + "columnName": "trends", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "lastReplyCount", + "columnName": "lastReplyCount", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "date" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "NMBNotice", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `content` TEXT NOT NULL, `date` INTEGER NOT NULL, `enable` INTEGER NOT NULL, `read` INTEGER NOT NULL, `lastUpdatedAt` TEXT NOT NULL)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "content", + "columnName": "content", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "date", + "columnName": "date", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "enable", + "columnName": "enable", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "read", + "columnName": "read", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "lastUpdatedAt", + "columnName": "lastUpdatedAt", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "LuweiNotice", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `appVersion` TEXT NOT NULL, `beitaiForums` TEXT NOT NULL, `nmbForums` TEXT NOT NULL, `loadingMsgs` TEXT NOT NULL, `clientsInfo` TEXT NOT NULL, `whitelist` TEXT NOT NULL, `lastUpdatedAt` TEXT NOT NULL)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "appVersion", + "columnName": "appVersion", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "beitaiForums", + "columnName": "beitaiForums", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "nmbForums", + "columnName": "nmbForums", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "loadingMsgs", + "columnName": "loadingMsgs", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "clientsInfo", + "columnName": "clientsInfo", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "whitelist", + "columnName": "whitelist", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "lastUpdatedAt", + "columnName": "lastUpdatedAt", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "Release", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `version` TEXT NOT NULL, `downloadUrl` TEXT NOT NULL, `message` TEXT NOT NULL, `lastUpdatedAt` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "version", + "columnName": "version", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "downloadUrl", + "columnName": "downloadUrl", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "message", + "columnName": "message", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "lastUpdatedAt", + "columnName": "lastUpdatedAt", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "ReadingPage", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `page` INTEGER NOT NULL, `domain` TEXT NOT NULL, `lastUpdatedAt` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "page", + "columnName": "page", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "domain", + "columnName": "domain", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "lastUpdatedAt", + "columnName": "lastUpdatedAt", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "BrowsingHistory", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`browsedDateTime` TEXT NOT NULL, `postId` TEXT NOT NULL, `postFid` TEXT NOT NULL, `pages` TEXT NOT NULL, `domain` TEXT NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)", + "fields": [ + { + "fieldPath": "browsedDateTime", + "columnName": "browsedDateTime", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "postId", + "columnName": "postId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "postFid", + "columnName": "postFid", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "pages", + "columnName": "pages", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "domain", + "columnName": "domain", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "PostHistory", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `newPost` INTEGER NOT NULL, `postTargetId` TEXT NOT NULL, `postTargetFid` TEXT NOT NULL, `postTargetPage` INTEGER NOT NULL, `cookieName` TEXT NOT NULL, `content` TEXT NOT NULL, `img` TEXT NOT NULL, `ext` TEXT NOT NULL, `domain` TEXT NOT NULL, `postDateTime` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "newPost", + "columnName": "newPost", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "postTargetId", + "columnName": "postTargetId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "postTargetFid", + "columnName": "postTargetFid", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "postTargetPage", + "columnName": "postTargetPage", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "cookieName", + "columnName": "cookieName", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "content", + "columnName": "content", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "img", + "columnName": "img", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "ext", + "columnName": "ext", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "domain", + "columnName": "domain", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "postDateTime", + "columnName": "postDateTime", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "Feed", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `page` INTEGER NOT NULL, `postId` TEXT NOT NULL, `category` TEXT NOT NULL, `domain` TEXT NOT NULL, `lastUpdatedAt` TEXT NOT NULL, PRIMARY KEY(`postId`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "page", + "columnName": "page", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "postId", + "columnName": "postId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "category", + "columnName": "category", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "domain", + "columnName": "domain", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "lastUpdatedAt", + "columnName": "lastUpdatedAt", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "postId" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "BlockedId", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `type` INTEGER NOT NULL, `domain` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "type", + "columnName": "type", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "domain", + "columnName": "domain", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "Notification", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `fid` TEXT NOT NULL, `newReplyCount` INTEGER NOT NULL, `message` TEXT NOT NULL, `read` INTEGER NOT NULL, `domain` TEXT NOT NULL, `lastUpdatedAt` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "fid", + "columnName": "fid", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "newReplyCount", + "columnName": "newReplyCount", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "message", + "columnName": "message", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "read", + "columnName": "read", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "domain", + "columnName": "domain", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "lastUpdatedAt", + "columnName": "lastUpdatedAt", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "Emoji", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `value` TEXT NOT NULL, `userDefined` INTEGER NOT NULL, `lastUsedAt` TEXT NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)", + "fields": [ + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "value", + "columnName": "value", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "userDefined", + "columnName": "userDefined", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "lastUsedAt", + "columnName": "lastUsedAt", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + } + ], + "views": [], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '482f29dd7b4306068a37ef171b09d40a')" + ] + } +} \ No newline at end of file diff --git a/app/src/main/java/com/laotoua/dawnislandk/DawnApp.kt b/app/src/main/java/com/laotoua/dawnislandk/DawnApp.kt index 4af81e04..b23dc8fc 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/DawnApp.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/DawnApp.kt @@ -21,6 +21,7 @@ import androidx.appcompat.app.AppCompatDelegate import com.google.firebase.crashlytics.FirebaseCrashlytics import com.laotoua.dawnislandk.data.local.ApplicationDataStore import com.laotoua.dawnislandk.di.DaggerDawnAppComponent +import com.laotoua.dawnislandk.util.DawnConstants import com.laotoua.dawnislandk.util.ReadableTime import com.tencent.mmkv.MMKV import com.tencent.mmkv.MMKVHandler @@ -36,6 +37,32 @@ class DawnApp : DaggerApplication() { companion object { lateinit var applicationDataStore: ApplicationDataStore + var currentDomain: String = DawnConstants.ADNMBDomain + private set + + fun onDomain(domain: String) { + currentDomain = domain + } + + val currentThumbCDN: String + get() = + when (currentDomain) { + DawnConstants.ADNMBDomain -> "${DawnConstants.ADNMB_IMG_CDN}thumb/" + DawnConstants.TNMBDomain -> "${DawnConstants.TNMB_IMG_CDN}thumb/" + else -> { + throw Exception("Unhandled Thumb CDN $currentDomain") + } + } + + val currentImgCDN: String + get() = + when (currentDomain) { + DawnConstants.ADNMBDomain -> "${DawnConstants.ADNMB_IMG_CDN}image/" + DawnConstants.TNMBDomain -> "${DawnConstants.TNMB_IMG_CDN}image/" + else -> { + throw Exception("Unhandled Image CDN $currentDomain") + } + } } override fun applicationInjector(): AndroidInjector { @@ -57,6 +84,8 @@ class DawnApp : DaggerApplication() { applicationDataStore = mApplicationDataStore + // domain + // MMKV MMKV.initialize(this) MMKV.registerHandler(handler) diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/ApplicationDataStore.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/ApplicationDataStore.kt index 35e15b22..920c9479 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/ApplicationDataStore.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/ApplicationDataStore.kt @@ -91,7 +91,7 @@ class ApplicationDataStore @Inject constructor( fun setBaseCDN(newHost: String) { baseCDN = newHost mmkv.putString(DawnConstants.DEFAULT_CDN, newHost) - if (newHost != "auto") RetrofitUrlManager.getInstance().putDomain("adnmb", baseCDN) + if (newHost != "auto") RetrofitUrlManager.getInstance().putDomain("nmb", baseCDN) } private var refCDN: String? = null @@ -105,7 +105,7 @@ class ApplicationDataStore @Inject constructor( fun setRefCDN(newHost: String) { refCDN = newHost mmkv.putString(DawnConstants.REF_CDN, newHost) - if (newHost != "auto") RetrofitUrlManager.getInstance().putDomain("adnmb-ref", refCDN) + if (newHost != "auto") RetrofitUrlManager.getInstance().putDomain("nmb-ref", refCDN) } private var feedId: String? = null diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/DawnDatabase.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/DawnDatabase.kt index 03354234..fa37c568 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/DawnDatabase.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/DawnDatabase.kt @@ -48,7 +48,7 @@ import com.laotoua.dawnislandk.data.local.entity.* BlockedId::class, Notification::class, Emoji::class], - version = 23 + version = 24 ) @TypeConverters(Converter::class) abstract class DawnDatabase : RoomDatabase() { @@ -357,6 +357,22 @@ abstract class DawnDatabase : RoomDatabase() { } } + // add domain flags + val migrate23To24 = object : Migration(23, 24) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE `BlockedId` ADD COLUMN `domain` TEXT NOT NULL DEFAULT 'adnmb'") + database.execSQL("ALTER TABLE `BrowsingHistory` ADD COLUMN `domain` TEXT NOT NULL DEFAULT 'adnmb'") + database.execSQL("ALTER TABLE `Comment` ADD COLUMN `domain` TEXT NOT NULL DEFAULT 'adnmb'") + database.execSQL("ALTER TABLE `Community` ADD COLUMN `domain` TEXT NOT NULL DEFAULT 'adnmb'") + database.execSQL("ALTER TABLE `Cookie` ADD COLUMN `domain` TEXT NOT NULL DEFAULT 'adnmb'") + database.execSQL("ALTER TABLE `Feed` ADD COLUMN `domain` TEXT NOT NULL DEFAULT 'adnmb'") + database.execSQL("ALTER TABLE `Notification` ADD COLUMN `domain` TEXT NOT NULL DEFAULT 'adnmb'") + database.execSQL("ALTER TABLE `Post` ADD COLUMN `domain` TEXT NOT NULL DEFAULT 'adnmb'") + database.execSQL("ALTER TABLE `PostHistory` ADD COLUMN `domain` TEXT NOT NULL DEFAULT 'adnmb'") + database.execSQL("ALTER TABLE `ReadingPage` ADD COLUMN `domain` TEXT NOT NULL DEFAULT 'adnmb'") + } + } + synchronized(this) { val instance = Room.databaseBuilder(context.applicationContext, DawnDatabase::class.java, "dawnDB") .addMigrations( @@ -381,7 +397,8 @@ abstract class DawnDatabase : RoomDatabase() { migrate19To20, migrate20To21, migrate21To22, - migrate22To23 + migrate22To23, + migrate23To24 ) .build() INSTANCE = instance diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/BlockedIdDao.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/BlockedIdDao.kt index f6347cd9..b10fe67d 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/BlockedIdDao.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/BlockedIdDao.kt @@ -19,17 +19,18 @@ package com.laotoua.dawnislandk.data.local.dao import androidx.lifecycle.LiveData import androidx.room.* +import com.laotoua.dawnislandk.DawnApp import com.laotoua.dawnislandk.data.local.entity.BlockedId @Dao interface BlockedIdDao { // returns both blocked post Ids & forum Ids - @Query("SELECT * From BlockedId") - suspend fun getAllBlockedIds(): List + @Query("SELECT * From BlockedId WHERE domain = :domain") + suspend fun getAllBlockedIds(domain: String = DawnApp.currentDomain): List - @Query("SELECT * From BlockedId") - fun getLiveAllBlockedIds(): LiveData> + @Query("SELECT * From BlockedId WHERE domain = :domain") + fun getLiveAllBlockedIds(domain: String = DawnApp.currentDomain): LiveData> @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insert(blockedId: BlockedId) @@ -38,7 +39,7 @@ interface BlockedIdDao { suspend fun insertAll(blockedIds: List) @Transaction - suspend fun updateBlockedForumIds(blockedIds: List){ + suspend fun updateBlockedForumIds(blockedIds: List) { nukeTimelineForumIds() if (blockedIds.isNotEmpty()) insertAll(blockedIds) } diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/BrowsingHistoryDao.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/BrowsingHistoryDao.kt index e1c40f93..4e4e77dd 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/BrowsingHistoryDao.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/BrowsingHistoryDao.kt @@ -19,6 +19,7 @@ package com.laotoua.dawnislandk.data.local.dao import androidx.lifecycle.LiveData import androidx.room.* +import com.laotoua.dawnislandk.DawnApp import com.laotoua.dawnislandk.data.local.entity.BrowsingHistory import com.laotoua.dawnislandk.data.local.entity.BrowsingHistoryAndPost import java.time.LocalDateTime @@ -26,24 +27,25 @@ import java.time.LocalDateTime @Dao interface BrowsingHistoryDao { @Transaction - @Query("SELECT * From BrowsingHistory ORDER BY browsedDateTime DESC") - fun getAllBrowsingHistoryAndPost(): LiveData> + @Query("SELECT * From BrowsingHistory WHERE domain = :domain ORDER BY browsedDateTime DESC") + fun getAllBrowsingHistoryAndPost(domain: String = DawnApp.currentDomain): LiveData> @Transaction - @Query("SELECT * From BrowsingHistory WHERE browsedDateTime>=date(:startDate) AND browsedDateTime=date(:startDate) AND browsedDateTime> - @Query("SELECT * From BrowsingHistory ORDER BY browsedDateTime DESC") - suspend fun getAllBrowsingHistory(): List + @Query("SELECT * From BrowsingHistory WHERE domain = :domain ORDER BY browsedDateTime DESC") + suspend fun getAllBrowsingHistory(domain: String = DawnApp.currentDomain): List - @Query("SELECT * From BrowsingHistory WHERE date(browsedDateTime)=date(:date) ORDER BY browsedDateTime DESC") - fun getBrowsingHistoryByDate(date: LocalDateTime): LiveData> + @Query("SELECT * From BrowsingHistory WHERE domain = :domain AND date(browsedDateTime)=date(:date) ORDER BY browsedDateTime DESC") + fun getBrowsingHistoryByDate(date: LocalDateTime, domain: String = DawnApp.currentDomain): LiveData> - @Query("SELECT * From BrowsingHistory WHERE date(browsedDateTime)=date(:today) AND postId=:postId ORDER BY browsedDateTime DESC LIMIT 1") - suspend fun getBrowsingHistoryByTodayAndIdSync(today: LocalDateTime, postId: String): BrowsingHistory? + @Query("SELECT * From BrowsingHistory WHERE domain = :domain AND date(browsedDateTime)=date(:today) AND postId=:postId ORDER BY browsedDateTime DESC LIMIT 1") + suspend fun getBrowsingHistoryByTodayAndIdSync(today: LocalDateTime, postId: String, domain: String = DawnApp.currentDomain): BrowsingHistory? @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insertBrowsingHistory(browsingHistory: BrowsingHistory) diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/CommentDao.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/CommentDao.kt index ed7def11..1aba08ff 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/CommentDao.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/CommentDao.kt @@ -20,23 +20,24 @@ package com.laotoua.dawnislandk.data.local.dao import androidx.lifecycle.LiveData import androidx.lifecycle.distinctUntilChanged import androidx.room.* +import com.laotoua.dawnislandk.DawnApp import com.laotoua.dawnislandk.data.local.entity.Comment import java.time.LocalDateTime @Dao interface CommentDao { - @Query("SELECT * FROM Comment WHERE parentId=:parentId") - suspend fun findAllByParentId(parentId: String): List + @Query("SELECT * FROM Comment WHERE domain = :domain AND parentId=:parentId") + suspend fun findAllByParentId(parentId: String, domain: String = DawnApp.currentDomain): List - @Query("SELECT * FROM Comment WHERE parentId=:parentId AND page<=:page ORDER BY id ASC") - suspend fun findByParentIdUntilPage(parentId: String, page: Int): List + @Query("SELECT * FROM Comment WHERE domain = :domain AND parentId=:parentId AND page<=:page ORDER BY id ASC") + suspend fun findByParentIdUntilPage(parentId: String, page: Int, domain: String = DawnApp.currentDomain): List - @Query("SELECT * FROM Comment WHERE parentId=:parentId AND page=:page ORDER BY id ASC") - fun findPageByParentId(parentId: String, page: Int): LiveData> + @Query("SELECT * FROM Comment WHERE domain = :domain AND parentId=:parentId AND page=:page ORDER BY id ASC") + fun findPageByParentId(parentId: String, page: Int, domain: String = DawnApp.currentDomain): LiveData> - fun findDistinctPageByParentId(parentId: String, page: Int): - LiveData> = findPageByParentId(parentId, page).distinctUntilChanged() + fun findDistinctPageByParentId(parentId: String, page: Int, domain: String = DawnApp.currentDomain): + LiveData> = findPageByParentId(parentId, page, domain).distinctUntilChanged() @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insert(comment: Comment) @@ -55,11 +56,11 @@ interface CommentDao { insert(comment) } - @Query("SELECT * FROM Comment WHERE id=:id LIMIT 1") - suspend fun findCommentByIdSync(id: String): Comment? + @Query("SELECT * FROM Comment WHERE domain = :domain AND id=:id LIMIT 1") + suspend fun findCommentByIdSync(id: String, domain: String = DawnApp.currentDomain): Comment? - @Query("SELECT * FROM Comment WHERE id=:id LIMIT 1") - fun findCommentById(id: String): LiveData + @Query("SELECT * FROM Comment WHERE domain = :domain AND id=:id LIMIT 1") + fun findCommentById(id: String, domain: String = DawnApp.currentDomain): LiveData @Delete suspend fun delete(comment: Comment) diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/CommunityDao.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/CommunityDao.kt index b0a244e4..da4d2aa3 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/CommunityDao.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/CommunityDao.kt @@ -19,15 +19,16 @@ package com.laotoua.dawnislandk.data.local.dao import androidx.lifecycle.LiveData import androidx.room.* +import com.laotoua.dawnislandk.DawnApp import com.laotoua.dawnislandk.data.local.entity.Community @Dao interface CommunityDao { - @Query("SELECT * FROM Community ORDER BY sort ASC") - fun getAll(): LiveData> + @Query("SELECT * FROM Community WHERE domain = :domain ORDER BY sort ASC") + fun getAll(domain: String = DawnApp.currentDomain): LiveData> - @Query("SELECT * FROM Community WHERE id=:id") - suspend fun getCommunityById(id: String): Community + @Query("SELECT * FROM Community WHERE id=:id AND domain = :domain") + suspend fun getCommunityById(id: String, domain: String = DawnApp.currentDomain): Community @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insert(community: Community) diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/CookieDao.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/CookieDao.kt index cc5eb7af..bd488b66 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/CookieDao.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/CookieDao.kt @@ -18,17 +18,18 @@ package com.laotoua.dawnislandk.data.local.dao import androidx.room.* +import com.laotoua.dawnislandk.DawnApp import com.laotoua.dawnislandk.data.local.entity.Cookie import java.time.LocalDateTime @Dao interface CookieDao { - @Query("SELECT * FROM Cookie ORDER BY lastUsedAt DESC") - suspend fun getAll(): List + @Query("SELECT * FROM Cookie WHERE domain=:domain ORDER BY lastUsedAt DESC") + suspend fun getAll(domain: String = DawnApp.currentDomain): List - @Query("SELECT * FROM Cookie WHERE cookieHash=:cookieHash") - suspend fun getCookieByHash(cookieHash: String): Cookie + @Query("SELECT * FROM Cookie WHERE cookieHash=:cookieHash AND domain=:domain ") + suspend fun getCookieByHash(cookieHash: String, domain: String = DawnApp.currentDomain): Cookie @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insert(cookie: Cookie) diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/FeedDao.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/FeedDao.kt index 916265e2..8e04ac42 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/FeedDao.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/FeedDao.kt @@ -20,6 +20,7 @@ package com.laotoua.dawnislandk.data.local.dao import androidx.lifecycle.LiveData import androidx.lifecycle.distinctUntilChanged import androidx.room.* +import com.laotoua.dawnislandk.DawnApp import com.laotoua.dawnislandk.data.local.entity.Feed import com.laotoua.dawnislandk.data.local.entity.FeedAndPost import com.laotoua.dawnislandk.data.local.entity.Post @@ -29,21 +30,21 @@ import java.time.LocalDateTime interface FeedDao { @Transaction - @Query("SELECT * From Feed") - fun getAllFeedAndPost(): LiveData> + @Query("SELECT * From Feed WHERE domain=:domain") + fun getAllFeedAndPost(domain: String = DawnApp.currentDomain): LiveData> - @Query("SELECT * From Feed where postId=:postId") - suspend fun findFeedByPostId(postId: String): Feed? + @Query("SELECT * From Feed where postId=:postId AND domain=:domain") + suspend fun findFeedByPostId(postId: String, domain: String = DawnApp.currentDomain): Feed? @Transaction - @Query("SELECT * From Feed where date(:targetTime)>date(Feed.lastUpdatedAt) ORDER BY Feed.lastUpdatedAt ASC LIMIT 1") - suspend fun findMostOutdatedFeedAndPost(targetTime: LocalDateTime): FeedAndPost? + @Query("SELECT * From Feed where date(:targetTime)>date(Feed.lastUpdatedAt) AND domain=:domain ORDER BY Feed.lastUpdatedAt ASC LIMIT 1") + suspend fun findMostOutdatedFeedAndPost(targetTime: LocalDateTime, domain: String = DawnApp.currentDomain): FeedAndPost? @Transaction - @Query("SELECT * From Feed WHERE page==:page ORDER BY id ASC") - fun getFeedAndPostOnPage(page: Int): LiveData> + @Query("SELECT * From Feed WHERE page==:page AND domain=:domain ORDER BY id ASC") + fun getFeedAndPostOnPage(page: Int, domain: String = DawnApp.currentDomain): LiveData> - fun getDistinctFeedAndPostOnPage(page: Int) = getFeedAndPostOnPage(page).distinctUntilChanged() + fun getDistinctFeedAndPostOnPage(page: Int, domain: String = DawnApp.currentDomain) = getFeedAndPostOnPage(page, domain).distinctUntilChanged() @Transaction suspend fun addFeedToTopAndIncrementFeedIds(feed: Feed) { @@ -58,24 +59,24 @@ interface FeedDao { } @Transaction - suspend fun deleteFeedAndDecrementFeedIdsById(id: String){ + suspend fun deleteFeedAndDecrementFeedIdsById(id: String) { findFeedByPostId(id)?.let { decrementFeedIdsAfter(it.id, it.page) deleteFeedByPostId(it.postId) } } - @Query("UPDATE Feed SET id=id+1 WHERE id>=:id AND page=:page") - suspend fun incrementFeedIdsAfter(id: Int, page:Int) + @Query("UPDATE Feed SET id=id+1 WHERE domain=:domain AND id>=:id AND page=:page") + suspend fun incrementFeedIdsAfter(id: Int, page: Int, domain: String = DawnApp.currentDomain) - @Query("UPDATE Feed SET id=id-1 WHERE id>:id AND page=:page") - suspend fun decrementFeedIdsAfter(id: Int, page:Int) + @Query("UPDATE Feed SET id=id-1 WHERE domain=:domain AND id>:id AND page=:page") + suspend fun decrementFeedIdsAfter(id: Int, page: Int, domain: String = DawnApp.currentDomain) @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insertFeed(feed: Feed) - @Query("DELETE FROM Feed WHERE postId=:postId") - suspend fun deleteFeedByPostId(postId: String) + @Query("DELETE FROM Feed WHERE postId=:postId AND domain=:domain") + suspend fun deleteFeedByPostId(postId: String, domain: String = DawnApp.currentDomain) @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insertAllFeed(feedList: List) diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/NotificationDao.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/NotificationDao.kt index c7cf7681..159dcc48 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/NotificationDao.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/NotificationDao.kt @@ -19,27 +19,28 @@ package com.laotoua.dawnislandk.data.local.dao import androidx.lifecycle.LiveData import androidx.room.* +import com.laotoua.dawnislandk.DawnApp import com.laotoua.dawnislandk.data.local.entity.Notification import com.laotoua.dawnislandk.data.local.entity.NotificationAndPost @Dao interface NotificationDao { - @Query("SELECT * FROM Notification ORDER BY lastUpdatedAt DESC") - fun getLiveAllNotifications(): LiveData> + @Query("SELECT * FROM Notification WHERE domain=:domain ORDER BY lastUpdatedAt DESC") + fun getLiveAllNotifications(domain: String = DawnApp.currentDomain): LiveData> - @Query("SELECT COUNT(*) FROM Notification WHERE read=0 ORDER BY lastUpdatedAt DESC") - fun getLiveUnreadNotificationsCount(): LiveData + @Query("SELECT COUNT(*) FROM Notification WHERE read=0 AND domain=:domain ORDER BY lastUpdatedAt DESC") + fun getLiveUnreadNotificationsCount(domain: String = DawnApp.currentDomain): LiveData @Transaction - @Query("SELECT * From Notification ORDER BY lastUpdatedAt DESC") - fun getLiveAllNotificationsAndPosts(): LiveData> + @Query("SELECT * From Notification WHERE domain=:domain ORDER BY lastUpdatedAt DESC") + fun getLiveAllNotificationsAndPosts(domain: String = DawnApp.currentDomain): LiveData> - @Query("SELECT * FROM Notification WHERE id=:id LIMIT 1") - suspend fun getNotificationByIdSync(id: String): Notification? + @Query("SELECT * FROM Notification WHERE id=:id AND domain=:domain LIMIT 1") + suspend fun getNotificationByIdSync(id: String, domain: String = DawnApp.currentDomain): Notification? - @Query("UPDATE Notification SET read=1, newReplyCount=0 WHERE id=:id") - suspend fun readNotificationByIdSync(id: String) + @Query("UPDATE Notification SET read=1, newReplyCount=0 WHERE id=:id AND domain=:domain") + suspend fun readNotificationByIdSync(id: String, domain: String = DawnApp.currentDomain) @Transaction suspend fun insertOrUpdateNotification(notification: Notification) { @@ -56,8 +57,8 @@ interface NotificationDao { @Delete suspend fun deleteNotifications(vararg notifications: Notification) - @Query("DELETE FROM Notification WHERE id=:id") - suspend fun deleteNotificationById(id: String) + @Query("DELETE FROM Notification WHERE id=:id AND domain=:domain") + suspend fun deleteNotificationById(id: String, domain: String = DawnApp.currentDomain) @Query("DELETE FROM Notification") suspend fun nukeTable() diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/PostDao.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/PostDao.kt index 6f007a91..c2e3edd6 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/PostDao.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/PostDao.kt @@ -20,21 +20,22 @@ package com.laotoua.dawnislandk.data.local.dao import androidx.lifecycle.LiveData import androidx.lifecycle.distinctUntilChanged import androidx.room.* +import com.laotoua.dawnislandk.DawnApp import com.laotoua.dawnislandk.data.local.entity.Post import java.time.LocalDateTime @Dao interface PostDao { - @Query("SELECT * FROM Post") - suspend fun getAll(): List + @Query("SELECT * FROM Post WHERE domain=:domain") + suspend fun getAll(domain: String = DawnApp.currentDomain): List - @Query("SELECT * FROM Post WHERE id=:id LIMIT 1") - fun findPostById(id: String): LiveData + @Query("SELECT * FROM Post WHERE id=:id AND domain=:domain LIMIT 1") + fun findPostById(id: String, domain: String = DawnApp.currentDomain): LiveData - @Query("SELECT * FROM Post WHERE id=:id LIMIT 1") - suspend fun findPostByIdSync(id: String): Post? + @Query("SELECT * FROM Post WHERE id=:id AND domain=:domain LIMIT 1") + suspend fun findPostByIdSync(id: String, domain: String = DawnApp.currentDomain): Post? - fun findDistinctPostById(id: String): LiveData = findPostById(id).distinctUntilChanged() + fun findDistinctPostById(id: String, domain: String = DawnApp.currentDomain): LiveData = findPostById(id, domain).distinctUntilChanged() @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insert(post: Post) diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/PostHistoryDao.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/PostHistoryDao.kt index 9eb42372..90e0ef82 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/PostHistoryDao.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/PostHistoryDao.kt @@ -19,20 +19,21 @@ package com.laotoua.dawnislandk.data.local.dao import androidx.lifecycle.LiveData import androidx.room.* +import com.laotoua.dawnislandk.DawnApp import com.laotoua.dawnislandk.data.local.entity.PostHistory import java.time.LocalDateTime @Dao interface PostHistoryDao { - @Query("SELECT * From PostHistory ORDER BY postDateTime DESC") - fun getAllPostHistory(): LiveData> + @Query("SELECT * From PostHistory WHERE domain=:domain ORDER BY postDateTime DESC") + fun getAllPostHistory(domain: String = DawnApp.currentDomain): LiveData> @Transaction - @Query("SELECT * From PostHistory WHERE postDateTime>=:startDate AND postDateTime<=:endDate ORDER BY postDateTime DESC ") - fun getAllPostHistoryInDateRange(startDate: LocalDateTime, endDate: LocalDateTime): LiveData> + @Query("SELECT * From PostHistory WHERE postDateTime>=:startDate AND postDateTime<=:endDate AND domain=:domain ORDER BY postDateTime DESC ") + fun getAllPostHistoryInDateRange(startDate: LocalDateTime, endDate: LocalDateTime, domain: String = DawnApp.currentDomain): LiveData> - @Query("SELECT * From PostHistory WHERE postDateTime=:date") - fun getPostHistoryByDate(date: LocalDateTime): LiveData> + @Query("SELECT * From PostHistory WHERE postDateTime=:date AND domain=:domain") + fun getPostHistoryByDate(date: LocalDateTime, domain: String = DawnApp.currentDomain): LiveData> @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insertPostHistory(browsingHistory: PostHistory) diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/ReadingPageDao.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/ReadingPageDao.kt index 82dbd795..9c6930b6 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/ReadingPageDao.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/dao/ReadingPageDao.kt @@ -21,17 +21,18 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query +import com.laotoua.dawnislandk.DawnApp import com.laotoua.dawnislandk.data.local.entity.ReadingPage @Dao interface ReadingPageDao { - @Query("SELECT * From ReadingPage WHERE id=:id") - suspend fun getReadingPageById(id:String): ReadingPage? + @Query("SELECT * From ReadingPage WHERE id=:id AND domain=:domain") + suspend fun getReadingPageById(id: String, domain: String = DawnApp.currentDomain): ReadingPage? @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insertReadingPage(readingPage: ReadingPage) - suspend fun insertReadingPageWithTimeStamp(readingPage: ReadingPage){ + suspend fun insertReadingPageWithTimeStamp(readingPage: ReadingPage) { readingPage.setUpdatedTimestamp() insertReadingPage(readingPage) } diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/BlockedId.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/BlockedId.kt index b5792f0b..f19fa056 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/BlockedId.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/BlockedId.kt @@ -19,6 +19,7 @@ package com.laotoua.dawnislandk.data.local.entity import androidx.room.Entity import androidx.room.PrimaryKey +import com.laotoua.dawnislandk.DawnApp @Entity data class BlockedId( @@ -26,15 +27,16 @@ data class BlockedId( /** type 0 refers blocking post fid (uses in timeline only) * type 1 refers blocking post id (uses in all communities) */ - val type: Int + val type: Int, + val domain: String = DawnApp.currentDomain ) { fun isBlockedPost(): Boolean = type == 1 fun isTimelineBlockedForum(): Boolean = type == 0 companion object { - fun makeBlockedPost(id: String): BlockedId = BlockedId(id, 1) + fun makeBlockedPost(id: String, domain: String = DawnApp.currentDomain): BlockedId = BlockedId(id, 1, domain) - fun makeTimelineBlockedForum(id: String): BlockedId = BlockedId(id, 0) + fun makeTimelineBlockedForum(id: String, domain: String = DawnApp.currentDomain): BlockedId = BlockedId(id, 0, domain) } } \ No newline at end of file diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/BrowsingHistory.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/BrowsingHistory.kt index c2c13c05..431cf525 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/BrowsingHistory.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/BrowsingHistory.kt @@ -19,6 +19,7 @@ package com.laotoua.dawnislandk.data.local.entity import androidx.room.Entity import androidx.room.PrimaryKey +import com.laotoua.dawnislandk.DawnApp import java.time.LocalDateTime @Entity @@ -26,7 +27,8 @@ data class BrowsingHistory( var browsedDateTime: LocalDateTime = LocalDateTime.now(), val postId: String, var postFid: String, - var pages: MutableSet // number of pages read + var pages: MutableSet, // number of pages read + val domain: String = DawnApp.currentDomain ) { @PrimaryKey(autoGenerate = true) var id: Int = 0 diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Comment.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Comment.kt index 4a34f809..e5a4f13f 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Comment.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Comment.kt @@ -20,6 +20,7 @@ package com.laotoua.dawnislandk.data.local.entity import androidx.room.Entity import androidx.room.Ignore import androidx.room.PrimaryKey +import com.laotoua.dawnislandk.DawnApp import com.squareup.moshi.JsonClass import java.time.LocalDateTime @@ -40,6 +41,7 @@ data class Comment( val ext: String, var page: Int = 1, var parentId: String = "", + val domain: String = DawnApp.currentDomain, var lastUpdatedAt: LocalDateTime = LocalDateTime.now() ) { // used for reply filtering diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Community.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Community.kt index dc95ac6c..74d7041c 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Community.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Community.kt @@ -19,6 +19,8 @@ package com.laotoua.dawnislandk.data.local.entity import androidx.room.Entity import androidx.room.PrimaryKey +import com.laotoua.dawnislandk.DawnApp +import com.laotoua.dawnislandk.util.DawnConstants import com.squareup.moshi.JsonClass @JsonClass(generateAdapter = true) @@ -29,7 +31,8 @@ data class Community( val sort: String, val name: String, val status: String, - val forums: List + val forums: List, + val domain: String = DawnApp.currentDomain ) { fun isCommonForums(): Boolean { return id == "1000" @@ -40,9 +43,15 @@ data class Community( } companion object { - fun makeCommonForums(forums: List): Community = Community("1000", "0", "常用板块", "n", forums) + fun makeCommonForums(forums: List, domain: String): Community { + val id = if (domain == DawnConstants.ADNMBDomain) "1000" else "2000" + return Community(id, "0", "常用板块", "n", forums, domain) + } - fun makeCommonPosts(fakeForums: List): Community = Community("1001", "-1", "常用串", "n", fakeForums) + fun makeCommonPosts(fakeForums: List, domain: String): Community { + val id = if (domain == DawnConstants.ADNMBDomain) "1001" else "2001" + return Community(id, "-1", "常用串", "n", fakeForums, domain) + } } } \ No newline at end of file diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Cookie.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Cookie.kt index 940d73e1..4f5140c6 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Cookie.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Cookie.kt @@ -19,6 +19,7 @@ package com.laotoua.dawnislandk.data.local.entity import androidx.room.Entity import androidx.room.PrimaryKey +import com.laotoua.dawnislandk.DawnApp import java.time.LocalDateTime @Entity @@ -26,7 +27,8 @@ data class Cookie( @PrimaryKey val cookieHash: String, val cookieName: String, var cookieDisplayName: String, - var lastUsedAt: LocalDateTime = LocalDateTime.now() + var lastUsedAt: LocalDateTime = LocalDateTime.now(), + val domain: String = DawnApp.currentDomain ){ fun getApiHeaderCookieHash():String = "userhash=$cookieHash" } \ No newline at end of file diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Feed.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Feed.kt index c3559098..fafe5a8c 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Feed.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Feed.kt @@ -19,6 +19,7 @@ package com.laotoua.dawnislandk.data.local.entity import androidx.room.Entity import androidx.room.PrimaryKey +import com.laotoua.dawnislandk.DawnApp import com.squareup.moshi.JsonClass import java.time.LocalDateTime @@ -28,6 +29,7 @@ data class Feed( val page: Int, // each page has at most 10 feeds, page also helps sorting @PrimaryKey val postId: String, // 该串的id val category: String, + val domain: String = DawnApp.currentDomain, var lastUpdatedAt: LocalDateTime = LocalDateTime.now() // timestamp which the row is updated ) { override fun equals(other: Any?) = @@ -57,7 +59,8 @@ data class Feed( val title: String, val content: String, val admin: String = "0", - val status: String = "" + val status: String = "", + val domain: String = DawnApp.currentDomain ) { fun toPost() = Post( id, @@ -75,6 +78,7 @@ data class Feed( status, emptyList(), "", + domain, LocalDateTime.now() ) } diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/NoticeForum.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/NoticeForum.kt index bf25b5f5..2c61712d 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/NoticeForum.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/NoticeForum.kt @@ -29,7 +29,9 @@ data class NoticeForum( val fgroup: String, val rule: String = "" // default rule ){ - fun getDisplayName():String = if (showName.isNotBlank()) showName else name + fun getDisplayName(): String = if (showName.isNotBlank()) showName else name - fun getPostRule():String = if (rule.isNotBlank()) rule else "请遵守总版规" + fun getPostRule(): String = if (rule.isNotBlank()) rule else "请遵守总版规" + + fun toForum(): Forum = Forum(id = id, sort = sort, name = name, showName = showName, fgroup = fgroup, msg = rule) } diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Notification.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Notification.kt index 6b616aef..33eade85 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Notification.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Notification.kt @@ -19,6 +19,7 @@ package com.laotoua.dawnislandk.data.local.entity import androidx.room.Entity import androidx.room.PrimaryKey +import com.laotoua.dawnislandk.DawnApp import java.time.LocalDateTime @Entity @@ -28,6 +29,7 @@ data class Notification( var newReplyCount: Int, val message: String = "", // feed subscription update do not use this field, it is reserved for other notifications var read: Boolean = false, + val domain: String = DawnApp.currentDomain, var lastUpdatedAt: LocalDateTime = LocalDateTime.now() ) { // valid targetId should be all digits, here only checking the first digit should be sufficient @@ -35,7 +37,7 @@ data class Notification( fun isValidFeedPushNotification(): Boolean = id.first().isDigit() companion object { - fun makeNotification(targetId: String, fid: String, newReplyCount: Int, message: String = ""): Notification = - Notification(targetId, fid, newReplyCount, message, false, LocalDateTime.now()) + fun makeNotification(targetId: String, fid: String, newReplyCount: Int, message: String = "", domain: String = DawnApp.currentDomain): Notification = + Notification(targetId, fid, newReplyCount, message, false, domain, LocalDateTime.now()) } } \ No newline at end of file diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Post.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Post.kt index 561cfe41..2f7e3a2f 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Post.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/Post.kt @@ -20,6 +20,7 @@ package com.laotoua.dawnislandk.data.local.entity import androidx.room.Entity import androidx.room.Ignore import androidx.room.PrimaryKey +import com.laotoua.dawnislandk.DawnApp import com.squareup.moshi.Json import com.squareup.moshi.JsonClass import java.time.LocalDateTime @@ -43,6 +44,7 @@ data class Post( val status: String = "", @Json(name = "replys") @Ignore var comments: List = emptyList(), //replys 主页展示回复的帖子(5个) val replyCount: String = "0", + val domain: String = DawnApp.currentDomain, var lastUpdatedAt: LocalDateTime = LocalDateTime.now() ) { // Room uses this @@ -61,6 +63,7 @@ data class Post( admin: String, status: String, replyCount: String, + domain: String, lastUpdatedAt: LocalDateTime ) : this( id, @@ -78,6 +81,7 @@ data class Post( status, emptyList(), replyCount, + domain, lastUpdatedAt ) @@ -96,7 +100,8 @@ data class Post( img, ext, 1, - id + id, + domain ) // special handler for sticky top banner @@ -105,8 +110,7 @@ data class Post( fun getImgUrl() = (img + ext) fun getSimplifiedTitle(): String = if (title.isNotBlank() && title != "无标题") "标题:$title" else "" fun getSimplifiedName(): String = if (name.isNotBlank() && name != "无名氏") "名称:$name" else "" - fun getMaxPage() = - if (replyCount.isBlank()) 1 else 1.coerceAtLeast(ceil(replyCount.toDouble() / 19).toInt()) + fun getMaxPage() = if (replyCount.isBlank()) 1 else 1.coerceAtLeast(ceil(replyCount.toDouble() / 19).toInt()) // only compares by server fields override fun equals(other: Any?) = @@ -159,6 +163,7 @@ data class Post( status = status, comments = emptyList(), replyCount = replyCount, + domain = domain, lastUpdatedAt = lastUpdatedAt ) diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/PostHistory.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/PostHistory.kt index de595e1c..3c3ac770 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/PostHistory.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/PostHistory.kt @@ -19,6 +19,7 @@ package com.laotoua.dawnislandk.data.local.entity import androidx.room.Entity import androidx.room.PrimaryKey +import com.laotoua.dawnislandk.DawnApp import java.time.LocalDateTime @Entity @@ -33,9 +34,10 @@ class PostHistory( val content: String, //content val img: String, val ext: String, + val domain: String = DawnApp.currentDomain, val postDateTime: LocalDateTime = LocalDateTime.now() ) { - constructor(id: String, targetPage: Int, img: String, ext: String, draft: Draft) : this( + constructor(id: String, targetPage: Int, img: String, ext: String, domain: String, draft: Draft) : this( id, draft.newPost, draft.postTargetId, @@ -45,6 +47,7 @@ class PostHistory( draft.content, img, ext, + domain, draft.postDateTime ) diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/ReadingPage.kt b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/ReadingPage.kt index 86c6bc62..1109415f 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/ReadingPage.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/local/entity/ReadingPage.kt @@ -19,12 +19,14 @@ package com.laotoua.dawnislandk.data.local.entity import androidx.room.Entity import androidx.room.PrimaryKey +import com.laotoua.dawnislandk.DawnApp import java.time.LocalDateTime @Entity data class ReadingPage( @PrimaryKey val id: String, var page: Int, + val domain: String = DawnApp.currentDomain, var lastUpdatedAt: LocalDateTime = LocalDateTime.now() ) { fun setUpdatedTimestamp(time: LocalDateTime = LocalDateTime.now()) { diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/remote/NMBService.kt b/app/src/main/java/com/laotoua/dawnislandk/data/remote/NMBService.kt index f0ac7bc9..70bdca00 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/remote/NMBService.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/remote/NMBService.kt @@ -51,35 +51,35 @@ interface NMBService { @Header("Host") host: String ): Call - @Headers("Domain-Name: adnmb") + @Headers("Domain-Name: nmb") @GET("Api/getForumList") fun getNMBForumList(): Call - @Headers("Domain-Name: adnmb") + @Headers("Domain-Name: nmb") @GET("Api/getTimelineList") fun getNMBTimelineList(): Call - @Headers("Domain-Name: adnmb") + @Headers("Domain-Name: nmb") @GET("Api/showf") fun getNMBPosts(@Query("id") fid: String, @Query("page") page: Int): Call - @Headers("Domain-Name: adnmb") + @Headers("Domain-Name: nmb") @GET("Api/feed") fun getNMBFeeds(@Query("uuid") uuid: String, @Query("page") page: Int): Call - @Headers("Domain-Name: adnmb") + @Headers("Domain-Name: nmb") @GET("Api/addFeed") fun addNMBFeed(@Query("uuid") uuid: String, @Query("tid") tid: String): Call - @Headers("Domain-Name: adnmb") + @Headers("Domain-Name: nmb") @GET("Api/delFeed") fun delNMBFeed(@Query("uuid") uuid: String, @Query("tid") tid: String): Call - @Headers("Domain-Name: adnmb") + @Headers("Domain-Name: nmb") @GET("Api/timeline/id/{id}") fun getNMBTimeLine(@Path("id") id: String = "1", @Query("page") page: Int, @Header("Cookie") hash: String?): Call - @Headers("Domain-Name: adnmb") + @Headers("Domain-Name: nmb") @GET("Api/thread") fun getNMBComments( @Header("Cookie") hash: String?, @@ -87,11 +87,11 @@ interface NMBService { @Query("page") page: Int ): Call - @Headers("Domain-Name: adnmb-ref") + @Headers("Domain-Name: nmb-ref") @GET("Home/Forum/ref") fun getNMBQuote(@Query("id") id: String): Call - @Headers("Domain-Name: adnmb") + @Headers("Domain-Name: nmb") @Multipart @POST("Home/Forum/doReplyThread.html") fun postComment( @@ -101,7 +101,7 @@ interface NMBService { @Part image: MultipartBody.Part?, @Header("Cookie") hash: String ): Call - @Headers("Domain-Name: adnmb") + @Headers("Domain-Name: nmb") @Multipart @POST("Home/Forum/doPostThread.html") fun postNewPost( diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/repository/CommentRepository.kt b/app/src/main/java/com/laotoua/dawnislandk/data/repository/CommentRepository.kt index bbaf9e84..5943921e 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/repository/CommentRepository.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/repository/CommentRepository.kt @@ -63,7 +63,7 @@ class CommentRepository @Inject constructor( fun getFid(id: String) = postMap[id]?.fid ?: "" suspend fun setPost(id: String, fid: String) { - clearCachedPages() + clearCache() Timber.d("Setting new Thread: $id") fifoPostList.add(id) if (commentsMap[id] == null) commentsMap[id] = SparseArray() @@ -95,7 +95,7 @@ class CommentRepository @Inject constructor( readingPageDao.insertReadingPageWithTimeStamp(readingProgress) } - private fun clearCachedPages() { + fun clearCache() { for (i in 0 until (commentsMap.size - cacheCap)) { fifoPostList.first().run { Timber.d("Reached cache Cap. Clearing ${this}...") @@ -265,7 +265,7 @@ class CommentRepository @Inject constructor( if (this is APIMessageResponse.Success && messageType == APIMessageResponse.MessageType.String) { coroutineScope { launch { - val newFeed = Feed(1, 1, id, "", LocalDateTime.now()) + val newFeed = Feed(1, 1, id, "", DawnApp.currentDomain, LocalDateTime.now()) feedDao.addFeedToTopAndIncrementFeedIds(newFeed) } } diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/repository/FeedRepository.kt b/app/src/main/java/com/laotoua/dawnislandk/data/repository/FeedRepository.kt index 738117e0..02fc28f1 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/repository/FeedRepository.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/repository/FeedRepository.kt @@ -45,6 +45,10 @@ class FeedRepository @Inject constructor( ) { private val feedsMap = SparseArray>>>() + fun clearCache() { + feedsMap.clear() + } + fun getLiveFeedPage(page: Int): LiveData>> { feedsMap.put(page, getCombinedFeedPage(page)) return feedsMap[page]!! @@ -102,7 +106,7 @@ class FeedRepository @Inject constructor( val baseIndex = (page - 1) * 10 + 1 val timestamp = LocalDateTime.now() data.mapIndexed { index, serverFeed -> - feeds.add(Feed(baseIndex + index, page, serverFeed.id, serverFeed.category, timestamp)) + feeds.add(Feed(baseIndex + index, page, serverFeed.id, serverFeed.category, DawnApp.currentDomain, timestamp)) posts.add(serverFeed.toPost()) } diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/repository/QuoteRepository.kt b/app/src/main/java/com/laotoua/dawnislandk/data/repository/QuoteRepository.kt index fc723a87..ce59ea1b 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/repository/QuoteRepository.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/repository/QuoteRepository.kt @@ -97,4 +97,9 @@ class QuoteRepository @Inject constructor( fifoQuoteList.removeAt(0) } } + + fun clearCache() { + quoteMap.clear() + fifoQuoteList.clear() + } } \ No newline at end of file diff --git a/app/src/main/java/com/laotoua/dawnislandk/data/repository/TrendRepository.kt b/app/src/main/java/com/laotoua/dawnislandk/data/repository/TrendRepository.kt index efd073c5..e0cd3a87 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/data/repository/TrendRepository.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/data/repository/TrendRepository.kt @@ -121,7 +121,7 @@ class TrendRepository @Inject constructor( } } - suspend fun extractLatestTrends(data: Post): Int { + private suspend fun extractLatestTrends(data: Post): Int { val foundTrends = mutableListOf() for (reply in data.comments) { if (reply.userid == po) { diff --git a/app/src/main/java/com/laotoua/dawnislandk/di/NMBNetworkModule.kt b/app/src/main/java/com/laotoua/dawnislandk/di/NMBNetworkModule.kt index 7b882c0b..196b0c5b 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/di/NMBNetworkModule.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/di/NMBNetworkModule.kt @@ -41,7 +41,7 @@ object NMBNetworkModule { .writeTimeout(30, TimeUnit.SECONDS) .build() return Retrofit.Builder() - .baseUrl(DawnConstants.nmbHost) + .baseUrl(DawnConstants.ADNMBHost) .client(okHttpClient) .build() .create(NMBService::class.java) diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/MainActivity.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/MainActivity.kt index e371210a..4a2f778b 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/MainActivity.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/MainActivity.kt @@ -20,6 +20,7 @@ package com.laotoua.dawnislandk.screens import android.animation.Animator import android.animation.TypeEvaluator import android.animation.ValueAnimator +import android.annotation.SuppressLint import android.content.BroadcastReceiver import android.content.Context import android.content.Intent @@ -50,6 +51,7 @@ import com.afollestad.materialdialogs.checkbox.isCheckPromptChecked import com.afollestad.materialdialogs.lifecycle.lifecycleOwner import com.afollestad.materialdialogs.list.listItemsSingleChoice import com.google.android.material.animation.AnimationUtils +import com.laotoua.dawnislandk.DawnApp import com.laotoua.dawnislandk.DawnApp.Companion.applicationDataStore import com.laotoua.dawnislandk.MainNavDirections import com.laotoua.dawnislandk.R @@ -61,6 +63,7 @@ import com.laotoua.dawnislandk.screens.widgets.popups.ForumDrawerPopup import com.laotoua.dawnislandk.util.DawnConstants import com.laotoua.dawnislandk.util.IntentsHelper import com.laotoua.dawnislandk.util.LoadingStatus +import com.laotoua.dawnislandk.util.SingleLiveEvent import com.lxj.xpopup.XPopup import com.lxj.xpopup.core.BasePopupView import com.lxj.xpopup.enums.PopupPosition @@ -91,6 +94,8 @@ class MainActivity : DaggerAppCompatActivity() { // The BroadcastReceiver that tracks network connectivity changes. private var networkStateReceiver: NetworkReceiver? = null private var lastNetworkTestTime: Long = 0 + private var lastSuccessfulBaseCDN: String = "" + private var lastSuccessfulRefCDN: String = "" private var doubleBackToExitPressedOnce = false @@ -143,7 +148,7 @@ class MainActivity : DaggerAppCompatActivity() { binding = ActivityMainBinding.inflate(layoutInflater) binding.toolbar.apply { immersiveToolbar() - setSubtitle(R.string.toolbar_subtitle) + setSubtitle(R.string.toolbar_subtitle_adnmb) } immersiveToolbarInitialization() customToolbarBackground() @@ -170,7 +175,7 @@ class MainActivity : DaggerAppCompatActivity() { return@observe } if (it.data.isNullOrEmpty()) return@observe - forumDrawer?.setCommunities(it.data) + if (DawnApp.currentDomain == DawnConstants.ADNMBDomain) forumDrawer?.setCommunities(it.data) sharedVM.setForumMappings(it.data) if (sharedVM.selectedForumId.value == null) sharedVM.setForumId(applicationDataStore.getDefaultForumId()) Timber.i("Loaded ${it.data.size} communities to Adapter") @@ -182,7 +187,7 @@ class MainActivity : DaggerAppCompatActivity() { return@observe } if (it.data.isNullOrEmpty()) return@observe - forumDrawer?.setTimelines(it.data) + if (DawnApp.currentDomain == DawnConstants.ADNMBDomain) forumDrawer?.setTimelines(it.data) sharedVM.setTimelineMappings(it.data) Timber.i("Loaded ${it.data.size} timelines to Adapter") } @@ -206,6 +211,7 @@ class MainActivity : DaggerAppCompatActivity() { val raw = data.toString().substringAfterLast("/") if (raw.isNotBlank()) { val id = if (raw.contains("?")) raw.substringBefore("?") else raw + // TODO tnmb if ((count == 1 && data.host == "t") || (count == 2 && path[1] == 't')) { val navAction = MainNavDirections.actionGlobalCommentsFragment(id, "") val navHostFragment = supportFragmentManager.findFragmentById(R.id.navHostFragment) @@ -244,8 +250,13 @@ class MainActivity : DaggerAppCompatActivity() { .setPopupCallback(object : SimpleCallback() { override fun beforeShow(popupView: BasePopupView?) { super.beforeShow(popupView) - sharedVM.communityList.value?.data?.let { drawer.setCommunities(it) } - sharedVM.timelineList.value?.data?.let { drawer.setTimelines(it) } + if (DawnApp.currentDomain == DawnConstants.ADNMBDomain) { + sharedVM.communityList.value?.data?.let { drawer.setCommunities(it) } + sharedVM.timelineList.value?.data?.let { drawer.setTimelines(it) } + } else { + sharedVM.beitaiForums.let { drawer.setCommunities(it) } + drawer.setTimelines(emptyList()) + } sharedVM.reedPictureUrl.value?.let { drawer.setReedPicture(it) } drawer.loadReedPicture() } @@ -263,6 +274,7 @@ class MainActivity : DaggerAppCompatActivity() { } // initialize Global resources + @SuppressLint("CheckResult") private suspend fun loadResources() { applicationDataStore.loadCookies() applicationDataStore.getLatestRelease()?.let { release -> @@ -310,6 +322,7 @@ class MainActivity : DaggerAppCompatActivity() { applicationDataStore.getLatestLuweiNotice()?.let { luweiNotice -> sharedVM.setLuweiLoadingBible(luweiNotice.loadingMsgs) + sharedVM.setBeiTaiForums(luweiNotice.beitaiForums) } // first time app entry @@ -553,10 +566,37 @@ class MainActivity : DaggerAppCompatActivity() { } } + fun goToADNMB() { + Timber.d("Switching to AD......") + sharedVM.onADNMB() + RetrofitUrlManager.getInstance().putDomain("host", DawnConstants.ADNMBHost) + autoSelectCDNs() + + sharedVM.setForumId(applicationDataStore.getDefaultForumId(), true) + + binding.toolbar.setSubtitle(R.string.toolbar_subtitle_adnmb) + } + + fun goToTNMB() { + Timber.d("Switching to BT......") + sharedVM.onTNMB() + RetrofitUrlManager.getInstance().putDomain("host", DawnConstants.TNMBHost) + RetrofitUrlManager.getInstance().putDomain("nmb", DawnConstants.TNMBHost) + RetrofitUrlManager.getInstance().putDomain("nmb-ref", DawnConstants.TNMBHost) + + sharedVM.beitaiForums.firstOrNull()?.forums?.firstOrNull()?.id?.let { sharedVM.setForumId(it, true) } + + binding.toolbar.setSubtitle(R.string.toolbar_subtitle_tnmb) + } + + private fun autoSelectCDNs() { + if (DawnApp.currentDomain == DawnConstants.TNMBDomain) return val currentTime = System.currentTimeMillis() if (currentTime - 20000 <= lastNetworkTestTime) { Timber.d("CDN was set less than 20 seconds ago, skipping...") + if (lastSuccessfulBaseCDN.isNotBlank()) RetrofitUrlManager.getInstance().putDomain("nmb", lastSuccessfulBaseCDN) + if (lastSuccessfulRefCDN.isNotBlank()) RetrofitUrlManager.getInstance().putDomain("nmb-ref", lastSuccessfulRefCDN) return } lastNetworkTestTime = currentTime @@ -566,12 +606,12 @@ class MainActivity : DaggerAppCompatActivity() { val ref = applicationDataStore.getRefCDN() if (ref != "auto") { Timber.d("Setting ref CDN to $ref") - RetrofitUrlManager.getInstance().putDomain("adnmb-ref", ref) + RetrofitUrlManager.getInstance().putDomain("nmb-ref", ref) } if (base != "auto") { Timber.i("Setting base CDN to $base...") - RetrofitUrlManager.getInstance().putDomain("adnmb", base) + RetrofitUrlManager.getInstance().putDomain("nmb", base) } if (ref != "auto" && base != "auto") return Timber.i("Auto selecting CDNs...") @@ -600,16 +640,18 @@ class MainActivity : DaggerAppCompatActivity() { // Base if (base == "auto" && availableConnections.firstKey() == timeElapsed) { Timber.d("Using $url for Base") - RetrofitUrlManager.getInstance().putDomain("adnmb", url) + lastSuccessfulBaseCDN = url + RetrofitUrlManager.getInstance().putDomain("nmb", lastSuccessfulBaseCDN) } // Ref if (ref == "auto") { - availableConnections.values.toList().firstOrNull { it in refCDNs } - ?.let { - Timber.d("Using $it for Ref") - RetrofitUrlManager.getInstance().putDomain("adnmb-ref", url) - } + availableConnections.values.toList().firstOrNull { it in refCDNs }?.let { + Timber.d("Using $it for Ref") + lastSuccessfulRefCDN = url + RetrofitUrlManager.getInstance().putDomain("nmb-ref", lastSuccessfulRefCDN) + } } + sharedVM.hostChange.postValue(SingleLiveEvent.create(true)) } } } catch (e: Exception) { diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/SharedViewModel.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/SharedViewModel.kt index 8d7fc1b4..bc232e34 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/SharedViewModel.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/SharedViewModel.kt @@ -29,10 +29,7 @@ import com.laotoua.dawnislandk.data.remote.APIMessageResponse import com.laotoua.dawnislandk.data.remote.NMBServiceClient import com.laotoua.dawnislandk.data.repository.CommunityRepository import com.laotoua.dawnislandk.screens.util.ContentTransformation -import com.laotoua.dawnislandk.util.DataResource -import com.laotoua.dawnislandk.util.LoadingStatus -import com.laotoua.dawnislandk.util.ReadableTime -import com.laotoua.dawnislandk.util.SingleLiveEvent +import com.laotoua.dawnislandk.util.* import kotlinx.coroutines.delay import kotlinx.coroutines.launch import timber.log.Timber @@ -71,11 +68,37 @@ class SharedViewModel @Inject constructor( private var forumMsgMapping = mapOf() - var timelineNameMapping = mapOf() - private set + private var timelineNameMapping = mapOf() private var timelineMsgMapping = mapOf() - var forumRefresh = false + var forceRefresh = false + val hostChange: MutableLiveData> = MutableLiveData() + + // TODO: clear cache when domain change + val currentDomain: MutableLiveData = MutableLiveData() + + var beitaiForums: List = listOf() + private set + + fun onADNMB() { + DawnApp.onDomain(DawnConstants.ADNMBDomain) + currentDomain.value = DawnConstants.ADNMBDomain + communityList.value?.data?.filterNot { it.isCommonForums() || it.isCommonPosts() }?.map { it.forums }?.flatten()?.let { flatten -> + forumNameMapping = flatten.associateBy(keySelector = { it.id }, valueTransform = { it.name }) + forumMsgMapping = flatten.associateBy(keySelector = { it.id }, valueTransform = { it.msg }) + } + + } + + fun onTNMB() { + DawnApp.onDomain(DawnConstants.TNMBDomain) + currentDomain.value = DawnConstants.TNMBDomain + beitaiForums.firstOrNull()?.forums?.let { + forumNameMapping = it.associateBy(keySelector = { it.id }, valueTransform = { it.name }) + } + forumMsgMapping = emptyMap() + + } init { getRandomReedPicture() @@ -159,6 +182,10 @@ class SharedViewModel @Inject constructor( forumMsgMapping = flatten.associateBy(keySelector = { it.id }, valueTransform = { it.msg }) } + fun setBeiTaiForums(list: List) { + beitaiForums = listOf(Community(id = "beitai", sort = "", name = "备胎", status = "", forums = list.map { it.toForum() }, domain = DawnConstants.TNMBDomain)) + } + fun setTimelineMappings(list: List) { timelineNameMapping = list.associateBy({ it.id }, { it.name }) timelineMsgMapping = list.associateBy({ it.id }, { it.notice }) @@ -175,9 +202,9 @@ class SharedViewModel @Inject constructor( } // timeline has `-` prefix, otherwise is just regular forum - fun setForumId(fid: String) { + fun setForumId(fid: String, refresh: Boolean = false) { Timber.d("Setting forum to id: $fid") - forumRefresh = _selectedForumId.value == fid + forceRefresh = refresh || _selectedForumId.value == fid _selectedForumId.value = fid } @@ -194,7 +221,13 @@ class SharedViewModel @Inject constructor( return if (mid.isBlank()) "" else timelineMsgMapping[mid] ?: "" } - fun getForumOrTimelineDisplayName(fid: String): String = if (fid.startsWith("-")) getTimelineDisplayName(fid) else getForumDisplayName(fid) + fun getForumOrTimelineDisplayName(fid: String): String { + return if (DawnApp.currentDomain == DawnConstants.ADNMBDomain) { + if (fid.startsWith("-")) getTimelineDisplayName(fid) else getForumDisplayName(fid) + } else { + beitaiForums.firstOrNull()?.forums?.find { it.id == fid }?.getDisplayName() ?: "备胎岛" + } + } private fun getForumDisplayName(fid: String): String = if (fid.isBlank()) "" else forumNameMapping[fid] ?: "A岛" @@ -274,7 +307,7 @@ class SharedViewModel @Inject constructor( if (post.userid == draft.cookieName && striped == draft.content) { // store server's copy draft.content = post.content - postHistoryDao.insertPostHistory(PostHistory(post.id, 1, post.img, post.ext, draft)) + postHistoryDao.insertPostHistory(PostHistory(post.id, 1, post.img, post.ext, DawnApp.currentDomain, draft)) saved = true _savePostStatus.postValue(SingleLiveEvent.create(true)) Timber.d("Saved new post with id ${post.id}") @@ -331,7 +364,7 @@ class SharedViewModel @Inject constructor( if (reply.userid == draft.cookieName && striped == draft.content) { // store server's copy draft.content = reply.content - postHistoryDao.insertPostHistory(PostHistory(reply.id, targetPage, reply.img, reply.ext, draft)) + postHistoryDao.insertPostHistory(PostHistory(reply.id, targetPage, reply.img, reply.ext, DawnApp.currentDomain, draft)) _savePostStatus.postValue(SingleLiveEvent.create(true)) Timber.d("Saved posted comment with id ${reply.id}") return diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/adapters/BaseViewHolderConversions.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/adapters/BaseViewHolderConversions.kt index 36df93f2..bdac24e7 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/adapters/BaseViewHolderConversions.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/adapters/BaseViewHolderConversions.kt @@ -35,7 +35,6 @@ import com.laotoua.dawnislandk.screens.util.ContentTransformation import com.laotoua.dawnislandk.screens.widgets.ClickableMovementMethod import com.laotoua.dawnislandk.screens.widgets.spans.ReferenceSpan import com.laotoua.dawnislandk.screens.widgets.spans.RoundBackgroundColorSpan -import com.laotoua.dawnislandk.util.DawnConstants import com.laotoua.dawnislandk.util.GlideApp import java.time.LocalDateTime @@ -120,7 +119,7 @@ fun BaseViewHolder.convertImage(imgUrl: String, visible: Boolean = true): BaseVi if (imgUrl.isNotBlank() && visible) { val imageView = getView(R.id.attachedImage) GlideApp.with(imageView) - .load(DawnConstants.thumbCDN + imgUrl) + .load(DawnApp.currentThumbCDN + imgUrl) // .override(400, 400) .fitCenter() .into(imageView) diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/adapters/CommunityNodeAdapter.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/adapters/CommunityNodeAdapter.kt index 65b9fbbf..e5ca62fe 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/adapters/CommunityNodeAdapter.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/adapters/CommunityNodeAdapter.kt @@ -75,8 +75,9 @@ class CommunityNodeAdapter(val forumClickListener: ForumClickListener, val timel private fun setData() { val nodes = mutableListOf() // Timelines - val timelineCommunity = TimelineCommunityNode(timelines) - nodes.add(timelineCommunity) + if (timelines.isNotEmpty()) { + nodes.add(TimelineCommunityNode(timelines)) + } // Communities val commonForumIds = communities.firstOrNull { it.isCommonForums() }?.forums?.map { it.id } ?: emptyList() for (c in communities) { @@ -92,6 +93,7 @@ class CommunityNodeAdapter(val forumClickListener: ForumClickListener, val timel nodes.add(CommunityNode(noDuplicateCommunity)) } } + if (nodes.size == 1 && nodes.first() is BaseExpandNode) (nodes.first() as BaseExpandNode).isExpanded = true setList(nodes) } diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/comments/CommentsFragment.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/comments/CommentsFragment.kt index 99ce7e66..c66fca47 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/comments/CommentsFragment.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/comments/CommentsFragment.kt @@ -20,6 +20,7 @@ package com.laotoua.dawnislandk.screens.comments import android.animation.Animator import android.animation.AnimatorListenerAdapter +import android.annotation.SuppressLint import android.content.ClipData import android.content.ClipboardManager import android.content.Intent @@ -93,6 +94,7 @@ class CommentsFragment : DaggerFragment() { private var mAdapter: QuickAdapter? = null private var viewCaching = false + private var cacheDomain = DawnConstants.ADNMBDomain private var refreshing = false // last visible item indicates the current page, uses for remembering last read page @@ -162,6 +164,7 @@ class CommentsFragment : DaggerFragment() { } } + @SuppressLint("CheckResult") override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -366,7 +369,7 @@ class CommentsFragment : DaggerFragment() { } 1 -> copyText( "串地址", - "${DawnConstants.nmbHost}/t/${viewModel.currentPostId}" + "${DawnApp.currentDomain}/t/${viewModel.currentPostId}" ) 2 -> copyText("串号", ">>No.${viewModel.currentPostId}") else -> { @@ -456,6 +459,13 @@ class CommentsFragment : DaggerFragment() { } } } + + sharedVM.currentDomain.observe(viewLifecycleOwner) { + if (it != cacheDomain) { + viewModel.clearCache(true) + cacheDomain = it + } + } } override fun onPause() { diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/comments/CommentsViewModel.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/comments/CommentsViewModel.kt index 1a473ba8..f7aa1ec8 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/comments/CommentsViewModel.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/comments/CommentsViewModel.kt @@ -186,12 +186,16 @@ class CommentsViewModel @Inject constructor( Timber.d("Got ${comments.value?.size} after merging on $targetPage") } - private fun clearCache(clearFilter: Boolean) { + fun clearCache(clearFilter: Boolean, clearEverything: Boolean = false) { listeningPagesIndices.map { i -> listeningPages[i]?.let { s -> comments.removeSource(s) } } listeningPages.clear() listeningPagesIndices.clear() commentList.clear() if (clearFilter) filterIds.clear() + if (clearEverything) { + quoteRepo.clearCache() + commentRepo.clearCache() + } } fun onlyPo() { @@ -225,7 +229,7 @@ class CommentsViewModel @Inject constructor( } fun getExternalShareContent(): String { - return "${ContentTransformation.htmlToSpanned(commentRepo.getHeaderPost(currentPostId)?.content.toString())}\n\n${DawnConstants.nmbHost}/t/${currentPostId}\n" + return "${ContentTransformation.htmlToSpanned(commentRepo.getHeaderPost(currentPostId)?.content.toString())}\n\n${DawnConstants.ADNMBHost}/t/${currentPostId}\n" } fun addFeed(id: String) { diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/comments/QuotePopup.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/comments/QuotePopup.kt index f5bf7735..a6a0d2c6 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/comments/QuotePopup.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/comments/QuotePopup.kt @@ -34,7 +34,6 @@ import com.laotoua.dawnislandk.screens.util.ContentTransformation.transformTime import com.laotoua.dawnislandk.screens.widgets.popups.ImageViewerPopup import com.laotoua.dawnislandk.screens.widgets.spans.ReferenceSpan import com.laotoua.dawnislandk.util.DataResource -import com.laotoua.dawnislandk.util.DawnConstants import com.laotoua.dawnislandk.util.GlideApp import com.laotoua.dawnislandk.util.LoadingStatus import com.lxj.xpopup.XPopup @@ -123,7 +122,7 @@ class QuotePopup( findViewById(R.id.attachedImage).run { visibility = if (quote.img.isNotBlank()) { GlideApp.with(context) - .load(DawnConstants.thumbCDN + quote.img + quote.ext) + .load(DawnApp.currentThumbCDN + quote.img + quote.ext) // .override(250, 250) .fitCenter() .into(this) diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/history/BrowsingHistoryFragment.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/history/BrowsingHistoryFragment.kt index 11c8ab5d..5e034c85 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/history/BrowsingHistoryFragment.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/history/BrowsingHistoryFragment.kt @@ -44,6 +44,7 @@ import com.laotoua.dawnislandk.screens.posts.PostCardFactory import com.laotoua.dawnislandk.screens.util.Layout.toast import com.laotoua.dawnislandk.screens.widgets.BaseNavFragment import com.laotoua.dawnislandk.screens.widgets.popups.ImageViewerPopup +import com.laotoua.dawnislandk.util.DawnConstants import com.laotoua.dawnislandk.util.ReadableTime import com.lxj.xpopup.XPopup import timber.log.Timber @@ -66,6 +67,8 @@ class BrowsingHistoryFragment : BaseNavFragment() { private val viewModel: BrowsingHistoryViewModel by viewModels { viewModelFactory } + private var cacheDomain: String = DawnConstants.ADNMBDomain + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -152,6 +155,14 @@ class BrowsingHistoryFragment : BaseNavFragment() { ) Timber.i("${this.javaClass.simpleName} Adapter will have ${list.size} items") } + + sharedVM.currentDomain.observe(viewLifecycleOwner) { + if (it != cacheDomain) { + viewModel.searchByDate() + cacheDomain = it + } + } + viewCaching = false return binding!!.root } diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/history/PostHistoryFragment.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/history/PostHistoryFragment.kt index 4eb1dce9..0e646d66 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/history/PostHistoryFragment.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/history/PostHistoryFragment.kt @@ -46,6 +46,7 @@ import com.laotoua.dawnislandk.screens.util.Layout.toast import com.laotoua.dawnislandk.screens.widgets.BaseNavFragment import com.laotoua.dawnislandk.screens.widgets.SectionHeader import com.laotoua.dawnislandk.screens.widgets.popups.ImageViewerPopup +import com.laotoua.dawnislandk.util.DawnConstants import com.laotoua.dawnislandk.util.ReadableTime import com.lxj.xpopup.XPopup import timber.log.Timber @@ -62,6 +63,7 @@ class PostHistoryFragment : BaseNavFragment() { private var binding: FragmentHistoryPostBinding? = null private var mAdapter: QuickMultiBinder? = null private var viewCaching = false + private var cacheDomain = DawnConstants.ADNMBDomain private val viewModel: PostHistoryViewModel by viewModels { viewModelFactory } @@ -137,6 +139,14 @@ class PostHistoryFragment : BaseNavFragment() { } displayList(list) } + + sharedVM.currentDomain.observe(viewLifecycleOwner) { + if (it != cacheDomain) { + viewModel.searchByDate() + cacheDomain = it + } + } + viewCaching = false return binding!!.root } diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/notification/NotificationFragment.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/notification/NotificationFragment.kt index a2885a1f..1d320d92 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/notification/NotificationFragment.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/notification/NotificationFragment.kt @@ -26,6 +26,7 @@ import android.view.* import android.widget.TextView import androidx.fragment.app.activityViewModels import androidx.fragment.app.viewModels +import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.DiffUtil @@ -51,6 +52,7 @@ import com.laotoua.dawnislandk.screens.posts.PostCardFactory import com.laotoua.dawnislandk.screens.util.ContentTransformation import com.laotoua.dawnislandk.screens.util.Layout import com.laotoua.dawnislandk.screens.widgets.spans.RoundBackgroundColorSpan +import com.laotoua.dawnislandk.util.DawnConstants import dagger.android.support.DaggerFragment import javax.inject.Inject @@ -64,6 +66,12 @@ class NotificationFragment : DaggerFragment() { private var binding: FragmentNotificationBinding? = null private var mAdapter: NotificationAdapter? = null + private var cacheDomain: String = DawnConstants.ADNMBDomain + + private val notificationObs = Observer> { list -> + if (list.isNullOrEmpty()) mAdapter?.showNoData() + else mAdapter?.setDiffNewData(list.toMutableList()) + } override fun onCreate(savedInstanceState: Bundle?) { @@ -124,11 +132,16 @@ class NotificationFragment : DaggerFragment() { } mAdapter?.setEmptyView(R.layout.view_no_data) - viewModel.notificationAndPost.observe(viewLifecycleOwner) { list -> - if (list.isNullOrEmpty()) mAdapter?.showNoData() - else mAdapter?.setDiffNewData(list.toMutableList()) - } + viewModel.notificationAndPost.observe(viewLifecycleOwner, notificationObs) + + sharedVM.currentDomain.observe(viewLifecycleOwner) { + if (it != cacheDomain) { + viewModel.refresh() + viewModel.notificationAndPost.observe(viewLifecycleOwner, notificationObs) + cacheDomain = it + } + } // Inflate the layout for this fragment return binding!!.root } diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/notification/NotificationViewModel.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/notification/NotificationViewModel.kt index 6f73bc1d..81d203b4 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/notification/NotificationViewModel.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/notification/NotificationViewModel.kt @@ -25,19 +25,24 @@ import kotlinx.coroutines.launch import javax.inject.Inject class NotificationViewModel @Inject constructor(private val notificationDao: NotificationDao):ViewModel() { - val notificationAndPost = notificationDao.getLiveAllNotificationsAndPosts() + var notificationAndPost = notificationDao.getLiveAllNotificationsAndPosts() + private set - fun deleteNotification(notification: Notification){ + fun deleteNotification(notification: Notification) { viewModelScope.launch { notificationDao.deleteNotifications(notification) } } - fun readNotification(notification: Notification){ + fun readNotification(notification: Notification) { viewModelScope.launch { notification.read = true notification.newReplyCount = 0 notificationDao.insertNotification(notification) } } + + fun refresh() { + notificationAndPost = notificationDao.getLiveAllNotificationsAndPosts() + } } \ No newline at end of file diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/posts/PostsFragment.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/posts/PostsFragment.kt index 8a50019f..706dd524 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/posts/PostsFragment.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/posts/PostsFragment.kt @@ -17,6 +17,7 @@ package com.laotoua.dawnislandk.screens.posts +import android.annotation.SuppressLint import android.os.Bundle import android.view.* import android.view.animation.AnimationUtils @@ -63,6 +64,7 @@ class PostsFragment : BaseNavFragment() { private var isFabOpen = false private var viewCaching = false private var refreshing = false + private var cacheDomain = "" override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -131,7 +133,7 @@ class PostsFragment : BaseNavFragment() { message(text = sharedVM.getForumOrTimelineMsg(fid)) { html { link -> val uri = if (link.startsWith("/")) { - DawnConstants.nmbHost + link + DawnConstants.ADNMBHost + link } else link openLinksWithOtherApps(uri, requireActivity()) } @@ -139,7 +141,7 @@ class PostsFragment : BaseNavFragment() { positiveButton(R.string.acknowledge) @Suppress("DEPRECATION") neutralButton(R.string.basic_rules) { - openLinksWithOtherApps(DawnConstants.nmbHost + "/forum", requireActivity()) + openLinksWithOtherApps(DawnConstants.ADNMBHost + "/forum", requireActivity()) } } return true @@ -153,6 +155,7 @@ class PostsFragment : BaseNavFragment() { } } + @SuppressLint("CheckResult") override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -388,11 +391,25 @@ class PostsFragment : BaseNavFragment() { if (viewModel.currentFid != it) { refreshing = true viewModel.setForum(it) - sharedVM.forumRefresh = false - } else if (sharedVM.forumRefresh) { + sharedVM.forceRefresh = false + } else if (sharedVM.forceRefresh) { refreshing = true viewModel.refresh() - sharedVM.forumRefresh = false + sharedVM.forceRefresh = false + } + } + + sharedVM.hostChange.observe(viewLifecycleOwner) { + if (it.getContentIfNotHandled() == true && viewModel.posts.value.isNullOrEmpty()) { + viewModel.refresh() + } + } + + sharedVM.currentDomain.observe(viewLifecycleOwner) { + if (it != cacheDomain) { + viewModel.clearCache() + viewModel.getBlockedIds() + cacheDomain = it } } diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/posts/PostsViewModel.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/posts/PostsViewModel.kt index 25ba93d6..cd360206 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/posts/PostsViewModel.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/posts/PostsViewModel.kt @@ -55,20 +55,27 @@ class PostsViewModel @Inject constructor( val loadingStatus: LiveData>> get() = _loadingStatus - fun getPosts() { + init { + getBlockedIds() + } + + fun getBlockedIds() { viewModelScope.launch { - if (blockedPostIds == null || blockedForumIds == null) { - val blockedIds = blockedIdDao.getAllBlockedIds() - blockedPostIds = mutableListOf() - blockedForumIds = mutableListOf() - for (blockedId in blockedIds) { - if (blockedId.isBlockedPost()) { - blockedPostIds!!.add(blockedId.id) - } else if (blockedId.isTimelineBlockedForum()) { - blockedForumIds!!.add(blockedId.id) - } + val blockedIds = blockedIdDao.getAllBlockedIds() + blockedPostIds = mutableListOf() + blockedForumIds = mutableListOf() + for (blockedId in blockedIds) { + if (blockedId.isBlockedPost()) { + blockedPostIds!!.add(blockedId.id) + } else if (blockedId.isTimelineBlockedForum()) { + blockedForumIds!!.add(blockedId.id) } } + } + } + + fun getPosts() { + viewModelScope.launch { _loadingStatus.postValue(SingleLiveEvent.create(LoadingStatus.LOADING)) val fid = _currentFid ?: "-1" Timber.d("Getting threads from $fid on page $pageCount") @@ -123,22 +130,24 @@ class PostsViewModel @Inject constructor( } } - fun setForum(fid: String) { - if (fid == currentFid) return + fun setForum(fid: String, forceRefresh: Boolean = false) { + if (fid == currentFid && !forceRefresh) return Timber.i("Forum has changed. Cleaning old threads...") - postList.clear() - postIds.clear() + clearCache() Timber.d("Setting new forum: $fid") _currentFid = fid - pageCount = 1 getPosts() } - fun refresh() { - Timber.d("Refreshing forum $currentFid...") + fun clearCache() { postList.clear() postIds.clear() pageCount = 1 + } + + fun refresh() { + Timber.d("Refreshing forum $currentFid...") + clearCache() getPosts() } diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/profile/CommonForumsFragment.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/profile/CommonForumsFragment.kt index cefedcf7..552ac1a8 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/profile/CommonForumsFragment.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/profile/CommonForumsFragment.kt @@ -33,6 +33,7 @@ import com.chad.library.adapter.base.listener.OnItemDragListener import com.chad.library.adapter.base.listener.OnItemSwipeListener import com.chad.library.adapter.base.module.DraggableModule import com.chad.library.adapter.base.viewholder.BaseViewHolder +import com.laotoua.dawnislandk.DawnApp import com.laotoua.dawnislandk.R import com.laotoua.dawnislandk.data.local.entity.Community import com.laotoua.dawnislandk.data.local.entity.Forum @@ -139,7 +140,7 @@ class CommonForumsFragment : DaggerFragment() { } override fun onDestroyView() { - val common = Community.makeCommonForums(commonForumAdapter?.data ?: emptyList()) + val common = Community.makeCommonForums(commonForumAdapter?.data ?: emptyList(), DawnApp.currentDomain) sharedVM.saveCommonCommunity(common) toast(R.string.might_need_to_restart_to_apply_setting) super.onDestroyView() diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/profile/CommonPostsFragment.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/profile/CommonPostsFragment.kt index 57961b3f..15842846 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/profile/CommonPostsFragment.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/profile/CommonPostsFragment.kt @@ -39,6 +39,7 @@ import com.chad.library.adapter.base.listener.OnItemSwipeListener import com.chad.library.adapter.base.module.DraggableModule import com.chad.library.adapter.base.viewholder.BaseViewHolder import com.google.android.material.textfield.TextInputLayout +import com.laotoua.dawnislandk.DawnApp import com.laotoua.dawnislandk.R import com.laotoua.dawnislandk.data.local.entity.Community import com.laotoua.dawnislandk.data.local.entity.Forum @@ -196,7 +197,7 @@ class CommonPostsFragment : DaggerFragment() { } override fun onDestroyView() { - val common = Community.makeCommonPosts(commonPostsAdapter?.data ?: emptyList()) + val common = Community.makeCommonPosts(commonPostsAdapter?.data ?: emptyList(), DawnApp.currentDomain) sharedVM.saveCommonCommunity(common) toast(R.string.might_need_to_restart_to_apply_setting) super.onDestroyView() diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/subscriptions/FeedsFragment.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/subscriptions/FeedsFragment.kt index eac082b2..3e3cf322 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/subscriptions/FeedsFragment.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/subscriptions/FeedsFragment.kt @@ -17,6 +17,7 @@ package com.laotoua.dawnislandk.screens.subscriptions +import android.annotation.SuppressLint import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -49,11 +50,13 @@ import com.laotoua.dawnislandk.screens.util.Layout.toast import com.laotoua.dawnislandk.screens.util.Layout.updateHeaderAndFooter import com.laotoua.dawnislandk.screens.widgets.BaseNavFragment import com.laotoua.dawnislandk.screens.widgets.popups.ImageViewerPopup +import com.laotoua.dawnislandk.util.DawnConstants import com.lxj.xpopup.XPopup import me.dkzwm.widget.srl.RefreshingListenerAdapter import me.dkzwm.widget.srl.config.Constants import timber.log.Timber import java.util.* +import kotlin.collections.ArrayList class FeedsFragment : BaseNavFragment() { @@ -71,6 +74,9 @@ class FeedsFragment : BaseNavFragment() { private var viewCaching = false private var refreshing = false + private var cacheDomain = DawnConstants.ADNMBDomain + + @SuppressLint("CheckResult") override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -201,6 +207,13 @@ class FeedsFragment : BaseNavFragment() { binding?.srlAndRv?.refreshLayout?.autoRefresh(Constants.ACTION_NOTIFY, false) } + sharedVM.currentDomain.observe(viewLifecycleOwner) { + if (it != cacheDomain) { + viewModel.clearCache(true) + cacheDomain = it + } + } + viewCaching = false return binding!!.root } diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/subscriptions/FeedsViewModel.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/subscriptions/FeedsViewModel.kt index 5d4a0ab0..95a7b11a 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/subscriptions/FeedsViewModel.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/subscriptions/FeedsViewModel.kt @@ -109,12 +109,17 @@ class FeedsViewModel @Inject constructor(private val feedRepo: FeedRepository) : } } - private fun clearCache() { + fun clearCache(forceClear: Boolean = false) { feedPageIndices.map { feedPages[it]?.let { s -> feeds.removeSource(s) } feedPages.remove(it) } feedPageIndices.clear() + if (forceClear) { + feeds.value = ArrayList() + lastJumpPage = 0 + feedRepo.clearCache() + } } } diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/subscriptions/TrendsFragment.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/subscriptions/TrendsFragment.kt index 72657ba3..42f99816 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/subscriptions/TrendsFragment.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/subscriptions/TrendsFragment.kt @@ -41,13 +41,10 @@ import com.laotoua.dawnislandk.screens.adapters.* import com.laotoua.dawnislandk.screens.posts.PostCardFactory import com.laotoua.dawnislandk.screens.util.Layout.updateHeaderAndFooter import com.laotoua.dawnislandk.screens.widgets.BaseNavFragment -import com.laotoua.dawnislandk.util.DataResource -import com.laotoua.dawnislandk.util.EventPayload -import com.laotoua.dawnislandk.util.LoadingStatus -import com.laotoua.dawnislandk.util.ReadableTime +import com.laotoua.dawnislandk.util.* import me.dkzwm.widget.srl.RefreshingListenerAdapter import timber.log.Timber -import java.util.ArrayList +import java.util.* class TrendsFragment : BaseNavFragment() { @@ -64,7 +61,7 @@ class TrendsFragment : BaseNavFragment() { private val viewModel: TrendsViewModel by viewModels { viewModelFactory } private val trendsObs = Observer>> { - if (mAdapter == null || binding == null) return@Observer + if (mAdapter == null || binding == null || sharedVM.currentDomain.value == DawnConstants.TNMBDomain) return@Observer updateHeaderAndFooter( binding!!.srlAndRv.refreshLayout, mAdapter!!, @@ -146,6 +143,15 @@ class TrendsFragment : BaseNavFragment() { } + sharedVM.currentDomain.observe(viewLifecycleOwner) { + if (it == DawnConstants.TNMBDomain) { + mAdapter?.showNoData() + mAdapter?.setDiffNewData(ArrayList()) + if (binding != null) mAdapter?.setFooterView(layoutInflater.inflate(R.layout.view_no_more_data, binding!!.srlAndRv.recyclerView, false)) + + } + } + viewModel.latestTrends.observe(viewLifecycleOwner, trendsObs) viewCaching = false return binding!!.root diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/widgets/BasePagerFragment.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/widgets/BasePagerFragment.kt index d62b1a1a..219a404e 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/widgets/BasePagerFragment.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/widgets/BasePagerFragment.kt @@ -116,8 +116,7 @@ abstract class BasePagerFragment : DaggerFragment() { object : FragmentStateAdapter(childFragmentManager, viewLifecycleOwner.lifecycle) { override fun getItemCount(): Int = pageFragmentClass.size override fun createFragment(position: Int): Fragment { - return pageFragmentClass[position]?.newInstance() - ?: error("Missing Fragment Class") + return pageFragmentClass[position]?.newInstance() ?: error("Missing Fragment Class") } } diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/widgets/popups/ForumDrawerPopup.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/widgets/popups/ForumDrawerPopup.kt index f605c628..937858f5 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/widgets/popups/ForumDrawerPopup.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/widgets/popups/ForumDrawerPopup.kt @@ -28,6 +28,7 @@ import androidx.navigation.findNavController import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.google.android.material.button.MaterialButton +import com.laotoua.dawnislandk.DawnApp import com.laotoua.dawnislandk.MainNavDirections import com.laotoua.dawnislandk.R import com.laotoua.dawnislandk.data.local.entity.Community @@ -36,6 +37,7 @@ import com.laotoua.dawnislandk.data.local.entity.Timeline import com.laotoua.dawnislandk.screens.MainActivity import com.laotoua.dawnislandk.screens.SharedViewModel import com.laotoua.dawnislandk.screens.adapters.CommunityNodeAdapter +import com.laotoua.dawnislandk.util.DawnConstants import com.laotoua.dawnislandk.util.GlideApp import com.lxj.xpopup.XPopup import com.lxj.xpopup.core.DrawerPopupView @@ -148,5 +150,24 @@ class ForumDrawerPopup( } } } + + + findViewById(R.id.hostToggle).apply { + when (DawnApp.currentDomain) { + DawnConstants.ADNMBDomain -> { + text = "B(*゚∇゚)T" + } + DawnConstants.TNMBDomain -> { + text = "A(*´∀`)A" + } + } + setOnClickListener { + if (!isShow) return@setOnClickListener + dismissWith { + if (DawnApp.currentDomain == DawnConstants.TNMBDomain) (context as MainActivity).goToADNMB() + else (context as MainActivity).goToTNMB() + } + } + } } } \ No newline at end of file diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/widgets/popups/ImageViewerPopup.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/widgets/popups/ImageViewerPopup.kt index 2ef1f790..847a4513 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/widgets/popups/ImageViewerPopup.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/widgets/popups/ImageViewerPopup.kt @@ -42,13 +42,13 @@ import androidx.transition.* import androidx.viewpager.widget.PagerAdapter import androidx.viewpager.widget.ViewPager.SimpleOnPageChangeListener import com.google.android.material.floatingactionbutton.FloatingActionButton +import com.laotoua.dawnislandk.DawnApp import com.laotoua.dawnislandk.R import com.laotoua.dawnislandk.data.local.entity.Comment import com.laotoua.dawnislandk.data.local.entity.Post import com.laotoua.dawnislandk.data.local.entity.PostHistory import com.laotoua.dawnislandk.data.remote.SearchResult import com.laotoua.dawnislandk.screens.MainActivity -import com.laotoua.dawnislandk.util.DawnConstants import com.laotoua.dawnislandk.util.ImageUtil import com.laotoua.dawnislandk.util.ReadableTime import com.laotoua.dawnislandk.util.SingleLiveEvent @@ -682,6 +682,6 @@ class ImageViewerPopup(context: Context) : BasePopupView(context), OnDragChangeL } } - return if (uri.startsWith("http")) uri else DawnConstants.imageCDN + uri + return if (uri.startsWith("http")) uri else DawnApp.currentImgCDN + uri } } \ No newline at end of file diff --git a/app/src/main/java/com/laotoua/dawnislandk/screens/widgets/popups/PostPopup.kt b/app/src/main/java/com/laotoua/dawnislandk/screens/widgets/popups/PostPopup.kt index 93f4ff51..2697d362 100644 --- a/app/src/main/java/com/laotoua/dawnislandk/screens/widgets/popups/PostPopup.kt +++ b/app/src/main/java/com/laotoua/dawnislandk/screens/widgets/popups/PostPopup.kt @@ -41,6 +41,7 @@ import com.afollestad.materialdialogs.lifecycle.lifecycleOwner import com.afollestad.materialdialogs.list.listItemsSingleChoice import com.google.android.material.button.MaterialButtonToggleGroup import com.google.android.material.textfield.TextInputLayout +import com.laotoua.dawnislandk.DawnApp import com.laotoua.dawnislandk.DawnApp.Companion.applicationDataStore import com.laotoua.dawnislandk.R import com.laotoua.dawnislandk.data.local.entity.Cookie @@ -229,6 +230,7 @@ class PostPopup(private val caller: MainActivity, private val sharedVM: SharedVi KeyboardUtils.hideSoftInput(postContent) } + @SuppressLint("CheckResult") override fun onCreate() { super.onCreate() postContent = findViewById(R.id.postContent).apply { @@ -331,9 +333,9 @@ class PostPopup(private val caller: MainActivity, private val sharedVM: SharedVi } }.onDismiss { if (targetId == null) return@onDismiss - postContent?.editText?.hint = - applicationDataStore.luweiNotice?.nmbForums?.firstOrNull { f -> f.id == targetId } - ?.getPostRule() + if (DawnApp.currentDomain == DawnConstants.ADNMBDomain) { + postContent?.editText?.hint = applicationDataStore.luweiNotice?.nmbForums?.firstOrNull { f -> f.id == targetId }?.getPostRule() + } updateTitle(targetId, newPost) if (postForum!!.text == "值班室") { MaterialDialog(context).show { @@ -483,22 +485,23 @@ class PostPopup(private val caller: MainActivity, private val sharedVM: SharedVi } findViewById