Skip to content

Commit

Permalink
Bug: fix loading if there is no network
Browse files Browse the repository at this point in the history
  • Loading branch information
androidlover5842 committed Dec 21, 2016
1 parent 691a2dc commit 322a2a3
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 69 deletions.
3 changes: 3 additions & 0 deletions .idea/markdown-navigator/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import android.Manifest;
import android.app.Activity;
import android.app.DownloadManager;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
Expand Down Expand Up @@ -38,84 +41,113 @@ protected void onCreate(Bundle savedInstanceState) {
UpdaterDialog= new PanterDialog(DialogActivity.this);
mNoUpdate = new PromptDialog(this);
ActivityCompat.requestPermissions(DialogActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 100);
RomUpdaterUtils romUpdaterUtils = new RomUpdaterUtils(this)
.setUpdateFrom(UpdateFrom.XML)
.setUpdateXML(UpdaterUri())
.withListener(new RomUpdaterUtils.UpdateListener() {
@Override
public void onSuccess(final Update update, Boolean isUpdateAvailable) {
if(Showlog().equals(true));
{
Log.d(Tag, "Update Found");
Log.d(Tag, update.getLatestVersion() + ", " + update.getUrlToDownload() + ", " + Boolean.toString(isUpdateAvailable));
}
if(isUpdateAvailable==false){
mProgressBar.setVisibility(View.GONE);
if(Showlog().equals(true));
if(isOnline()) {
RomUpdaterUtils romUpdaterUtils = new RomUpdaterUtils(this)
.setUpdateFrom(UpdateFrom.XML)
.setUpdateXML(UpdaterUri())
.withListener(new RomUpdaterUtils.UpdateListener() {
@Override
public void onSuccess(final Update update, Boolean isUpdateAvailable) {
if (Showlog().equals(true)) ;
{
Log.i(Tag, "No update found "+String.valueOf(isUpdateAvailable));
Log.d(Tag, "Update Found");
Log.d(Tag, update.getLatestVersion() + ", " + update.getUrlToDownload() + ", " + Boolean.toString(isUpdateAvailable));
}
mNoUpdate.setTitle("No Updates Found");
mNoUpdate.setDialogType(PromptDialog.DIALOG_TYPE_WRONG)
.setAnimationEnable(true)
.setTitleText("No update found")
.setContentText("Try again later")
.setPositiveListener("Ok", new PromptDialog.OnPositiveListener() {
@Override
public void onClick(PromptDialog dialog) {
mNoUpdate.dismiss();
finish();
}
}).show();
}
if (isUpdateAvailable == false) {
mProgressBar.setVisibility(View.GONE);
if (Showlog().equals(true)) ;
{
Log.i(Tag, "No update found " + String.valueOf(isUpdateAvailable));
}
mNoUpdate.setTitle("No Updates Found");
mNoUpdate.setDialogType(PromptDialog.DIALOG_TYPE_WRONG)
.setAnimationEnable(true)
.setTitleText("No update found")
.setContentText("Try again later")
.setPositiveListener("Ok", new PromptDialog.OnPositiveListener() {
@Override
public void onClick(PromptDialog dialog) {
mNoUpdate.dismiss();
finish();
}
}).show();
}

if (isUpdateAvailable == true) {
mProgressBar.setVisibility(View.GONE);
UpdaterDialog.setTitle("Update Found")
.setHeaderBackground(R.color.colorPrimaryDark)
.setMessage("Changelog :- \n\n" + update.getReleaseNotes())
.setPositive("Download", new View.OnClickListener() {
@Override
public void onClick(View view) {
Uri uri = Uri.parse(String.valueOf(update.getUrlToDownload()));
downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(uri);
String fileName = uri.getLastPathSegment();
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);

if(isUpdateAvailable==true)
{
mProgressBar.setVisibility(View.GONE);
UpdaterDialog.setTitle("Update Found")
.setHeaderBackground(R.color.colorPrimaryDark)
.setMessage("Changelog :- \n\n"+update.getReleaseNotes())
.setPositive("Download",new View.OnClickListener() {
@Override
public void onClick(View view) {
Uri uri = Uri.parse(String.valueOf(update.getUrlToDownload()));
downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(uri);
String fileName = uri.getLastPathSegment();
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,fileName);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
Long reference = downloadManager.enqueue(request);
UpdaterDialog.dismiss();

request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
Long reference = downloadManager.enqueue(request);
UpdaterDialog.dismiss();
}
})
.setNegative("DISMISS", new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
UpdaterDialog.dismiss();
}
})
.isCancelable(false)
.withAnimation(Animation.SIDE)
.show();
if (Showlog().equals(true)) ;
{
Log.d("Found", String.valueOf(update.getUrlToDownload()));
}
}
}

}
})
.setNegative("DISMISS", new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
UpdaterDialog.dismiss();
}
})
.isCancelable(false)
.withAnimation(Animation.SIDE)
.show();
if(Showlog().equals(true));
@Override
public void onFailed(RomUpdaterError error) {
if (Showlog().equals(true)) ;
{
Log.d("Found", String.valueOf(update.getUrlToDownload()));
Log.d("RomUpdater", "Something went wrong");
}
}
}
@Override
public void onFailed(RomUpdaterError error) {
if(Showlog().equals(true));
{
Log.d("RomUpdater", "Something went wrong");

});
romUpdaterUtils.start();
} else
{
mProgressBar.setVisibility(View.GONE);
mNoUpdate.setTitle("No network found");
mNoUpdate.setDialogType(PromptDialog.DIALOG_TYPE_WRONG)
.setAnimationEnable(true)
.setTitleText("No network found")
.setContentText("Please connect to network")
.setPositiveListener("Ok", new PromptDialog.OnPositiveListener() {
@Override
public void onClick(PromptDialog dialog) {
mNoUpdate.dismiss();
finish();
}
}
}).show();

}

});
romUpdaterUtils.start();
}
public boolean isOnline() {
ConnectivityManager conMgr = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = conMgr.getActiveNetworkInfo();

if(netInfo == null || !netInfo.isConnected() || !netInfo.isAvailable()){
Log.i(Tag,"No Internet connection");
return false;
}
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

public class Config {
public static boolean ShowLog;
public static String URL_OLD_RELEASES;
public static String URL_OLD_RELEASES(){
ShellExecuter.command="getprop ro.updater.oldrelease.url";
String output=ShellExecuter.runAsRoot();
Expand Down

0 comments on commit 322a2a3

Please sign in to comment.