Skip to content

Commit

Permalink
network: redesign (#650)
Browse files Browse the repository at this point in the history
  • Loading branch information
dogi authored Mar 4, 2020
1 parent b1541b8 commit 309dc08
Show file tree
Hide file tree
Showing 38 changed files with 1,008 additions and 789 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/io/treehouses/remote/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class Constants {
public static final int REQUEST_DIALOG_FRAGMENT_HOTSPOT = 5;
public static final int REQUEST_DIALOG_FRAGMENT_CHPASS = 6;
public static final int REQUEST_DIALOG_FRAGMENT_ADD_COMMAND = 7;
public static final int REQUEST_DIALOG_WIFI = 8;
public static final int NETWORK_BOTTOM_SHEET = 9;

// Constants that indicate the current connection state (use in BluetoothChatService)
public static final int STATE_NONE = 0; // we're doing nothing
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package io.treehouses.remote.Fragments.DialogFragments.BottomSheetDialogs;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.text.InputType;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.google.android.material.bottomsheet.BottomSheetDialogFragment;

import io.treehouses.remote.Constants;
import io.treehouses.remote.Fragments.DialogFragments.WifiDialogFragment;
import io.treehouses.remote.R;
import io.treehouses.remote.bases.BaseBottomSheetDialog;
import io.treehouses.remote.callback.HomeInteractListener;
import io.treehouses.remote.pojo.NetworkProfile;
import io.treehouses.remote.utils.SaveUtils;

import static io.treehouses.remote.Fragments.NewNetworkFragment.CLICKED_START_CONFIG;
import static io.treehouses.remote.Fragments.NewNetworkFragment.openWifiDialog;

public class BridgeBottomSheet extends BaseBottomSheetDialog {

private EditText essid, password, hotspotEssid, hotspotPassword;
private Button startConfig, addProfile, btnWifiSearch;


@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.dialog_bridge, container, false);

essid = v.findViewById(R.id.et_essid);
password = v.findViewById(R.id.et_password);
hotspotEssid = v.findViewById(R.id.et_hotspot_essid);
hotspotPassword = v.findViewById(R.id.et_hotspot_password);

startConfig = v.findViewById(R.id.btn_start_config);
addProfile = v.findViewById(R.id.add_bridge_profile);
btnWifiSearch = v.findViewById(R.id.btnWifiSearch);

try {
essid.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
hotspotEssid.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
} catch (Exception e) {
e.printStackTrace();
}

startConfigListener();
setAddProfileListener();

btnWifiSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openWifiDialog(BridgeBottomSheet.this, context);
}
});

return v;
}

private void startConfigListener() {
startConfig.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String temp = "treehouses bridge \"" + essid.getText().toString() + "\" \"" + hotspotEssid.getText().toString() + "\" ";
String overallMessage = TextUtils.isEmpty(password.getText().toString()) ? temp + "\"\"" : temp + "\"" + password.getText().toString() + "\"";
overallMessage += " ";

if (!TextUtils.isEmpty(hotspotPassword.getText().toString())) {
overallMessage += "\"" + hotspotPassword.getText().toString() + "\"";
}
listener.sendMessage(overallMessage);

Toast.makeText(context, "Connecting...", Toast.LENGTH_LONG).show();
Intent intent = new Intent();
intent.putExtra(CLICKED_START_CONFIG, true);
getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, intent);
dismiss();
}
});
}

private void setAddProfileListener() {
addProfile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NetworkProfile networkProfile = new NetworkProfile(essid.getText().toString(), password.getText().toString(),
hotspotEssid.getText().toString(), hotspotPassword.getText().toString());

SaveUtils.addProfile(context, networkProfile);
Toast.makeText(context, "Bridge Profile Added", Toast.LENGTH_LONG).show();
}
});
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if( resultCode != Activity.RESULT_OK ) {
return;
}
if( requestCode == Constants.REQUEST_DIALOG_WIFI ) {
String ssid = data.getStringExtra(WifiDialogFragment.WIFI_SSID_KEY);
essid.setText(ssid);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package io.treehouses.remote.Fragments.DialogFragments.BottomSheetDialogs;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import androidx.annotation.Nullable;

import com.google.android.material.bottomsheet.BottomSheetDialogFragment;

import io.treehouses.remote.R;
import io.treehouses.remote.bases.BaseBottomSheetDialog;
import io.treehouses.remote.callback.HomeInteractListener;

import static io.treehouses.remote.Fragments.NewNetworkFragment.CLICKED_START_CONFIG;

public class EthernetBottomSheet extends BaseBottomSheetDialog {

private EditText etIP, etMask, etGateway, DNSText;
private Button startConfig;

@Nullable
@Override

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.dialog_ethernet, container, false);
etIP = v.findViewById(R.id.ip);
etMask = v.findViewById(R.id.mask);
etGateway = v.findViewById(R.id.gateway);
DNSText = v.findViewById(R.id.dns);

startConfig = v.findViewById(R.id.btn_start_config);

startConfig.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String ip = etIP.getText().toString();
String dns = DNSText.getText().toString();
String gateway = etGateway.getText().toString();
String mask = etMask.getText().toString();
listener.sendMessage(String.format("treehouses ethernet %s %s %s %s", ip, mask, gateway, dns));
Intent intent = new Intent();
intent.putExtra(CLICKED_START_CONFIG, true);
getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, intent);
dismiss();
}
});
return v;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package io.treehouses.remote.Fragments.DialogFragments.BottomSheetDialogs;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.google.android.material.bottomsheet.BottomSheetDialogFragment;

import io.treehouses.remote.R;
import io.treehouses.remote.bases.BaseBottomSheetDialog;
import io.treehouses.remote.callback.HomeInteractListener;
import io.treehouses.remote.pojo.NetworkProfile;
import io.treehouses.remote.utils.SaveUtils;

import static io.treehouses.remote.Fragments.NewNetworkFragment.CLICKED_START_CONFIG;

public class HotspotBottomSheet extends BaseBottomSheetDialog {
private EditText essidText;
private EditText passwordText;
private Button startConfig, addProfile;
private Spinner spinner;

@Nullable
@Override

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.dialog_hotspot, container, false);

essidText = v.findViewById(R.id.et_hotspot_ssid);
passwordText = v.findViewById(R.id.et_hotspot_password);
startConfig = v.findViewById(R.id.btn_start_config);
addProfile = v.findViewById(R.id.set_hotspot_profile);

spinner = v.findViewById(R.id.spn_hotspot_type);

startConfigListener();

setAddProfileListener();
return v;
}

private void startConfigListener() {
startConfig.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (passwordText.getText().toString().isEmpty()) {
listener.sendMessage("treehouses ap \"" + spinner.getSelectedItem().toString() + "\" \"" + essidText.getText().toString() + "\"");
Toast.makeText(context, "Connecting...", Toast.LENGTH_LONG).show();
} else {
listener.sendMessage("treehouses ap \"" + spinner.getSelectedItem().toString() + "\" \"" + essidText.getText().toString() + "\" \"" + passwordText.getText().toString() + "\"");
Toast.makeText(context, "Connecting...", Toast.LENGTH_LONG).show();
}
Intent intent = new Intent();
intent.putExtra(CLICKED_START_CONFIG, true);
getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, intent);
dismiss();
}
});
}

private void setAddProfileListener() {
addProfile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SaveUtils.addProfile(context, new NetworkProfile(essidText.getText().toString(), passwordText.getText().toString(), spinner.getSelectedItem().toString()));
Toast.makeText(context, "Hotspot Profile Saved", Toast.LENGTH_LONG).show();
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package io.treehouses.remote.Fragments.DialogFragments.BottomSheetDialogs;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.google.android.material.bottomsheet.BottomSheetDialogFragment;

import io.treehouses.remote.Constants;
import io.treehouses.remote.Fragments.DialogFragments.WifiDialogFragment;
import io.treehouses.remote.R;
import io.treehouses.remote.bases.BaseBottomSheetDialog;
import io.treehouses.remote.pojo.NetworkProfile;
import io.treehouses.remote.utils.SaveUtils;

import static io.treehouses.remote.Fragments.NewNetworkFragment.CLICKED_START_CONFIG;
import static io.treehouses.remote.Fragments.NewNetworkFragment.openWifiDialog;


public class WifiBottomSheet extends BaseBottomSheetDialog {

private EditText ssidText;
private EditText passwordText;
private Button startConfig, addProfile, searchWifi;

@Nullable
@Override

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.dialog_wifi, container, false);
ssidText = v.findViewById(R.id.editTextSSID);
passwordText = v.findViewById(R.id.wifipassword);
startConfig = v.findViewById(R.id.btn_start_config);
addProfile = v.findViewById(R.id.set_wifi_profile);
searchWifi = v.findViewById(R.id.btnWifiSearch);

setStartConfigListener();

setAddProfileListener();

searchWifi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openWifiDialog(WifiBottomSheet.this, context);

}
});

return v;
}

private void setStartConfigListener() {
startConfig.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String ssid = ssidText.getText().toString();
String password = passwordText.getText().toString();
listener.sendMessage(String.format("treehouses wifi \"%s\" \"%s\"", ssid, password));
Toast.makeText(context, "Connecting...", Toast.LENGTH_LONG).show();
Intent intent = new Intent();
intent.putExtra(CLICKED_START_CONFIG, true);
getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, intent);
dismiss();
}
});
}

private void setAddProfileListener() {
addProfile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SaveUtils.addProfile(context, new NetworkProfile(ssidText.getText().toString(), passwordText.getText().toString()));
Toast.makeText(context, "WiFi Profile Saved", Toast.LENGTH_LONG).show();
}
});
}


@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if((resultCode == Activity.RESULT_OK) && (requestCode == Constants.REQUEST_DIALOG_WIFI) ) {
ssidText.setText(data.getStringExtra(WifiDialogFragment.WIFI_SSID_KEY));
}
}

@Override
public void onDismiss(final DialogInterface dialogInterface) {

}

}
Loading

0 comments on commit 309dc08

Please sign in to comment.