-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Create service to handle what's new functionality #3898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Add AppInfo and WhatsNewService
Signed-off-by: Chris Narkiewicz <[email protected]>
- Loading branch information
commit f0554ab59bfb2f85fab7a0717b1917aa520d6110
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * Nextcloud Android client application | ||
| * | ||
| * @author Chris Narkiewicz | ||
| * Copyright (C) 2019 Chris Narkiewicz <[email protected]> | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package com.nextcloud.client.appinfo; | ||
|
|
||
| /** | ||
| * This class provides general, static information about application | ||
| * build. | ||
| * | ||
| * All methods should be thread-safe. | ||
| */ | ||
| public interface AppInfo { | ||
|
|
||
| /** | ||
| * Get application version code as formatted string. | ||
| * | ||
| * @return Formatted version code as defined in AndroidManifest.xml | ||
| */ | ||
| String getFormattedVersionCode(); | ||
|
|
||
| } |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/nextcloud/client/appinfo/AppInfoImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Nextcloud Android client application | ||
| * | ||
| * @author Chris Narkiewicz | ||
| * Copyright (C) 2019 Chris Narkiewicz <[email protected]> | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package com.nextcloud.client.appinfo; | ||
|
|
||
| import com.owncloud.android.BuildConfig; | ||
|
|
||
| class AppInfoImpl implements AppInfo { | ||
|
|
||
| @Override | ||
| public String getFormattedVersionCode() { | ||
| return Integer.toString(BuildConfig.VERSION_CODE); | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/nextcloud/client/appinfo/AppInfoModule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Nextcloud Android client application | ||
| * | ||
| * @author Chris Narkiewicz | ||
| * Copyright (C) 2019 Chris Narkiewicz <[email protected]> | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package com.nextcloud.client.appinfo; | ||
|
|
||
| import dagger.Module; | ||
| import dagger.Provides; | ||
|
|
||
| @Module | ||
| public class AppInfoModule { | ||
| @Provides | ||
| AppInfo appInfo() { | ||
| return new AppInfoImpl(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,11 @@ | |
| * Nextcloud Android client application | ||
| * | ||
| * @author Bartosz Przybylski | ||
| * @author Chris Narkiewicz | ||
| * Copyright (C) 2015 Bartosz Przybylski | ||
| * Copyright (C) 2015 ownCloud Inc. | ||
| * Copyright (C) 2016 Nextcloud. | ||
| * Copyright (C) 2019 Chris Narkiewicz <[email protected]> | ||
| * | ||
| * This program is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE | ||
|
|
@@ -19,24 +21,20 @@ | |
| * You should have received a copy of the GNU Affero General Public | ||
| * License along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package com.nextcloud.client.whatsnew; | ||
|
|
||
| package com.owncloud.android.ui.activity; | ||
|
|
||
| import android.content.Context; | ||
| import android.content.Intent; | ||
| import android.os.Build; | ||
| import android.os.Bundle; | ||
| import android.view.View; | ||
| import android.widget.Button; | ||
| import android.widget.ImageButton; | ||
| import android.widget.TextView; | ||
|
|
||
| import com.nextcloud.client.appinfo.AppInfo; | ||
| import com.nextcloud.client.di.Injectable; | ||
| import com.nextcloud.client.preferences.AppPreferences; | ||
| import com.owncloud.android.MainApp; | ||
| import com.owncloud.android.BuildConfig; | ||
| import com.owncloud.android.R; | ||
| import com.owncloud.android.authentication.AccountUtils; | ||
| import com.owncloud.android.features.FeatureItem; | ||
| import com.owncloud.android.ui.adapter.FeaturesViewAdapter; | ||
| import com.owncloud.android.ui.adapter.FeaturesWebViewAdapter; | ||
| import com.owncloud.android.ui.whatsnew.ProgressIndicator; | ||
|
|
@@ -57,6 +55,8 @@ public class WhatsNewActivity extends FragmentActivity implements ViewPager.OnPa | |
| private ProgressIndicator mProgress; | ||
| private ViewPager mPager; | ||
| @Inject AppPreferences preferences; | ||
| @Inject AppInfo appInfo; | ||
| @Inject WhatsNewService whatsNew; | ||
|
|
||
| @Override | ||
| protected void onCreate(Bundle savedInstanceState) { | ||
|
|
@@ -73,12 +73,12 @@ protected void onCreate(Bundle savedInstanceState) { | |
|
|
||
| if (showWebView) { | ||
| FeaturesWebViewAdapter featuresWebViewAdapter = new FeaturesWebViewAdapter(getSupportFragmentManager(), | ||
| urls); | ||
| urls); | ||
| mProgress.setNumberOfSteps(featuresWebViewAdapter.getCount()); | ||
| mPager.setAdapter(featuresWebViewAdapter); | ||
| } else { | ||
| FeaturesViewAdapter featuresViewAdapter = new FeaturesViewAdapter(getSupportFragmentManager(), | ||
| getWhatsNew(this, preferences)); | ||
| whatsNew.getWhatsNew()); | ||
| mProgress.setNumberOfSteps(featuresViewAdapter.getCount()); | ||
| mPager.setAdapter(featuresViewAdapter); | ||
| } | ||
|
|
@@ -117,7 +117,7 @@ protected void onCreate(Bundle savedInstanceState) { | |
| if (showWebView) { | ||
| tv.setText(R.string.app_name); | ||
| } else { | ||
| tv.setText(String.format(getString(R.string.whats_new_title), MainApp.getVersionName())); | ||
| tv.setText(String.format(getString(R.string.whats_new_title), appInfo.getFormattedVersionCode())); | ||
| } | ||
|
|
||
| updateNextButtonIfNeeded(); | ||
|
|
@@ -140,21 +140,7 @@ private void updateNextButtonIfNeeded() { | |
| } | ||
|
|
||
| private void onFinish() { | ||
| preferences.setLastSeenVersionCode(MainApp.getVersionCode()); | ||
| } | ||
|
|
||
| public static void runIfNeeded(Context context, AppPreferences preferences) { | ||
| if (!context.getResources().getBoolean(R.bool.show_whats_new) || context instanceof WhatsNewActivity) { | ||
| return; | ||
| } | ||
|
|
||
| if (shouldShow(context, preferences)) { | ||
| context.startActivity(new Intent(context, WhatsNewActivity.class)); | ||
| } | ||
| } | ||
|
|
||
| private static boolean shouldShow(Context context, AppPreferences preferences) { | ||
| return !(context instanceof PassCodeActivity) && getWhatsNew(context, preferences).length > 0; | ||
| preferences.setLastSeenVersionCode(BuildConfig.VERSION_CODE); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -172,19 +158,5 @@ public void onPageSelected(int position) { | |
| public void onPageScrollStateChanged(int state) { | ||
| // unused but to be implemented due to abstract parent | ||
| } | ||
|
|
||
| static private boolean isFirstRun(Context context) { | ||
| return AccountUtils.getCurrentOwnCloudAccount(context) == null; | ||
| } | ||
|
|
||
| private static FeatureItem[] getWhatsNew(Context context, AppPreferences preferences) { | ||
| int itemVersionCode = 30030099; | ||
|
|
||
| if (!isFirstRun(context) && MainApp.getVersionCode() >= itemVersionCode | ||
| && preferences.getLastSeenVersionCode() < itemVersionCode) { | ||
| return new FeatureItem[0]; | ||
| } else { | ||
| return new FeatureItem[0]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
41 changes: 41 additions & 0 deletions
41
src/main/java/com/nextcloud/client/whatsnew/WhatsNewModule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* Nextcloud Android client application | ||
| * | ||
| * @author Chris Narkiewicz | ||
| * Copyright (C) 2019 Chris Narkiewicz <[email protected]> | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package com.nextcloud.client.whatsnew; | ||
|
|
||
| import android.content.res.Resources; | ||
|
|
||
| import com.nextcloud.client.account.CurrentAccountProvider; | ||
| import com.nextcloud.client.preferences.AppPreferences; | ||
|
|
||
| import javax.inject.Singleton; | ||
|
|
||
| import dagger.Module; | ||
| import dagger.Provides; | ||
|
|
||
| @Module | ||
| public class WhatsNewModule { | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| WhatsNewService whatsNewService(Resources resources, | ||
| AppPreferences preferences, | ||
| CurrentAccountProvider accountProvider) { | ||
| return new WhatsNewService(resources, preferences, accountProvider); | ||
| } | ||
| } | ||
75 changes: 75 additions & 0 deletions
75
src/main/java/com/nextcloud/client/whatsnew/WhatsNewService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* Nextcloud Android client application | ||
| * | ||
| * @author Chris Narkiewicz | ||
| * Copyright (C) 2019 Chris Narkiewicz <[email protected]> | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package com.nextcloud.client.whatsnew; | ||
ezaquarii marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import android.app.Activity; | ||
| import android.content.Context; | ||
| import android.content.Intent; | ||
| import android.content.res.Resources; | ||
|
|
||
| import com.nextcloud.client.account.CurrentAccountProvider; | ||
| import com.nextcloud.client.preferences.AppPreferences; | ||
| import com.owncloud.android.BuildConfig; | ||
| import com.owncloud.android.R; | ||
| import com.owncloud.android.features.FeatureItem; | ||
| import com.owncloud.android.ui.activity.PassCodeActivity; | ||
|
|
||
| public class WhatsNewService { | ||
|
|
||
| private Resources resources; | ||
| private AppPreferences preferences; | ||
| private CurrentAccountProvider accountProvider; | ||
|
|
||
| WhatsNewService(Resources resources, | ||
| AppPreferences preferences, | ||
| CurrentAccountProvider accountProvider) { | ||
| this.resources = resources; | ||
| this.preferences = preferences; | ||
| this.accountProvider = accountProvider; | ||
| } | ||
|
|
||
| public void launchActivityIfNeeded(Activity activity) { | ||
| if (!resources.getBoolean(R.bool.show_whats_new) || activity instanceof WhatsNewActivity) { | ||
| return; | ||
| } | ||
|
|
||
| if (shouldShow(activity)) { | ||
| activity.startActivity(new Intent(activity, WhatsNewActivity.class)); | ||
| } | ||
| } | ||
|
|
||
| FeatureItem[] getWhatsNew() { | ||
| int itemVersionCode = 99999999; | ||
|
|
||
| if (!isFirstRun() && BuildConfig.VERSION_CODE >= itemVersionCode | ||
| && preferences.getLastSeenVersionCode() < itemVersionCode) { | ||
| return new FeatureItem[0]; | ||
| } else { | ||
| return new FeatureItem[0]; | ||
| } | ||
| } | ||
|
|
||
| private boolean shouldShow(Context callingContext) { | ||
| return !(callingContext instanceof PassCodeActivity) && getWhatsNew().length > 0; | ||
| } | ||
|
|
||
| public boolean isFirstRun() { | ||
| return accountProvider.getCurrentAccount() == null; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.