You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.7 KiB
65 lines
1.7 KiB
package com.community.pocket.data.model;
|
|
|
|
import okhttp3.FormBody;
|
|
import okhttp3.MultipartBody;
|
|
|
|
public class LocalToken {
|
|
private final String token;
|
|
private final Long time;
|
|
private final String username;
|
|
|
|
private static volatile LocalToken instance;
|
|
|
|
private static volatile Token tokenInstance;
|
|
|
|
public static LocalToken getInstance(Token token) {
|
|
if (instance == null) {
|
|
tokenInstance = token;
|
|
instance = new LocalToken(tokenInstance.getToken(), tokenInstance.getTime(), tokenInstance.getUsername());
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
public static LocalToken getInstance() {
|
|
return instance;
|
|
}
|
|
|
|
public static void logout() {
|
|
instance = null;
|
|
tokenInstance = null;
|
|
}
|
|
|
|
private LocalToken(String token, Long time, String username) {
|
|
this.token = token;
|
|
this.time = time;
|
|
this.username = username;
|
|
}
|
|
|
|
public static String getToken() {
|
|
return instance.token;
|
|
}
|
|
|
|
public static Long getTime() {
|
|
return instance.time;
|
|
}
|
|
|
|
public static String getUsername() {
|
|
return instance.username;
|
|
}
|
|
|
|
public static Token getTokenInstance() {
|
|
return tokenInstance;
|
|
}
|
|
|
|
public static FormBody.Builder create() {
|
|
return new FormBody.Builder()
|
|
.add("token", LocalToken.getToken())
|
|
.add("username", LocalToken.getUsername());
|
|
}
|
|
|
|
public static MultipartBody.Builder createM() {
|
|
return new MultipartBody.Builder()
|
|
.addFormDataPart("token", LocalToken.getToken())
|
|
.addFormDataPart("username", LocalToken.getUsername());
|
|
}
|
|
}
|
|
|