1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-06-26 05:24:52 +02:00
dandelion/app/src/main/java/com/github/dfa/diaspora_android/App.java

100 lines
3.1 KiB
Java
Raw Normal View History

2016-07-29 14:00:28 +02:00
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
2016-03-29 19:38:50 +02:00
package com.github.dfa.diaspora_android;
2016-03-24 13:56:30 +01:00
import android.app.Application;
2016-03-30 03:13:38 +02:00
import android.content.Context;
import android.os.Build;
import android.support.annotation.Nullable;
2016-03-30 03:13:38 +02:00
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebView;
2016-03-24 13:56:30 +01:00
2016-03-29 19:38:50 +02:00
import com.github.dfa.diaspora_android.data.AppSettings;
2016-06-05 17:25:11 +02:00
import com.github.dfa.diaspora_android.data.PodUserProfile;
2016-03-29 19:38:50 +02:00
import com.github.dfa.diaspora_android.util.AvatarImageLoader;
2016-08-10 23:43:00 +02:00
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
2016-03-24 13:56:30 +01:00
public class App extends Application {
2016-03-30 03:13:38 +02:00
public static final String TAG = "DIASPORA_";
2016-03-24 13:56:30 +01:00
private AppSettings appSettings;
private AvatarImageLoader avatarImageLoader;
2016-03-30 03:13:38 +02:00
private CookieManager cookieManager;
2016-06-05 17:25:11 +02:00
private PodUserProfile podUserProfile;
2016-03-24 13:56:30 +01:00
@Override
public void onCreate() {
super.onCreate();
2016-03-30 03:13:38 +02:00
final Context c = getApplicationContext();
appSettings = new AppSettings(c);
avatarImageLoader = new AvatarImageLoader(c);
2016-06-05 17:25:11 +02:00
podUserProfile = new PodUserProfile(this);
2016-03-30 03:13:38 +02:00
// Get cookie manager
cookieManager = CookieManager.getInstance();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
2016-08-10 23:43:00 +02:00
//noinspection deprecation
2016-03-30 03:13:38 +02:00
CookieSyncManager.createInstance(c);
}
cookieManager.setAcceptCookie(true);
2016-03-24 13:56:30 +01:00
}
public void resetPodData(@Nullable WebView webView){
if(webView != null){
webView.stopLoading();
2016-08-10 23:43:00 +02:00
webView.loadUrl(DiasporaUrlHelper.URL_BLANK);
webView.clearFormData();
webView.clearHistory();
webView.clearCache(true);
}
// Clear avatar image
new AvatarImageLoader(this).clearAvatarImage();
// Clear preferences
appSettings.clearPodSettings();
// Clear cookies
2016-08-10 23:43:00 +02:00
//noinspection deprecation
cookieManager.removeAllCookie();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cookieManager.removeAllCookies(null);
}
}
2016-06-05 17:25:11 +02:00
public PodUserProfile getPodUserProfile(){
return podUserProfile;
}
2016-03-24 13:56:30 +01:00
public AppSettings getSettings() {
return appSettings;
}
public AvatarImageLoader getAvatarImageLoader() {
return avatarImageLoader;
}
2016-03-30 03:13:38 +02:00
public CookieManager getCookieManager() {
return cookieManager;
}
2016-03-24 13:56:30 +01:00
}