¿Как модуль Glide в CustomInfoWindow? Kotlin - PullRequest
0 голосов
/ 06 августа 2020

В настоящее время я использую Glide для загрузки изображений в свое приложение. Он отлично работает, пока мне не нужно загрузить изображение в CustomInfoWindow. Я получаю предупреждение, которое связано с проблемой, также я думаю, что это как-то связано с доступным кешем.

Предупреждение:

Logcat:

W/Glide: Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored
I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:5
I/DynamiteModule: Selected remote version of com.google.android.gms.googlecertificates, version >= 5
W/zygote: Skipping duplicate class check due to unrecognized classloader
I/zygote: Do full code cache collection, code=508KB, data=376KB
I/zygote: After code cache collection, code=402KB, data=275KB

build.gradle, import и class:

build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.0"

    defaultConfig {
        applicationId "com.example.xxxx"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 2
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.1'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-rc1'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.firebase:firebase-analytics:17.4.4'
    implementation 'com.google.firebase:firebase-auth-ktx:19.3.2'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'androidx.navigation:navigation-fragment:2.3.0'
    implementation 'androidx.navigation:navigation-ui:2.3.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
    implementation 'com.android.support:appcompat-v7'
    implementation 'com.google.firebase:firebase-auth:19.3.2'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.google.android.gms:play-services-auth:18.1.0'
    implementation 'com.google.firebase:firebase-firestore:21.5.0'
    implementation 'com.google.firebase:firebase-storage-ktx:19.1.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
    implementation 'com.google.firebase:firebase-core:17.4.4'
    implementation 'com.google.firebase:firebase-auth:19.3.2'
    implementation 'com.google.firebase:firebase-storage-ktx:19.1.1'
    implementation 'com.google.firebase:firebase-database-ktx:19.3.1'
    implementation 'com.google.firebase:firebase-messaging:20.2.3'
    implementation 'com.firebaseui:firebase-ui-storage:6.2.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19'
}

импорт

import android.Manifest
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.Point
import android.location.Location
import android.location.LocationManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.provider.MediaStore
import android.util.Log
import android.view.View
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.Toast
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.view.GravityCompat
import androidx.core.view.isGone
import androidx.core.view.isVisible
import com.bumptech.glide.Glide
import com.example.mappet001.reports.ReportPet
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationServices
import com.google.android.gms.maps.*
import com.google.android.gms.maps.model.*
import com.google.firebase.Timestamp
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.firestore.FieldValue
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.GeoPoint
import com.google.firebase.storage.FirebaseStorage
import kotlinx.android.synthetic.main.activity_maps.*
import kotlinx.android.synthetic.main.content_main.*
import kotlinx.android.synthetic.main.form_report.*
import kotlinx.android.synthetic.main.reportvisor_maps.view.*
import java.io.ByteArrayOutputStream
import java.io.File
import java.text.SimpleDateFormat
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.cos
import kotlin.math.sin

Класс

    //class InfoWindowAdapter
    inner class CustomInfoWindowGoogleMap(val context: Context) : GoogleMap.InfoWindowAdapter {

        override fun getInfoContents(p0: Marker?): View? {
            return null
        }

        @SuppressLint("InflateParams")
        override fun getInfoWindow(p0: Marker?): View? {
            val mInfoView = (context as Activity).layoutInflater.inflate(R.layout.reportvisor_maps, null)
            val mInfoWindow: ReportPet? = p0?.tag as ReportPet?

            mInfoView.title_window.text = mInfoWindow?.mTitleReport
            mInfoView.date_ReportVisor.text = mInfoWindow?.mDate
            mInfoView.description_ReportVisor.text = mInfoWindow?.mdescriptionReport
            mInfoView.type_ReportVisor.text = mInfoWindow?.mTypeReport
            try {
                val imageReportVisor = mInfoView.findViewById<ImageView>(R.id.image_ReportVisor)
                Glide.with(context).load(mInfoWindow?.mImageReport).into(imageReportVisor) // image
            }catch (e: Exception){
                Log.d("ERRORGLIDE","e: ${e.message}")
            }
            return mInfoView
        }
    }

затем вызываю маркер в onMapReady:

//marker + infoWindow
        mMap.setOnMarkerClickListener{
            if (it.isInfoWindowShown){
                it.hideInfoWindow()
            }else{
                it.showInfoWindow()
                zoomMarker(it.position)
            }
            true
        }

пожалуйста, помогите мне!

Спасибо

1 Ответ

0 голосов
/ 07 августа 2020

Для реализации AppGlideModule изменения в Build.Gradle :

implementation 'com.android.support:appcompat-v7' cambiar a esto:
implementation 'com.android.support:appcompat-v7:27.0.2'

В Build.Gradle добавьте зависимости плагина y:

apply plugin: 'kotlin-kapt'

dependencies {
  ...
  compile 'com.github.bumptech.glide:glide:4.11.0'
  kapt 'com.github.bumptech.glide:compiler:4.11.0'
}

синхронизируйте градиент

Добавьте класс под названием MyAppGlideModule :

Pakage com.example.NombreApp

import com.bumptech.glide.GlideBuilder
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.module.AppGlideModule
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.signature.ObjectKey

@GlideModule
class MyAppGlideModule: AppGlideModule(){}

Прежде чем продолжить, важно упомянуть, что если вы использовали Glide в качестве библиотеки, вы должны прокомментировать или удалить импорт glide: // import com.bumptech.glide.Glide.

Теперь в классе (YourClass), который вы хотите использовать AppGlide , реализуйте модуль следующим образом:
GlideApp.with(context).load(url).into(imageView)
По завершении перестройте проект:

Build -> Rebuild Proyect
источник: Youtube

...