-
Notifications
You must be signed in to change notification settings - Fork 9
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
shuza
committed
Aug 9, 2018
1 parent
e423267
commit 7b17ade
Showing
10 changed files
with
82 additions
and
43 deletions.
There are no files selected for viewing
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
16 changes: 0 additions & 16 deletions
16
app/src/main/java/ninja/shuza/sharedviewmodel/Communicator.kt
This file was deleted.
Oops, something went wrong.
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
27 changes: 12 additions & 15 deletions
27
app/src/main/java/ninja/shuza/sharedviewmodel/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,32 +1,29 @@ | ||
package ninja.shuza.sharedviewmodel | ||
|
||
import android.arch.lifecycle.Observer | ||
import android.arch.lifecycle.ViewModelProviders | ||
import android.support.v7.app.AppCompatActivity | ||
import android.os.Bundle | ||
import kotlinx.android.synthetic.main.activity_main.* | ||
import kotlin.properties.Delegates | ||
|
||
class MainActivity : AppCompatActivity(), Communicator { | ||
|
||
private var inputFrgament: InputFragment by Delegates.notNull() | ||
private var outputFragment: OutputFragment by Delegates.notNull() | ||
class MainActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
|
||
inputFrgament = InputFragment() | ||
inputFrgament.activityListener = this | ||
outputFragment = OutputFragment() | ||
|
||
supportFragmentManager.beginTransaction().add(R.id.layout_top, InputFragment()).commit() | ||
supportFragmentManager.beginTransaction().add(R.id.layout_bottom, OutputFragment()).commit() | ||
|
||
supportFragmentManager.beginTransaction().add(R.id.layout_top, inputFrgament).commit() | ||
supportFragmentManager.beginTransaction().add(R.id.layout_bottom, outputFragment).commit() | ||
} | ||
|
||
override fun passData(number: Int) { | ||
val message = resources.getString(R.string.show_input) | ||
tv_show_input.text = "$message $number" | ||
|
||
outputFragment.passDataToAnotherFragment(number) | ||
val sharedViewModel = ViewModelProviders.of(this).get(SharedViewModel::class.java) | ||
|
||
sharedViewModel.inputNumber.observe(this, Observer { | ||
it?.let { | ||
tv_show_input.text = "$message $it" | ||
} | ||
}) | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
app/src/main/java/ninja/shuza/sharedviewmodel/SharedViewModel.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,19 @@ | ||
package ninja.shuza.sharedviewmodel | ||
|
||
import android.arch.lifecycle.MutableLiveData | ||
import android.arch.lifecycle.ViewModel | ||
|
||
/** | ||
* | ||
* := created by: Shuza | ||
* := create date: 09-Aug-18 | ||
* := (C) CopyRight Shuza | ||
* := www.shuza.ninja | ||
* := shuza.sa@gmail.com | ||
* := Fun : Coffee : Code | ||
* | ||
**/ | ||
|
||
class SharedViewModel:ViewModel(){ | ||
val inputNumber = MutableLiveData<Int>() | ||
} |
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