Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to ViewPager2 #2873

Merged
merged 17 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:versionCode="106"
android:versionName="2.55">
android:versionName="2.56">

<uses-permission android:name="android.permission.NFC"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
Expand Down
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ dependencies {
implementation 'com.google.firebase:firebase-messaging:21.1.0'
implementation 'com.google.firebase:firebase-crashlytics:17.2.1'
implementation 'androidx.legacy:legacy-support-core-ui:1.0.0'
implementation (name: 'rtl-viewpager-2.0.0', ext: 'aar')
implementation('com.github.bumptech.glide:glide:4.9.0') {
exclude group: 'com.android.support'
}
Expand Down
Binary file removed app/libs/rtl-viewpager-2.0.0.aar
Binary file not shown.
40 changes: 0 additions & 40 deletions app/res/drawable/title_case_tab_vertical.xml

This file was deleted.

45 changes: 0 additions & 45 deletions app/res/drawable/title_neutral_tab_vertical.xml

This file was deleted.

47 changes: 23 additions & 24 deletions app/res/layout/tabbed_detail_view.xml
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:viewBindingIgnore="true">

<LinearLayout
android:id="@+id/tabbed_detail_menu"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>

<LinearLayout
android:id="@+id/tabbed_detail_pager_wrapper"
android:layout_below="@id/tabbed_detail_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="match_parent"
android:orientation="vertical">

<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
android:layout_gravity="top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/cc_brand_bg"
android:paddingTop="@dimen/dp6"
app:tabMode="scrollable"
app:tabGravity="center"
app:tabIndicatorGravity="bottom"
app:tabIndicatorHeight="@dimen/detail_view_tab_indicator_height"
app:tabIndicatorColor="@color/cc_brand_text"
app:tabPaddingStart="@dimen/detail_view_tab_padding_horizontal"
app:tabPaddingEnd="@dimen/detail_view_tab_padding_horizontal"
app:tabTextAppearance="@style/DetailViewTabStyle" />

<!-- NOTE: In order to deal with annoying issues of multiplicity,
this ID shouldn't be considered static for layouts, etc. DO NOT REFER
to the tabbed_detail_pager ID in any xml, and only within the pager
class in android until its ID changes. -->
<com.duolingo.open.rtlviewpager.RtlViewPager
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/tabbed_detail_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<androidx.viewpager.widget.PagerTabStrip
android:id="@+id/pager_tab_strip"
android:layout_gravity="top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/content_min_margin"
android:paddingBottom="@dimen/content_min_margin"
android:textColor="@color/cc_brand_text"
android:background="@color/cc_brand_bg"
/>
</com.duolingo.open.rtlviewpager.RtlViewPager>

android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>

</merge>
2 changes: 2 additions & 0 deletions app/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<dimen name="title_padding">10dp</dimen>
<dimen name="title_paddingLeft">20dp</dimen>
<dimen name="tab_gradient_radius">300dp</dimen>
<dimen name="detail_view_tab_indicator_height">3dp</dimen>
<dimen name="detail_view_tab_padding_horizontal">24dp</dimen>
shubham1g5 marked this conversation as resolved.
Show resolved Hide resolved

<dimen name="spacer_small">5dp</dimen>
<dimen name="standard_spacer_half">4dp</dimen>
Expand Down
8 changes: 6 additions & 2 deletions app/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@
</style>

<style name="DetailDrawerPulldown">
<item name="even_row_color">@color/cc_brand_bg</item>
<item name="odd_row_color">@color/drawer_pulldown_odd_row_color</item>
<item name="even_row_color">@color/transparent</item>
<item name="odd_row_color">@color/cc_neutral_bg</item>
</style>

<style name="ScreenPinnedButtonBase">
Expand Down Expand Up @@ -343,4 +343,8 @@
<item name="textColor">@color/cc_brand_color</item>
</style>

<style name="DetailViewTabStyle">
<item name="android:textColor">@color/cc_brand_text</item>
</style>

</resources>
1 change: 0 additions & 1 deletion app/src/org/commcare/activities/EntityDetailActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public void onCreateSessionSafe(Bundle savedInstanceState) {
mDetailView.setRoot(container.findViewById(R.id.entity_detail_tabs));
mDetailView.refresh(detail, mTreeReference, detailIndex);

mDetailView.showMenu();
isFinalSwipeActionEnabled = DeveloperPreferences.isDetailTabSwipeActionEnabled();
}

Expand Down
1 change: 0 additions & 1 deletion app/src/org/commcare/activities/EntitySelectActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,6 @@ private void displayReferenceAwesome(final TreeReference selection, int detailIn

Detail detail = session.getDetail(selectedIntent.getStringExtra(EntityDetailActivity.DETAIL_ID));
factory = new NodeEntityFactory(detail, session.getEvaluationContext(new AndroidInstanceInitializer(session)));
detailView.showMenu();

if (detail.isCompound()) {
// border around right panel doesn't look right when there are tabs
Expand Down
34 changes: 14 additions & 20 deletions app/src/org/commcare/adapters/EntityDetailPagerAdapter.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.commcare.adapters;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.lifecycle.Lifecycle;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import org.commcare.CommCareApplication;
import org.commcare.cases.entity.EntityUtil;
Expand All @@ -18,30 +21,28 @@
*
* @author jschweers
*/
public class EntityDetailPagerAdapter extends FragmentStatePagerAdapter {
public class EntityDetailPagerAdapter extends FragmentStateAdapter{

private ListItemViewModifier modifier;
private final ListItemViewModifier modifier;
private final Detail detail;
private final int detailIndex;
private final TreeReference mEntityReference;
private final Detail[] displayableChildDetails;

public EntityDetailPagerAdapter(FragmentManager fm, Detail detail, int detailIndex,
TreeReference reference, ListItemViewModifier modifier) {
super(fm);
public EntityDetailPagerAdapter(@NonNull FragmentManager fm, @NonNull Lifecycle lifecycle, Detail detail, int detailIndex, TreeReference reference, ListItemViewModifier modifier) {
super(fm, lifecycle);
this.detail = detail;
this.detailIndex = detailIndex;
this.mEntityReference = reference;
this.modifier = modifier;
this.displayableChildDetails = detail.getDisplayableChildDetails(
EntityUtil.prepareCompoundEvaluationContext(mEntityReference, detail,
CommCareApplication.instance().getCurrentSessionWrapper().getEvaluationContext()));
this.displayableChildDetails = detail.getDisplayableChildDetails(EntityUtil.prepareCompoundEvaluationContext(mEntityReference, detail, CommCareApplication.instance().getCurrentSessionWrapper().getEvaluationContext()));
}

@NonNull
@Override
public Fragment getItem(int i) {
public Fragment createFragment(int position) {
EntityDetailFragment fragment;
if (detail.getNodeset() != null || (detail.isCompound() && displayableChildDetails[i].getNodeset() != null)) {
if (detail.getNodeset() != null || (detail.isCompound() && displayableChildDetails[position].getNodeset() != null)) {
fragment = new EntitySubnodeDetailFragment();
} else {
fragment = new EntityDetailFragment();
Expand All @@ -50,7 +51,7 @@ public Fragment getItem(int i) {
Bundle args = new Bundle();
args.putString(EntityDetailFragment.DETAIL_ID, detail.getId());
if (detail.isCompound()) {
args.putInt(EntityDetailFragment.CHILD_DETAIL_INDEX, i);
args.putInt(EntityDetailFragment.CHILD_DETAIL_INDEX, position);
}
args.putInt(EntityDetailFragment.DETAIL_INDEX, detailIndex);
SerializationUtil.serializeToBundle(args, EntityDetailFragment.CHILD_REFERENCE, mEntityReference);
Expand All @@ -59,14 +60,7 @@ public Fragment getItem(int i) {
}

@Override
public CharSequence getPageTitle(int position) {
Detail detailShowing = detail.isCompound() ? displayableChildDetails[position] : detail;
return detailShowing.getTitle().getText().evaluate();
}

@Override
public int getCount() {
public int getItemCount() {
return detail.isCompound() ? displayableChildDetails.length : 1;
}

}
1 change: 0 additions & 1 deletion app/src/org/commcare/fragments/BreadcrumbBarFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ public void expandInlineTile(AppCompatActivity activity, View holder,
CommCareSession session = asw.getSession();

Detail detail = session.getDetail(inlineDetailId);
mInternalDetailView.showMenu();
mInternalDetailView.refresh(detail, tileData.second, 0);
}
expand(activity, holder.findViewById(R.id.com_tile_holder_detail_master));
Expand Down
Loading