Skip to content

Commit 239a79a

Browse files
committed
Add WhatsNewService and AppInfo
Signed-off-by: Chris Narkiewicz <[email protected]>
1 parent 02cbafe commit 239a79a

File tree

16 files changed

+307
-87
lines changed

16 files changed

+307
-87
lines changed

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ android {
246246
dependencies {
247247
// dependencies for app building
248248
implementation 'androidx.multidex:multidex:2.0.1'
249-
// implementation project('nextcloud-android-library')
250249
genericImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT'
251250
gplayImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT'
252251
versionDevImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT'

src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@
310310
<activity
311311
android:name=".ui.trashbin.TrashbinActivity"
312312
android:configChanges="orientation|screenSize|keyboardHidden"/>
313-
<activity android:name=".ui.activity.WhatsNewActivity"
313+
<activity android:name="com.nextcloud.client.whatsnew.WhatsNewActivity"
314314
android:theme="@style/Theme.ownCloud.noActionBar.Login" />
315315
<activity
316316
android:name=".ui.activity.FirstRunActivity"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Nextcloud Android client application
3+
*
4+
* @author Chris Narkiewicz
5+
* Copyright (C) 2019 Chris Narkiewicz <[email protected]>
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package com.nextcloud.client.appinfo;
21+
22+
/**
23+
* This class provides general, static information about application
24+
* build.
25+
*
26+
* All methods should be thread-safe.
27+
*/
28+
public interface AppInfo {
29+
30+
/**
31+
* Get application version code.
32+
*
33+
* TODO: check validity of this assumption:
34+
* Non gradle build systems do not provide {@link com.owncloud.android.BuildConfig#VERSION_CODE}
35+
* so we must fallback to this method :(
36+
*
37+
* @return Version code as defined in AndroidManifest.xml
38+
*/
39+
int getVersionCode();
40+
41+
/**
42+
* Get application version code as formatted string.
43+
*
44+
* TODO: check validity of this assumption:
45+
* Non gradle build systems do not provide {@link com.owncloud.android.BuildConfig#VERSION_CODE}
46+
* so we must fallback to this method :(
47+
*
48+
* @return Formatted version code as defined in AndroidManifest.xml
49+
*/
50+
String getFormattedVersionCode();
51+
52+
/**
53+
* Get application version name.
54+
*
55+
* TODO: check validity of this assumption:
56+
* Non gradle build systems do not provide {@link com.owncloud.android.BuildConfig#VERSION_NAME}
57+
* so we must fallback to this method :(
58+
*
59+
* @return Version code as defined in AndroidManifest.xml
60+
*/
61+
String getVersionName();
62+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Nextcloud Android client application
3+
*
4+
* @author Chris Narkiewicz
5+
* Copyright (C) 2019 Chris Narkiewicz <[email protected]>
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package com.nextcloud.client.appinfo;
21+
22+
import android.content.Context;
23+
import android.content.pm.PackageManager;
24+
25+
class AppInfoImpl implements AppInfo {
26+
27+
private Context context;
28+
29+
AppInfoImpl(Context context) {
30+
this.context = context;
31+
}
32+
33+
// Non gradle build systems do not provide BuildConfig.VERSION_CODE
34+
// so we must fallback to this method :(
35+
@Override
36+
public int getVersionCode() {
37+
try {
38+
String thisPackageName = context.getPackageName();
39+
return context.getPackageManager().getPackageInfo(thisPackageName, 0).versionCode;
40+
} catch (PackageManager.NameNotFoundException e) {
41+
return 0;
42+
}
43+
}
44+
45+
@Override
46+
public String getFormattedVersionCode() {
47+
return Integer.toString(getVersionCode());
48+
}
49+
50+
// Non gradle build systems do not provide BuildConfig.VERSION_CODE
51+
// so we must fallback to this method :(
52+
@Override
53+
public String getVersionName() {
54+
try {
55+
String thisPackageName = context.getPackageName();
56+
return context.getPackageManager().getPackageInfo(thisPackageName, 0).versionName;
57+
} catch (PackageManager.NameNotFoundException e) {
58+
return "";
59+
}
60+
}
61+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Nextcloud Android client application
3+
*
4+
* @author Chris Narkiewicz
5+
* Copyright (C) 2019 Chris Narkiewicz <[email protected]>
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package com.nextcloud.client.appinfo;
21+
22+
import android.content.Context;
23+
24+
import dagger.Module;
25+
import dagger.Provides;
26+
27+
@Module
28+
public class AppInfoModule {
29+
@Provides
30+
AppInfo appInfo(Context context) {
31+
return new AppInfoImpl(context);
32+
}
33+
}

src/main/java/com/nextcloud/client/di/AppComponent.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,23 @@
2222

2323
import android.app.Application;
2424

25+
import com.nextcloud.client.appinfo.AppInfoModule;
26+
import com.nextcloud.client.whatsnew.WhatsNewModule;
2527
import com.owncloud.android.MainApp;
2628

29+
import javax.inject.Singleton;
30+
2731
import dagger.BindsInstance;
2832
import dagger.Component;
2933
import dagger.android.support.AndroidSupportInjectionModule;
3034

3135
@Component(modules = {
3236
AndroidSupportInjectionModule.class,
33-
AppModule.class
37+
AppModule.class,
38+
AppInfoModule.class,
39+
WhatsNewModule.class,
3440
})
41+
@Singleton
3542
public interface AppComponent {
3643
void inject(MainApp app);
3744

src/main/java/com/nextcloud/client/di/AppModule.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import android.app.Application;
2525
import android.content.ContentResolver;
2626
import android.content.Context;
27+
import android.content.res.Resources;
2728

2829
import com.nextcloud.client.account.CurrentAccountProvider;
2930
import com.nextcloud.client.account.UserAccountManager;
@@ -56,6 +57,11 @@ Context context(Application application) {
5657
return application;
5758
}
5859

60+
@Provides
61+
Resources resources(Application application) {
62+
return application.getResources();
63+
}
64+
5965
@Provides
6066
AppPreferences preferences(Application application) {
6167
return AppPreferencesImpl.fromContext(application);

src/main/java/com/nextcloud/client/di/ComponentsModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
import com.owncloud.android.ui.activity.UploadListActivity;
5757
import com.owncloud.android.ui.activity.UploadPathActivity;
5858
import com.owncloud.android.ui.activity.UserInfoActivity;
59-
import com.owncloud.android.ui.activity.WhatsNewActivity;
59+
import com.nextcloud.client.whatsnew.WhatsNewActivity;
6060
import com.owncloud.android.ui.dialog.ChooseTemplateDialogFragment;
6161
import com.owncloud.android.ui.errorhandling.ErrorShowActivity;
6262
import com.owncloud.android.ui.fragment.ExtendedListFragment;

src/main/java/com/owncloud/android/ui/activity/WhatsNewActivity.java renamed to src/main/java/com/nextcloud/client/whatsnew/WhatsNewActivity.java

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,19 @@
2020
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
2121
*/
2222

23-
package com.owncloud.android.ui.activity;
23+
package com.nextcloud.client.whatsnew;
2424

25-
import android.content.Context;
26-
import android.content.Intent;
2725
import android.os.Build;
2826
import android.os.Bundle;
2927
import android.view.View;
3028
import android.widget.Button;
3129
import android.widget.ImageButton;
3230
import android.widget.TextView;
3331

32+
import com.nextcloud.client.appinfo.AppInfo;
3433
import com.nextcloud.client.di.Injectable;
3534
import com.nextcloud.client.preferences.AppPreferences;
36-
import com.owncloud.android.MainApp;
3735
import com.owncloud.android.R;
38-
import com.owncloud.android.authentication.AccountUtils;
39-
import com.owncloud.android.features.FeatureItem;
4036
import com.owncloud.android.ui.adapter.FeaturesViewAdapter;
4137
import com.owncloud.android.ui.adapter.FeaturesWebViewAdapter;
4238
import com.owncloud.android.ui.whatsnew.ProgressIndicator;
@@ -57,6 +53,8 @@ public class WhatsNewActivity extends FragmentActivity implements ViewPager.OnPa
5753
private ProgressIndicator mProgress;
5854
private ViewPager mPager;
5955
@Inject AppPreferences preferences;
56+
@Inject AppInfo appInfo;
57+
@Inject WhatsNewService whatsNew;
6058

6159
@Override
6260
protected void onCreate(Bundle savedInstanceState) {
@@ -73,12 +71,12 @@ protected void onCreate(Bundle savedInstanceState) {
7371

7472
if (showWebView) {
7573
FeaturesWebViewAdapter featuresWebViewAdapter = new FeaturesWebViewAdapter(getSupportFragmentManager(),
76-
urls);
74+
urls);
7775
mProgress.setNumberOfSteps(featuresWebViewAdapter.getCount());
7876
mPager.setAdapter(featuresWebViewAdapter);
7977
} else {
8078
FeaturesViewAdapter featuresViewAdapter = new FeaturesViewAdapter(getSupportFragmentManager(),
81-
getWhatsNew(this, preferences));
79+
whatsNew.getWhatsNew());
8280
mProgress.setNumberOfSteps(featuresViewAdapter.getCount());
8381
mPager.setAdapter(featuresViewAdapter);
8482
}
@@ -117,7 +115,7 @@ protected void onCreate(Bundle savedInstanceState) {
117115
if (showWebView) {
118116
tv.setText(R.string.app_name);
119117
} else {
120-
tv.setText(String.format(getString(R.string.whats_new_title), MainApp.getVersionName()));
118+
tv.setText(String.format(getString(R.string.whats_new_title), appInfo.getVersionName()));
121119
}
122120

123121
updateNextButtonIfNeeded();
@@ -140,21 +138,7 @@ private void updateNextButtonIfNeeded() {
140138
}
141139

142140
private void onFinish() {
143-
preferences.setLastSeenVersionCode(MainApp.getVersionCode());
144-
}
145-
146-
public static void runIfNeeded(Context context, AppPreferences preferences) {
147-
if (!context.getResources().getBoolean(R.bool.show_whats_new) || context instanceof WhatsNewActivity) {
148-
return;
149-
}
150-
151-
if (shouldShow(context, preferences)) {
152-
context.startActivity(new Intent(context, WhatsNewActivity.class));
153-
}
154-
}
155-
156-
private static boolean shouldShow(Context context, AppPreferences preferences) {
157-
return !(context instanceof PassCodeActivity) && getWhatsNew(context, preferences).length > 0;
141+
preferences.setLastSeenVersionCode(appInfo.getVersionCode());
158142
}
159143

160144
@Override
@@ -172,21 +156,6 @@ public void onPageSelected(int position) {
172156
public void onPageScrollStateChanged(int state) {
173157
// unused but to be implemented due to abstract parent
174158
}
159+
}
175160

176-
static private boolean isFirstRun(Context context) {
177-
return AccountUtils.getCurrentOwnCloudAccount(context) == null;
178-
}
179-
180-
private static FeatureItem[] getWhatsNew(Context context, AppPreferences preferences) {
181-
int itemVersionCode = 30030099;
182161

183-
if (!isFirstRun(context) && MainApp.getVersionCode() >= itemVersionCode
184-
&& preferences.getLastSeenVersionCode() < itemVersionCode) {
185-
return new FeatureItem[]{new FeatureItem(R.drawable.whats_new_device_credentials,
186-
R.string.whats_new_device_credentials_title, R.string.whats_new_device_credentials_content,
187-
false, false)};
188-
} else {
189-
return new FeatureItem[0];
190-
}
191-
}
192-
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.nextcloud.client.whatsnew;
2+
3+
import android.content.Context;
4+
import android.content.res.Resources;
5+
6+
import com.nextcloud.client.account.CurrentAccountProvider;
7+
import com.nextcloud.client.appinfo.AppInfo;
8+
import com.nextcloud.client.preferences.AppPreferences;
9+
10+
import javax.inject.Singleton;
11+
12+
import dagger.Module;
13+
import dagger.Provides;
14+
15+
@Module
16+
public class WhatsNewModule {
17+
18+
@Provides
19+
@Singleton
20+
WhatsNewService whatsNewService(
21+
Resources resources,
22+
AppPreferences preferences,
23+
CurrentAccountProvider accountProvider,
24+
AppInfo appInfo
25+
) {
26+
return new WhatsNewService(resources, preferences, accountProvider, appInfo);
27+
}
28+
}

0 commit comments

Comments
 (0)