Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

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
ezaquarii authored and tobiasKaminsky committed May 9, 2019
commit f0554ab59bfb2f85fab7a0717b1917aa520d6110
2 changes: 1 addition & 1 deletion src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
<activity
android:name=".ui.trashbin.TrashbinActivity"
android:configChanges="orientation|screenSize|keyboardHidden"/>
<activity android:name=".ui.activity.WhatsNewActivity"
<activity android:name="com.nextcloud.client.whatsnew.WhatsNewActivity"
android:theme="@style/Theme.ownCloud.noActionBar.Login" />
<activity
android:name=".ui.activity.FirstRunActivity"
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/com/nextcloud/client/appinfo/AppInfo.java
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 src/main/java/com/nextcloud/client/appinfo/AppInfoImpl.java
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 src/main/java/com/nextcloud/client/appinfo/AppInfoModule.java
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();
}
}
9 changes: 8 additions & 1 deletion src/main/java/com/nextcloud/client/di/AppComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,23 @@

import android.app.Application;

import com.nextcloud.client.appinfo.AppInfoModule;
import com.nextcloud.client.whatsnew.WhatsNewModule;
import com.owncloud.android.MainApp;

import javax.inject.Singleton;

import dagger.BindsInstance;
import dagger.Component;
import dagger.android.support.AndroidSupportInjectionModule;

@Component(modules = {
AndroidSupportInjectionModule.class,
AppModule.class
AppModule.class,
AppInfoModule.class,
WhatsNewModule.class,
})
@Singleton
public interface AppComponent {
void inject(MainApp app);

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/nextcloud/client/di/AppModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.app.Application;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;

import com.nextcloud.client.account.CurrentAccountProvider;
import com.nextcloud.client.account.UserAccountManager;
Expand Down Expand Up @@ -56,6 +57,11 @@ Context context(Application application) {
return application;
}

@Provides
Resources resources(Application application) {
return application.getResources();
}

@Provides
AppPreferences preferences(Application application) {
return AppPreferencesImpl.fromContext(application);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
import com.owncloud.android.ui.activity.UploadListActivity;
import com.owncloud.android.ui.activity.UploadPathActivity;
import com.owncloud.android.ui.activity.UserInfoActivity;
import com.owncloud.android.ui.activity.WhatsNewActivity;
import com.nextcloud.client.whatsnew.WhatsNewActivity;
import com.owncloud.android.ui.dialog.ChooseTemplateDialogFragment;
import com.owncloud.android.ui.errorhandling.ErrorShowActivity;
import com.owncloud.android.ui.fragment.ExtendedListFragment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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 src/main/java/com/nextcloud/client/whatsnew/WhatsNewModule.java
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 src/main/java/com/nextcloud/client/whatsnew/WhatsNewService.java
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;

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;
}
}
Loading