Skip to content

Commit

Permalink
Feature: New and improved User Interface
Browse files Browse the repository at this point in the history
- New UI design for various screens.
- Updated icons and images.
- Improved user experience.
- Time zone configuration support for nodes.
- Fixed token authentication issue.
  • Loading branch information
KhushbuShah25 committed Jun 8, 2021
1 parent c54274c commit 51b0fd7
Show file tree
Hide file tree
Showing 225 changed files with 6,256 additions and 3,439 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ For more details :
## Setup

To build this app, you will need a development machine, with Android Studio installed.
Download the source code and open this project in Android Studio.

To get this app please clone this repository using the below command and open this project in Android Studio:
```
git clone https://github.com/espressif/esp-rainmaker-android.git
```
You are now ready to run this demo.

## Features
Expand Down
22 changes: 17 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def defaultTransport = "Both"
def defaultSecurity = "Sec1"
def defaultPoP = ""
def defaultPrefix = "PROV_"
def defaultWiFiScanSrc = "Device"

def defaultAwsRegion = "us-east-1"
def defaultUserPoolId = "us-east-1_kWz4M6MfD"
Expand Down Expand Up @@ -43,7 +44,7 @@ android {
applicationId "com.espressif.rainmaker"
minSdkVersion 23
targetSdkVersion 30
versionCode 16
versionCode 28
versionName "2.3.0 - ${getGitHash()}"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand All @@ -70,6 +71,15 @@ android {
buildConfigField "String", "SECURITY", '"' + security + '"'
}

def wifiScanSrc = localProperties.getProperty("wifiScanSource", defaultWiFiScanSrc)
if (wifiScanSrc == null) {
throw new GradleException("WiFi scan source not found. Define it in the local.properties file.")
} else if (!wifiScanSrc.equalsIgnoreCase("Device") && !wifiScanSrc.equalsIgnoreCase("Phone")) {
throw new GradleException("Invalid 'wifiScanSource' value. Please check 'wifiScanSource' value in local.properties file.")
} else {
buildConfigField "String", "WIFI_SCAN_SRC", '"' + wifiScanSrc + '"'
}

buildConfigField "boolean", "isFilterPrefixEditable", localProperties.getProperty("isFilterPrefixEditable", "true")
buildConfigField "String", "DEVICE_NAME_PREFIX", '"' + localProperties.getProperty("deviceNamePrefix", defaultPrefix) + '"'

Expand Down Expand Up @@ -151,6 +161,7 @@ dependencies {
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.larswerkman:HoloColorPicker:1.5'

implementation 'com.google.protobuf:protobuf-lite:3.0.1'
implementation 'com.google.crypto.tink:tink-android:1.1.0'
Expand All @@ -166,16 +177,17 @@ dependencies {

implementation 'com.aventrix.jnanoid:jnanoid:2.0.0'
implementation 'com.budiyev.android:code-scanner:2.1.0'
implementation 'com.github.espressif:esp-idf-provisioning-android:lib-2.0.8'
implementation 'com.github.espressif:esp-idf-provisioning-android:lib-2.0.9'

implementation 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.22.5'
implementation 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.19.0'
implementation 'com.github.warkiz.tickseekbar:tickseekbar:0.1.4'
implementation('com.amazonaws:aws-android-sdk-iot:2.15.2') { transitive = true }
implementation('com.amazonaws:aws-android-sdk-mobile-client:2.15.2') { transitive = true }

// Room dependencies
implementation 'android.arch.persistence.room:runtime:2.2.6'
annotationProcessor 'android.arch.persistence.room:compiler:2.2.6'
def room_version = "2.3.0"
implementation "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.3.0'
Expand Down
19 changes: 8 additions & 11 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@

<activity
android:name="com.espressif.ui.activities.SplashActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan">
android:theme="@android:style/Theme.NoDisplay">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down Expand Up @@ -111,11 +108,6 @@
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="com.espressif.ui.activities.UserProfileActivity"
android:label="@string/title_activity_settings"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="com.espressif.ui.activities.EspDeviceActivity"
android:label="@string/title_activity_esp_device"
Expand Down Expand Up @@ -154,12 +146,12 @@
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="com.espressif.ui.activities.AddScheduleActivity"
android:label="@string/title_activity_add_device"
android:label="@string/title_activity_add_schedule"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="com.espressif.ui.activities.ScheduleActionsActivity"
android:label="@string/title_activity_add_device"
android:label="@string/title_activity_actions"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
<activity
Expand All @@ -182,6 +174,11 @@
android:label="@string/title_activity_sharing_requests"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="com.espressif.ui.activities.VoiceServicesActivity"
android:label="@string/title_activity_voice_services"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />

</application>

Expand Down
11 changes: 10 additions & 1 deletion app/src/main/java/com/espressif/AppConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class AppConstants {
public static final String HANDLER_RM_CLAIM = "rmaker_claim";

public static final String ESP_PREFERENCES = "Esp_Preferences";
public static final String PREF_FILE_WIFI_NETWORKS = "wifi_networks";
public static final String ESP_DATABASE_NAME = "esp_db";
public static final String NODE_TABLE = "node_table";
public static final String GROUP_TABLE = "group_table";
Expand All @@ -41,7 +42,8 @@ public enum UpdateEventType {
EVENT_DEVICE_ADDED,
EVENT_DEVICE_REMOVED,
EVENT_ADD_DEVICE_TIME_OUT,
EVENT_DEVICE_STATUS_UPDATE
EVENT_DEVICE_STATUS_UPDATE,
EVENT_STATE_CHANGE_UPDATE
}

public static final String CURRENT_VERSION = "v1";
Expand Down Expand Up @@ -73,8 +75,10 @@ public enum UpdateEventType {

// UI Types of Device
public static final String UI_TYPE_TOGGLE = "esp.ui.toggle";
public static final String UI_TYPE_PUSH_BTN_BIG = "esp.ui.push-btn-big";
public static final String UI_TYPE_SLIDER = "esp.ui.slider";
public static final String UI_TYPE_HUE_SLIDER = "esp.ui.hue-slider";
public static final String UI_TYPE_HUE_CIRCLE = "esp.ui.hue-circle";
public static final String UI_TYPE_DROP_DOWN = "esp.ui.dropdown";

// ESP Device Types
Expand Down Expand Up @@ -102,6 +106,7 @@ public enum UpdateEventType {
public static final String PARAM_TYPE_BRIGHTNESS = "esp.param.brightness";
public static final String PARAM_TYPE_TEMPERATURE = "esp.param.temperature";
public static final String PARAM_TYPE_TZ = "esp.param.tz";
public static final String PARAM_TYPE_TZ_POSIX = "esp.param.tz_posix";

// Keys used to pass data between activities and to store data in SharedPreference.
public static final String KEY_DEVICE_NAME_PREFIX = "device_prefix";
Expand All @@ -118,6 +123,7 @@ public enum UpdateEventType {
public static final String KEY_SSID = "ssid";
public static final String KEY_PASSWORD = "password";
public static final String KEY_SECURITY_TYPE = "security_type";
public static final String KEY_SHOULD_SAVE_PWD = "save_password";

// Keys used in JSON responses and used to pass data between activities.
public static final String KEY_NAME = "name";
Expand Down Expand Up @@ -216,4 +222,7 @@ public enum UpdateEventType {
public static final String CAPABILITY_WIFI_SACN = "wifi_scan";
public static final String CAPABILITY_NO_POP = "no_pop";
public static final String CAPABILITY_CLAIM = "claim";

public static final String WIFI_SCAN_FROM_DEVICE = "Device";
public static final String WIFI_SCAN_FROM_PHONE = "Phone";
}
140 changes: 131 additions & 9 deletions app/src/main/java/com/espressif/EspApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,49 @@
package com.espressif;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;

import com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser;
import com.espressif.cloudapi.ApiManager;
import com.espressif.cloudapi.ApiResponseListener;
import com.espressif.db.EspDatabase;
import com.espressif.mdns.mDNSDevice;
import com.espressif.provisioning.ESPProvisionManager;
import com.espressif.rainmaker.BuildConfig;
import com.espressif.ui.models.EspNode;
import com.espressif.ui.models.Group;
import com.espressif.ui.models.Schedule;
import com.espressif.ui.models.UpdateEvent;
import com.espressif.ui.user_module.AppHelper;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;

public class EspApplication extends Application {

private static final String TAG = EspApplication.class.getSimpleName();

private GetDataStatus currentStatus = GetDataStatus.FETCHING_DATA;
private AppState appState = AppState.NO_USER_LOGIN;

public HashMap<String, EspNode> nodeMap;
public HashMap<String, Schedule> scheduleMap;
public HashMap<String, mDNSDevice> mDNSDeviceMap;
public HashMap<String, Group> groupMap;

public enum GetDataStatus {
FETCHING_DATA,
private SharedPreferences appPreferences;
private ApiManager apiManager;

public enum AppState {
NO_USER_LOGIN,
GETTING_DATA,
GET_DATA_SUCCESS,
GET_DATA_FAILED,
DATA_REFRESHING
NO_INTERNET,
REFRESH_DATA
}

@Override
Expand All @@ -53,16 +68,123 @@ public void onCreate() {
scheduleMap = new HashMap<>();
mDNSDeviceMap = new HashMap<>();
groupMap = new HashMap<>();
appPreferences = getSharedPreferences(AppConstants.ESP_PREFERENCES, Context.MODE_PRIVATE);
AppHelper.init(this);
ApiManager.getInstance(this);
apiManager = ApiManager.getInstance(this);
ESPProvisionManager.getInstance(this);
}

public GetDataStatus getCurrentStatus() {
return currentStatus;
public AppState getAppState() {
return appState;
}

public void changeAppState(AppState newState, Bundle extras) {

switch (newState) {
case GETTING_DATA:
case REFRESH_DATA:
if (!appState.equals(newState)) {
appState = newState;
getNodesFromCloud();
}
EventBus.getDefault().post(new UpdateEvent(AppConstants.UpdateEventType.EVENT_STATE_CHANGE_UPDATE));
break;

case GET_DATA_FAILED:
appState = newState;
UpdateEvent updateEvent = new UpdateEvent(AppConstants.UpdateEventType.EVENT_STATE_CHANGE_UPDATE);
if (extras != null) {
updateEvent.setData(extras);
}
EventBus.getDefault().post(updateEvent);
break;

case NO_USER_LOGIN:
case GET_DATA_SUCCESS:
case NO_INTERNET:
appState = newState;
EventBus.getDefault().post(new UpdateEvent(AppConstants.UpdateEventType.EVENT_STATE_CHANGE_UPDATE));
break;
}
}

public void setCurrentStatus(GetDataStatus currentStatus) {
this.currentStatus = currentStatus;
private void getNodesFromCloud() {

apiManager.getNodes(new ApiResponseListener() {

@Override
public void onSuccess(Bundle data) {

if (BuildConfig.isNodeGroupingSupported) {

apiManager.getUserGroups(null, new ApiResponseListener() {

@Override
public void onSuccess(Bundle data) {
changeAppState(AppState.GET_DATA_SUCCESS, null);
}

@Override
public void onResponseFailure(Exception exception) {
Bundle data = new Bundle();
data.putString(AppConstants.KEY_ERROR_MSG, exception.getMessage());
changeAppState(EspApplication.AppState.GET_DATA_FAILED, data);
}

@Override
public void onNetworkFailure(Exception exception) {
changeAppState(AppState.NO_INTERNET, null);
}
});
} else {
changeAppState(AppState.GET_DATA_SUCCESS, null);
}
}

@Override
public void onResponseFailure(Exception exception) {
Bundle data = new Bundle();
data.putString(AppConstants.KEY_ERROR_MSG, exception.getMessage());
changeAppState(EspApplication.AppState.GET_DATA_FAILED, data);
}

@Override
public void onNetworkFailure(Exception exception) {
changeAppState(AppState.NO_INTERNET, null);
}
});
}

public void refreshData() {
if (!appState.equals(AppState.GETTING_DATA)) {
changeAppState(AppState.REFRESH_DATA, null);
}
}

public void logout() {
// Do logout and clear all data
if (!ApiManager.isOAuthLogin) {
String username = AppHelper.getCurrUser();
CognitoUser user = AppHelper.getPool().getUser(username);
user.signOut();
}

EspDatabase.getInstance(this).getNodeDao().deleteAll();
EspDatabase.getInstance(this).getGroupDao().deleteAll();
nodeMap.clear();
scheduleMap.clear();
mDNSDeviceMap.clear();
groupMap.clear();

SharedPreferences.Editor editor = appPreferences.edit();
editor.clear();
editor.apply();

SharedPreferences wifiNetworkPref = getSharedPreferences(AppConstants.PREF_FILE_WIFI_NETWORKS, Context.MODE_PRIVATE);
SharedPreferences.Editor wifiNetworkEditor = wifiNetworkPref.edit();
wifiNetworkEditor.clear();
wifiNetworkEditor.apply();
Log.e(TAG, "Deleted all things from local storage.");
changeAppState(AppState.NO_USER_LOGIN, null);
}
}
Loading

0 comments on commit 51b0fd7

Please sign in to comment.