diff options
author | cyBerta <cyberta@riseup.net> | 2021-07-29 18:23:55 +0200 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2021-11-14 19:22:16 +0100 |
commit | 05934715fec39cb22937e82acecd4add4fccd724 (patch) | |
tree | 21dc69fba378300d565a58b9b11e0c68bd6b2523 /app | |
parent | ff427f2863dd2c3c46030968f4d034553f09d0bf (diff) |
implement location load indicator in gateway selection cell
Diffstat (limited to 'app')
3 files changed, 18 insertions, 22 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java index d1222cd7..e4d8ca8b 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java @@ -46,6 +46,7 @@ import se.leap.bitmaskclient.base.MainActivity; import se.leap.bitmaskclient.base.models.Location; import se.leap.bitmaskclient.base.utils.PreferenceHelper; import se.leap.bitmaskclient.base.views.IconSwitchEntry; +import se.leap.bitmaskclient.base.views.LocationIndicator; import se.leap.bitmaskclient.eip.EipCommand; import se.leap.bitmaskclient.eip.EipStatus; import se.leap.bitmaskclient.eip.GatewaysManager; @@ -189,7 +190,7 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen static class ViewHolder extends RecyclerView.ViewHolder { public AppCompatTextView locationLabel; - public AppCompatTextView qualityLabel; + public LocationIndicator locationIndicator; public AppCompatImageView checkedIcon; public View layout; @@ -197,7 +198,7 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen super(v); layout = v; locationLabel = (AppCompatTextView) v.findViewById(R.id.location); - qualityLabel = (AppCompatTextView) v.findViewById(R.id.quality); + locationIndicator = (LocationIndicator) v.findViewById(R.id.quality); checkedIcon = (AppCompatImageView) v.findViewById(R.id.checked_icon); } } @@ -263,7 +264,7 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen DrawableCompat.setTint(checkIcon, ContextCompat.getColor(holder.layout.getContext(), R.color.colorSuccess)); holder.checkedIcon.setImageDrawable(checkIcon); holder.checkedIcon.setVisibility(location.selected ? VISIBLE : INVISIBLE); - holder.qualityLabel.setText(getQualityString(location.averageLoad)); + holder.locationIndicator.setLoad(GatewaysManager.Load.getLoadByValue(location.averageLoad)); if (location.selected) { selectedLocation = location; } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java index b311315c..24e9c323 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java @@ -130,9 +130,15 @@ public class GatewaysManager { while ((gateway = select(n, null)) != null) { if (!locationNames.containsKey(gateway.getName())) { locationNames.put(gateway.getName(), locations.size()); + // fake values for now + Random rand = new Random(); + double averageLoad = rand.nextDouble(); //location.averageLoad; + + Location location = new Location( gateway.getName(), - gateway.getFullness(), + averageLoad + /*gateway.getFullness()*/, 1, gateway.getName().equals(selectedCity)); locations.add(location); @@ -153,11 +159,7 @@ public class GatewaysManager { List <Location> locations = getGatewayLocations(); for (Location location : locations) { if (location.name.equals(name)) { - - // fake values for now - Random rand = new Random(); - double averageLoad = rand.nextDouble(); //location.averageLoad; - return Load.getLoadByValue(averageLoad); + return Load.getLoadByValue(location.averageLoad); } } diff --git a/app/src/main/res/layout/v_select_text_list_item.xml b/app/src/main/res/layout/v_select_text_list_item.xml index 07187016..36075424 100644 --- a/app/src/main/res/layout/v_select_text_list_item.xml +++ b/app/src/main/res/layout/v_select_text_list_item.xml @@ -19,20 +19,13 @@ tools:visibility="visible" /> - <androidx.appcompat.widget.AppCompatTextView + <se.leap.bitmaskclient.base.views.LocationIndicator android:id="@+id/quality" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:textAppearance="?android:attr/textAppearanceListItem" - android:gravity="center_vertical" - android:paddingStart="@dimen/standard_margin" - android:paddingLeft="@dimen/standard_margin" - android:paddingEnd="@dimen/standard_margin" - android:paddingRight="@dimen/standard_margin" - android:minHeight="?android:attr/listPreferredItemHeightSmall" - android:layout_toLeftOf="@id/checked_icon" - android:layout_toStartOf="@id/checked_icon" - tools:text="GOOD" + android:layout_width="56dp" + android:layout_height="match_parent" + android:layout_toLeftOf="@+id/checked_icon" + android:layout_toStartOf="@+id/checked_icon" + tools:visibility="visible" /> <androidx.appcompat.widget.AppCompatTextView |