Merge branch 'fix/issue-3-repo-update-rotate' of https://gitlab.com/pserwylo/fdroidclient
This commit is contained in:
commit
96333c1cba
@ -53,6 +53,7 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
// while the other uses progress events (string event types).
|
// while the other uses progress events (string event types).
|
||||||
public static final String EVENT_COMPLETE_WITH_CHANGES = "repoUpdateComplete (changed)";
|
public static final String EVENT_COMPLETE_WITH_CHANGES = "repoUpdateComplete (changed)";
|
||||||
public static final String EVENT_COMPLETE_AND_SAME = "repoUpdateComplete (not changed)";
|
public static final String EVENT_COMPLETE_AND_SAME = "repoUpdateComplete (not changed)";
|
||||||
|
public static final String EVENT_FINISHED = "repoUpdateFinished";
|
||||||
public static final String EVENT_ERROR = "repoUpdateError";
|
public static final String EVENT_ERROR = "repoUpdateError";
|
||||||
public static final String EVENT_INFO = "repoUpdateInfo";
|
public static final String EVENT_INFO = "repoUpdateInfo";
|
||||||
|
|
||||||
@ -86,16 +87,12 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
private Context context;
|
private Context context;
|
||||||
private ProgressDialog dialog;
|
private ProgressDialog dialog;
|
||||||
private ProgressListener listener;
|
private ProgressListener listener;
|
||||||
|
private String lastShownMessage = null;
|
||||||
|
|
||||||
public UpdateReceiver(Handler handler) {
|
public UpdateReceiver(Handler handler) {
|
||||||
super(handler);
|
super(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UpdateReceiver setContext(Context context) {
|
|
||||||
this.context = context;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UpdateReceiver setDialog(ProgressDialog dialog) {
|
public UpdateReceiver setDialog(ProgressDialog dialog) {
|
||||||
this.dialog = dialog;
|
this.dialog = dialog;
|
||||||
return this;
|
return this;
|
||||||
@ -112,6 +109,29 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ensureDialog() {
|
||||||
|
if (dialog == null) {
|
||||||
|
String title = context.getString(R.string.process_wait_title);
|
||||||
|
String message = lastShownMessage == null ? context.getString(R.string.process_update_msg) : lastShownMessage;
|
||||||
|
dialog = ProgressDialog.show(context, title, message, true, true);
|
||||||
|
dialog.setIcon(android.R.drawable.ic_dialog_info);
|
||||||
|
dialog.setCanceledOnTouchOutside(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public UpdateReceiver showDialog(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
ensureDialog();
|
||||||
|
dialog.show();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hideDialog() {
|
||||||
|
dialog.hide();
|
||||||
|
dialog.dismiss();
|
||||||
|
dialog = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onReceiveResult(int resultCode, Bundle resultData) {
|
protected void onReceiveResult(int resultCode, Bundle resultData) {
|
||||||
String message = resultData.getString(UpdateService.RESULT_MESSAGE);
|
String message = resultData.getString(UpdateService.RESULT_MESSAGE);
|
||||||
@ -128,10 +148,15 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
finished = true;
|
finished = true;
|
||||||
} else if (resultCode == UpdateService.STATUS_INFO) {
|
} else if (resultCode == UpdateService.STATUS_INFO) {
|
||||||
forwardEvent(EVENT_INFO);
|
forwardEvent(EVENT_INFO);
|
||||||
|
if (dialog != null) {
|
||||||
|
lastShownMessage = message;
|
||||||
dialog.setMessage(message);
|
dialog.setMessage(message);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (finished && dialog.isShowing())
|
if (finished) {
|
||||||
|
forwardEvent(EVENT_FINISHED);
|
||||||
|
if (dialog.isShowing()) {
|
||||||
try {
|
try {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
@ -141,21 +166,17 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static UpdateReceiver updateNow(Context context) {
|
public static UpdateReceiver updateNow(Context context) {
|
||||||
return updateRepoNow(null, context);
|
return updateRepoNow(null, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UpdateReceiver updateRepoNow(String address, Context context) {
|
public static UpdateReceiver updateRepoNow(String address, Context context) {
|
||||||
String title = context.getString(R.string.process_wait_title);
|
|
||||||
String message = context.getString(R.string.process_update_msg);
|
|
||||||
ProgressDialog dialog = ProgressDialog.show(context, title, message, true, true);
|
|
||||||
dialog.setIcon(android.R.drawable.ic_dialog_info);
|
|
||||||
dialog.setCanceledOnTouchOutside(false);
|
|
||||||
|
|
||||||
Intent intent = new Intent(context, UpdateService.class);
|
Intent intent = new Intent(context, UpdateService.class);
|
||||||
UpdateReceiver receiver = new UpdateReceiver(new Handler());
|
UpdateReceiver receiver = new UpdateReceiver(new Handler());
|
||||||
receiver.setContext(context).setDialog(dialog);
|
receiver.showDialog(context);
|
||||||
intent.putExtra(EXTRA_RECEIVER, receiver);
|
intent.putExtra(EXTRA_RECEIVER, receiver);
|
||||||
if (!TextUtils.isEmpty(address)) {
|
if (!TextUtils.isEmpty(address)) {
|
||||||
intent.putExtra(EXTRA_ADDRESS, address);
|
intent.putExtra(EXTRA_ADDRESS, address);
|
||||||
|
@ -15,9 +15,21 @@ import android.text.Editable;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.*;
|
import android.view.LayoutInflater;
|
||||||
import android.widget.*;
|
import android.view.Menu;
|
||||||
import org.fdroid.fdroid.*;
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import org.fdroid.fdroid.NfcNotEnabledActivity;
|
||||||
|
import org.fdroid.fdroid.ProgressListener;
|
||||||
|
import org.fdroid.fdroid.R;
|
||||||
|
import org.fdroid.fdroid.UpdateService;
|
||||||
|
import org.fdroid.fdroid.Utils;
|
||||||
import org.fdroid.fdroid.data.Repo;
|
import org.fdroid.fdroid.data.Repo;
|
||||||
import org.fdroid.fdroid.data.RepoProvider;
|
import org.fdroid.fdroid.data.RepoProvider;
|
||||||
|
|
||||||
@ -56,7 +68,10 @@ public class RepoDetailsFragment extends Fragment {
|
|||||||
private static final int UPDATE = 1;
|
private static final int UPDATE = 1;
|
||||||
private static final int ENABLE_NFC = 2;
|
private static final int ENABLE_NFC = 2;
|
||||||
|
|
||||||
|
private static final String TAG = "org.fdroid.fdroid.views.fragments.RepoDetailsFragment";
|
||||||
|
|
||||||
private MenuItem enableNfc = null;
|
private MenuItem enableNfc = null;
|
||||||
|
private UpdateService.UpdateReceiver updateHandler = null;
|
||||||
|
|
||||||
// TODO: Currently initialised in onCreateView. Not sure if that is the
|
// TODO: Currently initialised in onCreateView. Not sure if that is the
|
||||||
// best way to go about this...
|
// best way to go about this...
|
||||||
@ -65,6 +80,17 @@ public class RepoDetailsFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
|
if (updateHandler != null) {
|
||||||
|
updateHandler.showDialog(getActivity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetach() {
|
||||||
|
super.onDetach();
|
||||||
|
if (updateHandler != null) {
|
||||||
|
updateHandler.hideDialog();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getRepoId() {
|
private long getRepoId() {
|
||||||
@ -200,13 +226,17 @@ public class RepoDetailsFragment extends Fragment {
|
|||||||
values.put(RepoProvider.DataColumns.IN_USE, 1);
|
values.put(RepoProvider.DataColumns.IN_USE, 1);
|
||||||
RepoProvider.Helper.update(getActivity(), repo, values);
|
RepoProvider.Helper.update(getActivity(), repo, values);
|
||||||
|
|
||||||
UpdateService.updateRepoNow(repo.address, getActivity()).setListener(new ProgressListener() {
|
updateHandler = UpdateService.updateRepoNow(repo.address, getActivity()).setListener(new ProgressListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onProgress(Event event) {
|
public void onProgress(Event event) {
|
||||||
if (event.type.equals(UpdateService.EVENT_COMPLETE_WITH_CHANGES)) {
|
if (event.type.equals(UpdateService.EVENT_COMPLETE_WITH_CHANGES)) {
|
||||||
repo = loadRepoDetails();
|
repo = loadRepoDetails();
|
||||||
updateView((ViewGroup)getView());
|
updateView((ViewGroup)getView());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.type.equals(UpdateService.EVENT_FINISHED)) {
|
||||||
|
updateHandler = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -355,6 +385,7 @@ public class RepoDetailsFragment extends Fragment {
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
|
setRetainInstance(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,7 +3,10 @@ package org.fdroid.fdroid.views.fragments;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.*;
|
import android.content.ContentValues;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@ -17,10 +20,21 @@ import android.support.v4.view.MenuItemCompat;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.*;
|
import android.view.Menu;
|
||||||
import android.widget.*;
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import org.fdroid.fdroid.*;
|
import android.view.View;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
import org.fdroid.fdroid.FDroidApp;
|
||||||
|
import org.fdroid.fdroid.Preferences;
|
||||||
|
import org.fdroid.fdroid.ProgressListener;
|
||||||
|
import org.fdroid.fdroid.R;
|
||||||
|
import org.fdroid.fdroid.UpdateService;
|
||||||
import org.fdroid.fdroid.compat.ClipboardCompat;
|
import org.fdroid.fdroid.compat.ClipboardCompat;
|
||||||
import org.fdroid.fdroid.data.Repo;
|
import org.fdroid.fdroid.data.Repo;
|
||||||
import org.fdroid.fdroid.data.RepoProvider;
|
import org.fdroid.fdroid.data.RepoProvider;
|
||||||
@ -30,13 +44,12 @@ import org.fdroid.fdroid.net.MDnsHelper.RepoScanListAdapter;
|
|||||||
import org.fdroid.fdroid.views.RepoAdapter;
|
import org.fdroid.fdroid.views.RepoAdapter;
|
||||||
import org.fdroid.fdroid.views.RepoDetailsActivity;
|
import org.fdroid.fdroid.views.RepoDetailsActivity;
|
||||||
|
|
||||||
|
import javax.jmdns.ServiceInfo;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import javax.jmdns.ServiceInfo;
|
|
||||||
|
|
||||||
public class RepoListFragment extends ListFragment
|
public class RepoListFragment extends ListFragment
|
||||||
implements LoaderManager.LoaderCallbacks<Cursor>, RepoAdapter.EnabledListener {
|
implements LoaderManager.LoaderCallbacks<Cursor>, RepoAdapter.EnabledListener {
|
||||||
|
|
||||||
@ -46,10 +59,28 @@ public class RepoListFragment extends ListFragment
|
|||||||
private final int UPDATE_REPOS = 2;
|
private final int UPDATE_REPOS = 2;
|
||||||
private final int SCAN_FOR_REPOS = 3;
|
private final int SCAN_FOR_REPOS = 3;
|
||||||
|
|
||||||
|
private UpdateService.UpdateReceiver updateHandler = null;
|
||||||
|
|
||||||
public boolean hasChanged() {
|
public boolean hasChanged() {
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Activity activity) {
|
||||||
|
super.onAttach(activity);
|
||||||
|
if (updateHandler != null) {
|
||||||
|
updateHandler.showDialog(getActivity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetach() {
|
||||||
|
super.onDetach();
|
||||||
|
if (updateHandler != null) {
|
||||||
|
updateHandler.hideDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
|
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
|
||||||
Uri uri = RepoProvider.getContentUri();
|
Uri uri = RepoProvider.getContentUri();
|
||||||
@ -147,6 +178,7 @@ public class RepoListFragment extends ListFragment
|
|||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
|
if (getListAdapter() == null) {
|
||||||
// Can't do this in the onCreate view, because "onCreateView" which
|
// Can't do this in the onCreate view, because "onCreateView" which
|
||||||
// returns the list view is "called between onCreate and
|
// returns the list view is "called between onCreate and
|
||||||
// onActivityCreated" according to the docs.
|
// onActivityCreated" according to the docs.
|
||||||
@ -158,12 +190,13 @@ public class RepoListFragment extends ListFragment
|
|||||||
repoAdapter.setEnabledListener(this);
|
repoAdapter.setEnabledListener(this);
|
||||||
setListAdapter(repoAdapter);
|
setListAdapter(repoAdapter);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
setRetainInstance(true);
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,7 +248,7 @@ public class RepoListFragment extends ListFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateRepos() {
|
private void updateRepos() {
|
||||||
UpdateService.updateNow(getActivity()).setListener(new ProgressListener() {
|
updateHandler = UpdateService.updateNow(getActivity()).setListener(new ProgressListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onProgress(Event event) {
|
public void onProgress(Event event) {
|
||||||
if (event.type.equals(UpdateService.EVENT_COMPLETE_AND_SAME) ||
|
if (event.type.equals(UpdateService.EVENT_COMPLETE_AND_SAME) ||
|
||||||
@ -223,6 +256,10 @@ public class RepoListFragment extends ListFragment
|
|||||||
// No need to prompt to update any more, we just did it!
|
// No need to prompt to update any more, we just did it!
|
||||||
changed = false;
|
changed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.type.equals(UpdateService.EVENT_FINISHED)) {
|
||||||
|
updateHandler = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user