Skip to content

Commit

Permalink
correction bug crash bbox not found
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanMoreau committed Nov 10, 2015
1 parent 2364342 commit 8052d3f
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,47 +69,51 @@ public View getView(int position, View convertView, ViewGroup parent) {

appName.setText(app.getAppName());
appState.setText(app.getAppState().toString());

Bbox bbox = BboxHolder.getInstance().getBbox();

if (bbox != null) {
final ApplicationsManager applicationsManager = bbox.getApplicationsManager();

start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
applicationsManager.startApplication(app, new CallbackHttpStatus() {
@Override
public void onResult(int i) {
applicationsManager.getApplications(new ApplicationsManager.CallbackApplications() {
@Override
public void onResult(int status, List<Application> applicationsList) {
applications = applicationsList;
notifyDataSetChanged();
}
});
}
});
}
});

stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
applicationsManager.stopApplication(app, new CallbackHttpStatus() {
@Override
public void onResult(int i) {
applicationsManager.getApplications(new ApplicationsManager.CallbackApplications() {
@Override
public void onResult(int status, List<Application> applicationsList) {
applications = applicationsList;
notifyDataSetChanged();
}
});
}
});
}
});
try {
Bbox bbox = BboxHolder.getInstance().getBbox();

if (bbox != null) {
final ApplicationsManager applicationsManager = bbox.getApplicationsManager();

start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
applicationsManager.startApplication(app, new CallbackHttpStatus() {
@Override
public void onResult(int i) {
applicationsManager.getApplications(new ApplicationsManager.CallbackApplications() {
@Override
public void onResult(int status, List<Application> applicationsList) {
applications = applicationsList;
notifyDataSetChanged();
}
});
}
});
}
});

stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
applicationsManager.stopApplication(app, new CallbackHttpStatus() {
@Override
public void onResult(int i) {
applicationsManager.getApplications(new ApplicationsManager.CallbackApplications() {
@Override
public void onResult(int status, List<Application> applicationsList) {
applications = applicationsList;
notifyDataSetChanged();
}
});
}
});
}
});
}
}
catch (BboxNotFoundException e) {
e.toast(mContext);
}
}
return view;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import android.widget.Toast;

import fr.bouyguestelecom.tv.openapi.secondscreen.authenticate.IAuthCallback;
import fr.bouyguestelecom.tv.openapi.secondscreen.bbox.Bbox;
Expand Down Expand Up @@ -79,9 +80,9 @@ public void authenticate(String appId, String appSecret, IAuthCallback callback)
*
* @return the bbox.
*/
public Bbox getBbox() {
public Bbox getBbox() throws BboxNotFoundException {
if (mBbox == null) {
throw new RuntimeException("No bbox found! Check if a Miami bbox is present in the same network and if the service BboxApi is running.");
throw new BboxNotFoundException();
}
return mBbox;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package fr.bouyguestelecom.bboxlab.remotetemplate;

import android.content.Context;
import android.widget.Toast;

/**
* Created by tristan on 09/11/15.
*/
public class BboxNotFoundException extends Exception {

public BboxNotFoundException() {
super("No bbox found! Check if a Miami bbox is present in the same network and if the service BboxApi is running.");
}

public void toast (Context context) {
Toast toast = Toast.makeText(context, "No Bbox found. Please make sure the box is on the same network with the service BboxApi running.", Toast.LENGTH_LONG);
toast.show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ public void onAuthResult(int code, String msg)
displayWarningConnectivityMessage(msg); //Something wrong happen during authentication process
return;
} //Check the reason to know exactly why there is an error (problem with tokens means problem during connection with distant platform
//Authentication while problem with sessionId means problem with bbox connectivity check)
final Bbox bbox = BboxHolder.getInstance().getBbox(); //Starts almost everything, creates a BboxHolder that holds a Bbox
try { //Authentication while problem with sessionId means problem with bbox connectivity check)
final Bbox bbox = BboxHolder.getInstance().getBbox(); //Starts almost everything, creates a BboxHolder that holds a Bbox


if (bbox != null)
{
Expand Down Expand Up @@ -151,7 +152,10 @@ public void onConnect()
}
});
}
initAnymoteConnection(); //Pairing to a Bbox through anymote protocol
initAnymoteConnection();
}
catch (BboxNotFoundException e) {
}//Pairing to a Bbox through anymote protocol
}
};
mNavigationDrawerFragment.setUp(R.id.navigation_drawer,
Expand Down Expand Up @@ -336,12 +340,16 @@ private void initSetting(View rootView)
final TextView showCrtIP = (TextView) rootView.findViewById(R.id.showCrtIP);

editText.setText(preference.getString("bboxIP", "*.*.*.*"));
showCrtIP.setText(preference.getString("*.*.*.*", BboxHolder.getInstance().getBbox().getIp()));
save.setOnClickListener(new View.OnClickListener()
{
try {
showCrtIP.setText(preference.getString("*.*.*.*", BboxHolder.getInstance().getBbox().getIp()));
}
catch (BboxNotFoundException e) {
e.toast(this.getActivity());
};

save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
public void onClick(View view) {
SharedPreferences.Editor editor = preference.edit();

editor.putString("bboxIP", editText.getText().toString());
Expand All @@ -366,23 +374,27 @@ public void onClick(View view)

private void initAppController(final View rootView) // App controller
{
ApplicationsManager applicationsManager = BboxHolder.getInstance().getBbox()
.getApplicationsManager();
try {
ApplicationsManager applicationsManager = BboxHolder.getInstance().getBbox()
.getApplicationsManager();

applicationsManager.getApplications(new ApplicationsManager.CallbackApplications() // We are getting all the installed applications on the Bbox, and show them in a listView.
{
@Override
public void onResult(int status, List<Application> applications)
applicationsManager.getApplications(new ApplicationsManager.CallbackApplications() // We are getting all the installed applications on the Bbox, and show them in a listView.
{
ApplicationAdapter applicationAdapter = new ApplicationAdapter(getActivity()
.getApplicationContext()
, applications, getActivity());
ListView listView = (ListView) rootView
.findViewById(R.id.listView);

listView.setAdapter(applicationAdapter);
}
});
@Override
public void onResult(int status, List<Application> applications) {
ApplicationAdapter applicationAdapter = new ApplicationAdapter(getActivity()
.getApplicationContext()
, applications, getActivity());
ListView listView = (ListView) rootView
.findViewById(R.id.listView);

listView.setAdapter(applicationAdapter);
}
});
}
catch (BboxNotFoundException e) {
e.toast(this.getActivity());
}
}

private void initNotifications(final View rootView) // Notifications
Expand Down Expand Up @@ -442,36 +454,40 @@ public void onClick(View view)

private void initChanList(final View rootView) //Starts Channel List view, taking place on main view
{
MediaManager mediaMng = BboxHolder.getInstance().getBbox().getMediaManager(); //Preparing fetching sequence; Locking target Bbox, Checking setted Bbox presence, Using the setted Bbox's Media fetching sequence
try {

mediaMng.getChannels(new MediaManager.CallbackChannels() //Asynchronous REST data fetching through callback
{ //Anonymous channels' fetching function startpoint
@Override
public void onResult(int status, final List<Media> chans) //On receiving JSON data, fill the Channel List's fragment with
{
MediaAdapter mediaAdp = new MediaAdapter(getActivity()
.getApplicationContext(), chans, getActivity()); //Initialize the Channel List's main fragment
ListView lstView = (ListView) rootView.findViewById(R.id.listView); //Create the ListView and fill it with the corresponding xml fragment; This is where getView is used through override
final ToggleButton tglBtn = (ToggleButton) rootView.findViewById(R.id.toggleButton);
MediaManager mediaMng = BboxHolder.getInstance().getBbox().getMediaManager(); //Preparing fetching sequence; Locking target Bbox, Checking setted Bbox presence, Using the setted Bbox's Media fetching sequence

tglBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
mediaMng.getChannels(new MediaManager.CallbackChannels() //Asynchronous REST data fetching through callback
{ //Anonymous channels' fetching function startpoint
@Override
public void onResult(int status, final List<Media> chans) //On receiving JSON data, fill the Channel List's fragment with
{
@Override
public void onCheckedChanged(CompoundButton btnView, boolean isChk)
{
String lstStr = String.valueOf(chans.size());

if (isChk) {
tglBtn.setTextOn("Channels: " + lstStr);
} else {
tglBtn.setTextOff("Channels: " + lstStr);
MediaAdapter mediaAdp = new MediaAdapter(getActivity()
.getApplicationContext(), chans, getActivity()); //Initialize the Channel List's main fragment
ListView lstView = (ListView) rootView.findViewById(R.id.listView); //Create the ListView and fill it with the corresponding xml fragment; This is where getView is used through override
final ToggleButton tglBtn = (ToggleButton) rootView.findViewById(R.id.toggleButton);

tglBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton btnView, boolean isChk) {
String lstStr = String.valueOf(chans.size());

if (isChk) {
tglBtn.setTextOn("Channels: " + lstStr);
} else {
tglBtn.setTextOff("Channels: " + lstStr);
}
}
}
});

lstView.setAdapter(mediaAdp); //Fill lstView with every "element_media.xml"'s sub-fragments
}
});
});
if (lstView != null)
lstView.setAdapter(mediaAdp); //Fill lstView with every "element_media.xml"'s sub-fragments
}
});
}
catch (BboxNotFoundException e) {
e.toast(this.getActivity());
}
}
}

Expand Down

0 comments on commit 8052d3f

Please sign in to comment.