Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
e
os
App Lounge
Commits
2c4d0ba0
Commit
2c4d0ba0
authored
Aug 10, 2018
by
Nihar Thakkar
Browse files
Create fragments and implement fragment switching
parent
5dbcfcb3
Changes
12
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/io/eelo/appinstaller/MainActivity.kt
View file @
2c4d0ba0
...
...
@@ -6,17 +6,70 @@ import android.support.design.internal.BottomNavigationItemView
import
android.support.design.internal.BottomNavigationMenuView
import
android.support.design.widget.BottomNavigationView
import
android.annotation.SuppressLint
import
android.support.v4.app.Fragment
import
android.view.MenuItem
import
io.eelo.appinstaller.categories.CategoriesFragment
import
io.eelo.appinstaller.home.HomeFragment
import
io.eelo.appinstaller.search.SearchFragment
import
io.eelo.appinstaller.settings.SettingsFragment
import
io.eelo.appinstaller.updates.UpdatesFragment
import
kotlinx.android.synthetic.main.activity_main.*
class
MainActivity
:
AppCompatActivity
()
{
class
MainActivity
:
AppCompatActivity
(),
BottomNavigationView
.
OnNavigationItemSelectedListener
{
private
var
currentFragment
:
Fragment
?
=
null
private
val
homeFragment
=
HomeFragment
()
private
val
categoriesFragment
=
CategoriesFragment
()
private
val
searchFragment
=
SearchFragment
()
private
val
updatesFragment
=
UpdatesFragment
()
private
val
settingsFragment
=
SettingsFragment
()
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_main
)
// Show the home fragment by default
showFragment
(
homeFragment
)
bottom_navigation_view
.
setOnNavigationItemSelectedListener
(
this
)
// Disable shifting of nav bar items
removeShiftMode
(
bottom_navigation_view
)
}
override
fun
onNavigationItemSelected
(
item
:
MenuItem
):
Boolean
{
when
{
item
.
itemId
==
R
.
id
.
menu_home
->
{
showFragment
(
homeFragment
)
return
true
}
item
.
itemId
==
R
.
id
.
menu_categories
->
{
showFragment
(
categoriesFragment
)
return
true
}
item
.
itemId
==
R
.
id
.
menu_search
->
{
showFragment
(
searchFragment
)
return
true
}
item
.
itemId
==
R
.
id
.
menu_updates
->
{
showFragment
(
updatesFragment
)
return
true
}
item
.
itemId
==
R
.
id
.
menu_settings
->
{
showFragment
(
settingsFragment
)
return
true
}
}
return
false
}
private
fun
showFragment
(
fragment
:
Fragment
)
{
supportFragmentManager
.
beginTransaction
()
.
replace
(
R
.
id
.
frame_layout
,
fragment
)
.
commit
()
currentFragment
=
fragment
}
@SuppressLint
(
"RestrictedApi"
)
private
fun
removeShiftMode
(
bottomNavigationView
:
BottomNavigationView
)
{
val
menuView
=
bottomNavigationView
.
getChildAt
(
0
)
as
BottomNavigationMenuView
...
...
app/src/main/java/io/eelo/appinstaller/categories/CategoriesFragment.kt
0 → 100644
View file @
2c4d0ba0
package
io.eelo.appinstaller.categories
import
android.os.Bundle
import
android.support.v4.app.Fragment
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
io.eelo.appinstaller.R
class
CategoriesFragment
:
Fragment
()
{
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
val
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_categories
,
container
,
false
)
return
view
}
}
\ No newline at end of file
app/src/main/java/io/eelo/appinstaller/home/HomeFragment.kt
0 → 100644
View file @
2c4d0ba0
package
io.eelo.appinstaller.home
import
android.os.Bundle
import
android.support.v4.app.Fragment
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
io.eelo.appinstaller.R
class
HomeFragment
:
Fragment
()
{
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
val
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_home
,
container
,
false
)
return
view
}
}
\ No newline at end of file
app/src/main/java/io/eelo/appinstaller/search/SearchFragment.kt
0 → 100644
View file @
2c4d0ba0
package
io.eelo.appinstaller.search
import
android.os.Bundle
import
android.support.v4.app.Fragment
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
io.eelo.appinstaller.R
class
SearchFragment
:
Fragment
()
{
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
val
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_search
,
container
,
false
)
return
view
}
}
\ No newline at end of file
app/src/main/java/io/eelo/appinstaller/settings/SettingsFragment.kt
0 → 100644
View file @
2c4d0ba0
package
io.eelo.appinstaller.settings
import
android.os.Bundle
import
android.support.v4.app.Fragment
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
io.eelo.appinstaller.R
class
SettingsFragment
:
Fragment
()
{
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
val
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_settings
,
container
,
false
)
return
view
}
}
\ No newline at end of file
app/src/main/java/io/eelo/appinstaller/updates/UpdatesFragment.kt
0 → 100644
View file @
2c4d0ba0
package
io.eelo.appinstaller.updates
import
android.os.Bundle
import
android.support.v4.app.Fragment
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
io.eelo.appinstaller.R
class
UpdatesFragment
:
Fragment
()
{
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
val
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_updates
,
container
,
false
)
return
view
}
}
\ No newline at end of file
app/src/main/res/layout/activity_main.xml
View file @
2c4d0ba0
...
...
@@ -6,17 +6,25 @@
android:layout_height=
"match_parent"
tools:context=
".MainActivity"
>
<FrameLayout
android:id=
"@+id/frame_layout"
android:layout_width=
"match_parent"
android:layout_height=
"0dp"
app:layout_constraintBottom_toTopOf=
"@id/divider"
app:layout_constraintTop_toTopOf=
"parent"
/>
<View
android:id=
"@+id/divider"
android:layout_width=
"match_parent"
android:layout_height=
"1dp"
android:background=
"@color/colorDivider"
app:layout_constraintBottom_toTopOf=
"@id/bottom_navigation_view"
/>
app:layout_constraintBottom_toTopOf=
"@id/bottom_navigation_view"
/>
<android.support.design.widget.BottomNavigationView
android:id=
"@+id/bottom_navigation_view"
android:layout_width=
"match_parent"
a
pp:menu=
"@menu/activity_main_m
en
u
"
a
ndroid:layout_height=
"wrap_cont
en
t
"
app:layout_constraintBottom_toBottomOf=
"parent"
a
ndroid:layout_height=
"wrap_content"
/>
a
pp:menu=
"@menu/activity_main_menu"
/>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
app/src/main/res/layout/fragment_categories.xml
0 → 100644
View file @
2c4d0ba0
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Categories Fragment"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
app/src/main/res/layout/fragment_home.xml
0 → 100644
View file @
2c4d0ba0
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Home Fragment"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
app/src/main/res/layout/fragment_search.xml
0 → 100644
View file @
2c4d0ba0
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Search Fragment"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
app/src/main/res/layout/fragment_settings.xml
0 → 100644
View file @
2c4d0ba0
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Settings Fragment"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
app/src/main/res/layout/fragment_updates.xml
0 → 100644
View file @
2c4d0ba0
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Updates Fragment"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment