commit
3d779f3fb0
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,50 @@ |
|||||||
|
package io.legado.app |
||||||
|
|
||||||
|
import androidx.room.Room |
||||||
|
import androidx.room.migration.Migration |
||||||
|
import androidx.room.testing.MigrationTestHelper |
||||||
|
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory |
||||||
|
import androidx.test.platform.app.InstrumentationRegistry |
||||||
|
import androidx.test.runner.AndroidJUnit4 |
||||||
|
import io.legado.app.data.AppDatabase |
||||||
|
import org.junit.Rule |
||||||
|
import org.junit.Test |
||||||
|
import org.junit.runner.RunWith |
||||||
|
import java.io.IOException |
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4::class) |
||||||
|
class MigrationTest { |
||||||
|
private val TEST_DB = "migration-test" |
||||||
|
|
||||||
|
private val ALL_MIGRATIONS = arrayOf<Migration>( |
||||||
|
|
||||||
|
) |
||||||
|
|
||||||
|
@Rule |
||||||
|
val helper: MigrationTestHelper = MigrationTestHelper( |
||||||
|
InstrumentationRegistry.getInstrumentation(), |
||||||
|
AppDatabase::class.java.canonicalName, |
||||||
|
FrameworkSQLiteOpenHelperFactory() |
||||||
|
) |
||||||
|
|
||||||
|
@Test |
||||||
|
@Throws(IOException::class) |
||||||
|
fun migrateAll() { |
||||||
|
// Create earliest version of the database. |
||||||
|
helper.createDatabase(TEST_DB, 30).apply { |
||||||
|
close() |
||||||
|
} |
||||||
|
|
||||||
|
// Open latest version of the database. Room will validate the schema |
||||||
|
// once all migrations execute. |
||||||
|
Room.databaseBuilder( |
||||||
|
InstrumentationRegistry.getInstrumentation().targetContext, |
||||||
|
AppDatabase::class.java, |
||||||
|
TEST_DB |
||||||
|
).addMigrations(*ALL_MIGRATIONS) |
||||||
|
.build().apply { |
||||||
|
openHelper.writableDatabase |
||||||
|
close() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,283 @@ |
|||||||
|
package io.legado.app.data |
||||||
|
|
||||||
|
import androidx.room.migration.Migration |
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase |
||||||
|
import io.legado.app.constant.AppConst |
||||||
|
|
||||||
|
object DatabaseMigrations { |
||||||
|
|
||||||
|
val migrations: Array<Migration> by lazy { |
||||||
|
arrayOf( |
||||||
|
migration_10_11, |
||||||
|
migration_11_12, |
||||||
|
migration_12_13, |
||||||
|
migration_13_14, |
||||||
|
migration_14_15, |
||||||
|
migration_15_17, |
||||||
|
migration_17_18, |
||||||
|
migration_18_19, |
||||||
|
migration_19_20, |
||||||
|
migration_20_21, |
||||||
|
migration_21_22, |
||||||
|
migration_22_23, |
||||||
|
migration_23_24, |
||||||
|
migration_24_25, |
||||||
|
migration_25_26, |
||||||
|
migration_26_27, |
||||||
|
migration_27_28, |
||||||
|
migration_28_29, |
||||||
|
migration_29_30, |
||||||
|
migration_30_31, |
||||||
|
migration_31_32, |
||||||
|
migration_32_33, |
||||||
|
migration_33_34, |
||||||
|
migration_34_35 |
||||||
|
) |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_10_11 = object : Migration(10, 11) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL("DROP TABLE txtTocRules") |
||||||
|
database.execSQL( |
||||||
|
"""CREATE TABLE txtTocRules(id INTEGER NOT NULL, |
||||||
|
name TEXT NOT NULL, rule TEXT NOT NULL, serialNumber INTEGER NOT NULL, |
||||||
|
enable INTEGER NOT NULL, PRIMARY KEY (id))""" |
||||||
|
) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_11_12 = object : Migration(11, 12) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL("ALTER TABLE rssSources ADD style TEXT ") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_12_13 = object : Migration(12, 13) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL("ALTER TABLE rssSources ADD articleStyle INTEGER NOT NULL DEFAULT 0 ") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_13_14 = object : Migration(13, 14) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL( |
||||||
|
"""CREATE TABLE IF NOT EXISTS `books_new` (`bookUrl` TEXT NOT NULL, `tocUrl` TEXT NOT NULL, `origin` TEXT NOT NULL, |
||||||
|
`originName` TEXT NOT NULL, `name` TEXT NOT NULL, `author` TEXT NOT NULL, `kind` TEXT, `customTag` TEXT, `coverUrl` TEXT, |
||||||
|
`customCoverUrl` TEXT, `intro` TEXT, `customIntro` TEXT, `charset` TEXT, `type` INTEGER NOT NULL, `group` INTEGER NOT NULL, |
||||||
|
`latestChapterTitle` TEXT, `latestChapterTime` INTEGER NOT NULL, `lastCheckTime` INTEGER NOT NULL, `lastCheckCount` INTEGER NOT NULL, |
||||||
|
`totalChapterNum` INTEGER NOT NULL, `durChapterTitle` TEXT, `durChapterIndex` INTEGER NOT NULL, `durChapterPos` INTEGER NOT NULL, |
||||||
|
`durChapterTime` INTEGER NOT NULL, `wordCount` TEXT, `canUpdate` INTEGER NOT NULL, `order` INTEGER NOT NULL, |
||||||
|
`originOrder` INTEGER NOT NULL, `useReplaceRule` INTEGER NOT NULL, `variable` TEXT, PRIMARY KEY(`bookUrl`))""" |
||||||
|
) |
||||||
|
database.execSQL("INSERT INTO books_new select * from books ") |
||||||
|
database.execSQL("DROP TABLE books") |
||||||
|
database.execSQL("ALTER TABLE books_new RENAME TO books") |
||||||
|
database.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_books_name_author` ON `books` (`name`, `author`) ") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_14_15 = object : Migration(14, 15) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL("ALTER TABLE bookmarks ADD bookAuthor TEXT NOT NULL DEFAULT ''") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_15_17 = object : Migration(15, 17) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL("CREATE TABLE IF NOT EXISTS `readRecord` (`bookName` TEXT NOT NULL, `readTime` INTEGER NOT NULL, PRIMARY KEY(`bookName`))") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_17_18 = object : Migration(17, 18) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL("CREATE TABLE IF NOT EXISTS `httpTTS` (`id` INTEGER NOT NULL, `name` TEXT NOT NULL, `url` TEXT NOT NULL, PRIMARY KEY(`id`))") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_18_19 = object : Migration(18, 19) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL( |
||||||
|
"""CREATE TABLE IF NOT EXISTS `readRecordNew` (`androidId` TEXT NOT NULL, `bookName` TEXT NOT NULL, `readTime` INTEGER NOT NULL, |
||||||
|
PRIMARY KEY(`androidId`, `bookName`))""" |
||||||
|
) |
||||||
|
database.execSQL("INSERT INTO readRecordNew(androidId, bookName, readTime) select '${AppConst.androidId}' as androidId, bookName, readTime from readRecord") |
||||||
|
database.execSQL("DROP TABLE readRecord") |
||||||
|
database.execSQL("ALTER TABLE readRecordNew RENAME TO readRecord") |
||||||
|
} |
||||||
|
} |
||||||
|
private val migration_19_20 = object : Migration(19, 20) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL("ALTER TABLE book_sources ADD bookSourceComment TEXT") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_20_21 = object : Migration(20, 21) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL("ALTER TABLE book_groups ADD show INTEGER NOT NULL DEFAULT 1") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_21_22 = object : Migration(21, 22) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL( |
||||||
|
"""CREATE TABLE IF NOT EXISTS `books_new` (`bookUrl` TEXT NOT NULL, `tocUrl` TEXT NOT NULL, `origin` TEXT NOT NULL, |
||||||
|
`originName` TEXT NOT NULL, `name` TEXT NOT NULL, `author` TEXT NOT NULL, `kind` TEXT, `customTag` TEXT, |
||||||
|
`coverUrl` TEXT, `customCoverUrl` TEXT, `intro` TEXT, `customIntro` TEXT, `charset` TEXT, `type` INTEGER NOT NULL, |
||||||
|
`group` INTEGER NOT NULL, `latestChapterTitle` TEXT, `latestChapterTime` INTEGER NOT NULL, `lastCheckTime` INTEGER NOT NULL, |
||||||
|
`lastCheckCount` INTEGER NOT NULL, `totalChapterNum` INTEGER NOT NULL, `durChapterTitle` TEXT, `durChapterIndex` INTEGER NOT NULL, |
||||||
|
`durChapterPos` INTEGER NOT NULL, `durChapterTime` INTEGER NOT NULL, `wordCount` TEXT, `canUpdate` INTEGER NOT NULL, |
||||||
|
`order` INTEGER NOT NULL, `originOrder` INTEGER NOT NULL, `variable` TEXT, `readConfig` TEXT, PRIMARY KEY(`bookUrl`))""" |
||||||
|
) |
||||||
|
database.execSQL( |
||||||
|
"""INSERT INTO books_new select `bookUrl`, `tocUrl`, `origin`, `originName`, `name`, `author`, `kind`, `customTag`, `coverUrl`, |
||||||
|
`customCoverUrl`, `intro`, `customIntro`, `charset`, `type`, `group`, `latestChapterTitle`, `latestChapterTime`, `lastCheckTime`, |
||||||
|
`lastCheckCount`, `totalChapterNum`, `durChapterTitle`, `durChapterIndex`, `durChapterPos`, `durChapterTime`, `wordCount`, `canUpdate`, |
||||||
|
`order`, `originOrder`, `variable`, null |
||||||
|
from books""" |
||||||
|
) |
||||||
|
database.execSQL("DROP TABLE books") |
||||||
|
database.execSQL("ALTER TABLE books_new RENAME TO books") |
||||||
|
database.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_books_name_author` ON `books` (`name`, `author`) ") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_22_23 = object : Migration(22, 23) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL("ALTER TABLE chapters ADD baseUrl TEXT NOT NULL DEFAULT ''") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_23_24 = object : Migration(23, 24) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL("CREATE TABLE IF NOT EXISTS `caches` (`key` TEXT NOT NULL, `value` TEXT, `deadline` INTEGER NOT NULL, PRIMARY KEY(`key`))") |
||||||
|
database.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_caches_key` ON `caches` (`key`)") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_24_25 = object : Migration(24, 25) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL( |
||||||
|
"""CREATE TABLE IF NOT EXISTS `sourceSubs` |
||||||
|
(`id` INTEGER NOT NULL, `name` TEXT NOT NULL, `url` TEXT NOT NULL, `type` INTEGER NOT NULL, `customOrder` INTEGER NOT NULL, |
||||||
|
PRIMARY KEY(`id`))""" |
||||||
|
) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_25_26 = object : Migration(25, 26) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL( |
||||||
|
"""CREATE TABLE IF NOT EXISTS `ruleSubs` (`id` INTEGER NOT NULL, `name` TEXT NOT NULL, `url` TEXT NOT NULL, `type` INTEGER NOT NULL, |
||||||
|
`customOrder` INTEGER NOT NULL, `autoUpdate` INTEGER NOT NULL, `update` INTEGER NOT NULL, PRIMARY KEY(`id`))""" |
||||||
|
) |
||||||
|
database.execSQL(" insert into `ruleSubs` select *, 0, 0 from `sourceSubs` ") |
||||||
|
database.execSQL("DROP TABLE `sourceSubs`") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_26_27 = object : Migration(26, 27) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL(" ALTER TABLE rssSources ADD singleUrl INTEGER NOT NULL DEFAULT 0 ") |
||||||
|
database.execSQL( |
||||||
|
"""CREATE TABLE IF NOT EXISTS `bookmarks1` (`time` INTEGER NOT NULL, `bookUrl` TEXT NOT NULL, `bookName` TEXT NOT NULL, |
||||||
|
`bookAuthor` TEXT NOT NULL, `chapterIndex` INTEGER NOT NULL, `chapterPos` INTEGER NOT NULL, `chapterName` TEXT NOT NULL, |
||||||
|
`bookText` TEXT NOT NULL, `content` TEXT NOT NULL, PRIMARY KEY(`time`))""" |
||||||
|
) |
||||||
|
database.execSQL( |
||||||
|
"""insert into `bookmarks1` |
||||||
|
select `time`, `bookUrl`, `bookName`, `bookAuthor`, `chapterIndex`, `pageIndex`, `chapterName`, '', `content` |
||||||
|
from bookmarks""" |
||||||
|
) |
||||||
|
database.execSQL(" DROP TABLE `bookmarks` ") |
||||||
|
database.execSQL(" ALTER TABLE bookmarks1 RENAME TO bookmarks ") |
||||||
|
database.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_bookmarks_time` ON `bookmarks` (`time`)") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_27_28 = object : Migration(27, 28) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL("ALTER TABLE rssArticles ADD variable TEXT") |
||||||
|
database.execSQL("ALTER TABLE rssStars ADD variable TEXT") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_28_29 = object : Migration(28, 29) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL("ALTER TABLE rssSources ADD sourceComment TEXT") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_29_30 = object : Migration(29, 30) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL("ALTER TABLE chapters ADD `startFragmentId` TEXT") |
||||||
|
database.execSQL("ALTER TABLE chapters ADD `endFragmentId` TEXT") |
||||||
|
database.execSQL( |
||||||
|
""" |
||||||
|
CREATE TABLE IF NOT EXISTS `epubChapters` |
||||||
|
(`bookUrl` TEXT NOT NULL, `href` TEXT NOT NULL, `parentHref` TEXT, |
||||||
|
PRIMARY KEY(`bookUrl`, `href`), FOREIGN KEY(`bookUrl`) REFERENCES `books`(`bookUrl`) ON UPDATE NO ACTION ON DELETE CASCADE ) |
||||||
|
""" |
||||||
|
) |
||||||
|
database.execSQL("CREATE INDEX IF NOT EXISTS `index_epubChapters_bookUrl` ON `epubChapters` (`bookUrl`)") |
||||||
|
database.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_epubChapters_bookUrl_href` ON `epubChapters` (`bookUrl`, `href`)") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_30_31 = object : Migration(30, 31) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL("ALTER TABLE readRecord RENAME TO readRecord1") |
||||||
|
database.execSQL( |
||||||
|
""" |
||||||
|
CREATE TABLE IF NOT EXISTS `readRecord` (`deviceId` TEXT NOT NULL, `bookName` TEXT NOT NULL, `readTime` INTEGER NOT NULL, PRIMARY KEY(`deviceId`, `bookName`)) |
||||||
|
""" |
||||||
|
) |
||||||
|
database.execSQL("insert into readRecord (deviceId, bookName, readTime) select androidId, bookName, readTime from readRecord1") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_31_32 = object : Migration(31, 32) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL("DROP TABLE `epubChapters`") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_32_33 = object : Migration(32, 33) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL("ALTER TABLE bookmarks RENAME TO bookmarks_old") |
||||||
|
database.execSQL( |
||||||
|
""" |
||||||
|
CREATE TABLE IF NOT EXISTS `bookmarks` (`time` INTEGER NOT NULL, |
||||||
|
`bookName` TEXT NOT NULL, `bookAuthor` TEXT NOT NULL, `chapterIndex` INTEGER NOT NULL, |
||||||
|
`chapterPos` INTEGER NOT NULL, `chapterName` TEXT NOT NULL, `bookText` TEXT NOT NULL, |
||||||
|
`content` TEXT NOT NULL, PRIMARY KEY(`time`)) |
||||||
|
""" |
||||||
|
) |
||||||
|
database.execSQL( |
||||||
|
""" |
||||||
|
CREATE INDEX IF NOT EXISTS `index_bookmarks_bookName_bookAuthor` ON `bookmarks` (`bookName`, `bookAuthor`) |
||||||
|
""" |
||||||
|
) |
||||||
|
database.execSQL( |
||||||
|
""" |
||||||
|
insert into bookmarks (time, bookName, bookAuthor, chapterIndex, chapterPos, chapterName, bookText, content) |
||||||
|
select time, ifNull(b.name, bookName) bookName, ifNull(b.author, bookAuthor) bookAuthor, |
||||||
|
chapterIndex, chapterPos, chapterName, bookText, content from bookmarks_old o |
||||||
|
left join books b on o.bookUrl = b.bookUrl |
||||||
|
""" |
||||||
|
) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_33_34 = object : Migration(33, 34) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL("ALTER TABLE `book_groups` ADD `cover` TEXT") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private val migration_34_35 = object : Migration(34, 35) { |
||||||
|
override fun migrate(database: SupportSQLiteDatabase) { |
||||||
|
database.execSQL("ALTER TABLE `book_sources` ADD `concurrentRate` TEXT") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,83 @@ |
|||||||
|
package io.legado.app.ui.book.login |
||||||
|
|
||||||
|
import android.os.Bundle |
||||||
|
import android.text.InputType |
||||||
|
import android.util.Base64 |
||||||
|
import android.view.LayoutInflater |
||||||
|
import android.view.View |
||||||
|
import android.view.ViewGroup |
||||||
|
import io.legado.app.R |
||||||
|
import io.legado.app.base.BaseDialogFragment |
||||||
|
import io.legado.app.constant.AppConst |
||||||
|
import io.legado.app.data.entities.rule.LoginRule |
||||||
|
import io.legado.app.databinding.DialogLoginBinding |
||||||
|
import io.legado.app.help.CacheManager |
||||||
|
import io.legado.app.lib.theme.primaryColor |
||||||
|
import io.legado.app.ui.widget.text.EditText |
||||||
|
import io.legado.app.ui.widget.text.TextInputLayout |
||||||
|
import io.legado.app.utils.EncoderUtils |
||||||
|
import io.legado.app.utils.GSON |
||||||
|
import io.legado.app.utils.applyTint |
||||||
|
import io.legado.app.utils.viewbindingdelegate.viewBinding |
||||||
|
|
||||||
|
class SourceLoginDialog : BaseDialogFragment() { |
||||||
|
|
||||||
|
private val binding by viewBinding(DialogLoginBinding::bind) |
||||||
|
|
||||||
|
|
||||||
|
override fun onCreateView( |
||||||
|
inflater: LayoutInflater, |
||||||
|
container: ViewGroup?, |
||||||
|
savedInstanceState: Bundle? |
||||||
|
): View? { |
||||||
|
return inflater.inflate(R.layout.dialog_login, container) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
||||||
|
binding.toolBar.setBackgroundColor(primaryColor) |
||||||
|
val sourceUrl = arguments?.getString("sourceUrl") |
||||||
|
val loginRule = arguments?.getParcelable<LoginRule>("loginRule") |
||||||
|
loginRule?.ui?.forEachIndexed { index, rowUi -> |
||||||
|
when (rowUi.type) { |
||||||
|
"text" -> layoutInflater.inflate(R.layout.item_source_edit, binding.root) |
||||||
|
.apply { |
||||||
|
id = index |
||||||
|
} |
||||||
|
"password" -> layoutInflater.inflate(R.layout.item_source_edit, binding.root) |
||||||
|
.apply { |
||||||
|
id = index |
||||||
|
findViewById<EditText>(R.id.editText)?.inputType = |
||||||
|
InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
binding.toolBar.inflateMenu(R.menu.source_login) |
||||||
|
binding.toolBar.menu.applyTint(requireContext()) |
||||||
|
binding.toolBar.setOnMenuItemClickListener { |
||||||
|
when (it.itemId) { |
||||||
|
R.id.menu_ok -> { |
||||||
|
val loginData = hashMapOf<String, String?>() |
||||||
|
loginRule?.ui?.forEachIndexed { index, rowUi -> |
||||||
|
when (rowUi.type) { |
||||||
|
"text", "password" -> { |
||||||
|
val value = binding.root.findViewById<TextInputLayout>(index) |
||||||
|
.findViewById<EditText>(R.id.editText).text?.toString() |
||||||
|
loginData[rowUi.name] = value |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
val data = Base64.encodeToString( |
||||||
|
EncoderUtils.decryptAES( |
||||||
|
GSON.toJson(loginData).toByteArray(), |
||||||
|
AppConst.androidId.toByteArray() |
||||||
|
), |
||||||
|
Base64.DEFAULT |
||||||
|
) |
||||||
|
CacheManager.put("login_$sourceUrl", data) |
||||||
|
} |
||||||
|
} |
||||||
|
return@setOnMenuItemClickListener true |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,23 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:background="@color/background" |
||||||
|
android:gravity="center" |
||||||
|
android:orientation="horizontal"> |
||||||
|
|
||||||
|
<androidx.appcompat.widget.Toolbar |
||||||
|
android:id="@+id/tool_bar" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:background="@color/background_menu" |
||||||
|
android:elevation="5dp" |
||||||
|
android:theme="?attr/actionBarStyle" |
||||||
|
app:displayHomeAsUp="false" |
||||||
|
app:fitStatusBar="false" |
||||||
|
app:popupTheme="@style/AppTheme.PopupOverlay" |
||||||
|
app:titleTextAppearance="@style/ToolbarTitle" /> |
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout> |
Loading…
Reference in new issue