Fix issue with blinking in recycler view
This commit is contained in:
parent
3828d2ec51
commit
98a56ceb73
4 changed files with 95 additions and 70 deletions
|
@ -137,13 +137,13 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNeededMapsCard(TravelNeededMapsCard card) {
|
public void addNeededMapsCard(TravelNeededMapsCard card) {
|
||||||
if (addItem(getNeededMapsCardPosition(), card)) {
|
if (addItem(getNeededMapsCardPosition(), card)) {
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateNeededMapsCard() {
|
public void updateNeededMapsCard(boolean onlyProgress) {
|
||||||
int pos = getNeededMapsCardPosition();
|
int pos = getNeededMapsCardPosition();
|
||||||
if (neededMapsCardExists(pos)) {
|
if (neededMapsCardExists(pos)) {
|
||||||
notifyItemChanged(pos);
|
notifyItemChanged(pos);
|
||||||
|
@ -169,13 +169,13 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||||
return items.size() > position && items.get(position).getCardType() == TravelNeededMapsCard.TYPE;
|
return items.size() > position && items.get(position).getCardType() == TravelNeededMapsCard.TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDownloadUpdateCard(TravelDownloadUpdateCard card) {
|
public void addDownloadUpdateCard(TravelDownloadUpdateCard card) {
|
||||||
if (addItem(getDownloadUpdateCardPosition(), card)) {
|
if (addItem(getDownloadUpdateCardPosition(), card)) {
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateDownloadUpdateCard() {
|
public void updateDownloadUpdateCard(boolean onlyProgress) {
|
||||||
int pos = getDownloadUpdateCardPosition();
|
int pos = getDownloadUpdateCardPosition();
|
||||||
if (downloadUpdateCardExists(pos)) {
|
if (downloadUpdateCardExists(pos)) {
|
||||||
notifyItemChanged(pos);
|
notifyItemChanged(pos);
|
||||||
|
|
|
@ -90,8 +90,8 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
||||||
currentDownloadingIndexItem = current;
|
currentDownloadingIndexItem = current;
|
||||||
removeRedundantCards();
|
removeRedundantCards();
|
||||||
}
|
}
|
||||||
adapter.updateDownloadUpdateCard();
|
adapter.updateDownloadUpdateCard(true);
|
||||||
adapter.updateNeededMapsCard();
|
adapter.updateNeededMapsCard(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -194,7 +194,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
||||||
public void onPrimaryButtonClick() {
|
public void onPrimaryButtonClick() {
|
||||||
if (mainIndexItem != null) {
|
if (mainIndexItem != null) {
|
||||||
downloadManager.startDownload(getMyActivity(), mainIndexItem);
|
downloadManager.startDownload(getMyActivity(), mainIndexItem);
|
||||||
adapter.updateDownloadUpdateCard();
|
adapter.updateDownloadUpdateCard(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
||||||
public void onSecondaryButtonClick() {
|
public void onSecondaryButtonClick() {
|
||||||
if (downloadUpdateCard.isLoading()) {
|
if (downloadUpdateCard.isLoading()) {
|
||||||
downloadThread.cancelDownload(mainIndexItem);
|
downloadThread.cancelDownload(mainIndexItem);
|
||||||
adapter.updateDownloadUpdateCard();
|
adapter.updateDownloadUpdateCard(false);
|
||||||
} else if (!downloadUpdateCard.isDownload()) {
|
} else if (!downloadUpdateCard.isDownload()) {
|
||||||
removeDownloadUpdateCard();
|
removeDownloadUpdateCard();
|
||||||
} else if (downloadUpdateCard.isShowOtherMapsBtn()) {
|
} else if (downloadUpdateCard.isShowOtherMapsBtn()) {
|
||||||
|
@ -217,7 +217,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
downloadUpdateCard.setIndexItem(mainIndexItem);
|
downloadUpdateCard.setIndexItem(mainIndexItem);
|
||||||
adapter.setDownloadUpdateCard(downloadUpdateCard);
|
adapter.addDownloadUpdateCard(downloadUpdateCard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,14 +230,14 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
||||||
@Override
|
@Override
|
||||||
public void onPrimaryButtonClick() {
|
public void onPrimaryButtonClick() {
|
||||||
downloadManager.startDownload(getMyActivity(), getAllItemsForDownload());
|
downloadManager.startDownload(getMyActivity(), getAllItemsForDownload());
|
||||||
adapter.updateNeededMapsCard();
|
adapter.updateNeededMapsCard(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSecondaryButtonClick() {
|
public void onSecondaryButtonClick() {
|
||||||
if (neededMapsCard.isDownloading()) {
|
if (neededMapsCard.isDownloading()) {
|
||||||
app.getDownloadThread().cancelDownload(neededIndexItems);
|
app.getDownloadThread().cancelDownload(neededIndexItems);
|
||||||
adapter.updateNeededMapsCard();
|
adapter.updateNeededMapsCard(false);
|
||||||
} else {
|
} else {
|
||||||
removeNeededMapsCard();
|
removeNeededMapsCard();
|
||||||
}
|
}
|
||||||
|
@ -257,11 +257,11 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
||||||
} else if (!item.isDownloaded()) {
|
} else if (!item.isDownloaded()) {
|
||||||
downloadManager.startDownload(getMyActivity(), item);
|
downloadManager.startDownload(getMyActivity(), item);
|
||||||
}
|
}
|
||||||
adapter.updateNeededMapsCard();
|
adapter.updateNeededMapsCard(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
adapter.setNeededMapsCard(neededMapsCard);
|
adapter.addNeededMapsCard(neededMapsCard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,11 @@ import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.download.IndexItem;
|
import net.osmand.plus.download.IndexItem;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
|
|
||||||
public class TravelDownloadUpdateCard extends BaseTravelCard {
|
public class TravelDownloadUpdateCard extends BaseTravelCard {
|
||||||
|
@ -23,6 +23,7 @@ public class TravelDownloadUpdateCard extends BaseTravelCard {
|
||||||
|
|
||||||
private boolean download;
|
private boolean download;
|
||||||
private boolean showOtherMapsBtn;
|
private boolean showOtherMapsBtn;
|
||||||
|
private WeakReference<DownloadUpdateVH> ref;
|
||||||
|
|
||||||
private ClickListener listener;
|
private ClickListener listener;
|
||||||
|
|
||||||
|
@ -62,6 +63,7 @@ public class TravelDownloadUpdateCard extends BaseTravelCard {
|
||||||
if (viewHolder instanceof DownloadUpdateVH) {
|
if (viewHolder instanceof DownloadUpdateVH) {
|
||||||
boolean loading = isLoading();
|
boolean loading = isLoading();
|
||||||
DownloadUpdateVH holder = (DownloadUpdateVH) viewHolder;
|
DownloadUpdateVH holder = (DownloadUpdateVH) viewHolder;
|
||||||
|
this.ref = new WeakReference<TravelDownloadUpdateCard.DownloadUpdateVH>(holder);
|
||||||
holder.title.setText(getTitle(loading));
|
holder.title.setText(getTitle(loading));
|
||||||
holder.icon.setImageDrawable(getIcon());
|
holder.icon.setImageDrawable(getIcon());
|
||||||
holder.description.setText(getDescription());
|
holder.description.setText(getDescription());
|
||||||
|
@ -73,6 +75,22 @@ public class TravelDownloadUpdateCard extends BaseTravelCard {
|
||||||
holder.fileTitle.setText(getFileTitle());
|
holder.fileTitle.setText(getFileTitle());
|
||||||
holder.fileDescription.setText(getFileDescription());
|
holder.fileDescription.setText(getFileDescription());
|
||||||
holder.progressBar.setVisibility(loading ? View.VISIBLE : View.GONE);
|
holder.progressBar.setVisibility(loading ? View.VISIBLE : View.GONE);
|
||||||
|
updateProgressBar(holder);
|
||||||
|
}
|
||||||
|
boolean primaryBtnVisible = updatePrimaryButton(holder, loading);
|
||||||
|
boolean secondaryBtnVisible = updateSecondaryButton(holder, loading);
|
||||||
|
holder.buttonsDivider.setVisibility(primaryBtnVisible && secondaryBtnVisible ? View.VISIBLE : View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateProgresBar() {
|
||||||
|
DownloadUpdateVH holder = ref.get();
|
||||||
|
if (holder != null && holder.itemView.isShown()) {
|
||||||
|
updateProgressBar(holder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateProgressBar(DownloadUpdateVH holder) {
|
||||||
if (isLoadingInProgress()) {
|
if (isLoadingInProgress()) {
|
||||||
int progress = app.getDownloadThread().getCurrentDownloadingItemProgress();
|
int progress = app.getDownloadThread().getCurrentDownloadingItemProgress();
|
||||||
holder.progressBar.setProgress(progress < 0 ? 0 : progress);
|
holder.progressBar.setProgress(progress < 0 ? 0 : progress);
|
||||||
|
@ -80,11 +98,6 @@ public class TravelDownloadUpdateCard extends BaseTravelCard {
|
||||||
holder.progressBar.setProgress(0);
|
holder.progressBar.setProgress(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean primaryBtnVisible = updatePrimaryButton(holder, loading);
|
|
||||||
boolean secondaryBtnVisible = updateSecondaryButton(holder, loading);
|
|
||||||
holder.buttonsDivider.setVisibility(primaryBtnVisible && secondaryBtnVisible ? View.VISIBLE : View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCardType() {
|
public int getCardType() {
|
||||||
|
|
|
@ -10,14 +10,15 @@ import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.Version;
|
import net.osmand.plus.Version;
|
||||||
import net.osmand.plus.download.DownloadActivityType;
|
import net.osmand.plus.download.DownloadActivityType;
|
||||||
import net.osmand.plus.download.DownloadIndexesThread;
|
import net.osmand.plus.download.DownloadIndexesThread;
|
||||||
import net.osmand.plus.download.IndexItem;
|
import net.osmand.plus.download.IndexItem;
|
||||||
|
import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard.DownloadUpdateVH;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TravelNeededMapsCard extends BaseTravelCard {
|
public class TravelNeededMapsCard extends BaseTravelCard {
|
||||||
|
@ -29,7 +30,7 @@ public class TravelNeededMapsCard extends BaseTravelCard {
|
||||||
|
|
||||||
private Drawable downloadIcon;
|
private Drawable downloadIcon;
|
||||||
private Drawable cancelIcon;
|
private Drawable cancelIcon;
|
||||||
|
private WeakReference<NeededMapsVH> ref;
|
||||||
private CardListener listener;
|
private CardListener listener;
|
||||||
private View.OnClickListener onItemClickListener;
|
private View.OnClickListener onItemClickListener;
|
||||||
|
|
||||||
|
@ -57,11 +58,27 @@ public class TravelNeededMapsCard extends BaseTravelCard {
|
||||||
public void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder) {
|
public void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder) {
|
||||||
if (viewHolder instanceof NeededMapsVH) {
|
if (viewHolder instanceof NeededMapsVH) {
|
||||||
NeededMapsVH holder = (NeededMapsVH) viewHolder;
|
NeededMapsVH holder = (NeededMapsVH) viewHolder;
|
||||||
|
ref = new WeakReference<NeededMapsVH>(holder);
|
||||||
holder.description.setText(isInternetAvailable()
|
holder.description.setText(isInternetAvailable()
|
||||||
? R.string.maps_you_need_descr : R.string.no_index_file_to_download);
|
? R.string.maps_you_need_descr : R.string.no_index_file_to_download);
|
||||||
adjustChildCount(holder.itemsContainer);
|
adjustChildCount(holder.itemsContainer);
|
||||||
|
|
||||||
|
updateView(holder);
|
||||||
|
|
||||||
|
boolean primaryBtnVisible = updatePrimaryButton(holder);
|
||||||
|
boolean secondaryBtnVisible = updateSecondaryButton(holder);
|
||||||
|
holder.buttonsDivider.setVisibility(primaryBtnVisible && secondaryBtnVisible ? View.VISIBLE : View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateView() {
|
||||||
|
NeededMapsVH holder = ref.get();
|
||||||
|
if (holder != null && holder.itemView.isShown()) {
|
||||||
|
updateView(holder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateView(NeededMapsVH holder) {
|
||||||
boolean paidVersion = Version.isPaidVersion(app);
|
boolean paidVersion = Version.isPaidVersion(app);
|
||||||
|
|
||||||
for (int i = 0; i < items.size(); i++) {
|
for (int i = 0; i < items.size(); i++) {
|
||||||
|
@ -109,11 +126,6 @@ public class TravelNeededMapsCard extends BaseTravelCard {
|
||||||
|
|
||||||
view.findViewById(R.id.divider).setVisibility(lastItem ? View.GONE : View.VISIBLE);
|
view.findViewById(R.id.divider).setVisibility(lastItem ? View.GONE : View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean primaryBtnVisible = updatePrimaryButton(holder);
|
|
||||||
boolean secondaryBtnVisible = updateSecondaryButton(holder);
|
|
||||||
holder.buttonsDivider.setVisibility(primaryBtnVisible && secondaryBtnVisible ? View.VISIBLE : View.GONE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue