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

Fix "Shutdown" not working & fix NPE in Pictures #91

Open
wants to merge 2 commits 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
14 changes: 14 additions & 0 deletions src/org/xbmc/android/remote/business/ControlManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,18 @@ public void doRun() throws Exception {
}
});
}

/**
* Powers off the system.
* @param response Response object
* @param context Context reference
*/
public void powerOff(final DataResponse<Boolean> response, final Context context) {
mHandler.post(new Command<Boolean>(response, this) {
@Override
public void doRun() throws Exception {
response.value = control(context).powerOff(ControlManager.this);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.xbmc.android.util.WakeOnLan;
import org.xbmc.android.util.WifiHelper;
import org.xbmc.api.business.DataResponse;
import org.xbmc.api.business.IControlManager;
import org.xbmc.api.business.IInfoManager;
import org.xbmc.api.business.IMusicManager;
import org.xbmc.api.business.INotifiableManager;
Expand Down Expand Up @@ -83,17 +84,17 @@
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class HomeController extends AbstractController implements INotifiableController, IController, Observer, OnSharedPreferenceChangeListener {

Expand Down Expand Up @@ -317,7 +318,8 @@ public void onItemClick(AdapterView<?> listView, View v, int position, long ID)
}
break;
case HOME_ACTION_POWERDOWN:
PowerDown powerdown = new PowerDown();
final IControlManager cm = ManagerFactory.getControlManager(HomeController.this);
PowerDown powerdown = new PowerDown(cm);
powerdown.ShowDialog(mActivity);
break;
}
Expand Down
15 changes: 9 additions & 6 deletions src/org/xbmc/android/util/PowerDown.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

package org.xbmc.android.util;

import org.xbmc.android.remote.business.EventClientManager;
import org.xbmc.api.business.DataResponse;
import org.xbmc.api.business.IControlManager;
import org.xbmc.api.business.IEventClientManager;
import org.xbmc.eventclient.ButtonCodes;

import android.app.Activity;
import android.app.AlertDialog;
Expand All @@ -32,8 +32,13 @@
public class PowerDown {
IEventClientManager mEventClientManager;
private Activity mActivity;
private final IControlManager cm;

public void ShowDialog(Activity activity) {
public PowerDown(IControlManager cm) {
this.cm = cm;
}

public void ShowDialog(final Activity activity) {
mActivity = activity;
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
builder.setMessage("Are you sure you want to power off?").setCancelable(false);
Expand All @@ -44,9 +49,7 @@ public void onClick(DialogInterface dialog, int id) {
}

private void Down() {
EventClientManager pdEventClientManager = new EventClientManager();
pdEventClientManager.sendButton("R1", ButtonCodes.REMOTE_POWER, false, true, true, (short) 0, (byte) 0);

cm.powerOff(new DataResponse<Boolean>(), activity.getApplicationContext());
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Expand Down
9 changes: 8 additions & 1 deletion src/org/xbmc/api/business/IControlManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,11 @@ public void setGuiSetting(final DataResponse<Boolean> response, final int settin
* @return true on success, false otherwise.
*/
public void sendText(final DataResponse<Boolean> response, final String text, final Context context);
}

/**
* Powers off the system.
* @param response Response object
* @param context Context reference
*/
public void powerOff(final DataResponse<Boolean> response, final Context context);
}
9 changes: 8 additions & 1 deletion src/org/xbmc/api/data/IControlClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public interface IControlClient extends IClient {
public boolean pause(INotifiableManager manager);

/**
* Powers off the system.
* @param manager Manager reference
* @return true on success, false otherwise.
*/
public boolean powerOff(INotifiableManager manager);

/**
* Stops the currently playing media.
* @param manager Manager reference
* @return true on success, false otherwise.
Expand All @@ -101,7 +108,7 @@ public interface IControlClient extends IClient {
* Seeks to a position. If type is
* <ul>
* <li><code>absolute</code> - Sets the playing position of the currently
* playing media as a percentage of the medias length.</li>
* playing media as a percentage of the media's length.</li>
* <li><code>relative</code> - Adds/Subtracts the current percentage on to
* the current position in the song</li>
* </ul>
Expand Down
11 changes: 10 additions & 1 deletion src/org/xbmc/httpapi/client/ControlClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public boolean setVolume(INotifiableManager manager, int volume) {
* Seeks to a position. If type is
* <ul>
* <li><code>absolute</code> - Sets the playing position of the currently
* playing media as a percentage of the medias length.</li>
* playing media as a percentage of the media's length.</li>
* <li><code>relative</code> - Adds/Subtracts the current percentage on to
* the current position in the song</li>
* </ul>
Expand Down Expand Up @@ -479,4 +479,13 @@ else if (map.get("Type").contains("Video")) {
}
}
}

/**
* Powers off the system.
* @param response Response object
* @return true on success, false otherwise.
*/
public boolean powerOff(INotifiableManager manager) {
return mConnection.getBoolean(manager, "Shutdown()");
}
}
9 changes: 9 additions & 0 deletions src/org/xbmc/jsonrpc/client/ControlClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ public boolean stop(INotifiableManager manager) {
return mConnection.getString(manager, "Player.Stop", obj().p("playerid", getActivePlayerId(manager))).equals("OK");
}

/**
* Powers off the system.
* @param manager Manager reference
* @return OK on success, false otherwise.
*/
public boolean powerOff(INotifiableManager manager) {
return mConnection.getString(manager, "System.Shutdown", null).equals("OK");
}

/**
* Start playing the media file at the given URL
* @param manager Manager reference
Expand Down
4 changes: 1 addition & 3 deletions src/org/xbmc/jsonrpc/client/InfoClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,9 @@ public ArrayList<FileLocation> getDirectory(INotifiableManager manager, String p
* @return
*/
public ArrayList<FileLocation> getShares(INotifiableManager manager, int mediaType) {


final ArrayList<FileLocation> shares = new ArrayList<FileLocation>();
final JsonNode jsonShares = mConnection.getJson(manager, "Files.GetSources", obj().p("media", MediaType.getName(mediaType)));
if(jsonShares != null){
if(jsonShares != null && jsonShares.get("sources") != null) {
for (Iterator<JsonNode> i = jsonShares.get("sources").getElements(); i.hasNext();) {
JsonNode jsonShare = (JsonNode)i.next();
shares.add(new FileLocation(getString(jsonShare, "label"), getString(jsonShare, "file")));
Expand Down