Following is the scenario, I have 2 methods which create a Dialog in which the user can download data.
If the user clicks the (normal) download button, method showDownloads is triggered:
@Click(R.id.downloads)
public void showDownloads() {
Utils.processSubstring(releaseModel.getContent());
DownloadsDialog dialog = DownloadsDialog.getInstance(Utils.totalUrls.toArray(new String[Utils.totalUrls.size()]), DownloadsDialog.TYPE_USUAL);
dialog.show(getSupportFragmentManager(), DownloadsDialog.TAG);
}
If he/she clicks the premium download button the 2nd method is triggered, loadPremium:
public void loadPremium() {
Utils.processPremium(releaseModel.getContent());
DownloadsDialog dialog = DownloadsDialog.getInstance(Utils.totalUrls.toArray(new String[Utils.totalUrls.size()]), DownloadsDialog.TYPE_PREMIUM);
dialog.show(getSupportFragmentManager(), DownloadsDialog.TAG);
}
Both Dialogs, pass an instance (DownloadsDialog.TYPE_USUAL or DownloadsDialog.TYPE_PREMIUM) which identifies, which button has been clicked and which Dialog should be shown to the user.
In the DownloadAdapter I then set the color of the text for the instance of the Dialog which has been called. BROWN for normal download, GREEN for premium.
I intend to do this through a for-loop, as several items are being crosschecked but I have problems as the I can`t get it that when the normal doenload Dialog shows all the items are set color BROWN and when the premium dialog shows all items are set to GREEN.
Below screenshots show how it should be but I get only GREEN items for BOTH dialogs or BROWN items for BOTH dialogs.
I assume there is something wrong with my if-else statements but I don`t know for sure.
Normal downloads:
Here is the code from the method in the DownloadAdapter which sets the colors:
for (int i = 0; i < Premium_Urls.size(); i++) {
if (!Premium_Urls.get(i).contains(item) && !Utils.totalUrls.get(position).contains("http")) {
Spannable wordtoSpan = new SpannableString(item);
wordtoSpan.setSpan(new ForegroundColorSpan(Color.parseColor("#000000")), 0, item.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
wordtoSpan.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, item.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
holder.text.setText(wordtoSpan);
}
if (type == TYPE_USUAL) {
if (item.contains(Premium_Urls.get(i)) || Utils.totalUrls.toString().contains("http"))
holder.text.setText(item);
}
else if (type == TYPE_PREMIUM || (item.contains(Premium_Urls.get(i))
|| Utils.totalUrls.contains("http") {
Spannable wordtoSpan = new SpannableString(item);
wordtoSpan.setSpan(new ForegroundColorSpan(Color.parseColor("#139044")), 0, item.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
holder.text.setText(wordtoSpan);
}
}
Aucun commentaire:
Enregistrer un commentaire