mirror of
https://github.com/imcarlost/Friendlists.git
synced 2026-04-10 02:46:54 -04:00
implement navigation
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
apply from: 'versions.gradle'
|
apply from: '../versions.gradle'
|
||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
apply plugin: 'kotlin-android'
|
apply plugin: 'kotlin-android'
|
||||||
apply plugin: 'kotlin-android-extensions'
|
apply plugin: 'kotlin-android-extensions'
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".view.HomeActivity"
|
android:name=".view.MainActivity"
|
||||||
android:screenOrientation="portrait">
|
android:screenOrientation="portrait">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
package com.hako.friendlists.view
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
|
|
||||||
class HomeActivity : AppCompatActivity() {
|
|
||||||
|
|
||||||
}
|
|
||||||
22
app/src/main/java/com/hako/friendlists/view/MainActivity.kt
Normal file
22
app/src/main/java/com/hako/friendlists/view/MainActivity.kt
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package com.hako.friendlists.view
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.navigation.findNavController
|
||||||
|
import com.hako.friendlists.R
|
||||||
|
|
||||||
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
private val navController by lazy { findNavController(R.id.main_fragment_container) }
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setContentView(R.layout.activity_main)
|
||||||
|
setupNavigation()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupNavigation() {
|
||||||
|
navController.setGraph(R.navigation.main_navigation)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
8
app/src/main/res/layout/activity_main.xml
Normal file
8
app/src/main/res/layout/activity_main.xml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:id="@+id/main_fragment_container"
|
||||||
|
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:defaultNavHost="true" />
|
||||||
9
app/src/main/res/navigation/main_navigation.xml
Normal file
9
app/src/main/res/navigation/main_navigation.xml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:id="@+id/main_navigation"
|
||||||
|
app:startDestination="@id/userlist_navigation">
|
||||||
|
|
||||||
|
<include app:graph="@navigation/userlist_navigation" />
|
||||||
|
|
||||||
|
</navigation>
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
ext.deps = [:]
|
|
||||||
|
|
||||||
def versions = [:]
|
|
||||||
versions.kotlin = "1.3.41"
|
|
||||||
versions.gradle = "3.5.3"
|
|
||||||
|
|
||||||
def deps = [:]
|
|
||||||
|
|
||||||
def project = [:]
|
|
||||||
project.kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin"
|
|
||||||
project.gradle = "com.android.tools.build:gradle:$versions.gradle"
|
|
||||||
deps.project = project
|
|
||||||
|
|
||||||
def build_versions = [:]
|
|
||||||
build_versions.min_sdk = 21
|
|
||||||
build_versions.target_sdk = 29
|
|
||||||
build_versions.build_tools = "29.0.3"
|
|
||||||
ext.build_versions = build_versions
|
|
||||||
|
|
||||||
def kotlin = [:]
|
|
||||||
kotlin.version = "$versions.kotlin"
|
|
||||||
kotlin.std_lib = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlin"
|
|
||||||
deps.kotlin = kotlin
|
|
||||||
|
|
||||||
ext.deps = deps
|
|
||||||
|
|
||||||
def addRepos(RepositoryHandler handler) {
|
|
||||||
handler.google()
|
|
||||||
handler.jcenter()
|
|
||||||
handler.maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
|
|
||||||
}
|
|
||||||
|
|
||||||
ext.addRepos = this.&addRepos
|
|
||||||
@@ -39,6 +39,8 @@ dependencies {
|
|||||||
api deps.androidx.lifecycle_ext
|
api deps.androidx.lifecycle_ext
|
||||||
api deps.androidx.lifecycle_viewmodel
|
api deps.androidx.lifecycle_viewmodel
|
||||||
api deps.androidx.recycler_view
|
api deps.androidx.recycler_view
|
||||||
|
api deps.androidx.navigation_fragment
|
||||||
|
api deps.androidx.navigation_ui
|
||||||
api deps.retrofit.runtime
|
api deps.retrofit.runtime
|
||||||
api deps.retrofit.gson
|
api deps.retrofit.gson
|
||||||
api deps.retrofit.rx
|
api deps.retrofit.rx
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.hako.base.extensions
|
||||||
|
|
||||||
|
import androidx.annotation.IdRes
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.navigation.fragment.NavHostFragment
|
||||||
|
|
||||||
|
fun AppCompatActivity.findNavHostFragment(@IdRes id: Int) =
|
||||||
|
supportFragmentManager.findFragmentById(id) as NavHostFragment
|
||||||
|
|
||||||
|
fun Fragment.findNavHostFragment(@IdRes id: Int) =
|
||||||
|
childFragmentManager.findFragmentById(id) as NavHostFragment
|
||||||
|
|
||||||
|
fun Fragment.findNavController(@IdRes id: Int) =
|
||||||
|
androidx.navigation.Navigation.findNavController(view?.findViewById(id) ?: viewNotFound(id, this))
|
||||||
|
|
||||||
|
private fun viewNotFound(@IdRes id: Int, fragment: Fragment): Nothing = throw IllegalStateException(
|
||||||
|
"View ID $id at '${fragment::class.java.simpleName}' not found."
|
||||||
|
)
|
||||||
@@ -7,6 +7,7 @@ versions.androidx_core = "1.1.0"
|
|||||||
versions.androidx_constraint_layout = "1.1.3"
|
versions.androidx_constraint_layout = "1.1.3"
|
||||||
versions.androidx_lifecycle = "2.2.0"
|
versions.androidx_lifecycle = "2.2.0"
|
||||||
versions.androidx_recycler_view = "1.1.0"
|
versions.androidx_recycler_view = "1.1.0"
|
||||||
|
versions.androidx_navigation = "2.2.0"
|
||||||
versions.okhttp_logging_interceptor = "4.3.1"
|
versions.okhttp_logging_interceptor = "4.3.1"
|
||||||
versions.retrofit = "2.7.1"
|
versions.retrofit = "2.7.1"
|
||||||
versions.timber = "4.7.1"
|
versions.timber = "4.7.1"
|
||||||
@@ -33,6 +34,8 @@ androidx.constraint_layout = "androidx.constraintlayout:constraintlayout:$versio
|
|||||||
androidx.lifecycle_ext = "androidx.lifecycle:lifecycle-extensions:$versions.androidx_lifecycle"
|
androidx.lifecycle_ext = "androidx.lifecycle:lifecycle-extensions:$versions.androidx_lifecycle"
|
||||||
androidx.lifecycle_viewmodel = "androidx.lifecycle:lifecycle-viewmodel-ktx:$versions.androidx_lifecycle"
|
androidx.lifecycle_viewmodel = "androidx.lifecycle:lifecycle-viewmodel-ktx:$versions.androidx_lifecycle"
|
||||||
androidx.recycler_view = "androidx.recyclerview:recyclerview:$versions.androidx_recycler_view"
|
androidx.recycler_view = "androidx.recyclerview:recyclerview:$versions.androidx_recycler_view"
|
||||||
|
androidx.navigation_fragment = "androidx.navigation:navigation-fragment-ktx:$versions.androidx_navigation"
|
||||||
|
androidx.navigation_ui = "androidx.navigation:navigation-ui-ktx:$versions.androidx_navigation"
|
||||||
deps.androidx = androidx
|
deps.androidx = androidx
|
||||||
|
|
||||||
def retrofit = [:]
|
def retrofit = [:]
|
||||||
|
|||||||
@@ -1,4 +1,14 @@
|
|||||||
package com.hako.friendlist.feature
|
package com.hako.friendlist.feature
|
||||||
|
|
||||||
class UserlistFragment {
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import com.hako.friendlist_userlist.R
|
||||||
|
|
||||||
|
class UserlistFragment : Fragment() {
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||||
|
return inflater.inflate(R.layout.fragment_userlist, container, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
15
userlist/src/main/res/layout/fragment_userlist.xml
Normal file
15
userlist/src/main/res/layout/fragment_userlist.xml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView2"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Hello world"
|
||||||
|
tools:layout_editor_absoluteX="174dp"
|
||||||
|
tools:layout_editor_absoluteY="352dp" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
14
userlist/src/main/res/navigation/userlist_navigation.xml
Normal file
14
userlist/src/main/res/navigation/userlist_navigation.xml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/userlist_navigation"
|
||||||
|
app:startDestination="@id/userListFragment">
|
||||||
|
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/userListFragment"
|
||||||
|
android:name="com.hako.friendlist.feature.UserlistFragment"
|
||||||
|
tools:layout="@layout/fragment_userlist"
|
||||||
|
android:label="UserListFragment" />
|
||||||
|
|
||||||
|
</navigation>
|
||||||
Reference in New Issue
Block a user