Updated on 2026-08-14
This commit is contained in:
parent
faa1cd750c
commit
355c9166be
6 changed files with 94 additions and 0 deletions
|
|
@ -57,6 +57,7 @@ dependencies {
|
|||
implementation 'com.scottyab:rootbeer-lib:0.0.6'
|
||||
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
|
||||
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
|
||||
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
|
||||
implementation 'com.skyfishjy.ripplebackground:library:1.0.1'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
import static com.tangem.data.network.Server.ApiTangem.URL_TANGEM;
|
||||
|
||||
public class Server {
|
||||
|
||||
/**
|
||||
|
|
@ -14,6 +16,14 @@ public class Server {
|
|||
}
|
||||
}
|
||||
|
||||
public static class ApiUpdateVersion {
|
||||
public static final String URL_UPDATE_VERSION = ServerURL.API_UPDATE_VERSION;
|
||||
|
||||
public static class Method {
|
||||
public static final String LAST_VERSION = URL_UPDATE_VERSION +"TangemCash/tangem-binaries/master/apk-version.txt";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* https://coinmarketcap.com/api/
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import org.json.JSONException;
|
|||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
|
|
@ -41,6 +42,9 @@ import io.reactivex.Observable;
|
|||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.observers.DefaultObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
|
@ -301,4 +305,58 @@ public class ServerApiHelper {
|
|||
return "Electrum, " + host + ":" + String.valueOf(port);
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP
|
||||
* Last version request from GitHub
|
||||
*/
|
||||
private LastVersionListener lastVersionListener;
|
||||
|
||||
public interface LastVersionListener {
|
||||
void onLastVersion(String lastVersion);
|
||||
}
|
||||
|
||||
public void setLastVersionListener(LastVersionListener listener) {
|
||||
lastVersionListener = listener;
|
||||
}
|
||||
|
||||
public void requestLastVersion() {
|
||||
|
||||
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
|
||||
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
|
||||
OkHttpClient httpClient = new OkHttpClient.Builder().
|
||||
addInterceptor(logging).
|
||||
// addInterceptor(new AuthorizationInterceptor()).
|
||||
build();
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl(Server.ApiUpdateVersion.URL_UPDATE_VERSION)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.client(httpClient)
|
||||
.build();
|
||||
|
||||
UpdateVersionApi updateVersionApi = retrofit.create(UpdateVersionApi.class);
|
||||
|
||||
Call<ResponseBody> call = updateVersionApi.getLastVersion();
|
||||
call.enqueue(new Callback<ResponseBody>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
|
||||
Log.i(TAG, "LastVersion onResponse " + response.code());
|
||||
if (response.code() == 200) {
|
||||
String stringResponse;
|
||||
try {
|
||||
stringResponse = response.body().string();
|
||||
lastVersionListener.onLastVersion(stringResponse);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
|
||||
Log.e(TAG, "LastVersion onFailure " + t.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,4 +4,5 @@ public class ServerURL {
|
|||
public static final String API_TANGEM = "https://verify.tangem.com/";
|
||||
public static final String API_COINMARKET = "https://api.coinmarketcap.com/";
|
||||
public static final String API_INFURA = "https://mainnet.infura.io/";
|
||||
public static final String API_UPDATE_VERSION = "https://raw.githubusercontent.com/";
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
import com.tangem.data.network.model.CardVerifyBody;
|
||||
import com.tangem.data.network.model.CardVerifyResponse;
|
||||
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Header;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface UpdateVersionApi {
|
||||
@GET(Server.ApiUpdateVersion.Method.LAST_VERSION)
|
||||
Call<ResponseBody> getLastVersion();
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ import android.view.animation.Transformation
|
|||
import android.widget.RelativeLayout
|
||||
import android.widget.Toast
|
||||
import com.scottyab.rootbeer.RootBeer
|
||||
import com.tangem.data.network.ServerApiHelper
|
||||
import com.tangem.data.nfc.ReadCardInfoTask
|
||||
import com.tangem.domain.cardReader.CardProtocol
|
||||
import com.tangem.domain.cardReader.FW
|
||||
|
|
@ -147,6 +148,13 @@ class MainActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoco
|
|||
false
|
||||
}
|
||||
}
|
||||
|
||||
val apiHelper = ServerApiHelper()
|
||||
apiHelper.setLastVersionListener {
|
||||
response->
|
||||
if(response!! != BuildConfig.VERSION_NAME) Toast.makeText(this, "There is a new application version: "+response.toString(),Toast.LENGTH_LONG).show()
|
||||
}
|
||||
apiHelper.requestLastVersion()
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue