Skip to content

Commit

Permalink
Android: Fixed bugs in Dropbox Sync prototype.
Browse files Browse the repository at this point in the history
Related to issue #406.
  • Loading branch information
ycastonguay committed Oct 16, 2013
1 parent 208b9d7 commit 1d55763
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions MPfm/MPfm.Android/Classes/Activities/SyncCloudActivity.cs
Expand Up @@ -38,7 +38,7 @@
namespace MPfm.Android
{
[Activity(Label = "Sync (Cloud)", ScreenOrientation = ScreenOrientation.Sensor, Theme = "@style/MyAppTheme", ConfigurationChanges = ConfigChanges.KeyboardHidden | ConfigChanges.Orientation | ConfigChanges.ScreenSize)]
public class SyncCloudActivity : BaseActivity, ISyncCloudView, DbxDatastore.ISyncStatusListener
public class SyncCloudActivity : BaseActivity, ISyncCloudView, DbxDatastore.ISyncStatusListener, DbxAccountManager.IAccountListener
{
private MobileNavigationManager _navigationManager;
private ISyncDeviceSpecifications _syncDeviceSpecifications;
Expand All @@ -63,10 +63,17 @@ protected override void OnCreate(Bundle bundle)
string appKey = "6tc6565743i743n";
string appSecret = "fbkt3neevjjl0l2";
_accountManager = DbxAccountManager.GetInstance(ApplicationContext, appKey, appSecret);
_accountManager.AddListener(this);

if (_accountManager.HasLinkedAccount)
_account = _accountManager.LinkedAccount;

if (_account != null)
{
_store = DbxDatastore.OpenDefault(_account);
_store.AddSyncStatusListener(this);
}

_syncDeviceSpecifications = Bootstrapper.GetContainer().Resolve<ISyncDeviceSpecifications>();
_navigationManager = Bootstrapper.GetContainer().Resolve<MobileNavigationManager>();
SetContentView(Resource.Layout.SyncCloud);
Expand Down Expand Up @@ -104,6 +111,7 @@ private void BtnLoginOnClick(object sender, EventArgs e)
else
{
_accountManager.StartLink(this, 0);

}
_lblConnected.Text = string.Format("Is Linked: {0} {1}", _accountManager.HasLinkedAccount, DateTime.Now.ToLongTimeString());
}
Expand Down Expand Up @@ -251,24 +259,29 @@ protected override void OnResume()
{
Console.WriteLine("SyncCloudActivity - OnResume");
base.OnResume();

_store = DbxDatastore.OpenDefault(_account);
_store.AddSyncStatusListener(this);
}

protected override void OnStop()
{
Console.WriteLine("SyncCloudActivity - OnStop");
base.OnStop();

_store.RemoveSyncStatusListener(this);
_store.Close();
}

protected override void OnDestroy()
{
Console.WriteLine("SyncCloudActivity - OnDestroy");
base.OnDestroy();

if (_accountManager != null)
{
_accountManager.RemoveListener(this);
}

if (_store != null)
{
_store.RemoveSyncStatusListener(this);
_store.Close();
}
}

public override bool OnOptionsItemSelected(IMenuItem item)
Expand Down Expand Up @@ -317,6 +330,13 @@ public void OnDatastoreStatusChange(DbxDatastore store)
}
}

public void OnLinkedAccountChange(DbxAccountManager accountManager, DbxAccount account)
{
Console.WriteLine("SyncCloudActivity - OnLinkedAccountChange");
_account = account.IsLinked ? account : null;
_lblConnected.Text = string.Format("Is Linked: {0} {1}", _accountManager.HasLinkedAccount, DateTime.Now.ToLongTimeString());
}

#region ISyncCloudView implementation

public void SyncCloudError(Exception ex)
Expand Down

0 comments on commit 1d55763

Please sign in to comment.