Skip to content

Commit

Permalink
Add web server status in home card
Browse files Browse the repository at this point in the history
  • Loading branch information
PerfectSlayer committed Aug 5, 2018
1 parent 2f32c01 commit 6816251
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 8 deletions.
25 changes: 22 additions & 3 deletions app/src/main/java/org/adaway/ui/home/HomeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (C) 2011-2012 Dominik Schürmann <[email protected]>
*
* This file is part of AdAway.
*
*
* AdAway is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand Down Expand Up @@ -116,6 +116,14 @@ public class HomeFragment extends Fragment {
/*
* Web server card views.
*/
/**
* The web server status text(<code>null</code> until view created).
*/
private TextView mWebSeverStatusTextView;
/**
* The web server status icon(<code>null</code> until view created).
*/
private ImageView mWebServerStatusImageView;
/**
* The enable/disable web server button (<code>null</code> until view created).
*/
Expand Down Expand Up @@ -277,8 +285,10 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
mStatusTextView = view.findViewById(R.id.home_status_text);
mUpdateHostsButton = view.findViewById(R.id.home_update_hosts);
mRevertHostsButton = view.findViewById(R.id.home_revert_hosts);
// Get view from web server card
// Get views from web server card
CardView webServerCardView = view.findViewById(R.id.home_webserver_card);
mWebSeverStatusTextView = view.findViewById(R.id.home_webserver_status);
mWebServerStatusImageView = view.findViewById(R.id.home_webserver_icon);
mRunningWebServerButton = view.findViewById(R.id.home_webserver_enable);
/*
* Register local broadcast receiver.
Expand Down Expand Up @@ -457,11 +467,20 @@ private void toggleWebServer(@Nullable View view) {
*/
void notifyWebServerRunning(boolean running) {
// Check button
if (mRunningWebServerButton == null) {
if (mWebSeverStatusTextView == null || mWebServerStatusImageView == null || mRunningWebServerButton == null) {
return;
}
// Store web server running status
mWebServerRunning = running;
// Update status text and icon
mWebSeverStatusTextView.setText(running ?
R.string.webserver_status_running :
R.string.webserver_status_stopped
);
mWebServerStatusImageView.setImageResource(running ?
R.drawable.status_enabled :
R.drawable.status_disabled
);
// Update button text
mRunningWebServerButton.setText(running ?
R.string.button_disable_webserver :
Expand Down
44 changes: 39 additions & 5 deletions app/src/main/res/layout/home_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,47 @@
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/home_webserver_header"
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/header_webserver"
android:textAppearance="@android:style/TextAppearance.Medium" />
android:padding="16dp">

<TextView
android:id="@+id/home_webserver_header"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="@string/header_webserver"
android:textAppearance="@android:style/TextAppearance.Medium"
app:layout_constraintBottom_toTopOf="@+id/home_webserver_status"
app:layout_constraintEnd_toStartOf="@+id/home_webserver_icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/home_webserver_status"
android:layout_width="0dp"
android:layout_height="18dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="@string/webserver_status_stopped"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/home_webserver_icon"
app:layout_constraintStart_toStartOf="parent" />

<ImageView
android:id="@+id/home_webserver_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:contentDescription="@string/icon_update_status"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/status_disabled" />

</android.support.constraint.ConstraintLayout>

<View
android:layout_width="match_parent"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<string name="button_enable_hosts">Enable ad-blocking</string>
<string name="button_disable_hosts">Disable ad-blocking</string>
<string name="header_webserver">Web server</string>
<string name="webserver_status_running">Running</string>
<string name="webserver_status_stopped">Stopped</string>
<string name="button_enable_webserver">Enable web server</string>
<string name="button_disable_webserver">Disable web server</string>

Expand Down

0 comments on commit 6816251

Please sign in to comment.