[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.view.View;
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import androidx.core.view.ViewCompat;
import app.organicmaps.MwmActivity;
@@ -26,6 +27,10 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
{
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 View mFrame;
private final MaterialTextView mParent;
@@ -33,6 +38,7 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
private final MaterialTextView mSize;
private final WheelProgressView mProgress;
private final MaterialButton mButton;
private final View mOfflineExplanation;
private int mStorageSubscriptionSlot;
@@ -43,8 +49,10 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
@Override
public void onStatusChanged(List<MapManager.StorageCallbackData> data)
{
if (mCurrentCountry == null)
if (mCurrentCountry == null) {
updateOfflineExplanationVisibility();
return;
}
for (MapManager.StorageCallbackData item : data)
{
@@ -58,7 +66,7 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
{
mCurrentCountry.update();
updateProgressState(false);
updateOfflineExplanationVisibility();
return;
}
}
@@ -101,6 +109,12 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
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)
{
updateStateInternal(shouldAutoDownload);
@@ -108,6 +122,8 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
private void updateStateInternal(boolean shouldAutoDownload)
{
updateOfflineExplanationVisibility();
boolean showFrame =
(mCurrentCountry != null && !mCurrentCountry.present && !RoutingController.get().isNavigating());
if (showFrame)
@@ -191,6 +207,9 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
mProgress = controls.findViewById(R.id.wheel_downloader_progress);
mButton = controls.findViewById(R.id.downloader_button);
mOfflineExplanation = mFrame.findViewById(R.id.offline_explanation);
updateOfflineExplanationVisibility();
mProgress.setOnClickListener(v -> {
if (mCurrentCountry == null)
return;
@@ -247,6 +266,7 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
public void onResume()
{
updateOfflineExplanationVisibility();
if (mStorageSubscriptionSlot == 0)
{
mStorageSubscriptionSlot = MapManager.nativeSubscribe(mStorageCallback);

View File

@@ -26,27 +26,33 @@
android:clipChildren="false"
android:gravity="center"
tools:ignore="UselessParent">
<com.google.android.material.textview.MaterialTextView
<LinearLayout
android:id="@+id/offline_explanation"
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="match_parent"
android:layout_height="wrap_content"
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"/>
android:orientation="vertical">
<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="match_parent"
android:layout_height="wrap_content"
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
android:id="@+id/downloader_parent"
android:layout_width="wrap_content"

View File

@@ -17,29 +17,34 @@
android:layout_gravity="center"
android:gravity="center_horizontal"
android:background="@drawable/onmap_downloader_background">
<com.google.android.material.textview.MaterialTextView
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
<LinearLayout
android:id="@+id/offline_explanation"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="@dimen/margin_quarter"
android:layout_marginBottom="@dimen/margin_quarter"/>
android:layout_height="wrap_content"
android:orientation="vertical">
<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
android:id="@+id/downloader_parent"
android:layout_width="@dimen/square_block_size"