Fix download maps progress update in plugin installed dialog

This commit is contained in:
Chumva 2019-11-15 12:20:01 +02:00
parent 80c922449f
commit 0ee6bd6cdc
2 changed files with 76 additions and 2 deletions

View file

@ -7,6 +7,7 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
@ -17,8 +18,9 @@ import android.widget.TextView;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.download.DownloadIndexesThread;
public class PluginActivity extends OsmandActionBarActivity {
public class PluginActivity extends OsmandActionBarActivity implements DownloadIndexesThread.DownloadEvents {
private static final String TAG = "PluginActivity";
public static final String EXTRA_PLUGIN_ID = "plugin_id";
@ -111,9 +113,16 @@ public class PluginActivity extends OsmandActionBarActivity {
super.onResume();
OsmandApplication app = getMyApplication();
OsmandPlugin.checkInstalledMarketPlugins(app, this);
app.getDownloadThread().setUiActivity(this);
updateState();
}
@Override
protected void onPause() {
super.onPause();
getMyApplication().getDownloadThread().resetUiActivity(this);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
@ -166,4 +175,32 @@ public class PluginActivity extends OsmandActionBarActivity {
installHeader.setVisibility(View.GONE);
}
}
// DownloadEvents
@Override
public void newDownloadIndexes() {
for (Fragment fragment : getSupportFragmentManager().getFragments()) {
if (fragment instanceof DownloadIndexesThread.DownloadEvents && fragment.isAdded()) {
((DownloadIndexesThread.DownloadEvents) fragment).newDownloadIndexes();
}
}
}
@Override
public void downloadInProgress() {
for (Fragment fragment : getSupportFragmentManager().getFragments()) {
if (fragment instanceof DownloadIndexesThread.DownloadEvents && fragment.isAdded()) {
((DownloadIndexesThread.DownloadEvents) fragment).downloadInProgress();
}
}
}
@Override
public void downloadHasFinished() {
for (Fragment fragment : getSupportFragmentManager().getFragments()) {
if (fragment instanceof DownloadIndexesThread.DownloadEvents && fragment.isAdded()) {
((DownloadIndexesThread.DownloadEvents) fragment).downloadHasFinished();
}
}
}
}

View file

@ -5,6 +5,7 @@ import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.widget.PopupMenu;
import android.view.MenuItem;
import android.view.View;
@ -19,10 +20,11 @@ import net.osmand.aidl.OsmandAidlApi.ConnectedApp;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.download.DownloadIndexesThread;
import java.util.ArrayList;
public class PluginsActivity extends OsmandListActivity {
public class PluginsActivity extends OsmandListActivity implements DownloadIndexesThread.DownloadEvents {
public static final int ACTIVE_PLUGINS_LIST_MODIFIED = 1;
@ -59,9 +61,16 @@ public class PluginsActivity extends OsmandListActivity {
super.onResume();
OsmandApplication app = getMyApplication();
OsmandPlugin.checkInstalledMarketPlugins(app, this);
app.getDownloadThread().setUiActivity(this);
getListAdapter().notifyDataSetChanged();
}
@Override
protected void onPause() {
super.onPause();
getMyApplication().getDownloadThread().resetUiActivity(this);
}
private void enableDisablePlugin(OsmandPlugin plugin, boolean enable) {
OsmandApplication app = getMyApplication();
if (OsmandPlugin.enablePlugin(this, app, plugin, enable)) {
@ -78,6 +87,34 @@ public class PluginsActivity extends OsmandListActivity {
getListAdapter().notifyDataSetChanged();
}
// DownloadEvents
@Override
public void newDownloadIndexes() {
for (Fragment fragment : getSupportFragmentManager().getFragments()) {
if (fragment instanceof DownloadIndexesThread.DownloadEvents && fragment.isAdded()) {
((DownloadIndexesThread.DownloadEvents) fragment).newDownloadIndexes();
}
}
}
@Override
public void downloadInProgress() {
for (Fragment fragment : getSupportFragmentManager().getFragments()) {
if (fragment instanceof DownloadIndexesThread.DownloadEvents && fragment.isAdded()) {
((DownloadIndexesThread.DownloadEvents) fragment).downloadInProgress();
}
}
}
@Override
public void downloadHasFinished() {
for (Fragment fragment : getSupportFragmentManager().getFragments()) {
if (fragment instanceof DownloadIndexesThread.DownloadEvents && fragment.isAdded()) {
((DownloadIndexesThread.DownloadEvents) fragment).downloadHasFinished();
}
}
}
protected class PluginsListAdapter extends ArrayAdapter<Object> {
PluginsListAdapter() {