-
Notifications
You must be signed in to change notification settings - Fork 48
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
Showing
15 changed files
with
324 additions
and
9 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
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
38 changes: 38 additions & 0 deletions
38
app/src/main/java/com/hi/dhl/demo/binding/navigation/FragmentNav1.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,38 @@ | ||
package com.hi.dhl.demo.binding.navigation | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.navigation.Navigation | ||
import com.hi.dhl.binding.viewbind | ||
import com.hi.dhl.demo.binding.R | ||
import com.hi.dhl.demo.binding.databinding.FragmentNav1Binding | ||
|
||
/** | ||
* <pre> | ||
* author: dhl | ||
* date : 2020/12/21 | ||
* desc : | ||
* </pre> | ||
*/ | ||
class FragmentNav1 : Fragment() { | ||
|
||
val binding: FragmentNav1Binding by viewbind() | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
return binding.root | ||
} | ||
|
||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
binding.btnJump.setOnClickListener { | ||
Navigation.findNavController(it).navigate(R.id.action_fragmentNav1_to_fragmentNav2) | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
app/src/main/java/com/hi/dhl/demo/binding/navigation/FragmentNav2.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,47 @@ | ||
package com.hi.dhl.demo.binding.navigation | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.navigation.Navigation | ||
import com.hi.dhl.binding.databind | ||
import com.hi.dhl.demo.binding.MainViewModel | ||
import com.hi.dhl.demo.binding.R | ||
import com.hi.dhl.demo.binding.databinding.FragmentNav2Binding | ||
import org.koin.androidx.viewmodel.ext.android.viewModel | ||
|
||
/** | ||
* <pre> | ||
* author: dhl | ||
* date : 2020/12/21 | ||
* desc : | ||
* </pre> | ||
*/ | ||
class FragmentNav2 : Fragment() { | ||
|
||
val binding: FragmentNav2Binding by databind() | ||
val viewModel: MainViewModel by viewModel() | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
|
||
return binding.apply { | ||
lifecycleOwner = this@FragmentNav2 | ||
mainViewModel = viewModel | ||
}.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
viewModel.generateTimber() | ||
binding.btnJump.setOnClickListener { | ||
Navigation.findNavController(it).navigate(R.id.action_fragmentNav2_to_fragmentNav3) | ||
} | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
app/src/main/java/com/hi/dhl/demo/binding/navigation/FragmentNav3.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,38 @@ | ||
package com.hi.dhl.demo.binding.navigation | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.navigation.Navigation | ||
import com.hi.dhl.binding.viewbind | ||
import com.hi.dhl.demo.binding.R | ||
import com.hi.dhl.demo.binding.databinding.FragmentNav3Binding | ||
|
||
/** | ||
* <pre> | ||
* author: dhl | ||
* date : 2020/12/21 | ||
* desc : | ||
* </pre> | ||
*/ | ||
class FragmentNav3 : Fragment() { | ||
|
||
val binding: FragmentNav3Binding by viewbind() | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
binding.btnJump.setOnClickListener { | ||
Navigation.findNavController(it).navigate(R.id.action_fragmentNav3_to_fragmentNav1) | ||
} | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/com/hi/dhl/demo/binding/navigation/NavigationActivity.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,27 @@ | ||
package com.hi.dhl.demo.binding.navigation | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.hi.dhl.demo.binding.R | ||
|
||
/** | ||
* <pre> | ||
* author: dhl | ||
* date : 2020/12/21 | ||
* desc : | ||
* </pre> | ||
*/ | ||
class NavigationActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_navigation) | ||
} | ||
|
||
companion object { | ||
fun startActivity(activity: Activity) { | ||
activity.startActivity(Intent(activity, NavigationActivity::class.java)) | ||
} | ||
} | ||
} |
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
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,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:gravity="center" | ||
android:orientation="vertical"> | ||
|
||
<fragment | ||
android:id="@+id/navFragment" | ||
android:name="androidx.navigation.fragment.NavHostFragment" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
app:defaultNavHost="true" | ||
app:navGraph="@navigation/nav_graph" /> | ||
|
||
</LinearLayout> |
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,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:gravity="center" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="这是 FragmentNav1 通过 ViewBinding 绑定" /> | ||
|
||
<androidx.appcompat.widget.AppCompatButton | ||
android:id="@+id/btnJump" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="@dimen/margin_20dp" | ||
android:text="跳转 FragmentNav2" /> | ||
|
||
</LinearLayout> |
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,40 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<data> | ||
|
||
<variable | ||
name="mainViewModel" | ||
type="com.hi.dhl.demo.binding.MainViewModel" /> | ||
</data> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:gravity="center" | ||
android:orientation="vertical"> | ||
|
||
<androidx.appcompat.widget.AppCompatTextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="这是 FragmentNav2 通过 DataBinding 绑定" /> | ||
|
||
<androidx.appcompat.widget.AppCompatTextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_horizontal" | ||
android:layout_marginTop="@dimen/margin_20dp" | ||
android:layout_marginBottom="@dimen/margin_10dp" | ||
android:gravity="center_horizontal" | ||
android:text="@={mainViewModel.inputnNumber}" | ||
android:textColor="@color/black" /> | ||
|
||
<androidx.appcompat.widget.AppCompatButton | ||
android:id="@+id/btnJump" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="@dimen/margin_20dp" | ||
android:text="跳转 FragmentNav3" /> | ||
</LinearLayout> | ||
|
||
</layout> |
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,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:gravity="center" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="这是 FragmentNav3 通过 ViewBinding 绑定" /> | ||
|
||
<androidx.appcompat.widget.AppCompatButton | ||
android:id="@+id/btnJump" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="@dimen/margin_20dp" | ||
android:text="跳转 FragmentNav1" /> | ||
|
||
</LinearLayout> |
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
Oops, something went wrong.