Skip to content

Commit

Permalink
Update Log: Add isDebug(boolean) to Control Log
Browse files Browse the repository at this point in the history
  • Loading branch information
ZuiRenA committed Jan 17, 2020
1 parent 39bc166 commit fbf566a
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 46 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/com/shen/desserttask/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package com.shen.desserttask

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.shen.dessert_task.DessertDispatcher

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

}
}
1 change: 1 addition & 0 deletions app/src/main/java/com/shen/desserttask/MyApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class MyApplication : Application() {
.build()
.create(ITask::class.java, TaskImpl())
.addTask(TaskOne())
.addTask(easyTask { Log.d("EasyTask wow", "Start: ${Thread.currentThread().name}") })
.start()

//Method 1
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/shen/desserttask/task/ITask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.shen.desserttask.task
import com.shen.dessert_task.annotation.Task
import com.shen.dessert_task.annotation.TaskCallback
import com.shen.dessert_task.annotation.TaskConfig
import com.shen.dessert_task.annotation.TaskTailRunnable

/**
* created at 2020.2020/1/14.13:44
Expand All @@ -17,9 +18,12 @@ interface ITask {
fun two()

@Task
@TaskConfig(targetCallback = "callback", needCall = true)
@TaskConfig(targetCallback = "callback", needCall = true, tailRunnable = "threeTailRunnable")
fun three()

@TaskCallback("callback")
fun threeCallback()

@TaskTailRunnable("threeTailRunnable")
fun threeTailRunnable()
}
4 changes: 4 additions & 0 deletions app/src/main/java/com/shen/desserttask/task/TaskImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ class TaskImpl : ITask {
override fun threeCallback() {
Log.d("Wow threeCallback", "start: ${Thread.currentThread().name}")
}

override fun threeTailRunnable() {
Log.d("Wow threeTailRunnable", "start: ${Thread.currentThread().name}")
}
}
5 changes: 0 additions & 5 deletions dessert_task/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ android {
compileSdkVersion 29
buildToolsVersion "29.0.2"


defaultConfig {
minSdkVersion 15
targetSdkVersion 29
Expand All @@ -31,10 +30,6 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

apply from: 'https://raw.githubusercontent.com/sky-uk/gradle-maven-plugin/master/gradle-mavenizer.gradle'
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ class DessertDispatchRunnable : Runnable {

if (task.needCall) {
task.callback?.invoke()
if (DebugLog.isDebug) {
DebugLog.logD(task.javaClass.simpleName, "Callback finish")
}
DebugLog.logD(task.javaClass.simpleName, "Callback finish")
task.needCall = false
}

Expand All @@ -58,9 +56,7 @@ class DessertDispatchRunnable : Runnable {
task.isFinish = true

dispatcher?.run {
if (DebugLog.isDebug) {
DebugLog.logE("Satisfy Task", task.toString() + " ${task.methodName}")
}
DebugLog.logE("Satisfy Task", task.toString() + " ${task.methodName}")
task.satisfyChildren()
task.makeTaskDone()
}
Expand Down
24 changes: 24 additions & 0 deletions dessert_task/src/main/java/com/shen/dessert_task/Dispatcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package com.shen.dessert_task
import android.content.Context
import android.os.Looper
import androidx.annotation.UiThread
import com.shen.dessert_task.annotation.Task
import com.shen.dessert_task.annotation_tools.AnnotationConvertTools
import com.shen.dessert_task.annotation_tools.TaskFactory
import com.shen.dessert_task.ext.isMainProcess
import com.shen.dessert_task.sort.getSortResult
import com.shen.dessert_task.state.markTaskDone
import com.shen.dessert_task.utils.DebugLog
import java.lang.StringBuilder
import java.lang.ref.WeakReference
import java.util.concurrent.CountDownLatch
import java.util.concurrent.Future
Expand Down Expand Up @@ -103,6 +105,7 @@ class DessertDispatcher {
analyseCount.getAndIncrement()
printDependedMsg()
allTasks = getSortResult(allTasks, dependOnTasks) as MutableList<DessertTask>
printSortResultMsg()
countDownLatch = CountDownLatch(needWaitCount.get())

sendAndExecuteAsyncTask()
Expand Down Expand Up @@ -313,5 +316,26 @@ class DessertDispatcher {
}
}
}

private fun printSortResultMsg() {
if (!DebugLog.isDebug) {
return
}

val sortResult = StringBuilder()
allTasks.forEachIndexed { index, it ->
if (index == 0) {
sortResult.append("{\n")
}

sortResult.append("ClassName: ${it.javaClass.run { if (simpleName.isEmpty()) "Unknown" else simpleName }}" +
", MethodName: ${it.methodName.run { if (isEmpty()) "Unknown" else this }} \n")

if (index == allTasks.lastIndex) {
sortResult.append("}")
}
}
DebugLog.logD("SortTaskResult", sortResult.toString())
}
}

17 changes: 7 additions & 10 deletions dessert_task/src/main/java/com/shen/dessert_task/Task.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.shen.dessert_task

import android.content.Context
import android.os.Process
import androidx.annotation.IntRange
import com.shen.dessert_task.utils.DebugLog
Expand Down Expand Up @@ -54,15 +55,9 @@ abstract class DessertTask : IDessertTask {

///依赖的Task执行完一个
fun satisfy() {
if (DebugLog.isDebug) {
DebugLog.logD("${if (methodName.isEmpty()) this.javaClass.simpleName else methodName} Pre task satisfy", depends.count)
}

DebugLog.logD("${if (methodName.isEmpty()) this.javaClass.simpleName else methodName} Pre task satisfy", depends.count)
depends.countDown()

if (DebugLog.isDebug) {
DebugLog.logD("${if (methodName.isEmpty()) this.javaClass.simpleName else methodName} After task satisfy", depends.count)
}
DebugLog.logD("${if (methodName.isEmpty()) this.javaClass.simpleName else methodName} After task satisfy", depends.count)
}

/**
Expand Down Expand Up @@ -149,8 +144,10 @@ interface IDessertTask {
val callback: (() -> Unit)?
}

fun easyTask(block: () -> Unit) = object : DessertTask() {
fun easyTask(block: (context: Context?) -> Unit) = object : DessertTask() {
override val methodName: String = "easyTask"

override fun run() {
block()
block(context)
}
}

0 comments on commit fbf566a

Please sign in to comment.