/
githubmirror
/
omim
Обзор
Документация
Войти
/
githubmirror
/
omim
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
android/src/com/mapswithme/maps/downloader/DownloaderStatusIcon.java
112 строк
3 KB
Александр Зацепин
[android] Migrated code to Android X
22 окт 2019, 15:11
22 окт 2019, 15:11
f2dd324
Код
Авторство
О чём код?
package com.mapswithme.maps.downloader; import androidx.annotation.AttrRes; import androidx.annotation.DrawableRes; import android.util.SparseIntArray; import android.view.View; import android.widget.ImageView; import com.mapswithme.maps.R; import com.mapswithme.maps.widget.WheelProgressView; import com.mapswithme.util.ThemeUtils; import com.mapswithme.util.UiUtils; public class DownloaderStatusIcon { private final View mFrame; protected final ImageView mIcon; private final WheelProgressView mProgress; private static final SparseIntArray sIconsCache = new SparseIntArray(); public DownloaderStatusIcon(View frame) { mFrame = frame; mIcon = (ImageView) mFrame.findViewById(R.id.downloader_status); mProgress = (WheelProgressView) mFrame.findViewById(R.id.downloader_progress_wheel); } public DownloaderStatusIcon setOnIconClickListener(View.OnClickListener listener) { mIcon.setOnClickListener(listener); return this; } public DownloaderStatusIcon setOnCancelClickListener(View.OnClickListener listener) { mProgress.setOnClickListener(listener); return this; } protected @AttrRes int selectIcon(CountryItem country) { switch (country.status) { case CountryItem.STATUS_DONE: return R.attr.status_done; case CountryItem.STATUS_DOWNLOADABLE: case CountryItem.STATUS_PARTLY: return R.attr.status_downloadable; case CountryItem.STATUS_FAILED: return R.attr.status_failed; case CountryItem.STATUS_UPDATABLE: return R.attr.status_updatable; default: throw new IllegalArgumentException("Inappropriate item status: " + country.status); } } private @DrawableRes int resolveIcon(@AttrRes int iconAttr) { int res = sIconsCache.get(iconAttr); if (res == 0) { res = ThemeUtils.getResource(mFrame.getContext(), R.attr.downloaderTheme, iconAttr); sIconsCache.put(iconAttr, res); } return res; } protected void updateIcon(CountryItem country) { @AttrRes int iconAttr = selectIcon(country); @DrawableRes int icon = resolveIcon(iconAttr); mIcon.setImageResource(icon); } public void update(CountryItem country) { boolean pending = (country.status == CountryItem.STATUS_ENQUEUED); boolean inProgress = (country.status == CountryItem.STATUS_PROGRESS || country.status == CountryItem.STATUS_APPLYING || pending); UiUtils.showIf(inProgress, mProgress); UiUtils.showIf(!inProgress, mIcon); mProgress.setPending(pending); if (inProgress) { if (!pending) mProgress.setProgress(country.progress); return; } updateIcon(country); } public void show(boolean show) { UiUtils.showIf(show, mFrame); } public static void clearCache() { sIconsCache.clear(); } }