Skip to content

Commit

Permalink
优化协程
Browse files Browse the repository at this point in the history
  • Loading branch information
lulululbj committed Jan 3, 2019
1 parent c06f3e1 commit dd6e429
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

<activity android:name=".ui.appManager.AppListActivity"/>
<activity android:name=".ui.appManager.AppDetailActivity"/>
<activity android:name=".ui.editor.TextEditorActivity"/>
</application>

</manifest>
11 changes: 8 additions & 3 deletions app/src/main/java/luyao/box/adapter/AppAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import android.widget.ImageButton
import android.widget.PopupMenu
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch
import luyao.box.APK_PATH
Expand Down Expand Up @@ -46,7 +46,12 @@ class AppAdapter(layoutResId: Int = R.layout.item_app) : BaseQuickAdapter<AppBea
R.id.menu_open_app -> AppUtils.openApp(context, appBean.packageName)
R.id.menu_uninstall_app -> AppUtils.uninstallApp(context, appBean.packageName) // TODO 卸载之后刷新列表
R.id.menu_app_properties -> AppUtils.openAppProperties(context, appBean.packageName)
R.id.menu_app_detail -> context.startActivity(Intent(context, AppDetailActivity::class.java).putExtra("packageName",appBean.packageName))
R.id.menu_app_detail -> context.startActivity(
Intent(
context,
AppDetailActivity::class.java
).putExtra("packageName", appBean.packageName)
)
R.id.menu_save_apk -> saveApk(helper, context, appBean)
R.id.menu_share_apk -> shareApk()
R.id.menu_open_in_store -> AppUtils.openInStore(context, appBean.packageName)
Expand All @@ -57,7 +62,7 @@ class AppAdapter(layoutResId: Int = R.layout.item_app) : BaseQuickAdapter<AppBea
}

private fun saveApk(helper: BaseViewHolder, context: Context, appBean: AppBean) {
GlobalScope.launch(Dispatchers.Main) {
CoroutineScope(Dispatchers.Main).launch {
val progressView = helper.getView<SectorProgressView>(R.id.appProgressView)
val apkFile = File(appBean.sourceDir)
val destFile = File("$APK_PATH${appBean.appName}${File.separator}${apkFile.name}")
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/java/luyao/box/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import com.google.android.material.navigation.NavigationView
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.app_bar_main.*
import kotlinx.android.synthetic.main.title_layout.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import luyao.box.APK_PATH
import luyao.box.BASE_PATH
Expand Down Expand Up @@ -111,8 +111,6 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
private fun checkPermissions() {
if (!EasyPermissions.hasPermissions(this, *perms)) {
EasyPermissions.requestPermissions(this, "权限申请", 1001, *perms)
} else {
finish()
}
}

Expand All @@ -126,7 +124,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
}

private fun createBaseFile() {
GlobalScope.launch(Dispatchers.IO) {
CoroutineScope(Dispatchers.IO).launch {
val baseFolder = File(BASE_PATH)
if (!baseFolder.exists()) baseFolder.mkdirs()

Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/luyao/box/ui/editor/TextEditorActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package luyao.box.ui.editor

import luyao.box.R
import luyao.box.common.base.BaseActivity

/**
* Created by luyao
* on 2019/1/3 16:18
*/
class TextEditorActivity : BaseActivity() {


override fun getLayoutResId()= R.layout.activity_text_editor

override fun initView() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

override fun initData() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
26 changes: 26 additions & 0 deletions app/src/main/res/layout/activity_text_editor.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<include layout="@layout/title_layout"/>

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

<EditText
android:id="@+id/textEdit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:fontFamily="sans-serif-light"
android:textSize="14sp"
android:ems="10"
android:gravity="left|top"
android:inputType="textCapSentences|textMultiLine"/>
</ScrollView>

</LinearLayout>

0 comments on commit dd6e429

Please sign in to comment.