Browse Source

commonactivity: use icepick/bridge

Andrew Dolgov 11 months ago
parent
commit
d214c98c09

+ 2 - 0
build.gradle

@@ -13,6 +13,8 @@ allprojects {
     repositories {
         maven { url "http://dl.bintray.com/populov/maven" }
         maven { url "http://jzaccone.github.io/SlidingMenu-aar" }
+        maven { url "https://jitpack.io" }
+        maven {url "https://clojars.org/repo/"}
         jcenter()
         google()
     }

+ 4 - 0
org.fox.ttrss/build.gradle

@@ -50,5 +50,9 @@ dependencies {
     compile 'com.viewpagerindicator:library:2.4.1'
     compile 'com.nineoldandroids:library:2.4.0'
     compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
+    compile 'frankiesardo:icepick:3.2.0'
+    provided 'frankiesardo:icepick-processor:3.2.0'
+    annotationProcessor 'frankiesardo:icepick-processor:3.2.0'
+    compile 'com.github.livefront:bridge:v1.1.1'
     compile files('libs/YouTubeAndroidPlayerApi.jar')
 }

+ 19 - 0
org.fox.ttrss/src/main/java/org/fox/ttrss/Application.java

@@ -1,6 +1,11 @@
 package org.fox.ttrss;
 
 import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+
+import com.livefront.bridge.Bridge;
+import com.livefront.bridge.SavedStateHandler;
 
 import org.acra.ACRA;
 import org.acra.ReportingInteractionMode;
@@ -8,6 +13,8 @@ import org.acra.annotation.ReportsCrashes;
 import org.fox.ttrss.types.Article;
 import org.fox.ttrss.types.ArticleList;
 
+import icepick.Icepick;
+
 @ReportsCrashes(mode = ReportingInteractionMode.SILENT,
         excludeMatchingSharedPreferencesKeys = {"password"},
         resDialogText = R.string.crash_dialog_text,
@@ -33,6 +40,18 @@ public class Application extends android.app.Application {
             ACRA.init(this);
         }
 
+		Bridge.initialize(getApplicationContext(), new SavedStateHandler() {
+			@Override
+			public void saveInstanceState(@NonNull Object target, @NonNull Bundle state) {
+				Icepick.saveInstanceState(target, state);
+			}
+
+			@Override
+			public void restoreInstanceState(@NonNull Object target, @Nullable Bundle state) {
+				Icepick.restoreInstanceState(target, state);
+			}
+		});
+
 		m_singleton = this;
 	}
 	

+ 8 - 23
org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java

@@ -36,6 +36,7 @@ import android.view.View;
 import android.widget.CheckBox;
 
 import com.bumptech.glide.Glide;
+import com.livefront.bridge.Bridge;
 
 import org.fox.ttrss.util.DatabaseHelper;
 import org.fox.ttrss.widget.SmallWidgetProvider;
@@ -47,6 +48,8 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import icepick.State;
+
 public class CommonActivity extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
 	private final String TAG = this.getClass().getSimpleName();
 	
@@ -73,7 +76,7 @@ public class CommonActivity extends AppCompatActivity implements SharedPreferenc
 	//private SQLiteDatabase m_writableDb;
 
 	private boolean m_smallScreenMode = true;
-	private String m_theme;
+	@State protected String m_theme;
 	private boolean m_needRestart;
 
 	private static String s_customTabPackageName;
@@ -224,9 +227,9 @@ public class CommonActivity extends AppCompatActivity implements SharedPreferenc
 
 		setupWidgetUpdates(this);
 
-        if (savedInstanceState != null) {
-			m_theme = savedInstanceState.getString("theme");
-		} else {
+		Bridge.restoreInstanceState(this, savedInstanceState);
+
+        if (savedInstanceState == null) {
 			m_theme = m_prefs.getString("theme", CommonActivity.THEME_DEFAULT);
 		}
 
@@ -235,31 +238,13 @@ public class CommonActivity extends AppCompatActivity implements SharedPreferenc
 		CustomTabsClient.bindCustomTabsService(this, customTabPackageName != null ?
 				customTabPackageName : "com.android.chrome", m_customTabServiceConnection);
 
-		/*if (!ImageLoader.getInstance().isInited()) {
-			ImageLoaderConfiguration config;
-
-			try {
-				config = new ImageLoaderConfiguration.Builder(getApplicationContext())
-						.diskCache(
-								new LruDiscCache(new File(getCacheDir(), "article-images"),
-										DefaultConfigurationFactory.createFileNameGenerator(),
-										100 * 1024 * 1024))
-						.build();
-			} catch (IOException e) {
-				config = new ImageLoaderConfiguration.Builder(getApplicationContext())
-						.build();
-			}
-			ImageLoader.getInstance().init(config);
-		}*/
-
 		super.onCreate(savedInstanceState);
 	}
 
 	@Override
 	public void onSaveInstanceState(Bundle out) {
 		super.onSaveInstanceState(out);
-		
-		out.putString("theme", m_theme);
+		Bridge.saveInstanceState(this, out);
 	}
 	
 	public boolean isSmallScreen() {