Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
MarsadMaqsood committed Mar 19, 2022
1 parent 1d843a6 commit 187dd1e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
import androidx.core.content.FileProvider;

public class AppUpdateFileProvider extends FileProvider {

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ public class DownloadDialog extends DialogFragment implements View.OnClickListen
private TextView mPercentage, mDownloadTitle;
private ProgressBar mProgressBar;
private DownLoadService mDownLoadService;
private final ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
DownLoadService.DownLoadBinder binder = (DownLoadService.DownLoadBinder) service;
mDownLoadService = binder.getService();
mDownLoadService.registerProgressListener(mProgressListener);
mDownLoadService.startDownLoad(mDownloadUrl);
mDownLoadService.setNotificationIcon(notificationIcon);
}

@Override
public void onServiceDisconnected(ComponentName name) {
mDownLoadService = null;
}
};
private boolean mMustUpdate;
private boolean mIsShowBackgroundDownload;
private OnFragmentOperation mOnFragmentOperation;
Expand All @@ -66,7 +81,7 @@ public void handleMessage(Message msg) {
Formatter.formatFileSize(getActivity().getApplication(), contentLength)));

mPercentage.setText(
String.format(getResources().getString(R.string.update_lib_file_percentage), (((bytesRead/1024) * 100) / (contentLength / 1024))
String.format(getResources().getString(R.string.update_lib_file_percentage), (((bytesRead / 1024) * 100) / (contentLength / 1024))
));


Expand Down Expand Up @@ -124,21 +139,6 @@ public void onError() {
mHandler.sendEmptyMessage(ERROR);
}
};
private final ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
DownLoadService.DownLoadBinder binder = (DownLoadService.DownLoadBinder) service;
mDownLoadService = binder.getService();
mDownLoadService.registerProgressListener(mProgressListener);
mDownLoadService.startDownLoad(mDownloadUrl);
mDownLoadService.setNotificationIcon(notificationIcon);
}

@Override
public void onServiceDisconnected(ComponentName name) {
mDownLoadService = null;
}
};

public static DownloadDialog newInstance(String downLoadUrl, int notificationIcon) {
Bundle args = new Bundle();
Expand Down Expand Up @@ -214,8 +214,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
}

mDownloadTitle.setText(mDownloadTitleText);


}

@Override
Expand Down Expand Up @@ -245,13 +243,16 @@ public void onClick(View view) {

@Override
public void onDestroy() {
if (getActivity() != null)
getActivity().unbindService(mConnection);
super.onDestroy();
getActivity().unbindService(mConnection);

}

private void doCancel() {
mDownLoadService.cancel();
getActivity().finish();
if (getActivity() != null)
getActivity().finish();
ToastUtils.show(getActivity(), R.string.update_lib_download_cancel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class CheckUpdateTask extends Thread {

private static final String TAG = "CheckUpdateTask";

private Context mContext;
private final Context mContext;
private Callback mCallBack;
private String mCheckUpdateUrl;
private Boolean mIsPost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public void onCreate() {
mNotificationManager.createNotificationChannel(channel);
}


}

public void startDownLoad(String url) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public void run() {
in = new BufferedInputStream(connection.getInputStream());
int count = connection.getContentLength();
if (count <= 0) {
Log.e(TAG, "file length must > 0");
Log.e(TAG, "file length must be > 0");
return;
}

if (in == null) {
Log.e(TAG, "InputStream not be null");
Log.e(TAG, "InputStream can not be null");
return;
}

Expand Down

0 comments on commit 187dd1e

Please sign in to comment.