#4 implement_add_device_functionality

Merged
gegham merged 17 commits from implement_add_device_functionality into dev 4 years ago
There is no content yet.
gegham was assigned by musheghsahakyan98 4 years ago
gegham requested changes 4 years ago
@@ -66,0 +70,4 @@
switch (deviceStatusResource.status){
case SUCCESS:
Toast.makeText(LoginActivity.this,"Success",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(LoginActivity.this,MainActivity.class);
gegham commented 4 years ago

No need to open the MainActivity yet. Most probably we will still need to get the VPN.conf before going to the main activity.

No need to open the MainActivity yet. Most probably we will still need to get the VPN.conf before going to the main activity.
@@ -66,0 +75,4 @@
startActivity(intent);
Log.d("TAG","Success");
break;
case LOADING:
gegham commented 4 years ago

We need to have loaders showing during the API calls. Use the same approach as in mytello, with blocking user actions on the screen during the loader showing.

We need to have loaders showing during the API calls. Use the same approach as in mytello, with blocking user actions on the screen during the loader showing.
@@ -66,0 +85,4 @@
}
}
});
// Toast.makeText(LoginActivity.this,"Success",Toast.LENGTH_SHORT).show();
gegham commented 4 years ago

Remove this line.

Remove this line.
@@ -6,2 +7,4 @@
public static final String ADD_DEVICE_URL = "me/devices";
public static final String USERNAME = "username";
public static final String PASSWORD = "password";
public static final String HEADER = "X-Bubble-Session";
gegham commented 4 years ago

Change the name of this property to reflect which exact header it is.

Change the name of this property to reflect which exact header it is.
@@ -86,0 +246,4 @@
return Character.isUpperCase(first) ? brand : Character.toUpperCase(first) + brand.substring(1);
}

private String getDeviceIMEI(final Context context) {
gegham commented 4 years ago

Rename, tp reflect the method correctly.

Rename, tp reflect the method correctly.
gegham requested changes 4 years ago
@@ -71,6 +75,151 @@ public class DataRepository {
}.getMutableLiveData();
}

public MutableLiveData<StatusResource<Device>> getAllDevices(Context context) {
gegham commented 4 years ago

There should be 3 methods for devices:
getAllDevices(): we already have this. It should fetch all the devices from the API.
addDevice(): This method should add a new device to API. It should not deal with anything but adding a device.
getDevice(): This should be the method called from the LoginActivity. It should:
1. Check if there is an existing device in shared prefs, then just return it.
2. If there is no device, then make the getAllDevices call, and then the addDevice call, with the logic that we already have.

So the Login activity and it’s ViewModel shouldn’t be aware if the device was created or it already existed.

There should be 3 methods for devices: getAllDevices(): we already have this. It should fetch all the devices from the API. addDevice(): This method should add a new device to API. It should not deal with anything but adding a device. getDevice(): This should be the method called from the LoginActivity. It should: 1. Check if there is an existing device in shared prefs, then just return it. 2. If there is no device, then make the getAllDevices call, and then the addDevice call, with the logic that we already have. So the Login activity and it's ViewModel shouldn't be aware if the device was created or it already existed.
gegham requested changes 4 years ago
@@ -71,6 +75,154 @@ public class DataRepository {
}.getMutableLiveData();
}

gegham commented 4 years ago

login() -> isDeviceLoggedIn() -> getAllDevices ->
-> getVPNConf()
-> addDevice() -> getVPNConf()
-> createTunnel() -> SUCCESS -> LoginActivity -> MainActivity

login() -> isDeviceLoggedIn() -> getAllDevices -> -> getVPNConf() -> addDevice() -> getVPNConf() -> createTunnel() -> SUCCESS -> LoginActivity -> MainActivity
gegham requested changes 4 years ago
@@ -73,3 +73,3 @@
</intent-filter>
</activity>
<activity android:name=".activity.BaseActivityBubble" />
gegham commented 4 years ago

Do we need to have the BaseActivity in Manifest?

Do we need to have the BaseActivity in Manifest?
@@ -0,0 +32,4 @@
final Dialog dialog = new Dialog(getActivity(), getTheme()) {
@Override
public void onBackPressed() {
if (getActivity().getSupportFragmentManager().findFragmentByTag(LoginActivity.LOADING_TAG) != null) {
gegham commented 4 years ago

Why is the LoginActivity.LOADING_TAG used here?

Why is the LoginActivity.LOADING_TAG used here?
@@ -74,0 +128,4 @@
final String brand = getBrand();
final String model = getDeviceModel();
final String imei = getDeviceID(context);
final String deviceName = brand + " " + model + " " + ":" + " " + imei;
gegham commented 4 years ago

Put all the hardcoded strings in constants: " “, " : "

Put all the hardcoded strings in constants: " ", " : "
@@ -74,0 +138,4 @@
String brandModel = brand + " " + model + " ";
final List<Device> list = response.body();
final List<String> arrayListDevicesName = new ArrayList<>();
boolean flag = true;
gegham commented 4 years ago

Rename the boolean

Rename the boolean
@@ -74,0 +142,4 @@
for (final Device device : list) {
final String[] deviceNameItem = device.getName().split(":");
final String[] myDeviceName = deviceName.split(":");
if(deviceNameItem.length>1){
gegham commented 4 years ago

Check only the IMEI ( Android ID ) with equals

Check only the IMEI ( Android ID ) with equals
@@ -74,0 +143,4 @@
final String[] deviceNameItem = device.getName().split(":");
final String[] myDeviceName = deviceName.split(":");
if(deviceNameItem.length>1){
if(deviceNameItem[0].contains(myDeviceName[0]) && deviceNameItem[1].contains(myDeviceName[1])){
gegham commented 4 years ago

Change magic numbers to constants

Change magic numbers to constants
@@ -74,0 +247,4 @@
}.getMutableLiveData();
}

private MutableLiveData<List<Device>> getAllDevices(Context context){
gegham commented 4 years ago

Do we need LIveData here?

Do we need LIveData here?
gegham requested changes 4 years ago
@@ -66,0 +83,4 @@
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(listDevices->{
boolean flag = true;
gegham commented 4 years ago

Rename the flag boolean

Rename the flag boolean
@@ -66,0 +115,4 @@
String brandModel = brand + SPACE + model + SPACE;
final List<Device> list = listDevices;
final List<String> arrayListDevicesName = new ArrayList<>();
boolean isHaveDevice = false;
gegham commented 4 years ago

Rename isHaveDevice to hasDevice

Rename isHaveDevice to hasDevice
@@ -66,0 +142,4 @@
brandModel = deviceName;
final HashMap<String, String> body = new HashMap<>();
body.put(ApiConstants.DEVICE_NAME, brandModel);
body.put(ApiConstants.DEVICE_TYPE, "android");
gegham commented 4 years ago

Rename disposable2 and disposable properties accordingly

Rename disposable2 and disposable properties accordingly
gegham approved these changes 4 years ago
gegham closed this pull request 4 years ago
gegham deleted branch implement_add_device_functionality 4 years ago

Reviewers

gegham approved these changes 4 years ago
The pull request has been merged as 7dd33ca862.
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

This pull request currently doesn't have any dependencies.

Loading…
There is no content yet.