[android] Hide offline explanation after two downloads

Signed-off-by: NoelClick <dev@noel.click>
Co-authored-by: NoelClick <dev@noel.click>
Co-committed-by: NoelClick <dev@noel.click>
This commit is contained in:
NoelClick
2025-11-13 13:32:01 +01:00
committed by x7z4w
parent e4648fbc1f
commit 4f63c5fdcf
3 changed files with 74 additions and 43 deletions

View File

@@ -4,6 +4,7 @@ import android.location.Location;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.view.ViewCompat; import androidx.core.view.ViewCompat;
import app.organicmaps.MwmActivity; import app.organicmaps.MwmActivity;
@@ -26,6 +27,10 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
{ {
private static boolean sAutodownloadLocked; private static boolean sAutodownloadLocked;
private static final int HIDE_THRESHOLD = 2;
// Default bundles (e.g., world/coasts). Used to approximate “user-downloaded” count.
private static final int DEFAULT_MAP_BASELINE = 2;
private final MwmActivity mActivity; private final MwmActivity mActivity;
private final View mFrame; private final View mFrame;
private final MaterialTextView mParent; private final MaterialTextView mParent;
@@ -33,6 +38,7 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
private final MaterialTextView mSize; private final MaterialTextView mSize;
private final WheelProgressView mProgress; private final WheelProgressView mProgress;
private final MaterialButton mButton; private final MaterialButton mButton;
private final View mOfflineExplanation;
private int mStorageSubscriptionSlot; private int mStorageSubscriptionSlot;
@@ -43,8 +49,10 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
@Override @Override
public void onStatusChanged(List<MapManager.StorageCallbackData> data) public void onStatusChanged(List<MapManager.StorageCallbackData> data)
{ {
if (mCurrentCountry == null) if (mCurrentCountry == null) {
updateOfflineExplanationVisibility();
return; return;
}
for (MapManager.StorageCallbackData item : data) for (MapManager.StorageCallbackData item : data)
{ {
@@ -58,7 +66,7 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
{ {
mCurrentCountry.update(); mCurrentCountry.update();
updateProgressState(false); updateProgressState(false);
updateOfflineExplanationVisibility();
return; return;
} }
} }
@@ -101,6 +109,12 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
return enqueued || progress || applying; return enqueued || progress || applying;
} }
private void updateOfflineExplanationVisibility() {
if (mOfflineExplanation == null) return;
// hide once threshold reached; safe to call repeatedly.
app.organicmaps.util.UiUtils.showIf(MapManager.nativeGetDownloadedCount() < (DEFAULT_MAP_BASELINE + HIDE_THRESHOLD), mOfflineExplanation);
}
private void updateProgressState(boolean shouldAutoDownload) private void updateProgressState(boolean shouldAutoDownload)
{ {
updateStateInternal(shouldAutoDownload); updateStateInternal(shouldAutoDownload);
@@ -108,6 +122,8 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
private void updateStateInternal(boolean shouldAutoDownload) private void updateStateInternal(boolean shouldAutoDownload)
{ {
updateOfflineExplanationVisibility();
boolean showFrame = boolean showFrame =
(mCurrentCountry != null && !mCurrentCountry.present && !RoutingController.get().isNavigating()); (mCurrentCountry != null && !mCurrentCountry.present && !RoutingController.get().isNavigating());
if (showFrame) if (showFrame)
@@ -191,6 +207,9 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
mProgress = controls.findViewById(R.id.wheel_downloader_progress); mProgress = controls.findViewById(R.id.wheel_downloader_progress);
mButton = controls.findViewById(R.id.downloader_button); mButton = controls.findViewById(R.id.downloader_button);
mOfflineExplanation = mFrame.findViewById(R.id.offline_explanation);
updateOfflineExplanationVisibility();
mProgress.setOnClickListener(v -> { mProgress.setOnClickListener(v -> {
if (mCurrentCountry == null) if (mCurrentCountry == null)
return; return;
@@ -247,6 +266,7 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
public void onResume() public void onResume()
{ {
updateOfflineExplanationVisibility();
if (mStorageSubscriptionSlot == 0) if (mStorageSubscriptionSlot == 0)
{ {
mStorageSubscriptionSlot = MapManager.nativeSubscribe(mStorageCallback); mStorageSubscriptionSlot = MapManager.nativeSubscribe(mStorageCallback);

View File

@@ -26,27 +26,33 @@
android:clipChildren="false" android:clipChildren="false"
android:gravity="center" android:gravity="center"
tools:ignore="UselessParent"> tools:ignore="UselessParent">
<com.google.android.material.textview.MaterialTextView <LinearLayout
android:id="@+id/offline_explanation"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_eighth" android:orientation="vertical">
android:gravity="center_horizontal" <com.google.android.material.textview.MaterialTextView
android:textStyle="bold" android:layout_width="match_parent"
android:textAppearance="?android:attr/textAppearanceLarge" android:layout_height="wrap_content"
android:text="@string/offline_explanation_title"/> android:layout_marginBottom="@dimen/margin_eighth"
<com.google.android.material.textview.MaterialTextView android:gravity="center_horizontal"
android:layout_width="match_parent" android:textStyle="bold"
android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginBottom="@dimen/margin_eighth" android:text="@string/offline_explanation_title"/>
android:gravity="center_horizontal" <com.google.android.material.textview.MaterialTextView
android:textStyle="normal" android:layout_width="match_parent"
android:textAppearance="@style/MwmTextAppearance.Body1" android:layout_height="wrap_content"
android:text="@string/offline_explanation_text"/> android:layout_marginBottom="@dimen/margin_eighth"
<com.google.android.material.divider.MaterialDivider android:gravity="center_horizontal"
android:layout_width="match_parent" android:textStyle="normal"
android:layout_height="2dp" android:textAppearance="@style/MwmTextAppearance.Body1"
android:layout_marginTop="@dimen/margin_quarter" android:text="@string/offline_explanation_text"/>
android:layout_marginBottom="@dimen/margin_quarter"/> <com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="@dimen/margin_quarter"
android:layout_marginBottom="@dimen/margin_quarter"/>
</LinearLayout>
<com.google.android.material.textview.MaterialTextView <com.google.android.material.textview.MaterialTextView
android:id="@+id/downloader_parent" android:id="@+id/downloader_parent"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -17,29 +17,34 @@
android:layout_gravity="center" android:layout_gravity="center"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:background="@drawable/onmap_downloader_background"> android:background="@drawable/onmap_downloader_background">
<LinearLayout
<com.google.android.material.textview.MaterialTextView android:id="@+id/offline_explanation"
android:layout_width="@dimen/square_block_size"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_eighth"
android:gravity="center_horizontal"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/offline_explanation_title"/>
<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="212dp"
android:layout_marginBottom="@dimen/margin_eighth"
android:gravity="center_horizontal"
android:textStyle="normal"
android:textAppearance="@style/MwmTextAppearance.Body1"
android:text="@string/offline_explanation_text"/>
<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="2dp" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_quarter" android:orientation="vertical">
android:layout_marginBottom="@dimen/margin_quarter"/> <com.google.android.material.textview.MaterialTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_eighth"
android:gravity="center_horizontal"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/offline_explanation_title"/>
<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="212dp"
android:layout_marginBottom="@dimen/margin_eighth"
android:gravity="center_horizontal"
android:textStyle="normal"
android:textAppearance="@style/MwmTextAppearance.Body1"
android:text="@string/offline_explanation_text"/>
<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="@dimen/margin_quarter"
android:layout_marginBottom="@dimen/margin_quarter"/>
</LinearLayout>
<com.google.android.material.textview.MaterialTextView <com.google.android.material.textview.MaterialTextView
android:id="@+id/downloader_parent" android:id="@+id/downloader_parent"
android:layout_width="@dimen/square_block_size" android:layout_width="@dimen/square_block_size"