4 次代码提交 9642446c95 ... 9d467dde39

作者 SHA1 备注 提交日期
  黃笠維 9d467dde39 Merge branch '150-refactor-copy-file-activity' into 'master' 4 年之前
  Wayne 85f2bef002 Refactor: CopyFileActivity 4 年之前
  Wayne Hunag edf81d7e4a Merge branch '149-fix-text' into 'master' 4 年之前
  Wayne 5e81d1ac42 Fix reader page scroll direction text 4 年之前

+ 33 - 8
src/main/java/com/kdanmobile/reader/copyfile/CopyFileActivity.kt

@@ -1,12 +1,13 @@
 package com.kdanmobile.reader.copyfile
 
-import androidx.lifecycle.Observer
+import android.annotation.SuppressLint
 import android.content.Intent
+import android.os.Build
 import android.os.Bundle
+import androidx.lifecycle.Observer
 import com.kdanmobile.base.KdanBaseActivity
 import com.kdanmobile.reader.R
 import com.kdanmobile.reader.koin.ReadModuleKoinComponent
-import com.kdanmobile.reader.thumb.FileUtil
 import kotlinx.android.synthetic.main.activity_copy_file.*
 import org.koin.android.viewmodel.ext.android.viewModel
 import org.koin.core.parameter.parametersOf
@@ -17,7 +18,9 @@ abstract class CopyFileActivity : KdanBaseActivity(), ReadModuleKoinComponent {
     abstract fun getKdanPdfReaderFolder(): File
     abstract fun provideReaderActivityIntent(filePath: String?): Intent
     open fun hasPermissionToAccessExternalStorage(): Boolean = true
-    open fun onFileCopyComplete(callback: () -> Unit) = callback.invoke()
+    open fun onFileCopyComplete() {
+        tryToStartReaderActivity()
+    }
 
     companion object {
         const val KEY_FILE_ABSOLUTE_PATH = "file_absolute_path"
@@ -39,18 +42,36 @@ abstract class CopyFileActivity : KdanBaseActivity(), ReadModuleKoinComponent {
 
     private fun onCopyProgressUpdate(progress: Int?) {
         progress?.also {
-            progressBar.progress = it
-            tvProgressPercent.text = "$it%"
+            updateProgress(fileCopyProgressMap(progress))
+        }
+    }
+
+    /**
+     * You can change progress by overriding this method.
+     */
+    protected open fun fileCopyProgressMap(progress: Int): Int {
+        return progress
+    }
+
+    /**
+     * Force update progress value on screen.
+     */
+    @SuppressLint("SetTextI18n")
+    protected fun updateProgress(progress: Int) {
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+            progressBar.setProgress(progress, true)
+        } else {
+            progressBar.progress = progress
         }
+        tvProgressPercent.text = "$progress%"
     }
 
     private fun onEvent(event: CopyFileViewModel.Event?) {
         if (null == event) return
         when (event) {
             is CopyFileViewModel.Event.Success -> {
-                onFileCopyComplete {
-                    startReaderActivity(event.filePath)
-                }
+                onCopyProgressUpdate(100)
+                onFileCopyComplete()
             }
             is CopyFileViewModel.Event.Failed -> {
                 event.e.printStackTrace()
@@ -70,6 +91,10 @@ abstract class CopyFileActivity : KdanBaseActivity(), ReadModuleKoinComponent {
         fileCannotOpenDialog.show(supportFragmentManager, fileCannotOpenDialog.tag)
     }
 
+    protected fun tryToStartReaderActivity() {
+        startReaderActivity(viewModel.dstFilePath)
+    }
+
     private fun startReaderActivity(filePath: String?) {
         startActivity(provideReaderActivityIntent(filePath))
         overridePendingTransition(0, 0)

+ 5 - 5
src/main/java/com/kdanmobile/reader/copyfile/CopyFileViewModel.kt

@@ -1,17 +1,16 @@
 package com.kdanmobile.reader.copyfile
 
+import android.content.Context
+import android.content.Intent
 import androidx.lifecycle.LiveData
 import androidx.lifecycle.MutableLiveData
 import androidx.lifecycle.ViewModel
-import android.content.Context
-import android.content.Intent
 import com.kdanmobile.reader.event.EventBroadcaster
 import com.kdanmobile.reader.event.EventManager
 import io.reactivex.android.schedulers.AndroidSchedulers
 import io.reactivex.disposables.Disposable
 import io.reactivex.schedulers.Schedulers
 import java.io.File
-import java.lang.Exception
 
 /**
  * 1. if info.shouldCopyFile == false,
@@ -36,7 +35,7 @@ class CopyFileViewModel(applicationContext: Context,
 
     sealed class Event {
         data class Success(val filePath: String?): Event()
-        data class Failed(val filePath: String?, val e: Throwable): Event()
+        data class Failed(val filePath: String?, val e: Throwable) : Event()
     }
 
     val copyProgressLiveData: LiveData<Int>
@@ -46,7 +45,8 @@ class CopyFileViewModel(applicationContext: Context,
 
     private var copyFileDisposable: Disposable? = null
     private var srcFilePath: String? = null
-    private var dstFilePath: String? = null
+    var dstFilePath: String? = null
+        private set
     private var hasCompleteCopy = false
 
     init {

+ 2 - 2
src/main/res/layout/view_turn_page_mode_select.xml

@@ -30,14 +30,14 @@
             android:id="@+id/radioBtn_turnPageMode_horizontally"
             android:layout_width="wrap_content"
             android:layout_height="48dp"
-            android:text="@string/reader_setting_page_scroll_mode_vertical"
+            android:text="@string/reader_setting_page_scroll_mode_horizontal"
             app:layout_constraintLeft_toLeftOf="parent" />
 
         <RadioButton
             android:id="@+id/radioBtn_turnPageMode_vertically"
             android:layout_width="wrap_content"
             android:layout_height="48dp"
-            android:text="@string/reader_setting_page_scroll_mode_horizontal"
+            android:text="@string/reader_setting_page_scroll_mode_vertical"
             app:layout_constraintLeft_toLeftOf="parent" />
 
     </RadioGroup>

+ 2 - 2
src/main/res/values-de/strings.xml

@@ -30,8 +30,8 @@
 
     <string name="dialogAddBookmark_page">Seite</string>
     <string name="reader_setting_page_scroll_mode">Durch Seiten scrollen</string>
-    <string name="reader_setting_page_scroll_mode_horizontal">Vertikal</string>
-    <string name="reader_setting_page_scroll_mode_vertical">Horizontal</string>
+    <string name="reader_setting_page_scroll_mode_vertical">Vertikal</string>
+    <string name="reader_setting_page_scroll_mode_horizontal">Horizontal</string>
     <string name="reader_setting_page_theme">Themen</string>
     <string name="reader_setting_page_smart_crop">Zuschneiden-Modus</string>
     <string name="reader_setting_status_bar">Statusleiste anzeigen</string>

+ 2 - 2
src/main/res/values-es/strings.xml

@@ -29,8 +29,8 @@
 
     <string name="dialogAddBookmark_page">página</string>
     <string name="reader_setting_page_scroll_mode">Desplace páginas</string>
-    <string name="reader_setting_page_scroll_mode_horizontal">Verticalmente</string>
-    <string name="reader_setting_page_scroll_mode_vertical">Horizontalmente</string>
+    <string name="reader_setting_page_scroll_mode_vertical">Verticalmente</string>
+    <string name="reader_setting_page_scroll_mode_horizontal">Horizontalmente</string>
     <string name="reader_setting_page_theme">Темы</string>
     <string name="reader_setting_page_smart_crop">Режим вырезания</string>
     <string name="reader_setting_status_bar">Показать строку состояния</string>

+ 2 - 2
src/main/res/values-fr/strings.xml

@@ -29,8 +29,8 @@
 
     <string name="dialogAddBookmark_page">Page</string>
     <string name="reader_setting_page_scroll_mode">Défilement des Pages</string>
-    <string name="reader_setting_page_scroll_mode_horizontal">Verticalement</string>
-    <string name="reader_setting_page_scroll_mode_vertical">Horizontalement</string>
+    <string name="reader_setting_page_scroll_mode_vertical">Verticalement</string>
+    <string name="reader_setting_page_scroll_mode_horizontal">Horizontalement</string>
     <string name="reader_setting_page_theme">Thèmes</string>
     <string name="reader_setting_page_smart_crop">Mode Couper</string>
     <string name="reader_setting_status_bar">Afficher la barre d\'état</string>

+ 2 - 2
src/main/res/values-it/strings.xml

@@ -29,8 +29,8 @@
 
     <string name="dialogAddBookmark_page">Pagina</string>
     <string name="reader_setting_page_scroll_mode">Pagine di scorrimento</string>
-    <string name="reader_setting_page_scroll_mode_horizontal">Verticalmente</string>
-    <string name="reader_setting_page_scroll_mode_vertical">Orizzontalmente</string>
+    <string name="reader_setting_page_scroll_mode_vertical">Verticalmente</string>
+    <string name="reader_setting_page_scroll_mode_horizontal">Orizzontalmente</string>
     <string name="reader_setting_page_theme">Temi</string>
     <string name="reader_setting_page_smart_crop">Modalità ritaglio</string>
     <string name="reader_setting_status_bar">Mostra la barra di stato</string>

+ 2 - 2
src/main/res/values-ja/strings.xml

@@ -27,8 +27,8 @@
     <string name="fileManager_no_results">見つかりませんでした。</string>
     <string name="fileManager_thishi_search">少なくとも3文字入力して下さい。</string>
     <string name="reader_setting_page_scroll_mode">ページをスクロールします</string>
-    <string name="reader_setting_page_scroll_mode_horizontal">縦方向</string>
-    <string name="reader_setting_page_scroll_mode_vertical">横方向</string>
+    <string name="reader_setting_page_scroll_mode_vertical">縦方向</string>
+    <string name="reader_setting_page_scroll_mode_horizontal">横方向</string>
     <string name="dialogAddBookmark_page">ページ数:</string>
     <string name="reader_setting_page_theme">テーマ</string>
     <string name="reader_setting_page_smart_crop">切り取りモード</string>

+ 2 - 2
src/main/res/values-ko/strings.xml

@@ -29,8 +29,8 @@
 
     <string name="dialogAddBookmark_page">페이지</string>
     <string name="reader_setting_page_scroll_mode">페이지 스크롤</string>
-    <string name="reader_setting_page_scroll_mode_horizontal">세로</string>
-    <string name="reader_setting_page_scroll_mode_vertical">가로</string>
+    <string name="reader_setting_page_scroll_mode_vertical">세로</string>
+    <string name="reader_setting_page_scroll_mode_horizontal">가로</string>
     <string name="reader_setting_page_theme">테마</string>
     <string name="reader_setting_page_smart_crop">자르기 모드</string>
     <string name="reader_setting_status_bar">상태 표시줄 표시</string>

+ 2 - 2
src/main/res/values-pt/strings.xml

@@ -29,8 +29,8 @@
 
     <string name="dialogAddBookmark_page">página</string>
     <string name="reader_setting_page_scroll_mode">Páginas de rolagem</string>
-    <string name="reader_setting_page_scroll_mode_horizontal">Verticalmente</string>
-    <string name="reader_setting_page_scroll_mode_vertical">Horizontalmente</string>
+    <string name="reader_setting_page_scroll_mode_vertical">Verticalmente</string>
+    <string name="reader_setting_page_scroll_mode_horizontal">Horizontalmente</string>
     <string name="reader_setting_page_theme">Temas</string>
     <string name="reader_setting_page_smart_crop">Modo de Recorte</string>
     <string name="reader_setting_status_bar">Mostrar barra de status</string>

+ 2 - 2
src/main/res/values-ru/strings.xml

@@ -29,8 +29,8 @@
 
     <string name="dialogAddBookmark_page">страница</string>
     <string name="reader_setting_page_scroll_mode">Прокручивание страниц</string>
-    <string name="reader_setting_page_scroll_mode_horizontal">Вертикально</string>
-    <string name="reader_setting_page_scroll_mode_vertical">Горизонтально</string>
+    <string name="reader_setting_page_scroll_mode_vertical">Вертикально</string>
+    <string name="reader_setting_page_scroll_mode_horizontal">Горизонтально</string>
     <string name="reader_setting_page_theme">Temas</string>
     <string name="reader_setting_page_smart_crop">Modo Recorte</string>
     <string name="reader_setting_status_bar">Mostrar la barra de estado</string>

+ 2 - 2
src/main/res/values-zh-rTW/strings.xml

@@ -30,8 +30,8 @@
 
     <string name="dialogAddBookmark_page">頁數</string>
     <string name="reader_setting_page_scroll_mode">翻頁設定</string>
-    <string name="reader_setting_page_scroll_mode_horizontal">垂直滾動</string>
-    <string name="reader_setting_page_scroll_mode_vertical">水平滾動</string>
+    <string name="reader_setting_page_scroll_mode_vertical">垂直滾動</string>
+    <string name="reader_setting_page_scroll_mode_horizontal">水平滾動</string>
     <string name="reader_setting_page_theme">頁面背景主題</string>
     <string name="reader_setting_page_smart_crop">裁邊模式</string>
     <string name="reader_setting_status_bar">顯示狀態列</string>

+ 2 - 2
src/main/res/values-zh/strings.xml

@@ -30,8 +30,8 @@
 
     <string name="dialogAddBookmark_page">页码</string>
     <string name="reader_setting_page_scroll_mode">翻页设置</string>
-    <string name="reader_setting_page_scroll_mode_horizontal">垂直滚动</string>
-    <string name="reader_setting_page_scroll_mode_vertical">水平滚动</string>
+    <string name="reader_setting_page_scroll_mode_vertical">垂直滚动</string>
+    <string name="reader_setting_page_scroll_mode_horizontal">水平滚动</string>
     <string name="reader_setting_page_theme">主题</string>
     <string name="reader_setting_page_smart_crop">裁边模式</string>
     <string name="reader_setting_status_bar">显示状态栏</string>

+ 2 - 2
src/main/res/values/strings.xml

@@ -43,8 +43,8 @@
     <string name="reader_setting_page_smart_crop">Crop mode</string>
     <string name="reader_setting_status_bar">Show status bar</string>
     <string name="reader_setting_page_scroll_mode">View Settings</string>
-    <string name="reader_setting_page_scroll_mode_vertical">Single page view</string>
-    <string name="reader_setting_page_scroll_mode_horizontal">Continuous scroll</string>
+    <string name="reader_setting_page_scroll_mode_horizontal">Horizontally</string>
+    <string name="reader_setting_page_scroll_mode_vertical">Vertically</string>
     <string name="reader_setting_switch_page_button">Show page navigation buttons</string>
     <string name="reader_setting_screen_setting">Display Settings</string>
     <string name="reader_setting_screen_setting_sleep">Screen timeout</string>