-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
920f95b
commit 6da3afc
Showing
25 changed files
with
235 additions
and
368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ils/src/main/java/constacne/DownLoadBy.kt → ...tils/src/main/java/constant/DownLoadBy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package constacne | ||
package constant | ||
|
||
/** | ||
* desc: 下载方式 | ||
|
2 changes: 1 addition & 1 deletion
2
...pputils/src/main/java/constacne/UiType.kt → ...apputils/src/main/java/constant/UiType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package constacne | ||
package constant | ||
|
||
/** | ||
* desc: UI 类型 | ||
|
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package extension | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.net.ConnectivityManager | ||
import android.net.Uri | ||
import android.os.Build | ||
import android.support.v4.content.FileProvider | ||
import java.io.File | ||
|
||
/** | ||
* desc: context 相关扩展 | ||
* author: teprinciple on 2020/3/27. | ||
*/ | ||
|
||
|
||
/** | ||
* appName | ||
*/ | ||
val Context.appName | ||
get() = packageManager.getPackageInfo(packageName, 0)?.applicationInfo?.loadLabel(packageManager).toString() | ||
|
||
/** | ||
* 检测wifi是否连接 | ||
*/ | ||
fun Context.isWifiConnected(): Boolean { | ||
val cm = this.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager | ||
cm ?: return false | ||
val networkInfo = cm.activeNetworkInfo | ||
return networkInfo != null && networkInfo.type == ConnectivityManager.TYPE_WIFI | ||
} | ||
|
||
|
||
/** | ||
* 跳转安装 | ||
*/ | ||
fun Context.installApk(apkPath: String?) { | ||
|
||
if (apkPath.isNullOrEmpty())return | ||
|
||
val intent = Intent(Intent.ACTION_VIEW) | ||
val apkFile = File(apkPath) | ||
|
||
// android 7.0 fileprovider 适配 | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | ||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) | ||
val contentUri = FileProvider.getUriForFile(this, this.packageName + ".fileprovider", apkFile) | ||
intent.setDataAndType(contentUri, "application/vnd.android.package-archive") | ||
} else { | ||
intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive") | ||
} | ||
|
||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
this.startActivity(intent) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package extension | ||
|
||
import android.app.ActivityManager | ||
import android.content.Context | ||
import android.os.Build | ||
import android.support.v4.content.ContextCompat | ||
import android.util.Log | ||
import android.view.View | ||
import update.UpdateAppUtils | ||
import util.GlobalContextProvider | ||
import kotlin.system.exitProcess | ||
|
||
/** | ||
* desc: 扩展 | ||
* author: teprinc | ||
* iple on 2020/3/27. | ||
*/ | ||
|
||
/** | ||
* 全局context | ||
*/ | ||
val globalContext by lazy { GlobalContextProvider.mContext } | ||
|
||
|
||
/** | ||
* 打印日志 | ||
*/ | ||
fun log(content: String?) = UpdateAppUtils.updateInfo.config.isDebug.yes { | ||
Log.e("[UpdateAppUtils]", content ?: "") | ||
} | ||
|
||
/** | ||
* 获取color | ||
*/ | ||
fun color(color: Int) = if (globalContext == null) 0 else ContextCompat.getColor(globalContext!!, color) | ||
|
||
/** | ||
* 获取 String | ||
*/ | ||
fun string(string: Int) = globalContext?.getString(string) ?: "" | ||
|
||
/** | ||
* view 显示隐藏 | ||
*/ | ||
fun View.visibleOrGone(show: Boolean) { | ||
if (show) { | ||
this.visibility = View.VISIBLE | ||
} else { | ||
this.visibility = View.GONE | ||
} | ||
} | ||
|
||
/** | ||
* 退出app | ||
*/ | ||
fun exitApp() { | ||
val manager = globalContext!!.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
manager.appTasks.forEach { it.finishAndRemoveTask() } | ||
} else { | ||
exitProcess(0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package extension | ||
|
||
import java.io.File | ||
|
||
/** | ||
* desc: string 相关扩展 | ||
* author: teprinciple on 2020/3/27. | ||
*/ | ||
|
||
/** | ||
* 根据文件路径删除文件 | ||
*/ | ||
fun String?.deleteFile() { | ||
kotlin.runCatching { | ||
val file = File(this ?: "") | ||
(file.isFile).yes { | ||
file.delete() | ||
log("删除成功") | ||
} | ||
}.onFailure { | ||
log(it.message) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.