pull/90/head^2
kunfei 5 years ago
parent 97da203675
commit 1dc55667e3
  1. 5
      app/src/main/java/io/legado/app/lib/theme/TintHelper.kt
  2. 4
      app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt
  3. 2
      app/src/main/java/io/legado/app/ui/explore/ExploreShowViewModel.kt
  4. 2
      app/src/main/java/io/legado/app/ui/filechooser/adapter/FileAdapter.kt
  5. 1
      app/src/main/java/io/legado/app/ui/filechooser/adapter/PathAdapter.kt
  6. 40
      app/src/main/java/io/legado/app/ui/filechooser/utils/FileUtils.kt
  7. 10
      app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionAnimator.kt
  8. 23
      app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScroller.kt
  9. 158
      app/src/main/java/io/legado/app/utils/Snackbars.kt
  10. 8
      app/src/main/java/io/legado/app/utils/Toasts.kt

@ -254,11 +254,10 @@ object TintHelper {
if (!skipIndeterminate)
progressBar.indeterminateTintList = sl
} else {
val mode = PorterDuff.Mode.SRC_IN
if (!skipIndeterminate && progressBar.indeterminateDrawable != null)
progressBar.indeterminateDrawable.setColorFilter(color, mode)
progressBar.indeterminateDrawable.setTint(color)
if (progressBar.progressDrawable != null)
progressBar.progressDrawable.setColorFilter(color, mode)
progressBar.progressDrawable.setTint(color)
}
}

@ -74,8 +74,6 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
}
override fun delBookmark(bookmark: Bookmark) {
bookmark?.let {
App.db.bookmarkDao().delByBookmark(it.bookUrl, it.chapterName)
}
App.db.bookmarkDao().delByBookmark(bookmark.bookUrl, bookmark.chapterName)
}
}

@ -21,7 +21,7 @@ class ExploreShowViewModel(application: Application) : BaseViewModel(application
execute {
val sourceUrl = intent.getStringExtra("sourceUrl")
exploreUrl = intent.getStringExtra("exploreUrl")
if (bookSource == null) {
if (bookSource == null && sourceUrl != null) {
bookSource = App.db.bookSourceDao().getBookSource(sourceUrl)
}
explore()

@ -64,7 +64,7 @@ class FileAdapter(context: Context, val callBack: CallBack) :
fileParent.icon = upIcon
fileParent.name = DIR_PARENT
fileParent.size = 0
fileParent.path = File(path).parent
fileParent.path = File(path).parent ?: ""
data.add(fileParent)
}
currentPath?.let { currentPath ->

@ -15,6 +15,7 @@ import java.util.*
class PathAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<String>(context, R.layout.item_path_filepicker) {
private val paths = LinkedList<String>()
@Suppress("DEPRECATION")
private val sdCardDirectory = Environment.getExternalStorageDirectory().absolutePath
private val arrowIcon = ConvertUtils.toDrawable(FilePickerIcon.getARROW())

@ -34,13 +34,13 @@ object FileUtils {
* 将目录分隔符统一为平台默认的分隔符并为目录结尾添加分隔符
*/
fun separator(path: String): String {
var path = path
var path1 = path
val separator = File.separator
path = path.replace("\\", separator)
if (!path.endsWith(separator)) {
path += separator
path1 = path1.replace("\\", separator)
if (!path1.endsWith(separator)) {
path1 += separator
}
return path
return path1
}
fun closeSilently(c: Closeable?) {
@ -62,7 +62,7 @@ object FileUtils {
startDirPath: String,
excludeDirs: Array<String?>? = null, @SortType sortType: Int = BY_NAME_ASC
): Array<File?> {
var excludeDirs = excludeDirs
var excludeDirs1 = excludeDirs
val dirList = ArrayList<File>()
val startDir = File(startDirPath)
if (!startDir.isDirectory) {
@ -75,12 +75,12 @@ object FileUtils {
f.isDirectory
})
?: return arrayOfNulls(0)
if (excludeDirs == null) {
excludeDirs = arrayOfNulls(0)
if (excludeDirs1 == null) {
excludeDirs1 = arrayOfNulls(0)
}
for (dir in dirs) {
val file = dir.absoluteFile
if (!excludeDirs.contentDeepToString().contains(file.name)) {
if (!excludeDirs1.contentDeepToString().contains(file.name)) {
dirList.add(file)
}
}
@ -191,7 +191,7 @@ object FileUtils {
*/
fun listFiles(startDirPath: String, allowExtensions: Array<String?>): Array<File?>? {
val file = File(startDirPath)
return file.listFiles { dir, name ->
return file.listFiles { _, name ->
//返回当前目录所有以某些扩展名结尾的文件
val extension = getExtension(name)
allowExtensions.contentDeepToString().contains(extension)
@ -294,10 +294,8 @@ object FileUtils {
bis.close()
bos.close()
} else if (src.isDirectory) {
val files = src.listFiles()
tar.mkdirs()
for (file in files) {
src.listFiles()?.forEach { file ->
copy(file.absoluteFile, File(tar.absoluteFile, file.name))
}
}
@ -399,18 +397,16 @@ object FileUtils {
fun writeBytes(filepath: String, data: ByteArray): Boolean {
val file = File(filepath)
var fos: FileOutputStream? = null
try {
return try {
if (!file.exists()) {
file.parentFile.mkdirs()
file.parentFile?.mkdirs()
file.createNewFile()
}
fos = FileOutputStream(filepath)
fos.write(data)
return true
true
} catch (e: IOException) {
return false
false
} finally {
closeSilently(fos)
}
@ -422,16 +418,16 @@ object FileUtils {
fun appendText(path: String, content: String): Boolean {
val file = File(path)
var writer: FileWriter? = null
try {
return try {
if (!file.exists()) {
file.createNewFile()
}
writer = FileWriter(file, true)
writer.write(content)
return true
true
} catch (e: IOException) {
return false
false
} finally {
closeSilently(writer)
}

@ -23,13 +23,11 @@ import java.util.*
class ExplosionAnimator(private val mContainer: View, bitmap: Bitmap, bound: Rect) :
ValueAnimator() {
private val mPaint: Paint
private val mPaint: Paint = Paint()
private val mParticles: Array<Particle?>
private val mBound: Rect
private val mBound: Rect = Rect(bound)
init {
mPaint = Paint()
mBound = Rect(bound)
val partLen = 15
mParticles = arrayOfNulls(partLen * partLen)
val random = Random(System.currentTimeMillis())
@ -97,7 +95,7 @@ class ExplosionAnimator(private val mContainer: View, bitmap: Bitmap, bound: Rec
override fun start() {
super.start()
mContainer.invalidate(mBound)
mContainer.invalidate()
}
private inner class Particle {
@ -141,7 +139,7 @@ class ExplosionAnimator(private val mContainer: View, bitmap: Bitmap, bound: Rec
internal var DEFAULT_DURATION: Long = 0x400
private val DEFAULT_INTERPOLATOR = AccelerateInterpolator(0.6f)
private val END_VALUE = 1.4f
private const val END_VALUE = 1.4f
private val X = Utils.dp2Px(5).toFloat()
private val Y = Utils.dp2Px(20).toFloat()
private val V = Utils.dp2Px(2).toFloat()

@ -482,18 +482,17 @@ class FastScroller : LinearLayout {
var showTrack = true
if (attrs != null) {
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.FastScroller, 0, 0)
if (typedArray != null) {
try {
bubbleColor = typedArray.getColor(R.styleable.FastScroller_bubbleColor, bubbleColor)
handleColor = typedArray.getColor(R.styleable.FastScroller_handleColor, handleColor)
trackColor = typedArray.getColor(R.styleable.FastScroller_trackColor, trackColor)
textColor = typedArray.getColor(R.styleable.FastScroller_bubbleTextColor, textColor)
fadeScrollbar = typedArray.getBoolean(R.styleable.FastScroller_fadeScrollbar, fadeScrollbar)
showBubble = typedArray.getBoolean(R.styleable.FastScroller_showBubble, showBubble)
showTrack = typedArray.getBoolean(R.styleable.FastScroller_showTrack, showTrack)
} finally {
typedArray.recycle()
}
try {
bubbleColor = typedArray.getColor(R.styleable.FastScroller_bubbleColor, bubbleColor)
handleColor = typedArray.getColor(R.styleable.FastScroller_handleColor, handleColor)
trackColor = typedArray.getColor(R.styleable.FastScroller_trackColor, trackColor)
textColor = typedArray.getColor(R.styleable.FastScroller_bubbleTextColor, textColor)
fadeScrollbar =
typedArray.getBoolean(R.styleable.FastScroller_fadeScrollbar, fadeScrollbar)
showBubble = typedArray.getBoolean(R.styleable.FastScroller_showBubble, showBubble)
showTrack = typedArray.getBoolean(R.styleable.FastScroller_showTrack, showTrack)
} finally {
typedArray.recycle()
}
}
setTrackColor(trackColor)

@ -4,139 +4,13 @@ import android.view.View
import androidx.annotation.StringRes
import com.google.android.material.snackbar.Snackbar
/**
* Display the Snackbar with the [Snackbar.LENGTH_SHORT] duration.
*
* @param message the message text resource.
*/
@Deprecated("Use 'View.snackbar(Int)' instead.", ReplaceWith("view.snackbar(message)"))
inline fun snackbar(view: View, message: Int) = Snackbar
.make(view, message, Snackbar.LENGTH_SHORT)
.apply { show() }
/**
* Display Snackbar with the [Snackbar.LENGTH_LONG] duration.
*
* @param message the message text resource.
*/
@Deprecated("Use 'View.longSnackbar(Int)' instead.", ReplaceWith("view.longSnackbar(message)"))
inline fun longSnackbar(view: View, message: Int) = Snackbar
.make(view, message, Snackbar.LENGTH_LONG)
.apply { show() }
/**
* Display Snackbar with the [Snackbar.LENGTH_INDEFINITE] duration.
*
* @param message the message text resource.
*/
@Deprecated("Use 'View.indefiniteSnackbar(Int)' instead.", ReplaceWith("view.indefiniteSnackbar(message)"))
inline fun indefiniteSnackbar(view: View, message: Int) = Snackbar
.make(view, message, Snackbar.LENGTH_INDEFINITE)
.apply { show() }
/**
* Display the Snackbar with the [Snackbar.LENGTH_SHORT] duration.
*
* @param message the message text.
*/
@Deprecated("Use 'View.snackbar(CharSequence)' instead.", ReplaceWith("view.snackbar(message)"))
inline fun snackbar(view: View, message: CharSequence) = Snackbar
.make(view, message, Snackbar.LENGTH_SHORT)
.apply { show() }
/**
* Display Snackbar with the [Snackbar.LENGTH_LONG] duration.
*
* @param message the message text.
*/
@Deprecated("Use 'View.longSnackbar(CharSequence)' instead.", ReplaceWith("view.longSnackbar(message)"))
inline fun longSnackbar(view: View, message: CharSequence) = Snackbar
.make(view, message, Snackbar.LENGTH_LONG)
.apply { show() }
/**
* Display Snackbar with the [Snackbar.LENGTH_INDEFINITE] duration.
*
* @param message the message text.
*/
@Deprecated("Use 'View.indefiniteSnackbar(CharSequence)' instead.", ReplaceWith("view.indefiniteSnackbar(message)"))
inline fun indefiniteSnackbar(view: View, message: CharSequence) = Snackbar
.make(view, message, Snackbar.LENGTH_INDEFINITE)
.apply { show() }
/**
* Display the Snackbar with the [Snackbar.LENGTH_SHORT] duration.
*
* @param message the message text resource.
*/
@Deprecated("Use 'View.snackbar(Int, Int, (View) -> Unit)' instead.", ReplaceWith("view.snackbar(message, actionText, action)"))
inline fun snackbar(view: View, message: Int, actionText: Int, noinline action: (View) -> Unit) = Snackbar
.make(view, message, Snackbar.LENGTH_SHORT)
.setAction(actionText, action)
.apply { show() }
/**
* Display Snackbar with the [Snackbar.LENGTH_LONG] duration.
*
* @param message the message text resource.
*/
@Deprecated("Use 'View.longSnackbar(Int, Int, (View) -> Unit)' instead.", ReplaceWith("view.longSnackbar(message, actionText, action)"))
inline fun longSnackbar(view: View, message: Int, actionText: Int, noinline action: (View) -> Unit) = Snackbar
.make(view, message, Snackbar.LENGTH_LONG)
.setAction(actionText, action)
.apply { show() }
/**
* Display Snackbar with the [Snackbar.LENGTH_INDEFINITE] duration.
*
* @param message the message text resource.
*/
@Deprecated("Use 'View.indefiniteSnackbar(Int, Int, (View) -> Unit)' instead.", ReplaceWith("view.indefiniteSnackbar(message, actionText, action)"))
inline fun indefiniteSnackbar(view: View, message: Int, actionText: Int, noinline action: (View) -> Unit) = Snackbar
.make(view, message, Snackbar.LENGTH_INDEFINITE)
.setAction(actionText, action)
.apply { show() }
/**
* Display the Snackbar with the [Snackbar.LENGTH_SHORT] duration.
*
* @param message the message text.
*/
@Deprecated("Use 'View.snackbar(CharSequence, CharSequence, (View) -> Unit)' instead.", ReplaceWith("view.snackbar(message, actionText, action)"))
inline fun snackbar(view: View, message: CharSequence, actionText: CharSequence, noinline action: (View) -> Unit) = Snackbar
.make(view, message, Snackbar.LENGTH_SHORT)
.setAction(actionText, action)
.apply { show() }
/**
* Display Snackbar with the [Snackbar.LENGTH_LONG] duration.
*
* @param message the message text.
*/
@Deprecated("Use 'View.longSnackbar(CharSequence, CharSequence, (View) -> Unit)' instead.", ReplaceWith("view.longSnackbar(message, actionText, action)"))
inline fun longSnackbar(view: View, message: CharSequence, actionText: CharSequence, noinline action: (View) -> Unit) = Snackbar
.make(view, message, Snackbar.LENGTH_LONG)
.setAction(actionText, action)
.apply { show() }
/**
* Display Snackbar with the [Snackbar.LENGTH_INDEFINITE] duration.
*
* @param message the message text.
*/
@Deprecated("Use 'View.indefiniteSnackbar(CharSequence, CharSequence, (View) -> Unit)' instead.", ReplaceWith("view.indefiniteSnackbar(message, actionText, action)"))
inline fun indefiniteSnackbar(view: View, message: CharSequence, actionText: CharSequence, noinline action: (View) -> Unit) = Snackbar
.make(view, message, Snackbar.LENGTH_INDEFINITE)
.setAction(actionText, action)
.apply { show() }
/**
* Display the Snackbar with the [Snackbar.LENGTH_SHORT] duration.
*
* @param message the message text resource.
*/
@JvmName("snackbar2")
inline fun View.snackbar(@StringRes message: Int) = Snackbar
fun View.snackbar(@StringRes message: Int) = Snackbar
.make(this, message, Snackbar.LENGTH_SHORT)
.apply { show() }
@ -146,7 +20,7 @@ inline fun View.snackbar(@StringRes message: Int) = Snackbar
* @param message the message text resource.
*/
@JvmName("longSnackbar2")
inline fun View.longSnackbar(@StringRes message: Int) = Snackbar
fun View.longSnackbar(@StringRes message: Int) = Snackbar
.make(this, message, Snackbar.LENGTH_LONG)
.apply { show() }
@ -156,7 +30,7 @@ inline fun View.longSnackbar(@StringRes message: Int) = Snackbar
* @param message the message text resource.
*/
@JvmName("indefiniteSnackbar2")
inline fun View.indefiniteSnackbar(@StringRes message: Int) = Snackbar
fun View.indefiniteSnackbar(@StringRes message: Int) = Snackbar
.make(this, message, Snackbar.LENGTH_INDEFINITE)
.apply { show() }
@ -166,7 +40,7 @@ inline fun View.indefiniteSnackbar(@StringRes message: Int) = Snackbar
* @param message the message text.
*/
@JvmName("snackbar2")
inline fun View.snackbar(message: CharSequence) = Snackbar
fun View.snackbar(message: CharSequence) = Snackbar
.make(this, message, Snackbar.LENGTH_SHORT)
.apply { show() }
@ -176,7 +50,7 @@ inline fun View.snackbar(message: CharSequence) = Snackbar
* @param message the message text.
*/
@JvmName("longSnackbar2")
inline fun View.longSnackbar(message: CharSequence) = Snackbar
fun View.longSnackbar(message: CharSequence) = Snackbar
.make(this, message, Snackbar.LENGTH_LONG)
.apply { show() }
@ -186,7 +60,7 @@ inline fun View.longSnackbar(message: CharSequence) = Snackbar
* @param message the message text.
*/
@JvmName("indefiniteSnackbar2")
inline fun View.indefiniteSnackbar(message: CharSequence) = Snackbar
fun View.indefiniteSnackbar(message: CharSequence) = Snackbar
.make(this, message, Snackbar.LENGTH_INDEFINITE)
.apply { show() }
@ -196,7 +70,7 @@ inline fun View.indefiniteSnackbar(message: CharSequence) = Snackbar
* @param message the message text resource.
*/
@JvmName("snackbar2")
inline fun View.snackbar(message: Int, @StringRes actionText: Int, noinline action: (View) -> Unit) = Snackbar
fun View.snackbar(message: Int, @StringRes actionText: Int, action: (View) -> Unit) = Snackbar
.make(this, message, Snackbar.LENGTH_SHORT)
.setAction(actionText, action)
.apply { show() }
@ -207,7 +81,8 @@ inline fun View.snackbar(message: Int, @StringRes actionText: Int, noinline acti
* @param message the message text resource.
*/
@JvmName("longSnackbar2")
inline fun View.longSnackbar(@StringRes message: Int, @StringRes actionText: Int, noinline action: (View) -> Unit) = Snackbar
fun View.longSnackbar(@StringRes message: Int, @StringRes actionText: Int, action: (View) -> Unit) =
Snackbar
.make(this, message, Snackbar.LENGTH_LONG)
.setAction(actionText, action)
.apply { show() }
@ -218,7 +93,8 @@ inline fun View.longSnackbar(@StringRes message: Int, @StringRes actionText: Int
* @param message the message text resource.
*/
@JvmName("indefiniteSnackbar2")
inline fun View.indefiniteSnackbar(@StringRes message: Int, @StringRes actionText: Int, noinline action: (View) -> Unit) = Snackbar
fun View.indefiniteSnackbar(@StringRes message: Int, @StringRes actionText: Int, action: (View) -> Unit) =
Snackbar
.make(this, message, Snackbar.LENGTH_INDEFINITE)
.setAction(actionText, action)
.apply { show() }
@ -229,7 +105,8 @@ inline fun View.indefiniteSnackbar(@StringRes message: Int, @StringRes actionTex
* @param message the message text.
*/
@JvmName("snackbar2")
inline fun View.snackbar(message: CharSequence, actionText: CharSequence, noinline action: (View) -> Unit) = Snackbar
fun View.snackbar(message: CharSequence, actionText: CharSequence, action: (View) -> Unit) =
Snackbar
.make(this, message, Snackbar.LENGTH_SHORT)
.setAction(actionText, action)
.apply { show() }
@ -240,7 +117,8 @@ inline fun View.snackbar(message: CharSequence, actionText: CharSequence, noinli
* @param message the message text.
*/
@JvmName("longSnackbar2")
inline fun View.longSnackbar(message: CharSequence, actionText: CharSequence, noinline action: (View) -> Unit) = Snackbar
fun View.longSnackbar(message: CharSequence, actionText: CharSequence, action: (View) -> Unit) =
Snackbar
.make(this, message, Snackbar.LENGTH_LONG)
.setAction(actionText, action)
.apply { show() }
@ -251,7 +129,11 @@ inline fun View.longSnackbar(message: CharSequence, actionText: CharSequence, no
* @param message the message text.
*/
@JvmName("indefiniteSnackbar2")
inline fun View.indefiniteSnackbar(message: CharSequence, actionText: CharSequence, noinline action: (View) -> Unit) = Snackbar
fun View.indefiniteSnackbar(
message: CharSequence,
actionText: CharSequence,
action: (View) -> Unit
) = Snackbar
.make(this, message, Snackbar.LENGTH_INDEFINITE)
.setAction(actionText, action)
.apply { show() }

@ -11,25 +11,25 @@ import org.jetbrains.anko.toast
*
* @param message the message text resource.
*/
inline fun Fragment.toast(message: Int) = requireActivity().toast(message)
fun Fragment.toast(message: Int) = requireActivity().toast(message)
/**
* Display the simple Toast message with the [Toast.LENGTH_SHORT] duration.
*
* @param message the message text.
*/
inline fun Fragment.toast(message: CharSequence) = requireActivity().toast(message)
fun Fragment.toast(message: CharSequence) = requireActivity().toast(message)
/**
* Display the simple Toast message with the [Toast.LENGTH_LONG] duration.
*
* @param message the message text resource.
*/
inline fun Fragment.longToast(message: Int) = requireActivity().longToast(message)
fun Fragment.longToast(message: Int) = requireActivity().longToast(message)
/**
* Display the simple Toast message with the [Toast.LENGTH_LONG] duration.
*
* @param message the message text.
*/
inline fun Fragment.longToast(message: CharSequence) = requireActivity().longToast(message)
fun Fragment.longToast(message: CharSequence) = requireActivity().longToast(message)

Loading…
Cancel
Save