Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #281 Download/more button in app lists
- Loading branch information
Showing
31 changed files
with
468 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/github/yeriomin/yalpstore/AppListDownloadReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.github.yeriomin.yalpstore; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
|
||
import com.github.yeriomin.yalpstore.view.AppBadge; | ||
|
||
public class AppListDownloadReceiver extends ForegroundDownloadReceiver { | ||
|
||
public AppListDownloadReceiver(AppListActivity activity) { | ||
super(activity); | ||
} | ||
|
||
@Override | ||
protected void cleanup() { | ||
draw(); | ||
} | ||
|
||
@Override | ||
protected void draw() { | ||
AppBadge appBadge = getAppBadge(); | ||
if (null != appBadge) { | ||
appBadge.redrawMoreButton(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void process(Context context, Intent intent) { | ||
AppListActivity activity = (AppListActivity) activityRef.get(); | ||
if (!activity.getListedPackageNames().contains(state.getApp().getPackageName())) { | ||
return; | ||
} | ||
super.process(context, intent); | ||
} | ||
|
||
private AppBadge getAppBadge() { | ||
if (null == activityRef.get() || null == state || null == state.getApp()) { | ||
return null; | ||
} | ||
return (AppBadge) ((AppListActivity) activityRef.get()).getListItem(state.getApp().getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 14 additions & 19 deletions
33
app/src/main/java/com/github/yeriomin/yalpstore/DownloadProgressBarUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,38 @@ | ||
package com.github.yeriomin.yalpstore; | ||
|
||
import android.util.Pair; | ||
import android.view.View; | ||
import android.widget.ProgressBar; | ||
|
||
import java.lang.ref.WeakReference; | ||
|
||
public class DownloadProgressBarUpdater extends RepeatingTask { | ||
public class DownloadProgressBarUpdater extends DownloadProgressUpdater { | ||
|
||
private String packageName; | ||
private WeakReference<ProgressBar> progressBarRef = new WeakReference<>(null); | ||
|
||
public DownloadProgressBarUpdater(String packageName, ProgressBar progressBar) { | ||
this.packageName = packageName; | ||
super(packageName); | ||
progressBarRef = new WeakReference<>(progressBar); | ||
} | ||
|
||
@Override | ||
protected boolean shouldRunAgain() { | ||
DownloadState state = DownloadState.get(packageName); | ||
return null != state && !state.isEverythingFinished(); | ||
protected void setProgress(int progress, int max) { | ||
ProgressBar progressBar = progressBarRef.get(); | ||
if (null == progressBar) { | ||
return; | ||
} | ||
progressBar.setIndeterminate(false); | ||
progressBar.setVisibility(View.VISIBLE); | ||
progressBar.setProgress(progress); | ||
progressBar.setMax(max); | ||
} | ||
|
||
@Override | ||
protected void payload() { | ||
protected void finish() { | ||
ProgressBar progressBar = progressBarRef.get(); | ||
if (null == progressBar) { | ||
return; | ||
} | ||
DownloadState state = DownloadState.get(packageName); | ||
if (null == state || state.isEverythingFinished()) { | ||
progressBar.setVisibility(View.INVISIBLE); | ||
progressBar.setIndeterminate(true); | ||
return; | ||
} | ||
Pair<Integer, Integer> progress = state.getProgress(); | ||
progressBar.setIndeterminate(false); | ||
progressBar.setVisibility(View.VISIBLE); | ||
progressBar.setProgress(progress.first); | ||
progressBar.setMax(progress.second); | ||
progressBar.setVisibility(View.INVISIBLE); | ||
progressBar.setIndeterminate(true); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/github/yeriomin/yalpstore/DownloadProgressUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.github.yeriomin.yalpstore; | ||
|
||
import android.util.Pair; | ||
|
||
abstract public class DownloadProgressUpdater extends RepeatingTask { | ||
|
||
private String packageName; | ||
|
||
abstract protected void setProgress(int progress, int max); | ||
abstract protected void finish(); | ||
|
||
public DownloadProgressUpdater(String packageName) { | ||
this.packageName = packageName; | ||
} | ||
|
||
@Override | ||
protected boolean shouldRunAgain() { | ||
DownloadState state = DownloadState.get(packageName); | ||
return null != state && !state.isEverythingFinished(); | ||
} | ||
|
||
@Override | ||
protected void payload() { | ||
DownloadState state = DownloadState.get(packageName); | ||
if (null == state || state.isEverythingFinished()) { | ||
finish(); | ||
} else { | ||
Pair<Integer, Integer> progress = state.getProgress(); | ||
setProgress(progress.first, progress.second); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/com/github/yeriomin/yalpstore/DownloadProgressUpdaterFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.github.yeriomin.yalpstore; | ||
|
||
import android.widget.ProgressBar; | ||
|
||
import com.github.yeriomin.yalpstore.view.AppBadge; | ||
|
||
public class DownloadProgressUpdaterFactory { | ||
|
||
static public DownloadProgressUpdater get(YalpStoreActivity activity, String packageName) { | ||
if (activity instanceof DetailsActivity) { | ||
return get((DetailsActivity) activity, packageName); | ||
} else if (activity instanceof AppListActivity) { | ||
return get((AppListActivity) activity, packageName); | ||
} | ||
return null; | ||
} | ||
|
||
static private DownloadProgressUpdater get(DetailsActivity activity, String packageName) { | ||
return new DownloadProgressBarUpdater(packageName, (ProgressBar) activity.findViewById(R.id.download_progress)); | ||
} | ||
|
||
static private DownloadProgressUpdater get(AppListActivity activity, String packageName) { | ||
return new ListItemDownloadProgressUpdater(packageName, (AppBadge) activity.getListItem(packageName)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.