Updated download button
This commit is contained in:
parent
cfae45eea2
commit
77c44365af
6 changed files with 94 additions and 73 deletions
|
@ -28,15 +28,4 @@
|
|||
android:layout_weight="1"
|
||||
android:groupIndicator="@android:color/transparent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/DownloadButton"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="3dp"
|
||||
android:layout_marginRight="3dp"
|
||||
android:layout_marginTop="3dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/download_files"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
|
@ -102,5 +102,19 @@
|
|||
android:layout_height="0dp"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/DownloadButton"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_marginLeft="3dp"
|
||||
android:layout_marginRight="3dp"
|
||||
android:layout_marginTop="3dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/download_files"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</TabHost>
|
|
@ -10,10 +10,7 @@ import android.os.Bundle;
|
|||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TabHost;
|
||||
import android.widget.TextView;
|
||||
import android.widget.*;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
|
@ -94,6 +91,15 @@ public class DownloadActivity extends SherlockFragmentActivity {
|
|||
makeSureUserCancelDownload();
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.DownloadButton).setOnClickListener(new View.OnClickListener(){
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
downloadFilesCheckFreeVersion();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -248,10 +254,8 @@ public class DownloadActivity extends SherlockFragmentActivity {
|
|||
determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
|
||||
}
|
||||
}
|
||||
Fragment fragment = mTabsAdapter.getItem(tabHost.getCurrentTab());
|
||||
if (fragment instanceof DownloadIndexFragment){
|
||||
((DownloadIndexFragment) fragment).updateDownloadButton(false);
|
||||
}
|
||||
updateDownloadButton(false);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -275,6 +279,46 @@ public class DownloadActivity extends SherlockFragmentActivity {
|
|||
|
||||
public void updateDownloadList(List<IndexItem> list){
|
||||
Fragment fragment = mTabsAdapter.getItem(2);
|
||||
//will fall if change tab order
|
||||
((UpdatesIndexFragment) fragment).updateItemsList(list);
|
||||
}
|
||||
|
||||
public void updateDownloadButton(boolean scroll) {
|
||||
// View view = getView();
|
||||
// if (view == null || getExpandableListView() == null){
|
||||
// return;
|
||||
// }
|
||||
// int x = getExpandableListView().getScrollX();
|
||||
// int y = getExpandableListView().getScrollY();
|
||||
if (getEntriesToDownload().isEmpty()) {
|
||||
findViewById(R.id.DownloadButton).setVisibility(View.GONE);
|
||||
} else {
|
||||
BasicProgressAsyncTask<?, ?, ?> task = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
|
||||
boolean running = task instanceof DownloadIndexesThread.DownloadIndexesAsyncTask;
|
||||
((Button) findViewById(R.id.DownloadButton)).setEnabled(!running);
|
||||
String text;
|
||||
int downloads = DownloadActivity.downloadListIndexThread.getDownloads();
|
||||
if (!running) {
|
||||
text = getString(R.string.download_files) + " (" + downloads + ")"; //$NON-NLS-1$
|
||||
} else {
|
||||
text = getString(R.string.downloading_file_new) + " (" + downloads + ")"; //$NON-NLS-1$
|
||||
}
|
||||
findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
|
||||
if (Version.isFreeVersion(getMyApplication())) {
|
||||
int countedDownloads = DownloadActivity.downloadListIndexThread.getDownloads();
|
||||
int left = DownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS - settings.NUMBER_OF_FREE_DOWNLOADS.get() - downloads;
|
||||
boolean excessLimit = left < 0;
|
||||
if (left < 0)
|
||||
left = 0;
|
||||
if (DownloadActivityType.isCountedInDownloads(getType())) {
|
||||
text += " (" + (excessLimit ? "! " : "") + getString(R.string.files_limit, left).toLowerCase() + ")";
|
||||
}
|
||||
}
|
||||
((Button) findViewById(R.id.DownloadButton)).setText(text);
|
||||
}
|
||||
// if (scroll) {
|
||||
// getExpandableListView().scrollTo(x, y);
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -74,14 +74,6 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
|
|||
|
||||
//getSupportActionBar().setTitle(R.string.local_index_download);
|
||||
// recreation upon rotation is pgetaprevented in manifest file
|
||||
view.findViewById(R.id.DownloadButton).setOnClickListener(new View.OnClickListener(){
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getDownloadActivity().downloadFilesCheckFreeVersion();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
filterText = (EditText) view.findViewById(R.id.search_box);
|
||||
textWatcher = new TextWatcher() {
|
||||
|
@ -340,46 +332,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
|
|||
AccessibleToast.makeText(getDownloadActivity(), MessageFormat.format(getString(R.string.items_were_selected), selected), Toast.LENGTH_SHORT).show();
|
||||
listAdapter.notifyDataSetInvalidated();
|
||||
if(selected > 0){
|
||||
updateDownloadButton(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void updateDownloadButton(boolean scroll) {
|
||||
View view = getView();
|
||||
if (view == null || getExpandableListView() == null){
|
||||
return;
|
||||
}
|
||||
int x = getExpandableListView().getScrollX();
|
||||
int y = getExpandableListView().getScrollY();
|
||||
if (getDownloadActivity().getEntriesToDownload().isEmpty()) {
|
||||
view.findViewById(R.id.DownloadButton).setVisibility(View.GONE);
|
||||
} else {
|
||||
BasicProgressAsyncTask<?, ?, ?> task = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
|
||||
boolean running = task instanceof DownloadIndexesThread.DownloadIndexesAsyncTask;
|
||||
((Button) view.findViewById(R.id.DownloadButton)).setEnabled(!running);
|
||||
String text;
|
||||
int downloads = DownloadActivity.downloadListIndexThread.getDownloads();
|
||||
if (!running) {
|
||||
text = getString(R.string.download_files) + " (" + downloads + ")"; //$NON-NLS-1$
|
||||
} else {
|
||||
text = getString(R.string.downloading_file_new) + " (" + downloads + ")"; //$NON-NLS-1$
|
||||
}
|
||||
view.findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
|
||||
if (Version.isFreeVersion(getMyApplication())) {
|
||||
int countedDownloads = DownloadActivity.downloadListIndexThread.getDownloads();
|
||||
int left = DownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS - settings.NUMBER_OF_FREE_DOWNLOADS.get() - downloads;
|
||||
boolean excessLimit = left < 0;
|
||||
if (left < 0)
|
||||
left = 0;
|
||||
if (DownloadActivityType.isCountedInDownloads(getDownloadActivity().getType())) {
|
||||
text += " (" + (excessLimit ? "! " : "") + getString(R.string.files_limit, left).toLowerCase() + ")";
|
||||
}
|
||||
}
|
||||
((Button) view.findViewById(R.id.DownloadButton)).setText(text);
|
||||
}
|
||||
if (scroll) {
|
||||
getExpandableListView().scrollTo(x, y);
|
||||
getDownloadActivity().updateDownloadButton(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -407,7 +360,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
|
|||
if(ch.isChecked()){
|
||||
ch.setChecked(!ch.isChecked());
|
||||
getDownloadActivity().getEntriesToDownload().remove(e);
|
||||
updateDownloadButton(true);
|
||||
getDownloadActivity().updateDownloadButton(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -416,7 +369,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
|
|||
// if(!fileToUnzip.exists()){
|
||||
// builder.setMessage(MessageFormat.format(getString(R.string.download_question), baseName, extractDateAndSize(e.getValue())));
|
||||
getDownloadActivity().getEntriesToDownload().put(e, download);
|
||||
updateDownloadButton(true);
|
||||
getDownloadActivity().updateDownloadButton(true);
|
||||
ch.setChecked(!ch.isChecked());
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -138,13 +138,13 @@ public class DownloadIndexesThread {
|
|||
if (o instanceof DownloadEntry) {
|
||||
if (uiFragment != null) {
|
||||
((DownloadIndexAdapter) uiFragment.getExpandableListAdapter()).notifyDataSetInvalidated();
|
||||
uiFragment.updateDownloadButton(false);
|
||||
uiFragment.getDownloadActivity().updateDownloadButton(false);
|
||||
}
|
||||
} else if (o instanceof IndexItem) {
|
||||
entriesToDownload.remove(o);
|
||||
if (uiFragment != null) {
|
||||
((DownloadIndexAdapter) uiFragment.getExpandableListAdapter()).notifyDataSetInvalidated();
|
||||
uiFragment.updateDownloadButton(false);
|
||||
uiFragment.getDownloadActivity().updateDownloadButton(false);
|
||||
}
|
||||
} else if (o instanceof String) {
|
||||
AccessibleToast.makeText(ctx, (String) o, Toast.LENGTH_LONG).show();
|
||||
|
|
|
@ -67,7 +67,7 @@ public class UpdatesIndexFragment extends SherlockListFragment {
|
|||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
View v = convertView;
|
||||
|
||||
if(v == null){
|
||||
|
@ -83,8 +83,29 @@ public class UpdatesIndexFragment extends SherlockListFragment {
|
|||
String d = e.getDate(format) + "\n" + e.getSizeDescription(getMyApplication());
|
||||
description.setText(d);
|
||||
|
||||
CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);
|
||||
final CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);
|
||||
ch.setChecked(getDownloadActivity().getEntriesToDownload().containsKey(e));
|
||||
ch.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ch.setChecked(!ch.isChecked());
|
||||
final IndexItem e = (IndexItem) getListAdapter().getItem(position);
|
||||
if(ch.isChecked()){
|
||||
ch.setChecked(!ch.isChecked());
|
||||
getDownloadActivity().getEntriesToDownload().remove(e);
|
||||
getDownloadActivity().updateDownloadButton(true);
|
||||
return;
|
||||
}
|
||||
|
||||
List<DownloadEntry> download = e.createDownloadEntry(getMyApplication(), getDownloadActivity().getType(), new ArrayList<DownloadEntry>());
|
||||
if (download.size() > 0) {
|
||||
getDownloadActivity().getEntriesToDownload().put(e, download);
|
||||
getDownloadActivity().updateDownloadButton(true);
|
||||
ch.setChecked(!ch.isChecked());
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return v;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue