mirror of https://github.com/ThmmyNoLife/mTHMMY
Apostolos Fanakis
6 years ago
7 changed files with 227 additions and 50 deletions
@ -0,0 +1,75 @@ |
|||||
|
package gr.thmmy.mthmmy.services; |
||||
|
|
||||
|
import android.content.Context; |
||||
|
|
||||
|
import com.snatik.storage.Storage; |
||||
|
|
||||
|
import net.gotev.uploadservice.ServerResponse; |
||||
|
import net.gotev.uploadservice.UploadInfo; |
||||
|
import net.gotev.uploadservice.UploadServiceBroadcastReceiver; |
||||
|
|
||||
|
import gr.thmmy.mthmmy.activities.upload.UploadsHelper; |
||||
|
import gr.thmmy.mthmmy.base.BaseApplication; |
||||
|
|
||||
|
public class UploadsReceiver extends UploadServiceBroadcastReceiver { |
||||
|
public interface Delegate { |
||||
|
void onProgress(long uploadedBytes, long totalBytes, int progress, double uploadRate); |
||||
|
|
||||
|
void onError(Exception exception); |
||||
|
|
||||
|
void onCompleted(int serverResponseCode, byte[] serverResponseBody); |
||||
|
|
||||
|
void onCancelled(); |
||||
|
} |
||||
|
|
||||
|
private Delegate delegate; |
||||
|
private Storage storage; |
||||
|
|
||||
|
public void setDelegate(Delegate delegate) { |
||||
|
this.delegate = delegate; |
||||
|
} |
||||
|
|
||||
|
public void provideStorage(Storage storage) { |
||||
|
this.storage = storage; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onProgress(Context context, UploadInfo uploadInfo) { |
||||
|
if (delegate != null) { |
||||
|
delegate.onProgress(uploadInfo.getUploadedBytes(), uploadInfo.getTotalBytes(), |
||||
|
uploadInfo.getProgressPercent(), uploadInfo.getUploadRate()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse, |
||||
|
Exception exception) { |
||||
|
if (delegate != null) { |
||||
|
delegate.onError(exception); |
||||
|
} |
||||
|
if (storage != null){ |
||||
|
UploadsHelper.deleteTempFiles(storage); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) { |
||||
|
if (delegate != null) { |
||||
|
delegate.onCompleted(serverResponse.getHttpCode(), serverResponse.getBody()); |
||||
|
} |
||||
|
if (storage != null){ |
||||
|
UploadsHelper.deleteTempFiles(storage); |
||||
|
} |
||||
|
BaseApplication.getInstance().logFirebaseAnalyticsEvent("file_upload", null); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onCancelled(Context context, UploadInfo uploadInfo) { |
||||
|
if (delegate != null) { |
||||
|
delegate.onCancelled(); |
||||
|
} |
||||
|
if (storage != null){ |
||||
|
UploadsHelper.deleteTempFiles(storage); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,38 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
|
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="match_parent" |
||||
|
android:orientation="vertical" |
||||
|
android:paddingEnd="24dp" |
||||
|
android:paddingStart="24dp"> |
||||
|
|
||||
|
<TextView |
||||
|
android:id="@+id/dialog_title" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_marginBottom="20dp" |
||||
|
android:layout_marginTop="24dp" |
||||
|
android:text="@string/upload_progress_dialog_title" |
||||
|
android:textColor="@color/accent" |
||||
|
android:textSize="20sp" /> |
||||
|
|
||||
|
<me.zhanghai.android.materialprogressbar.MaterialProgressBar |
||||
|
android:id="@+id/dialogProgressBar" |
||||
|
style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal.NoPadding" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="@dimen/progress_bar_height" |
||||
|
android:indeterminate="false" |
||||
|
app:mpb_progressStyle="horizontal" |
||||
|
app:mpb_progressTint="@color/accent" /> |
||||
|
|
||||
|
<TextView |
||||
|
android:id="@+id/dialog_bytes_uploaded" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_marginBottom="20dp" |
||||
|
android:layout_marginTop="12dp" |
||||
|
android:minEms="64" |
||||
|
android:text="@string/upload_progress_dialog_bytes_uploaded" |
||||
|
android:textColor="@color/white" /> |
||||
|
</LinearLayout> |
Loading…
Reference in new issue