Skip to content

Commit

Permalink
status page treehouses upgrade (fixes #190) (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sriharsha-Singam authored and dogi committed Feb 28, 2019
1 parent 2649ec0 commit c7d4007
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 108 deletions.
155 changes: 50 additions & 105 deletions app/src/main/java/io/treehouses/remote/Fragments/StatusFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.treehouses.remote.R;

import android.app.Fragment;
import android.app.ProgressDialog;
import android.bluetooth.BluetoothAdapter;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
Expand Down Expand Up @@ -79,47 +80,18 @@ public StatusFragment(){}

Boolean wifiStatusVal = false;

Button upgrade;

ProgressDialog pd;

Boolean updateRightNow = false;

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

// ArrayList<String> list = new ArrayList<String>();
// list.add("Bluetooth RPI Connection");
// list.add("RPI Wifi Connection:");
// list.add("Connected RPI Name:");
// list.add("RPI Type:");
// list.add("Upgrade Status:");
//
// ArrayList<Drawable> list1 = new ArrayList<Drawable>();
// list1.add(getResources().getDrawable(R.drawable.tick));
// list1.add("RPI Wifi Connection:");
// list1.add("Connected RPI Name:");
// list1.add("RPI Type:");
// list1.add("Upgrade Status:");
//
// ListView listView = view.findViewById(R.id.listView);
//// ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, list);
// ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.cardlist, R.id.tvStatus, list, R.id.ivStatus, list1);
// listView.setAdapter(adapter);

btStatus = view.findViewById(R.id.btStatus);
wifiStatus = view.findViewById(R.id.wifiStatus);
btRPIName = view.findViewById(R.id.rpiName);
rpiType = view.findViewById(R.id.rpiType);
ivUpgrad = view.findViewById(R.id.upgradeCheck);


tvStatus = view.findViewById(R.id.tvStatus);
tvStatus1 = view.findViewById(R.id.tvStatus1);
tvStatus2 = view.findViewById(R.id.tvStatus2);
tvStatus3 = view.findViewById(R.id.tvStatus3);
tvUpgrade = view.findViewById(R.id.tvUpgradeCheck);

// allButtons.add(btStatus);
// allButtons.add(wifiStatus);
// allButtons.add(btRPIName);
// allButtons.add(rpiType);
initializeUIElements(view);

InitialActivity initialActivity = new InitialActivity();
BluetoothChatService chatService = initialActivity.getChatService();
Expand All @@ -133,82 +105,42 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
btStatus.setImageDrawable(getResources().getDrawable(R.drawable.tick));
}
checkStatusNow(view);
// String ping = "ping -c 1 google.com";
// byte[] pSend = ping.getBytes();
// mChatService.write(pSend);




String ping = "treehouses detectrpi";
byte[] pSend1 = ping.getBytes();
mChatService.write(pSend1);

// final Handler h = new Handler();
// final int delay = 20000;
// h.postDelayed(new Runnable(){
// public void run(){
String ping = "treehouses detectrpi";
byte[] pSend1 = ping.getBytes();
mChatService.write(pSend1);
//// h.postDelayed(this, delay);
// }
// }, delay);

// final Handler h1 = new Handler();
// final int delay1 = 20000;
// h1.postDelayed(new Runnable(){
// public void run(){
// String ping1 = "treehouses internet";
// byte[] pSend2 = ping1.getBytes();
// mChatService.write(pSend2);
// h1.postDelayed(this, delay1);
// }
// }, delay1);

// Log.e("PROCESSING", ""+processing);
//// while(processing){System.out.print("-");}
//// Log.e("PROCESSING", ""+processing);
// for(int i = 0; i < 1000; i++){System.out.print("-");}
// Log.e("INCOMING MESSAGE", ""+processedMessage);


// for(int i = 0; i < 1000; i++){System.out.print("-");}
// String ping2 = "treehouses rebootneeded";
// byte[] pSend3 = ping2.getBytes();
// mChatService.write(pSend3);
return view;
}

// initialActivity.sendMessage("treehouses detectrpi");
public void initializeUIElements(View view){
btStatus = view.findViewById(R.id.btStatus);
wifiStatus = view.findViewById(R.id.wifiStatus);
btRPIName = view.findViewById(R.id.rpiName);
rpiType = view.findViewById(R.id.rpiType);
ivUpgrad = view.findViewById(R.id.upgradeCheck);


return view;
tvStatus = view.findViewById(R.id.tvStatus);
tvStatus1 = view.findViewById(R.id.tvStatus1);
tvStatus2 = view.findViewById(R.id.tvStatus2);
tvStatus3 = view.findViewById(R.id.tvStatus3);
tvUpgrade = view.findViewById(R.id.tvUpgradeCheck);
upgrade = view.findViewById(R.id.upgrade);
upgrade.setVisibility(View.GONE);

upgrade.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
writeToRPI("treehouses upgrade");
updateRightNow = true;
pd = ProgressDialog.show(getActivity(), "Updating...", "Please wait a few seconds...");
pd.setCanceledOnTouchOutside(true);
}
});
}

private void checkStatusNow(View view){
// if(mChatService.getState() == Constants.STATE_CONNECTED){
// btStatus.setBackgroundResource((R.drawable.circle));
// GradientDrawable bgShape = (GradientDrawable)btStatus.getBackground();
// bgShape.setColor(Color.GREEN);
// wifiStatus.setBackgroundResource((R.drawable.circle));
// bgShape = (GradientDrawable)wifiStatus.getBackground();
// bgShape.setColor(Color.GREEN);
// btRPIName.setBackgroundResource((R.drawable.circle));
// bgShape = (GradientDrawable)btRPIName.getBackground();
// bgShape.setColor(Color.GREEN);
// rpiType.setBackgroundResource((R.drawable.circle));
// bgShape = (GradientDrawable)rpiType.getBackground();
// bgShape.setColor(Color.GREEN);
// }else{
// btStatus.setBackgroundResource((R.drawable.circle));
// GradientDrawable bgShape = (GradientDrawable)btStatus.getBackground();
// bgShape.setColor(Color.RED);
// wifiStatus.setBackgroundResource((R.drawable.circle));
// bgShape = (GradientDrawable)wifiStatus.getBackground();
// bgShape.setColor(Color.RED);
// btRPIName.setBackgroundResource((R.drawable.circle));
// bgShape = (GradientDrawable)btRPIName.getBackground();
// bgShape.setColor(Color.RED);
// rpiType.setBackgroundResource((R.drawable.circle));
// bgShape = (GradientDrawable)rpiType.getBackground();
// bgShape.setColor(Color.RED);
// }
Log.e("DEVICE",""+mConnectedDeviceName);
}

Expand All @@ -223,6 +155,11 @@ public void updateStatus(){
if(outs.size() == 3){
checkUpgradeStatus();
}
if(outs.size() == 4){
outs.remove(2);
outs.remove(2);
checkWifiStatus();
}
}

void writeToRPI(String ping){
Expand Down Expand Up @@ -253,16 +190,24 @@ void checkWifiStatus(){
writeToRPI("treehouses upgrade --check");
}else{
tvUpgrade.setText("Upgrade Status: NO INTERNET");
upgrade.setVisibility(View.GONE);
}
}

void checkUpgradeStatus(){
if(outs.get(2).equals("false")){
if(updateRightNow){
updateRightNow = false;
pd.dismiss();
Toast.makeText(getContext(),"Treehouses Cli has been updated!!!",Toast.LENGTH_LONG).show();
}
if(outs.get(2).equals("false ")){
ivUpgrad.setImageDrawable(getResources().getDrawable(R.drawable.tick));
tvUpgrade.setText("Upgrade Status: Latest Version");
upgrade.setVisibility(View.GONE);
}else{
ivUpgrad.setImageDrawable(getResources().getDrawable(R.drawable.tick_png));
tvUpgrade.setText("Upgrade Status: Required for Version: "+outs.get(2).substring(4));
upgrade.setVisibility(View.VISIBLE);
}
}
// /**
Expand Down
18 changes: 15 additions & 3 deletions app/src/main/res/layout/activity_status_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@
<!--app:srcCompat="@drawable/tick_png" />-->
<!--</androidx.cardview.widget.CardView>-->

<Button
android:id="@+id/upgrade"
android:layout_width="wrap_content"
android:layout_height="51dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="?attr/colorPrimary"
android:text="Upgrade?"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cardView3" />

<androidx.cardview.widget.CardView
android:id="@+id/cardView1"
android:layout_width="0dp"
Expand Down Expand Up @@ -250,9 +263,7 @@
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="94dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="@+id/upgrade"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cardView3">

Expand All @@ -278,6 +289,7 @@
android:layout_width="49dp"
android:layout_height="match_parent"
app:srcCompat="@drawable/tick_png" />

</androidx.cardview.widget.CardView>

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit c7d4007

Please sign in to comment.