我已经使用Glide下载图像很长时间了,所以这样的代码无处不在:
import re
s = "1236.0"
r = re.compile(r'[1-9]')
r2 = re.compile(r'(\.)')
if re.search(r,s) and re.search(r2,s):
print("Float")
if re.search(r,s) and not re.search(r2,s):
print("Integer")
突然之间,我需要记录每个图像的URL进行进一步分析。而不是搜索Glade的每种用法并像这样更改代码:
GlideApp.with(getContext())
.load(imgUrl)
.into(imgView);
有什么办法可以像在Glide的默认选项中那样全局地添加requestListener,这样我就不需要搜索和更改整个应用程序中的所有Glide使用情况?
我使用的是Glide v4,我已经检查了post,该网址直接将网址记录到logcat中,但没有记录到本地存储中以进行进一步分析。
答案 0 :(得分:3)
Glide 4.9.0可以设置默认的requestListener。
链接https://github.com/bumptech/glide/releases/tag/v4.9.0 https://github.com/bumptech/glide/commit/37127f0f817d4a11dfdcc447946397b5288de593
在自定义AppGlideModule中
public class Libreria : INotifyPropertyChanged
{
[PrimaryKey]
public Guid Id { get; set; }
public Tipo Tipo { get; set; }
public int IdTipo { get; set; }
public int NrOggetti { get; set; }
public string DataUltimaApertura { get; set; }
string _label;
string _icon;
public Libreria()
{
}
public string Label
{
set
{
if (_label != value)
{
_label = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Label"));
}
}
}
get
{
return _label;
}
}
public string Icona
{
set
{
if (_icon != value)
{
_icon = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Icona"));
}
}
}
get
{
return _icon;
}
}
public string EtichettaNrOggetti
{
get
{
return string.Format("Nr. elementi: {0}", NrOggetti);
}
}
public List<Libreria> GetLibrerie()
{
string query = string.Format("SELECT COUNT(oggetto.idlibreria) AS NrOggetti, Label, IdTipo, DataUltimaApertura, Icona FROM libreria LEFT JOIN oggetto ON libreria.id = oggetto.idlibreria GROUP BY libreria.id ORDER BY dataultimaapertura DESC");
return App.DBConnection.Query<Libreria>(query);
// return App.DBConnection.Table<Libreria>().OrderByDescending(lib => lib.Dataultimaapertura).ToList();
}
public Guid Insert()
{
this.Id = Guid.NewGuid();
string query = string.Format("INSERT INTO libreria(id, idtipo, label, dataultimaapertura, icona) VALUES('" + this.Id + "'," + this.IdTipo + ",'" + this.Label + "', '" + this.DataUltimaApertura + "', '" + this.Icona + "')");
App.DBConnection.Execute(query);
return this.Id;
}
public event PropertyChangedEventHandler PropertyChanged;
}
自定义活动片段中
@GlideModule
public class MyAppGlideModule extends AppGlideModule {
@Override
public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
builder.addGlobalRequestListener(new RequestListener<Object>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Object> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Object resource, Object model, Target<Object> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
});
}
}
GlideApp.with(object).addDefaultRequestListener()