From df0e143cf69429dedd297c24c9b7ba6c7ff7b9e9 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Wed, 18 Jan 2017 20:17:58 +0200 Subject: [PATCH] BaseApplication class, fixed refresh upon app restart (e.g. after crash), optimized imports --- app/src/main/AndroidManifest.xml | 1 + app/src/main/assets/mit_libraries.html | 2 +- .../mthmmy/activities/AboutActivity.java | 2 +- .../mthmmy/activities/LoginActivity.java | 2 +- .../activities/board/BoardActivity.java | 2 +- .../mthmmy/activities/main/MainActivity.java | 2 +- .../activities/main/forum/ForumAdapter.java | 2 +- .../activities/main/forum/ForumFragment.java | 4 +- .../activities/main/recent/RecentAdapter.java | 2 +- .../main/recent/RecentFragment.java | 2 +- .../activities/profile/ProfileActivity.java | 2 +- .../latestPosts/LatestPostsAdapter.java | 2 +- .../latestPosts/LatestPostsFragment.java | 4 +- .../profile/stats/StatsFragment.java | 2 +- .../activities/topic/TopicActivity.java | 2 +- .../mthmmy/activities/topic/TopicAdapter.java | 1 - .../{activities => }/base/BaseActivity.java | 77 ++------------- .../gr/thmmy/mthmmy/base/BaseApplication.java | 97 +++++++++++++++++++ .../{activities => }/base/BaseFragment.java | 8 +- .../gr/thmmy/mthmmy/model/LinkTarget.java | 1 - .../mthmmy/utils/FileManager/ThmmyFile.java | 2 +- .../utils/ScrollAwareLinearBehavior.java | 1 - 22 files changed, 127 insertions(+), 93 deletions(-) rename app/src/main/java/gr/thmmy/mthmmy/{activities => }/base/BaseActivity.java (77%) create mode 100644 app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java rename app/src/main/java/gr/thmmy/mthmmy/{activities => }/base/BaseFragment.java (89%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f8bed348..ba225043 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,6 +9,7 @@
  • -
    jsoup v1.10.1 (Copyright ©2009-2017, Jonathan Hedley <jonathan@hedley.net>)
    +
    jsoup v1.10.2 (Copyright ©2009-2017, Jonathan Hedley <jonathan@hedley.net>)
  • android-gif-drawable v1.2.3 (Copyright ©2016 Karol Wrótniak, Droids on Roids)
    diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java index 0b33c3e9..ffc54d8d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java @@ -16,7 +16,7 @@ import android.widget.TextView; import gr.thmmy.mthmmy.BuildConfig; import gr.thmmy.mthmmy.R; -import gr.thmmy.mthmmy.activities.base.BaseActivity; +import gr.thmmy.mthmmy.base.BaseActivity; public class AboutActivity extends BaseActivity { private static final int TIME_INTERVAL = 1000; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java index 2035653a..7dacd734 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java @@ -12,8 +12,8 @@ import android.widget.ScrollView; import android.widget.Toast; import gr.thmmy.mthmmy.R; -import gr.thmmy.mthmmy.activities.base.BaseActivity; import gr.thmmy.mthmmy.activities.main.MainActivity; +import gr.thmmy.mthmmy.base.BaseActivity; import mthmmy.utils.Report; import static gr.thmmy.mthmmy.session.SessionManager.CONNECTION_ERROR; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java index 9b7071f5..a48a3a8a 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java @@ -27,7 +27,7 @@ import javax.net.ssl.SSLHandshakeException; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.LoginActivity; -import gr.thmmy.mthmmy.activities.base.BaseActivity; +import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.model.Board; import gr.thmmy.mthmmy.model.LinkTarget; import gr.thmmy.mthmmy.model.Topic; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java index cb9981b1..84319e3f 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java @@ -12,11 +12,11 @@ import android.widget.Toast; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.LoginActivity; -import gr.thmmy.mthmmy.activities.base.BaseActivity; import gr.thmmy.mthmmy.activities.board.BoardActivity; import gr.thmmy.mthmmy.activities.main.forum.ForumFragment; import gr.thmmy.mthmmy.activities.main.recent.RecentFragment; import gr.thmmy.mthmmy.activities.topic.TopicActivity; +import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.model.Board; import gr.thmmy.mthmmy.model.TopicSummary; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java index 896078e8..40f14c93 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java @@ -15,7 +15,7 @@ import com.bignerdranch.expandablerecyclerview.ParentViewHolder; import java.util.List; import gr.thmmy.mthmmy.R; -import gr.thmmy.mthmmy.activities.base.BaseFragment; +import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.Board; import gr.thmmy.mthmmy.model.Category; import gr.thmmy.mthmmy.model.TopicSummary; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java index 9b51c3af..d9777cf7 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java @@ -24,8 +24,8 @@ import java.util.ArrayList; import java.util.List; import gr.thmmy.mthmmy.R; -import gr.thmmy.mthmmy.activities.base.BaseActivity; -import gr.thmmy.mthmmy.activities.base.BaseFragment; +import gr.thmmy.mthmmy.base.BaseActivity; +import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.Board; import gr.thmmy.mthmmy.model.Category; import gr.thmmy.mthmmy.session.SessionManager; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java index beb22697..32e46af0 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java @@ -11,7 +11,7 @@ import android.widget.TextView; import java.util.List; import gr.thmmy.mthmmy.R; -import gr.thmmy.mthmmy.activities.base.BaseFragment; +import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.TopicSummary; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java index 307f1b33..546b2db3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java @@ -23,7 +23,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import gr.thmmy.mthmmy.R; -import gr.thmmy.mthmmy.activities.base.BaseFragment; +import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.TopicSummary; import gr.thmmy.mthmmy.session.SessionManager; import gr.thmmy.mthmmy.utils.CustomRecyclerView; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java index 66e85146..383323be 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java @@ -34,11 +34,11 @@ import javax.net.ssl.SSLHandshakeException; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.LoginActivity; -import gr.thmmy.mthmmy.activities.base.BaseActivity; import gr.thmmy.mthmmy.activities.profile.latestPosts.LatestPostsFragment; import gr.thmmy.mthmmy.activities.profile.stats.StatsFragment; import gr.thmmy.mthmmy.activities.profile.summary.SummaryFragment; import gr.thmmy.mthmmy.activities.topic.TopicActivity; +import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.model.LinkTarget; import gr.thmmy.mthmmy.model.PostSummary; import gr.thmmy.mthmmy.utils.CircleTransform; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java index 7976dd13..5f0f77d2 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java @@ -11,7 +11,7 @@ import android.widget.TextView; import java.util.ArrayList; import gr.thmmy.mthmmy.R; -import gr.thmmy.mthmmy.activities.base.BaseFragment; +import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.PostSummary; import gr.thmmy.mthmmy.model.TopicSummary; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java index 01786f3b..ccdb5593 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java @@ -21,8 +21,8 @@ import java.util.ArrayList; import javax.net.ssl.SSLHandshakeException; import gr.thmmy.mthmmy.R; -import gr.thmmy.mthmmy.activities.base.BaseActivity; -import gr.thmmy.mthmmy.activities.base.BaseFragment; +import gr.thmmy.mthmmy.base.BaseActivity; +import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.PostSummary; import gr.thmmy.mthmmy.utils.ParseHelpers; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java index c75d16bb..789bcfe4 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java @@ -38,7 +38,7 @@ import java.util.List; import javax.net.ssl.SSLHandshakeException; import gr.thmmy.mthmmy.R; -import gr.thmmy.mthmmy.activities.base.BaseActivity; +import gr.thmmy.mthmmy.base.BaseActivity; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import mthmmy.utils.Report; import okhttp3.Request; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java index 3943bf0d..229ec37a 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java @@ -28,7 +28,7 @@ import java.util.Objects; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.LoginActivity; -import gr.thmmy.mthmmy.activities.base.BaseActivity; +import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.model.LinkTarget; import gr.thmmy.mthmmy.model.Post; import gr.thmmy.mthmmy.utils.ParseHelpers; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java index f44e3a65..a9627b25 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java @@ -16,7 +16,6 @@ import android.support.v4.content.res.ResourcesCompat; import android.support.v7.widget.CardView; import android.support.v7.widget.RecyclerView; import android.text.TextUtils; -import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/base/BaseActivity.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java similarity index 77% rename from app/src/main/java/gr/thmmy/mthmmy/activities/base/BaseActivity.java rename to app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java index 4794cf9e..492f84a1 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -1,24 +1,15 @@ -package gr.thmmy.mthmmy.activities.base; +package gr.thmmy.mthmmy.base; import android.app.ProgressDialog; -import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; -import android.graphics.drawable.Drawable; -import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; -import android.widget.ImageView; import android.widget.Toast; -import com.franmontiel.persistentcookiejar.PersistentCookieJar; -import com.franmontiel.persistentcookiejar.cache.SetCookieCache; -import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor; -import com.jakewharton.picasso.OkHttp3Downloader; import com.mikepenz.fontawesome_typeface_library.FontAwesome; import com.mikepenz.iconics.IconicsDrawable; import com.mikepenz.materialdrawer.AccountHeader; @@ -29,11 +20,6 @@ import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; import com.mikepenz.materialdrawer.model.ProfileDrawerItem; import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem; import com.mikepenz.materialdrawer.model.interfaces.IProfile; -import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader; -import com.mikepenz.materialdrawer.util.DrawerImageLoader; -import com.squareup.picasso.Picasso; - -import java.util.concurrent.TimeUnit; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.AboutActivity; @@ -52,23 +38,10 @@ public abstract class BaseActivity extends AppCompatActivity { // Client & Cookies protected static OkHttpClient client; - private static final long connectTimeout = 30; //TimeUnit.SECONDS for all three - private static final long writeTimeout = 30; - private static final long readTimeout = 30; - protected static Picasso picasso; - private static PersistentCookieJar cookieJar; - private static SharedPrefsCookiePersistor sharedPrefsCookiePersistor; - - //Shared Preferences - protected static final String SHARED_PREFS_NAME = "ThmmySharedPrefs"; - protected static SharedPreferences sharedPrefs; //SessionManager protected static SessionManager sessionManager; - //Other variables - private static boolean init = false; //To initialize stuff only once per app start - //Common UI elements protected Toolbar toolbar; protected Drawer drawer; @@ -76,47 +49,11 @@ public abstract class BaseActivity extends AppCompatActivity @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - if (!init) { - sharedPrefs = getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE); - sharedPrefsCookiePersistor = new SharedPrefsCookiePersistor(BaseActivity.this); - cookieJar = new PersistentCookieJar(new SetCookieCache(), sharedPrefsCookiePersistor); - client = new OkHttpClient.Builder() - .cookieJar(cookieJar) - .connectTimeout(connectTimeout, TimeUnit.SECONDS) - .writeTimeout(writeTimeout, TimeUnit.SECONDS) - .readTimeout(readTimeout, TimeUnit.SECONDS) - .build(); - sessionManager = new SessionManager(client, cookieJar, sharedPrefsCookiePersistor, sharedPrefs); - picasso = new Picasso.Builder(BaseActivity.this) - .downloader(new OkHttp3Downloader(client)) - .build(); - Picasso.setSingletonInstance(picasso); // all following Picasso (with Picasso.with(Context context) requests will use this Picasso object - //initialize and create the image loader logic TODO move this to a singleton BaseApplication obj - DrawerImageLoader.init(new AbstractDrawerImageLoader() { - @Override - public void set(ImageView imageView, Uri uri, Drawable placeholder) { - Picasso.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView); - } - @Override - public void cancel(ImageView imageView) { - Picasso.with(imageView.getContext()).cancelRequest(imageView); - } - - @Override - public Drawable placeholder(Context ctx, String tag) { - if (DrawerImageLoader.Tags.PROFILE.name().equals(tag)) { - return new IconicsDrawable(ctx).icon(FontAwesome.Icon.faw_user) - .paddingDp(10) - .color(ContextCompat.getColor(ctx, R.color.primary_light)) - .backgroundColor(ContextCompat.getColor(ctx, R.color.primary)); - } - - return super.placeholder(ctx, tag); - } - }); - init = true; - } + if(client==null) + client = BaseApplication.getInstance().getClient(); //must check every time - e.g. + // they become null when app restarts after crash + if(sessionManager==null) + sessionManager = BaseApplication.getInstance().getSessionManager(); } @Override @@ -143,7 +80,7 @@ public abstract class BaseActivity extends AppCompatActivity return sessionManager; } - //TODO: move stuff below + //TODO: move stuff below (?) //------------------------------------------DRAWER STUFF---------------------------------------- protected static final int HOME_ID=0; protected static final int LOG_ID =1; diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java new file mode 100644 index 00000000..686086aa --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java @@ -0,0 +1,97 @@ +package gr.thmmy.mthmmy.base; + +import android.app.Application; +import android.content.Context; +import android.content.SharedPreferences; +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.support.v4.content.ContextCompat; +import android.widget.ImageView; + +import com.franmontiel.persistentcookiejar.PersistentCookieJar; +import com.franmontiel.persistentcookiejar.cache.SetCookieCache; +import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor; +import com.jakewharton.picasso.OkHttp3Downloader; +import com.mikepenz.fontawesome_typeface_library.FontAwesome; +import com.mikepenz.iconics.IconicsDrawable; +import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader; +import com.mikepenz.materialdrawer.util.DrawerImageLoader; +import com.squareup.picasso.Picasso; + +import java.util.concurrent.TimeUnit; + +import gr.thmmy.mthmmy.R; +import gr.thmmy.mthmmy.session.SessionManager; +import okhttp3.OkHttpClient; + +public class BaseApplication extends Application { + + + private static BaseApplication baseApplication; //BaseApplication singleton + + // Client & SessionManager + private OkHttpClient client; + private static SessionManager sessionManager; + + //Shared Preferences + private static final String SHARED_PREFS_NAME = "ThmmySharedPrefs"; + + public static BaseApplication getInstance(){ + return baseApplication; + } + + @Override + public void onCreate() { + super.onCreate(); + baseApplication = this; //init singleton + + SharedPreferences sharedPrefs = getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE); + SharedPrefsCookiePersistor sharedPrefsCookiePersistor = new SharedPrefsCookiePersistor(getApplicationContext()); + PersistentCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), sharedPrefsCookiePersistor); + client = new OkHttpClient.Builder() + .cookieJar(cookieJar) + .connectTimeout(30, TimeUnit.SECONDS) + .writeTimeout(30, TimeUnit.SECONDS) + .readTimeout(30, TimeUnit.SECONDS) + .build(); + sessionManager = new SessionManager(client, cookieJar, sharedPrefsCookiePersistor, sharedPrefs); + Picasso picasso = new Picasso.Builder(getApplicationContext()) + .downloader(new OkHttp3Downloader(client)) + .build(); + + Picasso.setSingletonInstance(picasso); //All following Picasso (with Picasso.with(Context context) requests will use this Picasso object + + //Initialize and create the image loader logic + DrawerImageLoader.init(new AbstractDrawerImageLoader() { + @Override + public void set(ImageView imageView, Uri uri, Drawable placeholder) { + Picasso.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView); + } + @Override + public void cancel(ImageView imageView) { + Picasso.with(imageView.getContext()).cancelRequest(imageView); + } + + @Override + public Drawable placeholder(Context ctx, String tag) { + if (DrawerImageLoader.Tags.PROFILE.name().equals(tag)) { + return new IconicsDrawable(ctx).icon(FontAwesome.Icon.faw_user) + .paddingDp(10) + .color(ContextCompat.getColor(ctx, R.color.primary_light)) + .backgroundColor(ContextCompat.getColor(ctx, R.color.primary)); + } + return super.placeholder(ctx, tag); + } + }); + } + + public OkHttpClient getClient() { + return client; + } + + public SessionManager getSessionManager() { + return sessionManager; + } + + +} diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/base/BaseFragment.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseFragment.java similarity index 89% rename from app/src/main/java/gr/thmmy/mthmmy/activities/base/BaseFragment.java rename to app/src/main/java/gr/thmmy/mthmmy/base/BaseFragment.java index 6b0b93c9..c7b3d477 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/base/BaseFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseFragment.java @@ -1,4 +1,4 @@ -package gr.thmmy.mthmmy.activities.base; +package gr.thmmy.mthmmy.base; import android.content.Context; import android.os.Bundle; @@ -16,14 +16,16 @@ public abstract class BaseFragment extends Fragment { private String TAG; protected int sectionNumber; - protected OkHttpClient client; + protected static OkHttpClient client; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); TAG = getArguments().getString(ARG_TAG); sectionNumber = getArguments().getInt(ARG_SECTION_NUMBER); - client = BaseActivity.getClient(); + if(client==null) + client = BaseApplication.getInstance().getClient(); //must check every time - e.g. + // becomes null when app restarts after crash Report.d(TAG, "onCreate"); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/LinkTarget.java b/app/src/main/java/gr/thmmy/mthmmy/model/LinkTarget.java index aaf14773..4a112d2a 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/LinkTarget.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/LinkTarget.java @@ -1,7 +1,6 @@ package gr.thmmy.mthmmy.model; import android.net.Uri; -import android.support.annotation.NonNull; import java.util.Objects; diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/FileManager/ThmmyFile.java b/app/src/main/java/gr/thmmy/mthmmy/utils/FileManager/ThmmyFile.java index c1eb7cfb..8e8414f6 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/FileManager/ThmmyFile.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/FileManager/ThmmyFile.java @@ -16,7 +16,7 @@ import mthmmy.utils.Report; import okhttp3.Request; import okhttp3.Response; -import static gr.thmmy.mthmmy.activities.base.BaseActivity.getClient; +import static gr.thmmy.mthmmy.base.BaseActivity.getClient; /** * Used for downloading and storing a file from the forum using {@link okhttp3}. diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareLinearBehavior.java b/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareLinearBehavior.java index 6e791204..0f3564c6 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareLinearBehavior.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareLinearBehavior.java @@ -6,7 +6,6 @@ import android.support.design.widget.CoordinatorLayout; import android.support.v4.view.ViewCompat; import android.support.v4.view.animation.FastOutSlowInInterpolator; import android.util.AttributeSet; -import android.util.Log; import android.view.View; import android.view.ViewPropertyAnimator;