1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2025-01-08 11:11:34 +00:00

Add status light to toolbar in MainActivity to indicate if syncthing is running (fixes #187) (#188)

* SyncthingActivity: Reformat code

* Add status light to toolbar

* MainActivity: Add status light indicating if syncthing is running (fixes #187)

* New colors for status light

* Tri-state status light
This commit is contained in:
Catfriend1 2019-01-03 23:47:55 +01:00 committed by GitHub
parent 8a2fe3ceec
commit 461d65d9b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 6 deletions

View file

@ -36,6 +36,7 @@ import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -114,9 +115,17 @@ public class MainActivity extends SyncthingActivity
oneTimeShot = false; oneTimeShot = false;
} }
// Update status light indicating if syncthing is running.
Button btnDisabled = (Button) findViewById(R.id.btnDisabled);
Button btnStarting = (Button) findViewById(R.id.btnStarting);
Button btnActive = (Button) findViewById(R.id.btnActive);
if (btnDisabled != null && btnStarting != null && btnActive != null) {
btnActive.setVisibility(currentState == SyncthingService.State.ACTIVE ? View.VISIBLE : View.GONE);
btnStarting.setVisibility(currentState == SyncthingService.State.STARTING ? View.VISIBLE : View.GONE);
btnDisabled.setVisibility(currentState != SyncthingService.State.ACTIVE && currentState != SyncthingService.State.STARTING ? View.VISIBLE : View.GONE);
}
switch (currentState) { switch (currentState) {
case STARTING:
break;
case ACTIVE: case ACTIVE:
// Check if the usage reporting minimum delay passed by. // Check if the usage reporting minimum delay passed by.
Boolean usageReportingDelayPassed = (new Date().getTime() > getFirstStartTime() + USAGE_REPORTING_DIALOG_DELAY); Boolean usageReportingDelayPassed = (new Date().getTime() > getFirstStartTime() + USAGE_REPORTING_DIALOG_DELAY);
@ -128,8 +137,6 @@ public class MainActivity extends SyncthingActivity
case ERROR: case ERROR:
finish(); finish();
break; break;
case DISABLED:
break;
} }
} }

View file

@ -39,8 +39,9 @@ public abstract class SyncthingActivity extends AppCompatActivity implements Ser
super.onPostCreate(savedInstanceState); super.onPostCreate(savedInstanceState);
Toolbar toolbar = findViewById(R.id.toolbar); Toolbar toolbar = findViewById(R.id.toolbar);
if (toolbar == null) if (toolbar == null) {
return; return;
}
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
//noinspection ConstantConditions //noinspection ConstantConditions

View file

@ -10,4 +10,36 @@
android:elevation="@dimen/toolbar_elevation" android:elevation="@dimen/toolbar_elevation"
app:titleMarginStart="16dp" app:titleMarginStart="16dp"
android:theme="@style/ThemeOverlay.Syncthing.Toolbar" android:theme="@style/ThemeOverlay.Syncthing.Toolbar"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> android:popupTheme="@style/ThemeOverlay.AppCompat.Light" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/btnActive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:visibility="gone"
app:buttonTint="#76ff03"/>
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/btnStarting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:visibility="gone"
app:buttonTint="#fff103"/>
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/btnDisabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:visibility="gone"
app:buttonTint="#ffae03"/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>