Updated on 2026-08-14

This commit is contained in:
Tangem 2018-10-10 21:00:25 +03:00
parent ff22469cde
commit 68917838a4
7 changed files with 84 additions and 25 deletions

View file

@ -3,14 +3,17 @@ package com.tangem;
import android.app.Application;
import android.support.v7.app.AppCompatDelegate;
public class AppController extends Application {
import com.tangem.di.AppComponent;
import com.tangem.di.DaggerAppComponent;
public class App extends Application {
/**
* A singleton instance of the application class for easy access in other places
*/
private static AppController sInstance;
private static App sInstance;
public AppController() {
public App() {
super();
}
@ -18,18 +21,26 @@ public class AppController extends Application {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
private static AppComponent component;
@Override
public void onCreate() {
super.onCreate();
// initialize the singleton
sInstance = this;
component = DaggerAppComponent.create();
}
/**
* @return singleton instance
*/
public static synchronized AppController getInstance() {
public static synchronized App getInstance() {
return sInstance;
}
public static AppComponent getComponent() {
return component;
}
}

View file

@ -5,6 +5,7 @@ import android.support.annotation.NonNull;
import android.util.Log;
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import com.tangem.App;
import com.tangem.data.network.model.CardVerifyAndGetInfo;
import com.tangem.data.network.model.InfuraBody;
import com.tangem.data.network.model.InfuraResponse;
@ -64,12 +65,7 @@ public class ServerApiHelper {
}
public void estimateFee(int blockCount) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Server.ApiEstimatefee.URL_ESTIMATEFEE)
.addConverterFactory(GsonConverterFactory.create())
.build();
EstimatefeeApi estimatefeeApi = retrofit.create(EstimatefeeApi.class);
EstimatefeeApi estimatefeeApi = App.getComponent().getRetrofitEstimatefee().create(EstimatefeeApi.class);
Call<String> call;
switch (blockCount) {
@ -136,12 +132,7 @@ public class ServerApiHelper {
}
public void infura(String method, int id, String wallet, String contract, String tx) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Server.ApiInfura.URL_INFURA)
.addConverterFactory(GsonConverterFactory.create())
.build();
InfuraApi infuraApi = retrofit.create(InfuraApi.class);
InfuraApi infuraApi = App.getComponent().getRetrofitInfura().create(InfuraApi.class);
InfuraBody infuraBody;
switch (method) {

View file

@ -0,0 +1,18 @@
package com.tangem.di;
import javax.inject.Named;
import javax.inject.Singleton;
import dagger.Component;
import retrofit2.Retrofit;
@Singleton
@Component(modules = {NetworkModule.class})
public interface AppComponent {
@Named(NetworkModule.PROVIDE_RETROFIT_INFURA)
Retrofit getRetrofitInfura();
@Named(NetworkModule.PROVIDE_RETROFIT_ESTIMATEFEE)
Retrofit getRetrofitEstimatefee();
}

View file

@ -0,0 +1,39 @@
package com.tangem.di;
import com.tangem.data.network.Server;
import javax.inject.Named;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
@Module
class NetworkModule {
final static String PROVIDE_RETROFIT_INFURA = "provideRetrofitInfura";
final static String PROVIDE_RETROFIT_ESTIMATEFEE = "provideRetrofitEstimatefee";
@Singleton
@Provides
@Named(PROVIDE_RETROFIT_INFURA)
Retrofit provideRetrofitInfura() {
return new Retrofit.Builder()
.baseUrl(Server.ApiInfura.URL_INFURA)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
@Singleton
@Provides
@Named(PROVIDE_RETROFIT_ESTIMATEFEE)
Retrofit provideRetrofitEstimatefee() {
return new Retrofit.Builder()
.baseUrl(Server.ApiEstimatefee.URL_ESTIMATEFEE)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
}

View file

@ -4,8 +4,10 @@ import android.nfc.NfcAdapter
import android.nfc.Tag
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.tangem.App
import com.tangem.presentation.fragment.LoadedWallet
import com.tangem.wallet.R
import retrofit2.Retrofit
class LoadedWalletActivity : AppCompatActivity() {
@ -28,12 +30,4 @@ class LoadedWalletActivity : AppCompatActivity() {
}
}
// override fun onBackPressed() {
// val loadedWallet = supportFragmentManager.findFragmentById(R.id.loaded_wallet_fragment) as LoadedWallet
// val data = loadedWallet.prepareResultIntent()
// data.putExtra(EXTRA_MODIFICATION, "update")
// setResult(Activity.RESULT_OK, data)
// finish()
// }
}