Skip to content

Commit

Permalink
Dynamic Tabs work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
JSnipes29 committed Jan 21, 2024
1 parent 8f933db commit a3c7616
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.pennapps.labs.pennmobile.adapters.DynamicTabsAdapter
import com.pennapps.labs.pennmobile.classes.Tab
import kotlinx.android.synthetic.main.fragment_dynamic_tabs.view.*


class DynamicTabsFragment : Fragment() {

lateinit var dynamicTabsAdapter: DynamicTabsAdapter
lateinit var tabs : List<Tab>

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

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_dynamic_tabs, container, false)
tabs = listOf(Tab("Dining"), Tab("GSR"), Tab("Laundry"))
// val itemTouchHelper = object : ItemTouchHelper() {
// }
dynamicTabsAdapter = DynamicTabsAdapter(tabs)
view.rvDynamicTabs.adapter = dynamicTabsAdapter
view.rvDynamicTabs.layoutManager = LinearLayoutManager(context)
return view
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,12 @@ class HomeFragment : Fragment() {
Log.i("HomeFragment", "polls $loaded")

if (loaded == totalCells) {
home_cells_rv?.adapter = HomeAdapter(ArrayList(homepageCells))
loadingPanel?.visibility = View.GONE
internetConnectionHome?.visibility = View.GONE
home_refresh_layout?.isRefreshing = false
mActivity.runOnUiThread {
home_cells_rv?.adapter = HomeAdapter(ArrayList(homepageCells))
loadingPanel?.visibility = View.GONE
internetConnectionHome?.visibility = View.GONE
home_refresh_layout?.isRefreshing = false
}
}
}, { throwable ->
Log.e("Poll", "Error retrieving polls", throwable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ class MainActivity : AppCompatActivity() {
private fun onExpandableBottomNavigationItemSelected() {
expandable_bottom_bar.setOnNavigationItemSelectedListener { item ->
val position = when (item.itemId) {
R.id.nav_home-> MainPagerAdapter.HOME_POSITION
R.id.nav_dining-> MainPagerAdapter.DINING_POSITION
R.id.nav_gsr-> MainPagerAdapter.GSR_POSITION
R.id.nav_laundry-> MainPagerAdapter.LAUNDRY_POSITION
R.id.nav_more-> MainPagerAdapter.MORE_POSITION
else -> MainPagerAdapter.HOME_POSITION
R.id.nav_home-> 0
R.id.nav_dining-> 1
R.id.nav_gsr-> 2
R.id.nav_laundry-> 3
R.id.nav_more-> 4
else -> 0
}
main_view_pager.setCurrentItem(position, false)
true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.pennapps.labs.pennmobile.adapters

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.pennapps.labs.pennmobile.R
import com.pennapps.labs.pennmobile.classes.Tab
import kotlinx.android.synthetic.main.dynamic_tab_item.view.*

class DynamicTabsAdapter(private val tabs : List<Tab>) : RecyclerView.Adapter<DynamicTabsAdapter.ViewHolder>() {

class ViewHolder(val view: View) : RecyclerView.ViewHolder(view) {

init {
// Define click listener for the ViewHolder's View
}
fun bindTab(tab: Tab) {
view.tvDynamicTab.text = tab.name

}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.dynamic_tab_item, parent, false))
}

override fun getItemCount(): Int {
return tabs.size
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.itemView
holder.bindTab(tabs[position])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,54 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Lifecycle
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.google.gson.Gson
import com.pennapps.labs.pennmobile.DiningHolderFragment
import com.pennapps.labs.pennmobile.GsrTabbedFragment
import com.pennapps.labs.pennmobile.HomeFragment
import com.pennapps.labs.pennmobile.LaundryFragment
import com.pennapps.labs.pennmobile.more_fragments.MoreFragment
import java.util.*

class MainPagerAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle?) : FragmentStateAdapter(fragmentManager, lifecycle!!) {

companion object {

const val HOME_ID = 0
const val DINING_ID = 1
const val GSR_ID = 2
const val LAUNDRY_ID = 3
const val MORE_ID = 4
const val COUNT = 5
fun updateMainList() {
// val gson = Gson()
//
// // below line is to get to string present from our
// // shared prefs if not present setting it as null.
// val json = sharedPreferences.getString("courses", null)
//
// // below line is to get the type of our array list.
// val type: Type = object : TypeToken<ArrayList<CourseRVModal?>?>() {}.type
//
// // in below line we are getting data from gson
// // and saving it to our array list
// courseList = gson.fromJson<Any>(json, type) as ArrayList<CourseRVModal>
}
//val mainList : List<Int> = updateMainList() // [ HOME, DINING, GSR, LAUNDRY, FITNESS]
val mainList : List<Int> = listOf(DINING_ID, GSR_ID, LAUNDRY_ID)
}
override fun createFragment(position: Int): Fragment {
return when(position) {
HOME_POSITION-> HomeFragment()
DINING_POSITION-> DiningHolderFragment()
GSR_POSITION-> GsrTabbedFragment()
LAUNDRY_POSITION-> LaundryFragment()
MORE_POSITION-> MoreFragment()
if(position == 0) {
return HomeFragment()
}
if(position == 4) {
return MoreFragment()
}
return when(mainList[position - 1]) {
HOME_ID-> HomeFragment()
DINING_ID-> DiningHolderFragment()
GSR_ID-> GsrTabbedFragment()
LAUNDRY_ID-> LaundryFragment()
MORE_ID-> MoreFragment()
else -> HomeFragment()
}
}
Expand All @@ -26,16 +60,4 @@ class MainPagerAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle?)
return COUNT
}

override fun getItemId(position: Int): Long {
return if (position < COUNT) position.toLong() else createFragment(position).hashCode().toLong()
}

companion object {
const val HOME_POSITION = 0
const val DINING_POSITION = 1
const val GSR_POSITION = 2
const val LAUNDRY_POSITION = 3
const val MORE_POSITION = 4
const val COUNT = 5
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.pennapps.labs.pennmobile.classes

class Tab(val name: String) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ class PreferenceFragment : PreferenceFragmentCompat() {
return@setOnPreferenceClickListener true
}

val selectPreferencePref: Preference? = findPreference("pref_account_preferences")
selectPreferencePref?.setOnPreferenceClickListener {
mActivity.supportFragmentManager.beginTransaction()
.replace(R.id.more_frame, DynamicTabsFragment())
.addToBackStack(null)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit()
return@setOnPreferenceClickListener true
}

val aboutFeaturePref: Preference? = findPreference("pref_about_feature")
aboutFeaturePref?.setOnPreferenceClickListener {
mActivity.supportFragmentManager.beginTransaction()
Expand Down
34 changes: 34 additions & 0 deletions PennMobile/src/main/res/layout/dynamic_tab_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="60dp"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">

<ImageView
android:id="@+id/ivDynamicTab"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:background="@drawable/ic_home_grey"/>
<TextView
android:id="@+id/tvDynamicTab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
app:layout_constraintStart_toEndOf="@id/ivDynamicTab"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:textSize="24sp"
style="@style/tab_text"
tools:text="Dining"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/black"
app:layout_constraintBottom_toBottomOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
25 changes: 25 additions & 0 deletions PennMobile/src/main/res/layout/fragment_dynamic_tabs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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=".DynamicTabsFragment">

<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvDynamicTabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

tools:listitem="@layout/dynamic_tab_item"
tools:itemCount="8"/>
</androidx.cardview.widget.CardView>

</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 @@ -233,4 +233,6 @@
<string name="fitness_mf">Mon - Fri</string>
<string name="fitness_sat">Saturday</string>
<string name="fitness_capacity">Capacity</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
5 changes: 5 additions & 0 deletions PennMobile/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
android:summary="Modify your name and email"
android:title="Edit your profile"
app:iconSpaceReserved="false" />
<Preference
android:id="@+id/pref_account_preferences"
android:key="pref_account_preferences"
android:title="Select Preferences"
app:iconSpaceReserved="false" />
<Preference
android:id="@+id/pref_account_login_logout"
android:key="pref_account_login_logout"
Expand Down

0 comments on commit a3c7616

Please sign in to comment.