Update examples
This commit is contained in:
parent
78f0c44025
commit
e452d14e7f
15
README.md
15
README.md
@ -138,8 +138,6 @@ package it.tdlight.example;
|
|||||||
import it.tdlight.common.TelegramClient;
|
import it.tdlight.common.TelegramClient;
|
||||||
import it.tdlight.tdlight.ClientManager;
|
import it.tdlight.tdlight.ClientManager;
|
||||||
import it.tdlight.common.Init;
|
import it.tdlight.common.Init;
|
||||||
import it.tdlight.common.Log;
|
|
||||||
import it.tdlight.common.TDLibException;
|
|
||||||
|
|
||||||
import it.tdlight.jni.TdApi;
|
import it.tdlight.jni.TdApi;
|
||||||
|
|
||||||
@ -156,6 +154,9 @@ public class Example {
|
|||||||
// Documentation of tdlib methods can be found here:
|
// Documentation of tdlib methods can be found here:
|
||||||
// https://tdlight-team.github.io/tdlight-docs
|
// https://tdlight-team.github.io/tdlight-docs
|
||||||
|
|
||||||
|
// An example on how to use tdlight java can be found here:
|
||||||
|
// https://github.com/tdlight-team/tdlight-java/blob/master/example/src/main/java/it.tdlight.example/Example.java
|
||||||
|
|
||||||
// A similar example on how to use tdlib can be found here:
|
// A similar example on how to use tdlib can be found here:
|
||||||
// https://github.com/tdlib/td/blob/master/example/java/org/drinkless/tdlib/example/Example.java
|
// https://github.com/tdlib/td/blob/master/example/java/org/drinkless/tdlib/example/Example.java
|
||||||
}
|
}
|
||||||
@ -166,25 +167,15 @@ public class Example {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void onUpdateError(Throwable exception) {
|
private static void onUpdateError(Throwable exception) {
|
||||||
if (exception instanceof TDLibException) {
|
|
||||||
String errorMessage = ((TDLibException) exception).getErrorMessage();
|
|
||||||
System.out.println("Received an error from updates: " + errorMessage);
|
|
||||||
} else {
|
|
||||||
System.out.println("Received an error from updates:");
|
System.out.println("Received an error from updates:");
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static void onError(Throwable exception) {
|
private static void onError(Throwable exception) {
|
||||||
if (exception instanceof TDLibException) {
|
|
||||||
String errorMessage = ((TDLibException) exception).getErrorMessage();
|
|
||||||
System.out.println("Received an error: " + errorMessage);
|
|
||||||
} else {
|
|
||||||
System.out.println("Received an error:");
|
System.out.println("Received an error:");
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### TDLib methods documentation
|
### TDLib methods documentation
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
package it.tdlight.example;
|
package it.tdlight.example;
|
||||||
|
|
||||||
|
import it.tdlight.common.ExceptionHandler;
|
||||||
import it.tdlight.common.Init;
|
import it.tdlight.common.Init;
|
||||||
import it.tdlight.common.ResultHandler;
|
import it.tdlight.common.ResultHandler;
|
||||||
import it.tdlight.common.TelegramClient;
|
import it.tdlight.common.TelegramClient;
|
||||||
@ -158,7 +159,7 @@ public final class Example {
|
|||||||
case TdApi.AuthorizationStateClosed.CONSTRUCTOR:
|
case TdApi.AuthorizationStateClosed.CONSTRUCTOR:
|
||||||
print("Closed");
|
print("Closed");
|
||||||
if (!needQuit) {
|
if (!needQuit) {
|
||||||
client = ClientManager.create(new UpdateHandler(), null, null); // recreate client after previous has closed
|
client = ClientManager.create(new UpdateHandler(), new ErrorHandler(), new ErrorHandler()); // recreate client after previous has closed
|
||||||
} else {
|
} else {
|
||||||
canQuit = true;
|
canQuit = true;
|
||||||
}
|
}
|
||||||
@ -305,7 +306,7 @@ public final class Example {
|
|||||||
|
|
||||||
// create client
|
// create client
|
||||||
Init.start();
|
Init.start();
|
||||||
client = ClientManager.create(new UpdateHandler(), null, null);
|
client = ClientManager.create(new UpdateHandler(), new ErrorHandler(), new ErrorHandler());
|
||||||
|
|
||||||
client.execute(new TdApi.SetLogVerbosityLevel(0));
|
client.execute(new TdApi.SetLogVerbosityLevel(0));
|
||||||
// disable TDLib log
|
// disable TDLib log
|
||||||
@ -588,6 +589,14 @@ public final class Example {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class ErrorHandler implements ExceptionHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onException(Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class AuthorizationRequestHandler implements ResultHandler {
|
private static class AuthorizationRequestHandler implements ResultHandler {
|
||||||
@Override
|
@Override
|
||||||
public void onResult(TdApi.Object object) {
|
public void onResult(TdApi.Object object) {
|
||||||
|
Loading…
Reference in New Issue
Block a user