Fix
This commit is contained in:
commit
a5fa3e172d
13 changed files with 1426 additions and 198 deletions
4
LICENSE
4
LICENSE
|
@ -143,4 +143,6 @@
|
|||
- Montreal: "Montreal Metro" by STM - http://www.stm.info/en-bref/pictometro.htm. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:Montreal_Metro.svg#/media/File:Montreal_Metro.svg
|
||||
- Toronto: "TTC" by Source. Licensed under Fair use via Wikipedia - https://en.wikipedia.org/wiki/File:TTC.svg#/media/File:TTC.svg
|
||||
- Bangkok: "MRT (Bangkok) logo" by Bangkok_Metro_logo.png: Paul_012.Original uploader was Paul 012 at en.wikipediaderivative work: Nevetsjc (talk)Revision traced from http://si0.twimg.com/profile_images/975897559/logo.jpg - Bangkok_Metro_logo.png. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:MRT_(Bangkok)_logo.svg#/media/File:MRT_(Bangkok)_logo.svg
|
||||
- Rotterdam: "RET metro logo" by Sebastiaan1997 - Own work. Licensed under CC BY-SA 3.0 via Commons - https://commons.wikimedia.org/wiki/File:RET_metro_logo.svg#/media/File:RET_metro_logo.svg
|
||||
- Rotterdam: "RET metro logo" by Sebastiaan1997 - Own work. Licensed under CC BY-SA 3.0 via Commons - https://commons.wikimedia.org/wiki/File:RET_metro_logo.svg#/media/File:RET_metro_logo.svg
|
||||
- Amsterdam: "Amsterdam metro" by Peeperman - Own work. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:Amsterdam_metro.svg#/media/File:Amsterdam_metro.svg
|
||||
- Brussels: "Brussels Metro logo" by Source. Licensed under Fair use via Wikipedia - https://en.wikipedia.org/wiki/File:Brussels_Metro_logo.svg#/media/File:Brussels_Metro_logo.svg
|
|
@ -3,7 +3,8 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/mainLayout">
|
||||
|
||||
<net.osmand.plus.views.controls.PagerSlidingTabStrip
|
||||
android:id="@+id/sliding_tabs"
|
||||
|
@ -11,83 +12,10 @@
|
|||
android:layout_height="@dimen/list_item_height"
|
||||
android:background="?attr/colorPrimary" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ProgressView"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" >
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="3dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:gravity="center_vertical|left"
|
||||
android:orientation="horizontal" >
|
||||
<include layout="@layout/free_version_banner"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/IndeterminateProgressBar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:indeterminate="true"
|
||||
android:indeterminateOnly="true"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ProgressPercent"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:gravity="right|center_vertical"
|
||||
android:maxLines="1"
|
||||
android:text=""
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
tools:text="@string/lorem_ipsum" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ProgressMessage"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginLeft="3dp"
|
||||
android:layout_toLeftOf="@id/ProgressPercent"
|
||||
android:layout_toRightOf="@id/IndeterminateProgressBar"
|
||||
android:ellipsize="end"
|
||||
android:gravity="left|center_vertical"
|
||||
android:singleLine="true"
|
||||
android:text=""
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
tools:text="@string/lorem_ipsum" />
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/memory_progress"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
tools:progress="50"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/Cancel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_action_remove_dark" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<include layout="@layout/progress_with_two_texts"/>
|
||||
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/pager"
|
||||
|
|
|
@ -2,12 +2,7 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="?attr/ctx_menu_info_view_bg">
|
||||
|
||||
<include layout="@layout/free_version_banner"/>
|
||||
|
||||
<include layout="@layout/progress_with_two_texts"/>
|
||||
|
||||
android:background="?attr/ctx_menu_info_view_bg"
|
||||
android:orientation="vertical">
|
||||
<include layout="@layout/download_items_list"/>
|
||||
</LinearLayout>
|
|
@ -1,10 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/freeVersionBanner"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/freeVersionBanner"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
|
@ -12,6 +12,7 @@
|
|||
tools:showIn="@layout/local_index_fragment_header">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/freeVersionBannerTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="4dp">
|
||||
|
@ -47,8 +48,9 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:max="10"
|
||||
tools:progress="5"
|
||||
android:progressDrawable="@drawable/number_of_downloads_progress_bar_drawable"/>
|
||||
android:progressDrawable="@drawable/number_of_downloads_progress_bar_drawable"
|
||||
android:saveEnabled="false"
|
||||
tools:progress="5"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
@ -162,16 +164,16 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
osmand:textAllCapsCompat="true"
|
||||
android:text="@string/get_full_version"/>
|
||||
android:text="@string/get_full_version"
|
||||
osmand:textAllCapsCompat="true"/>
|
||||
|
||||
<net.osmand.plus.widgets.ButtonEx
|
||||
android:id="@+id/laterButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
osmand:textAllCapsCompat="true"
|
||||
android:text="@string/later"/>
|
||||
android:text="@string/later"
|
||||
osmand:textAllCapsCompat="true"/>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -262,7 +262,7 @@
|
|||
<string name="poi_research">Forskning</string>
|
||||
<string name="poi_it">IT kontor</string>
|
||||
<string name="poi_newspaper">Avisredaktion</string>
|
||||
<string name="poi_architect">Arkitekt</string>
|
||||
<string name="poi_architect">Arkitektkontor</string>
|
||||
<string name="poi_advertising_agency">Reklamebureau</string>
|
||||
<string name="poi_educational_institution">Uddannelsesinstitution</string>
|
||||
<string name="poi_studio">Lydstudio</string>
|
||||
|
@ -1829,7 +1829,7 @@
|
|||
<string name="poi_shelter_type_basic_hut">Sheltertype: hytte</string>
|
||||
<string name="poi_shelter_type_building">Sheltertype: bygning</string>
|
||||
<string name="poi_shelter_type_wildlife_hide">Sheltertype: vildtskjul</string>
|
||||
<string name="poi_shelter_type_rock_shelter">Sheltertype: heller</string>
|
||||
<string name="poi_shelter_type_rock_shelter">Sheltertype: klippehule</string>
|
||||
<string name="poi_shelter_type_sun_shelter">Sheltertype: solafskærming</string>
|
||||
<string name="poi_shelter_type_field_shelter">Sheltertype: feltly</string>
|
||||
<string name="poi_shelter_type_tent">Sheltertype: telt</string>
|
||||
|
@ -1861,4 +1861,29 @@
|
|||
<string name="poi_artwork_type_stele">Kunstværk: stele</string>
|
||||
<string name="poi_artwork_type_fountain">Kunstværk: springvand</string>
|
||||
|
||||
<string name="poi_width">Bredde</string>
|
||||
|
||||
<string name="poi_architect_name">Arkitekt</string>
|
||||
|
||||
<string name="poi_architecture_modern">Arkitektur: moderne</string>
|
||||
<string name="poi_architecture_stalinist_neoclassicism">Arkitektur: stalinistisk nyklassicisme</string>
|
||||
<string name="poi_architecture_eclectic">Arkitektur: eklecticisme</string>
|
||||
<string name="poi_architecture_new_objectivity">Arkitektur: ny objektivitet</string>
|
||||
<string name="poi_architecture_contemporary">Arkitektur: moderne</string>
|
||||
<string name="poi_architecture_constructivism">Arkitektur: konstruktivisme</string>
|
||||
<string name="poi_architecture_umgebinde">Arkitektur: umgebindehaus</string>
|
||||
<string name="poi_architecture_timber_frame">Arkitektur: træskelet</string>
|
||||
<string name="poi_architecture_art_nouveau">Arkitektur: jugendstil</string>
|
||||
<string name="poi_architecture_neoclassicism">Arkitektur: nyklassicisme</string>
|
||||
<string name="poi_architecture_victorian">Arkitektur: victoriansk</string>
|
||||
<string name="poi_architecture_brutalism">Arkitektur: brutalisme</string>
|
||||
<string name="poi_architecture_classicism">Arkitektur: klassicisme</string>
|
||||
<string name="poi_architecture_gothic">Arkitektur: gotik</string>
|
||||
<string name="poi_architecture_oldrussian">Arkitektur: gammelrussisk</string>
|
||||
<string name="poi_architecture_baroque">Arkitektur: barok</string>
|
||||
<string name="poi_architecture_postconstructivism">Arkitektur: postkonstruktivisme</string>
|
||||
<string name="poi_architecture_wilhelminian_style">Arkitektur: wilheminsk stil</string>
|
||||
<string name="poi_architecture_renaissance">Arkitektur: renæssance</string>
|
||||
<string name="poi_architecture_romanesque">Arkitektur: romansk stil</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -574,12 +574,12 @@
|
|||
<string name="gps_provider">GPS</string>
|
||||
<string name="int_seconds">секунд</string>
|
||||
<string name="int_min">мин.</string>
|
||||
<string name="background_service_int_descr">Выберите интервал позиционирования для сервиса</string>
|
||||
<string name="background_service_int_descr">Выберите интервал пробуждения для фоновой службы</string>
|
||||
<string name="background_service_int">Интервал пробуждения GPS</string>
|
||||
<string name="background_service_provider_descr">Выберите источник позиционирования для сервиса</string>
|
||||
<string name="background_service_provider_descr">Выберите источник позиционирования для фоновой службы</string>
|
||||
<string name="background_service_provider">Источник позиционирования</string>
|
||||
<string name="background_router_service_descr">Запускает OsmAnd в фоновом режиме для отслеживания местоположения при выключенном экране</string>
|
||||
<string name="background_router_service">Сервис навигации</string>
|
||||
<string name="background_router_service">Запуск приложения в фоновом режиме</string>
|
||||
<string name="off_router_service_no_gps_available">Сервис маршрутизации OsmAnd включён, если отключить позиционирование, он перестанет вести по маршруту.</string>
|
||||
<string name="routing_settings_descr">Настройки навигации</string>
|
||||
<string name="routing_settings">Навигация</string>
|
||||
|
@ -2103,4 +2103,23 @@
|
|||
<string name="simulate_your_location_stop_descr">Остановить моделирование</string>
|
||||
<string name="favorite_category_add_new">Добавить новую</string>
|
||||
<string name="favorite_category_select">Выберите категорию</string>
|
||||
<string name="default_speed_system_descr">Выберите единицы измерения скорости</string>
|
||||
<string name="default_speed_system">Единицы измерения скорости</string>
|
||||
<string name="si_nm">Морские мили</string>
|
||||
<string name="si_kmh">Километр в час</string>
|
||||
<string name="si_mph">Миля в час</string>
|
||||
<string name="si_m_s">Метр в секунду</string>
|
||||
<string name="si_min_km">Минута на километр</string>
|
||||
<string name="si_min_m">Минута на милю</string>
|
||||
<string name="si_nm_h">Морская миля в час (узел)</string>
|
||||
<string name="min_mile">мин/м</string>
|
||||
<string name="min_km">мин/км</string>
|
||||
<string name="m_s">м/с</string>
|
||||
|
||||
<string name="shared_string_trip_recording">Запись поездки</string>
|
||||
<string name="shared_string_navigation">Навигация</string>
|
||||
<string name="favourites_edit_dialog_title">Информация об избранной точке</string>
|
||||
<string name="routing_attr_avoid_shuttle_train_name">Избегать пригородных поездов</string>
|
||||
<string name="routing_attr_avoid_shuttle_train_description">Избегать пригородных поездов</string>
|
||||
<string name="traffic_warning_hazard">Опасность</string>
|
||||
</resources>
|
||||
|
|
|
@ -1665,4 +1665,12 @@
|
|||
<string name="poi_toilets_access_community">洗手間進出:社區</string>
|
||||
<string name="poi_toilets_access_public">洗手間進出:公共</string>
|
||||
|
||||
<string name="poi_diaper_room">尿布更換室</string>
|
||||
|
||||
<string name="poi_diaper_yes">尿布更換台</string>
|
||||
<string name="poi_diaper_no">無尿布更換台</string>
|
||||
<string name="poi_maxstay">停車時限</string>
|
||||
|
||||
<string name="poi_vending_parking_tickets">停車票卡</string>
|
||||
<string name="poi_vending_cigarettes">香菸</string>
|
||||
</resources>
|
||||
|
|
|
@ -22,12 +22,12 @@ import android.widget.BaseAdapter;
|
|||
import android.widget.BaseExpandableListAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ExpandableListAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
|
@ -39,11 +39,14 @@ import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
|||
import net.osmand.plus.activities.OsmandExpandableListFragment;
|
||||
import net.osmand.plus.activities.TabActivity;
|
||||
import net.osmand.plus.base.BasicProgressAsyncTask;
|
||||
import net.osmand.plus.download.items.RegionDialogFragment;
|
||||
import net.osmand.plus.download.items.SearchDialogFragment;
|
||||
import net.osmand.plus.download.items.WorldItemsFragment;
|
||||
import net.osmand.plus.srtmplugin.SRTMPlugin;
|
||||
import net.osmand.plus.views.controls.PagerSlidingTabStrip;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
|
@ -54,15 +57,7 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
|
||||
public class DownloadActivity extends BaseDownloadActivity {
|
||||
|
||||
private View progressView;
|
||||
private ProgressBar indeterminateProgressBar;
|
||||
private ProgressBar determinateProgressBar;
|
||||
private TextView progressMessage;
|
||||
private TextView progressPercent;
|
||||
private ImageView cancel;
|
||||
|
||||
public class DownloadActivity extends BaseDownloadActivity implements RegionDialogFragment.DialogDismissListener {
|
||||
private List<LocalIndexInfo> localIndexInfos = new ArrayList<LocalIndexInfo>();
|
||||
|
||||
private String initialFilter = "";
|
||||
|
@ -135,21 +130,6 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
|
||||
settings = ((OsmandApplication) getApplication()).getSettings();
|
||||
|
||||
indeterminateProgressBar = (ProgressBar) findViewById(R.id.IndeterminateProgressBar);
|
||||
determinateProgressBar = (ProgressBar) findViewById(R.id.memory_progress);
|
||||
progressView = findViewById(R.id.ProgressView);
|
||||
progressMessage = (TextView) findViewById(R.id.ProgressMessage);
|
||||
progressPercent = (TextView) findViewById(R.id.ProgressPercent);
|
||||
cancel = (ImageView) findViewById(R.id.Cancel);
|
||||
cancel.setImageDrawable(getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_remove_dark));
|
||||
cancel.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
makeSureUserCancelDownload();
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.downloadButton).setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
|
@ -221,6 +201,7 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
protected void onResume() {
|
||||
super.onResume();
|
||||
getMyApplication().getAppCustomization().resumeActivity(DownloadActivity.class, this);
|
||||
initFreeVersionBanner(findViewById(R.id.mainLayout));
|
||||
}
|
||||
|
||||
|
||||
|
@ -260,53 +241,15 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
|
||||
@Override
|
||||
public void updateProgress(boolean updateOnlyProgress) {
|
||||
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
|
||||
final boolean isFinished = basicProgressAsyncTask == null
|
||||
|| basicProgressAsyncTask.getStatus() == AsyncTask.Status.FINISHED;
|
||||
boolean indeterminate = true;
|
||||
int percent = 0;
|
||||
String message = "";
|
||||
if (!isFinished) {
|
||||
indeterminate = basicProgressAsyncTask.isIndeterminate();
|
||||
message = basicProgressAsyncTask.getDescription();
|
||||
if (!indeterminate) {
|
||||
percent = basicProgressAsyncTask.getProgressPercentage();
|
||||
}
|
||||
}
|
||||
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask =
|
||||
DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
|
||||
if (visibleBanner != null) {
|
||||
visibleBanner.updateProgress(isFinished, indeterminate, percent, message);
|
||||
final int countedDownloads = DownloadActivity.downloadListIndexThread.getCountedDownloads();
|
||||
visibleBanner.updateProgress(countedDownloads, basicProgressAsyncTask);
|
||||
}
|
||||
if (!updateOnlyProgress) {
|
||||
updateDownloadButton();
|
||||
}
|
||||
|
||||
|
||||
// TODO delete after refactoring!
|
||||
//needed when rotation is performed and progress can be null
|
||||
if (progressView == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (updateOnlyProgress) {
|
||||
if (basicProgressAsyncTask != null && !basicProgressAsyncTask.isIndeterminate()) {
|
||||
progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() + "%");
|
||||
determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
|
||||
}
|
||||
} else {
|
||||
progressView.setVisibility(!isFinished ? View.VISIBLE : View.GONE);
|
||||
if (!isFinished) {
|
||||
indeterminateProgressBar.setVisibility(!indeterminate ? View.GONE : View.VISIBLE);
|
||||
determinateProgressBar.setVisibility(indeterminate ? View.GONE : View.VISIBLE);
|
||||
cancel.setVisibility(indeterminate ? View.GONE : View.VISIBLE);
|
||||
progressPercent.setVisibility(indeterminate ? View.GONE : View.VISIBLE);
|
||||
|
||||
progressMessage.setText(basicProgressAsyncTask.getDescription());
|
||||
if (!indeterminate) {
|
||||
progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() + "%");
|
||||
determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -636,14 +579,12 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
|
||||
|
||||
public void showDialog(FragmentActivity activity, DialogFragment fragment) {
|
||||
FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
|
||||
Fragment prev = activity.getSupportFragmentManager().findFragmentByTag("dialog");
|
||||
if (prev != null) {
|
||||
ft.remove(prev);
|
||||
}
|
||||
ft.addToBackStack(null);
|
||||
fragment.show(activity.getSupportFragmentManager(), "dialog");
|
||||
}
|
||||
|
||||
fragment.show(ft, "dialog");
|
||||
@Override
|
||||
public void onDialogDismissed() {
|
||||
initFreeVersionBanner(findViewById(R.id.mainLayout));
|
||||
}
|
||||
|
||||
private static class ToggleCollapseFreeVersionBanner implements View.OnClickListener {
|
||||
|
@ -674,46 +615,57 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
private final ProgressBar progressBar;
|
||||
private final TextView leftTextView;
|
||||
private final TextView rightTextView;
|
||||
private final Context ctx;
|
||||
private final boolean shouldShowFreeVersionBanner;
|
||||
private final ProgressBar downloadsLeftProgressBar;
|
||||
private final View buttonsLinearLayout;
|
||||
private final TextView freeVersionDescriptionTextView;
|
||||
private OsmandApplication application;
|
||||
private final TextView downloadsLeftTextView;
|
||||
private final View laterButton;
|
||||
|
||||
private final Context ctx;
|
||||
private final OsmandApplication application;
|
||||
private final boolean shouldShowFreeVersionBanner;
|
||||
private final View freeVersionBannerTitle;
|
||||
|
||||
public BannerAndDownloadFreeVersion(View view, Context ctx) {
|
||||
this.ctx = ctx;
|
||||
application = (OsmandApplication) ctx.getApplicationContext();
|
||||
freeVersionBanner = view.findViewById(R.id.freeVersionBanner);
|
||||
downloadProgressLayout = view.findViewById(R.id.downloadProgressLayout);
|
||||
progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
|
||||
leftTextView = (TextView) view.findViewById(R.id.leftTextView);
|
||||
rightTextView = (TextView) view.findViewById(R.id.rightTextView);
|
||||
application = (OsmandApplication) ctx.getApplicationContext();
|
||||
shouldShowFreeVersionBanner = Version.isFreeVersion(application)
|
||||
|| application.getSettings().SHOULD_SHOW_FREE_VERSION_BANNER.get();
|
||||
initFreeVersionBanner();
|
||||
downloadsLeftTextView = (TextView) freeVersionBanner.findViewById(R.id.downloadsLeftTextView);
|
||||
downloadsLeftProgressBar = (ProgressBar) freeVersionBanner.findViewById(R.id.downloadsLeftProgressBar);
|
||||
downloadsLeftProgressBar = (ProgressBar) freeVersionBanner.findViewById(R.id.downloadsLeftProgressBar);
|
||||
buttonsLinearLayout = freeVersionBanner.findViewById(R.id.buttonsLinearLayout);
|
||||
freeVersionDescriptionTextView = (TextView) freeVersionBanner
|
||||
.findViewById(R.id.freeVersionDescriptionTextView);
|
||||
laterButton = freeVersionBanner.findViewById(R.id.laterButton);
|
||||
freeVersionBannerTitle = freeVersionBanner.findViewById(R.id.freeVersionBannerTitle);
|
||||
|
||||
shouldShowFreeVersionBanner = Version.isFreeVersion(application)
|
||||
|| application.getSettings().SHOULD_SHOW_FREE_VERSION_BANNER.get();
|
||||
|
||||
initFreeVersionBanner();
|
||||
updateFreeVersionBanner();
|
||||
}
|
||||
|
||||
public void updateProgress(boolean isFinished, boolean indeterminate, int percent, String message) {
|
||||
public void updateProgress(int countedDownloads,
|
||||
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask) {
|
||||
final boolean isFinished = basicProgressAsyncTask == null
|
||||
|| basicProgressAsyncTask.getStatus() == AsyncTask.Status.FINISHED;
|
||||
if (isFinished) {
|
||||
downloadProgressLayout.setVisibility(View.GONE);
|
||||
// TODO
|
||||
// freeVersionBanner.setVisibility(View.VISIBLE);
|
||||
updateFreeVersionBanner();
|
||||
} else {
|
||||
if (freeVersionBanner.getVisibility() == View.VISIBLE) {
|
||||
freeVersionBanner.setVisibility(View.GONE);
|
||||
}
|
||||
boolean indeterminate = basicProgressAsyncTask.isIndeterminate();
|
||||
String message = basicProgressAsyncTask.getDescription();
|
||||
int percent = basicProgressAsyncTask.getProgressPercentage();
|
||||
|
||||
setMinimizedFreeVersionBanner(true);
|
||||
updateAvailableDownloads(countedDownloads);
|
||||
downloadProgressLayout.setVisibility(View.VISIBLE);
|
||||
progressBar.setIndeterminate(indeterminate);
|
||||
if (indeterminate) {
|
||||
// TODO
|
||||
leftTextView.setText(message);
|
||||
} else {
|
||||
// TODO if only 1 map, show map name
|
||||
|
@ -731,6 +683,7 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
freeVersionBanner.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
freeVersionBanner.setVisibility(View.VISIBLE);
|
||||
downloadsLeftProgressBar.setMax(BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS);
|
||||
freeVersionDescriptionTextView.setText(ctx.getString(R.string.free_version_message,
|
||||
BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS));
|
||||
|
@ -746,21 +699,45 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
}
|
||||
}
|
||||
});
|
||||
freeVersionBanner.findViewById(R.id.laterButton).setOnClickListener(
|
||||
laterButton.setOnClickListener(
|
||||
new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView, buttonsLinearLayout));
|
||||
}
|
||||
|
||||
private void updateFreeVersionBanner() {
|
||||
if (!shouldShowFreeVersionBanner) return;
|
||||
setMinimizedFreeVersionBanner(false);
|
||||
OsmandSettings settings = application.getSettings();
|
||||
downloadsLeftProgressBar.setProgress(settings.NUMBER_OF_FREE_DOWNLOADS.get());
|
||||
final int downloadsLeft = BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS
|
||||
- settings.NUMBER_OF_FREE_DOWNLOADS.get();
|
||||
final Integer mapsDownloaded = settings.NUMBER_OF_FREE_DOWNLOADS.get();
|
||||
downloadsLeftProgressBar.setProgress(mapsDownloaded);
|
||||
int downloadsLeft = BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS
|
||||
- mapsDownloaded;
|
||||
downloadsLeft = Math.max(downloadsLeft, 0);
|
||||
if (downloadsLeft <= 0) {
|
||||
laterButton.setVisibility(View.GONE);
|
||||
}
|
||||
downloadsLeftTextView.setText(ctx.getString(R.string.downloads_left_template, downloadsLeft));
|
||||
// TODO review logic
|
||||
freeVersionBanner.setOnClickListener(new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView,
|
||||
buttonsLinearLayout));
|
||||
}
|
||||
|
||||
private void updateAvailableDownloads(int activeTasks) {
|
||||
OsmandSettings settings = application.getSettings();
|
||||
final Integer mapsDownloaded = settings.NUMBER_OF_FREE_DOWNLOADS.get() + activeTasks;
|
||||
downloadsLeftProgressBar.setProgress(mapsDownloaded);
|
||||
}
|
||||
|
||||
private void setMinimizedFreeVersionBanner(boolean minimize) {
|
||||
if (minimize) {
|
||||
freeVersionDescriptionTextView.setVisibility(View.GONE);
|
||||
buttonsLinearLayout.setVisibility(View.GONE);
|
||||
freeVersionBannerTitle.setVisibility(View.GONE);
|
||||
} else {
|
||||
freeVersionDescriptionTextView.setVisibility(View.VISIBLE);
|
||||
buttonsLinearLayout.setVisibility(View.VISIBLE);
|
||||
freeVersionBannerTitle.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
745
OsmAnd/src/net/osmand/plus/download/DownloadActivity.java.orig
Normal file
745
OsmAnd/src/net/osmand/plus/download/DownloadActivity.java.orig
Normal file
|
@ -0,0 +1,745 @@
|
|||
package net.osmand.plus.download;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.BaseExpandableListAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ExpandableListAdapter;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.activities.LocalIndexInfo;
|
||||
import net.osmand.plus.activities.OsmAndListFragment;
|
||||
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||
import net.osmand.plus.activities.OsmandExpandableListFragment;
|
||||
import net.osmand.plus.activities.TabActivity;
|
||||
import net.osmand.plus.base.BasicProgressAsyncTask;
|
||||
<<<<<<< HEAD
|
||||
import net.osmand.plus.download.items.SearchDialogFragment;
|
||||
=======
|
||||
import net.osmand.plus.download.items.RegionDialogFragment;
|
||||
>>>>>>> 123c270bc595f997b400d0de3681e6ab22f427cf
|
||||
import net.osmand.plus.download.items.WorldItemsFragment;
|
||||
import net.osmand.plus.srtmplugin.SRTMPlugin;
|
||||
import net.osmand.plus.views.controls.PagerSlidingTabStrip;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class DownloadActivity extends BaseDownloadActivity implements RegionDialogFragment.DialogDismissListener {
|
||||
private List<LocalIndexInfo> localIndexInfos = new ArrayList<LocalIndexInfo>();
|
||||
|
||||
private String initialFilter = "";
|
||||
private boolean singleTab;
|
||||
|
||||
List<TabActivity.TabItem> mTabs = new ArrayList<TabActivity.TabItem>();
|
||||
|
||||
public static final String FILTER_KEY = "filter";
|
||||
public static final String FILTER_CAT = "filter_cat";
|
||||
|
||||
public static final String TAB_TO_OPEN = "Tab_to_open";
|
||||
public static final String LOCAL_TAB = "local";
|
||||
public static final String DOWNLOAD_TAB = "download";
|
||||
public static final String UPDATES_TAB = "updates";
|
||||
public static final String SINGLE_TAB = "SINGLE_TAB";
|
||||
private List<DownloadActivityType> downloadTypes = new ArrayList<DownloadActivityType>();
|
||||
private BannerAndDownloadFreeVersion visibleBanner;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
getMyApplication().applyTheme(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
updateDownloads();
|
||||
|
||||
setContentView(R.layout.download);
|
||||
singleTab = getIntent() != null && getIntent().getBooleanExtra(SINGLE_TAB, false);
|
||||
int currentTab = 0;
|
||||
String tab = getIntent() == null || getIntent().getExtras() == null ? null : getIntent().getExtras().getString(TAB_TO_OPEN);
|
||||
if (tab != null) {
|
||||
if (tab.equals(DOWNLOAD_TAB)) {
|
||||
currentTab = 1;
|
||||
} else if (tab.equals(UPDATES_TAB)) {
|
||||
currentTab = 2;
|
||||
}
|
||||
}
|
||||
// if (singleTab) {
|
||||
// ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
|
||||
// viewPager.setVisibility(View.GONE);
|
||||
// Fragment f = currentTab == 0 ? new LocalIndexesFragment() :
|
||||
// (currentTab == 1? new DownloadIndexFragment() : new UpdatesIndexFragment());
|
||||
// String tag = currentTab == 0 ? LOCAL_TAB :
|
||||
// (currentTab == 1 ? DOWNLOAD_TAB : UPDATES_TAB);
|
||||
// findViewById(R.id.layout).setVisibility(View.VISIBLE);
|
||||
// android.support.v4.app.FragmentManager manager = getSupportFragmentManager();
|
||||
// if (manager.findFragmentByTag(tag) == null){
|
||||
// getSupportFragmentManager().beginTransaction().add(R.id.layout, f, tag).commit();
|
||||
// }
|
||||
// } else {
|
||||
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
|
||||
PagerSlidingTabStrip mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tabs);
|
||||
|
||||
mTabs.add(new TabActivity.TabItem(R.string.download_tab_local,
|
||||
getString(R.string.download_tab_local), LocalIndexesFragment.class));
|
||||
mTabs.add(new TabActivity.TabItem(R.string.download_tab_downloads,
|
||||
getString(R.string.download_tab_downloads), DownloadIndexFragment.class));
|
||||
mTabs.add(new TabActivity.TabItem(R.string.download_tab_updates,
|
||||
getString(R.string.download_tab_updates), UpdatesIndexFragment.class));
|
||||
|
||||
// mTabs.add(new TabActivity.TabItem(R.string.download_tab_local,
|
||||
// getString(R.string.download_tab_local), NewLocalIndexesFragment.class));
|
||||
mTabs.add(new TabActivity.TabItem(R.string.download_tab_downloads,
|
||||
getString(R.string.download_tab_downloads), WorldItemsFragment.class));
|
||||
|
||||
viewPager.setAdapter(new TabActivity.OsmandFragmentPagerAdapter(getSupportFragmentManager(), mTabs));
|
||||
mSlidingTabLayout.setViewPager(viewPager);
|
||||
|
||||
viewPager.setCurrentItem(currentTab);
|
||||
// }
|
||||
|
||||
settings = ((OsmandApplication) getApplication()).getSettings();
|
||||
|
||||
findViewById(R.id.downloadButton).setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
downloadFilesCheckFreeVersion();
|
||||
}
|
||||
|
||||
});
|
||||
findViewById(R.id.wikiButton).setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
downloadWikiFiles();
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.CancelAll).setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getEntriesToDownload().clear();
|
||||
updateDownloadButton();
|
||||
for (WeakReference<Fragment> ref : fragSet) {
|
||||
Fragment f = ref.get();
|
||||
if (f != null) {
|
||||
if (f instanceof OsmAndListFragment) {
|
||||
if (f.isAdded() && ((OsmAndListFragment) f).getListAdapter() instanceof ArrayAdapter) {
|
||||
((ArrayAdapter) ((OsmAndListFragment) f).getListAdapter()).notifyDataSetChanged();
|
||||
}
|
||||
} else if (f.isAdded() && f instanceof OsmandExpandableListFragment &&
|
||||
((OsmandExpandableListFragment) f).getAdapter() instanceof BaseExpandableListAdapter) {
|
||||
((BaseExpandableListAdapter) ((OsmandExpandableListFragment) f).getAdapter()).notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
downloadTypes = createDownloadTypes();
|
||||
final Intent intent = getIntent();
|
||||
if (intent != null && intent.getExtras() != null) {
|
||||
final String filter = intent.getExtras().getString(FILTER_KEY);
|
||||
if (filter != null) {
|
||||
initialFilter = filter;
|
||||
}
|
||||
|
||||
final String filterCat = intent.getExtras().getString(FILTER_CAT);
|
||||
if (filterCat != null) {
|
||||
DownloadActivityType type = DownloadActivityType.getIndexType(filterCat.toLowerCase());
|
||||
if (type != null) {
|
||||
downloadTypes.remove(type);
|
||||
downloadTypes.add(0, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
changeType(downloadTypes.get(0));
|
||||
}
|
||||
|
||||
|
||||
public Map<String, String> getIndexActivatedFileNames() {
|
||||
return downloadListIndexThread != null ? downloadListIndexThread.getIndexActivatedFileNames() : null;
|
||||
}
|
||||
|
||||
public String getInitialFilter() {
|
||||
return initialFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
getMyApplication().getAppCustomization().resumeActivity(DownloadActivity.class, this);
|
||||
initFreeVersionBanner(findViewById(R.id.mainLayout));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int itemId = item.getItemId();
|
||||
switch (itemId) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setLocalIndexInfos(List<LocalIndexInfo> list) {
|
||||
this.localIndexInfos = list;
|
||||
}
|
||||
|
||||
public List<LocalIndexInfo> getLocalIndexInfos() {
|
||||
return localIndexInfos;
|
||||
}
|
||||
|
||||
public void changeType(final DownloadActivityType tp) {
|
||||
//invalidateOptionsMenu();
|
||||
if (downloadListIndexThread != null && type != tp) {
|
||||
type = tp;
|
||||
downloadListIndexThread.runCategorization(tp);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
getMyApplication().getAppCustomization().pauseActivity(DownloadActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgress(boolean updateOnlyProgress) {
|
||||
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask =
|
||||
DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
|
||||
if (visibleBanner != null) {
|
||||
final int countedDownloads = DownloadActivity.downloadListIndexThread.getCountedDownloads();
|
||||
visibleBanner.updateProgress(countedDownloads, basicProgressAsyncTask);
|
||||
}
|
||||
if (!updateOnlyProgress) {
|
||||
updateDownloadButton();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDownloadList(List<IndexItem> list) {
|
||||
for (WeakReference<Fragment> ref : fragSet) {
|
||||
Fragment f = ref.get();
|
||||
if (f instanceof UpdatesIndexFragment) {
|
||||
if (f.isAdded()) {
|
||||
((UpdatesIndexFragment) f).updateItemsList(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void categorizationFinished(List<IndexItem> filtered, List<IndexItemCategory> cats) {
|
||||
for (WeakReference<Fragment> ref : fragSet) {
|
||||
Fragment f = ref.get();
|
||||
if (f instanceof DownloadIndexFragment) {
|
||||
if (f.isAdded()) {
|
||||
((DownloadIndexFragment) f).categorizationFinished(filtered, cats);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCategorizationFinished() {
|
||||
for (WeakReference<Fragment> ref : fragSet) {
|
||||
Fragment f = ref.get();
|
||||
if (f instanceof WorldItemsFragment) {
|
||||
if (f.isAdded()) {
|
||||
((WorldItemsFragment) f).onCategorizationFinished();
|
||||
}
|
||||
} else if (f instanceof SearchDialogFragment) {
|
||||
if (f.isAdded()) {
|
||||
((SearchDialogFragment) f).onCategorizationFinished();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void downloadListUpdated() {
|
||||
for (WeakReference<Fragment> ref : fragSet) {
|
||||
Fragment f = ref.get();
|
||||
if (f instanceof DownloadIndexFragment) {
|
||||
if (f.isAdded()) {
|
||||
((DownloadIndexAdapter) ((DownloadIndexFragment) f).getExpandableListAdapter())
|
||||
.notifyDataSetInvalidated();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startDownload(IndexItem item) {
|
||||
final boolean b = super.startDownload(item);
|
||||
visibleBanner.initFreeVersionBanner();
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadedIndexes() {
|
||||
for (WeakReference<Fragment> ref : fragSet) {
|
||||
Fragment f = ref.get();
|
||||
if (f instanceof LocalIndexesFragment) {
|
||||
if (f.isAdded()) {
|
||||
((LocalIndexesFragment) f).reloadData();
|
||||
}
|
||||
} else if (f instanceof DownloadIndexFragment) {
|
||||
if (f.isAdded()) {
|
||||
DownloadIndexAdapter adapter = ((DownloadIndexAdapter)
|
||||
((DownloadIndexFragment) f).getExpandableListAdapter());
|
||||
if (adapter != null) {
|
||||
adapter.setLoadedFiles(getIndexActivatedFileNames(), getIndexFileNames());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void downloadWikiFiles() {
|
||||
if (Version.isFreeVersion(getMyApplication())) {
|
||||
new InstallPaidVersionDialogFragment().show(getSupportFragmentManager(),
|
||||
InstallPaidVersionDialogFragment.TAG);
|
||||
} else {
|
||||
Builder bld = new AlertDialog.Builder(this);
|
||||
final List<IndexItem> wi = getWikipediaItems();
|
||||
long size = 0;
|
||||
for (IndexItem i : wi) {
|
||||
size += i.getSize();
|
||||
}
|
||||
bld.setMessage(getString(R.string.download_wikipedia_files, (size >> 20)));
|
||||
bld.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
for (IndexItem i : wi) {
|
||||
addToDownload(i);
|
||||
}
|
||||
updateDownloadButton();
|
||||
checkOldWikiFiles();
|
||||
}
|
||||
});
|
||||
bld.setNegativeButton(R.string.shared_string_cancel, null);
|
||||
if (wi.size() > 0) {
|
||||
bld.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkOldWikiFiles() {
|
||||
Map<String, String> fileNames = getMyApplication().getResourceManager().getIndexFileNames();
|
||||
final Set<String> wiki = new HashSet<String>();
|
||||
for (String s : fileNames.keySet()) {
|
||||
if (s.contains("_wiki")) {
|
||||
wiki.add(s);
|
||||
}
|
||||
}
|
||||
if (wiki.size() > 0) {
|
||||
Builder bld = new AlertDialog.Builder(this);
|
||||
bld.setMessage(R.string.archive_wikipedia_data);
|
||||
bld.setNegativeButton(R.string.shared_string_cancel, null);
|
||||
bld.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
for (String w : wiki) {
|
||||
File fl = getMyApplication().getAppPath(w);
|
||||
File nf = new File(fl.getParentFile(), IndexConstants.BACKUP_INDEX_DIR + "/" + fl.getName());
|
||||
boolean res = fl.renameTo(nf);
|
||||
if (!res) {
|
||||
System.err.println("Renaming from " + fl.getAbsolutePath() + " to " + nf.getAbsolutePath() + " failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
bld.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateDownloadButton() {
|
||||
// View view = getView();
|
||||
// if (view == null || getExpandableListView() == null){
|
||||
// return;
|
||||
// }
|
||||
// int x = getExpandableListView().getScrollX();
|
||||
// int y = getExpandableListView().getScrollY();
|
||||
if (getEntriesToDownload().isEmpty()) {
|
||||
findViewById(R.id.DownloadLayout).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.shared_string_download) + " (" + downloads + ")"; //$NON-NLS-1$
|
||||
} else {
|
||||
text = getString(R.string.shared_string_downloading) + " (" + downloads + ")"; //$NON-NLS-1$
|
||||
}
|
||||
findViewById(R.id.DownloadLayout).setVisibility(View.VISIBLE);
|
||||
if (Version.isFreeVersion(getMyApplication())) {
|
||||
int left = DownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS - settings.NUMBER_OF_FREE_DOWNLOADS.get() - downloads;
|
||||
boolean excessLimit = left < 0;
|
||||
if (left < 0)
|
||||
left = 0;
|
||||
if (getDownloadType() == DownloadActivityType.NORMAL_FILE || getDownloadType() == DownloadActivityType.ROADS_FILE) {
|
||||
text += " (" + (excessLimit ? "! " : "") + getString(R.string.files_limit, left).toLowerCase() + ")";
|
||||
}
|
||||
}
|
||||
((Button) findViewById(R.id.downloadButton)).setText(text);
|
||||
List<IndexItem> wikipediaItems = getWikipediaItems();
|
||||
findViewById(R.id.wikiButton).setVisibility(wikipediaItems.size() == 0 ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
for (WeakReference<Fragment> ref : fragSet) {
|
||||
Fragment f = ref.get();
|
||||
if (f != null)
|
||||
if (f.isAdded()) {
|
||||
if (f instanceof OsmandExpandableListFragment) {
|
||||
ExpandableListAdapter ad = ((OsmandExpandableListFragment) f).getExpandableListView()
|
||||
.getExpandableListAdapter();
|
||||
if (ad instanceof OsmandBaseExpandableListAdapter) {
|
||||
((OsmandBaseExpandableListAdapter) ad).notifyDataSetChanged();
|
||||
}
|
||||
} else if (f instanceof ListFragment) {
|
||||
ListAdapter la = ((ListFragment) f).getListAdapter();
|
||||
if (la instanceof BaseAdapter) {
|
||||
((BaseAdapter) la).notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (scroll) {
|
||||
// getExpandableListView().scrollTo(x, y);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
private List<IndexItem> getWikipediaItems() {
|
||||
Set<String> wikipediaItems = new HashSet<String>();
|
||||
Map<String, String> indexed = getMyApplication().getResourceManager().getIndexFileNames();
|
||||
for (IndexItem i : getEntriesToDownload().keySet()) {
|
||||
if (i.getType() == DownloadActivityType.NORMAL_FILE) {
|
||||
boolean fit = true;
|
||||
fit = fit && i.getFileName().contains("obf");
|
||||
fit = fit && !i.getFileName().contains("world");
|
||||
String fname = i.getBasename();
|
||||
if (fit && !indexed.containsKey(fname + ".wiki.obf")) {
|
||||
wikipediaItems.add(fname);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (IndexItem i : getEntriesToDownload().keySet()) {
|
||||
if (i.getType() == DownloadActivityType.WIKIPEDIA_FILE) {
|
||||
wikipediaItems.remove(i.getBasename());
|
||||
}
|
||||
}
|
||||
List<IndexItem> res = new ArrayList<IndexItem>();
|
||||
IndexFileList list = downloadListIndexThread.getIndexFiles();
|
||||
if (list != null) {
|
||||
List<IndexItem> indexFiles = list.getIndexFiles();
|
||||
for (IndexItem i : indexFiles) {
|
||||
if (i.getType() == DownloadActivityType.WIKIPEDIA_FILE &&
|
||||
wikipediaItems.contains(i.getBasename())) {
|
||||
res.add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public List<DownloadActivityType> getDownloadTypes() {
|
||||
return downloadTypes;
|
||||
}
|
||||
|
||||
public List<DownloadActivityType> createDownloadTypes() {
|
||||
List<DownloadActivityType> items = new ArrayList<DownloadActivityType>();
|
||||
items.add(DownloadActivityType.NORMAL_FILE);
|
||||
if (!Version.isFreeVersion(getMyApplication())) {
|
||||
items.add(DownloadActivityType.WIKIPEDIA_FILE);
|
||||
}
|
||||
items.add(DownloadActivityType.VOICE_FILE);
|
||||
items.add(DownloadActivityType.ROADS_FILE);
|
||||
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null) {
|
||||
items.add(DownloadActivityType.HILLSHADE_FILE);
|
||||
items.add(DownloadActivityType.SRTM_COUNTRY_FILE);
|
||||
}
|
||||
|
||||
getMyApplication().getAppCustomization().getDownloadTypes(items);
|
||||
return items;
|
||||
}
|
||||
|
||||
public boolean isLightActionBar() {
|
||||
return ((OsmandApplication) getApplication()).getSettings().isLightActionBar();
|
||||
}
|
||||
|
||||
|
||||
public Map<String, String> getIndexFileNames() {
|
||||
return downloadListIndexThread != null ? downloadListIndexThread.getIndexFileNames() : null;
|
||||
}
|
||||
|
||||
public List<IndexItem> getIndexFiles() {
|
||||
return downloadListIndexThread != null ? downloadListIndexThread.getCachedIndexFiles() : null;
|
||||
}
|
||||
|
||||
public void showDialogToDownloadMaps(Collection<String> maps) {
|
||||
int count = 0;
|
||||
int sz = 0;
|
||||
String s = "";
|
||||
for (IndexItem i : DownloadActivity.downloadListIndexThread.getCachedIndexFiles()) {
|
||||
for (String map : maps) {
|
||||
if ((i.getFileName().equals(map + ".obf.zip") || i.getFileName().equals(map + "_" + IndexConstants.BINARY_MAP_VERSION + ".obf.zip"))
|
||||
&& i.getType() == DownloadActivityType.NORMAL_FILE) {
|
||||
final List<DownloadEntry> de = i.createDownloadEntry(getMyApplication(), i.getType(), new ArrayList<DownloadEntry>(1));
|
||||
for (DownloadEntry d : de) {
|
||||
count++;
|
||||
sz += d.sizeMB;
|
||||
}
|
||||
if (s.length() > 0) {
|
||||
s += ", ";
|
||||
}
|
||||
s += i.getVisibleName(getMyApplication(), getMyApplication().getResourceManager().getOsmandRegions());
|
||||
getEntriesToDownload().put(i, de);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(getString(R.string.download_additional_maps, s, sz));
|
||||
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
downloadFilesCheckInternet();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.shared_string_no, new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
getEntriesToDownload().clear();
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
getEntriesToDownload().clear();
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void initFreeVersionBanner(View header) {
|
||||
visibleBanner = new BannerAndDownloadFreeVersion(header, this);
|
||||
updateProgress(true);
|
||||
}
|
||||
|
||||
|
||||
public void showDialog(FragmentActivity activity, DialogFragment fragment) {
|
||||
fragment.show(activity.getSupportFragmentManager(), "dialog");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialogDismissed() {
|
||||
initFreeVersionBanner(findViewById(R.id.mainLayout));
|
||||
}
|
||||
|
||||
private static class ToggleCollapseFreeVersionBanner implements View.OnClickListener {
|
||||
private final View freeVersionDescriptionTextView;
|
||||
private final View buttonsLinearLayout;
|
||||
|
||||
private ToggleCollapseFreeVersionBanner(View freeVersionDescriptionTextView,
|
||||
View buttonsLinearLayout) {
|
||||
this.freeVersionDescriptionTextView = freeVersionDescriptionTextView;
|
||||
this.buttonsLinearLayout = buttonsLinearLayout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (freeVersionDescriptionTextView.getVisibility() == View.VISIBLE) {
|
||||
freeVersionDescriptionTextView.setVisibility(View.GONE);
|
||||
buttonsLinearLayout.setVisibility(View.GONE);
|
||||
} else {
|
||||
freeVersionDescriptionTextView.setVisibility(View.VISIBLE);
|
||||
buttonsLinearLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class BannerAndDownloadFreeVersion {
|
||||
private final View freeVersionBanner;
|
||||
private final View downloadProgressLayout;
|
||||
private final ProgressBar progressBar;
|
||||
private final TextView leftTextView;
|
||||
private final TextView rightTextView;
|
||||
private final ProgressBar downloadsLeftProgressBar;
|
||||
private final View buttonsLinearLayout;
|
||||
private final TextView freeVersionDescriptionTextView;
|
||||
private final TextView downloadsLeftTextView;
|
||||
private final View laterButton;
|
||||
|
||||
private final Context ctx;
|
||||
private final OsmandApplication application;
|
||||
private final boolean shouldShowFreeVersionBanner;
|
||||
private final View freeVersionBannerTitle;
|
||||
|
||||
public BannerAndDownloadFreeVersion(View view, Context ctx) {
|
||||
this.ctx = ctx;
|
||||
application = (OsmandApplication) ctx.getApplicationContext();
|
||||
freeVersionBanner = view.findViewById(R.id.freeVersionBanner);
|
||||
downloadProgressLayout = view.findViewById(R.id.downloadProgressLayout);
|
||||
progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
|
||||
leftTextView = (TextView) view.findViewById(R.id.leftTextView);
|
||||
rightTextView = (TextView) view.findViewById(R.id.rightTextView);
|
||||
downloadsLeftTextView = (TextView) freeVersionBanner.findViewById(R.id.downloadsLeftTextView);
|
||||
downloadsLeftProgressBar = (ProgressBar) freeVersionBanner.findViewById(R.id.downloadsLeftProgressBar);
|
||||
buttonsLinearLayout = freeVersionBanner.findViewById(R.id.buttonsLinearLayout);
|
||||
freeVersionDescriptionTextView = (TextView) freeVersionBanner
|
||||
.findViewById(R.id.freeVersionDescriptionTextView);
|
||||
laterButton = freeVersionBanner.findViewById(R.id.laterButton);
|
||||
freeVersionBannerTitle = freeVersionBanner.findViewById(R.id.freeVersionBannerTitle);
|
||||
|
||||
shouldShowFreeVersionBanner = Version.isFreeVersion(application)
|
||||
|| application.getSettings().SHOULD_SHOW_FREE_VERSION_BANNER.get();
|
||||
|
||||
initFreeVersionBanner();
|
||||
updateFreeVersionBanner();
|
||||
}
|
||||
|
||||
public void updateProgress(int countedDownloads,
|
||||
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask) {
|
||||
final boolean isFinished = basicProgressAsyncTask == null
|
||||
|| basicProgressAsyncTask.getStatus() == AsyncTask.Status.FINISHED;
|
||||
if (isFinished) {
|
||||
downloadProgressLayout.setVisibility(View.GONE);
|
||||
updateFreeVersionBanner();
|
||||
} else {
|
||||
boolean indeterminate = basicProgressAsyncTask.isIndeterminate();
|
||||
String message = basicProgressAsyncTask.getDescription();
|
||||
int percent = basicProgressAsyncTask.getProgressPercentage();
|
||||
|
||||
setMinimizedFreeVersionBanner(true);
|
||||
updateAvailableDownloads(countedDownloads);
|
||||
downloadProgressLayout.setVisibility(View.VISIBLE);
|
||||
progressBar.setIndeterminate(indeterminate);
|
||||
if (indeterminate) {
|
||||
leftTextView.setText(message);
|
||||
} else {
|
||||
// TODO if only 1 map, show map name
|
||||
progressBar.setProgress(percent);
|
||||
// final String format = ctx.getString(R.string.downloading_number_of_files);
|
||||
leftTextView.setText(message);
|
||||
rightTextView.setText(percent + "%");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initFreeVersionBanner() {
|
||||
if (!shouldShowFreeVersionBanner) {
|
||||
freeVersionBanner.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
freeVersionBanner.setVisibility(View.VISIBLE);
|
||||
downloadsLeftProgressBar.setMax(BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS);
|
||||
freeVersionDescriptionTextView.setText(ctx.getString(R.string.free_version_message,
|
||||
BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS));
|
||||
freeVersionBanner.findViewById(R.id.getFullVersionButton).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
BaseDownloadActivity context = (BaseDownloadActivity) v.getContext();
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Version.marketPrefix(context
|
||||
.getMyApplication()) + "net.osmand.plus"));
|
||||
try {
|
||||
context.startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
}
|
||||
}
|
||||
});
|
||||
laterButton.setOnClickListener(
|
||||
new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView, buttonsLinearLayout));
|
||||
}
|
||||
|
||||
private void updateFreeVersionBanner() {
|
||||
if (!shouldShowFreeVersionBanner) return;
|
||||
setMinimizedFreeVersionBanner(false);
|
||||
OsmandSettings settings = application.getSettings();
|
||||
final Integer mapsDownloaded = settings.NUMBER_OF_FREE_DOWNLOADS.get();
|
||||
downloadsLeftProgressBar.setProgress(mapsDownloaded);
|
||||
int downloadsLeft = BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS
|
||||
- mapsDownloaded;
|
||||
downloadsLeft = Math.max(downloadsLeft, 0);
|
||||
if (downloadsLeft <= 0) {
|
||||
laterButton.setVisibility(View.GONE);
|
||||
}
|
||||
downloadsLeftTextView.setText(ctx.getString(R.string.downloads_left_template, downloadsLeft));
|
||||
// TODO review logic
|
||||
freeVersionBanner.setOnClickListener(new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView,
|
||||
buttonsLinearLayout));
|
||||
}
|
||||
|
||||
private void updateAvailableDownloads(int activeTasks) {
|
||||
OsmandSettings settings = application.getSettings();
|
||||
final Integer mapsDownloaded = settings.NUMBER_OF_FREE_DOWNLOADS.get() + activeTasks;
|
||||
downloadsLeftProgressBar.setProgress(mapsDownloaded);
|
||||
}
|
||||
|
||||
private void setMinimizedFreeVersionBanner(boolean minimize) {
|
||||
if (minimize) {
|
||||
freeVersionDescriptionTextView.setVisibility(View.GONE);
|
||||
buttonsLinearLayout.setVisibility(View.GONE);
|
||||
freeVersionBannerTitle.setVisibility(View.GONE);
|
||||
} else {
|
||||
freeVersionDescriptionTextView.setVisibility(View.VISIBLE);
|
||||
buttonsLinearLayout.setVisibility(View.VISIBLE);
|
||||
freeVersionBannerTitle.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.download.items;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
@ -14,10 +15,12 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.WorldRegion;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
|
||||
public class RegionDialogFragment extends DialogFragment {
|
||||
public class RegionDialogFragment extends DialogFragment{
|
||||
public static final String TAG = "RegionDialogFragment";
|
||||
private static final String REGION_ID_DLG_KEY = "world_region_dialog_key";
|
||||
private String regionId;
|
||||
private DialogDismissListener dialogDismissListener;
|
||||
private DialogDismissListener listener;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -62,10 +65,16 @@ public class RegionDialogFragment extends DialogFragment {
|
|||
toolbar.setTitle(region.getName());
|
||||
}
|
||||
}
|
||||
getDownloadActivity().initFreeVersionBanner(view);
|
||||
((DownloadActivity) getActivity()).initFreeVersionBanner(view);
|
||||
listener = new DialogDismissListener() {
|
||||
@Override
|
||||
public void onDialogDismissed() {
|
||||
((DownloadActivity) getActivity()).initFreeVersionBanner(view);
|
||||
}
|
||||
};
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putString(REGION_ID_DLG_KEY, regionId);
|
||||
|
@ -81,7 +90,9 @@ public class RegionDialogFragment extends DialogFragment {
|
|||
}
|
||||
|
||||
public void onRegionSelected(String regionId) {
|
||||
getDownloadActivity().showDialog(getActivity(), createInstance(regionId));
|
||||
final RegionDialogFragment regionDialogFragment = createInstance(regionId);
|
||||
regionDialogFragment.setOnDismissListener(listener);
|
||||
((DownloadActivity) getActivity()).showDialog(getActivity(), regionDialogFragment);
|
||||
}
|
||||
|
||||
public static RegionDialogFragment createInstance(String regionId) {
|
||||
|
@ -91,4 +102,19 @@ public class RegionDialogFragment extends DialogFragment {
|
|||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
super.onDismiss(dialog);
|
||||
if (dialogDismissListener != null)
|
||||
dialogDismissListener.onDialogDismissed();
|
||||
}
|
||||
|
||||
public void setOnDismissListener(DialogDismissListener listener) {
|
||||
this.dialogDismissListener = listener;
|
||||
}
|
||||
|
||||
public interface DialogDismissListener {
|
||||
void onDialogDismissed();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
package net.osmand.plus.download.items;
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
import android.content.DialogInterface;
|
||||
>>>>>>> 123c270bc595f997b400d0de3681e6ab22f427cf
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.WorldRegion;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
|
||||
<<<<<<< HEAD
|
||||
public class RegionDialogFragment extends DialogFragment {
|
||||
=======
|
||||
public class RegionDialogFragment extends DialogFragment{
|
||||
>>>>>>> 123c270bc595f997b400d0de3681e6ab22f427cf
|
||||
public static final String TAG = "RegionDialogFragment";
|
||||
private static final String REGION_ID_DLG_KEY = "world_region_dialog_key";
|
||||
private String regionId;
|
||||
private DialogDismissListener dialogDismissListener;
|
||||
private DialogDismissListener listener;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
boolean isLightTheme = getMyApplication()
|
||||
.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
|
||||
int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme;
|
||||
setStyle(STYLE_NO_FRAME, themeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
final View view = inflater.inflate(R.layout.maps_in_category_fragment, container, false);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
regionId = savedInstanceState.getString(REGION_ID_DLG_KEY);
|
||||
}
|
||||
if (regionId == null) {
|
||||
regionId = getArguments().getString(REGION_ID_DLG_KEY);
|
||||
}
|
||||
if (regionId == null)
|
||||
regionId = "";
|
||||
|
||||
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
|
||||
toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha));
|
||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
if (regionId.length() > 0) {
|
||||
Fragment fragment = getChildFragmentManager().findFragmentById(R.id.fragmentContainer);
|
||||
if (fragment == null) {
|
||||
getChildFragmentManager().beginTransaction().add(R.id.fragmentContainer,
|
||||
RegionItemsFragment.createInstance(regionId)).commit();
|
||||
}
|
||||
WorldRegion region = getMyApplication().getWorldRegion().getRegionById(regionId);
|
||||
if (region != null) {
|
||||
toolbar.setTitle(region.getName());
|
||||
}
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
getDownloadActivity().initFreeVersionBanner(view);
|
||||
=======
|
||||
((DownloadActivity) getActivity()).initFreeVersionBanner(view);
|
||||
listener = new DialogDismissListener() {
|
||||
@Override
|
||||
public void onDialogDismissed() {
|
||||
((DownloadActivity) getActivity()).initFreeVersionBanner(view);
|
||||
}
|
||||
};
|
||||
>>>>>>> 123c270bc595f997b400d0de3681e6ab22f427cf
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putString(REGION_ID_DLG_KEY, regionId);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
private OsmandApplication getMyApplication() {
|
||||
return (OsmandApplication) getActivity().getApplication();
|
||||
}
|
||||
|
||||
private DownloadActivity getDownloadActivity() {
|
||||
return (DownloadActivity) getActivity();
|
||||
}
|
||||
|
||||
public void onRegionSelected(String regionId) {
|
||||
<<<<<<< HEAD
|
||||
getDownloadActivity().showDialog(getActivity(), createInstance(regionId));
|
||||
=======
|
||||
final RegionDialogFragment regionDialogFragment = createInstance(regionId);
|
||||
regionDialogFragment.setOnDismissListener(listener);
|
||||
((DownloadActivity) getActivity()).showDialog(getActivity(), regionDialogFragment);
|
||||
>>>>>>> 123c270bc595f997b400d0de3681e6ab22f427cf
|
||||
}
|
||||
|
||||
public static RegionDialogFragment createInstance(String regionId) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(REGION_ID_DLG_KEY, regionId);
|
||||
RegionDialogFragment fragment = new RegionDialogFragment();
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
super.onDismiss(dialog);
|
||||
if (dialogDismissListener != null)
|
||||
dialogDismissListener.onDialogDismissed();
|
||||
}
|
||||
|
||||
public void setOnDismissListener(DialogDismissListener listener) {
|
||||
this.dialogDismissListener = listener;
|
||||
}
|
||||
|
||||
public interface DialogDismissListener {
|
||||
void onDialogDismissed();
|
||||
}
|
||||
}
|
|
@ -71,8 +71,6 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
|
|||
|
||||
onCategorizationFinished();
|
||||
|
||||
getDownloadActivity().initFreeVersionBanner(view);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -128,7 +126,9 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
|
|||
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
|
||||
if (groupPosition == worldRegionsIndex) {
|
||||
WorldRegion region = (WorldRegion)listAdapter.getChild(groupPosition, childPosition);
|
||||
getDownloadActivity().showDialog(getActivity(), RegionDialogFragment.createInstance(region.getRegionId()));
|
||||
final RegionDialogFragment regionDialogFragment = RegionDialogFragment.createInstance(region.getRegionId());
|
||||
regionDialogFragment.setOnDismissListener((DownloadActivity) getActivity());
|
||||
((DownloadActivity)getActivity()).showDialog(getActivity(), regionDialogFragment);
|
||||
return true;
|
||||
} else if (groupPosition == voicePromptsIndex) {
|
||||
if (childPosition == voicePromptsItemsRecordedSubIndex) {
|
||||
|
|
|
@ -0,0 +1,366 @@
|
|||
package net.osmand.plus.download.items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.WorldRegion;
|
||||
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||
import net.osmand.plus.activities.OsmandExpandableListFragment;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
import net.osmand.plus.download.items.ItemsListBuilder.VoicePromptsType;
|
||||
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
|
||||
import net.osmand.plus.srtmplugin.SRTMPlugin;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ExpandableListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class WorldItemsFragment extends OsmandExpandableListFragment {
|
||||
public static final String TAG = "WorldItemsFragment";
|
||||
private static final Log LOG = PlatformUtil.getLog(WorldItemsFragment.class);
|
||||
|
||||
public static final int RELOAD_ID = 0;
|
||||
public static final int SEARCH_ID = 1;
|
||||
|
||||
private WorldItemsAdapter listAdapter;
|
||||
|
||||
private int worldRegionsIndex = -1;
|
||||
private int worldMapsIndex = -1;
|
||||
private int voicePromptsIndex = -1;
|
||||
|
||||
private int voicePromptsItemsRecordedSubIndex = -1;
|
||||
private int voicePromptsItemsTTSSubIndex = -1;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.download_index_fragment, container, false);
|
||||
|
||||
ExpandableListView listView = (ExpandableListView) view.findViewById(android.R.id.list);
|
||||
listAdapter = new WorldItemsAdapter(getActivity());
|
||||
listView.setAdapter(listAdapter);
|
||||
expandAllGroups();
|
||||
setListView(listView);
|
||||
|
||||
onCategorizationFinished();
|
||||
|
||||
<<<<<<< HEAD
|
||||
getDownloadActivity().initFreeVersionBanner(view);
|
||||
|
||||
=======
|
||||
>>>>>>> 123c270bc595f997b400d0de3681e6ab22f427cf
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (!listAdapter.isEmpty()) {
|
||||
expandAllGroups();
|
||||
}
|
||||
}
|
||||
|
||||
private void expandAllGroups() {
|
||||
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
|
||||
getExpandableListView().expandGroup(i);
|
||||
}
|
||||
}
|
||||
|
||||
public OsmandApplication getMyApplication() {
|
||||
return (OsmandApplication) getActivity().getApplication();
|
||||
}
|
||||
|
||||
private void fillWorldItemsAdapter(ItemsListBuilder builder) {
|
||||
if (listAdapter != null) {
|
||||
listAdapter.clear();
|
||||
if (builder.getRegionMapItems().size() > 0) {
|
||||
int unusedIndex = 0;
|
||||
worldRegionsIndex = unusedIndex++;
|
||||
listAdapter.add("World regions", builder.getRegionsFromAllItems());
|
||||
worldMapsIndex = unusedIndex++;
|
||||
listAdapter.add("World maps", builder.getRegionMapItems());
|
||||
|
||||
int unusedSubIndex = 0;
|
||||
List<String> voicePromptsItems = new LinkedList<>();
|
||||
if (!builder.isVoicePromptsItemsEmpty(VoicePromptsType.RECORDED)) {
|
||||
voicePromptsItems.add(builder.getVoicePromtName(VoicePromptsType.RECORDED));
|
||||
voicePromptsItemsRecordedSubIndex = unusedSubIndex++;
|
||||
}
|
||||
if (!builder.isVoicePromptsItemsEmpty(VoicePromptsType.TTS)) {
|
||||
voicePromptsItems.add(builder.getVoicePromtName(VoicePromptsType.TTS));
|
||||
voicePromptsItemsTTSSubIndex = unusedSubIndex;
|
||||
}
|
||||
if (!voicePromptsItems.isEmpty()) {
|
||||
voicePromptsIndex = unusedIndex;
|
||||
listAdapter.add("Voice prompts", voicePromptsItems);
|
||||
}
|
||||
}
|
||||
//listAdapter.add("Voice promts", null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
|
||||
if (groupPosition == worldRegionsIndex) {
|
||||
WorldRegion region = (WorldRegion)listAdapter.getChild(groupPosition, childPosition);
|
||||
<<<<<<< HEAD
|
||||
getDownloadActivity().showDialog(getActivity(), RegionDialogFragment.createInstance(region.getRegionId()));
|
||||
=======
|
||||
final RegionDialogFragment regionDialogFragment = RegionDialogFragment.createInstance(region.getRegionId());
|
||||
regionDialogFragment.setOnDismissListener((DownloadActivity) getActivity());
|
||||
((DownloadActivity)getActivity()).showDialog(getActivity(), regionDialogFragment);
|
||||
>>>>>>> 123c270bc595f997b400d0de3681e6ab22f427cf
|
||||
return true;
|
||||
} else if (groupPosition == voicePromptsIndex) {
|
||||
if (childPosition == voicePromptsItemsRecordedSubIndex) {
|
||||
getDownloadActivity().showDialog(getActivity(),
|
||||
VoiceDialogFragment.createInstance(VoicePromptsType.RECORDED));
|
||||
} else {
|
||||
getDownloadActivity().showDialog(getActivity(),
|
||||
VoiceDialogFragment.createInstance(VoicePromptsType.TTS));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
MenuItem itemReload = menu.add(0, RELOAD_ID, 0, R.string.shared_string_refresh);
|
||||
itemReload.setIcon(R.drawable.ic_action_refresh_dark);
|
||||
MenuItemCompat.setShowAsAction(itemReload, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
|
||||
MenuItem itemSearch = menu.add(0, SEARCH_ID, 1, R.string.shared_string_search);
|
||||
itemSearch.setIcon(R.drawable.ic_action_search_dark);
|
||||
MenuItemCompat.setShowAsAction(itemSearch, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case RELOAD_ID:
|
||||
// re-create the thread
|
||||
DownloadActivity.downloadListIndexThread.runReloadIndexFiles();
|
||||
return true;
|
||||
case SEARCH_ID:
|
||||
getDownloadActivity().showDialog(getActivity(), SearchDialogFragment.createInstance(""));
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private DownloadActivity getDownloadActivity() {
|
||||
return (DownloadActivity) getActivity();
|
||||
}
|
||||
|
||||
public void onCategorizationFinished() {
|
||||
ItemsListBuilder builder = getDownloadActivity().getItemsBuilder();
|
||||
if (builder != null && builder.build()) {
|
||||
fillWorldItemsAdapter(builder);
|
||||
listAdapter.notifyDataSetChanged();
|
||||
expandAllGroups();
|
||||
}
|
||||
}
|
||||
|
||||
private class WorldItemsAdapter extends OsmandBaseExpandableListAdapter {
|
||||
|
||||
private Map<String, List<Object>> data = new LinkedHashMap<>();
|
||||
private List<String> sections = new LinkedList<>();
|
||||
private boolean srtmDisabled;
|
||||
private boolean nauticalPluginDisabled;
|
||||
private boolean freeVersion;
|
||||
|
||||
private class SimpleViewHolder {
|
||||
TextView textView;
|
||||
}
|
||||
|
||||
public WorldItemsAdapter(Context ctx) {
|
||||
srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null;
|
||||
nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null;
|
||||
freeVersion = Version.isFreeVersion(getMyApplication());
|
||||
TypedArray ta = ctx.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
|
||||
ta.recycle();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
data.clear();
|
||||
sections.clear();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void add(String section, List list) {
|
||||
if (!sections.contains(section)) {
|
||||
sections.add(section);
|
||||
}
|
||||
if (!data.containsKey(section)) {
|
||||
data.put(section, new ArrayList<>());
|
||||
}
|
||||
data.get(section).addAll(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getChild(int groupPosition, int childPosition) {
|
||||
String section = sections.get(groupPosition);
|
||||
return data.get(section).get(childPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getChildId(int groupPosition, int childPosition) {
|
||||
return groupPosition * 10000 + childPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChildType(int groupPosition, int childPosition) {
|
||||
if (groupPosition == worldRegionsIndex || groupPosition == voicePromptsIndex) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChildTypeCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
|
||||
|
||||
final Object child = getChild(groupPosition, childPosition);
|
||||
|
||||
if (groupPosition == worldRegionsIndex) {
|
||||
WorldRegion item = (WorldRegion)child;
|
||||
SimpleViewHolder viewHolder;
|
||||
if (convertView == null) {
|
||||
convertView = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.simple_list_menu_item, parent, false);
|
||||
viewHolder = new SimpleViewHolder();
|
||||
viewHolder.textView = (TextView) convertView.findViewById(R.id.title);
|
||||
convertView.setTag(viewHolder);
|
||||
} else {
|
||||
viewHolder = (SimpleViewHolder) convertView.getTag();
|
||||
}
|
||||
Drawable iconLeft = getMyApplication().getIconsCache()
|
||||
.getContentIcon(R.drawable.ic_world_globe_dark);
|
||||
viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null);
|
||||
viewHolder.textView.setText(item.getName());
|
||||
|
||||
} else if (groupPosition == worldMapsIndex) {
|
||||
ItemsListBuilder.ResourceItem item = (ItemsListBuilder.ResourceItem) child;
|
||||
ItemViewHolder viewHolder;
|
||||
if (convertView == null) {
|
||||
convertView = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.two_line_with_images_list_item, parent, false);
|
||||
viewHolder = new ItemViewHolder(convertView);
|
||||
convertView.setTag(viewHolder);
|
||||
} else {
|
||||
viewHolder = (ItemViewHolder) convertView.getTag();
|
||||
}
|
||||
viewHolder.setSrtmDisabled(srtmDisabled);
|
||||
viewHolder.setNauticalPluginDisabled(nauticalPluginDisabled);
|
||||
viewHolder.setFreeVersion(freeVersion);
|
||||
viewHolder.bindIndexItem(item.getIndexItem(), getDownloadActivity(), false, false);
|
||||
} else if (groupPosition == voicePromptsIndex) {
|
||||
String item = (String)child;
|
||||
SimpleViewHolder viewHolder;
|
||||
if (convertView == null) {
|
||||
convertView = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.simple_list_menu_item, parent, false);
|
||||
viewHolder = new SimpleViewHolder();
|
||||
viewHolder.textView = (TextView) convertView.findViewById(R.id.title);
|
||||
convertView.setTag(viewHolder);
|
||||
} else {
|
||||
viewHolder = (SimpleViewHolder) convertView.getTag();
|
||||
}
|
||||
Drawable iconLeft = getMyApplication().getIconsCache()
|
||||
.getContentIcon(R.drawable.ic_action_volume_up);
|
||||
viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null);
|
||||
viewHolder.textView.setText(item);
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getGroupView(int groupPosition, boolean isExpanded, final View convertView,
|
||||
final ViewGroup parent) {
|
||||
View v = convertView;
|
||||
String section = getGroup(groupPosition);
|
||||
if (v == null) {
|
||||
LayoutInflater inflater = (LayoutInflater) getDownloadActivity()
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
v = inflater.inflate(R.layout.download_item_list_section, parent, false);
|
||||
}
|
||||
TextView nameView = ((TextView) v.findViewById(R.id.section_name));
|
||||
nameView.setText(section);
|
||||
|
||||
v.setOnClickListener(null);
|
||||
|
||||
TypedValue typedValue = new TypedValue();
|
||||
Resources.Theme theme = getActivity().getTheme();
|
||||
theme.resolveAttribute(R.attr.ctx_menu_info_view_bg, typedValue, true);
|
||||
v.setBackgroundColor(typedValue.data);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChildrenCount(int groupPosition) {
|
||||
String section = sections.get(groupPosition);
|
||||
return data.get(section).size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroup(int groupPosition) {
|
||||
return sections.get(groupPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGroupCount() {
|
||||
return sections.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getGroupId(int groupPosition) {
|
||||
return groupPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasStableIds() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChildSelectable(int groupPosition, int childPosition) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue