Skip to content

Commit

Permalink
Merge pull request #26 from Qase/FIX/HIPMC-2750
Browse files Browse the repository at this point in the history
Fix/hipmc 2750
  • Loading branch information
neubami94 committed Feb 24, 2022
2 parents 1096cc8 + 86104fa commit ef747ed
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 66 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ apply plugin: 'kotlin-android'

android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "quanti.com.kotlinlog3"
minSdkVersion 16
targetSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -24,6 +23,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
ndkVersion '21.3.6528147'

}

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@


buildscript {
ext.kotlin_version = '1.3.31'
ext.kotlin_version = '1.4.0'
repositories {
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'

Expand Down
6 changes: 3 additions & 3 deletions kotlinlog/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ group = 'com.qithub.qase'

android {
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
minSdkVersion 16
targetSdkVersion 27
targetSdkVersion 28
versionCode 3
versionName "2.2.6"
versionName "2.2.7"
buildConfigField 'int', 'VERSION_CODE', "$versionCode"
buildConfigField 'String', 'VERSION_NAME', "\"$versionName\""
consumerProguardFile('proguard-rules.pro')
Expand Down Expand Up @@ -58,6 +57,7 @@ android {
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
ndkVersion '21.3.6528147'
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
package quanti.com.kotlinlog.file

import android.app.AlertDialog
import android.app.Dialog
import android.content.DialogInterface
import android.content.Intent
import android.os.Bundle
import android.app.AlertDialog
import android.widget.Toast
import androidx.fragment.app.DialogFragment
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.io.File
import kotlinx.coroutines.*
import quanti.com.kotlinlog.R
import quanti.com.kotlinlog.utils.copyLogsTOSDCard
import quanti.com.kotlinlog.utils.getFormattedFileNameDayNow
import quanti.com.kotlinlog.utils.getUriForFile
import quanti.com.kotlinlog.utils.getZipOfLogs
import quanti.com.kotlinlog.utils.hasFileWritePermission
import java.io.File

/**
* Created by Trnka Vladislav on 20.06.2017.
Expand Down Expand Up @@ -88,32 +83,32 @@ class SendLogDialogFragment : DialogFragment() {
}
}

var zipFile: Deferred<File>? = null
private var zipFile: Deferred<File>? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
zipFile = GlobalScope.async {
val extraFiles = arguments!!.getSerializable(EXTRA_FILES) as ArrayList<File>
getZipOfLogs(activity!!.applicationContext, 4, extraFiles)
zipFile = CoroutineScope(Dispatchers.IO).async {
val extraFiles = requireArguments().getSerializable(EXTRA_FILES) as ArrayList<File>
getZipOfLogs(requireActivity().applicationContext, 4, extraFiles)
}
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val hasFilePermission = activity!!.applicationContext.hasFileWritePermission()
val hasFilePermission = requireActivity().applicationContext.hasFileWritePermission()

return AlertDialog
.Builder(context!!, arguments!!.getInt(DIALOG_THEME))
.Builder(requireContext(), requireArguments().getInt(DIALOG_THEME))
.apply {
setMessage(arguments!!.getString(MESSAGE))
setTitle(arguments!!.getString(TITLE))
setMessage(requireArguments().getString(MESSAGE))
setTitle(requireArguments().getString(TITLE))
setPositiveButton(
arguments!!.getString(EMAIL_BUTTON_TEXT),
requireArguments().getString(EMAIL_BUTTON_TEXT),
this@SendLogDialogFragment::positiveButtonClick
)

if (hasFilePermission) {
setNeutralButton(
arguments!!.getString(FILE_BUTTON_TEXT),
requireArguments().getString(FILE_BUTTON_TEXT),
this@SendLogDialogFragment::neutralButtonClick
)
}
Expand All @@ -125,56 +120,54 @@ class SendLogDialogFragment : DialogFragment() {
* Create zip of all logs and open email client to send
*/
@Suppress("UNUSED_PARAMETER")
private fun positiveButtonClick(dialog: DialogInterface, which: Int) = runBlocking {

val appContext = this@SendLogDialogFragment.context!!.applicationContext

val addresses = arguments!!.getStringArray(SEND_EMAIL_ADDRESSES)
val subject = getString(R.string.logs_email_subject) + " " + getFormattedFileNameDayNow()
val bodyText = getString(R.string.logs_email_text)

//await non block's current thread
val zipFileUri = zipFile?.await()?.getUriForFile(appContext)

val intent = Intent(Intent.ACTION_SEND).apply {
type = "message/rfc822" //email
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
putExtra(Intent.EXTRA_EMAIL, addresses)
putExtra(Intent.EXTRA_SUBJECT, subject)
putExtra(Intent.EXTRA_TEXT, bodyText)
putExtra(Intent.EXTRA_STREAM, zipFileUri)
}
private fun positiveButtonClick(dialog: DialogInterface, which: Int) =
CoroutineScope(Dispatchers.Main).launch {
val appContext = this@SendLogDialogFragment.requireContext().applicationContext

val addresses = requireArguments().getStringArray(SEND_EMAIL_ADDRESSES)
val subject =
getString(R.string.logs_email_subject) + " " + getFormattedFileNameDayNow()
val bodyText = getString(R.string.logs_email_text)

// await non block's current thread
val zipFileUri = zipFile?.await()?.getUriForFile(appContext)

val intent = Intent(Intent.ACTION_SEND).apply {
type = "message/rfc822" // email
type = "message/rfc822" // email
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
putExtra(Intent.EXTRA_EMAIL, addresses)
putExtra(Intent.EXTRA_SUBJECT, subject)
putExtra(Intent.EXTRA_TEXT, bodyText)
putExtra(Intent.EXTRA_STREAM, zipFileUri)
}

try {
startActivity(Intent.createChooser(intent, "Send mail..."))
} catch (ex: android.content.ActivityNotFoundException) {
Toast.makeText(
appContext,
getString(R.string.logs_email_no_client_installed),
Toast.LENGTH_LONG
).show()
try {
startActivity(Intent.createChooser(intent, "Send mail..."))
} catch (ex: android.content.ActivityNotFoundException) {
Toast.makeText(
appContext,
getString(R.string.logs_email_no_client_installed),
Toast.LENGTH_LONG
).show()
}
}

}

/**
* On neutral button click
* Copy ZIP of all logs to sd card
*/
@Suppress("UNUSED_PARAMETER")
private fun neutralButtonClick(dialog: DialogInterface, which: Int) {
private fun neutralButtonClick(dialog: DialogInterface, which: Int) =
CoroutineScope(Dispatchers.Main).launch {
val appContext = this@SendLogDialogFragment.requireContext().applicationContext

val appContext = this@SendLogDialogFragment.context!!.applicationContext
val file = zipFile?.await()?.copyLogsTOSDCard(requireContext())

GlobalScope.launch(Dispatchers.IO) {
val file = zipFile!!.await().copyLogsTOSDCard(requireContext())
launch(Dispatchers.Main) {
Toast.makeText(
appContext,
"File successfully copied" + "\n" + file.absolutePath,
Toast.LENGTH_LONG
).show()
}
Toast.makeText(
appContext,
"File successfully copied" + "\n" + file?.absolutePath,
Toast.LENGTH_LONG
).show()
}
}
}

0 comments on commit ef747ed

Please sign in to comment.