Skip to content

Commit

Permalink
"Attach" the view to the bottom of the cellular details screen so tha…
Browse files Browse the repository at this point in the history
…t when new neighbors are added they are within view

This attachment to the bottom only occurs when the view is already scrolled to the bottom
  • Loading branch information
christianrowlands committed Apr 14, 2024
1 parent 2320182 commit f788a93
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Rect;
import android.os.Bundle;
import android.telephony.SubscriptionInfo;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -21,6 +23,7 @@

import com.craxiom.networksurvey.R;
import com.craxiom.networksurvey.SimChangeReceiver;
import com.craxiom.networksurvey.databinding.FragmentMainTabsBinding;
import com.craxiom.networksurvey.services.NetworkSurveyService;
import com.craxiom.networksurvey.services.controller.CellularController;
import com.google.android.material.tabs.TabLayout;
Expand All @@ -40,6 +43,8 @@ public class MainCellularFragment extends AServiceDataFragment
private List<SubscriptionInfo> activeSubscriptionInfoList;

private BroadcastReceiver simBroadcastReceiver;
private FragmentMainTabsBinding binding;
private boolean scrolledToBottom;

@Override
public void onCreate(@Nullable Bundle savedInstanceState)
Expand Down Expand Up @@ -90,7 +95,21 @@ public void onReceive(Context context, Intent intent)
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState)
{
return inflater.inflate(R.layout.fragment_main_tabs, container, false);
binding = FragmentMainTabsBinding.inflate(inflater, container, false);

binding.mainTabsScrollView.getViewTreeObserver().addOnPreDrawListener(() -> {
scrolledToBottom = isScrolledToBottom();
return true;
});

binding.mainTabsScrollView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
if (scrolledToBottom)
{
binding.mainTabsScrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
});

return binding.getRoot();
}

@Override
Expand Down Expand Up @@ -212,4 +231,16 @@ private String getTabTitle(int position)

return "SIM " + subscriptionId;
}

/**
* @return True if the NestedScrollView is scrolled to the bottom. False otherwise.
*/
private boolean isScrolledToBottom()
{
Rect scrollBounds = new Rect();
binding.mainTabsScrollView.getDrawingRect(scrollBounds);
int bottom = binding.mainTabsScrollView.getChildAt(0).getBottom() + binding.mainTabsScrollView.getPaddingBottom();
int delta = bottom - scrollBounds.bottom;
return delta == 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import com.craxiom.networksurvey.util.ColorUtils;
import com.craxiom.networksurvey.util.MathUtils;
import com.craxiom.networksurvey.util.ParserUtils;
import com.mackhartley.roundedprogressbar.ProgressTextFormatter;
import com.mackhartley.roundedprogressbar.RoundedProgressBar;

import java.text.DecimalFormat;
Expand Down
1 change: 1 addition & 0 deletions networksurvey/src/main/res/layout/fragment_main_tabs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<androidx.core.widget.NestedScrollView 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:id="@+id/main_tabs_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/network_details_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="@dimen/fragment_padding_top"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.craxiom.networksurvey.NetworkSurveyActivity">

<LinearLayout
android:id="@+id/network_details_layout"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
Expand Down
2 changes: 1 addition & 1 deletion networksurvey/src/main/res/navigation/cellular.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:id="@+id/main_cellular_fragment"
android:name="com.craxiom.networksurvey.fragments.MainCellularFragment"
android:label="Cellular"
tools:layout="@layout/fragment_network_details">
tools:layout="@layout/fragment_main_tabs">
<action
android:id="@+id/action_main_to_connection"
app:destination="@id/connection_fragment" />
Expand Down
6 changes: 3 additions & 3 deletions networksurvey/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ but work independently, so you have full control over how you handle your data.<
<!-- NR labels -->
<string name="narfcn_band_label">NARFCN/Band</string>
<string name="narfcn_label">NARFCN</string>
<string name="ss_rsrp_label">SS_RSRP</string>
<string name="ss_rsrq_label">SS_RSRQ</string>
<string name="ss_sinr_label">SS_SINR</string>
<string name="ss_rsrp_label">SS-RSRP</string>
<string name="ss_rsrq_label">SS-RSRQ</string>
<string name="ss_sinr_label">SS-SINR</string>

<!-- Dashboard Constants -->
<string name="card_title_logging_details">File Logging Control</string>
Expand Down

0 comments on commit f788a93

Please sign in to comment.