Muhammad al-xorazmiy nomidagi toshkent axborot texnologiyalari universiteti farg’ona filiali dasturiy injiniringi va raqamli iqtisodiyot fakulteti dasturiy injinering
This method stops the camera animation if there is one in progress
Download 122.69 Kb.
|
MI5
Amaliy qism object Client { internal var retrofit: Retrofit? = null var username: String = "" var password: String = "" fun initClient(context: Context, host: String, username: String, password: String) { this.username= username this.password= password val gson = GsonBuilder() .setLenient() .create() retrofit = Retrofit.Builder() .baseUrl(host) .client(getOkHttpClient(context)) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create(gson)) .build() } fun getInstance(context: Context): Retrofit{ if (retrofit != null){ return retrofit!! }else{ val data = Prefs.getServerData() initClient(context, data!!.serverHost, data!!.username, data!!.password) return retrofit!! } } fun getOkHttpClient(context: Context): OkHttpClient { var builder = OkHttpClient().newBuilder() builder.connectTimeout(60, TimeUnit.SECONDS) builder.writeTimeout(60, TimeUnit.SECONDS) builder.readTimeout(60, TimeUnit.SECONDS) builder.retryOnConnectionFailure(false) if (BuildConfig.DEBUG) { builder.addInterceptor(ChuckInterceptor(context)) } builder.addInterceptor(AppInterceptor()) return builder.build() } class AppInterceptor : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { val original = chain.request() return chain.proceed(getRequest(original)) } fun getRequest(original: Request): Request { var builder = original.newBuilder() builder.addHeader("Content-Type", "application/json") builder.addHeader("Connection", "close") builder.addHeader("X-MobileLang", Prefs.getLang()) builder.addHeader("X-Mobile-Type", "android") builder.addHeader("X-Mobile-Version", BuildConfig.VERSION_CODE.toString()) builder.addHeader("Authorization", Credentials.basic(username, password)) if (Prefs.getToken() != null && !Prefs.getToken().isEmpty()) { builder.addHeader("token", Prefs.getToken()) } builder.method(original.method(), original.body()) return builder.build() } } } class MapActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnCameraMoveListener, GoogleMap.OnCameraMoveCanceledListener, GoogleMap.OnCameraIdleListener { companion object { const val REQUEST_CHECK_SETTINGS = 43 } private lateinit var googleMap: GoogleMap private lateinit var fusedLocationProviderClient: FusedLocationProviderClient var marker: com.google.android.gms.maps.model.Marker? = null var locationModel: AddressModel? = null var locationUpdated = false override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_map) val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment? mapFragment!!.getMapAsync(this) fusedLocationProviderClient = FusedLocationProviderClient(this) cardViewSelect.setOnClickListener { if (locationModel != null) { EventBus.getDefault() .post(EventModel(Constants.EVENT_SELECT_ADDRESS, locationModel)) finish() } else{ showWarning("Пожалуйста, выберите место доставки.") } Download 122.69 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2025
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling