Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/build
/captures
.externalNativeBuild
*.apk
10 changes: 10 additions & 0 deletions control/src/main/java/com/appmon/control/DeviceListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class DeviceListActivity extends AppCompatActivity implements IDeviceList
IDeviceListPresenter mPresenter;

ListView mListView;
TextView mNoDevicesText;

List<DeviceInfo> mDeviceList;
DeviceListAdapter mListAdapter;

Expand All @@ -38,6 +40,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_device_list);
mListView = (ListView) findViewById(R.id.deviceList);
mNoDevicesText = (TextView) findViewById(R.id.noDevicesText);
mPresenter = new DeviceListPresenter(ModelManager.getInstance()
.getDeviceListModel());
mPresenter.attachView(this);
Expand Down Expand Up @@ -94,6 +97,13 @@ public void openAppList(String deviceId) {
public void updateList(List<DeviceInfo> devices) {
mDeviceList = devices;
mListAdapter.notifyDataSetChanged();
if (mDeviceList.size() == 0) {
mListView.setVisibility(View.GONE);
mNoDevicesText.setVisibility(View.VISIBLE);
} else {
mNoDevicesText.setVisibility(View.GONE);
mListView.setVisibility(View.VISIBLE);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ public void showMessage(Message msg) {
case NETWORK_ERROR:
Toast.makeText(this, R.string.text_network_error, Toast.LENGTH_SHORT).show();
break;
case REAUTH_NEEDED:
Toast.makeText(this, R.string.text_reauth, Toast.LENGTH_SHORT).show();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public class AppListModel implements IAppListModel {
//
// private Map<PresenterOps, DatabaseChildListener> mListenerBridges;
private DatabaseBridgeManager<PresenterOps> mDatabaseBridgeManager;
private IDatabaseService mDatabase;

private String lastUserId = null;

private IAuthService mAuth;
private IDatabaseService mDatabase;

public AppListModel(ICloudServices cloudServices) {
mDatabase = cloudServices.getDatabase();
Expand Down Expand Up @@ -78,10 +78,12 @@ public void onChildRemoved(IDataSnapshot prevSnapshot) {
};
mDatabaseBridgeManager.addListener(getRootPath() + presenter.getDeviceId(), presenter,
listener);
mDatabase.goOnline();
}

@Override
public void removePresenter(PresenterOps presenter) {
mDatabase.goOffline();
mDatabaseBridgeManager.removeListener(presenter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.appmon.shared.IAuthService;
import com.appmon.shared.ICloudServices;
import com.appmon.shared.IDataSnapshot;
import com.appmon.shared.IDatabaseService;
import com.appmon.shared.entities.DeviceInfo;

public class DeviceListModel implements IDeviceListModel {
Expand All @@ -15,9 +16,10 @@ public class DeviceListModel implements IDeviceListModel {
private String lastUserId = null;

private IAuthService mAuth;

private IDatabaseService mDatabase;
public DeviceListModel(ICloudServices cloudServices) {
mDatabaseBridgeManager = new DatabaseBridgeManager<>(cloudServices.getDatabase());
mDatabase = cloudServices.getDatabase();
mDatabaseBridgeManager = new DatabaseBridgeManager<>(mDatabase);
mAuth = cloudServices.getAuth();
}

Expand Down Expand Up @@ -72,11 +74,12 @@ public void onCanceled(DatabaseError error) {
};
// link listener
mDatabaseBridgeManager.addListener(getRootPath(), presenter, listener);

mDatabase.goOnline();
}

@Override
public void removePresenter(PresenterOps presenter) {
mDatabase.goOffline();
mDatabaseBridgeManager.removeListener(presenter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface IResetPasswordListener extends IFallibleListener<ResetPasswordError> {

enum ChangeAppPinError { WEAK_PIN }
enum ChangeClientPinError { WEAK_PIN, INTERNAL_ERROR }
enum ChangePasswordError { WEAK_PASSWORD, INTERNAL_ERROR }
enum ChangePasswordError { WEAK_PASSWORD, REAUTH_NEEDED, INTERNAL_ERROR }
enum RegisterError { WEAK_PASSWORD, INVALID_EMAIL, USER_EXISTS, INTERNAL_ERROR }
enum SignInError {INVALID_EMAIL, WRONG_PASSWORD, INTERNAL_ERROR }
enum ResetPasswordError { INVALID_USER, INTERNAL_ERROR }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ public void onFailure(IUser.ChangePasswordError error) {
case WEAK_PASSWORD:
l.onFail(ChangePasswordError.WEAK_PASSWORD);
break;
case REAUTH_NEEDED:
l.onFail(ChangePasswordError.REAUTH_NEEDED);
break;
default:
l.onFail(ChangePasswordError.INTERNAL_ERROR);
}
Expand Down Expand Up @@ -244,6 +247,7 @@ public void changeClientPin(String pin) {
}
return;
}
mDatabase.goOnline(); // can be turned off by device list model
mDatabase.setValue(mUserRootPath + "pin", pin, new ResultListener<Void, DatabaseError>() {
@Override
public void onSuccess(Void value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public void onFail(IUserModel.ChangePasswordError error) {
case WEAK_PASSWORD:
mView.showInputError(ISettingsView.InputError.WEAK_PASSWORD);
break;
case REAUTH_NEEDED:
mView.showMessage(ISettingsView.Message.REAUTH_NEEDED);
mView.clearFocus();
break;
case INTERNAL_ERROR:
mView.showMessage(ISettingsView.Message.NETWORK_ERROR);
mView.clearFocus();
Expand Down Expand Up @@ -124,10 +128,11 @@ public void changeAppPin(String pin, String pinRepeat) {

@Override
public void changeClientPin(String pin) {
if (mView != null) {
mView.setProgressVisible(true);
mView.clearInputErrors();
}
mModel.changeClientPin(pin);
if (mView == null) return;
mView.setProgressVisible(true);
mView.clearInputErrors();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ enum Message {
APP_PIN_CHANGED,
CLIENT_PIN_CHANGED,
NETWORK_ERROR,
REAUTH_NEEDED,
}

/**
Expand Down
6 changes: 4 additions & 2 deletions control/src/main/res/layout/activity_device_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
<ListView
android:id="@+id/deviceList"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent"
android:visibility="gone"/>
<!-- Centred "No devices" text view-->
<TextView
android:id="@+id/noDevicesText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/text_no_devices"
android:visibility="gone"/>
android:visibility="visible"/>
</FrameLayout>
3 changes: 2 additions & 1 deletion control/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<string name="text_login">Sign in</string>
<string name="text_register">Register</string>
<string name="text_no_devices">No devices</string>
<string name="text_no_devices">No connected devices</string>
<string name="text_app_search">Search applications</string>
<string name="text_change_password">Change password</string>
<string name="text_change_pin">Change pin</string>
Expand Down Expand Up @@ -50,6 +50,7 @@
<string name="text_no_applications">No applications</string>
<string name="text_device_list_sync_error">Device list sync error</string>
<string name="text_app_list_sync_error">App list sync error</string>
<string name="text_reauth">Please sign out and log in again</string>
<string name="enter_pin">Enter pin:</string>
<string name="pin">Pin</string>
</resources>
2 changes: 1 addition & 1 deletion shared/src/main/java/com/appmon/shared/IUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Represents base user account actions.
*/
public interface IUser {
enum ChangePasswordError {WEAK_PASSWORD, INVALID_USER}
enum ChangePasswordError {WEAK_PASSWORD, REAUTH_NEEDED, INTERNAL_ERROR}
/**
* @return current user unique ID. Can't be null.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuthInvalidUserException;
import com.google.firebase.auth.FirebaseAuthRecentLoginRequiredException;
import com.google.firebase.auth.FirebaseAuthWeakPasswordException;

/**
Expand Down Expand Up @@ -41,8 +42,11 @@ public void onComplete(@NonNull Task<Void> task) {
} else {
if (task.getException() instanceof FirebaseAuthWeakPasswordException) {
listener.onFailure(ChangePasswordError.WEAK_PASSWORD);
} else if (task.getException() instanceof FirebaseAuthInvalidUserException) {
listener.onFailure(ChangePasswordError.INVALID_USER);
} else if (task.getException() instanceof
FirebaseAuthRecentLoginRequiredException) {
listener.onFailure(ChangePasswordError.REAUTH_NEEDED);
} else {
listener.onFailure(ChangePasswordError.INTERNAL_ERROR);
}
}
}
Expand Down