Add addons search
This commit is contained in:
parent
645f22f64a
commit
2693d62702
|
@ -158,7 +158,7 @@ public class HostConnection {
|
||||||
|
|
||||||
private static final int DEFAULT_CONNECT_TIMEOUT = 5000; // ms
|
private static final int DEFAULT_CONNECT_TIMEOUT = 5000; // ms
|
||||||
|
|
||||||
private static final int TCP_READ_TIMEOUT = 30000; // ms
|
public static final int TCP_READ_TIMEOUT = 30000; // ms
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OkHttpClient. Make sure it is initialized, by calling {@link #getOkHttpClient()}
|
* OkHttpClient. Make sure it is initialized, by calling {@link #getOkHttpClient()}
|
||||||
|
@ -166,6 +166,15 @@ public class HostConnection {
|
||||||
private OkHttpClient httpClient = null;
|
private OkHttpClient httpClient = null;
|
||||||
private static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8");
|
private static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag to indicate that the tcp response have to be ignored.
|
||||||
|
*/
|
||||||
|
private boolean ignoreTcpResponse = false;
|
||||||
|
|
||||||
|
public void setIgnoreTcpResponse(boolean ignoreTcpResponse) {
|
||||||
|
this.ignoreTcpResponse = ignoreTcpResponse;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new host connection
|
* Creates a new host connection
|
||||||
* @param hostInfo Host info object
|
* @param hostInfo Host info object
|
||||||
|
@ -698,7 +707,19 @@ public class HostConnection {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean shouldIgnoreTcpResponse(ObjectNode jsonResponse) {
|
||||||
|
boolean ignore = false;
|
||||||
|
if (jsonResponse.has(ApiMethod.ID_NODE) && ignoreTcpResponse) {
|
||||||
|
ignoreTcpResponse = false;
|
||||||
|
ignore = true;
|
||||||
|
}
|
||||||
|
LogUtils.LOGD(TAG, "ignore tcp response - " + ignore);
|
||||||
|
return ignore;
|
||||||
|
}
|
||||||
|
|
||||||
private <T> void handleTcpResponse(ObjectNode jsonResponse) {
|
private <T> void handleTcpResponse(ObjectNode jsonResponse) {
|
||||||
|
if (shouldIgnoreTcpResponse(jsonResponse))
|
||||||
|
return;
|
||||||
|
|
||||||
if (!jsonResponse.has(ApiMethod.ID_NODE)) {
|
if (!jsonResponse.has(ApiMethod.ID_NODE)) {
|
||||||
// It's a notification, notify observers
|
// It's a notification, notify observers
|
||||||
|
|
|
@ -338,7 +338,6 @@ public abstract class BaseMediaActivity extends BaseActivity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void inputOnInputRequested(String title, String type, String value) {
|
public void inputOnInputRequested(String title, String type, String value) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -19,30 +19,43 @@ import android.annotation.TargetApi;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.text.TextDirectionHeuristicsCompat;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import org.xbmc.kore.R;
|
import org.xbmc.kore.R;
|
||||||
|
import org.xbmc.kore.host.HostManager;
|
||||||
|
import org.xbmc.kore.jsonrpc.HostConnection;
|
||||||
|
import org.xbmc.kore.jsonrpc.method.Input;
|
||||||
import org.xbmc.kore.ui.AbstractFragment;
|
import org.xbmc.kore.ui.AbstractFragment;
|
||||||
import org.xbmc.kore.ui.BaseMediaActivity;
|
import org.xbmc.kore.ui.BaseMediaActivity;
|
||||||
import org.xbmc.kore.ui.sections.remote.RemoteActivity;
|
import org.xbmc.kore.ui.sections.remote.RemoteActivity;
|
||||||
import org.xbmc.kore.utils.LogUtils;
|
import org.xbmc.kore.utils.LogUtils;
|
||||||
import org.xbmc.kore.utils.Utils;
|
import org.xbmc.kore.utils.Utils;
|
||||||
|
|
||||||
|
import org.xbmc.kore.ui.generic.SendTextDialogFragment;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controls the presentation of Addons information (list, details)
|
* Controls the presentation of Addons information (list, details)
|
||||||
* All the information is presented by specific fragments
|
* All the information is presented by specific fragments
|
||||||
*/
|
*/
|
||||||
public class AddonsActivity extends BaseMediaActivity
|
public class AddonsActivity extends BaseMediaActivity
|
||||||
implements AddonListFragment.OnAddonSelectedListener {
|
implements AddonListFragment.OnAddonSelectedListener,
|
||||||
|
SendTextDialogFragment.SendTextDialogListener {
|
||||||
private static final String TAG = LogUtils.makeLogTag(AddonsActivity.class);
|
private static final String TAG = LogUtils.makeLogTag(AddonsActivity.class);
|
||||||
|
|
||||||
public static final String ADDONID = "addon_id";
|
public static final String ADDONID = "addon_id";
|
||||||
public static final String ADDONTITLE = "addon_title";
|
public static final String ADDONTITLE = "addon_title";
|
||||||
|
|
||||||
|
private static final String DUMMY_INPUT = "kore_dummy_input";
|
||||||
|
|
||||||
private String selectedAddonId;
|
private String selectedAddonId;
|
||||||
private String selectedAddonTitle;
|
private String selectedAddonTitle;
|
||||||
|
|
||||||
|
private boolean dialogShown;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Fragment createFragment() {
|
protected Fragment createFragment() {
|
||||||
return new AddonListContainerFragment();
|
return new AddonListContainerFragment();
|
||||||
|
@ -135,4 +148,56 @@ public class AddonsActivity extends BaseMediaActivity
|
||||||
|
|
||||||
updateActionBar(getActionBarTitle(), true);
|
updateActionBar(getActionBarTitle(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void inputOnInputRequested(String title, String type, String value) {
|
||||||
|
final SendTextDialogFragment dialog =
|
||||||
|
SendTextDialogFragment.newInstance(title);
|
||||||
|
dialog.show(getSupportFragmentManager(), null);
|
||||||
|
dialogShown = true;
|
||||||
|
Thread t = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
TimeUnit.MILLISECONDS.sleep(HostConnection.TCP_READ_TIMEOUT - 2000);
|
||||||
|
if (dialogShown) {
|
||||||
|
dialog.dismissAllowingStateLoss();
|
||||||
|
sendTextInput(DUMMY_INPUT, true, true);
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callbacks from Send text dialog
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onSendTextFinished(String text, boolean done) {
|
||||||
|
dialogShown = false;
|
||||||
|
if (TextDirectionHeuristicsCompat.FIRSTSTRONG_LTR.isRtl(text, 0, text.length())) {
|
||||||
|
text = new StringBuilder(text).reverse().toString();
|
||||||
|
}
|
||||||
|
sendTextInput(text,done, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSendTextCancel() {
|
||||||
|
dialogShown = false;
|
||||||
|
sendTextInput(DUMMY_INPUT, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendTextInput(String text, boolean done, boolean isDummy) {
|
||||||
|
HostManager hostManager = HostManager.getInstance(this);
|
||||||
|
hostManager.getConnection().setIgnoreTcpResponse(isDummy);
|
||||||
|
|
||||||
|
HostConnection httpHostConnection = new HostConnection(hostManager.getHostInfo());
|
||||||
|
httpHostConnection.setProtocol(HostConnection.PROTOCOL_HTTP);
|
||||||
|
|
||||||
|
Input.SendText action = new Input.SendText(text, done);
|
||||||
|
action.execute(httpHostConnection, null, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue