mirror of
https://github.com/syncthing/syncthing-android.git
synced 2025-01-11 04:25:53 +00:00
Fixed dialogs not shown in MainActivity, added MainActivityTest.
This commit is contained in:
parent
1ed4db8684
commit
1653d409ec
3 changed files with 57 additions and 0 deletions
|
@ -0,0 +1,26 @@
|
|||
package com.nutomic.syncthingandroid.test;
|
||||
|
||||
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class MockSyncthingService extends SyncthingService {
|
||||
|
||||
private LinkedList<OnApiChangeListener> mOnApiChangedListeners = new LinkedList<>();
|
||||
|
||||
@Override
|
||||
public void registerOnApiChangeListener(OnApiChangeListener listener) {
|
||||
mOnApiChangedListeners.add(listener);
|
||||
}
|
||||
|
||||
public boolean containsListenerInstance(Class clazz) {
|
||||
for(OnApiChangeListener l : mOnApiChangedListeners) {
|
||||
if (l.getClass().equals(clazz)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.nutomic.syncthingandroid.test.activities;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import com.nutomic.syncthingandroid.activities.MainActivity;
|
||||
import com.nutomic.syncthingandroid.fragments.NodesFragment;
|
||||
import com.nutomic.syncthingandroid.fragments.ReposFragment;
|
||||
import com.nutomic.syncthingandroid.syncthing.SyncthingServiceBinder;
|
||||
import com.nutomic.syncthingandroid.test.MockSyncthingService;
|
||||
|
||||
public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {
|
||||
|
||||
private MockSyncthingService mService = new MockSyncthingService();
|
||||
|
||||
public MainActivityTest() {
|
||||
super(MainActivity.class);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testOnServiceConnected() {
|
||||
getActivity().onServiceConnected(null, new SyncthingServiceBinder(mService));
|
||||
assertTrue(mService.containsListenerInstance(MainActivity.class));
|
||||
assertTrue(mService.containsListenerInstance(ReposFragment.class));
|
||||
assertTrue(mService.containsListenerInstance(NodesFragment.class));
|
||||
}
|
||||
|
||||
}
|
|
@ -20,6 +20,7 @@ import android.support.v4.widget.DrawerLayout;
|
|||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBar.Tab;
|
||||
import android.support.v7.app.ActionBar.TabListener;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
@ -47,6 +48,7 @@ public class MainActivity extends SyncthingActivity
|
|||
@Override
|
||||
@SuppressLint("InflateParams")
|
||||
public void onApiChange(SyncthingService.State currentState) {
|
||||
Log.d("MainActivity", currentState.toString());
|
||||
if (currentState != SyncthingService.State.ACTIVE && !isFinishing()) {
|
||||
if (currentState == SyncthingService.State.DISABLED) {
|
||||
if (mLoadingDialog != null) {
|
||||
|
@ -205,6 +207,7 @@ public class MainActivity extends SyncthingActivity
|
|||
@Override
|
||||
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
||||
super.onServiceConnected(componentName, iBinder);
|
||||
getService().registerOnApiChangeListener(this);
|
||||
getService().registerOnApiChangeListener(mRepositoriesFragment);
|
||||
getService().registerOnApiChangeListener(mNodesFragment);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue