Skip to content

Commit

Permalink
Started refactor to new nav
Browse files Browse the repository at this point in the history
  • Loading branch information
SarthakSingh31 committed Nov 19, 2019
1 parent 9ff1edd commit cc3bc40
Show file tree
Hide file tree
Showing 42 changed files with 784 additions and 29 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.1.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".NavDrawerMain"
android:label="@string/title_activity_nav_drawer_main"
android:theme="@style/AppTheme.NoActionBar"></activity>
<activity
android:name=".LoginActivity"
android:label="@string/app_name">
Expand All @@ -22,8 +26,7 @@
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name">
</activity>
android:label="@string/app_name"></activity>
</application>

</manifest>
2 changes: 1 addition & 1 deletion app/src/main/java/com/example/myuw/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class LoginActivity: AppCompatActivity() {
}

fun startMainActivity() {
val intent = Intent(this, MainActivity::class.java)
val intent = Intent(this, NavDrawerMain::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NO_ANIMATION
startActivity(intent)
this.finish()
Expand Down
57 changes: 57 additions & 0 deletions app/src/main/java/com/example/myuw/NavDrawerMain.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.example.myuw

import android.os.Bundle
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.android.material.snackbar.Snackbar
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import androidx.drawerlayout.widget.DrawerLayout
import com.google.android.material.navigation.NavigationView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import android.view.Menu

class NavDrawerMain : AppCompatActivity() {

private lateinit var appBarConfiguration: AppBarConfiguration

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_nav_drawer_main)
val toolbar: Toolbar = findViewById(R.id.toolbar)
setSupportActionBar(toolbar)

/* val fab: FloatingActionButton = findViewById(R.id.fab)
fab.setOnClickListener { view ->
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
} */
val drawerLayout: DrawerLayout = findViewById(R.id.drawer_layout)
val navView: NavigationView = findViewById(R.id.nav_view)
val navController = findNavController(R.id.nav_host_fragment)
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
appBarConfiguration = AppBarConfiguration(
setOf(
R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow,
R.id.nav_tools, R.id.nav_share, R.id.nav_send
), drawerLayout
)
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.nav_drawer_main, menu)
return true
}

override fun onSupportNavigateUp(): Boolean {
val navController = findNavController(R.id.nav_host_fragment)
return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
}
}
31 changes: 31 additions & 0 deletions app/src/main/java/com/example/myuw/ui/gallery/GalleryFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.myuw.ui.gallery

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import com.example.myuw.R

class GalleryFragment : Fragment() {

private lateinit var galleryViewModel: GalleryViewModel

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
galleryViewModel =
ViewModelProviders.of(this).get(GalleryViewModel::class.java)
val root = inflater.inflate(R.layout.fragment_gallery, container, false)
val textView: TextView = root.findViewById(R.id.text_gallery)
galleryViewModel.text.observe(this, Observer {
textView.text = it
})
return root
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/example/myuw/ui/gallery/GalleryViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.myuw.ui.gallery

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class GalleryViewModel : ViewModel() {

private val _text = MutableLiveData<String>().apply {
value = "This is gallery Fragment"
}
val text: LiveData<String> = _text
}
31 changes: 31 additions & 0 deletions app/src/main/java/com/example/myuw/ui/home/HomeFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.myuw.ui.home

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import com.example.myuw.R

class HomeFragment : Fragment() {

private lateinit var homeViewModel: HomeViewModel

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
homeViewModel =
ViewModelProviders.of(this).get(HomeViewModel::class.java)
val root = inflater.inflate(R.layout.fragment_home, container, false)
val textView: TextView = root.findViewById(R.id.text_home)
homeViewModel.text.observe(this, Observer {
textView.text = it
})
return root
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/example/myuw/ui/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.myuw.ui.home

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class HomeViewModel : ViewModel() {

private val _text = MutableLiveData<String>().apply {
value = "This is home Fragment"
}
val text: LiveData<String> = _text
}
31 changes: 31 additions & 0 deletions app/src/main/java/com/example/myuw/ui/send/SendFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.myuw.ui.send

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import com.example.myuw.R

class SendFragment : Fragment() {

private lateinit var sendViewModel: SendViewModel

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
sendViewModel =
ViewModelProviders.of(this).get(SendViewModel::class.java)
val root = inflater.inflate(R.layout.fragment_send, container, false)
val textView: TextView = root.findViewById(R.id.text_send)
sendViewModel.text.observe(this, Observer {
textView.text = it
})
return root
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/example/myuw/ui/send/SendViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.myuw.ui.send

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class SendViewModel : ViewModel() {

private val _text = MutableLiveData<String>().apply {
value = "This is send Fragment"
}
val text: LiveData<String> = _text
}
31 changes: 31 additions & 0 deletions app/src/main/java/com/example/myuw/ui/share/ShareFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.myuw.ui.share

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import com.example.myuw.R

class ShareFragment : Fragment() {

private lateinit var shareViewModel: ShareViewModel

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
shareViewModel =
ViewModelProviders.of(this).get(ShareViewModel::class.java)
val root = inflater.inflate(R.layout.fragment_share, container, false)
val textView: TextView = root.findViewById(R.id.text_share)
shareViewModel.text.observe(this, Observer {
textView.text = it
})
return root
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/example/myuw/ui/share/ShareViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.myuw.ui.share

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class ShareViewModel : ViewModel() {

private val _text = MutableLiveData<String>().apply {
value = "This is share Fragment"
}
val text: LiveData<String> = _text
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.myuw.ui.slideshow

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import com.example.myuw.R

class SlideshowFragment : Fragment() {

private lateinit var slideshowViewModel: SlideshowViewModel

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
slideshowViewModel =
ViewModelProviders.of(this).get(SlideshowViewModel::class.java)
val root = inflater.inflate(R.layout.fragment_slideshow, container, false)
val textView: TextView = root.findViewById(R.id.text_slideshow)
slideshowViewModel.text.observe(this, Observer {
textView.text = it
})
return root
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.myuw.ui.slideshow

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class SlideshowViewModel : ViewModel() {

private val _text = MutableLiveData<String>().apply {
value = "This is slideshow Fragment"
}
val text: LiveData<String> = _text
}
31 changes: 31 additions & 0 deletions app/src/main/java/com/example/myuw/ui/tools/ToolsFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.myuw.ui.tools

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import com.example.myuw.R

class ToolsFragment : Fragment() {

private lateinit var toolsViewModel: ToolsViewModel

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
toolsViewModel =
ViewModelProviders.of(this).get(ToolsViewModel::class.java)
val root = inflater.inflate(R.layout.fragment_tools, container, false)
val textView: TextView = root.findViewById(R.id.text_tools)
toolsViewModel.text.observe(this, Observer {
textView.text = it
})
return root
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/example/myuw/ui/tools/ToolsViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.myuw.ui.tools

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class ToolsViewModel : ViewModel() {

private val _text = MutableLiveData<String>().apply {
value = "This is tools Fragment"
}
val text: LiveData<String> = _text
}
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_menu_camera.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0" />
<path
android:fillColor="#FF000000"
android:pathData="M9,2L7.17,4H4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2H9zm3,15c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z" />
</vector>
Loading

0 comments on commit cc3bc40

Please sign in to comment.