Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
Implement the sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
k-kagurazaka committed Nov 2, 2017
1 parent 647b699 commit 2008b68
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 4 deletions.
2 changes: 2 additions & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ dependencies {
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'

implementation project(':library')

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
Expand Down
1 change: 1 addition & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package="com.kkagurazaka.taiyaki.sample">

<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
13 changes: 13 additions & 0 deletions sample/src/main/java/com/kkagurazaka/taiyaki/sample/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.kkagurazaka.taiyaki.sample

import android.app.Application
import com.kkagurazaka.taiyaki.Taiyaki

class App : Application() {

override fun onCreate() {
super.onCreate()

registerActivityLifecycleCallbacks(Taiyaki.LifeCycleCallbacks)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
package com.kkagurazaka.taiyaki.sample

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.Toast
import com.kkagurazaka.taiyaki.HasTaiyaki
import com.kkagurazaka.taiyaki.Taiyaki
import kotlinx.android.synthetic.main.activity_main.*
import kotlin.concurrent.thread

class MainActivity : AppCompatActivity(), HasTaiyaki<MainDialogRequest> {

class MainActivity : AppCompatActivity() {
override val taiyaki = Taiyaki(this)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

button.setOnClickListener {
Toast.makeText(this, "After 3 secs, dialog will show.", Toast.LENGTH_SHORT).show()

thread {
Thread.sleep(3000)

// showDialog(DialogWithParamRequest("FooBar")) // <- IllegalStateException!
taiyaki.request(DialogWithParamRequest("FooBar"))
}
}
}

override fun onDialogRequest(request: MainDialogRequest) {
showDialog(request)
}

private fun showDialog(request: MainDialogRequest) {
when (request) {
is DialogWithParamRequest -> {
TextDialogFragment.newInstance("Param: ${request.param}")
}
is DialogWithoutParamRequest -> {
TextDialogFragment.newInstance("No Param")
}
}.show(supportFragmentManager, null)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.kkagurazaka.taiyaki.sample

import com.kkagurazaka.taiyaki.DialogRequest

sealed class MainDialogRequest : DialogRequest

data class DialogWithParamRequest(val param: String) : MainDialogRequest()

object DialogWithoutParamRequest : MainDialogRequest()
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.kkagurazaka.taiyaki.sample

import android.app.Dialog
import android.os.Bundle
import android.support.v4.app.DialogFragment
import android.support.v7.app.AlertDialog

class TextDialogFragment : DialogFragment() {

private val message
get() = arguments?.getString(KEY_MESSAGE, "")

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog =
AlertDialog.Builder(activity!!)
.setMessage(message)
.create()

companion object Factory {

private const val KEY_MESSAGE = "key.message"

fun newInstance(message: String): TextDialogFragment =
TextDialogFragment().apply {
arguments = Bundle().apply {
putString(KEY_MESSAGE, message)
}
}
}
}
5 changes: 3 additions & 2 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
android:layout_height="match_parent"
tools:context="com.kkagurazaka.taiyaki.sample.MainActivity">

<TextView
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:text="Click me!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
Expand Down

0 comments on commit 2008b68

Please sign in to comment.