update Base

androidx
Ztiany 5 years ago
parent f19c35b70d
commit fb8c8c90d5
  1. 14
      lib_base/src/main/java/com/android/base/app/fragment/BaseDialogFragment.kt
  2. 14
      lib_base/src/main/java/com/android/base/app/fragment/BaseFragment.kt
  3. 13
      lib_base/src/main/java/com/android/base/app/fragment/utils.kt
  4. 3
      lib_base/src/main/java/com/android/base/imageloader/Source.java
  5. 12
      lib_base/src/main/java/com/android/base/utils/android/ActFragWrapper.java
  6. 21
      lib_base/src/main/java/com/android/base/utils/android/BitmapUtils.kt
  7. 31
      lib_base/src/main/java/com/android/base/utils/common/Files.kt
  8. 2
      lib_qrcode/src/main/java/com/android/sdk/qrcode/CameraUtils.java
  9. 6
      lib_qrcode/src/main/java/com/android/sdk/qrcode/Debug.java
  10. 2
      lib_qrcode/src/main/java/com/android/sdk/qrcode/QRCodeView.kt

@ -39,6 +39,18 @@ open class BaseDialogFragment : AppCompatDialogFragment(), LoadingView, OnBackPr
private var recentShowingDialogTime: Long = 0
private var _state: Bundle? = null
protected val state: Bundle
get() {
var state = _state
if (state == null) {
state = Bundle()
_state = state
}
return state
}
private fun tag() = this.javaClass.simpleName
override fun onAttach(context: Context) {
@ -49,6 +61,7 @@ open class BaseDialogFragment : AppCompatDialogFragment(), LoadingView, OnBackPr
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
_state = getInstanceState(savedInstanceState)
Timber.tag(tag()).d("-->onCreate savedInstanceState = $savedInstanceState")
fragmentDelegates.onCreate(savedInstanceState)
}
@ -156,6 +169,7 @@ open class BaseDialogFragment : AppCompatDialogFragment(), LoadingView, OnBackPr
override fun onSaveInstanceState(outState: Bundle) {
fragmentDelegates.onSaveInstanceState(outState)
saveInstanceState(outState, _state)
super.onSaveInstanceState(outState)
}

@ -50,6 +50,18 @@ open class BaseFragment : Fragment(), LoadingView, OnBackPressListener, Fragment
private var recentShowingDialogTime: Long = 0
private var _state: Bundle? = null
protected val state: Bundle
get() {
var state = _state
if (state == null) {
state = Bundle()
_state = state
}
return state
}
private fun tag() = this.javaClass.simpleName
override fun onAttach(context: Context) {
@ -60,6 +72,7 @@ open class BaseFragment : Fragment(), LoadingView, OnBackPressListener, Fragment
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
_state = getInstanceState(savedInstanceState)
Timber.tag(tag()).d("-->onCreate savedInstanceState = $savedInstanceState")
fragmentDelegates.onCreate(savedInstanceState)
}
@ -167,6 +180,7 @@ open class BaseFragment : Fragment(), LoadingView, OnBackPressListener, Fragment
override fun onSaveInstanceState(outState: Bundle) {
fragmentDelegates.onSaveInstanceState(outState)
saveInstanceState(outState, _state)
super.onSaveInstanceState(outState)
}

@ -1,5 +1,6 @@
package com.android.base.app.fragment
import android.os.Bundle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import com.android.base.app.ui.LoadingView
@ -36,4 +37,16 @@ internal fun <T> T.dismissDialog(recentShowingDialogTime: Long, minimumMills: Lo
}
}
}
private const val FRAGMENT_STATE_KEY = "fragment_state_key"
internal fun saveInstanceState(outState: Bundle, _state: Bundle?) {
_state?.let {
outState.putBundle(FRAGMENT_STATE_KEY, it)
}
}
internal fun getInstanceState(state: Bundle?): Bundle? {
return state?.getBundle(FRAGMENT_STATE_KEY)
}

@ -13,6 +13,9 @@ public class Source {
Uri mUri;
byte[] mBytes;
private Source() {
}
public static Source create(String url) {
Source source = new Source();
source.mUrl = url;

@ -24,6 +24,12 @@ public class ActFragWrapper {
return context;
}
public static ActFragWrapper create(Fragment fragment) {
ActFragWrapper context = new ActFragWrapper();
context.mFragment = fragment;
return context;
}
public Context getContext() {
if (mActivity != null) {
return mActivity;
@ -44,12 +50,6 @@ public class ActFragWrapper {
}
}
public static ActFragWrapper create(Fragment fragment) {
ActFragWrapper context = new ActFragWrapper();
context.mFragment = fragment;
return context;
}
public void startService(Intent intent) {
if (mActivity != null) {
mActivity.startService(intent);

@ -0,0 +1,21 @@
package com.android.base.utils.android
import android.graphics.Bitmap
import androidx.annotation.IntRange
import com.android.base.utils.common.makeParentPath
import java.io.File
import java.io.FileOutputStream
fun Bitmap.saveToFile(format: Bitmap.CompressFormat, @IntRange(from = 1, to = 100) quality: Int, savePath: String): Boolean {
return try {
val file = File(savePath)
file.makeParentPath()
file.createNewFile()
compress(format, quality, FileOutputStream(file))
true
} catch (e: Exception) {
e.printStackTrace()
false
}
}

@ -6,20 +6,17 @@ import com.blankj.utilcode.util.FileUtils
import timber.log.Timber
import java.io.File
fun File?.makeFilePath(): Boolean {
if (this == null) {
return false
}
val parent = this.parentFile
return parent.exists() || makeDir(parent)
fun File.makeParentPath(): Boolean {
val path = this.parentFile
return path.exists() || makeDir(path)
}
private fun makeDir(file: File?): Boolean {
return file != null && (file.exists() || file.mkdirs())
}
fun File?.sizeOf(): Long {
if (this == null || !this.exists()) {
fun File.sizeOf(): Long {
if (!this.exists()) {
return 0
}
return if (this.isDirectory) {
@ -44,25 +41,15 @@ fun File.deleteSelf() {
}
}
fun File?.isFileExists(): Boolean {
return this != null && this.isFile && this.exists()
}
/**
* 获取全路径中的文件拓展名
*
* @return 文件拓展名
*/
fun File?.getFileExtension(): String? {
return if (this == null) null else getFileExtension(this.path)
fun File.isFileExists(): Boolean {
return this.isFile && this.exists()
}
/**
* 获取全路径中的文件拓展名
*
* @param filePath 文件路径
* @return 文件拓展名
*/
fun getFileExtension(filePath: String): String {
return FileUtils.getFileExtension(filePath)
fun File.getFileExtension(): String {
return FileUtils.getFileExtension(this.absolutePath)
}

@ -127,4 +127,4 @@ public class CameraUtils {
return supportedPreviewResolutions.get(supportedPreviewResolutions.size() - 1);
}
}
}

@ -7,16 +7,16 @@ import android.util.Log;
* Email: ztiany3@gmail.com
* Date : 2019-04-02 12:55
*/
public class Debug {
class Debug {
private static final String TAG = "QRCODE";
private static boolean debug = BuildConfig.DEBUG;
public static void setDebug(boolean debug) {
static void setDebug(boolean debug) {
Debug.debug = debug;
}
public static void log(String msg) {
static void log(String msg) {
if (debug && msg != null) {
Log.d(TAG, msg);
}

@ -197,7 +197,6 @@ abstract class QRCodeView @JvmOverloads constructor(
} catch (e: Exception) {
e.printStackTrace()
}
}
/**
@ -209,7 +208,6 @@ abstract class QRCodeView @JvmOverloads constructor(
} catch (e: Exception) {
e.printStackTrace()
}
}
/**

Loading…
Cancel
Save