Browse Source

launch add account when no accounts

tags/0.0.5
Robin Thoni 9 years ago
parent
commit
dddd6deeb8

+ 0
- 8
app/src/main/java/com/rthoni/camotion/business/CamotionAccountBusiness.java View File

@@ -19,10 +19,6 @@ import com.rthoni.camotion.ui.AddAccountActivity;
19 19
  * Created by robin on 11/28/15.
20 20
  */
21 21
 public class CamotionAccountBusiness extends Service {
22
-    /**
23
-     * The tag used for the logs.
24
-     */
25
-    private static final String LOG_TAG = CamotionAccountBusiness.class.getSimpleName();
26 22
 
27 23
     /**
28 24
      * The implementation of the class |AccountAuthenticatorImpl|.
@@ -44,7 +40,6 @@ public class CamotionAccountBusiness extends Service {
44 40
      */
45 41
     @Override
46 42
     public IBinder onBind(Intent intent) {
47
-        Log.v(CamotionAccountBusiness.LOG_TAG, "Binding the service");
48 43
         IBinder ret = null;
49 44
         if (intent.getAction().equals(android.accounts.AccountManager.ACTION_AUTHENTICATOR_INTENT)) {
50 45
             ret = getAuthenticator().getIBinder();
@@ -90,12 +85,9 @@ public class CamotionAccountBusiness extends Service {
90 85
                                  String authTokenType,
91 86
                                  String[] requiredFeatures,
92 87
                                  Bundle options) throws NetworkErrorException {
93
-            Log.d(CamotionAccountBusiness.LOG_TAG, "Adding new account");
94 88
             Bundle reply = new Bundle();
95 89
 
96
-            Log.d(CamotionAccountBusiness.LOG_TAG, "The auth token type is " + authTokenType);
97 90
             Intent i = new Intent(mContext, AddAccountActivity.class);
98
-            i.setAction("com.gowex.pista.addnewaccount");
99 91
             i.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
100 92
             i.putExtra("AuthTokenType", authTokenType);
101 93
             reply.putParcelable(AccountManager.KEY_INTENT, i);

+ 24
- 0
app/src/main/java/com/rthoni/camotion/ui/MainActivity.java View File

@@ -1,8 +1,10 @@
1 1
 package com.rthoni.camotion.ui;
2 2
 
3
+import android.content.Intent;
3 4
 import android.content.res.Configuration;
4 5
 import android.os.Bundle;
5 6
 import android.os.PersistableBundle;
7
+import android.provider.Settings;
6 8
 import android.support.design.widget.NavigationView;
7 9
 import android.support.v4.view.GravityCompat;
8 10
 import android.support.v4.widget.DrawerLayout;
@@ -38,6 +40,10 @@ public class MainActivity extends AppCompatActivity
38 40
     private SubMenu _locationsMenu;
39 41
     private NavigationView _navigationView;
40 42
 
43
+    private int _lastView = -1;
44
+
45
+    private static final int REQUEST_CODE_ADD_ACCOUNT = 0;
46
+
41 47
     @Override
42 48
     protected void onCreate(Bundle savedInstanceState) {
43 49
         super.onCreate(savedInstanceState);
@@ -70,6 +76,15 @@ public class MainActivity extends AppCompatActivity
70 76
     private void init()
71 77
     {
72 78
         List<LocationDbo> locations = CamotionBusiness.getLocations(MainActivity.this);
79
+
80
+        if (locations.isEmpty())
81
+        {
82
+            Intent intent = new Intent(Settings.ACTION_ADD_ACCOUNT);
83
+            intent.putExtra(Settings.EXTRA_AUTHORITIES, new String[]{getResources().getString(R.string.account_type)});
84
+            startActivityForResult(intent, REQUEST_CODE_ADD_ACCOUNT);
85
+            return;
86
+        }
87
+
73 88
         _locationsMenu.clear();
74 89
         if (locations.isEmpty()) {
75 90
             return;
@@ -95,6 +110,15 @@ public class MainActivity extends AppCompatActivity
95 110
 
96 111
     }
97 112
 
113
+    @Override
114
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
115
+        super.onActivityResult(requestCode, resultCode, data);
116
+        if (requestCode == REQUEST_CODE_ADD_ACCOUNT)
117
+        {
118
+            init();
119
+        }
120
+    }
121
+
98 122
     private void setLocation(LocationDbo location)
99 123
     {
100 124
         _currentLocation = location;

+ 1
- 1
app/src/main/res/values/strings.xml View File

@@ -22,7 +22,7 @@
22 22
     <string name="error_username">Username is required</string>
23 23
     <string name="error_password">Password is required</string>
24 24
     <string name="error_domain">Domain is required</string>
25
-    <string name="account_type">com.rthoni.luticate.account</string>
25
+    <string name="account_type">com.rthoni.camotion.account</string>
26 26
 
27 27
     <string name="loading">Loading…</string>
28 28
     <string name="login_progress">Logging in…</string>

+ 1
- 1
app/src/main/res/xml/authenticator.xml View File

@@ -1,6 +1,6 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
3
-                       android:accountType="com.rthoni.luticate.account"
3
+                       android:accountType="@string/account_type"
4 4
                        android:icon="@mipmap/ic_launcher"
5 5
                        android:smallIcon="@mipmap/ic_launcher"
6 6
                        android:label="@string/app_name"

Loading…
Cancel
Save