1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-26 14:21:16 +00:00

adds display of syncthing version in main drawer

This commit is contained in:
Lars K.W. Gohlke 2016-06-09 08:55:49 +02:00
parent 1f6acb8f83
commit 1aafb38764
6 changed files with 101 additions and 2 deletions

View file

@ -24,6 +24,7 @@ dependencies {
compile 'eu.chainfire:libsuperuser:1.0.0.201602271131'
compile 'com.android.support:design:23.3.0'
compile 'com.google.zxing:android-integration:3.2.1'
compile 'com.google.code.gson:gson:2.6.2'
androidTestCompile 'com.squareup.okhttp:mockwebserver:2.4.0'
}

View file

@ -72,6 +72,18 @@ public class RestApiTest extends AndroidTestCase {
latch.await(1, TimeUnit.SECONDS);
}
public void testGetSystemVersion() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
mApi.getSystemVersion(new RestApi.OnReceiveSystemVersionListener() {
@Override
public void onReceiveSystemVersion(RestApi.SystemVersion info) {
assertNotNull(info);
latch.countDown();
}
});
latch.await(1, TimeUnit.SECONDS);
}
public void testGetFolders() {
assertNotNull(mApi.getFolders());
}

View file

@ -38,7 +38,6 @@ import android.widget.TextView;
import android.widget.Toast;
import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.fragments.DeviceFragment;
import com.nutomic.syncthingandroid.fragments.DeviceListFragment;
import com.nutomic.syncthingandroid.fragments.DrawerFragment;
import com.nutomic.syncthingandroid.fragments.FolderListFragment;

View file

@ -24,7 +24,9 @@ import java.util.TimerTask;
* Displays information about the local device.
*/
public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemInfoListener,
RestApi.OnReceiveConnectionsListener, View.OnClickListener {
RestApi.OnReceiveConnectionsListener,
RestApi.OnReceiveSystemVersionListener,
View.OnClickListener {
private TextView mDeviceId;
private TextView mCpuUsage;
@ -32,6 +34,7 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
private TextView mDownload;
private TextView mUpload;
private TextView mAnnounceServer;
private TextView mVersion;
private TextView mExitButton;
@ -85,6 +88,7 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
mDownload = (TextView) view.findViewById(R.id.download);
mUpload = (TextView) view.findViewById(R.id.upload);
mAnnounceServer = (TextView) view.findViewById(R.id.announce_server);
mVersion = (TextView) view.findViewById(R.id.version);
mExitButton = (TextView) view.findViewById(R.id.drawerActionExit);
view.findViewById(R.id.drawerActionWebGui)
@ -128,6 +132,7 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
if (mActivity.getApi() == null || getActivity() == null || getActivity().isFinishing())
return;
mActivity.getApi().getSystemInfo(this);
mActivity.getApi().getSystemVersion(this);
mActivity.getApi().getConnections(this);
}
@ -166,6 +171,17 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
}
}
/**
* Populates views with status received via {@link RestApi#getSystemInfo}.
*/
@Override
public void onReceiveSystemVersion(RestApi.SystemVersion info) {
if (getActivity() == null)
return;
mVersion.setText(info.version);
}
/**
* Populates views with status received via {@link RestApi#getConnections}.
*/

View file

@ -11,6 +11,10 @@ import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
import com.google.gson.annotations.SerializedName;
import com.nutomic.syncthingandroid.BuildConfig;
import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.activities.RestartActivity;
@ -82,6 +86,19 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
public long sys;
}
public static class SystemVersion {
@SerializedName("arch")
public String architecture;
@SerializedName("codename")
public String codename;
@SerializedName("longVersion")
public String longVersion;
@SerializedName("os")
public String os;
@SerializedName("version")
public String version;
}
public static class Folder implements Serializable {
public String path;
public String label;
@ -423,6 +440,13 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
public void onReceiveSystemInfo(SystemInfo info);
}
/**
* Result listener for {@link #getSystemVersion(OnReceiveSystemVersionListener)}.
*/
public interface OnReceiveSystemVersionListener {
void onReceiveSystemVersion(SystemVersion version);
}
/**
* Requests and parses information about current system status and resource usage.
*
@ -459,6 +483,29 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
}.execute(mUrl, GetTask.URI_SYSTEM, mApiKey);
}
/**
* Requests and parses system version information.
*
* @param listener Callback invoked when the result is received.
*/
public void getSystemVersion(final OnReceiveSystemVersionListener listener) {
new GetTask(mHttpsCertPath) {
@Override
protected void onPostExecute(String response) {
if (response == null) {
return;
}
try {
SystemVersion systemVersion = new Gson().fromJson(response, SystemVersion.class);
listener.onReceiveSystemVersion(systemVersion);
} catch (JsonSyntaxException e) {
Log.w(TAG, "Failed to read system info", e);
}
}
}.execute(mUrl, GetTask.URI_VERSION, mApiKey);
}
/**
* Returns a list of all existing folders.
*/

View file

@ -203,6 +203,30 @@
android:textAppearance="@style/TextAppearance.AppCompat.Caption" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="48dp"
android:orientation="vertical"
android:paddingLeft="@dimen/abc_action_bar_content_inset_material"
android:paddingRight="@dimen/abc_action_bar_content_inset_material">
<TextView
android:id="@+id/syncthingVersion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/syncthing_version_title"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="?android:textColorSecondary" />
<TextView
android:id="@+id/version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Caption" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1px"