Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removing event bus + improving listeners #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ dependencies {
implementation 'com.google.crypto.tink:tink-android:1.6.1'
implementation project(path: ':provisioning')

implementation 'org.greenrobot:eventbus:3.3.1'
implementation 'com.github.yuriy-budiyev:code-scanner:2.1.2'
implementation 'com.github.firdausmaulan:AVLoadingIndicatorView:2.3.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,18 @@
import com.espressif.provisioning.ESPConstants;
import com.espressif.provisioning.ESPDevice;
import com.espressif.provisioning.ESPProvisionManager;
import com.espressif.provisioning.listeners.EventUpdateListener;
import com.espressif.provisioning.listeners.QRCodeScanListener;
import com.espressif.wifi_provisioning.R;
import com.google.android.material.card.MaterialCardView;
import com.wang.avi.AVLoadingIndicatorView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

public class AddDeviceActivity extends AppCompatActivity {
public class AddDeviceActivity extends AppCompatActivity implements EventUpdateListener {

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

Expand Down Expand Up @@ -95,8 +93,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
intent = new Intent();
sharedPreferences = getSharedPreferences(AppConstants.ESP_PREFERENCES, Context.MODE_PRIVATE);
provisionManager = ESPProvisionManager.getInstance(getApplicationContext());
provisionManager.addListener(this);
initViews();
EventBus.getDefault().register(this);
}

@Override
Expand Down Expand Up @@ -150,7 +148,6 @@ protected void onPause() {
protected void onDestroy() {

hideLoading();
EventBus.getDefault().unregister(this);
// if (cameraPreview != null) {
// cameraPreview.release();
// }
Expand Down Expand Up @@ -220,8 +217,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}

@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(DeviceConnectionEvent event) {
@Override public void onEvent(DeviceConnectionEvent event) {

Log.d(TAG, "On Device Connection Event RECEIVED : " + event.getEventType());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,17 @@
import com.espressif.provisioning.DeviceConnectionEvent;
import com.espressif.provisioning.ESPConstants;
import com.espressif.provisioning.listeners.BleScanListener;
import com.espressif.provisioning.listeners.EventUpdateListener;
import com.espressif.ui.adapters.BleDeviceListAdapter;
import com.espressif.ui.models.BleDevice;
import com.espressif.ui.utils.Utils;
import com.espressif.wifi_provisioning.BuildConfig;
import com.espressif.wifi_provisioning.R;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.HashMap;

public class BLEProvisionLanding extends ManualProvBaseActivity {
public class BLEProvisionLanding extends ManualProvBaseActivity implements EventUpdateListener {

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

Expand Down Expand Up @@ -198,7 +196,7 @@ public void onRequestPermissionsResult(int requestCode, String permissions[], in
}
}

@Subscribe(threadMode = ThreadMode.MAIN)
@Override
public void onEvent(DeviceConnectionEvent event) {

Log.d(TAG, "ON Device Prov Event RECEIVED : " + event.getEventType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.espressif.provisioning.ESPProvisionManager;
import com.espressif.wifi_provisioning.R;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONException;
import org.json.JSONObject;

Expand All @@ -48,12 +47,10 @@ protected void onCreate(Bundle savedInstanceState) {
securityType = getIntent().getIntExtra(AppConstants.KEY_SECURITY_TYPE, AppConstants.SEC_TYPE_DEFAULT);
provisionManager = ESPProvisionManager.getInstance(getApplicationContext());
sharedPreferences = getSharedPreferences(AppConstants.ESP_PREFERENCES, Context.MODE_PRIVATE);
EventBus.getDefault().register(this);
}

@Override
protected void onDestroy() {
EventBus.getDefault().unregister(this);
super.onDestroy();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,14 @@
import com.espressif.provisioning.DeviceConnectionEvent;
import com.espressif.provisioning.ESPConstants;
import com.espressif.provisioning.ESPProvisionManager;
import com.espressif.provisioning.listeners.EventUpdateListener;
import com.espressif.provisioning.listeners.ResponseListener;
import com.espressif.wifi_provisioning.R;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;

public class ProofOfPossessionActivity extends AppCompatActivity {
public class ProofOfPossessionActivity extends AppCompatActivity implements EventUpdateListener {

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

Expand All @@ -62,8 +60,8 @@ protected void onCreate(Bundle savedInstanceState) {

provisionManager = ESPProvisionManager.getInstance(getApplicationContext());
initViews();
EventBus.getDefault().register(this);

provisionManager.addListener(this);
deviceName = provisionManager.getEspDevice().getDeviceName();

if (!TextUtils.isEmpty(deviceName)) {
Expand All @@ -83,7 +81,7 @@ protected void onCreate(Bundle savedInstanceState) {

@Override
protected void onDestroy() {
EventBus.getDefault().unregister(this);
provisionManager.removeListener(this);
super.onDestroy();
}

Expand All @@ -93,7 +91,7 @@ public void onBackPressed() {
super.onBackPressed();
}

@Subscribe(threadMode = ThreadMode.MAIN)
@Override
public void onEvent(DeviceConnectionEvent event) {

Log.d(TAG, "On Device Connection Event RECEIVED : " + event.getEventType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@

import com.espressif.AppConstants;
import com.espressif.provisioning.DeviceConnectionEvent;
import com.espressif.provisioning.listeners.EventUpdateListener;
import com.espressif.wifi_provisioning.R;
import com.espressif.provisioning.ESPConstants;
import com.espressif.provisioning.ESPProvisionManager;
import com.espressif.provisioning.listeners.ProvisionListener;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class ProvisionActivity extends AppCompatActivity {
public class ProvisionActivity extends AppCompatActivity implements EventUpdateListener {

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

Expand All @@ -66,8 +63,8 @@ protected void onCreate(Bundle savedInstanceState) {
passphraseValue = intent.getStringExtra(AppConstants.KEY_WIFI_PASSWORD);
dataset = intent.getStringExtra(AppConstants.KEY_THREAD_DATASET);
provisionManager = ESPProvisionManager.getInstance(getApplicationContext());
provisionManager.addListener(this);
initViews();
EventBus.getDefault().register(this);

Log.d(TAG, "Selected AP -" + ssidValue);
showLoading();
Expand All @@ -82,12 +79,11 @@ public void onBackPressed() {

@Override
protected void onDestroy() {
EventBus.getDefault().unregister(this);
provisionManager.removeListener(this);
super.onDestroy();
}

@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(DeviceConnectionEvent event) {
@Override public void onEvent(DeviceConnectionEvent event) {

Log.d(TAG, "On Device Connection Event RECEIVED : " + event.getEventType());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@
import com.espressif.AppConstants;
import com.espressif.provisioning.DeviceConnectionEvent;
import com.espressif.provisioning.ESPConstants;
import com.espressif.provisioning.listeners.EventUpdateListener;
import com.espressif.ui.utils.Utils;
import com.espressif.wifi_provisioning.R;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;

public class ProvisionLanding extends ManualProvBaseActivity {
public class ProvisionLanding extends ManualProvBaseActivity implements EventUpdateListener {

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

Expand Down Expand Up @@ -92,8 +91,7 @@ public void onRequestPermissionsResult(int requestCode, String permissions[], in
}
}

@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(DeviceConnectionEvent event) {
@Override public void onEvent(DeviceConnectionEvent event) {

Log.d(TAG, "On Device Prov Event RECEIVED : " + event.getEventType());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,16 @@
import com.espressif.provisioning.ESPConstants;
import com.espressif.provisioning.ESPProvisionManager;
import com.espressif.provisioning.WiFiAccessPoint;
import com.espressif.provisioning.listeners.EventUpdateListener;
import com.espressif.provisioning.listeners.WiFiScanListener;
import com.espressif.ui.utils.Utils;
import com.espressif.wifi_provisioning.R;
import com.google.android.gms.threadnetwork.ThreadNetwork;
import com.google.android.gms.threadnetwork.ThreadNetworkCredentials;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;

public class ThreadConfigActivity extends AppCompatActivity {
public class ThreadConfigActivity extends AppCompatActivity implements EventUpdateListener {

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

Expand All @@ -72,16 +69,15 @@ protected void onCreate(Bundle savedInstanceState) {
handler = new Handler();
threadNetworkList = new ArrayList<>();
provisionManager = ESPProvisionManager.getInstance(getApplicationContext());
provisionManager.addListener(this);
scanCapAvailable = getIntent().getBooleanExtra(AppConstants.KEY_THREAD_SCAN_AVAILABLE, false);

initViews();
EventBus.getDefault().register(this);
getThreadPreferredCredentials();
}

@Override
protected void onDestroy() {
EventBus.getDefault().unregister(this);
provisionManager.removeListener(this);
super.onDestroy();
}

Expand All @@ -91,7 +87,7 @@ public void onBackPressed() {
super.onBackPressed();
}

@Subscribe(threadMode = ThreadMode.MAIN)
@Override
public void onEvent(DeviceConnectionEvent event) {

Log.d(TAG, "On Device Connection Event RECEIVED : " + event.getEventType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@
import com.espressif.provisioning.DeviceConnectionEvent;
import com.espressif.provisioning.ESPConstants;
import com.espressif.provisioning.ESPProvisionManager;
import com.espressif.provisioning.listeners.EventUpdateListener;
import com.espressif.wifi_provisioning.R;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class WiFiConfigActivity extends AppCompatActivity {
public class WiFiConfigActivity extends AppCompatActivity implements EventUpdateListener {

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

Expand All @@ -54,13 +52,13 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_wifi_config);

provisionManager = ESPProvisionManager.getInstance(getApplicationContext());
provisionManager.addListener(this);
initViews();
EventBus.getDefault().register(this);
}

@Override
protected void onDestroy() {
EventBus.getDefault().unregister(this);
provisionManager.removeListener(this);
super.onDestroy();
}

Expand All @@ -70,7 +68,7 @@ public void onBackPressed() {
super.onBackPressed();
}

@Subscribe(threadMode = ThreadMode.MAIN)
@Override
public void onEvent(DeviceConnectionEvent event) {

Log.d(TAG, "On Device Connection Event RECEIVED : " + event.getEventType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,15 @@
import com.espressif.provisioning.ESPConstants;
import com.espressif.provisioning.ESPProvisionManager;
import com.espressif.provisioning.WiFiAccessPoint;
import com.espressif.provisioning.listeners.EventUpdateListener;
import com.espressif.provisioning.listeners.WiFiScanListener;
import com.espressif.ui.adapters.WiFiListAdapter;
import com.espressif.wifi_provisioning.R;
import com.google.android.material.textfield.TextInputLayout;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;

public class WiFiScanActivity extends AppCompatActivity {
public class WiFiScanActivity extends AppCompatActivity implements EventUpdateListener {

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

Expand Down Expand Up @@ -80,6 +77,7 @@ protected void onCreate(Bundle savedInstanceState) {
wifiAPList = new ArrayList<>();
handler = new Handler();
provisionManager = ESPProvisionManager.getInstance(getApplicationContext());
provisionManager.addListener(this);

String deviceName = provisionManager.getEspDevice().getDeviceName();
String wifiMsg = String.format(getString(R.string.setup_instructions), deviceName);
Expand Down Expand Up @@ -116,13 +114,12 @@ public void onLayoutChange(View v, int left, int top, int right, int bottom, int
}
});

EventBus.getDefault().register(this);
startWifiScan();
}

@Override
protected void onDestroy() {
EventBus.getDefault().unregister(this);
provisionManager.removeListener(this);
super.onDestroy();
}

Expand All @@ -132,8 +129,7 @@ public void onBackPressed() {
super.onBackPressed();
}

@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(DeviceConnectionEvent event) {
@Override public void onEvent(DeviceConnectionEvent event) {

Log.d(TAG, "On Device Connection Event RECEIVED : " + event.getEventType());

Expand Down
1 change: 0 additions & 1 deletion provisioning/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'org.greenrobot:eventbus:3.3.1'
implementation 'com.google.protobuf:protobuf-javalite:3.18.0'
implementation 'com.google.crypto.tink:tink-android:1.6.1'
implementation 'com.google.android.gms:play-services-vision:20.1.3'
Expand Down
Loading