This repository has been archived by the owner on Dec 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
647b699
commit 2008b68
Showing
7 changed files
with
92 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
sample/src/main/java/com/kkagurazaka/taiyaki/sample/App.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
37 changes: 35 additions & 2 deletions
37
sample/src/main/java/com/kkagurazaka/taiyaki/sample/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
sample/src/main/java/com/kkagurazaka/taiyaki/sample/MainDialogRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
29 changes: 29 additions & 0 deletions
29
sample/src/main/java/com/kkagurazaka/taiyaki/sample/TextDialogFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters