Skip to content

Commit

Permalink
created fragments kind of
Browse files Browse the repository at this point in the history
  • Loading branch information
vavali08 committed Nov 12, 2023
1 parent 6c584f4 commit 354cb2e
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.pennapps.labs.pennmobile

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
* A simple [Fragment] subclass.
* Use the [SubletteeFragment.newInstance] factory method to
* create an instance of this fragment.
*/
class SubletteeFragment : Fragment() {



override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_sublettee_view, container, false)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.pennapps.labs.pennmobile

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
* A simple [Fragment] subclass.
* Use the [SubletterFragment.newInstance] factory method to
* create an instance of this fragment.
*/
class SubletterFragment : Fragment() {


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_subletter_view, container, false)
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.pennapps.labs.pennmobile

import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter

class SublettingAdapter(fm: Fragment) : FragmentStateAdapter(fm) {
override fun getItemCount(): Int = 2
override fun createFragment(position: Int): Fragment {
return if (position == 0) {
SubletterFragment()
} else {
SubletteeFragment()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.pennapps.labs.pennmobile

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.viewpager.widget.ViewPager
import com.google.android.material.tabs.TabLayout
import com.pennapps.labs.pennmobile.adapters.DiningPagerAdapter
import com.pennapps.labs.pennmobile.components.collapsingtoolbar.ToolbarBehavior
import com.pennapps.labs.pennmobile.utils.Utils
import kotlinx.android.synthetic.main.fragment_dining.view.dining_swiperefresh
import kotlinx.android.synthetic.main.fragment_dining_holder.view.appbar_home_holder
import kotlinx.android.synthetic.main.fragment_dining_holder.view.date_view
import kotlinx.android.synthetic.main.fragment_gsr_tabs.view.appbar_home
import kotlinx.android.synthetic.main.fragment_gsr_tabs.view.date_view
import kotlinx.android.synthetic.main.fragment_gsr_tabs.view.title_view
import kotlinx.android.synthetic.main.include_main.toolbar

/**
* A simple [Fragment] subclass.
* Use the [SublettingFragment.newInstance] factory method to
* create an instance of this fragment.
* https://tutorials.eu/viewpager2-with-fragmentstateadapter-in-android/
*/
class SublettingFragment : Fragment() {
lateinit var pagerAdapter: SublettingAdapter
private lateinit var mActivity: MainActivity

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mActivity = activity as MainActivity
mActivity.closeKeyboard()
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_subletting, container, false)
initAppBar(view)
// Inflate the layout for this fragment
return view
}


private fun initAppBar(view: View) {
(view.appbar_home_holder.layoutParams as CoordinatorLayout.LayoutParams).behavior = ToolbarBehavior()
}





}
14 changes: 14 additions & 0 deletions PennMobile/src/main/res/layout/fragment_sublettee_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="sublettee"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
13 changes: 13 additions & 0 deletions PennMobile/src/main/res/layout/fragment_subletter_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="subletter"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
26 changes: 26 additions & 0 deletions PennMobile/src/main/res/layout/fragment_subletting.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager2"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<com.google.android.material.tabs.TabLayout
android:id="@+id/subletting_tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</androidx.viewpager2.widget.ViewPager2>


</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 2 additions & 0 deletions PennMobile/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,6 @@
<string name="fitness_sat">Saturday</string>
<string name="fitness_capacity">Capacity</string>
<string name="room">Room</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ buildscript {
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.0.0'
// Crashlytics Gradle plugin.
classpath "org.jacoco:org.jacoco.core:0.8.5"
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72'
}
}

0 comments on commit 354cb2e

Please sign in to comment.