Update examples
This commit is contained in:
parent
78f0c44025
commit
e452d14e7f
23
README.md
23
README.md
@ -138,8 +138,6 @@ package it.tdlight.example;
|
||||
import it.tdlight.common.TelegramClient;
|
||||
import it.tdlight.tdlight.ClientManager;
|
||||
import it.tdlight.common.Init;
|
||||
import it.tdlight.common.Log;
|
||||
import it.tdlight.common.TDLibException;
|
||||
|
||||
import it.tdlight.jni.TdApi;
|
||||
|
||||
@ -155,6 +153,9 @@ public class Example {
|
||||
|
||||
// Documentation of tdlib methods can be found here:
|
||||
// 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:
|
||||
// https://github.com/tdlib/td/blob/master/example/java/org/drinkless/tdlib/example/Example.java
|
||||
@ -166,23 +167,13 @@ public class Example {
|
||||
}
|
||||
|
||||
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:");
|
||||
exception.printStackTrace();
|
||||
}
|
||||
System.out.println("Received an error from updates:");
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
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:");
|
||||
exception.printStackTrace();
|
||||
}
|
||||
System.out.println("Received an error:");
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -6,6 +6,7 @@
|
||||
//
|
||||
package it.tdlight.example;
|
||||
|
||||
import it.tdlight.common.ExceptionHandler;
|
||||
import it.tdlight.common.Init;
|
||||
import it.tdlight.common.ResultHandler;
|
||||
import it.tdlight.common.TelegramClient;
|
||||
@ -158,7 +159,7 @@ public final class Example {
|
||||
case TdApi.AuthorizationStateClosed.CONSTRUCTOR:
|
||||
print("Closed");
|
||||
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 {
|
||||
canQuit = true;
|
||||
}
|
||||
@ -305,7 +306,7 @@ public final class Example {
|
||||
|
||||
// create client
|
||||
Init.start();
|
||||
client = ClientManager.create(new UpdateHandler(), null, null);
|
||||
client = ClientManager.create(new UpdateHandler(), new ErrorHandler(), new ErrorHandler());
|
||||
|
||||
client.execute(new TdApi.SetLogVerbosityLevel(0));
|
||||
// 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 {
|
||||
@Override
|
||||
public void onResult(TdApi.Object object) {
|
||||
|
Loading…
Reference in New Issue
Block a user