99import android .os .Handler ;
1010import android .view .Menu ;
1111import android .view .MenuItem ;
12- import android .view .View ;
1312import android .view .WindowManager ;
1413import android .widget .ListView ;
15- import android .widget .RadioButton ;
1614
1715import androidx .annotation .NonNull ;
18- import androidx .appcompat .widget .Toolbar ;
1916import 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 ;
2121import com .google .android .material .floatingactionbutton .FloatingActionButton ;
2222
2323import 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 }
0 commit comments