Refactored downloadIndex to fragment

This commit is contained in:
Denis 2014-09-09 14:14:52 +03:00
parent d3a7ab2368
commit 9b6b51579f
17 changed files with 162 additions and 177 deletions

View file

@ -132,7 +132,6 @@
<activity android:name="net.osmand.access.SettingsAccessibilityActivity" android:configChanges="keyboardHidden|orientation" />
<activity android:name="net.osmand.plus.activities.search.SearchActivity" android:label="@string/search_activity" />
<activity android:name="net.osmand.plus.activities.DownloadIndexActivity" android:configChanges="keyboardHidden|orientation" android:label="@string/local_index_download" />
<activity android:name="net.osmand.plus.activities.ShowRouteInfoActivity" android:label="@string/show_route" />
<activity android:name="net.osmand.plus.activities.FavouritesListActivity" android:label="@string/favourites_list_activity" />
<activity android:name="net.osmand.plus.activities.FavouritesActivity" android:windowSoftInputMode="adjustPan" />

View file

@ -10,12 +10,8 @@ import net.osmand.IProgress;
import net.osmand.IndexConstants;
import net.osmand.Location;
import net.osmand.data.LocationPoint;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.FavouritesActivity;
import net.osmand.plus.activities.MainMenuActivity;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.PluginsActivity;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.activities.*;
import net.osmand.plus.activities.DownloadIndexFragment;
import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
@ -79,14 +75,14 @@ public class OsmAndAppCustomization {
}
public Class<? extends Activity> getDownloadIndexActivity() {
return DownloadIndexActivity.class;
return DownloadActivity.class;
}
public Class<? extends Activity> getPluginsActivity() {
return PluginsActivity.class;
}
public Class<? extends Activity> getLocalIndexActivity() {
public Class<? extends Activity> getDownloadActivity() {
return DownloadActivity.class;
}
@ -115,7 +111,7 @@ public class OsmAndAppCustomization {
return "http://"+IndexConstants.INDEX_DOWNLOAD_DOMAIN+"/get_indexes?gzip&" + Version.getVersionAsURLParam(app); //$NON-NLS-1$;
}
public void preDownloadActivity(final DownloadIndexActivity da, final List<DownloadActivityType> downloadTypes, ActionBar actionBar ) {
public void preDownloadActivity(final DownloadIndexFragment da, final List<DownloadActivityType> downloadTypes, ActionBar actionBar ) {
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(actionBar.getThemedContext(), R.layout.sherlock_spinner_item,
toString(downloadTypes)

View file

@ -18,11 +18,8 @@ import net.osmand.access.AccessibilityPlugin;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.access.AccessibilityMode;
import net.osmand.plus.activities.DayNightHelper;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.activities.*;
import net.osmand.plus.activities.DownloadIndexFragment;
import net.osmand.plus.api.SQLiteAPI;
import net.osmand.plus.api.SQLiteAPIImpl;
import net.osmand.plus.helpers.WaypointHelper;
@ -114,7 +111,7 @@ public class OsmandApplication extends Application {
BRouterServiceConnection bRouterServiceConnection;
MapActivity mapActivity;
DownloadIndexActivity downloadActivity;
DownloadIndexFragment downloadActivity;
@Override
public void onCreate() {
@ -882,11 +879,11 @@ public class OsmandApplication extends Application {
this.mapActivity = mapActivity;
}
public void setDownloadActivity(DownloadIndexActivity downloadActivity) {
public void setDownloadActivity(DownloadIndexFragment downloadActivity) {
this.downloadActivity = downloadActivity;
}
public DownloadIndexActivity getDownloadActivity() {
public DownloadIndexFragment getDownloadActivity() {
return downloadActivity;
}
}

View file

@ -10,6 +10,10 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.*;
import com.actionbarsherlock.view.MenuInflater;
import net.osmand.IndexConstants;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast;
@ -21,12 +25,7 @@ import net.osmand.plus.Version;
import net.osmand.plus.activities.SettingsGeneralActivity.MoveFilesToDifferentDirectory;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.base.SuggestExternalDirectoryDialog;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadEntry;
import net.osmand.plus.download.DownloadIndexAdapter;
import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.download.IndexItemCategory;
import net.osmand.plus.download.*;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
@ -41,21 +40,12 @@ import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.SubMenu;
public class DownloadIndexActivity extends OsmandExpandableListActivity {
public class DownloadIndexFragment extends OsmandExpandableListFragment {
/** menus **/
private static final int MORE_ID = 10;
@ -83,23 +73,24 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
private TextView progressPercent;
private ImageView cancel;
DownloadIndexAdapter listAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final List<DownloadActivityType> downloadTypes = getDownloadTypes();
type = downloadTypes.get(0);
settings = ((OsmandApplication) getApplication()).getSettings();
if(downloadListIndexThread == null) {
downloadListIndexThread = new DownloadIndexesThread(this);
}
setContentView(R.layout.download_index);
indeterminateProgressBar = (ProgressBar) findViewById(R.id.IndeterminateProgressBar);
determinateProgressBar = (ProgressBar) findViewById(R.id.DeterminateProgressBar);
progressView = findViewById(R.id.ProgressView);
progressMessage = (TextView) findViewById(R.id.ProgressMessage);
progressPercent = (TextView) findViewById(R.id.ProgressPercent);
cancel = (ImageView) findViewById(R.id.Cancel);
View view = inflater.inflate(R.layout.download_index, container, false);
ExpandableListView listView = (ExpandableListView)view.findViewById(android.R.id.list);
List<IndexItem> list = new ArrayList<IndexItem>();
listAdapter = new DownloadIndexAdapter(this, list);
listView.setAdapter(listAdapter);
setListView(listView);
indeterminateProgressBar = (ProgressBar) view.findViewById(R.id.IndeterminateProgressBar);
determinateProgressBar = (ProgressBar) view.findViewById(R.id.DeterminateProgressBar);
progressView = view.findViewById(R.id.ProgressView);
progressMessage = (TextView) view.findViewById(R.id.ProgressMessage);
progressPercent = (TextView) view.findViewById(R.id.ProgressPercent);
cancel = (ImageView) view.findViewById(R.id.Cancel);
int d = settings.isLightContent() ? R.drawable.a_1_navigation_cancel_small_light : R.drawable.a_1_navigation_cancel_small_dark;
cancel.setImageDrawable(getResources().getDrawable(d));
cancel.setOnClickListener(new View.OnClickListener() {
@ -109,9 +100,9 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
makeSureUserCancelDownload();
}
});
getSupportActionBar().setTitle(R.string.local_index_download);
//getSupportActionBar().setTitle(R.string.local_index_download);
// recreation upon rotation is pgetaprevented in manifest file
findViewById(R.id.DownloadButton).setOnClickListener(new View.OnClickListener(){
view.findViewById(R.id.DownloadButton).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
@ -120,28 +111,28 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
});
filterText = (EditText) findViewById(R.id.search_box);
textWatcher = new TextWatcher() {
@Override
filterText = (EditText) view.findViewById(R.id.search_box);
textWatcher = new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
}
@Override
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
int after) {
}
@Override
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
DownloadIndexAdapter adapter = ((DownloadIndexAdapter)getExpandableListAdapter());
if(adapter != null){
adapter.getFilter().filter(s);
int count) {
if(listAdapter != null){
listAdapter.getFilter().filter(s);
}
}
}
};
};
filterText.addTextChangedListener(textWatcher);
final Intent intent = getIntent();
//final Intent intent = getIntent();
final Intent intent = null;
if (intent != null && intent.getExtras() != null) {
final String filter = intent.getExtras().getString(FILTER_KEY);
if (filter != null) {
@ -157,19 +148,29 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
}
}
}
List<IndexItem> list = new ArrayList<IndexItem>();
getMyApplication().getAppCustomization().preDownloadActivity(this, downloadTypes, getMyActivity().getSupportActionBar());
return view;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
settings = ((OsmandApplication) getMyApplication()).getSettings();
if(downloadListIndexThread == null) {
downloadListIndexThread = new DownloadIndexesThread(getActivity());
}
downloadListIndexThread.setUiActivity(this);
if (downloadListIndexThread.getCachedIndexFiles() != null && downloadListIndexThread.isDownloadedFromInternet()) {
downloadListIndexThread.runCategorization(type);
} else {
downloadListIndexThread.runReloadIndexFiles();
}
DownloadIndexAdapter adapter = new DownloadIndexAdapter(this, list);
setListAdapter(adapter);
if(getMyApplication().getResourceManager().getIndexFileNames().isEmpty()) {
boolean showedDialog = false;
if(Build.VERSION.SDK_INT < OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) {
SuggestExternalDirectoryDialog.showDialog(this, null, null);
SuggestExternalDirectoryDialog.showDialog(getActivity(), null, null);
}
if(!showedDialog) {
showDialogOfFreeDownloadsIfNeeded();
@ -178,7 +179,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
showDialogOfFreeDownloadsIfNeeded();
}
getMyApplication().getAppCustomization().preDownloadActivity(this, downloadTypes, getSupportActionBar());
if (Build.VERSION.SDK_INT >= OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) {
final String currentStorage = settings.getExternalStorageDirectory().getAbsolutePath();
String primaryStorage = settings.getDefaultExternalStorageLocation();
@ -197,7 +198,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
if (currentDirectoryNotWritable) {
final String newLoc = settings.getMatchingExternalFilesDir(currentStorage);
if (newLoc != null && newLoc.length() != 0) {
AccessibleAlertBuilder ab = new AccessibleAlertBuilder(this);
AccessibleAlertBuilder ab = new AccessibleAlertBuilder(getMyActivity());
ab.setMessage(getString(R.string.android_19_location_disabled,
settings.getExternalStorageDirectory()));
ab.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@ -216,7 +217,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
private void copyFilesForAndroid19(final String newLoc) {
MoveFilesToDifferentDirectory task =
new MoveFilesToDifferentDirectory(DownloadIndexActivity.this,
new MoveFilesToDifferentDirectory(getMyActivity(),
new File(settings.getExternalStorageDirectory(), IndexConstants.APP_DIR),
new File(newLoc, IndexConstants.APP_DIR)) {
protected Boolean doInBackground(Void[] params) {
@ -233,13 +234,13 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
}
@Override
protected void onResume() {
public void onResume() {
super.onResume();
getMyApplication().setDownloadActivity(this);
BasicProgressAsyncTask<?, ?, ?> t = downloadListIndexThread.getCurrentRunningTask();
updateProgress(false);
if(t instanceof DownloadIndexesThread.DownloadIndexesAsyncTask) {
View mainView = findViewById(R.id.MainLayout);
View mainView = getView().findViewById(R.id.MainLayout);
if (mainView != null) {
mainView.setKeepScreenOn(true);
}
@ -247,7 +248,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
}
@Override
protected void onPause() {
public void onPause() {
super.onPause();
getMyApplication().setDownloadActivity(null);
}
@ -273,7 +274,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
}
}
if(count > 0){
Builder builder = new AlertDialog.Builder(this);
Builder builder = new AlertDialog.Builder(getMyActivity());
builder.setMessage(getString(R.string.download_additional_maps, s, sz));
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
@ -303,7 +304,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
private void showDialogOfFreeDownloadsIfNeeded() {
if (Version.isFreeVersion(getMyApplication())) {
Builder msg = new AlertDialog.Builder(this);
Builder msg = new AlertDialog.Builder(getMyActivity());
msg.setTitle(R.string.free_version_title);
String m = getString(R.string.free_version_message, MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "", "") + "\n";
m += getString(R.string.available_downloads_left, MAXIMUM_AVAILABLE_FREE_DOWNLOADS - settings.NUMBER_OF_FREE_DOWNLOADS.get());
@ -346,7 +347,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
return super.onOptionsItemSelected(item);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
if (getMyApplication().getAppCustomization().showDownloadExtraActions()) {
SubMenu s = menu.addSubMenu(0, MORE_ID, 0, R.string.default_buttons_other_actions);
s.add(0, RELOAD_ID, 0, R.string.update_downlod_list);
@ -358,7 +359,6 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
: R.drawable.abs__ic_menu_moreoverflow_holo_dark);
s.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}
return super.onCreateOptionsMenu(menu);
}
public DownloadActivityType getType() {
@ -378,16 +378,14 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
public void deselectAll() {
final DownloadIndexAdapter listAdapter = (DownloadIndexAdapter)getExpandableListAdapter();
downloadListIndexThread.getEntriesToDownload().clear();
listAdapter.notifyDataSetInvalidated();
findViewById(R.id.DownloadButton).setVisibility(View.GONE);
getView().findViewById(R.id.DownloadButton).setVisibility(View.GONE);
}
private void filterExisting() {
final DownloadIndexAdapter listAdapter = (DownloadIndexAdapter)getExpandableListAdapter();
final Map<String, String> listAlreadyDownloaded = downloadListIndexThread.getDownloadedIndexFileNames();
final List<IndexItem> filtered = new ArrayList<IndexItem>();
@ -402,7 +400,6 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
private void selectAll() {
final DownloadIndexAdapter listAdapter = (DownloadIndexAdapter)getExpandableListAdapter();
int selected = 0;
for (int j = 0; j < listAdapter.getGroupCount(); j++) {
for (int i = 0; i < listAdapter.getChildrenCount(j); i++) {
@ -413,7 +410,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
}
}
}
AccessibleToast.makeText(this, MessageFormat.format(getString(R.string.items_were_selected), selected), Toast.LENGTH_SHORT).show();
AccessibleToast.makeText(getMyActivity(), MessageFormat.format(getString(R.string.items_were_selected), selected), Toast.LENGTH_SHORT).show();
listAdapter.notifyDataSetInvalidated();
if(selected > 0){
updateDownloadButton(true);
@ -422,14 +419,15 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
public void updateDownloadButton(boolean scroll) {
int x = getListView().getScrollX();
int y = getListView().getScrollY();
View view = getView();
int x = getExpandableListView().getScrollX();
int y = getExpandableListView().getScrollY();
if (getEntriesToDownload().isEmpty()) {
findViewById(R.id.DownloadButton).setVisibility(View.GONE);
view.findViewById(R.id.DownloadButton).setVisibility(View.GONE);
} else {
BasicProgressAsyncTask<?, ?, ?> task = downloadListIndexThread.getCurrentRunningTask();
boolean running = task instanceof DownloadIndexesThread.DownloadIndexesAsyncTask;
((Button) findViewById(R.id.DownloadButton)).setEnabled(!running);
((Button) view.findViewById(R.id.DownloadButton)).setEnabled(!running);
String text;
int downloads = downloadListIndexThread.getDownloads();
if (!running) {
@ -437,7 +435,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
} else {
text = getString(R.string.downloading_file_new) + " (" + downloads + ")"; //$NON-NLS-1$
}
findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
view.findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
if (Version.isFreeVersion(getMyApplication())) {
int countedDownloads = downloadListIndexThread.getDownloads();
int left = MAXIMUM_AVAILABLE_FREE_DOWNLOADS - settings.NUMBER_OF_FREE_DOWNLOADS.get() - downloads;
@ -448,10 +446,10 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
text += " (" + (excessLimit ? "! " : "") + getString(R.string.files_limit, left).toLowerCase() + ")";
}
}
((Button) findViewById(R.id.DownloadButton)).setText(text);
((Button) view.findViewById(R.id.DownloadButton)).setText(text);
}
if (scroll) {
getListView().scrollTo(x, y);
getExpandableListView().scrollTo(x, y);
}
}
@ -470,9 +468,8 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
return items;
}
public void changeType(final DownloadActivityType tp) {
invalidateOptionsMenu();
getMyActivity().invalidateOptionsMenu();
if (downloadListIndexThread != null && type != tp) {
type = tp;
downloadListIndexThread.runCategorization(tp);
@ -480,16 +477,8 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
}
public ExpandableListView getListView() {
return super.getExpandableListView();
}
public ExpandableListAdapter getListAdapter() {
return super.getExpandableListAdapter();
}
private void makeSureUserCancelDownload() {
Builder bld = new AlertDialog.Builder(this);
Builder bld = new AlertDialog.Builder(getMyActivity());
bld.setTitle(getString(R.string.default_buttons_cancel));
bld.setMessage(R.string.confirm_interrupt_download);
bld.setPositiveButton(R.string.default_buttons_yes, new OnClickListener() {
@ -509,7 +498,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
final IndexItem e = (IndexItem) ((DownloadIndexAdapter)getListAdapter()).getChild(groupPosition, childPosition);
final IndexItem e = (IndexItem) listAdapter.getChild(groupPosition, childPosition);
final CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);
if(ch.isChecked()){
@ -579,7 +568,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
}
if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS || wiki) {
String msgTx = getString(R.string.free_version_message, MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "");
Builder msg = new AlertDialog.Builder(this);
Builder msg = new AlertDialog.Builder(getMyActivity());
msg.setTitle(R.string.free_version_title);
msg.setMessage(msgTx);
msg.setPositiveButton(R.string.default_buttons_ok, null);
@ -595,7 +584,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
protected void downloadFilesCheckInternet() {
if(!getMyApplication().getSettings().isWifiConnected()) {
Builder builder = new AlertDialog.Builder(this);
Builder builder = new AlertDialog.Builder(getMyActivity());
builder.setMessage(getString(R.string.download_using_mobile_internet));
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
@ -619,7 +608,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
// get availabile space
double asz = downloadListIndexThread.getAvailableSpace();
if (asz != -1 && asz > 0 && sz / asz > 0.4) {
Builder builder = new AlertDialog.Builder(this);
Builder builder = new AlertDialog.Builder(getMyActivity());
builder.setMessage(MessageFormat.format(getString(R.string.download_files_question_space), list.size(), sz, asz));
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
@ -635,23 +624,17 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
}
@Override
protected void onDestroy() {
public void onDestroy() {
super.onDestroy();
if (textWatcher != null) {
EditText filterText = (EditText) findViewById(R.id.search_box);
EditText filterText = (EditText) getView().findViewById(R.id.search_box);
filterText.removeTextChangedListener(textWatcher);
}
downloadListIndexThread.setUiActivity(null);
}
public void updateProgress(boolean updateOnlyProgress) {
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask = downloadListIndexThread.getCurrentRunningTask();
if(updateOnlyProgress) {
@ -678,4 +661,10 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
updateDownloadButton(false);
}
}
public DownloadActivity getMyActivity(){ return (DownloadActivity)getActivity();}
public ExpandableListAdapter getExpandableListAdapter(){ return listAdapter;}
public View findViewById(int id){ return getView().findViewById(id);}
}

View file

@ -130,7 +130,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
if(favouritesAdapter.getGroupCount() > 0 &&
"".equals(favouritesAdapter.getGroup(0).name)) {
getListView().expandGroup(0);
getExpandableListView().expandGroup(0);
}
}

View file

@ -12,7 +12,6 @@ import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.render.MapRenderRepositories;
import net.osmand.plus.sherpafy.SherpafyCustomization;
import net.osmand.plus.sherpafy.TourViewActivity;
import android.app.Activity;
import android.app.AlertDialog.Builder;
@ -376,7 +375,7 @@ public class MainMenuActivity extends Activity {
@Override
public void onClick(DialogInterface dialog, int which) {
startActivity(new Intent(MainMenuActivity.this, DownloadIndexActivity.class));
startActivity(new Intent(MainMenuActivity.this, DownloadIndexFragment.class));
}
});

View file

@ -62,13 +62,9 @@ public abstract class OsmandExpandableListFragment extends SherlockFragment impl
}
}
public ExpandableListView getListView() {
return listView;
}
public ExpandableListView getExpandableListView() { return listView; }
public ExpandableListView getExpandableListView() {
return listView;
}
public void setListView(ExpandableListView listView) { this.listView = listView;}
public MenuItem createMenuItem(Menu m, int id, int titleRes, int iconLight, int iconDark, int menuItemType) {
int r = isLightActionBar() ? iconLight : iconDark;

View file

@ -104,10 +104,10 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
public void setContent() {
getListView().setFastScrollEnabled(true);
getExpandableListView().setFastScrollEnabled(true);
lightContent = app.getSettings().isLightContent();
if (adapter == null) {
adapter = new SelectedGPXAdapter(getListView());
adapter = new SelectedGPXAdapter(getExpandableListView());
setAdapter(adapter);
}
List<GpxDisplayGroup> groups = selectedGpxHelper.getDisplayGroups();
@ -131,7 +131,7 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
adapter.setDisplayGroups(groups);
if(isArgumentTrue(ARG_TO_EXPAND_TRACK_INFO)){
for(int i = 0; i < groups.size(); i++) {
getListView().expandGroup(i);
getExpandableListView().expandGroup(i);
}
}
}

View file

@ -101,7 +101,7 @@ public class SettingsActivity extends SettingsBaseActivity {
if (empty) {
startActivity(new Intent(this, getMyApplication().getAppCustomization().getDownloadIndexActivity()));
} else {
startActivity(new Intent(this, getMyApplication().getAppCustomization().getLocalIndexActivity()));
startActivity(new Intent(this, getMyApplication().getAppCustomization().getDownloadActivity()));
}
return true;
} else if (preference == bidforfix) {

View file

@ -372,8 +372,8 @@ public class SettingsGeneralActivity extends SettingsBaseActivity {
if (id.equals(settings.VOICE_PROVIDER.getId())) {
if (MORE_VALUE.equals(newValue)) {
// listPref.set(oldValue); // revert the change..
final Intent intent = new Intent(this, DownloadIndexActivity.class);
intent.putExtra(DownloadIndexActivity.FILTER_CAT, DownloadActivityType.VOICE_FILE.getTag());
final Intent intent = new Intent(this, DownloadIndexFragment.class);
intent.putExtra(DownloadIndexFragment.FILTER_CAT, DownloadActivityType.VOICE_FILE.getTag());
startActivity(intent);
} else {
super.onPreferenceChange(preference, newValue);

View file

@ -7,6 +7,7 @@ import com.actionbarsherlock.app.SherlockFragmentActivity;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexFragment;
import net.osmand.plus.activities.FavouritesActivity;
/**
@ -16,6 +17,9 @@ public class DownloadActivity extends SherlockFragmentActivity {
private TabHost tabHost;
private FavouritesActivity.TabsAdapter mTabsAdapter;
public static DownloadIndexesThread downloadListIndexThread;
private DownloadActivityType type = DownloadActivityType.NORMAL_FILE;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -31,7 +35,20 @@ public class DownloadActivity extends SherlockFragmentActivity {
mTabsAdapter = new FavouritesActivity.TabsAdapter(this, tabHost, viewPager, settings);
mTabsAdapter.addTab(tabHost.newTabSpec("LOCAL_INDEX").setIndicator("Local maps"),
LocalIndexesFragment.class, null);
mTabsAdapter.addTab(tabHost.newTabSpec("DOWNLOADS").setIndicator("Downloads"),
DownloadIndexFragment.class, null);
tabHost.setCurrentTab(0);
}
public DownloadActivityType getType() { return type;}
public void setType(DownloadActivityType type) { this.type = type;}
public void changeType(final DownloadActivityType tp) {
invalidateOptionsMenu();
if (downloadListIndexThread != null && type != tp) {
type = tp;
downloadListIndexThread.runCategorization(tp);
}
}
}

View file

@ -8,7 +8,7 @@ import java.util.Map;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.DownloadIndexFragment;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import android.content.Context;
import android.content.res.TypedArray;
@ -28,7 +28,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
private DownloadIndexFilter myFilter;
private final List<IndexItem> indexFiles;
private final List<IndexItemCategory> list = new ArrayList<IndexItemCategory>();
private DownloadIndexActivity downloadActivity;
private DownloadIndexFragment downloadActivity;
private Map<String, String> indexFileNames = null;
private Map<String, String> indexActivatedFileNames = null;
@ -38,7 +38,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
private OsmandRegions osmandRegions;
private java.text.DateFormat format;
public DownloadIndexAdapter(DownloadIndexActivity downloadActivity, List<IndexItem> indexFiles) {
public DownloadIndexAdapter(DownloadIndexFragment downloadActivity, List<IndexItem> indexFiles) {
this.downloadActivity = downloadActivity;
this.indexFiles = new ArrayList<IndexItem>(indexFiles);
List<IndexItemCategory> cats = IndexItemCategory.categorizeIndexItems(downloadActivity.getMyApplication(), indexFiles);
@ -48,7 +48,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
}
format = downloadActivity.getMyApplication().getResourceManager().getDateFormat();
okColor = downloadActivity.getResources().getColor(R.color.color_ok);
TypedArray ta = downloadActivity.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
TypedArray ta = downloadActivity.getMyActivity().getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
defaultColor = ta.getColor(0, downloadActivity.getResources().getColor(R.color.color_unknown));
ta.recycle();
updateColor = downloadActivity.getResources().getColor(R.color.color_update);
@ -62,7 +62,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
}
public void collapseTrees(final CharSequence constraint) {
downloadActivity.runOnUiThread(new Runnable() {
downloadActivity.getMyActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
synchronized (DownloadIndexAdapter.this) {
@ -125,7 +125,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
}
}
List<IndexItem> filter = new ArrayList<IndexItem>();
Context c = downloadActivity;
Context c = downloadActivity.getMyActivity();
for (IndexItem item : indexFiles) {
boolean add = true;
String indexLC = osmandRegions.getDownloadNameIndexLowercase(item.getBasename());
@ -218,7 +218,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
View v = convertView;
IndexItemCategory group = getGroup(groupPosition);
if (v == null) {
LayoutInflater inflater = downloadActivity.getLayoutInflater();
LayoutInflater inflater = (LayoutInflater) downloadActivity.getMyActivity().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
v = inflater.inflate(net.osmand.plus.R.layout.expandable_list_item_category, parent, false);
}
final View row = v;
@ -233,7 +233,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater inflater = downloadActivity.getLayoutInflater();
LayoutInflater inflater = (LayoutInflater) downloadActivity.getMyActivity().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
v = inflater.inflate(net.osmand.plus.R.layout.download_index_list_item, parent, false);
}
final View row = v;
@ -253,7 +253,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
public void onClick(View v) {
final CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);
ch.setChecked(!ch.isChecked());
downloadActivity.onChildClick(downloadActivity.getListView(), row, groupPosition, childPosition, getChildId(groupPosition, childPosition));
downloadActivity.onChildClick(downloadActivity.getExpandableListView(), row, groupPosition, childPosition, getChildId(groupPosition, childPosition));
}
});

View file

@ -23,7 +23,7 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.DownloadIndexFragment;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning;
import net.osmand.plus.resources.ResourceManager;
@ -47,7 +47,7 @@ import android.view.View;
import android.widget.Toast;
public class DownloadIndexesThread {
private DownloadIndexActivity uiActivity = null;
private DownloadIndexFragment uiActivity = null;
private IndexFileList indexFiles = null;
private Map<IndexItem, List<DownloadEntry>> entriesToDownload = new ConcurrentHashMap<IndexItem, List<DownloadEntry>>();
private Set<DownloadEntry> currentDownloads = new HashSet<DownloadEntry>();
@ -72,7 +72,7 @@ public class DownloadIndexesThread {
indexFiles = null;
}
public void setUiActivity(DownloadIndexActivity uiActivity) {
public void setUiActivity(DownloadIndexFragment uiActivity) {
this.uiActivity = uiActivity;
}
@ -92,13 +92,13 @@ public class DownloadIndexesThread {
public void updateLoadedFiles() {
Map<String, String> indexActivatedFileNames = app.getResourceManager().getIndexFileNames();
DownloadIndexActivity.listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT,
DownloadIndexFragment.listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT,
indexActivatedFileNames);
Map<String, String> indexFileNames = app.getResourceManager().getIndexFileNames();
DownloadIndexActivity.listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT,
DownloadIndexFragment.listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT,
indexFileNames);
app.getAppCustomization().updatedLoadedFiles(indexFileNames, indexActivatedFileNames);
DownloadIndexActivity.listWithAlternatives(dateFormat, app.getAppPath(IndexConstants.TILES_INDEX_DIR),
DownloadIndexFragment.listWithAlternatives(dateFormat, app.getAppPath(IndexConstants.TILES_INDEX_DIR),
IndexConstants.SQLITE_EXT, indexFileNames);
app.getResourceManager().getBackupIndexes(indexFileNames);
this.indexFileNames = indexFileNames;
@ -230,7 +230,7 @@ public class DownloadIndexesThread {
break downloadCycle;
}
if (exceedsFreelimit(entry)) {
breakDownloadMessage = app.getString(R.string.free_version_message, DownloadIndexActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS
breakDownloadMessage = app.getString(R.string.free_version_message, DownloadIndexFragment.MAXIMUM_AVAILABLE_FREE_DOWNLOADS
+ "");
break downloadCycle;
}
@ -272,7 +272,7 @@ public class DownloadIndexesThread {
private boolean exceedsFreelimit(DownloadEntry entry) {
return Version.isFreeVersion(app) &&
DownloadActivityType.isCountedInDownloads(entry.item.getType()) && downloads.get() >= DownloadIndexActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS;
DownloadActivityType.isCountedInDownloads(entry.item.getType()) && downloads.get() >= DownloadIndexFragment.MAXIMUM_AVAILABLE_FREE_DOWNLOADS;
}
private String reindexFiles(List<File> filesToReindex) {
@ -323,7 +323,7 @@ public class DownloadIndexesThread {
if (de.isAsset) {
try {
if (uiActivity != null) {
ResourceManager.copyAssets(uiActivity.getAssets(), de.assetName, de.targetFile);
ResourceManager.copyAssets(uiActivity.getMyActivity().getAssets(), de.assetName, de.targetFile);
boolean changedDate = de.targetFile.setLastModified(de.dateModified);
if(!changedDate) {
log.error("Set last timestamp is not supported");
@ -386,7 +386,7 @@ public class DownloadIndexesThread {
.createDownloadEntry(uiActivity.getMyApplication(), DownloadActivityType.NORMAL_FILE,
new ArrayList<DownloadEntry>());
uiActivity.getEntriesToDownload().put(basemap, downloadEntry);
AccessibleToast.makeText(uiActivity, R.string.basemap_was_selected_to_download,
AccessibleToast.makeText(uiActivity.getMyActivity(), R.string.basemap_was_selected_to_download,
Toast.LENGTH_LONG).show();
uiActivity.findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
}
@ -507,7 +507,7 @@ public class DownloadIndexesThread {
if ((type == DownloadActivityType.SRTM_COUNTRY_FILE || type == DownloadActivityType.HILLSHADE_FILE)
&& OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) instanceof SRTMPlugin
&& !OsmandPlugin.getEnabledPlugin(SRTMPlugin.class).isPaid()) {
Builder msg = new AlertDialog.Builder(uiActivity);
Builder msg = new AlertDialog.Builder(uiActivity.getMyActivity());
msg.setTitle(R.string.srtm_paid_version_title);
msg.setMessage(R.string.srtm_paid_version_msg);
msg.setNegativeButton(R.string.button_upgrade_osmandplus, new DialogInterface.OnClickListener() {

View file

@ -14,13 +14,10 @@ import com.actionbarsherlock.view.*;
import net.osmand.IProgress;
import net.osmand.IndexConstants;
import net.osmand.access.AccessibleToast;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.*;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.activities.*;
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.util.Algorithms;
import android.app.Activity;
@ -32,12 +29,10 @@ import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.AsyncTask.Status;
import android.os.Bundle;
import android.os.StatFs;
import android.text.SpannableString;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
@ -459,9 +454,6 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
localOptionsMenu(itemId);
}
};
optionsMenuAdapter.item(R.string.local_index_download)
.icons(R.drawable.ic_action_gdown_dark, R.drawable.ic_action_gdown_light)
.listen(listener).position(0).reg();
optionsMenuAdapter.item(R.string.local_index_mi_reload)
.icons(R.drawable.ic_action_refresh_dark, R.drawable.ic_action_refresh_light)
.listen(listener).position(1).reg();
@ -632,7 +624,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
@Override
public void onClick(View widget) {
asyncLoader.setResult(null);
startActivity(new Intent(getMyActivity(), DownloadIndexActivity.class));
startActivity(new Intent(getMyActivity(), DownloadIndexFragment.class));
}
@Override
@ -650,7 +642,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
public void localOptionsMenu(final int itemId) {
if (itemId == R.string.local_index_download) {
asyncLoader.setResult(null);
startActivity(new Intent(getMyActivity(), DownloadIndexActivity.class));
startActivity(new Intent(getMyActivity(), DownloadIndexFragment.class));
} else if (itemId == R.string.local_index_mi_reload) {
reloadIndexes();
} else if (itemId == R.string.local_index_mi_delete) {

View file

@ -31,13 +31,14 @@ import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.DownloadIndexFragment;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityLayers;
import net.osmand.plus.activities.SelectedGPXFragment;
import net.osmand.plus.activities.actions.ShareLocation;
import net.osmand.plus.api.FileSettingsAPIImpl;
import net.osmand.plus.api.SettingsAPI;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.routing.RouteCalculationResult;
@ -60,7 +61,6 @@ import android.view.Window;
import android.widget.TextView;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.app.SherlockFragmentActivity;
public class SherpafyCustomization extends OsmAndAppCustomization {
@ -107,8 +107,8 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
public boolean setAccessCode(String acCode) {
acCode = acCode.toUpperCase();
if(DownloadIndexActivity.downloadListIndexThread != null) {
DownloadIndexActivity.downloadListIndexThread.clear();
if(DownloadIndexFragment.downloadListIndexThread != null) {
DownloadIndexFragment.downloadListIndexThread.clear();
}
if(validate(acCode) || Algorithms.isEmpty(acCode)) {
accessCodePref.set(acCode);
@ -182,7 +182,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
}
public void updatedLoadedFiles(java.util.Map<String,String> indexFileNames, java.util.Map<String,String> indexActivatedFileNames) {
DownloadIndexActivity.listWithAlternatives(app.getResourceManager().getDateFormat(),
DownloadIndexFragment.listWithAlternatives(app.getResourceManager().getDateFormat(),
toursFolder, "", indexFileNames);
}
@ -198,7 +198,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
for(File tr : availableTours) {
if (tr.isDirectory()) {
String date = app.getResourceManager().getDateFormat()
.format(new Date(DownloadIndexActivity.findFileInDir(tr).lastModified()));
.format(new Date(DownloadIndexFragment.findFileInDir(tr).lastModified()));
indexFileNames.put(tr.getName(), date);
final TourInformation tourInformation = new TourInformation(tr);
tourPresent.add(tourInformation);
@ -229,7 +229,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
}
this.tourPresent = tourPresent;
if(!suggestToDownloadMap.isEmpty()) {
final DownloadIndexActivity da = app.getDownloadActivity();
final DownloadIndexFragment da = app.getDownloadActivity();
if (da != null) {
app.runInUIThread(new Runnable() {
@ -612,7 +612,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
return s;
}
public void preDownloadActivity(final DownloadIndexActivity da, final List<DownloadActivityType> downloadTypes, ActionBar actionBar) {
public void preDownloadActivity(final DownloadActivity da, final List<DownloadActivityType> downloadTypes, ActionBar actionBar) {
actionBar.setTitle(TourDownloadType.TOUR.getString(da));
}

View file

@ -5,7 +5,7 @@ import java.util.WeakHashMap;
import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.DownloadIndexFragment;
import net.osmand.plus.sherpafy.TourInformation.StageFavorite;
import net.osmand.plus.sherpafy.TourInformation.StageInformation;
import android.content.Intent;
@ -376,7 +376,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
public void startDownloadActivity() {
final Intent download = new Intent(this, DownloadIndexActivity.class);
final Intent download = new Intent(this, DownloadIndexFragment.class);
download.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
refreshListAfterDownload = true;
startActivity(download);

View file

@ -12,7 +12,7 @@ import net.osmand.binary.BinaryMapDataObject;
import net.osmand.data.RotatedTileBox;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.DownloadIndexFragment;
import net.osmand.plus.resources.ResourceManager;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
@ -87,7 +87,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
@Override
public void onClick(View v) {
final Intent intent = new Intent(view.getContext(), view.getApplication().getAppCustomization().getDownloadIndexActivity());
intent.putExtra(DownloadIndexActivity.FILTER_KEY, filter.toString());
intent.putExtra(DownloadIndexFragment.FILTER_KEY, filter.toString());
view.getContext().startActivity(intent);
}
});