Skip to content

Commit

Permalink
[Refactor] Move campaign logic to a separate class
Browse files Browse the repository at this point in the history
  • Loading branch information
MuntashirAkon committed Jan 9, 2023
1 parent e0b4613 commit 3a42fd9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import io.github.muntashirakon.AppManager.profiles.ProfilesActivity;
import io.github.muntashirakon.AppManager.rules.RulesTypeSelectionDialogFragment;
import io.github.muntashirakon.AppManager.runningapps.RunningAppsActivity;
import io.github.muntashirakon.AppManager.self.life.FundingCampaignChecker;
import io.github.muntashirakon.AppManager.settings.FeatureController;
import io.github.muntashirakon.AppManager.settings.Ops;
import io.github.muntashirakon.AppManager.settings.SettingsActivity;
Expand All @@ -72,6 +73,7 @@
import io.github.muntashirakon.AppManager.utils.StoragePermission;
import io.github.muntashirakon.AppManager.utils.UIUtils;
import io.github.muntashirakon.dialog.AlertDialogBuilder;
import io.github.muntashirakon.dialog.ScrollableDialogBuilder;
import io.github.muntashirakon.reflow.ReflowMenuViewWrapper;
import io.github.muntashirakon.util.UiUtils;
import io.github.muntashirakon.widget.MultiSelectionView;
Expand Down Expand Up @@ -552,6 +554,12 @@ private void displayChangelogIfRequired() {
if (!AppPref.getBoolean(AppPref.PrefKey.PREF_DISPLAY_CHANGELOG_BOOL)) {
return;
}
if (FundingCampaignChecker.campaignRunning()) {
new ScrollableDialogBuilder(this)
.setMessage(R.string.funding_campaign_dialog_message)
.enableAnchors()
.show();
}
Snackbar.make(findViewById(android.R.id.content), R.string.view_changelog, 3 * 60 * 1000)
.setAction(R.string.ok, v -> {
long lastVersion = (long) AppPref.get(AppPref.PrefKey.PREF_DISPLAY_CHANGELOG_LAST_VERSION_LONG);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: GPL-3.0-or-later

package io.github.muntashirakon.AppManager.self.life;

public class FundingCampaignChecker {
private static final long FUNDING_CAMPAIGN_START = 1671796800000L;
private static final long FUNDING_CAMPAIGN_END = 1680350400000L;

public static boolean campaignRunning() {
long currentTime = System.currentTimeMillis();
return currentTime >= FUNDING_CAMPAIGN_START && currentTime <= FUNDING_CAMPAIGN_END;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@
import io.github.muntashirakon.AppManager.BaseActivity;
import io.github.muntashirakon.AppManager.R;
import io.github.muntashirakon.AppManager.logs.Log;
import io.github.muntashirakon.AppManager.self.life.FundingCampaignChecker;

public class SettingsActivity extends BaseActivity implements PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
private static final String SCHEME = "app-manager";
private static final String HOST = "settings";

private static final long FUNDING_CAMPAIGN_START = 1671796800000L;
private static final long FUNDING_CAMPAIGN_END = 1680350400000L;

@NonNull
public static Intent getIntent(@NonNull Context context, @Nullable String... paths) {
Intent intent = new Intent(context, SettingsActivity.class);
Expand Down Expand Up @@ -67,9 +65,7 @@ protected void onAuthenticated(Bundle savedInstanceState) {
progressIndicator.hide();

View fundingCampaignNotice = findViewById(R.id.funding_campaign_notice);
long currentTime = System.currentTimeMillis();
boolean campaignOngoing = currentTime >= FUNDING_CAMPAIGN_START && currentTime <= FUNDING_CAMPAIGN_END;
fundingCampaignNotice.setVisibility(campaignOngoing ? View.VISIBLE : View.GONE);
fundingCampaignNotice.setVisibility(FundingCampaignChecker.campaignRunning() ? View.VISIBLE : View.GONE);

Uri uri = getIntent().getData();
if (uri != null && SCHEME.equals(uri.getScheme()) && HOST.equals(uri.getHost()) && uri.getPath() != null) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1238,5 +1238,6 @@
<string name="changelog_type_improve">Improve</string>
<string name="unsupported_split_apk">Unsupported</string>
<string name="view_changelog">Find out what\'s new in this release</string>
<string name="funding_campaign_dialog_message">We\'re running a <b>funding campaign</b> for App Manager for a limited period. Visit <a href="https://opencollective.com/app-manager#category-ABOUT">opencollective.com/app-manager</a> to learn more about the campaign. This notice will not be displayed again, but you can find it in the Settings page during the entire campaign.</string>
<string name="funding_campaign_text">We\'re running a <b>funding campaign</b> for App Manager for a limited period. <a href="https://opencollective.com/app-manager#category-ABOUT">learn more…</a></string>
</resources>

0 comments on commit 3a42fd9

Please sign in to comment.