diff --git a/app/src/main/java/org/tasks/voice/VoiceCommandActivity.java b/app/src/main/java/org/tasks/voice/VoiceCommandActivity.java deleted file mode 100644 index 6c8d1cc99..000000000 --- a/app/src/main/java/org/tasks/voice/VoiceCommandActivity.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.tasks.voice; - -import static org.tasks.Strings.isNullOrEmpty; - -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.widget.Toast; -import com.todoroo.astrid.service.TaskCreator; -import dagger.hilt.android.AndroidEntryPoint; -import dagger.hilt.android.qualifiers.ApplicationContext; -import javax.inject.Inject; -import org.tasks.R; -import org.tasks.injection.InjectingAppCompatActivity; - -@AndroidEntryPoint -public class VoiceCommandActivity extends InjectingAppCompatActivity { - - @Inject TaskCreator taskCreator; - @Inject @ApplicationContext Context context; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - Intent intent = getIntent(); - - if ("com.google.android.gm.action.AUTO_SEND".equals(intent.getAction())) { - final String text = intent.getStringExtra(Intent.EXTRA_TEXT); - if (!isNullOrEmpty(text)) { - taskCreator.basicQuickAddTask(text); - Toast.makeText(context, getString(R.string.voice_command_added_task), Toast.LENGTH_LONG) - .show(); - } - finish(); - } - } -} diff --git a/app/src/main/java/org/tasks/voice/VoiceCommandActivity.kt b/app/src/main/java/org/tasks/voice/VoiceCommandActivity.kt new file mode 100644 index 000000000..c0737430e --- /dev/null +++ b/app/src/main/java/org/tasks/voice/VoiceCommandActivity.kt @@ -0,0 +1,43 @@ +package org.tasks.voice + +import android.content.Context +import android.content.Intent +import android.os.Bundle +import androidx.lifecycle.lifecycleScope +import com.todoroo.astrid.service.TaskCreator +import dagger.hilt.android.AndroidEntryPoint +import dagger.hilt.android.qualifiers.ApplicationContext +import kotlinx.coroutines.launch +import org.tasks.R +import org.tasks.injection.InjectingAppCompatActivity +import org.tasks.ui.Toaster +import javax.inject.Inject + +@AndroidEntryPoint +class VoiceCommandActivity : InjectingAppCompatActivity() { + @Inject lateinit var taskCreator: TaskCreator + @Inject @ApplicationContext lateinit var context: Context + @Inject lateinit var toaster: Toaster + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + if (intent.action == AUTO_SEND) { + lifecycleScope.launch { + intent.getStringExtra(Intent.EXTRA_TEXT) + ?.takeUnless { it.isBlank() } + ?.let { + taskCreator.basicQuickAddTask(it) + toaster.longToast(R.string.voice_command_added_task) + } + finish() + } + } else { + finish() + } + } + + companion object { + private const val AUTO_SEND = "com.google.android.gm.action.AUTO_SEND" + } +} \ No newline at end of file