-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #588 from pennlabs/fitness
Fitness
- Loading branch information
Showing
37 changed files
with
1,894 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
PennMobile/src/main/java/com/pennapps/labs/pennmobile/FitnessHolderFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.pennapps.labs.pennmobile | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.TextView | ||
import androidx.coordinatorlayout.widget.CoordinatorLayout | ||
import androidx.fragment.app.Fragment | ||
import com.google.android.material.appbar.AppBarLayout | ||
import com.google.android.material.tabs.TabLayoutMediator | ||
import com.pennapps.labs.pennmobile.adapters.FitnessPagerAdapter | ||
import com.pennapps.labs.pennmobile.components.collapsingtoolbar.ToolbarBehavior | ||
import com.pennapps.labs.pennmobile.utils.Utils | ||
|
||
import kotlinx.android.synthetic.main.fragment_fitness_holder.pager | ||
import kotlinx.android.synthetic.main.fragment_fitness_holder.tabLayout | ||
|
||
class FitnessHolderFragment: Fragment() { | ||
private lateinit var mActivity : MainActivity | ||
private lateinit var mView : View | ||
private lateinit var pagerAdapter : FitnessPagerAdapter | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
mActivity = activity as MainActivity | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
super.onCreateView(inflater, container, savedInstanceState) | ||
return inflater.inflate(R.layout.fragment_fitness_holder, container, false) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
mView = view | ||
// initialize app bar and swipe refresh | ||
initAppBar() | ||
|
||
pagerAdapter = FitnessPagerAdapter(this) | ||
pager?.adapter = pagerAdapter | ||
pager.isUserInputEnabled = false | ||
TabLayoutMediator(tabLayout, pager) { tab, position -> | ||
if (position == 0) { | ||
tab.text = "Pottruck" | ||
} else { | ||
tab.text = "Favorites" | ||
} | ||
}.attach() | ||
} | ||
|
||
/** | ||
* Initialize the app bar of the fragment and | ||
* fills in the textViews for the title/date | ||
*/ | ||
private fun initAppBar() { | ||
val appBarLayout : AppBarLayout = mView.findViewById(R.id.appbar_home_holder) | ||
val titleView : TextView = mView.findViewById(R.id.title_view) | ||
val dateView : TextView = mView.findViewById(R.id.date_view) | ||
|
||
(appBarLayout.layoutParams as CoordinatorLayout.LayoutParams).behavior = ToolbarBehavior() | ||
titleView.text = getString(R.string.fitness) | ||
dateView.text = Utils.getCurrentSystemTime() | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
PennMobile/src/main/java/com/pennapps/labs/pennmobile/FitnessPreferencesFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.pennapps.labs.pennmobile | ||
|
||
import android.os.Bundle | ||
import android.util.Log | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.TextView | ||
import androidx.fragment.app.DialogFragment | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.pennapps.labs.pennmobile.adapters.FitnessPreferenceAdapter | ||
import com.pennapps.labs.pennmobile.classes.FitnessPreferenceViewModel | ||
|
||
interface CloseListener { | ||
fun updateAdapters() | ||
} | ||
|
||
class FitnessPreferencesFragment(private val dataModel: FitnessPreferenceViewModel, | ||
private val listener: CloseListener) : DialogFragment() { | ||
|
||
private lateinit var mActivity : MainActivity | ||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
mActivity = activity as MainActivity | ||
return inflater.inflate(R.layout.fragment_fitness_preferences, container, false) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
val prefAdapter = FitnessPreferenceAdapter(dataModel) | ||
|
||
val recyclerView: RecyclerView = view.findViewById(R.id.fitness_preference_recycler_view) | ||
recyclerView.adapter = prefAdapter | ||
|
||
val cancelText : TextView = view.findViewById(R.id.fitness_fragment_pref_cancel) | ||
cancelText.setOnClickListener { | ||
dataModel.restorePreferences() | ||
dialog?.dismiss() | ||
} | ||
|
||
val saveText : TextView = view.findViewById(R.id.fitness_fragment_pref_save) | ||
saveText.setOnClickListener { | ||
dataModel.updatePositionMap() | ||
dataModel.updateRemotePreferences(mActivity) | ||
listener.updateAdapters() | ||
|
||
dialog?.dismiss() | ||
} | ||
} | ||
|
||
override fun onStart() { | ||
super.onStart() | ||
val dialog = dialog | ||
|
||
if (dialog != null) { | ||
val width = ViewGroup.LayoutParams.MATCH_PARENT | ||
val height = ViewGroup.LayoutParams.MATCH_PARENT | ||
dialog.window!!.setLayout(width, height) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.