Skip to content

Commit edffa5a

Browse files
Meenbeesemeenbeese
authored andcommitted
Refresh activity layout with segmented button
1 parent f26ee8e commit edffa5a

File tree

6 files changed

+75
-41
lines changed

6 files changed

+75
-41
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
android:theme="@style/OrbotActivityTheme" />
7171

7272
<activity
73+
android:theme="@style/OrbotActivityMaterialTheme"
7374
android:name=".ui.v3onionservice.OnionServiceActivity"
7475
android:label="@string/v3_hosted_services" />
7576

app/src/main/java/org/torproject/android/ui/v3onionservice/OnionServiceActivity.java

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
import android.os.Handler;
1010
import android.view.Menu;
1111
import android.view.MenuItem;
12-
import android.view.View;
1312
import android.view.WindowManager;
1413
import android.widget.ListView;
15-
import android.widget.RadioButton;
1614

1715
import androidx.annotation.NonNull;
18-
import androidx.appcompat.widget.Toolbar;
1916
import androidx.coordinatorlayout.widget.CoordinatorLayout;
17+
import androidx.core.content.ContextCompat;
2018

19+
import com.google.android.material.appbar.MaterialToolbar;
20+
import com.google.android.material.button.MaterialButton;
2121
import com.google.android.material.floatingactionbutton.FloatingActionButton;
2222

2323
import org.torproject.android.R;
@@ -31,7 +31,8 @@ public class OnionServiceActivity extends BaseActivity {
3131
private static final String BASE_WHERE_SELECTION_CLAUSE = OnionServiceColumns.CREATED_BY_USER + "=";
3232
private static final String BUNDLE_KEY_SHOW_USER_SERVICES = "show_user_key";
3333
private static final int REQUEST_CODE_READ_ZIP_BACKUP = 347;
34-
private RadioButton radioShowUserServices;
34+
private MaterialButton btnShowUserServices;
35+
private MaterialButton btnShowAppServices;
3536
private FloatingActionButton fab;
3637
private ContentResolver mContentResolver;
3738
private OnionV3ListAdapter mAdapter;
@@ -44,10 +45,10 @@ public void onCreate(Bundle bundle) {
4445
setContentView(R.layout.activity_hosted_services);
4546
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
4647

47-
Toolbar toolbar = findViewById(R.id.toolbar);
48+
MaterialToolbar toolbar = findViewById(R.id.toolbar);
4849
setSupportActionBar(toolbar);
49-
var sab = getSupportActionBar();
50-
if (sab != null) sab.setDisplayHomeAsUpEnabled(true);
50+
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
51+
toolbar.setNavigationOnClickListener(v -> getOnBackPressedDispatcher().onBackPressed());
5152

5253
mLayoutRoot = findViewById(R.id.hostedServiceCoordinatorLayout);
5354
fab = findViewById(R.id.fab);
@@ -59,11 +60,27 @@ public void onCreate(Bundle bundle) {
5960

6061
ListView onionList = findViewById(R.id.onion_list);
6162

62-
radioShowUserServices = findViewById(R.id.radioUserServices);
63-
RadioButton radioShowAppServices = findViewById(R.id.radioAppServices);
64-
boolean showUserServices = radioShowAppServices.isChecked() || bundle == null || bundle.getBoolean(BUNDLE_KEY_SHOW_USER_SERVICES, false);
65-
if (showUserServices) radioShowUserServices.setChecked(true);
66-
else radioShowAppServices.setChecked(true);
63+
btnShowUserServices = findViewById(R.id.radioUserServices);
64+
btnShowAppServices = findViewById(R.id.radioAppServices);
65+
66+
btnShowUserServices.setOnClickListener(v -> {
67+
btnShowUserServices.setBackgroundColor(ContextCompat.getColor(this, R.color.orbot_btn_enabled_purple));
68+
btnShowAppServices.setBackgroundColor(ContextCompat.getColor(this, R.color.orbot_btn_disable_grey));
69+
filterServices(true);
70+
});
71+
72+
btnShowAppServices.setOnClickListener(v -> {
73+
btnShowUserServices.setBackgroundColor(ContextCompat.getColor(this, R.color.orbot_btn_disable_grey));
74+
btnShowAppServices.setBackgroundColor(ContextCompat.getColor(this, R.color.orbot_btn_enabled_purple));
75+
filterServices(false);
76+
});
77+
78+
boolean showUserServices = btnShowAppServices.isChecked() || bundle == null || bundle.getBoolean(BUNDLE_KEY_SHOW_USER_SERVICES, false);
79+
if (showUserServices) {
80+
btnShowUserServices.setChecked(true);
81+
} else {
82+
btnShowAppServices.setChecked(true);
83+
}
6784
filterServices(showUserServices);
6885
onionList.setAdapter(mAdapter);
6986
onionList.setOnItemClickListener((parent, view, position, id) -> {
@@ -98,9 +115,9 @@ public boolean onCreateOptionsMenu(Menu menu) {
98115
}
99116

100117
@Override
101-
protected void onSaveInstanceState(@NonNull Bundle icicle) {
102-
super.onSaveInstanceState(icicle);
103-
icicle.putBoolean(BUNDLE_KEY_SHOW_USER_SERVICES, radioShowUserServices.isChecked());
118+
protected void onSaveInstanceState(@NonNull Bundle bundle) {
119+
super.onSaveInstanceState(bundle);
120+
bundle.putBoolean(BUNDLE_KEY_SHOW_USER_SERVICES, btnShowUserServices.isChecked());
104121
}
105122

106123
@Override
@@ -122,14 +139,6 @@ protected void onActivityResult(int requestCode, int result, Intent data) {
122139
}
123140
}
124141

125-
public void onRadioButtonClick(View view) {
126-
int id = view.getId();
127-
if (id == R.id.radioUserServices)
128-
filterServices(true);
129-
else if (id == R.id.radioAppServices)
130-
filterServices(false);
131-
}
132-
133142
private class OnionServiceObserver extends ContentObserver {
134143

135144
OnionServiceObserver(Handler handler) {
@@ -138,7 +147,7 @@ private class OnionServiceObserver extends ContentObserver {
138147

139148
@Override
140149
public void onChange(boolean selfChange) {
141-
filterServices(radioShowUserServices.isChecked()); // updates adapter
150+
filterServices(btnShowUserServices.isChecked());
142151
showBatteryOptimizationsMessageIfAppropriate();
143152
}
144153
}

app/src/main/res/layout/activity_hosted_services.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
android:layout_width="match_parent"
1414
android:layout_height="wrap_content">
1515

16-
<androidx.appcompat.widget.Toolbar
16+
<com.google.android.material.appbar.MaterialToolbar
1717
android:id="@+id/toolbar"
1818
android:baselineAligned="false"
1919
android:layout_width="match_parent"
20-
android:layout_height="?attr/actionBarSize"/>
20+
android:layout_height="?attr/actionBarSize"
21+
android:background="@color/new_background"
22+
app:titleTextColor="@android:color/white"
23+
app:titleCentered="true" />
2124

2225
</com.google.android.material.appbar.AppBarLayout>
2326

@@ -28,7 +31,8 @@
2831
android:layout_width="wrap_content"
2932
android:layout_height="wrap_content"
3033
android:layout_gravity="bottom|end"
31-
android:layout_margin="@dimen/fab_margin"
34+
android:layout_marginStart="@dimen/fab_margin"
35+
android:layout_marginEnd="@dimen/fab_margin"
3236
android:tint="@android:color/black"
3337
app:fabSize="normal"
3438
app:backgroundTint="@color/progress_bar_purple"

app/src/main/res/layout/layout_hs_list_view_main.xml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,39 @@
1414
tools:context="org.torproject.android.ui.v3onionservice.OnionServiceActivity"
1515
tools:showIn="@layout/activity_hosted_services">
1616

17-
18-
<TextView
17+
<com.google.android.material.textview.MaterialTextView
1918
android:layout_width="wrap_content"
2019
android:layout_height="wrap_content"
2120
android:layout_marginBottom="2dp"
2221
android:text="@string/service_type" />
2322

24-
<RadioGroup
25-
android:paddingStart="-5dp"
23+
<com.google.android.material.button.MaterialButtonToggleGroup
24+
android:id="@+id/toggleButtonGroup"
2625
android:layout_width="match_parent"
2726
android:layout_height="wrap_content"
2827
android:layout_marginBottom="@dimen/activity_vertical_margin"
29-
android:orientation="horizontal">
28+
app:singleSelection="true">
3029

31-
<RadioButton
30+
<com.google.android.material.button.MaterialButton
3231
android:id="@+id/radioUserServices"
33-
android:layout_width="140dp"
32+
style="@style/SegmentedButtonStyle"
33+
android:backgroundTint="@color/orbot_btn_enabled_purple"
34+
android:layout_width="0dp"
3435
android:layout_height="wrap_content"
35-
android:onClick="onRadioButtonClick"
36-
android:text="@string/user_services" />
36+
android:layout_weight="1"
37+
android:text="@string/user_services"
38+
app:cornerRadius="10dp" />
3739

38-
<RadioButton
40+
<com.google.android.material.button.MaterialButton
3941
android:id="@+id/radioAppServices"
40-
android:layout_width="140dp"
42+
style="@style/SegmentedButtonStyle"
43+
android:backgroundTint="@color/orbot_btn_disable_grey"
44+
android:layout_width="0dp"
4145
android:layout_height="wrap_content"
42-
android:onClick="onRadioButtonClick"
43-
android:text="@string/app_services" />
44-
</RadioGroup>
46+
android:layout_weight="1"
47+
android:text="@string/app_services"
48+
app:cornerRadius="10dp" />
49+
</com.google.android.material.button.MaterialButtonToggleGroup>
4550

4651
<ListView
4752
android:id="@+id/onion_list"

app/src/main/res/values/styles.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,11 @@
3131
<style name="BottomSheetRadio" parent="android:Widget.CompoundButton.RadioButton">
3232
<item name="buttonTint">@color/menu_header</item>
3333
</style>
34+
35+
<style name="SegmentedButtonStyle" parent="Widget.MaterialComponents.Button">
36+
<item name="android:foreground">?attr/selectableItemBackground</item>
37+
<item name="android:textColor">@color/panel_background_main</item>
38+
<item name="android:textAppearance">@style/TextAppearance.Material3.TitleMedium</item>
39+
</style>
40+
3441
</resources>

app/src/main/res/values/theme.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
<item name="colorPrimaryDark">@color/new_background_secondary</item>
1717
</style>
1818

19+
<style name="OrbotActivityMaterialTheme" parent="Theme.MaterialComponents.NoActionBar">
20+
<item name="android:statusBarColor">@color/new_background_secondary</item>
21+
<item name="android:windowBackground">@color/new_background_secondary</item>
22+
<item name="android:windowIsFloating">false</item>
23+
<item name="colorPrimary">@color/new_background_secondary</item>
24+
<item name="colorPrimaryDark">@color/new_background_secondary</item>
25+
</style>
26+
1927
<style name="OrbotDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
2028
<item name="android:background">@color/new_background_secondary</item>
2129
<item name="android:textColor">@android:color/white</item>

0 commit comments

Comments
 (0)