Upgrade to Pro — share decks privately, control downloads, hide ads and more …

server-engineer-android-introduction

 server-engineer-android-introduction

sutetotanuki

October 12, 2018
Tweet

More Decks by sutetotanuki

Other Decks in Programming

Transcript

  1. N#BBT αʔόʔ N#BBTͷొ৔ ೝূ Ӭଓ 1VTI ͦͷଞ αʔόʔ ೝূ Ӭଓ

    1VTI ͦͷଞ ؆୯ͰҰൠతͳϢʔεέʔεͳΒ N#BBTͷΈͰ׬݁ͯ͠͠·͏͜ͱ΋ ొ৔લ ొ৔ޙ
  2. ॻ੶ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?)

    { // ToastΛදࣔ } class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { // ը໘ͷΩϟϓγϣϯΛมߋ } class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { // μΠΞϩάΛදࣔ }
  3. άάͬͯࣸܦ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?)

    { // μΠΞϩάΛදࣔ } class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { // μΠΞϩάΛදࣔ } class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { // μΠΞϩάΛදࣔ }
  4. override fun onCreate(savedInstanceState: Bundle?) { // ॲཧ1.. // ॲཧ2.. //

    ॲཧ3.. // ॲཧ4.. // ॲཧ5.. PO$SFBUFʹू·Δॲཧ ͍͍͠Ε͵ෆ҆
  5. %BUB#JOEJOH <layout> <data> <variable name="viewModel" type="com.example.ui.main.ViewModel/" /> </data> <EditText android:text="@={viewModel.body}"

    /> <Button android:onClick="@{(view)->viewModel.submit()}" /> class ViewModel() { val body = MutableLiveData<String>() fun submit() { // ॲཧ } }
  6. %BUB#JOEJOH <layout> <data> <variable name="viewModel" type="com.example.ui.main.ViewModel/" /> </data> <EditText android:text="@={viewModel.body}"

    /> <Button android:onClick="@{(view)->viewModel.submit()}" /> </layout> class ViewModel() { val body = MutableLiveData<String>() fun submit() { // ॲཧ } }
  7. %BUB#JOEJOH <layout> <data> <variable name="viewModel" type="com.example.ui.main.ViewModel/" /> </data> <EditText android:text="@={viewModel.body}"

    /> <Button android:onClick="@{(view)->viewModel.submit()}" /> class ViewModel() { val body = MutableLiveData<String>() fun submit() { // ॲཧ } }
  8. %BUB#JOEJOH <layout> <data> <variable name="viewModel" type="com.example.ui.main.ViewModel/" /> </data> <EditText android:text="@={viewModel.body}"

    /> <Button android:onClick="@{(view)->viewModel.submit()}" /> class ViewModel() { val body = MutableLiveData<String>() fun submit() { // ॲཧ } }
  9. %BUB#JOEJOH <layout> <data> <variable name="viewModel" type="com.example.ui.main.ViewModel/" /> </data> <EditText android:text="@={viewModel.body}"

    /> <Button android:onClick="@{(view)->viewModel.submit()}" /> class ViewModel() { val body = MutableLiveData<String>() fun submit() { // ॲཧ } }
  10. -JWF%BUB <layout> <data> <variable name="viewModel" type="com.example.ui.main.ViewModel/" /> </data> <EditText android:text="@={viewModel.body}"

    /> <Button android:onClick="@{(view)->viewModel.submit()}" /> class ViewModel() { val body = MutableLiveData<String>() fun submit() { // ॲཧ } }
  11. 3PPN @Dao interface WordDao { @Insert fun insert(word: Word) @Query("DELETE

    FROM word_table") fun deleteAll() @Query("SELECT * FROM word_table ORDER BY word ASC") fun allWords(): LiveData<List<Word>> }
  12. "OESPJEͰͷ࢖༻ྫ fun done(task: Task) = repository.doneTask(task) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ //

    ੒ޭ࣌ͷॲཧ }, { // ࣦഊ࣌ͷॲཧ }) override fun doneTask(task: Task): Completable = Completable.create { try { task.status = Task.Status.DONE db.taskDao().updateTask(task) it.onComplete() } catch (e: Exception) { it.onError(e) } } ॲཧࣗମ͸ผεϨουʹͯ͠ ݁ՌΛϝΠϯεϨουͰड͚औΔ
  13. ,PUMJODPSPVUJOFT w %JTQBUDIFS ࣮ߦ͢ΔεϨου  w +PC DPSPVUJOFΛΩϟϯηϧͰ͖Δ  w

    $PSPVUJOF$POUFYU ओʹ%JTQBUDIFSͱ+PCͷ ૊Έ߹Θͤ  w 4DPQF είʔϓ಺Ͱ࣮ߦ͞ΕͨDPSPVUJOF͸ࢠ DPSPVUJOFʹͳΔ
  14. class WordViewModel(application: Application) : AndroidViewModel(application) { private var parentJob =

    Job() private val coroutineContext: CoroutineContext get() = parentJob + Dispatchers.Main private val scope = CoroutineScope(coroutineContext) override fun onCleared() { super.onCleared() parentJob.cancel() } } viewModel.scope.launch(Dispatchers.IO) { // ඇಉظʹ͍ͨ͠ॲཧ } "OESPJEͰͷ࢖༻ྫ "DUJWJUZͷഁغ࣌ʹίϧʔνϯΛDBODFM͠ͳ͍ͱ ϝϞϦϦʔΫ͢ΔՄೳੑ͕͋Δ