|
|
|
|
@ -9,6 +9,8 @@ import io.realm.Realm |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
|
|
|
|
import net.pokeranalytics.android.ui.activity.components.RequestCode |
|
|
|
|
import net.pokeranalytics.android.ui.activity.components.ResultCode |
|
|
|
|
import net.pokeranalytics.android.ui.extensions.showAlertDialog |
|
|
|
|
import net.pokeranalytics.android.ui.fragment.ImportFragment |
|
|
|
|
import timber.log.Timber |
|
|
|
|
|
|
|
|
|
@ -39,11 +41,15 @@ class ImportActivity : PokerAnalyticsActivity() { |
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) { |
|
|
|
|
super.onCreate(savedInstanceState) |
|
|
|
|
|
|
|
|
|
this.fileURI = intent.getParcelableExtra(ImportActivity.IntentKey.URI.keyName) |
|
|
|
|
Timber.d("//////// data = ${intent?.data}") |
|
|
|
|
|
|
|
|
|
setContentView(R.layout.activity_import) |
|
|
|
|
initUI() |
|
|
|
|
intent?.data?.let { |
|
|
|
|
this.fileURI = it |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setContentView(R.layout.activity_import) |
|
|
|
|
// initUI() |
|
|
|
|
requestImportConfirmation() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onStop() { |
|
|
|
|
@ -51,7 +57,7 @@ class ImportActivity : PokerAnalyticsActivity() { |
|
|
|
|
|
|
|
|
|
// Updates the main thread instance with newly inserted data |
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
realm.refresh() |
|
|
|
|
// realm.refresh() |
|
|
|
|
realm.close() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -71,16 +77,57 @@ class ImportActivity : PokerAnalyticsActivity() { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// private fun requestPermission() { |
|
|
|
|
// if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) { |
|
|
|
|
// ActivityCompat.requestPermissions( |
|
|
|
|
// this, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), PERMISSION_REQUEST_ACCESS_FINE_LOCATION |
|
|
|
|
// ) |
|
|
|
|
// override fun onNewIntent(intent: Intent?) { |
|
|
|
|
// super.onNewIntent(intent) |
|
|
|
|
// |
|
|
|
|
// Timber.d("++++++ data = ${intent?.data}") |
|
|
|
|
// |
|
|
|
|
// setIntent(intent) |
|
|
|
|
// intent?.let { |
|
|
|
|
// |
|
|
|
|
// when (intent.action) { |
|
|
|
|
// "android.intent.action.VIEW" -> { // import |
|
|
|
|
// val data = it.data |
|
|
|
|
// if (data != null) { |
|
|
|
|
// this.requestImportConfirmation(data) |
|
|
|
|
// } else { |
|
|
|
|
// throw PAIllegalStateException("URI null on import") |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
// else -> { |
|
|
|
|
// Timber.w("Intent ${intent.action} unmanaged") |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) { |
|
|
|
|
// super.onRequestPermissionsResult(requestCode, permissions, grantResults) |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
|
|
|
|
super.onActivityResult(requestCode, resultCode, data) |
|
|
|
|
|
|
|
|
|
when (requestCode) { |
|
|
|
|
RequestCode.IMPORT.value -> { |
|
|
|
|
if (resultCode == ResultCode.IMPORT_UNRECOGNIZED_FORMAT.value) { |
|
|
|
|
showAlertDialog(context = this, message = R.string.unknown_import_format_popup_message, positiveAction = { |
|
|
|
|
finish() |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Import |
|
|
|
|
|
|
|
|
|
private fun requestImportConfirmation() { |
|
|
|
|
|
|
|
|
|
showAlertDialog(context = this, title = R.string.import_confirmation, showCancelButton = true, positiveAction = { |
|
|
|
|
initUI() |
|
|
|
|
// newInstanceForResult(this, uri) |
|
|
|
|
}, negativeAction = { |
|
|
|
|
finish() |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |