parent
4be80d399c
commit
9a8182b00e
@ -1,11 +1,59 @@ |
||||
package net.pokeranalytics.android.ui.fragment |
||||
|
||||
import android.os.Bundle |
||||
import android.view.LayoutInflater |
||||
import android.view.View |
||||
import android.view.ViewGroup |
||||
import kotlinx.coroutines.Dispatchers |
||||
import kotlinx.coroutines.GlobalScope |
||||
import kotlinx.coroutines.async |
||||
import kotlinx.coroutines.launch |
||||
import net.pokeranalytics.android.R |
||||
import net.pokeranalytics.android.ui.fragment.components.RealmFragment |
||||
import net.pokeranalytics.android.util.csv.CSVImporter |
||||
import timber.log.Timber |
||||
import java.util.* |
||||
import kotlin.coroutines.CoroutineContext |
||||
|
||||
class ImportFragment : RealmFragment() { |
||||
|
||||
val coroutineContext: CoroutineContext |
||||
get() = Dispatchers.Main |
||||
|
||||
private lateinit var filePath: String |
||||
|
||||
fun setData(path: String) { |
||||
this.filePath = path |
||||
} |
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
||||
super.onCreateView(inflater, container, savedInstanceState) |
||||
return inflater.inflate(R.layout.fragment_import, container, false) |
||||
} |
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
||||
super.onViewCreated(view, savedInstanceState) |
||||
this.startImport() |
||||
} |
||||
|
||||
fun startImport() { |
||||
|
||||
GlobalScope.launch(coroutineContext) { |
||||
|
||||
val test = GlobalScope.async { |
||||
val s = Date() |
||||
Timber.d(">>> start...") |
||||
|
||||
val csv = CSVImporter(filePath) |
||||
csv.start() |
||||
|
||||
val e = Date() |
||||
val duration = (e.time - s.time) / 1000.0 |
||||
Timber.d(">>> Import ended in $duration seconds") |
||||
|
||||
} |
||||
test.await() |
||||
} |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue