receive Downloader error messages in swap
This commit is contained in:
		
							parent
							
								
									f0158063fb
								
							
						
					
					
						commit
						bc14e62e46
					
				@ -35,6 +35,7 @@ import org.fdroid.fdroid.localrepo.peers.PeerFinder;
 | 
			
		||||
import org.fdroid.fdroid.localrepo.type.BluetoothSwap;
 | 
			
		||||
import org.fdroid.fdroid.localrepo.type.SwapType;
 | 
			
		||||
import org.fdroid.fdroid.localrepo.type.WifiSwap;
 | 
			
		||||
import org.fdroid.fdroid.net.Downloader;
 | 
			
		||||
import org.fdroid.fdroid.net.WifiStateChangeService;
 | 
			
		||||
import org.fdroid.fdroid.views.swap.SwapWorkflowActivity;
 | 
			
		||||
import rx.Observable;
 | 
			
		||||
@ -190,6 +191,10 @@ public class SwapService extends Service {
 | 
			
		||||
                            "POSTing to \"/request-swap\" with repo \"" + swapBackUri + "\"): " + responseCode);
 | 
			
		||||
                } catch (IOException e) {
 | 
			
		||||
                    Log.e(TAG, "Error while asking server to swap with us", e);
 | 
			
		||||
                    Intent intent = new Intent(Downloader.ACTION_INTERRUPTED);
 | 
			
		||||
                    intent.setData(Uri.parse(repo.address));
 | 
			
		||||
                    intent.putExtra(Downloader.EXTRA_ERROR_MESSAGE, e.getLocalizedMessage());
 | 
			
		||||
                    LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent);
 | 
			
		||||
                } finally {
 | 
			
		||||
                    conn.disconnect();
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
@ -57,6 +57,8 @@ import org.fdroid.fdroid.Utils;
 | 
			
		||||
import org.fdroid.fdroid.data.Apk;
 | 
			
		||||
import org.fdroid.fdroid.data.App;
 | 
			
		||||
import org.fdroid.fdroid.data.NewRepoConfig;
 | 
			
		||||
import org.fdroid.fdroid.data.Repo;
 | 
			
		||||
import org.fdroid.fdroid.data.RepoProvider;
 | 
			
		||||
import org.fdroid.fdroid.installer.InstallManagerService;
 | 
			
		||||
import org.fdroid.fdroid.installer.Installer;
 | 
			
		||||
import org.fdroid.fdroid.localrepo.LocalRepoService;
 | 
			
		||||
@ -64,6 +66,7 @@ import org.fdroid.fdroid.localrepo.SwapService;
 | 
			
		||||
import org.fdroid.fdroid.localrepo.SwapView;
 | 
			
		||||
import org.fdroid.fdroid.localrepo.peers.Peer;
 | 
			
		||||
import org.fdroid.fdroid.net.BluetoothDownloader;
 | 
			
		||||
import org.fdroid.fdroid.net.Downloader;
 | 
			
		||||
import org.fdroid.fdroid.net.HttpDownloader;
 | 
			
		||||
import org.fdroid.fdroid.net.WifiStateChangeService;
 | 
			
		||||
import org.fdroid.fdroid.views.main.MainActivity;
 | 
			
		||||
@ -225,6 +228,9 @@ public class SwapWorkflowActivity extends AppCompatActivity {
 | 
			
		||||
        container = (ViewGroup) findViewById(R.id.container);
 | 
			
		||||
 | 
			
		||||
        localBroadcastManager = LocalBroadcastManager.getInstance(this);
 | 
			
		||||
        localBroadcastManager.registerReceiver(downloaderInterruptedReceiver,
 | 
			
		||||
                new IntentFilter(Downloader.ACTION_INTERRUPTED));
 | 
			
		||||
 | 
			
		||||
        wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
 | 
			
		||||
 | 
			
		||||
        new SwapDebug().logStatus();
 | 
			
		||||
@ -232,6 +238,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void onDestroy() {
 | 
			
		||||
        localBroadcastManager.unregisterReceiver(downloaderInterruptedReceiver);
 | 
			
		||||
        unbindService(serviceConnection);
 | 
			
		||||
        super.onDestroy();
 | 
			
		||||
    }
 | 
			
		||||
@ -1172,6 +1179,16 @@ public class SwapWorkflowActivity extends AppCompatActivity {
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    private final BroadcastReceiver downloaderInterruptedReceiver = new BroadcastReceiver() {
 | 
			
		||||
        @Override
 | 
			
		||||
        public void onReceive(Context context, Intent intent) {
 | 
			
		||||
            Repo repo = RepoProvider.Helper.findByUrl(context, intent.getData(), null);
 | 
			
		||||
            if (repo != null && repo.isSwap) {
 | 
			
		||||
                setUpConnectingProgressText(intent.getStringExtra(Downloader.EXTRA_ERROR_MESSAGE));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    private void setUpConnectingView() {
 | 
			
		||||
        TextView heading = container.findViewById(R.id.progress_text);
 | 
			
		||||
        heading.setText(R.string.swap_connecting);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user