mirror of https://github.com/tasks/tasks
Convert VoiceCommandActivity to Kotlin
parent
c62796acec
commit
6670403b7a
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue