abdularis / androidbuttonprogress Goto Github PK
View Code? Open in Web Editor NEWProvides download button progress view for android
Provides download button progress view for android
I'm running the following code:
<com.github.abdularis.buttonprogress.DownloadButtonProgress
android:id="@+id/button_synchronize"
android:layout_width="32dp"
android:layout_height="32dp"
android:visibility="@{entry.canSynchronize() ? View.VISIBLE : View.GONE}"
app:buttonState="@{entry.synchronizationState}"
/>
and using data-binding to synchronize the button state and visibility.
I'm using the following databinding adapter:
public class DownloadButtonStateBindingAdapter {
@BindingAdapter("buttonState")
public static void setMyAttr(DownloadButtonProgress myInnerView, int value) {
switch (value) {
case DownloadButtonProgress.STATE_IDLE:
myInnerView.setIdle();
break;
case DownloadButtonProgress.STATE_INDETERMINATE:
myInnerView.setIndeterminate();
break;
case DownloadButtonProgress.STATE_DETERMINATE:
myInnerView.setDeterminate();
break;
case DownloadButtonProgress.STATE_FINISHED:
myInnerView.setFinish();
break;
default:
break;
}
}
}
unfortunately, the setIdle
, ... methods do more than just setting the state.
public void setIdle() {
mCurrState = STATE_IDLE;
setVisibility(VISIBLE);
invalidate();
}
This forces me to reset the visibility after each setIdle
call. Why are you setting the visibility here? Could you please remove that call?
sessionHolder.progressBar.addOnClickListener(new DownloadButtonProgress.OnClickListener() {
@Override
public void onIdleButtonClick(View view) {
download(ccModel.getUrl(), ccModel.getText3()+".mp3",path,sessionHolder);
}
@Override
public void onCancelButtonClick(View view) {
PRDownloader.cancelAll();
}
@Override
public void onFinishButtonClick(View view) {
}
});
private void download(String url, String fileName, String dirPath,final SessionHolder sessionHolder){
PRDownloaderConfig config = PRDownloaderConfig.newBuilder().setReadTimeout(30_000).setConnectTimeout(30_000).build();
PRDownloader.cancelAll();
PRDownloader.initialize(mcontext.getApplicationContext(), config);
PRDownloader.download(url, dirPath, fileName)
.build()
.setOnStartOrResumeListener(new OnStartOrResumeListener() {
@Override
public void onStartOrResume() {
// holder.progressBar.setVisibility(View.VISIBLE);
}
})
.setOnProgressListener(new OnProgressListener() {
@Override
public void onProgress(Progress progress) {
sessionHolder.progressBar.setDeterminate();
sessionHolder.progressBar.setCurrentProgress((int)(((float)progress.currentBytes/progress.totalBytes)*100));
}
}).setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel() {
Drawable n = AppCompatResources.getDrawable(mcontext , R.drawable.ic_cloud_download_black_24dp);
sessionHolder.progressBar.setCancelable(true);
}
}).start(new OnDownloadListener() {
@Override
public void onDownloadComplete() {
// holder.progressBar.setVisibility(View.GONE);
Toast.makeText(mcontext, "دانلود با موفقیت انجام شد", Toast.LENGTH_LONG).show();
sessionHolder.progressBar.setFinish();
}
@Override
public void onError(Error error) {
Toast.makeText(mcontext, "اتصال به اینترنت را چک کنید", Toast.LENGTH_LONG).show();
}
});
}
When using databinding like this:
<com.github.abdularis.buttonprogress.DownloadButtonProgress
android:id="@+id/button_download"
android:layout_width="32dp"
android:layout_height="32dp"
android:onClick="@{() -> viewModel.doSomething()}"
/>
the doSomething method is never called.
My current workaround is to use a binding adapter.
@BindingAdapter("downloadButtonOnClick")
public static void setOnClickListener(DownloadButtonProgress myInnerView, View.OnClickListener listener) {
myInnerView.setOnClickListener(listener);
}
and
<com.github.abdularis.buttonprogress.DownloadButtonProgress
android:id="@+id/button_download"
android:layout_width="32dp"
android:layout_height="32dp"
app:downloadButtonOnClick="@{() -> viewModel.doSomething()}"
/>
hello,
i'm trying to use recyclerview with your lib, but i have a bug , please check the video attached
https://drive.google.com/file/d/1uS0XcARWYRBejqxEOUvsf-aENLcUJDX9/view?usp=sharing
Is it possible that you can fix the below error in the next release?
It requires re-naming the attribute progress
to something else, to avoid compilation error due to conflicts with similar attirbutes already defined in AndroidX libraries. @abdularis
Hi;
Just tried your library, good work but i can not make it work, the lib is imported and shows in external libraries but DownloadButtonProgress Class is not found neither by designer nor in code, only thing appearing is the resource R in your packege !!
As there is no license provided for this project, I am unsure as to I am able to use it. Anyone able to clear that up?
Hello...First of all Nice Library...In your recent update having dependency
implementation 'com.github.abdularis:AndroidButtonProgress:1.0.1' has mistake that it includes capital letters which causes build failure...After minimizing it project builds succefully...So please correct it to implementation 'com.github.abdularis:androidbuttonprogress:1.0.1'
If anyone implemented this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.