mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-26 22:31:16 +00:00
Fixed crash on screen rotate and drawer not refreshing after screen rotate.
This commit is contained in:
parent
9d041d0bb3
commit
0984ba1b2d
2 changed files with 34 additions and 14 deletions
|
@ -64,16 +64,7 @@ public class LocalNodeInfoFragment extends Fragment
|
||||||
@Override
|
@Override
|
||||||
public void onDrawerOpened(View drawerView) {
|
public void onDrawerOpened(View drawerView) {
|
||||||
super.onDrawerOpened(drawerView);
|
super.onDrawerOpened(drawerView);
|
||||||
mTimer = new Timer();
|
LocalNodeInfoFragment.this.onDrawerOpened();
|
||||||
mTimer.schedule(new TimerTask() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateGui();
|
|
||||||
}
|
|
||||||
|
|
||||||
}, 0, SyncthingService.GUI_UPDATE_INTERVAL);
|
|
||||||
mActivity.getSupportActionBar().setTitle(R.string.system_info);
|
|
||||||
mActivity.supportInvalidateOptionsMenu();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -94,6 +85,29 @@ public class LocalNodeInfoFragment extends Fragment
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
mActivity = (MainActivity) getActivity();
|
mActivity = (MainActivity) getActivity();
|
||||||
|
|
||||||
|
if (savedInstanceState != null && savedInstanceState.getBoolean("active")) {
|
||||||
|
onDrawerOpened();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
outState.putBoolean("active", mTimer != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onDrawerOpened() {
|
||||||
|
mTimer = new Timer();
|
||||||
|
mTimer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
updateGui();
|
||||||
|
}
|
||||||
|
|
||||||
|
}, 0, SyncthingService.GUI_UPDATE_INTERVAL);
|
||||||
|
mActivity.getSupportActionBar().setTitle(R.string.system_info);
|
||||||
|
mActivity.supportInvalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -119,6 +133,9 @@ public class LocalNodeInfoFragment extends Fragment
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onReceiveSystemInfo(RestApi.SystemInfo info) {
|
public void onReceiveSystemInfo(RestApi.SystemInfo info) {
|
||||||
|
if (getActivity() == null)
|
||||||
|
return;
|
||||||
|
|
||||||
mNodeId.setText(info.myID);
|
mNodeId.setText(info.myID);
|
||||||
mCpuUsage.setText(new DecimalFormat("0.00").format(info.cpuPercent) + "%");
|
mCpuUsage.setText(new DecimalFormat("0.00").format(info.cpuPercent) + "%");
|
||||||
mRamUsage.setText(RestApi.readableFileSize(mActivity, info.sys));
|
mRamUsage.setText(RestApi.readableFileSize(mActivity, info.sys));
|
||||||
|
|
|
@ -13,6 +13,7 @@ import android.os.IBinder;
|
||||||
import android.support.v4.app.ActionBarDrawerToggle;
|
import android.support.v4.app.ActionBarDrawerToggle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
|
import android.support.v4.app.FragmentPagerAdapter;
|
||||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
|
@ -21,9 +22,11 @@ import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.app.ActionBar.Tab;
|
import android.support.v7.app.ActionBar.Tab;
|
||||||
import android.support.v7.app.ActionBar.TabListener;
|
import android.support.v7.app.ActionBar.TabListener;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.view.OrientationEventListener;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
|
@ -91,8 +94,8 @@ public class MainActivity extends ActionBarActivity
|
||||||
getSupportActionBar().setHomeButtonEnabled(true);
|
getSupportActionBar().setHomeButtonEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final FragmentStatePagerAdapter mSectionsPagerAdapter =
|
private final FragmentPagerAdapter mSectionsPagerAdapter =
|
||||||
new FragmentStatePagerAdapter(getSupportFragmentManager()) {
|
new FragmentPagerAdapter(getSupportFragmentManager()) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Fragment getItem(int position) {
|
public Fragment getItem(int position) {
|
||||||
|
@ -216,7 +219,8 @@ public class MainActivity extends ActionBarActivity
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
// Avoid crash if called during startup.
|
// Avoid crash if called during startup.
|
||||||
if (mRepositoriesFragment != null && mNodesFragment != null) {
|
if (mRepositoriesFragment != null && mNodesFragment != null &&
|
||||||
|
mLocalNodeInfoFragment != null) {
|
||||||
FragmentManager fm = getSupportFragmentManager();
|
FragmentManager fm = getSupportFragmentManager();
|
||||||
fm.putFragment(outState, ReposFragment.class.getName(), mRepositoriesFragment);
|
fm.putFragment(outState, ReposFragment.class.getName(), mRepositoriesFragment);
|
||||||
fm.putFragment(outState, NodesFragment.class.getName(), mNodesFragment);
|
fm.putFragment(outState, NodesFragment.class.getName(), mNodesFragment);
|
||||||
|
@ -297,5 +301,4 @@ public class MainActivity extends ActionBarActivity
|
||||||
? mSyncthingService.getApi()
|
? mSyncthingService.getApi()
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue