diff --git a/app/src/main/java/com/gh/common/databind/BindingAdapters.java b/app/src/main/java/com/gh/common/databind/BindingAdapters.java index 1d47fae3a1..812b02efd3 100644 --- a/app/src/main/java/com/gh/common/databind/BindingAdapters.java +++ b/app/src/main/java/com/gh/common/databind/BindingAdapters.java @@ -52,6 +52,8 @@ import com.gh.gamecenter.WebActivity; import com.gh.gamecenter.common.entity.LinkEntity; import com.gh.gamecenter.common.utils.DarkModeUtils; import com.gh.gamecenter.common.utils.ExtensionsKt; +import com.gh.gamecenter.common.utils.FileUtils; +import com.gh.gamecenter.common.utils.ImageUtils; import com.gh.gamecenter.common.utils.NewFlatLogUtils; import com.gh.gamecenter.common.utils.SensorsBridge; import com.gh.gamecenter.core.utils.MtaHelper; @@ -69,7 +71,6 @@ import com.gh.gamecenter.gamedetail.dialog.GamePermissionDialogFragment; import com.gh.gamecenter.manager.PackagesManager; import com.gh.vspace.VHelper; import com.lightgame.download.DownloadEntity; -import com.lightgame.download.FileUtils; import com.lightgame.utils.Utils; import java.io.File; diff --git a/app/src/main/java/com/gh/common/simulator/SimulatorDownloadManager.kt b/app/src/main/java/com/gh/common/simulator/SimulatorDownloadManager.kt index a4a274a7d9..85566ef106 100644 --- a/app/src/main/java/com/gh/common/simulator/SimulatorDownloadManager.kt +++ b/app/src/main/java/com/gh/common/simulator/SimulatorDownloadManager.kt @@ -20,15 +20,14 @@ import com.gh.gamecenter.common.constant.Constants import com.gh.gamecenter.common.utils.* import com.gh.gamecenter.core.AppExecutor.uiExecutor import com.gh.gamecenter.core.utils.* +import com.gh.gamecenter.entity.TrackableEntity import com.gh.gamecenter.feature.entity.ApkEntity import com.gh.gamecenter.feature.entity.SimulatorEntity -import com.gh.gamecenter.entity.TrackableEntity import com.gh.ndownload.NDataChanger import com.halo.assistant.HaloApp import com.lightgame.download.DataWatcher import com.lightgame.download.DownloadEntity import com.lightgame.download.DownloadStatus -import com.lightgame.download.FileUtils import com.lightgame.utils.Utils import java.lang.ref.WeakReference import java.text.DecimalFormat diff --git a/app/src/main/java/com/gh/common/simulator/SimulatorGameManager.kt b/app/src/main/java/com/gh/common/simulator/SimulatorGameManager.kt index 2371b85f02..60193d0c24 100644 --- a/app/src/main/java/com/gh/common/simulator/SimulatorGameManager.kt +++ b/app/src/main/java/com/gh/common/simulator/SimulatorGameManager.kt @@ -30,7 +30,6 @@ import com.gh.gamecenter.room.AppDatabase import com.halo.assistant.HaloApp import com.lightgame.download.DownloadDao import com.lightgame.download.DownloadEntity -import com.lightgame.download.FileUtils import com.lightgame.utils.AppManager import io.reactivex.Single import io.reactivex.android.schedulers.AndroidSchedulers diff --git a/app/src/main/java/com/gh/common/util/DownloadItemUtils.kt b/app/src/main/java/com/gh/common/util/DownloadItemUtils.kt index d345a3d63e..dd2babb65f 100644 --- a/app/src/main/java/com/gh/common/util/DownloadItemUtils.kt +++ b/app/src/main/java/com/gh/common/util/DownloadItemUtils.kt @@ -46,7 +46,6 @@ import com.gh.vspace.VHelper import com.lightgame.download.DownloadConfig import com.lightgame.download.DownloadEntity import com.lightgame.download.DownloadStatus -import com.lightgame.download.FileUtils import com.lightgame.utils.Utils import java.io.File import java.util.concurrent.LinkedBlockingQueue diff --git a/app/src/main/java/com/gh/common/util/DownloadObserver.kt b/app/src/main/java/com/gh/common/util/DownloadObserver.kt index beeb5712fc..df7364f52c 100644 --- a/app/src/main/java/com/gh/common/util/DownloadObserver.kt +++ b/app/src/main/java/com/gh/common/util/DownloadObserver.kt @@ -32,7 +32,10 @@ import com.gh.gamecenter.help.HelpAndFeedbackBridge import com.gh.gamecenter.pkg.PkgHelper import com.gh.vspace.VHelper import com.halo.assistant.HaloApp -import com.lightgame.download.* +import com.lightgame.download.DataWatcher +import com.lightgame.download.DownloadConfig +import com.lightgame.download.DownloadEntity +import com.lightgame.download.DownloadStatus import com.lightgame.utils.AppManager import com.lightgame.utils.Utils import org.greenrobot.eventbus.EventBus diff --git a/app/src/main/java/com/gh/common/util/GameActivityDownloadHelper.kt b/app/src/main/java/com/gh/common/util/GameActivityDownloadHelper.kt index c14f66c3f6..65502f06eb 100644 --- a/app/src/main/java/com/gh/common/util/GameActivityDownloadHelper.kt +++ b/app/src/main/java/com/gh/common/util/GameActivityDownloadHelper.kt @@ -41,7 +41,6 @@ import com.gh.gamecenter.retrofit.RetrofitManager import com.gh.gamecenter.teenagermode.TeenagerModeActivity import com.gh.vspace.VHelper import com.lightgame.download.DownloadEntity -import com.lightgame.download.FileUtils import com.lightgame.utils.Utils import java.io.File diff --git a/app/src/main/java/com/gh/common/util/PackageInstaller.kt b/app/src/main/java/com/gh/common/util/PackageInstaller.kt index d599cfc759..dd198c10eb 100644 --- a/app/src/main/java/com/gh/common/util/PackageInstaller.kt +++ b/app/src/main/java/com/gh/common/util/PackageInstaller.kt @@ -24,7 +24,6 @@ import com.gh.gamecenter.vpn.VpnHelper import com.gh.vspace.VHelper import com.halo.assistant.HaloApp import com.lightgame.download.DownloadEntity -import com.lightgame.download.FileUtils import com.lightgame.utils.Utils import java.io.File diff --git a/app/src/main/java/com/gh/common/xapk/XapkUnzipThread.kt b/app/src/main/java/com/gh/common/xapk/XapkUnzipThread.kt index 7c769b0cfd..8a42dc8035 100644 --- a/app/src/main/java/com/gh/common/xapk/XapkUnzipThread.kt +++ b/app/src/main/java/com/gh/common/xapk/XapkUnzipThread.kt @@ -2,15 +2,11 @@ package com.gh.common.xapk import android.os.Build import android.os.Environment -import com.gh.gamecenter.common.utils.debounceActionWithInterval -import com.gh.gamecenter.common.utils.getExtension -import com.gh.gamecenter.common.utils.throwException -import com.gh.gamecenter.common.utils.throwExceptionInDebug import com.gh.gamecenter.BuildConfig +import com.gh.gamecenter.common.utils.* import com.gh.gamecenter.core.utils.MD5Utils import com.halo.assistant.HaloApp import com.lightgame.download.DownloadEntity -import com.lightgame.download.FileUtils import com.lightgame.utils.Utils import net.lingala.zip4j.progress.ProgressMonitor import java.io.File diff --git a/app/src/main/java/com/gh/download/DownloadManager.java b/app/src/main/java/com/gh/download/DownloadManager.java index 83ba99271c..9f924e137a 100644 --- a/app/src/main/java/com/gh/download/DownloadManager.java +++ b/app/src/main/java/com/gh/download/DownloadManager.java @@ -25,36 +25,44 @@ import com.gh.gamecenter.feature.entity.CustomPageTrackData; import com.gh.gamecenter.feature.entity.TagStyleEntity; import com.gh.gamecenter.feature.exposure.ExposureEvent; import com.gh.common.exposure.ExposureUtils; -import com.gh.gamecenter.common.exposure.meta.MetaUtil; import com.gh.common.history.HistoryHelper; import com.gh.common.simulator.SimulatorGameManager; import com.gh.common.util.DataCollectionUtils; -import com.gh.gamecenter.common.utils.DeviceUtils; import com.gh.common.util.DialogUtils; -import com.gh.gamecenter.core.utils.GsonUtils; import com.gh.common.util.HomePluggableHelper; import com.gh.common.util.LunchType; -import com.gh.gamecenter.common.utils.NetworkUtils; import com.gh.common.util.PackageInstaller; import com.gh.common.util.PackageUtils; +import com.gh.gamecenter.BuildConfig; +import com.gh.gamecenter.common.base.GlobalActivityManager; +import com.gh.gamecenter.common.constant.Constants; +import com.gh.gamecenter.common.exposure.meta.MetaUtil; +import com.gh.gamecenter.common.utils.DeviceUtils; +import com.gh.gamecenter.common.utils.ExtensionsKt; +import com.gh.gamecenter.common.utils.FileUtils; +import com.gh.gamecenter.common.utils.NetworkUtils; +import com.gh.gamecenter.common.utils.SensorsBridge; +import com.gh.gamecenter.core.AppExecutor; +import com.gh.gamecenter.core.utils.AppDebugConfig; +import com.gh.gamecenter.core.utils.GsonUtils; import com.gh.gamecenter.core.utils.PageSwitchDataHelper; import com.gh.gamecenter.core.utils.SPUtils; -import com.gh.gamecenter.BuildConfig; import com.gh.gamecenter.core.utils.SentryHelper; import com.gh.gamecenter.download.DownloadedGameIdAndPackageNameDao; -import com.gh.gamecenter.feature.entity.ApkEntity; -import com.gh.gamecenter.feature.entity.GameEntity; import com.gh.gamecenter.entity.GameUpdateEntity; import com.gh.gamecenter.entity.HomePluggableFilterEntity; -import com.gh.gamecenter.feature.entity.PluginLocation; import com.gh.gamecenter.eventbus.EBDownloadStatus; -import com.gh.gamecenter.manager.PackagesManager; +import com.gh.gamecenter.feature.entity.ApkEntity; +import com.gh.gamecenter.feature.entity.GameEntity; +import com.gh.gamecenter.feature.entity.PluginLocation; +import com.gh.gamecenter.feature.exposure.ExposureEvent; import com.gh.gamecenter.login.user.UserManager; +import com.gh.gamecenter.manager.PackagesManager; import com.gh.gamecenter.packagehelper.PackageRepository; -import com.gh.vspace.VHelper; import com.gh.ndownload.NDataChanger; import com.gh.ndownload.NDownloadBridge; import com.gh.ndownload.NDownloadService; +import com.gh.vspace.VHelper; import com.halo.assistant.HaloApp; import com.lightgame.download.ConnectionUtils; import com.lightgame.download.DataWatcher; @@ -63,7 +71,6 @@ import com.lightgame.download.DownloadDao; import com.lightgame.download.DownloadEntity; import com.lightgame.download.DownloadStatus; import com.lightgame.download.DownloadStatusListener; -import com.lightgame.download.FileUtils; import com.lightgame.download.HttpDnsManager; import com.lightgame.utils.Utils; diff --git a/app/src/main/java/com/gh/download/PackageObserver.kt b/app/src/main/java/com/gh/download/PackageObserver.kt index 6af21e4bb3..9f9dd3b53d 100644 --- a/app/src/main/java/com/gh/download/PackageObserver.kt +++ b/app/src/main/java/com/gh/download/PackageObserver.kt @@ -4,12 +4,16 @@ import android.annotation.SuppressLint import android.text.TextUtils import com.gh.common.util.* import com.gh.gamecenter.feature.utils.ConcernUtils +import com.gh.common.util.DataCollectionUtils +import com.gh.common.util.PackageInstaller +import com.gh.common.util.PackageUtils import com.gh.common.xapk.XapkInstaller import com.gh.download.server.BrowserInstallHelper import com.gh.gamecenter.common.constant.Constants import com.gh.gamecenter.common.loghub.LoghubUtils import com.gh.gamecenter.common.retrofit.EmptyResponse import com.gh.gamecenter.common.retrofit.Response +import com.gh.gamecenter.common.utils.FileUtils import com.gh.gamecenter.common.utils.* import com.gh.gamecenter.common.utils.NewFlatLogUtils import com.gh.gamecenter.core.runOnIoThread @@ -18,6 +22,7 @@ import com.gh.gamecenter.core.utils.ThirdPartyPackageHelper import com.gh.gamecenter.core.utils.UrlFilterUtils import com.gh.gamecenter.entity.GameDigestEntity import com.gh.gamecenter.eventbus.EBPackage +import com.gh.gamecenter.feature.utils.ConcernUtils import com.gh.gamecenter.login.user.UserManager import com.gh.gamecenter.manager.PackagesManager import com.gh.gamecenter.packagehelper.PackageRepository diff --git a/app/src/main/java/com/gh/download/dialog/DownloadDialogItemViewHolder.kt b/app/src/main/java/com/gh/download/dialog/DownloadDialogItemViewHolder.kt index 60844b373e..38c9feeb80 100644 --- a/app/src/main/java/com/gh/download/dialog/DownloadDialogItemViewHolder.kt +++ b/app/src/main/java/com/gh/download/dialog/DownloadDialogItemViewHolder.kt @@ -28,7 +28,6 @@ import com.gh.gamecenter.feature.exposure.ExposureEvent import com.gh.gamecenter.manager.PackagesManager import com.lightgame.download.DownloadEntity import com.lightgame.download.DownloadStatus -import com.lightgame.download.FileUtils import com.lightgame.utils.AppManager import com.lightgame.utils.Utils diff --git a/app/src/main/java/com/gh/download/server/DownloadServer.kt b/app/src/main/java/com/gh/download/server/DownloadServer.kt index c84024e9a3..67a54b7776 100644 --- a/app/src/main/java/com/gh/download/server/DownloadServer.kt +++ b/app/src/main/java/com/gh/download/server/DownloadServer.kt @@ -1,12 +1,12 @@ package com.gh.download.server +import com.gh.download.DownloadManager import com.gh.gamecenter.common.constant.Constants -import com.gh.gamecenter.feature.exposure.ExposureEvent +import com.gh.gamecenter.common.utils.FileUtils import com.gh.gamecenter.common.utils.getMetaExtra import com.gh.gamecenter.common.utils.toObject -import com.gh.download.DownloadManager +import com.gh.gamecenter.feature.exposure.ExposureEvent import com.halo.assistant.HaloApp -import com.lightgame.download.FileUtils import fi.iki.elonen.NanoHTTPD import io.reactivex.disposables.CompositeDisposable import io.reactivex.schedulers.Schedulers diff --git a/app/src/main/java/com/gh/gamecenter/MainActivity.java b/app/src/main/java/com/gh/gamecenter/MainActivity.java index a52e2a6801..de0edfeb33 100644 --- a/app/src/main/java/com/gh/gamecenter/MainActivity.java +++ b/app/src/main/java/com/gh/gamecenter/MainActivity.java @@ -79,6 +79,7 @@ import com.gh.gamecenter.common.retrofit.BiResponse; import com.gh.gamecenter.common.retrofit.Response; import com.gh.gamecenter.common.utils.DialogHelper; import com.gh.gamecenter.common.utils.ExtensionsKt; +import com.gh.gamecenter.common.utils.FileUtils; import com.gh.gamecenter.common.utils.NewFlatLogUtils; import com.gh.gamecenter.common.utils.SensorsBridge; import com.gh.gamecenter.common.utils.ShareUtils; @@ -114,6 +115,7 @@ import com.halo.assistant.HaloApp; import com.lightgame.download.DownloadEntity; import com.lightgame.download.DownloadStatus; import com.lightgame.download.FileUtils; +import com.lightgame.utils.AppManager; import com.lightgame.utils.Utils; import com.sina.weibo.sdk.auth.AuthInfo; import com.sina.weibo.sdk.openapi.IWBAPI; diff --git a/app/src/main/java/com/gh/gamecenter/cloudarchive/MyArchiveOptionDialogFragment.kt b/app/src/main/java/com/gh/gamecenter/cloudarchive/MyArchiveOptionDialogFragment.kt index ee52a09504..d13a366351 100644 --- a/app/src/main/java/com/gh/gamecenter/cloudarchive/MyArchiveOptionDialogFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/cloudarchive/MyArchiveOptionDialogFragment.kt @@ -23,7 +23,6 @@ import com.gh.gamecenter.entity.ArchiveEntity import com.gh.gamecenter.feature.entity.GameEntity import com.gh.vspace.VArchiveHelper import com.halo.assistant.HaloApp -import com.lightgame.download.FileUtils import org.greenrobot.eventbus.EventBus class MyArchiveOptionDialogFragment( diff --git a/app/src/main/java/com/gh/gamecenter/download/GameDownloadFragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/download/GameDownloadFragmentAdapter.java index d377745cc6..ca1d9ddaec 100644 --- a/app/src/main/java/com/gh/gamecenter/download/GameDownloadFragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/download/GameDownloadFragmentAdapter.java @@ -28,6 +28,7 @@ import com.gh.gamecenter.common.constant.Constants; import com.gh.gamecenter.common.entity.IconFloat; import com.gh.gamecenter.common.utils.DialogHelper; import com.gh.gamecenter.common.utils.ExtensionsKt; +import com.gh.gamecenter.common.utils.FileUtils; import com.gh.gamecenter.common.utils.ImageUtils; import com.gh.gamecenter.common.utils.NetworkUtils; import com.gh.gamecenter.common.utils.NewFlatLogUtils; @@ -44,7 +45,6 @@ import com.lightgame.adapter.BaseRecyclerAdapter; import com.lightgame.download.DownloadConfig; import com.lightgame.download.DownloadEntity; import com.lightgame.download.DownloadStatus; -import com.lightgame.download.FileUtils; import com.lightgame.utils.Utils; import org.greenrobot.eventbus.EventBus; diff --git a/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java b/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/src/main/java/com/gh/gamecenter/qa/video/publish/VideoPublishFragment.kt b/app/src/main/java/com/gh/gamecenter/qa/video/publish/VideoPublishFragment.kt index bc56f60914..a6bf26fc7a 100644 --- a/app/src/main/java/com/gh/gamecenter/qa/video/publish/VideoPublishFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/qa/video/publish/VideoPublishFragment.kt @@ -47,7 +47,6 @@ import com.gh.gamecenter.video.upload.OnUploadListener import com.gh.gamecenter.video.upload.UploadManager import com.gh.gamecenter.video.upload.view.VideoFileEntity import com.gh.gamecenter.video.videomanager.VideoDraftActivity -import com.lightgame.download.FileUtils import com.lightgame.utils.Util_System_Keyboard import java.io.File diff --git a/app/src/main/java/com/gh/gamecenter/video/upload/view/UploadVideoActivity.kt b/app/src/main/java/com/gh/gamecenter/video/upload/view/UploadVideoActivity.kt index 59206799b2..09fcf9611a 100644 --- a/app/src/main/java/com/gh/gamecenter/video/upload/view/UploadVideoActivity.kt +++ b/app/src/main/java/com/gh/gamecenter/video/upload/view/UploadVideoActivity.kt @@ -53,7 +53,6 @@ import com.gh.gamecenter.video.poster.PosterEditActivity import com.gh.gamecenter.video.upload.OnUploadListener import com.gh.gamecenter.video.upload.UploadManager import com.google.android.flexbox.FlexboxLayout -import com.lightgame.download.FileUtils import com.lightgame.utils.Util_System_Keyboard import com.lightgame.utils.Utils import com.zhihu.matisse.Matisse diff --git a/app/src/main/java/com/gh/ndownload/NDownloadBridge.kt b/app/src/main/java/com/gh/ndownload/NDownloadBridge.kt index ba960a0c4b..540922e923 100644 --- a/app/src/main/java/com/gh/ndownload/NDownloadBridge.kt +++ b/app/src/main/java/com/gh/ndownload/NDownloadBridge.kt @@ -19,7 +19,6 @@ import com.lg.download.listener.InnerDownloadListener import com.lg.ndownload.* import com.lightgame.download.DownloadDao import com.lightgame.download.DownloadEntity -import com.lightgame.download.FileUtils import com.lightgame.utils.Utils import com.tencent.vasdolly.reader.ChannelReader import com.tencent.vasdolly.writer.ChannelWriter diff --git a/app/src/main/java/com/gh/vspace/gapps/GAppsDownloadDialogFragment.kt b/app/src/main/java/com/gh/vspace/gapps/GAppsDownloadDialogFragment.kt index d6562ea2fb..f3ae20579e 100644 --- a/app/src/main/java/com/gh/vspace/gapps/GAppsDownloadDialogFragment.kt +++ b/app/src/main/java/com/gh/vspace/gapps/GAppsDownloadDialogFragment.kt @@ -14,6 +14,7 @@ import com.gh.common.util.NewFlatLogUtils import com.gh.download.simple.* import com.gh.gamecenter.R import com.gh.gamecenter.common.base.fragment.BaseBottomDialogFragment +import com.gh.gamecenter.common.utils.FileUtils import com.gh.gamecenter.common.utils.toColor import com.gh.gamecenter.core.AppExecutor import com.gh.gamecenter.core.runOnIoThread @@ -28,7 +29,6 @@ import com.lg.download.DownloadError import com.lg.download.DownloadStatus import com.lg.download.httpclient.DefaultHttpClient import com.lg.ndownload.DownloadConfigBuilder -import com.lightgame.download.FileUtils import java.io.File class GAppsDownloadDialogFragment : BaseBottomDialogFragment() { diff --git a/module_common/src/main/java/com/gh/gamecenter/common/base/activity/BaseActivity.java b/module_common/src/main/java/com/gh/gamecenter/common/base/activity/BaseActivity.java index c7c873c0b5..c8fbb08660 100644 --- a/module_common/src/main/java/com/gh/gamecenter/common/base/activity/BaseActivity.java +++ b/module_common/src/main/java/com/gh/gamecenter/common/base/activity/BaseActivity.java @@ -51,11 +51,12 @@ import com.gh.gamecenter.common.constant.EntranceConsts; import com.gh.gamecenter.common.constant.RouteConsts; import com.gh.gamecenter.common.eventbus.EBShowDialog; import com.gh.gamecenter.common.tracker.IBusiness; +import com.gh.gamecenter.common.utils.DarkModeUtils; import com.gh.gamecenter.common.utils.DialogHelper; import com.gh.gamecenter.common.utils.EnvHelper; import com.gh.gamecenter.common.utils.ExtensionsKt; +import com.gh.gamecenter.common.utils.FileUtils; import com.gh.gamecenter.common.utils.NetworkUtils; -import com.gh.gamecenter.common.utils.DarkModeUtils; import com.gh.gamecenter.common.utils.NewFlatLogUtils; import com.gh.gamecenter.common.utils.PackageFlavorHelper; import com.gh.gamecenter.common.utils.SensorsBridge; @@ -71,7 +72,6 @@ import com.gh.gamecenter.core.utils.SPUtils; import com.gh.gamecenter.core.utils.StringUtils; import com.lightgame.BaseAppCompatActivity; import com.lightgame.download.DownloadEntity; -import com.lightgame.download.FileUtils; import com.lightgame.utils.Utils; import com.tencent.tauth.Tencent; diff --git a/module_common/src/main/java/com/gh/gamecenter/common/retrofit/OkHttpCache.java b/module_common/src/main/java/com/gh/gamecenter/common/retrofit/OkHttpCache.java index a8a1b4e50e..0452e165ec 100644 --- a/module_common/src/main/java/com/gh/gamecenter/common/retrofit/OkHttpCache.java +++ b/module_common/src/main/java/com/gh/gamecenter/common/retrofit/OkHttpCache.java @@ -2,9 +2,9 @@ package com.gh.gamecenter.common.retrofit; import android.content.Context; -import com.gh.gamecenter.core.utils.MD5Utils; +import com.gh.gamecenter.common.utils.FileUtils; import com.gh.gamecenter.common.utils.TimestampUtils; -import com.lightgame.download.FileUtils; +import com.gh.gamecenter.core.utils.MD5Utils; import java.io.File; import java.io.IOException; diff --git a/module_common/src/main/java/com/gh/gamecenter/common/utils/FileUtils.java b/module_common/src/main/java/com/gh/gamecenter/common/utils/FileUtils.java new file mode 100644 index 0000000000..35d115b977 --- /dev/null +++ b/module_common/src/main/java/com/gh/gamecenter/common/utils/FileUtils.java @@ -0,0 +1,607 @@ +package com.gh.gamecenter.common.utils; + +import android.Manifest; +import android.content.Context; +import android.content.pm.PackageManager; +import android.database.Cursor; +import android.net.Uri; +import android.os.Environment; +import android.os.StatFs; +import android.os.StrictMode; +import android.provider.MediaStore; + +import androidx.annotation.Nullable; + +import com.lightgame.download.ChmodException; + +import org.json.JSONObject; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.UUID; + +/** + * @author guanchao wen + * @email shuwoom.wgc@gmail.com + * @modify hzh 2016/03/16 + * @update 2015-7-29下午2:26:02 + */ +public class FileUtils { + + public static String getDownloadPath(Context context, String name) { + return getDownloadDir(context) + File.separator + name; + } + + public static String getDownloadDir(Context context) { + String dir = null; + if (isMounted() + && context.checkCallingOrSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + String baseDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath(); + dir = checkDir(baseDir + File.separator + "gh-files"); + File file = new File(dir); + if (file.exists() && !file.canRead()) { + dir = null; + } + } + if (dir == null) { + String baseDir = context.getFilesDir().getAbsolutePath(); + dir = checkDir(baseDir + File.separator + "gh-files"); + try { + Runtime.getRuntime().exec("chmod 755 " + dir); + } catch (IOException e) { + throw new ChmodException("Cannot chmod 755 " + dir); + } + } + return dir; + } + + public static boolean isMounted() { + return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); + } + + private static String checkDir(String dir) { + File directory = new File(dir); + if (directory.exists() && !directory.isDirectory()) { + directory.delete(); + } + if (!directory.exists()) { + directory.mkdirs(); + } + return dir; + } + + public static String getLogPath(Context context, String name) { + return checkDir(getDir(context, "log")) + File.separator + name; + } + + public static String getDir(Context context, String dir) { + if (isMounted()) { + // /storage/emulated/0/Android/data/包名/files + File file = context.getExternalFilesDir(null); + if (file != null) { + return file.getAbsolutePath() + File.separator + dir; + } + } + // /data/data/包名/files + return context.getFilesDir().getAbsolutePath() + File.separator + dir; + } + + public static String getPlatformPicDir(Context context) { + return checkDir(getDir(context, "PlatformPic")); + } + + public static void deleteFile(String savePath) { + try { + File file = new File(savePath); + if (file.exists()) { + file.delete(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void deleteFolder(File folder) { + if (folder != null) { + if (folder.isDirectory()) { + for (File file : folder.listFiles()) { + if (file.isDirectory()) { + deleteFolder(file); + } else { + file.delete(); + } + } + } + folder.delete(); + } + } + + public static boolean isEmptyFile(String path) { + File file = new File(path); + return !(file.exists() && file.length() != 0); + } + + public static String isCanDownload(Context context, String size) { + String msg = null; + String packageSizeStr = ""; + for (int i = 0; i < size.length(); i++) { + if ((size.charAt(i) >= 48 && size.charAt(i) <= 57) || size.charAt(i) == 46) { + packageSizeStr += size.charAt(i); + } + } + float packageSize = 0; + if (packageSizeStr.length() != 0) { + packageSize = Float.valueOf(packageSizeStr); + } + float freeSpace = getFreeSpaceByPath(getDownloadDir(context)); + if (freeSpace < packageSize) { + msg = "手机存储空间不足,无法进行下载!"; + } + return msg; + } + + public static String isCanDownload(Context context, long size) { + String msg = null; + float freeSpace = getFreeSpaceByPath(getDownloadDir(context)); + if (freeSpace < size / 1024f / 1024f) { + msg = "手机存储空间不足,无法进行下载!"; + } + return msg; + } + + // 返回剩余空间 单位MB + @SuppressWarnings("deprecation") + public static float getFreeSpaceByPath(String path) { + // 部分用 SD卡的老手机会抛出 java.lang.IllegalArgumentException: Invalid path: 的异常 + // 出现这异常干脆返回 8192MB 让他下 + try { + StatFs statfs = new StatFs(path); + long blockSize = statfs.getBlockSize(); + long availableBlocks = statfs.getAvailableBlocks(); + + return availableBlocks * blockSize / 1024f / 1024f; + } catch (Exception e) { + e.printStackTrace(); + return 8192; + } + } + + // 下载文件 + public static int downloadFile(String url, String savePath) { + DataInputStream dis = null; + FileOutputStream fos = null; + try { + HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); + connection.setRequestMethod("GET"); + connection.setConnectTimeout(5 * 1000); + connection.setReadTimeout(5 * 1000); + connection.connect(); + int code = connection.getResponseCode(); + if (code == 200) { + dis = new DataInputStream(connection.getInputStream()); + File file = new File(savePath); + if (file.exists()) { + file.delete(); + } + file.getParentFile().mkdir(); + file.createNewFile(); + fos = new FileOutputStream(file); + byte[] buffer = new byte[1024]; + int len; + while ((len = dis.read(buffer)) != -1) { + fos.write(buffer, 0, len); + } + fos.flush(); + } + return code; + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (fos != null) { + try { + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (dis != null) { + try { + dis.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return -1; + } + + // 下载并更新文件 (与上面方法的不同之处是只有在下载完成以后才会更新旧文件) + public static int downloadAndUpdateFile(String url, String savePath) { + DataInputStream dis = null; + FileOutputStream fos = null; + try { + String tempSavePath = savePath + ".tmp"; + + HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); + connection.setRequestMethod("GET"); + connection.setConnectTimeout(5 * 1000); + connection.setReadTimeout(5 * 1000); + connection.connect(); + int code = connection.getResponseCode(); + if (code == 200) { + dis = new DataInputStream(connection.getInputStream()); + File tempFile = new File(tempSavePath); + if (tempFile.exists()) { + tempFile.delete(); + } + tempFile.getParentFile().mkdir(); + tempFile.createNewFile(); + fos = new FileOutputStream(tempFile); + byte[] buffer = new byte[1024]; + int len; + while ((len = dis.read(buffer)) != -1) { + fos.write(buffer, 0, len); + } + fos.flush(); + + File file = new File(savePath); + if (file.exists()) { + file.delete(); + } + + tempFile.renameTo(file); + } + return code; + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (fos != null) { + try { + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (dis != null) { + try { + dis.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return -1; + } + + // 上传文件 + public static JSONObject uploadFile(String url, String filePath, String token) { + String end = "\r\n"; + String twoHyphens = "--"; + String boundary = UUID.randomUUID().toString().replaceAll("-", "").substring(0, 16); + try { + HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); + /* + * Output to the connection. Default is false, set to true because + * post method must write something to the connection + */ + connection.setDoOutput(true); + // Read from the connection. Default is true. + connection.setDoInput(true); + // Post cannot use caches + connection.setUseCaches(false); + // Set the post method. Default is GET + connection.setRequestMethod("POST"); + connection.setConnectTimeout(5 * 1000); + connection.setReadTimeout(5 * 1000); + // 设置请求属性 + connection.setRequestProperty("Connection", "Keep-Alive"); + connection.setRequestProperty("Charset", "UTF-8"); + connection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary); + if (token != null) { + connection.setRequestProperty("TOKEN", token); + } + // 设置StrictMode 否则HTTPURLConnection连接失败,因为这是在主进程中进行网络连接 + StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() + .detectDiskReads().detectDiskWrites().detectNetwork() + .penaltyLog().build()); + File file = new File(filePath); +// if (file.exists()) { +// Utils.log("name = " + file.getName()); +// Utils.log("length = " + file.length()); +// } + // 设置DataOutputStream,getOutputStream中默认调用connect() + DataOutputStream dos = new DataOutputStream(connection.getOutputStream()); // output + // to the connection + dos.writeBytes(twoHyphens + boundary + end); + dos.writeBytes("Content-Disposition: form-data; " + + "name=\"Filedata\";filename=\"" + file.getName() + "\"" + end); + dos.writeBytes(end); + // 取得文件的FileInputStream + FileInputStream fStream = new FileInputStream(file); + // 设置每次写入8192bytes + int bufferSize = 8192; + byte[] buffer = new byte[bufferSize]; // 8k + int length; + // 从文件读取数据至缓冲区 + while ((length = fStream.read(buffer)) != -1) { + // 将资料写入DataOutputStream中 + dos.write(buffer, 0, length); + } + dos.writeBytes(end); + dos.writeBytes(twoHyphens + boundary + twoHyphens + end); + // 关闭流,写入的东西自动生成Http正文 + fStream.close(); + // 关闭DataOutputStream + dos.flush(); + dos.close(); + + InputStream inputStream; + try { + inputStream = connection.getInputStream(); + } catch (IOException ioe) { + inputStream = connection.getErrorStream(); + } + int ch; + StringBuffer b = new StringBuffer(); + while ((ch = inputStream.read()) != -1) { + b.append((char) ch); + } + // 显示网页响应内容 +// Utils.log("content = " + b.toString().trim()); + + int statusCode = connection.getResponseCode(); +// Utils.log("statusCode = " + statusCode); + JSONObject response = null; + switch (statusCode) { + case 200: + // {"icon":"http:\/\/gh-test-1.oss-cn-qingdao.aliyuncs.com\/pic\/57e4f4d58a3200042d29492f.jpg"} + response = new JSONObject(b.toString().trim()); + response.put("statusCode", 200); + break; + case 403: + response = new JSONObject(b.toString().trim()); + response.put("statusCode", 403); + break; + case 401: + response = new JSONObject(); + response.put("statusCode", 401); + break; + } + + return response; + } catch (Exception e) { + // 显示异常信息 + e.printStackTrace(); +// Utils.log("Fail:" + e); + } + return null; + } + + + // 上传文件 realPath:真实路径(防止对文件压缩后filePath路径改变) 提交成功后会返回该路径 以便识别上传文件的身份 + public static JSONObject uploadFile(String url, String filePath, String realPath, String token) { + String end = "\r\n"; + String twoHyphens = "--"; + String boundary = UUID.randomUUID().toString().replaceAll("-", "").substring(0, 16); + try { + HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); + /* + * Output to the connection. Default is false, set to true because + * post method must write something to the connection + */ + connection.setDoOutput(true); + // Read from the connection. Default is true. + connection.setDoInput(true); + // Post cannot use caches + connection.setUseCaches(false); + // Set the post method. Default is GET + connection.setRequestMethod("POST"); + connection.setConnectTimeout(5 * 1000); + connection.setReadTimeout(5 * 1000); + // 设置请求属性 + connection.setRequestProperty("Connection", "Keep-Alive"); + connection.setRequestProperty("Charset", "UTF-8"); + connection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary); + if (token != null) { + connection.setRequestProperty("TOKEN", token); + } + // 设置StrictMode 否则HTTPURLConnection连接失败,因为这是在主进程中进行网络连接 + StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() + .detectDiskReads().detectDiskWrites().detectNetwork() + .penaltyLog().build()); + File file = new File(filePath); +// if (file.exists()) { +// Utils.log("name = " + file.getName()); +// Utils.log("length = " + file.length()); +// } + // 设置DataOutputStream,getOutputStream中默认调用connect() + DataOutputStream dos = new DataOutputStream(connection.getOutputStream()); // output + // to the connection + dos.writeBytes(twoHyphens + boundary + end); + dos.writeBytes("Content-Disposition: form-data; " + + "name=\"Filedata\";filename=\"" + file.getName() + "\"" + end); + dos.writeBytes(end); + // 取得文件的FileInputStream + FileInputStream fStream = new FileInputStream(file); + // 设置每次写入8192bytes + int bufferSize = 8192; + byte[] buffer = new byte[bufferSize]; // 8k + int length; + // 从文件读取数据至缓冲区 + while ((length = fStream.read(buffer)) != -1) { + // 将资料写入DataOutputStream中 + dos.write(buffer, 0, length); + } + dos.writeBytes(end); + dos.writeBytes(twoHyphens + boundary + twoHyphens + end); + // 关闭流,写入的东西自动生成Http正文 + fStream.close(); + // 关闭DataOutputStream + dos.flush(); + dos.close(); + + InputStream inputStream; + try { + inputStream = connection.getInputStream(); + } catch (IOException ioe) { + inputStream = connection.getErrorStream(); + } + int ch; + StringBuffer b = new StringBuffer(); + while ((ch = inputStream.read()) != -1) { + b.append((char) ch); + } + // 显示网页响应内容 +// Utils.log("content = " + b.toString().trim()); + + int statusCode = connection.getResponseCode(); +// Utils.log("statusCode = " + statusCode); + JSONObject response = null; + switch (statusCode) { + case 200: + // {"icon":"http:\/\/gh-test-1.oss-cn-qingdao.aliyuncs.com\/pic\/57e4f4d58a3200042d29492f.jpg"} + response = new JSONObject(b.toString().trim()); + response.put("statusCode", 200); + response.put("realPath", realPath); + break; + case 403: + response = new JSONObject(b.toString().trim()); + response.put("statusCode", 403); + response.put("realPath", realPath); + break; + case 401: + response = new JSONObject(); + response.put("statusCode", 401); + break; + } + + return response; + } catch (Exception e) { + // 显示异常信息 + e.printStackTrace(); +// Utils.log("Fail:" + e); + } + return null; + } + + + // 读取文件,返回byte[] + public static byte[] readFile(File file) { + if (file == null) { + return null; + } + FileInputStream fis = null; + ByteArrayOutputStream bos = null; + try { + fis = new FileInputStream(file); + bos = new ByteArrayOutputStream(); + byte[] buffer = new byte[2048]; + int len; + while ((len = fis.read(buffer)) != -1) { + bos.write(buffer, 0, len); + } + bos.flush(); + return bos.toByteArray(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (fis != null) { + try { + fis.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (bos != null) { + try { + bos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return null; + } + + // 根据byte[],保存文件 + public static void saveFile(File file, byte[] data) { + if (file == null || data == null) { + return; + } + ByteArrayInputStream bis = null; + FileOutputStream fos = null; + try { + bis = new ByteArrayInputStream(data); + fos = new FileOutputStream(file); + byte[] buffer = new byte[2048]; + int len; + while ((len = bis.read(buffer)) != -1) { + fos.write(buffer, 0, len); + } + fos.flush(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (bis != null) { + try { + bis.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (fos != null) { + try { + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + /** + * @param context suggestion application context + * @param filePath file path + * @return A MIME type for the content {category}/{type} + * example: video/mp4 + */ + @Nullable + public static String getFileMimeType(Context context, String filePath) { + Uri contentUri = getFileContentUri(context, filePath); + if (contentUri != null) { + return context.getContentResolver().getType(contentUri); + } + return null; + } + + @Nullable + public static Uri getFileContentUri(Context context, String filePath) { + Cursor cursor = null; + try { + String absolutePath = new File(filePath).getAbsolutePath(); + cursor = context.getContentResolver().query( + MediaStore.Files.getContentUri("external"), + new String[]{MediaStore.Files.FileColumns._ID}, + MediaStore.Files.FileColumns.DATA + "=? ", + new String[]{absolutePath}, null); + if (cursor != null && cursor.moveToFirst()) { + int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID)); + cursor.close(); + return Uri.withAppendedPath(MediaStore.Files.getContentUri("external"), "" + id); + } else return null; + } catch (Exception ignore) { + } finally { + if (cursor != null) cursor.close(); + } + return null; + } +} diff --git a/module_core_feature/src/main/java/com/gh/gamecenter/feature/utils/PlatformUtils.java b/module_core_feature/src/main/java/com/gh/gamecenter/feature/utils/PlatformUtils.java index 06f0ac6625..78c0456fd9 100644 --- a/module_core_feature/src/main/java/com/gh/gamecenter/feature/utils/PlatformUtils.java +++ b/module_core_feature/src/main/java/com/gh/gamecenter/feature/utils/PlatformUtils.java @@ -11,12 +11,12 @@ import androidx.core.content.ContextCompat; import com.gh.gamecenter.common.eventbus.EBReuse; import com.gh.gamecenter.common.retrofit.Response; +import com.gh.gamecenter.common.utils.FileUtils; import com.gh.gamecenter.core.AppExecutor; import com.gh.gamecenter.feature.HaloApp; import com.gh.gamecenter.feature.R; import com.gh.gamecenter.feature.entity.PlatformEntity; import com.gh.gamecenter.feature.retrofit.RetrofitManager; -import com.lightgame.download.FileUtils; import org.greenrobot.eventbus.EventBus; diff --git a/module_setting/src/main/java/com/gh/gamecenter/setting/view/SettingsFragment.kt b/module_setting/src/main/java/com/gh/gamecenter/setting/view/SettingsFragment.kt index cb59a6f202..5a4f9b1059 100644 --- a/module_setting/src/main/java/com/gh/gamecenter/setting/view/SettingsFragment.kt +++ b/module_setting/src/main/java/com/gh/gamecenter/setting/view/SettingsFragment.kt @@ -47,7 +47,6 @@ import com.gh.gamecenter.setting.R import com.gh.gamecenter.setting.databinding.FragmentSettingBinding import com.gh.gamecenter.setting.view.security.SecurityActivity import com.gh.gid.GidHelper -import com.lightgame.download.FileUtils import com.lightgame.utils.Utils import io.reactivex.Observable import io.reactivex.ObservableEmitter diff --git a/module_setting_compose/src/main/java/com/gh/gamecenter/setting/compose/activity/ComposeSettingActivity.kt b/module_setting_compose/src/main/java/com/gh/gamecenter/setting/compose/activity/ComposeSettingActivity.kt index 33106e49ab..a134f113b8 100644 --- a/module_setting_compose/src/main/java/com/gh/gamecenter/setting/compose/activity/ComposeSettingActivity.kt +++ b/module_setting_compose/src/main/java/com/gh/gamecenter/setting/compose/activity/ComposeSettingActivity.kt @@ -55,7 +55,6 @@ import com.gh.gamecenter.setting.compose.ui.component.Space import com.gh.gamecenter.setting.compose.ui.theme.* import com.gh.gamecenter.setting.compose.viewmodel.ComposeSettingViewModel import com.gh.gid.GidHelper -import com.lightgame.download.FileUtils import com.lightgame.utils.Utils import io.reactivex.Observable import io.reactivex.ObservableEmitter