extends Fragment implements View.OnClickListener, ActionModeListener,
SharedPreferences.OnSharedPreferenceChangeListener, CommonPresenter.AbstractPresenter, Observer, ResponseCallback, ItemClickListener {
@@ -53,14 +56,14 @@ public abstract class FragmentBase extends Fra
protected Unbinder unbinder;
protected @IntegerRes int mColumnSize;
- public String TAG;
+ public final String TAG = getClass().getSimpleName();
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
- TAG = this.toString();
super.onCreate(savedInstanceState);
setRetainInstance(true);
- AnalyticsUtil.logCurrentScreen(getActivity(), TAG);
+ if (getActivity() != null)
+ KoinExt.get(ISupportAnalytics.class).logCurrentScreen(getActivity(), TAG);
}
/**
@@ -105,11 +108,6 @@ public void onDestroyView() {
actionMode = null;
}
- /**
- * Called when the Fragment is visible to the user. This is generally
- * tied to {@link Activity#onStart() Activity.onStart} of the containing
- * Activity's lifecycle.
- */
@Override
public void onStart() {
super.onStart();
@@ -119,11 +117,6 @@ public void onStart() {
setHasOptionsMenu(true);
}
- /**
- * Called when the Fragment is no longer started. This is generally
- * tied to {@link Activity#onStop() Activity.onStop} of the containing
- * Activity's lifecycle.
- */
@Override
public void onStop() {
if(EventBus.getDefault().isRegistered(this))
@@ -131,11 +124,6 @@ public void onStop() {
super.onStop();
}
- /**
- * Called when the Fragment is no longer resumed. This is generally
- * tied to {@link Activity#onPause() Activity.onPause} of the containing
- * Activity's lifecycle.
- */
@Override
public void onPause() {
super.onPause();
@@ -145,12 +133,6 @@ public void onPause() {
presenter.onPause(this);
}
- /**
- * Called when the fragment is visible to the user and actively running.
- * This is generally
- * tied to {@link Activity#onResume() Activity.onResume} of the containing
- * Activity's lifecycle.
- */
@Override
public void onResume() {
super.onResume();
@@ -195,8 +177,8 @@ public void setInflateMenu(@MenuRes int inflateMenu) {
* @return true if the fragment is still valid otherwise false
*/
protected boolean isAlive() {
- //return getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED);
- return isVisible() || !isDetached() || !isRemoving();
+ return getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED);
+ // return isVisible() || !isDetached() || !isRemoving();
}
/**
@@ -331,22 +313,19 @@ public void onDestroyActionMode(ActionMode mode) {
@Override
public void showError(String error) {
- if(!TextUtils.isEmpty(error)) {
- Log.e(TAG, error);
- if (getPresenter() != null && getPresenter().getApplicationPref().isCrashReportsEnabled())
- AnalyticsUtil.reportException(TAG, error);
- }
+ if(!TextUtils.isEmpty(error))
+ Timber.tag(TAG).d(error);
}
@Override
public void showEmpty(String message) {
if(!TextUtils.isEmpty(message))
- Log.d(TAG, message);
+ Timber.tag(TAG).i(message);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
- Log.i(TAG, key);
+ Timber.tag(TAG).i(key);
}
protected void showBottomSheet() {
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/fragment/FragmentBaseComment.java b/app/src/main/java/com/mxt/anitrend/base/custom/fragment/FragmentBaseComment.java
index 22dfd6a31..9463875ab 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/fragment/FragmentBaseComment.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/fragment/FragmentBaseComment.java
@@ -3,17 +3,18 @@
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.support.design.widget.Snackbar;
-import android.support.v7.widget.LinearLayoutManager;
-import android.support.v7.widget.StaggeredGridLayoutManager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.StaggeredGridLayoutManager;
+
import com.annimon.stream.IntPair;
+import com.google.android.material.snackbar.Snackbar;
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.custom.recycler.RecyclerViewAdapter;
import com.mxt.anitrend.base.custom.recycler.StatefulRecyclerView;
@@ -211,7 +212,7 @@ public void showError(String error) {
if(getPresenter() != null && getPresenter().getCurrentPage() > 1 && isPager) {
if(stateLayout.isLoading())
stateLayout.showContent();
- snackbar = NotifyUtil.make(stateLayout, R.string.text_unable_to_load_next_page, Snackbar.LENGTH_INDEFINITE)
+ snackbar = NotifyUtil.INSTANCE.make(stateLayout, R.string.text_unable_to_load_next_page, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.try_again, snackBarOnClick);
snackbar.show();
}
@@ -233,7 +234,7 @@ public void showEmpty(String message) {
if(getPresenter() != null && getPresenter().getCurrentPage() > 1 && isPager) {
if(stateLayout.isLoading())
stateLayout.showContent();
- snackbar = NotifyUtil.make(stateLayout, R.string.text_unable_to_load_next_page, Snackbar.LENGTH_INDEFINITE)
+ snackbar = NotifyUtil.INSTANCE.make(stateLayout, R.string.text_unable_to_load_next_page, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.try_again, snackBarOnClick);
snackbar.show();
}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/fragment/FragmentBaseList.java b/app/src/main/java/com/mxt/anitrend/base/custom/fragment/FragmentBaseList.java
index f37d4bf35..1efc543d5 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/fragment/FragmentBaseList.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/fragment/FragmentBaseList.java
@@ -3,16 +3,17 @@
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.support.design.widget.Snackbar;
-import android.support.v7.widget.StaggeredGridLayoutManager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.recyclerview.widget.StaggeredGridLayoutManager;
+
import com.annimon.stream.IntPair;
+import com.google.android.material.snackbar.Snackbar;
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.custom.presenter.CommonPresenter;
import com.mxt.anitrend.base.custom.recycler.RecyclerViewAdapter;
@@ -20,9 +21,9 @@
import com.mxt.anitrend.base.custom.view.container.CustomSwipeRefreshLayout;
import com.mxt.anitrend.base.interfaces.event.RecyclerLoadListener;
import com.mxt.anitrend.util.CompatUtil;
-import com.mxt.anitrend.util.GraphUtil;
import com.mxt.anitrend.util.KeyUtil;
import com.mxt.anitrend.util.NotifyUtil;
+import com.mxt.anitrend.util.graphql.GraphUtil;
import com.nguyenhoanglam.progresslayout.ProgressLayout;
import org.greenrobot.eventbus.EventBus;
@@ -210,7 +211,7 @@ public void showError(String error) {
if(getPresenter() != null && getPresenter().getCurrentPage() > 1 && isPager) {
if(stateLayout.isLoading())
stateLayout.showContent();
- snackbar = NotifyUtil.make(stateLayout, R.string.text_unable_to_load_next_page, Snackbar.LENGTH_INDEFINITE)
+ snackbar = NotifyUtil.INSTANCE.make(stateLayout, R.string.text_unable_to_load_next_page, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.try_again, snackBarOnClick);
snackbar.show();
}
@@ -231,7 +232,7 @@ public void showEmpty(String message) {
if(getPresenter() != null && getPresenter().getCurrentPage() > 1 && isPager) {
if(stateLayout.isLoading())
stateLayout.showContent();
- snackbar = NotifyUtil.make(stateLayout, R.string.text_unable_to_load_next_page, Snackbar.LENGTH_INDEFINITE)
+ snackbar = NotifyUtil.INSTANCE.make(stateLayout, R.string.text_unable_to_load_next_page, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.try_again, snackBarOnClick);
snackbar.show();
}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/fragment/FragmentChannelBase.java b/app/src/main/java/com/mxt/anitrend/base/custom/fragment/FragmentChannelBase.java
index 0e37d1b36..28fc891fb 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/fragment/FragmentChannelBase.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/fragment/FragmentChannelBase.java
@@ -5,18 +5,18 @@
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.support.design.widget.Snackbar;
-import android.support.v7.widget.StaggeredGridLayoutManager;
import android.text.TextUtils;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.recyclerview.widget.StaggeredGridLayoutManager;
+
import com.annimon.stream.IntPair;
+import com.google.android.material.snackbar.Snackbar;
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.custom.recycler.RecyclerViewAdapter;
import com.mxt.anitrend.base.custom.recycler.StatefulRecyclerView;
@@ -31,9 +31,9 @@
import com.mxt.anitrend.presenter.widget.WidgetPresenter;
import com.mxt.anitrend.util.CompatUtil;
import com.mxt.anitrend.util.DialogUtil;
-import com.mxt.anitrend.util.EpisodeUtil;
import com.mxt.anitrend.util.KeyUtil;
import com.mxt.anitrend.util.NotifyUtil;
+import com.mxt.anitrend.util.collection.EpisodeUtil;
import com.mxt.anitrend.view.activity.index.SearchActivity;
import com.nguyenhoanglam.progresslayout.ProgressLayout;
@@ -45,6 +45,7 @@
import butterknife.BindView;
import butterknife.ButterKnife;
+import timber.log.Timber;
/**
* Created by max on 2017/11/04.
@@ -66,6 +67,8 @@ public abstract class FragmentChannelBase extends FragmentBase mAdapter;
private StaggeredGridLayoutManager mLayoutManager;
+ private final String TAG = FragmentBase.class.getSimpleName();
+
private final View.OnClickListener stateLayoutOnClick = view -> {
if(swipeRefreshLayout.isRefreshing())
swipeRefreshLayout.setRefreshing(false);
@@ -216,7 +219,7 @@ public void showError(String error) {
if(getPresenter() != null && getPresenter().getCurrentPage() > 1 && isPager) {
if(stateLayout.isLoading())
stateLayout.showContent();
- snackbar = NotifyUtil.make(stateLayout, R.string.text_unable_to_load_next_page, Snackbar.LENGTH_INDEFINITE)
+ snackbar = NotifyUtil.INSTANCE.make(stateLayout, R.string.text_unable_to_load_next_page, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.try_again, snackBarOnClick);
snackbar.show();
}
@@ -237,7 +240,7 @@ public void showEmpty(String message) {
if(getPresenter() != null && getPresenter().getCurrentPage() > 1 && isPager) {
if(stateLayout.isLoading())
stateLayout.showContent();
- snackbar = NotifyUtil.make(stateLayout, R.string.text_unable_to_load_next_page, Snackbar.LENGTH_INDEFINITE)
+ snackbar = NotifyUtil.INSTANCE.make(stateLayout, R.string.text_unable_to_load_next_page, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.try_again, snackBarOnClick);
snackbar.show();
}
@@ -334,7 +337,7 @@ public void onChanged(@Nullable Rss content) {
showEmpty(getString(R.string.layout_empty_response));
} catch (Exception e) {
e.printStackTrace();
- Log.e("onChanged(Rss content)", e.getLocalizedMessage());
+ Timber.tag("onChanged(Rss content)").e(e);
showEmpty(getString(R.string.layout_empty_response));
}
}
@@ -349,29 +352,27 @@ public void onChanged(@Nullable Rss content) {
*/
@Override
public void onItemClick(View target, IntPair data) {
- switch (target.getId()) {
- case R.id.series_image:
- DialogUtil.createMessage(getActivity(), data.getSecond().getTitle(), data.getSecond().getDescription()+"
"+copyright,
- R.string.Watch, R.string.Dismiss, R.string.action_search, (dialog, which) -> {
- Intent intent;
- switch (which) {
- case POSITIVE:
- if(data.getSecond().getLink() != null) {
- intent = new Intent(Intent.ACTION_VIEW, Uri.parse(data.getSecond().getLink()));
- startActivity(intent);
- } else
- NotifyUtil.makeText(getActivity(), R.string.text_premium_show, Toast.LENGTH_SHORT).show();
- break;
- case NEUTRAL:
- if(getActivity() != null) {
- intent = new Intent(getActivity(), SearchActivity.class);
- intent.putExtra(KeyUtil.arg_search, EpisodeUtil.INSTANCE.getActualTile(data.getSecond().getTitle()));
- getActivity().startActivity(intent);
- }
- break;
- }
- });
- break;
+ if (target.getId() == R.id.series_image) {
+ DialogUtil.createMessage(getActivity(), data.getSecond().getTitle(), data.getSecond().getDescription() + "
" + copyright,
+ R.string.Watch, R.string.Dismiss, R.string.action_search, (dialog, which) -> {
+ Intent intent;
+ switch (which) {
+ case POSITIVE:
+ if (data.getSecond().getLink() != null) {
+ intent = new Intent(Intent.ACTION_VIEW, Uri.parse(data.getSecond().getLink()));
+ startActivity(intent);
+ } else
+ NotifyUtil.INSTANCE.makeText(getActivity(), R.string.text_premium_show, Toast.LENGTH_SHORT).show();
+ break;
+ case NEUTRAL:
+ if (getActivity() != null) {
+ intent = new Intent(getActivity(), SearchActivity.class);
+ intent.putExtra(KeyUtil.arg_search, EpisodeUtil.INSTANCE.getActualTile(data.getSecond().getTitle()));
+ getActivity().startActivity(intent);
+ }
+ break;
+ }
+ });
}
}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/glide/GlideAppModule.kt b/app/src/main/java/com/mxt/anitrend/base/custom/glide/GlideAppModule.kt
index a953a5237..261aac5b7 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/glide/GlideAppModule.kt
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/glide/GlideAppModule.kt
@@ -12,6 +12,7 @@ import com.bumptech.glide.load.engine.cache.MemorySizeCalculator
import com.bumptech.glide.module.AppGlideModule
import com.bumptech.glide.request.RequestOptions
import com.mxt.anitrend.R
+import com.mxt.anitrend.extension.getCompatDrawable
import com.mxt.anitrend.util.CompatUtil
import com.mxt.anitrend.util.KeyUtil
@@ -55,7 +56,7 @@ class GlideAppModule : AppGlideModule() {
.format(if (isLowRamDevice) DecodeFormat.PREFER_RGB_565 else DecodeFormat.PREFER_ARGB_8888)
.timeout(KeyUtil.GLIDE_REQUEST_TIMEOUT)
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
- .error(CompatUtil.getDrawable(context, R.drawable.ic_emoji_sweat))
+ .error(context.getCompatDrawable(R.drawable.ic_emoji_sweat))
builder.setDefaultRequestOptions(options)
}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/pager/BaseStatePageAdapter.java b/app/src/main/java/com/mxt/anitrend/base/custom/pager/BaseStatePageAdapter.java
index b957d5e3e..5dd07776d 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/pager/BaseStatePageAdapter.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/pager/BaseStatePageAdapter.java
@@ -2,10 +2,11 @@
import android.content.Context;
import android.os.Bundle;
-import android.support.annotation.ArrayRes;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentManager;
-import android.support.v4.app.FragmentStatePagerAdapter;
+
+import androidx.annotation.ArrayRes;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentManager;
+import androidx.fragment.app.FragmentStatePagerAdapter;
import java.util.Locale;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/presenter/CommonPresenter.java b/app/src/main/java/com/mxt/anitrend/base/custom/presenter/CommonPresenter.java
index 3f7028ddf..07d920076 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/presenter/CommonPresenter.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/presenter/CommonPresenter.java
@@ -8,7 +8,7 @@
import com.mxt.anitrend.base.interfaces.dao.BoxQuery;
import com.mxt.anitrend.base.interfaces.event.LifecycleListener;
import com.mxt.anitrend.data.DatabaseHelper;
-import com.mxt.anitrend.util.ApplicationPref;
+import com.mxt.anitrend.util.Settings;
import org.greenrobot.eventbus.EventBus;
@@ -23,7 +23,7 @@ public abstract class CommonPresenter extends RecyclerScrollListener implements
private Bundle bundle;
private Context context;
private BoxQuery databaseHelper;
- private ApplicationPref applicationPref;
+ private Settings settings;
public CommonPresenter(Context context) {
this.context = context;
@@ -45,7 +45,7 @@ public void setParams(Bundle bundle) {
public BoxQuery getDatabase() {
if(databaseHelper == null)
- databaseHelper = new DatabaseHelper(context);
+ databaseHelper = new DatabaseHelper();
return databaseHelper;
}
@@ -55,7 +55,7 @@ public BoxQuery getDatabase() {
@Override
public void onPause(SharedPreferences.OnSharedPreferenceChangeListener changeListener) {
if(changeListener != null)
- getApplicationPref().getSharedPreferences()
+ getSettings().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(changeListener);
}
@@ -65,7 +65,7 @@ public void onPause(SharedPreferences.OnSharedPreferenceChangeListener changeLis
@Override
public void onResume(SharedPreferences.OnSharedPreferenceChangeListener changeListener) {
if(changeListener != null)
- getApplicationPref().getSharedPreferences()
+ getSettings().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(changeListener);
}
@@ -78,10 +78,10 @@ public void onDestroy() {
bundle = null;
}
- public ApplicationPref getApplicationPref() {
- if(applicationPref == null)
- applicationPref = new ApplicationPref(context);
- return applicationPref;
+ public Settings getSettings() {
+ if(settings == null)
+ settings = new Settings(context);
+ return settings;
}
/**
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/recycler/RecyclerScrollListener.java b/app/src/main/java/com/mxt/anitrend/base/custom/recycler/RecyclerScrollListener.java
index 035342b0b..a96bc311b 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/recycler/RecyclerScrollListener.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/recycler/RecyclerScrollListener.java
@@ -1,9 +1,9 @@
package com.mxt.anitrend.base.custom.recycler;
-import android.support.annotation.Nullable;
-import android.support.v7.widget.GridLayoutManager;
-import android.support.v7.widget.RecyclerView;
-import android.support.v7.widget.StaggeredGridLayoutManager;
+import androidx.annotation.Nullable;
+import androidx.recyclerview.widget.GridLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import com.mxt.anitrend.base.interfaces.event.RecyclerLoadListener;
import com.mxt.anitrend.model.entity.container.attribute.PageInfo;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/recycler/RecyclerViewAdapter.java b/app/src/main/java/com/mxt/anitrend/base/custom/recycler/RecyclerViewAdapter.java
index 8b883f0a5..82e648e9e 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/recycler/RecyclerViewAdapter.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/recycler/RecyclerViewAdapter.java
@@ -2,14 +2,15 @@
import android.animation.Animator;
import android.content.Context;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.support.v7.widget.GridLayoutManager;
-import android.support.v7.widget.RecyclerView;
-import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.ViewGroup;
import android.widget.Filterable;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.recyclerview.widget.GridLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.recyclerview.widget.StaggeredGridLayoutManager;
+
import com.mxt.anitrend.base.custom.animation.ScaleAnimation;
import com.mxt.anitrend.base.custom.animation.SlideInAnimation;
import com.mxt.anitrend.base.interfaces.base.BaseAnimation;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/recycler/RecyclerViewHolder.java b/app/src/main/java/com/mxt/anitrend/base/custom/recycler/RecyclerViewHolder.java
index 2985b26ee..115b43352 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/recycler/RecyclerViewHolder.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/recycler/RecyclerViewHolder.java
@@ -1,10 +1,11 @@
package com.mxt.anitrend.base.custom.recycler;
import android.content.Context;
-import android.support.annotation.NonNull;
-import android.support.v7.widget.RecyclerView;
import android.view.View;
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.RecyclerView;
+
import com.annimon.stream.IntPair;
import com.mxt.anitrend.base.interfaces.event.ItemClickListener;
import com.mxt.anitrend.util.ActionModeUtil;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/recycler/StatefulRecyclerView.java b/app/src/main/java/com/mxt/anitrend/base/custom/recycler/StatefulRecyclerView.java
index 31494523d..e514f03b1 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/recycler/StatefulRecyclerView.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/recycler/StatefulRecyclerView.java
@@ -1,10 +1,11 @@
package com.mxt.anitrend.base.custom.recycler;
import android.content.Context;
-import android.support.annotation.Nullable;
-import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
+import androidx.annotation.Nullable;
+import androidx.recyclerview.widget.RecyclerView;
+
import com.mxt.anitrend.base.interfaces.view.CustomView;
/**
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/sheet/BottomSheetBase.java b/app/src/main/java/com/mxt/anitrend/base/custom/sheet/BottomSheetBase.java
index 6435518aa..2f9481f2c 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/sheet/BottomSheetBase.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/sheet/BottomSheetBase.java
@@ -2,16 +2,16 @@
import android.app.Dialog;
import android.os.Bundle;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.support.annotation.StringRes;
-import android.support.design.widget.BottomSheetBehavior;
-import android.support.design.widget.BottomSheetDialogFragment;
-import android.support.design.widget.CoordinatorLayout;
-import android.support.v7.widget.AppCompatImageView;
-import android.util.Log;
import android.view.View;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.annotation.StringRes;
+import androidx.appcompat.widget.AppCompatImageView;
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
+
+import com.google.android.material.bottomsheet.BottomSheetBehavior;
+import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.miguelcatalan.materialsearchview.MaterialSearchView;
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.custom.view.text.SingleLineTextView;
@@ -27,6 +27,7 @@
import butterknife.BindView;
import butterknife.Unbinder;
+import timber.log.Timber;
/**
* Created by max on 2017/11/02.
@@ -230,11 +231,11 @@ public BottomSheetBuilder setNegativeText(@StringRes int negativeText) {
@Override
public void showError(String error) {
- Log.e(TAG, error);
+ Timber.tag(TAG).e(error);
}
@Override
public void showEmpty(String message) {
- Log.d(TAG, message);
+ Timber.tag(TAG).d(message);
}
}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/sheet/BottomSheetGiphyList.java b/app/src/main/java/com/mxt/anitrend/base/custom/sheet/BottomSheetGiphyList.java
index 0b993f1b5..b7615bbf9 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/sheet/BottomSheetGiphyList.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/sheet/BottomSheetGiphyList.java
@@ -1,16 +1,17 @@
package com.mxt.anitrend.base.custom.sheet;
import android.app.Activity;
-import android.arch.lifecycle.Observer;
-import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.lifecycle.Observer;
+import androidx.lifecycle.ViewModelProviders;
+import androidx.recyclerview.widget.StaggeredGridLayoutManager;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.custom.recycler.RecyclerViewAdapter;
import com.mxt.anitrend.base.custom.recycler.StatefulRecyclerView;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/sheet/BottomSheetList.java b/app/src/main/java/com/mxt/anitrend/base/custom/sheet/BottomSheetList.java
index 8d2c62e52..d53b2bdc2 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/sheet/BottomSheetList.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/sheet/BottomSheetList.java
@@ -1,14 +1,14 @@
package com.mxt.anitrend.base.custom.sheet;
-import android.arch.lifecycle.Observer;
-import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.os.Parcelable;
-import android.support.annotation.Nullable;
-import android.support.v7.widget.StaggeredGridLayoutManager;
-import android.util.Log;
import android.view.View;
+import androidx.annotation.Nullable;
+import androidx.lifecycle.Observer;
+import androidx.lifecycle.ViewModelProviders;
+import androidx.recyclerview.widget.StaggeredGridLayoutManager;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.custom.recycler.RecyclerViewAdapter;
import com.mxt.anitrend.base.custom.recycler.StatefulRecyclerView;
@@ -22,6 +22,7 @@
import java.util.List;
import butterknife.BindView;
+import timber.log.Timber;
public abstract class BottomSheetList extends BottomSheetBase> implements ItemClickListener, Observer>, RecyclerLoadListener, CustomSwipeRefreshLayout.OnRefreshAndLoadListener {
@@ -152,7 +153,7 @@ public void onLoadMore() {
*/
@Override
public void onChanged(@Nullable List data) {
- Log.d(TAG, "onChanged(@Nullable List data) invoked");
+ Timber.tag(TAG).d("onChanged(@Nullable List data) invoked");
}
@Override
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/container/CardViewBase.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/container/CardViewBase.java
index e340f92d4..68b48d6cd 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/container/CardViewBase.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/container/CardViewBase.java
@@ -1,11 +1,12 @@
package com.mxt.anitrend.base.custom.view.container;
import android.content.Context;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.support.v7.widget.CardView;
import android.util.AttributeSet;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.cardview.widget.CardView;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.interfaces.view.CustomView;
import com.mxt.anitrend.util.CompatUtil;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/container/CustomSwipeRefreshLayout.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/container/CustomSwipeRefreshLayout.java
index 6d83e8729..aef158da4 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/container/CustomSwipeRefreshLayout.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/container/CustomSwipeRefreshLayout.java
@@ -3,16 +3,6 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
-import android.support.annotation.ColorInt;
-import android.support.annotation.ColorRes;
-import android.support.annotation.NonNull;
-import android.support.v4.content.ContextCompat;
-import android.support.v4.view.MotionEventCompat;
-import android.support.v4.view.NestedScrollingChild;
-import android.support.v4.view.NestedScrollingChildHelper;
-import android.support.v4.view.NestedScrollingParent;
-import android.support.v4.view.NestedScrollingParentHelper;
-import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
@@ -24,6 +14,18 @@
import android.view.animation.Transformation;
import android.widget.AbsListView;
+import androidx.annotation.ColorInt;
+import androidx.annotation.ColorRes;
+import androidx.annotation.NonNull;
+import androidx.core.content.ContextCompat;
+import androidx.core.view.MotionEventCompat;
+import androidx.core.view.NestedScrollingChild;
+import androidx.core.view.NestedScrollingChildHelper;
+import androidx.core.view.NestedScrollingParent;
+import androidx.core.view.NestedScrollingParentHelper;
+import androidx.core.view.ViewCompat;
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
+
import com.mxt.anitrend.base.custom.view.drawable.MaterialProgressDrawable;
import com.mxt.anitrend.base.custom.view.image.CircleImageView;
@@ -31,7 +33,7 @@
* Created by max on 2017/12/05.
* Both way swipe refresh layout.
*
- * This is a more powerful {@link android.support.v4.widget.SwipeRefreshLayout}, it can swipe
+ * This is a more powerful {@link SwipeRefreshLayout}, it can swipe
* to refresh and load.
*
* @author wangdaye MySplash
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/container/LoginCardView.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/container/LoginCardView.java
index 7bf8a2309..34cfea204 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/container/LoginCardView.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/container/LoginCardView.java
@@ -1,14 +1,12 @@
package com.mxt.anitrend.base.custom.view.container;
import android.content.Context;
-import android.os.Build;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.support.v7.widget.LinearLayoutCompat;
import android.util.AttributeSet;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
import com.mxt.anitrend.R;
-import com.mxt.anitrend.util.CompatUtil;
public class LoginCardView extends CardViewBase {
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/container/NotificationCardView.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/container/NotificationCardView.java
index de05ec630..6a8918a63 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/container/NotificationCardView.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/container/NotificationCardView.java
@@ -1,10 +1,11 @@
package com.mxt.anitrend.base.custom.view.container;
import android.content.Context;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
import android.util.AttributeSet;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
public class NotificationCardView extends CardViewBase {
public NotificationCardView(@NonNull Context context) {
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/drawable/MaterialProgressDrawable.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/drawable/MaterialProgressDrawable.java
index 8997b0185..69a5cd472 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/drawable/MaterialProgressDrawable.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/drawable/MaterialProgressDrawable.java
@@ -12,9 +12,6 @@
import android.graphics.RectF;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
-import android.support.annotation.IntDef;
-import android.support.annotation.NonNull;
-import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.animation.Animation;
@@ -22,6 +19,10 @@
import android.view.animation.LinearInterpolator;
import android.view.animation.Transformation;
+import androidx.annotation.IntDef;
+import androidx.annotation.NonNull;
+import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
+
import com.mxt.anitrend.base.custom.view.container.CustomSwipeRefreshLayout;
import java.lang.annotation.Retention;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/editor/ComposerWidget.kt b/app/src/main/java/com/mxt/anitrend/base/custom/view/editor/ComposerWidget.kt
index 8cd05af34..705b1749d 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/editor/ComposerWidget.kt
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/editor/ComposerWidget.kt
@@ -1,18 +1,15 @@
package com.mxt.anitrend.base.custom.view.editor
import android.annotation.SuppressLint
-import android.arch.lifecycle.Lifecycle
import android.content.Context
import android.os.Build
-import android.support.annotation.RequiresApi
-import android.text.Editable
-import android.text.TextUtils
import android.util.AttributeSet
import android.view.View
import android.widget.EditText
import android.widget.FrameLayout
import android.widget.Toast
-
+import androidx.annotation.RequiresApi
+import androidx.lifecycle.Lifecycle
import com.annimon.stream.IntPair
import com.mxt.anitrend.R
import com.mxt.anitrend.base.custom.consumer.BaseConsumer
@@ -20,31 +17,25 @@ import com.mxt.anitrend.base.interfaces.event.ItemClickListener
import com.mxt.anitrend.base.interfaces.event.RetroCallback
import com.mxt.anitrend.base.interfaces.view.CustomView
import com.mxt.anitrend.databinding.WidgetComposerBinding
+import com.mxt.anitrend.extension.getLayoutInflater
import com.mxt.anitrend.model.entity.anilist.FeedList
import com.mxt.anitrend.model.entity.anilist.FeedReply
import com.mxt.anitrend.model.entity.base.UserBase
-import com.mxt.anitrend.model.entity.container.request.QueryContainerBuilder
-import com.mxt.anitrend.model.entity.giphy.Gif
import com.mxt.anitrend.model.entity.giphy.Giphy
import com.mxt.anitrend.presenter.widget.WidgetPresenter
-import com.mxt.anitrend.util.CompatUtil
-import com.mxt.anitrend.util.ErrorUtil
-import com.mxt.anitrend.util.GraphUtil
import com.mxt.anitrend.util.KeyUtil
-import com.mxt.anitrend.util.MarkDownUtil
import com.mxt.anitrend.util.NotifyUtil
-
+import com.mxt.anitrend.util.graphql.GraphUtil
+import com.mxt.anitrend.util.graphql.apiError
+import com.mxt.anitrend.util.markdown.MarkDownUtil
+import io.wax911.emojify.parser.EmojiParser
+import okhttp3.ResponseBody
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
-
-import java.util.Locale
-
-import io.wax911.emojify.EmojiManager
-import io.wax911.emojify.parser.EmojiParser
-import okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.Response
+import java.util.*
/**
* Created by max on 2017/12/02.
@@ -55,7 +46,7 @@ class ComposerWidget : FrameLayout, CustomView, View.OnClickListener, RetroCallb
private val binding by lazy {
WidgetComposerBinding.inflate(
- CompatUtil.getLayoutInflater(context),
+ getLayoutInflater(),
this, true
)
}
@@ -223,7 +214,7 @@ class ComposerWidget : FrameLayout, CustomView, View.OnClickListener, RetroCallb
if (lifecycle?.currentState?.isAtLeast(Lifecycle.State.RESUMED) == true) {
resetFlipperState()
if (response.isSuccessful) {
- binding.comment.text.clear()
+ binding.comment.text?.clear()
when (requestType) {
KeyUtil.MUT_SAVE_TEXT_FEED -> if (feedList != null)
presenter.notifyAllListeners(BaseConsumer(requestType, feedList), false)
@@ -239,7 +230,7 @@ class ComposerWidget : FrameLayout, CustomView, View.OnClickListener, RetroCallb
presenter.notifyAllListeners(BaseConsumer(requestType), false)
}
} else
- NotifyUtil.makeText(context, ErrorUtil.getError(response), Toast.LENGTH_SHORT).show()
+ NotifyUtil.makeText(context, response.apiError(), Toast.LENGTH_SHORT).show()
presenter.onDestroy()
}
}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/editor/MarkdownInputEditor.kt b/app/src/main/java/com/mxt/anitrend/base/custom/view/editor/MarkdownInputEditor.kt
index 1cb067736..852f8f576 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/editor/MarkdownInputEditor.kt
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/editor/MarkdownInputEditor.kt
@@ -4,12 +4,6 @@ import android.content.Context
import android.graphics.Typeface
import android.os.Build
import android.os.Bundle
-import android.support.annotation.IdRes
-import android.support.design.widget.TextInputEditText
-import android.support.v13.view.inputmethod.EditorInfoCompat
-import android.support.v13.view.inputmethod.InputConnectionCompat
-import android.support.v13.view.inputmethod.InputContentInfoCompat
-import android.support.v4.content.ContextCompat
import android.text.InputFilter
import android.text.Spanned
import android.text.TextUtils
@@ -19,25 +13,20 @@ import android.view.Menu
import android.view.MenuItem
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputConnection
-
+import androidx.annotation.IdRes
+import androidx.core.content.ContextCompat
+import androidx.core.view.inputmethod.EditorInfoCompat
+import androidx.core.view.inputmethod.InputConnectionCompat
+import androidx.core.view.inputmethod.InputContentInfoCompat
+import com.google.android.material.textfield.TextInputEditText
import com.mxt.anitrend.R
import com.mxt.anitrend.base.interfaces.view.CustomView
import com.mxt.anitrend.util.CompatUtil
import com.mxt.anitrend.util.KeyUtil
-import com.mxt.anitrend.util.MarkDownUtil
-
+import com.mxt.anitrend.util.KeyUtil.*
+import com.mxt.anitrend.util.markdown.MarkDownUtil
import io.wax911.emojify.parser.EmojiParser
-import com.mxt.anitrend.util.KeyUtil.MD_BOLD
-import com.mxt.anitrend.util.KeyUtil.MD_BULLET
-import com.mxt.anitrend.util.KeyUtil.MD_CENTER_ALIGN
-import com.mxt.anitrend.util.KeyUtil.MD_CODE
-import com.mxt.anitrend.util.KeyUtil.MD_HEADING
-import com.mxt.anitrend.util.KeyUtil.MD_ITALIC
-import com.mxt.anitrend.util.KeyUtil.MD_NUMBER
-import com.mxt.anitrend.util.KeyUtil.MD_QUOTE
-import com.mxt.anitrend.util.KeyUtil.MD_STRIKE
-
/**
* Created by max on 2017/08/14.
* Markdown input editor
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/image/AppCompatTintImageView.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/image/AppCompatTintImageView.java
index b0d2e92d3..2f245068c 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/image/AppCompatTintImageView.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/image/AppCompatTintImageView.java
@@ -1,13 +1,14 @@
package com.mxt.anitrend.base.custom.view.image;
import android.content.Context;
-import android.databinding.BindingAdapter;
-import android.support.annotation.AttrRes;
-import android.support.annotation.ColorRes;
-import android.support.annotation.DrawableRes;
-import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;
+import androidx.annotation.AttrRes;
+import androidx.annotation.ColorRes;
+import androidx.annotation.DrawableRes;
+import androidx.appcompat.widget.AppCompatImageView;
+import androidx.databinding.BindingAdapter;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.interfaces.view.CustomView;
import com.mxt.anitrend.util.CompatUtil;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/image/AspectImageView.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/image/AspectImageView.java
index f9ac4aabf..63e6cbea0 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/image/AspectImageView.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/image/AspectImageView.java
@@ -1,10 +1,11 @@
package com.mxt.anitrend.base.custom.view.image;
import android.content.Context;
-import android.databinding.BindingAdapter;
import android.graphics.Point;
import android.util.AttributeSet;
+import androidx.databinding.BindingAdapter;
+
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
@@ -21,7 +22,7 @@
* or set to wrap content to automatically get the view width at runtime
*/
-public class AspectImageView extends android.support.v7.widget.AppCompatImageView implements CustomView {
+public class AspectImageView extends androidx.appcompat.widget.AppCompatImageView implements CustomView {
private int spanSize;
private int defaultMargin;
@@ -81,7 +82,11 @@ public static void setImage(AspectImageView view, String url) {
@BindingAdapter({"imageUrl"})
public static void setImage(AspectImageView view, ImageBase imageBase) {
- if(imageBase != null)
- setImage(view, imageBase.getLarge());
+ if(imageBase != null) {
+ if (imageBase.getExtraLarge() != null)
+ setImage(view, imageBase.getExtraLarge());
+ else
+ setImage(view, imageBase.getLarge());
+ }
}
}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/image/AvatarImageView.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/image/AvatarImageView.java
deleted file mode 100644
index a1050e0b2..000000000
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/image/AvatarImageView.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package com.mxt.anitrend.base.custom.view.image;
-
-import android.content.Context;
-import android.databinding.BindingAdapter;
-import android.support.v7.widget.AppCompatImageView;
-import android.util.AttributeSet;
-
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
-import com.bumptech.glide.request.RequestOptions;
-import com.mxt.anitrend.R;
-import com.mxt.anitrend.base.interfaces.view.CustomView;
-import com.mxt.anitrend.model.entity.anilist.meta.ImageBase;
-
-/**
- * Created by max on 2017/10/29.
- * Circle image view
- */
-
-public class AvatarImageView extends AppCompatImageView implements CustomView {
-
- public AvatarImageView(Context context) {
- super(context);
- onInit();
- }
-
- public AvatarImageView(Context context, AttributeSet attrs) {
- super(context, attrs);
- onInit();
- }
-
- public AvatarImageView(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- onInit();
- }
-
- /**
- * Optionally included when constructing custom views
- */
- @Override
- public void onInit() {
-
- }
-
- /**
- * Clean up any resources that won't be needed
- */
- @Override
- public void onViewRecycled() {
-
- }
-
- @BindingAdapter({"avatarUrl"})
- public static void setImage(AvatarImageView view, String url) {
- Glide.with(view.getContext()).load(url).apply(RequestOptions.centerCropTransform())
- .apply(RequestOptions.placeholderOf(R.drawable.avatar_placeholder))
- .transition(DrawableTransitionOptions.withCrossFade(150))
- .apply(RequestOptions.circleCropTransform())
- .into(view);
- }
-
- @BindingAdapter({"avatarUrl"})
- public static void setImage(AvatarImageView view, ImageBase imageBase) {
- setImage(view, imageBase.getLarge());
- }
-}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/image/AvatarImageView.kt b/app/src/main/java/com/mxt/anitrend/base/custom/view/image/AvatarImageView.kt
new file mode 100644
index 000000000..5794dd51d
--- /dev/null
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/image/AvatarImageView.kt
@@ -0,0 +1,41 @@
+package com.mxt.anitrend.base.custom.view.image
+
+import android.content.Context
+import android.util.AttributeSet
+import androidx.appcompat.widget.AppCompatImageView
+import com.bumptech.glide.Glide
+import com.mxt.anitrend.base.interfaces.view.CustomView
+
+/**
+ * Created by max on 2017/10/29.
+ * Circle image view
+ */
+
+class AvatarImageView : AppCompatImageView, CustomView {
+
+ constructor(context: Context) : super(context) {
+ onInit()
+ }
+
+ constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
+ onInit()
+ }
+
+ constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
+ onInit()
+ }
+
+ /**
+ * Optionally included when constructing custom views
+ */
+ override fun onInit() {
+
+ }
+
+ /**
+ * Clean up any resources that won't be needed
+ */
+ override fun onViewRecycled() {
+ Glide.with(context).clear(this)
+ }
+}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/image/AvatarIndicatorView.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/image/AvatarIndicatorView.java
deleted file mode 100644
index 6cb4708ea..000000000
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/image/AvatarIndicatorView.java
+++ /dev/null
@@ -1,142 +0,0 @@
-package com.mxt.anitrend.base.custom.view.image;
-
-import android.content.Context;
-import android.content.Intent;
-import android.util.AttributeSet;
-import android.view.View;
-import android.widget.FrameLayout;
-
-import com.mxt.anitrend.R;
-import com.mxt.anitrend.base.custom.consumer.BaseConsumer;
-import com.mxt.anitrend.base.interfaces.view.CustomView;
-import com.mxt.anitrend.databinding.WidgetAvatarIndicatorBinding;
-import com.mxt.anitrend.model.entity.anilist.User;
-import com.mxt.anitrend.presenter.base.BasePresenter;
-import com.mxt.anitrend.presenter.widget.WidgetPresenter;
-import com.mxt.anitrend.util.CompatUtil;
-import com.mxt.anitrend.util.DateUtil;
-import com.mxt.anitrend.util.KeyUtil;
-import com.mxt.anitrend.view.activity.detail.NotificationActivity;
-import com.mxt.anitrend.view.activity.detail.ProfileActivity;
-import com.mxt.anitrend.view.activity.index.LoginActivity;
-
-import org.greenrobot.eventbus.EventBus;
-import org.greenrobot.eventbus.Subscribe;
-import org.greenrobot.eventbus.ThreadMode;
-
-/**
- * Created by max on 2017/11/30.
- * avatar image view which will be capable of displaying
- * current notification count.
- */
-
-public class AvatarIndicatorView extends FrameLayout implements CustomView, View.OnClickListener, BaseConsumer.onRequestModelChange {
-
- private WidgetAvatarIndicatorBinding binding;
- private BasePresenter presenter;
- private User currentUser;
- private long mLastSynced;
-
- public AvatarIndicatorView(Context context) {
- super(context);
- onInit();
- }
-
- public AvatarIndicatorView(Context context, AttributeSet attrs) {
- super(context, attrs);
- onInit();
- }
-
- public AvatarIndicatorView(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- onInit();
- }
-
- @Override
- public void onInit() {
- presenter = new WidgetPresenter<>(getContext());
- binding = WidgetAvatarIndicatorBinding.inflate(CompatUtil.INSTANCE.getLayoutInflater(getContext()), this, true);
- binding.setOnClickListener(this);
- checkLastSyncTime();
- }
-
- private void checkLastSyncTime() {
- if(presenter.getApplicationPref().isAuthenticated()) {
- if((currentUser = presenter.getDatabase().getCurrentUser()) != null) {
- AvatarImageView.setImage(binding.userAvatar, currentUser.getAvatar());
- if (currentUser.getUnreadNotificationCount() > 0) {
- binding.notificationCount.setText(String.valueOf(currentUser.getUnreadNotificationCount()));
- showNotificationWidget();
- } else
- hideNotificationCountWidget();
- } else
- hideNotificationCountWidget();
- }
- }
-
- @Override
- public void onViewRecycled() {
- if(presenter != null)
- presenter.onDestroy();
- }
-
- @Override @Subscribe(threadMode = ThreadMode.MAIN_ORDERED)
- public void onModelChanged(BaseConsumer consumer) {
- if(consumer.getRequestMode() == KeyUtil.USER_CURRENT_REQ) {
- if (DateUtil.INSTANCE.timeDifferenceSatisfied(KeyUtil.TIME_UNIT_MINUTES, mLastSynced, 15))
- mLastSynced = System.currentTimeMillis();
- checkLastSyncTime();
- }
- }
-
- private void showNotificationWidget() {
- binding.notificationCount.setVisibility(VISIBLE);
- binding.container.setVisibility(VISIBLE);
- binding.executePendingBindings();
- invalidate();
- }
-
- private void hideNotificationCountWidget() {
- binding.notificationCount.setVisibility(GONE);
- binding.container.setVisibility(GONE);
- binding.executePendingBindings();
- invalidate();
- }
-
- @Override
- public void onClick(View view) {
- if(presenter.getApplicationPref().isAuthenticated() && currentUser != null) {
- if (view.getId() == R.id.user_avatar) {
- Intent intent;
- if (currentUser.getUnreadNotificationCount() > 0) {
- intent = new Intent(getContext(), NotificationActivity.class);
- hideNotificationCountWidget();
- }
- else {
- intent = new Intent(getContext(), ProfileActivity.class);
- intent.putExtra(KeyUtil.arg_userName, currentUser.getName());
- }
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- getContext().startActivity(intent);
- }
- } else {
- Intent intent = new Intent(getContext(), LoginActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- getContext().startActivity(intent);
- }
- }
-
- @Override
- protected void onAttachedToWindow() {
- super.onAttachedToWindow();
- if(!EventBus.getDefault().isRegistered(this))
- EventBus.getDefault().register(this);
- }
-
- @Override
- protected void onDetachedFromWindow() {
- if(EventBus.getDefault().isRegistered(this))
- EventBus.getDefault().unregister(this);
- super.onDetachedFromWindow();
- }
-}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/image/AvatarIndicatorView.kt b/app/src/main/java/com/mxt/anitrend/base/custom/view/image/AvatarIndicatorView.kt
new file mode 100644
index 000000000..85c9ebfbf
--- /dev/null
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/image/AvatarIndicatorView.kt
@@ -0,0 +1,127 @@
+package com.mxt.anitrend.base.custom.view.image
+
+import android.content.Context
+import android.content.Intent
+import android.util.AttributeSet
+import android.view.View
+import android.widget.FrameLayout
+import com.mxt.anitrend.R
+import com.mxt.anitrend.base.custom.consumer.BaseConsumer
+import com.mxt.anitrend.base.interfaces.view.CustomView
+import com.mxt.anitrend.binding.setImage
+import com.mxt.anitrend.databinding.WidgetAvatarIndicatorBinding
+import com.mxt.anitrend.extension.getLayoutInflater
+import com.mxt.anitrend.model.entity.anilist.User
+import com.mxt.anitrend.presenter.widget.WidgetPresenter
+import com.mxt.anitrend.util.KeyUtil
+import com.mxt.anitrend.util.date.DateUtil
+import com.mxt.anitrend.view.activity.detail.NotificationActivity
+import com.mxt.anitrend.view.activity.detail.ProfileActivity
+import com.mxt.anitrend.view.activity.index.LoginActivity
+import org.greenrobot.eventbus.EventBus
+import org.greenrobot.eventbus.Subscribe
+import org.greenrobot.eventbus.ThreadMode
+import org.koin.core.KoinComponent
+import org.koin.core.inject
+
+/**
+ * Created by max on 2017/11/30.
+ * avatar image view which will be capable of displaying
+ * current notification count.
+ */
+
+class AvatarIndicatorView : FrameLayout, CustomView, View.OnClickListener, BaseConsumer.onRequestModelChange, KoinComponent {
+
+ constructor(context: Context) :
+ super(context) { onInit() }
+
+ constructor(context: Context, attrs: AttributeSet) :
+ super(context, attrs) { onInit() }
+
+ constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) :
+ super(context, attrs, defStyleAttr) { onInit() }
+
+ private val presenter: WidgetPresenter by inject()
+
+ private val currentUser: User?
+ get() = presenter.database?.currentUser
+
+ private lateinit var binding: WidgetAvatarIndicatorBinding
+ private var mLastSynced: Long = 0
+
+ override fun onInit() {
+ binding = WidgetAvatarIndicatorBinding.inflate(context.getLayoutInflater(), this, true)
+ binding.onClickListener = this
+ checkLastSyncTime()
+ }
+
+ private fun checkLastSyncTime() {
+ if (presenter.settings?.isAuthenticated == true) {
+ if (currentUser != null) {
+ binding.userAvatar.setImage(currentUser?.avatar)
+ if ((currentUser?.unreadNotificationCount ?: 0) > 0) {
+ binding.notificationCount.text = currentUser?.unreadNotificationCount.toString()
+ showNotificationWidget()
+ } else
+ hideNotificationCountWidget()
+ } else
+ hideNotificationCountWidget()
+ }
+ }
+
+ override fun onViewRecycled() {
+ presenter.onDestroy()
+ }
+
+ @Subscribe(threadMode = ThreadMode.MAIN_ORDERED)
+ override fun onModelChanged(consumer: BaseConsumer) {
+ if (consumer.requestMode == KeyUtil.USER_CURRENT_REQ) {
+ if (DateUtil.timeDifferenceSatisfied(KeyUtil.TIME_UNIT_MINUTES, mLastSynced, 15))
+ mLastSynced = System.currentTimeMillis()
+ checkLastSyncTime()
+ }
+ }
+
+ private fun showNotificationWidget() {
+ binding.notificationCount.visibility = View.VISIBLE
+ binding.container.visibility = View.VISIBLE
+ }
+
+ private fun hideNotificationCountWidget() {
+ binding.notificationCount.visibility = View.GONE
+ binding.container.visibility = View.GONE
+ }
+
+ override fun onClick(view: View) {
+ if (presenter.settings.isAuthenticated && currentUser != null) {
+ if (view.id == R.id.user_avatar) {
+ val intent: Intent
+ if ((currentUser?.unreadNotificationCount ?: 0) > 0) {
+ intent = Intent(context, NotificationActivity::class.java)
+ hideNotificationCountWidget()
+ } else {
+ intent = Intent(context, ProfileActivity::class.java)
+ intent.putExtra(KeyUtil.arg_userName, currentUser?.name)
+ }
+ intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
+ context.startActivity(intent)
+ }
+ } else {
+ val intent = Intent(context, LoginActivity::class.java)
+ intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
+ context.startActivity(intent)
+ }
+ }
+
+ override fun onAttachedToWindow() {
+ super.onAttachedToWindow()
+ if (!EventBus.getDefault().isRegistered(this))
+ EventBus.getDefault().register(this)
+ }
+
+ override fun onDetachedFromWindow() {
+ if (EventBus.getDefault().isRegistered(this))
+ EventBus.getDefault().unregister(this)
+ super.onDetachedFromWindow()
+ }
+}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/image/BrandImageView.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/image/BrandImageView.java
index 8d76c2cf1..6664fc76d 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/image/BrandImageView.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/image/BrandImageView.java
@@ -14,13 +14,14 @@
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
-import android.support.annotation.NonNull;
-import android.support.v7.widget.AppCompatImageView;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.Gravity;
+import androidx.annotation.NonNull;
+import androidx.appcompat.widget.AppCompatImageView;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.interfaces.view.CustomView;
import com.mxt.anitrend.util.CompatUtil;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/image/CircleImageView.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/image/CircleImageView.java
index d67b75743..d8abb5255 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/image/CircleImageView.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/image/CircleImageView.java
@@ -8,11 +8,12 @@
import android.graphics.Shader;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
-import android.support.v4.view.ViewCompat;
-import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;
import android.view.animation.Animation;
+import androidx.appcompat.widget.AppCompatImageView;
+import androidx.core.view.ViewCompat;
+
import com.mxt.anitrend.base.custom.view.container.CustomSwipeRefreshLayout;
/**
@@ -63,7 +64,7 @@ public CircleImageView(Context context, int color, final float radius) {
} else {
OvalShape oval = new OvalShadow(mShadowRadius, diameter);
circle = new ShapeDrawable(oval);
- ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, circle.getPaint());
+ setLayerType(LAYER_TYPE_SOFTWARE, circle.getPaint());
circle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset,
KEY_SHADOW_COLOR);
final int padding = mShadowRadius;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/image/HeaderImageView.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/image/HeaderImageView.java
index 7adca64e1..a0964508c 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/image/HeaderImageView.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/image/HeaderImageView.java
@@ -1,10 +1,11 @@
package com.mxt.anitrend.base.custom.view.image;
import android.content.Context;
-import android.databinding.BindingAdapter;
-import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;
+import androidx.appcompat.widget.AppCompatImageView;
+import androidx.databinding.BindingAdapter;
+
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/image/WideImageView.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/image/WideImageView.java
index 3462c8193..1aa04cdc1 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/image/WideImageView.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/image/WideImageView.java
@@ -1,10 +1,11 @@
package com.mxt.anitrend.base.custom.view.image;
import android.content.Context;
-import android.databinding.BindingAdapter;
-import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;
+import androidx.appcompat.widget.AppCompatImageView;
+import androidx.databinding.BindingAdapter;
+
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/AiringTextView.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/AiringTextView.java
index f18810e31..e80c599b2 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/AiringTextView.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/AiringTextView.java
@@ -1,12 +1,13 @@
package com.mxt.anitrend.base.custom.view.text;
import android.content.Context;
-import android.databinding.BindingAdapter;
import android.util.AttributeSet;
+import androidx.databinding.BindingAdapter;
+
import com.mxt.anitrend.model.entity.base.MediaBase;
import com.mxt.anitrend.util.CompatUtil;
-import com.mxt.anitrend.util.DateUtil;
+import com.mxt.anitrend.util.date.DateUtil;
import javax.annotation.Nullable;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/FeedHeadlineTextView.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/FeedHeadlineTextView.java
index d6ad97efb..809dd4dee 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/FeedHeadlineTextView.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/FeedHeadlineTextView.java
@@ -1,12 +1,13 @@
package com.mxt.anitrend.base.custom.view.text;
import android.content.Context;
-import android.databinding.BindingAdapter;
-import android.support.v7.widget.AppCompatTextView;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
+import androidx.appcompat.widget.AppCompatTextView;
+import androidx.databinding.BindingAdapter;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.interfaces.view.CustomView;
import com.mxt.anitrend.model.entity.anilist.FeedList;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/PageIndicator.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/PageIndicator.java
deleted file mode 100644
index 311af41fd..000000000
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/PageIndicator.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package com.mxt.anitrend.base.custom.view.text;
-
-import android.content.Context;
-import android.graphics.Typeface;
-import android.support.annotation.Nullable;
-import android.support.v7.widget.AppCompatTextView;
-import android.util.AttributeSet;
-import android.util.TypedValue;
-
-import com.mxt.anitrend.R;
-import com.mxt.anitrend.base.interfaces.view.CustomView;
-import com.mxt.anitrend.util.CompatUtil;
-
-import java.util.Locale;
-
-/**
- * Created by max on 2017/11/25.
- */
-
-public class PageIndicator extends AppCompatTextView implements CustomView {
-
- private int maximum;
-
- public PageIndicator(Context context) {
- super(context);
- onInit();
- }
-
- public PageIndicator(Context context, @Nullable AttributeSet attrs) {
- super(context, attrs);
- onInit();
- }
-
- public PageIndicator(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- onInit();
- }
-
- /**
- * Optionally included when constructing custom views
- */
- @Override
- public void onInit() {
- int padding = CompatUtil.INSTANCE.dipToPx(8);
-
- setTextColor(CompatUtil.INSTANCE.getColor(getContext(), R.color.colorTextLight));
- setBackground(CompatUtil.INSTANCE.getDrawable(getContext(), R.drawable.bubble_background));
-
- setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
- setPadding(padding, padding, padding, padding);
- setTypeface(Typeface.DEFAULT_BOLD);
- }
-
- public void setMaximum(int maximum) {
- this.maximum = maximum;
- }
-
- public void setCurrentPosition(int index) {
- setText(String.format(Locale.getDefault(), "%d / %d", index, maximum));
- }
-
- /**
- * Clean up any resources that won't be needed
- */
- @Override
- public void onViewRecycled() {
-
- }
-}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/PageIndicator.kt b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/PageIndicator.kt
new file mode 100644
index 000000000..8081e3674
--- /dev/null
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/PageIndicator.kt
@@ -0,0 +1,59 @@
+package com.mxt.anitrend.base.custom.view.text
+
+import android.content.Context
+import android.graphics.Typeface
+import android.util.AttributeSet
+import android.util.TypedValue
+import androidx.appcompat.widget.AppCompatTextView
+import com.mxt.anitrend.R
+import com.mxt.anitrend.base.interfaces.view.CustomView
+import com.mxt.anitrend.extension.getCompatColor
+import com.mxt.anitrend.extension.getCompatDrawable
+import com.mxt.anitrend.util.CompatUtil
+import java.util.*
+
+/**
+ * Created by max on 2017/11/25.
+ */
+
+class PageIndicator : AppCompatTextView, CustomView {
+
+ var maximum: Int = 0
+
+ constructor(context: Context) : super(context) {
+ onInit()
+ }
+
+ constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
+ onInit()
+ }
+
+ constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
+ onInit()
+ }
+
+ /**
+ * Optionally included when constructing custom views
+ */
+ override fun onInit() {
+ val padding = CompatUtil.dipToPx(8f)
+
+ setTextColor(context.getCompatColor(R.color.colorTextLight))
+ background = context.getCompatDrawable(R.drawable.bubble_background)
+
+ setTextSize(TypedValue.COMPLEX_UNIT_SP, 10f)
+ setPadding(padding, padding, padding, padding)
+ typeface = Typeface.DEFAULT_BOLD
+ }
+
+ fun setCurrentPosition(index: Int) {
+ text = String.format(Locale.getDefault(), "%d / %d", index, maximum)
+ }
+
+ /**
+ * Clean up any resources that won't be needed
+ */
+ override fun onViewRecycled() {
+
+ }
+}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/RangeDateTextView.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/RangeDateTextView.java
index 8590bd05d..495da07cc 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/RangeDateTextView.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/RangeDateTextView.java
@@ -1,11 +1,12 @@
package com.mxt.anitrend.base.custom.view.text;
import android.content.Context;
-import android.databinding.BindingAdapter;
import android.util.AttributeSet;
+import androidx.databinding.BindingAdapter;
+
import com.mxt.anitrend.model.entity.anilist.meta.FuzzyDate;
-import com.mxt.anitrend.util.DateUtil;
+import com.mxt.anitrend.util.date.DateUtil;
/**
* Created by max on 2017/10/28.
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/RatingTextView.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/RatingTextView.java
deleted file mode 100644
index 34d3e4355..000000000
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/RatingTextView.java
+++ /dev/null
@@ -1,210 +0,0 @@
-package com.mxt.anitrend.base.custom.view.text;
-
-import android.content.Context;
-import android.databinding.BindingAdapter;
-import android.graphics.drawable.Drawable;
-import android.os.Build;
-import android.support.annotation.ColorRes;
-import android.support.annotation.Nullable;
-import android.support.annotation.RequiresApi;
-import android.util.AttributeSet;
-import android.widget.LinearLayout;
-
-import com.mxt.anitrend.R;
-import com.mxt.anitrend.base.interfaces.view.CustomView;
-import com.mxt.anitrend.databinding.CustomRatingWidgetBinding;
-import com.mxt.anitrend.model.entity.anilist.MediaList;
-import com.mxt.anitrend.model.entity.anilist.meta.MediaListOptions;
-import com.mxt.anitrend.model.entity.base.MediaBase;
-import com.mxt.anitrend.presenter.base.BasePresenter;
-import com.mxt.anitrend.util.CompatUtil;
-import com.mxt.anitrend.util.KeyUtil;
-
-import java.util.Locale;
-
-/**
- * Created by max on 2018/01/27.
- * Special text base rating view
- */
-
-public class RatingTextView extends LinearLayout implements CustomView {
-
- private @Nullable MediaListOptions mediaListOptions;
- private CustomRatingWidgetBinding binding;
-
- public RatingTextView(Context context) {
- super(context);
- onInit();
- }
-
- public RatingTextView(Context context, @Nullable AttributeSet attrs) {
- super(context, attrs);
- onInit();
- }
-
- public RatingTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- onInit();
- }
-
- @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
- public RatingTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
- super(context, attrs, defStyleAttr, defStyleRes);
- onInit();
- }
-
- /**
- * Optionally included when constructing custom views
- */
- @Override
- public void onInit() {
- binding = CustomRatingWidgetBinding.inflate(CompatUtil.INSTANCE.getLayoutInflater(getContext()), this, true);
- BasePresenter basePresenter = new BasePresenter(getContext());
- if(basePresenter.getApplicationPref().isAuthenticated())
- mediaListOptions = basePresenter.getDatabase().getCurrentUser().getMediaListOptions();
- }
-
- private void setFavourState(boolean isFavourite) {
- @ColorRes int colorTint = isFavourite ? R.color.colorStateYellow : R.color.white;
- Drawable drawable = CompatUtil.INSTANCE.getDrawable(getContext(), R.drawable.ic_star_grey_600_24dp, colorTint);
- binding.ratingFavourState.setImageDrawable(drawable);
- }
-
- private void setListStatus(MediaBase mediaBase) {
- if(mediaBase.getMediaListEntry() != null) {
- binding.ratingListStatus.setVisibility(VISIBLE);
- switch (mediaBase.getMediaListEntry().getStatus()) {
- case KeyUtil.CURRENT:
- binding.ratingListStatus.setTintDrawable(R.drawable.ic_remove_red_eye_white_18dp,
- R.color.white);
- break;
- case KeyUtil.PLANNING:
- binding.ratingListStatus.setTintDrawable(R.drawable.ic_bookmark_white_24dp,
- R.color.white);
- break;
- case KeyUtil.COMPLETED:
- binding.ratingListStatus.setTintDrawable(R.drawable.ic_done_all_grey_600_24dp,
- R.color.white);
- break;
- case KeyUtil.DROPPED:
- binding.ratingListStatus.setTintDrawable(R.drawable.ic_delete_red_600_18dp,
- R.color.white);
- break;
- case KeyUtil.PAUSED:
- binding.ratingListStatus.setTintDrawable(R.drawable.ic_pause_white_18dp,
- R.color.white);
- break;
- case KeyUtil.REPEATING:
- binding.ratingListStatus.setTintDrawable(R.drawable.ic_repeat_white_18dp,
- R.color.white);
- break;
- }
- }
- else
- binding.ratingListStatus.setVisibility(GONE);
- }
-
- private void setListStatus() {
- binding.ratingListStatus.setVisibility(GONE);
- }
-
- private void setRating(MediaList mediaList) {
- if(mediaListOptions != null)
- switch (mediaListOptions.getScoreFormat()) {
- case KeyUtil.POINT_10_DECIMAL:
- binding.ratingValue.setText(String.format(Locale.getDefault(),"%.1f", mediaList.getScore()));
- break;
- case KeyUtil.POINT_100:
- case KeyUtil.POINT_10:
- case KeyUtil.POINT_5:
- binding.ratingValue.setText(String.format(Locale.getDefault(),"%d", (int)mediaList.getScore()));
- break;
- case KeyUtil.POINT_3:
- binding.ratingValue.setText("");
- int score = (int)mediaList.getScore();
- switch (score) {
- case 0:
- binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(CompatUtil.INSTANCE.getDrawable(getContext(),
- R.drawable.ic_face_white_18dp), null, null, null);
- break;
- case 1:
- binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(CompatUtil.INSTANCE.getDrawable(getContext(),
- R.drawable.ic_sentiment_dissatisfied_white_18dp), null, null, null);
- break;
- case 2:
- binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(CompatUtil.INSTANCE.getDrawable(getContext(),
- R.drawable.ic_sentiment_neutral_white_18dp), null, null, null);
- break;
- case 3:
- binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(CompatUtil.INSTANCE.getDrawable(getContext(),
- R.drawable.ic_sentiment_satisfied_white_18dp), null, null, null);
- break;
- }
- break;
- }
- else
- binding.ratingValue.setText(String.format(Locale.getDefault(),"%d", (int)mediaList.getScore()));
- }
-
- private void setRating(MediaBase mediaBase) {
- float mediaScoreDefault = (float) mediaBase.getAverageScore() * 5 / 100f;
- if(mediaListOptions != null)
- switch (mediaListOptions.getScoreFormat()) {
- case KeyUtil.POINT_10_DECIMAL:
- mediaScoreDefault = (mediaBase.getAverageScore() / 10f);
- binding.ratingValue.setText(String.format(Locale.getDefault(),"%.1f", mediaScoreDefault));
- break;
- case KeyUtil.POINT_100:
- binding.ratingValue.setText(String.format(Locale.getDefault(),"%d", mediaBase.getAverageScore()));
- break;
- case KeyUtil.POINT_10:
- mediaScoreDefault = (mediaBase.getAverageScore() / 10f);
- binding.ratingValue.setText(String.format(Locale.getDefault(),"%d", (int) mediaScoreDefault));
- break;
- case KeyUtil.POINT_5:
- binding.ratingValue.setText(String.format(Locale.getDefault(),"%d", (int) mediaScoreDefault));
- break;
- case KeyUtil.POINT_3:
- binding.ratingValue.setText("");
- if(mediaBase.getAverageScore() == 0)
- binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(CompatUtil.INSTANCE.getDrawable(getContext(),
- R.drawable.ic_face_white_18dp), null, null, null);
- if(mediaBase.getAverageScore() > 0 && mediaBase.getAverageScore() <= 33)
- binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(CompatUtil.INSTANCE.getDrawable(getContext(),
- R.drawable.ic_sentiment_dissatisfied_white_18dp), null, null, null);
- else if (mediaBase.getAverageScore() >= 34 && mediaBase.getAverageScore() <= 66)
- binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(CompatUtil.INSTANCE.getDrawable(getContext(),
- R.drawable.ic_sentiment_neutral_white_18dp), null, null, null);
- else if (mediaBase.getAverageScore() >= 67 && mediaBase.getAverageScore() <= 100)
- binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(CompatUtil.INSTANCE.getDrawable(getContext(),
- R.drawable.ic_sentiment_satisfied_white_18dp), null, null, null);
- break;
- }
- else
- binding.ratingValue.setText(String.format(Locale.getDefault(),"%d", mediaBase.getAverageScore()));
- }
-
- @BindingAdapter("rating")
- public static void setAverageRating(RatingTextView view, MediaBase mediaBase) {
- //float rating = (float) mediaBase.getAverageScore() * MAX / 100;
- view.setRating(mediaBase);
- view.setListStatus(mediaBase);
- view.setFavourState(mediaBase.isFavourite());
- }
-
- @BindingAdapter("rating")
- public static void setAverageRating(RatingTextView view, MediaList mediaList) {
- //float rating = (float) mediaList.getScore() * MAX / 100;
- view.setListStatus();
- view.setRating(mediaList);
- view.setFavourState(mediaList.getMedia().isFavourite());
- }
-
- /**
- * Clean up any resources that won't be needed
- */
- @Override
- public void onViewRecycled() {
-
- }
-}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/RatingTextView.kt b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/RatingTextView.kt
new file mode 100644
index 000000000..1104ed996
--- /dev/null
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/RatingTextView.kt
@@ -0,0 +1,152 @@
+package com.mxt.anitrend.base.custom.view.text
+
+import android.content.Context
+import android.os.Build
+import android.util.AttributeSet
+import android.view.View
+import android.widget.LinearLayout
+import androidx.annotation.ColorRes
+import androidx.annotation.RequiresApi
+import com.mxt.anitrend.R
+import com.mxt.anitrend.base.interfaces.view.CustomView
+import com.mxt.anitrend.databinding.CustomRatingWidgetBinding
+import com.mxt.anitrend.extension.LAZY_MODE_UNSAFE
+import com.mxt.anitrend.extension.getCompatDrawable
+import com.mxt.anitrend.extension.getLayoutInflater
+import com.mxt.anitrend.model.entity.anilist.MediaList
+import com.mxt.anitrend.model.entity.anilist.meta.MediaListOptions
+import com.mxt.anitrend.model.entity.base.MediaBase
+import com.mxt.anitrend.presenter.base.BasePresenter
+import com.mxt.anitrend.util.KeyUtil
+import org.koin.core.KoinComponent
+import org.koin.core.inject
+import java.util.*
+
+/**
+ * Created by max on 2018/01/27.
+ * Special text base rating view
+ */
+
+class RatingTextView : LinearLayout, CustomView, KoinComponent {
+
+ private var mediaListOptions: MediaListOptions? = null
+ private val presenter by inject()
+ private val binding by lazy(LAZY_MODE_UNSAFE) {
+ CustomRatingWidgetBinding.inflate(getLayoutInflater(), this, true)
+ }
+
+ constructor(context: Context) : super(context) {
+ onInit()
+ }
+
+ constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
+ onInit()
+ }
+
+ constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
+ onInit()
+ }
+
+ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
+ constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
+ onInit()
+ }
+
+ /**
+ * Optionally included when constructing custom views
+ */
+ override fun onInit() {
+ val basePresenter = BasePresenter(context)
+ if (presenter.settings.isAuthenticated)
+ mediaListOptions = basePresenter.database.currentUser?.mediaListOptions
+ }
+
+ fun setFavourState(isFavourite: Boolean) {
+ @ColorRes val colorTint = if (isFavourite) R.color.colorStateYellow else R.color.white
+ val drawable = context.getCompatDrawable(R.drawable.ic_star_grey_600_24dp, colorTint)
+ binding.ratingFavourState.setImageDrawable(drawable)
+ }
+
+ fun setListStatus(mediaBase: MediaBase) {
+ if (mediaBase.mediaListEntry != null) {
+ binding.ratingListStatus.visibility = View.VISIBLE
+ when (mediaBase.mediaListEntry?.status) {
+ KeyUtil.CURRENT -> binding.ratingListStatus.setTintDrawable(R.drawable.ic_remove_red_eye_white_18dp,
+ R.color.white)
+ KeyUtil.PLANNING -> binding.ratingListStatus.setTintDrawable(R.drawable.ic_bookmark_white_24dp,
+ R.color.white)
+ KeyUtil.COMPLETED -> binding.ratingListStatus.setTintDrawable(R.drawable.ic_done_all_grey_600_24dp,
+ R.color.white)
+ KeyUtil.DROPPED -> binding.ratingListStatus.setTintDrawable(R.drawable.ic_delete_red_600_18dp,
+ R.color.white)
+ KeyUtil.PAUSED -> binding.ratingListStatus.setTintDrawable(R.drawable.ic_pause_white_18dp,
+ R.color.white)
+ KeyUtil.REPEATING -> binding.ratingListStatus.setTintDrawable(R.drawable.ic_repeat_white_18dp,
+ R.color.white)
+ }
+ } else
+ binding.ratingListStatus.visibility = View.GONE
+ }
+
+ fun setListStatus() {
+ binding.ratingListStatus.visibility = View.GONE
+ }
+
+ fun setRating(mediaList: MediaList) {
+ if (mediaListOptions != null)
+ when (mediaListOptions?.scoreFormat) {
+ KeyUtil.POINT_10_DECIMAL -> binding.ratingValue.text = String.format(Locale.getDefault(), "%.1f", mediaList.score)
+ KeyUtil.POINT_100, KeyUtil.POINT_10, KeyUtil.POINT_5 -> binding.ratingValue.text = String.format(Locale.getDefault(), "%d", mediaList.score.toInt())
+ KeyUtil.POINT_3 -> {
+ binding.ratingValue.text = ""
+ when (mediaList.score.toInt()) {
+ 0 -> binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(context.getCompatDrawable(R.drawable.ic_face_white_18dp), null, null, null)
+ 1 -> binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(context.getCompatDrawable(R.drawable.ic_sentiment_dissatisfied_white_18dp), null, null, null)
+ 2 -> binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(context.getCompatDrawable(R.drawable.ic_sentiment_neutral_white_18dp), null, null, null)
+ 3 -> binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(context.getCompatDrawable(R.drawable.ic_sentiment_satisfied_white_18dp), null, null, null)
+ }
+ }
+ }
+ else
+ binding.ratingValue.text = String.format(Locale.getDefault(), "%d", mediaList.score.toInt())
+ }
+
+ fun setRating(mediaBase: MediaBase) {
+ var mediaScoreDefault = mediaBase.averageScore.toFloat() * 5 / 100f
+ if (mediaListOptions != null)
+ when (mediaListOptions?.scoreFormat) {
+ KeyUtil.POINT_10_DECIMAL -> {
+ mediaScoreDefault = mediaBase.averageScore / 10f
+ binding.ratingValue.text = String.format(Locale.getDefault(), "%.1f", mediaScoreDefault)
+ }
+ KeyUtil.POINT_100 -> binding.ratingValue.text = String.format(Locale.getDefault(), "%d", mediaBase.averageScore)
+ KeyUtil.POINT_10 -> {
+ mediaScoreDefault = mediaBase.averageScore / 10f
+ binding.ratingValue.text = String.format(Locale.getDefault(), "%d", mediaScoreDefault.toInt())
+ }
+ KeyUtil.POINT_5 -> binding.ratingValue.text = String.format(Locale.getDefault(), "%d", mediaScoreDefault.toInt())
+ KeyUtil.POINT_3 -> {
+ binding.ratingValue.text = ""
+ if (mediaBase.averageScore == 0)
+ binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(context.getCompatDrawable(R.drawable.ic_face_white_18dp), null, null, null)
+ when {
+ mediaBase.averageScore in 1..33 ->
+ binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(context.getCompatDrawable(R.drawable.ic_sentiment_dissatisfied_white_18dp), null, null, null)
+ mediaBase.averageScore in 34..66 ->
+ binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(context.getCompatDrawable(R.drawable.ic_sentiment_neutral_white_18dp), null, null, null)
+ mediaBase.averageScore in 67..100 ->
+ binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(context.getCompatDrawable(R.drawable.ic_sentiment_satisfied_white_18dp), null, null, null)
+ }
+ }
+ }
+ else
+ binding.ratingValue.text = String.format(Locale.getDefault(), "%d", mediaBase.averageScore)
+ }
+
+ /**
+ * Clean up any resources that won't be needed
+ */
+ override fun onViewRecycled() {
+
+ }
+}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/RichMarkdownTextView.kt b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/RichMarkdownTextView.kt
index 2104005f8..c51ee3dd6 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/RichMarkdownTextView.kt
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/RichMarkdownTextView.kt
@@ -1,29 +1,19 @@
package com.mxt.anitrend.base.custom.view.text
import android.content.Context
-import android.support.v4.text.util.LinkifyCompat
-import android.support.v7.widget.AppCompatTextView
-import android.text.Spanned
import android.text.method.LinkMovementMethod
import android.text.util.Linkify
import android.util.AttributeSet
-import android.widget.TextView
+import androidx.appcompat.widget.AppCompatTextView
+import androidx.core.text.util.LinkifyCompat
import com.mxt.anitrend.base.interfaces.view.CustomView
-import com.mxt.anitrend.util.MarkDownUtil
-import com.mxt.anitrend.util.RegexUtil
-import org.commonmark.parser.Parser
-import ru.noties.markwon.AbstractMarkwonPlugin
-import ru.noties.markwon.Markwon
-import ru.noties.markwon.MarkwonConfiguration
-import ru.noties.markwon.core.CorePlugin
-import ru.noties.markwon.html.HtmlPlugin
-import ru.noties.markwon.html.MarkwonHtmlParserImpl
-import ru.noties.markwon.image.AsyncDrawableScheduler
-import ru.noties.markwon.image.ImagesPlugin
-import ru.noties.markwon.image.okhttp.OkHttpImagesPlugin
-import java.util.Arrays.asList
+import com.mxt.anitrend.util.markdown.MarkDownUtil
+import com.mxt.anitrend.util.markdown.RegexUtil
+import io.noties.markwon.Markwon
+import org.koin.core.KoinComponent
+import org.koin.core.inject
-class RichMarkdownTextView : AppCompatTextView, CustomView {
+class RichMarkdownTextView : AppCompatTextView, CustomView, KoinComponent {
constructor(context: Context) :
super(context) { onInit() }
@@ -34,34 +24,7 @@ class RichMarkdownTextView : AppCompatTextView, CustomView {
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) :
super(context, attrs, defStyleAttr) { onInit() }
- val markwon by lazy {
- Markwon.builder(context)
- .usePlugins(asList(
- CorePlugin.create(),
- ImagesPlugin.create(context),
- OkHttpImagesPlugin.create(),
- HtmlPlugin.create(),
- object: AbstractMarkwonPlugin() {
- @Override
- override fun configureParser(builder: Parser.Builder) {
-
- }
-
- override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
- builder.htmlParser(MarkwonHtmlParserImpl.create())
- }
-
- override fun beforeSetText(textView: TextView, markdown: Spanned) {
- AsyncDrawableScheduler.unschedule(textView)
- }
-
- override fun afterSetText(textView: TextView) {
- AsyncDrawableScheduler.schedule(textView)
- }
- }
- ))
- .build()
- }
+ val markwon by inject()
/**
* Optionally included when constructing custom views
@@ -81,7 +44,7 @@ class RichMarkdownTextView : AppCompatTextView, CustomView {
fun setMarkDownText(markDownText: String?) {
val strippedText = RegexUtil.removeTags(markDownText)
- val markdownSpan = MarkDownUtil.convert(strippedText, context, this)
+ val markdownSpan = MarkDownUtil.convert(strippedText)
setText(markdownSpan, BufferType.SPANNABLE)
//richMarkDown(this, markDownText)
}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SeriesProgressTextView.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SeriesProgressTextView.java
index 983c745c9..d895dd6e2 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SeriesProgressTextView.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SeriesProgressTextView.java
@@ -8,7 +8,7 @@
import com.mxt.anitrend.model.entity.base.MediaBase;
import com.mxt.anitrend.util.CompatUtil;
import com.mxt.anitrend.util.KeyUtil;
-import com.mxt.anitrend.util.MediaUtil;
+import com.mxt.anitrend.util.media.MediaUtil;
import java.util.Locale;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SeriesTypeView.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SeriesTypeView.java
index 0d35a4c85..ba9fb8706 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SeriesTypeView.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SeriesTypeView.java
@@ -1,9 +1,10 @@
package com.mxt.anitrend.base.custom.view.text;
import android.content.Context;
-import android.databinding.BindingAdapter;
import android.util.AttributeSet;
+import androidx.databinding.BindingAdapter;
+
import com.mxt.anitrend.R;
public class SeriesTypeView extends SingleLineTextView {
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SeriesYearTypeTextView.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SeriesYearTypeTextView.java
index f4622ee18..200b4dad8 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SeriesYearTypeTextView.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SeriesYearTypeTextView.java
@@ -1,9 +1,10 @@
package com.mxt.anitrend.base.custom.view.text;
import android.content.Context;
-import android.databinding.BindingAdapter;
import android.util.AttributeSet;
+import androidx.databinding.BindingAdapter;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.model.entity.anilist.meta.FuzzyDate;
import com.mxt.anitrend.model.entity.base.MediaBase;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SingleLineFontTextView.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SingleLineFontTextView.java
index 96c6dda0e..bf5e55aa5 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SingleLineFontTextView.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SingleLineFontTextView.java
@@ -2,10 +2,11 @@
import android.content.Context;
import android.content.res.AssetManager;
-import android.databinding.BindingAdapter;
import android.graphics.Typeface;
import android.util.AttributeSet;
+import androidx.databinding.BindingAdapter;
+
/**
* Created by max on 2017/12/24.
* custom font single line text view
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SingleLineTextView.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SingleLineTextView.java
index 8ceeafb78..70b7bc6c6 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SingleLineTextView.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SingleLineTextView.java
@@ -1,10 +1,11 @@
package com.mxt.anitrend.base.custom.view.text;
import android.content.Context;
-import android.support.v7.widget.AppCompatTextView;
import android.text.TextUtils;
import android.util.AttributeSet;
+import androidx.appcompat.widget.AppCompatTextView;
+
import com.mxt.anitrend.base.interfaces.view.CustomView;
/**
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SpoilerTagTextView.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SpoilerTagTextView.java
index 2b49712b1..6803681f8 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SpoilerTagTextView.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/text/SpoilerTagTextView.java
@@ -1,11 +1,12 @@
package com.mxt.anitrend.base.custom.view.text;
import android.content.Context;
-import android.databinding.BindingAdapter;
-import android.text.TextUtils;
import android.util.AttributeSet;
-import com.mxt.anitrend.util.CompatUtil;
+
+import androidx.databinding.BindingAdapter;
+
import com.mxt.anitrend.R;
+import com.mxt.anitrend.util.CompatUtil;
public class SpoilerTagTextView extends SingleLineTextView {
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/AboutPanelWidget.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/AboutPanelWidget.java
index bb4e7e8f0..3159b09e3 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/AboutPanelWidget.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/AboutPanelWidget.java
@@ -1,19 +1,19 @@
package com.mxt.anitrend.base.custom.view.widget;
-import android.arch.lifecycle.Lifecycle;
import android.content.Context;
import android.content.Intent;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.support.v4.app.FragmentActivity;
-import android.support.v4.app.FragmentManager;
import android.util.AttributeSet;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.Toast;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.fragment.app.FragmentActivity;
+import androidx.fragment.app.FragmentManager;
+import androidx.lifecycle.Lifecycle;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.custom.consumer.BaseConsumer;
import com.mxt.anitrend.base.custom.sheet.BottomSheetBase;
@@ -25,12 +25,11 @@
import com.mxt.anitrend.model.entity.container.attribute.PageInfo;
import com.mxt.anitrend.model.entity.container.body.ConnectionContainer;
import com.mxt.anitrend.model.entity.container.body.PageContainer;
-import com.mxt.anitrend.model.entity.container.request.QueryContainerBuilder;
import com.mxt.anitrend.presenter.widget.WidgetPresenter;
-import com.mxt.anitrend.util.DateUtil;
-import com.mxt.anitrend.util.GraphUtil;
import com.mxt.anitrend.util.KeyUtil;
import com.mxt.anitrend.util.NotifyUtil;
+import com.mxt.anitrend.util.date.DateUtil;
+import com.mxt.anitrend.util.graphql.GraphUtil;
import com.mxt.anitrend.view.activity.detail.FavouriteActivity;
import com.mxt.anitrend.view.sheet.BottomSheetListUsers;
@@ -38,8 +37,10 @@
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
+import io.github.wax911.library.model.request.QueryContainerBuilder;
import retrofit2.Call;
import retrofit2.Response;
+import timber.log.Timber;
/**
* Created by max on 2017/11/27.
@@ -52,6 +53,8 @@ public class AboutPanelWidget extends FrameLayout implements CustomView, View.On
private Lifecycle lifecycle;
private long userId;
+ private final String TAG = AboutPanelWidget.class.getSimpleName();
+
private long mLastSynced;
private QueryContainerBuilder queryContainer;
@@ -127,7 +130,7 @@ public void onResponse(@NonNull Call> call, @NonNull Res
public void onFailure(@NonNull Call> call, @NonNull Throwable throwable) {
if(isAlive()) {
throwable.printStackTrace();
- Log.e(this.toString(), throwable.getMessage());
+ Timber.tag(TAG).e(throwable);
}
}
});
@@ -154,7 +157,7 @@ public void onResponse(@NonNull Call> call, @NonNull Res
public void onFailure(@NonNull Call> call, @NonNull Throwable throwable) {
if(isAlive()) {
throwable.printStackTrace();
- Log.e(this.toString(), throwable.getMessage());
+ Timber.tag(TAG).e(throwable);
}
}
});
@@ -196,7 +199,7 @@ public void onResponse(@NonNull Call> call, @NonN
public void onFailure(@NonNull Call> call, @NonNull Throwable throwable) {
if(isAlive()) {
throwable.printStackTrace();
- Log.e(this.toString(), throwable.getMessage());
+ Timber.tag(TAG).e(throwable);
}
}
});
@@ -220,7 +223,7 @@ public void onClick(View view) {
switch (view.getId()) {
case R.id.user_favourites_container:
if(favourites < 1)
- NotifyUtil.makeText(getContext(), R.string.text_activity_loading, Toast.LENGTH_SHORT).show();
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.text_activity_loading, Toast.LENGTH_SHORT).show();
else {
Intent intent = new Intent(getContext(), FavouriteActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -230,7 +233,7 @@ public void onClick(View view) {
break;
case R.id.user_followers_container:
if(followers == null || followers.getTotal() < 1)
- NotifyUtil.makeText(getContext(), R.string.text_activity_loading, Toast.LENGTH_SHORT).show();
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.text_activity_loading, Toast.LENGTH_SHORT).show();
else if (fragmentManager != null){
mBottomSheet = new BottomSheetListUsers.Builder().setUserId(userId)
.setModelCount(followers.getTotal())
@@ -242,7 +245,7 @@ else if (fragmentManager != null){
break;
case R.id.user_following_container:
if(following == null || following.getTotal() < 1)
- NotifyUtil.makeText(getContext(), R.string.text_activity_loading, Toast.LENGTH_SHORT).show();
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.text_activity_loading, Toast.LENGTH_SHORT).show();
else if (fragmentManager != null){
mBottomSheet = new BottomSheetListUsers.Builder().setUserId(userId)
.setModelCount(following.getTotal())
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/AutoIncrementWidget.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/AutoIncrementWidget.java
index 91a0c0a74..b447a0fb4 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/AutoIncrementWidget.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/AutoIncrementWidget.java
@@ -3,14 +3,14 @@
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
import android.util.AttributeSet;
-import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.custom.consumer.BaseConsumer;
import com.mxt.anitrend.base.interfaces.event.RetroCallback;
@@ -19,15 +19,16 @@
import com.mxt.anitrend.model.entity.anilist.MediaList;
import com.mxt.anitrend.presenter.widget.WidgetPresenter;
import com.mxt.anitrend.util.CompatUtil;
-import com.mxt.anitrend.util.DateUtil;
-import com.mxt.anitrend.util.ErrorUtil;
import com.mxt.anitrend.util.KeyUtil;
-import com.mxt.anitrend.util.MediaListUtil;
-import com.mxt.anitrend.util.MediaUtil;
import com.mxt.anitrend.util.NotifyUtil;
+import com.mxt.anitrend.util.date.DateUtil;
+import com.mxt.anitrend.util.graphql.AniGraphErrorUtilKt;
+import com.mxt.anitrend.util.media.MediaListUtil;
+import com.mxt.anitrend.util.media.MediaUtil;
import retrofit2.Call;
import retrofit2.Response;
+import timber.log.Timber;
/**
* Created by max on 2018/02/22.
@@ -43,6 +44,7 @@ public class AutoIncrementWidget extends LinearLayout implements CustomView, Vie
private MediaList model;
private String currentUser;
+ private final String TAG = AutoIncrementWidget.class.getSimpleName();
public AutoIncrementWidget(Context context) {
super(context);
@@ -82,11 +84,11 @@ public void onClick(View view) {
binding.widgetFlipper.showNext();
updateModelState();
} else
- NotifyUtil.makeText(getContext(), R.string.busy_please_wait, Toast.LENGTH_SHORT).show();
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.busy_please_wait, Toast.LENGTH_SHORT).show();
break;
}
} else
- NotifyUtil.makeText(getContext(), MediaUtil.isAnimeType(model.getMedia()) ?
+ NotifyUtil.INSTANCE.makeText(getContext(), MediaUtil.isAnimeType(model.getMedia()) ?
R.string.text_unable_to_increment_episodes : R.string.text_unable_to_increment_chapters,
R.drawable.ic_warning_white_18dp, Toast.LENGTH_SHORT).show();
}
@@ -119,18 +121,19 @@ public void onResponse(@NonNull Call call, @NonNull Response(requestType, model), false);
} else
resetFlipperState();
} else {
resetFlipperState();
- Log.e(this.toString(), ErrorUtil.INSTANCE.getError(response));
- NotifyUtil.makeText(getContext(), R.string.text_error_request, Toast.LENGTH_SHORT).show();
+ Timber.tag(TAG).w(AniGraphErrorUtilKt.apiError(response));
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.text_error_request, Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
+ Timber.tag(TAG).w(e);
e.printStackTrace();
}
}
@@ -138,10 +141,11 @@ public void onResponse(@NonNull Call call, @NonNull Response call, @NonNull Throwable throwable) {
try {
- Log.e(toString(), throwable.getLocalizedMessage());
+ Timber.tag(TAG).e(throwable);
throwable.printStackTrace();
resetFlipperState();
} catch (Exception e) {
+ Timber.tag(TAG).e(e);
e.printStackTrace();
}
}
@@ -157,7 +161,7 @@ private void updateModelState() {
model.setStatus(KeyUtil.COMPLETED);
model.setCompletedAt(DateUtil.INSTANCE.getCurrentDate());
}
- presenter.setParams(MediaListUtil.getMediaListParams(model, presenter.getDatabase()
+ presenter.setParams(MediaListUtil.INSTANCE.getMediaListParams(model, presenter.getDatabase()
.getCurrentUser().getMediaListOptions().getScoreFormat()));
presenter.requestData(requestType, getContext(), this);
}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CommentWidget.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CommentWidget.java
index 3af14cd72..241c2f1d5 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CommentWidget.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CommentWidget.java
@@ -1,7 +1,6 @@
package com.mxt.anitrend.base.custom.view.widget;
import android.content.Context;
-import android.graphics.Typeface;
import android.util.AttributeSet;
import com.mxt.anitrend.R;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CustomProgress.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CustomProgress.java
index 8b0b7897d..821bf896a 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CustomProgress.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CustomProgress.java
@@ -6,10 +6,11 @@
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.os.Build;
-import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.ProgressBar;
+import androidx.annotation.Nullable;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.interfaces.view.CustomView;
import com.mxt.anitrend.util.CompatUtil;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CustomRatingBar.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CustomRatingBar.java
index f355a799b..71fc85410 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CustomRatingBar.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CustomRatingBar.java
@@ -1,10 +1,11 @@
package com.mxt.anitrend.base.custom.view.widget;
import android.content.Context;
-import android.databinding.BindingAdapter;
-import android.support.v7.widget.AppCompatRatingBar;
import android.util.AttributeSet;
+import androidx.appcompat.widget.AppCompatRatingBar;
+import androidx.databinding.BindingAdapter;
+
import com.mxt.anitrend.base.interfaces.view.CustomView;
/**
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CustomSeriesAnimeManage.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CustomSeriesAnimeManage.java
index db2aa3e98..7ca1ffe69 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CustomSeriesAnimeManage.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CustomSeriesAnimeManage.java
@@ -3,19 +3,20 @@
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
-import android.support.annotation.RequiresApi;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;
+import androidx.annotation.RequiresApi;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.databinding.CustomActionAnimeBinding;
import com.mxt.anitrend.util.CompatUtil;
import com.mxt.anitrend.util.KeyUtil;
-import com.mxt.anitrend.util.MediaListUtil;
import com.mxt.anitrend.util.NotifyUtil;
+import com.mxt.anitrend.util.media.MediaListUtil;
/**
* Created by max on 2018/01/03.
@@ -55,7 +56,7 @@ public void onInit() {
* Saves the current views states into the model
* and returns a bundle of the params
*
- * @see com.mxt.anitrend.util.MediaListUtil
+ * @see MediaListUtil
*/
@Override
public Bundle persistChanges() {
@@ -70,7 +71,7 @@ public Bundle persistChanges() {
model.setHidden(binding.diaCurrentPrivacy.isChecked());
model.setNotes(binding.diaCurrentNotes.getFormattedText());
model.setStatus(KeyUtil.MediaListStatus[binding.diaCurrentStatus.getSelectedItemPosition()]);
- return MediaListUtil.getMediaListParams(model, getMediaListOptions().getScoreFormat());
+ return MediaListUtil.INSTANCE.getMediaListParams(model, getMediaListOptions().getScoreFormat());
}
@Override
@@ -120,13 +121,13 @@ public void onItemSelected(AdapterView> adapterView, View view, int i, long l)
switch (KeyUtil.MediaListStatus[i]) {
case KeyUtil.CURRENT:
if (CompatUtil.INSTANCE.equals(getSeriesModel().getStatus(), KeyUtil.NOT_YET_RELEASED))
- NotifyUtil.makeText(getContext(), R.string.warning_anime_not_airing, Toast.LENGTH_LONG).show();
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.warning_anime_not_airing, Toast.LENGTH_LONG).show();
break;
case KeyUtil.PLANNING:
break;
case KeyUtil.COMPLETED:
if (!CompatUtil.INSTANCE.equals(getSeriesModel().getStatus(), KeyUtil.FINISHED))
- NotifyUtil.makeText(getContext(), R.string.warning_anime_is_airing, Toast.LENGTH_LONG).show();
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.warning_anime_is_airing, Toast.LENGTH_LONG).show();
else {
int total = getSeriesModel().getEpisodes();
model.setProgress(total);
@@ -136,7 +137,7 @@ public void onItemSelected(AdapterView> adapterView, View view, int i, long l)
break;
default:
if (CompatUtil.INSTANCE.equals(getSeriesModel().getStatus(), KeyUtil.NOT_YET_RELEASED))
- NotifyUtil.makeText(getContext(), R.string.warning_anime_not_airing, Toast.LENGTH_LONG).show();
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.warning_anime_not_airing, Toast.LENGTH_LONG).show();
break;
}
}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CustomSeriesManageBase.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CustomSeriesManageBase.java
index 585f38c2c..5ad91d193 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CustomSeriesManageBase.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CustomSeriesManageBase.java
@@ -3,12 +3,13 @@
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
-import android.support.annotation.NonNull;
-import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.widget.AdapterView;
import android.widget.RelativeLayout;
+import androidx.annotation.NonNull;
+import androidx.annotation.RequiresApi;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.adapter.spinner.IconArrayAdapter;
import com.mxt.anitrend.base.interfaces.view.CustomView;
@@ -17,6 +18,7 @@
import com.mxt.anitrend.model.entity.base.MediaBase;
import com.mxt.anitrend.presenter.fragment.MediaPresenter;
import com.mxt.anitrend.util.CompatUtil;
+import com.mxt.anitrend.util.media.MediaListUtil;
import java.util.HashMap;
import java.util.Map;
@@ -100,7 +102,7 @@ public MediaListOptions getMediaListOptions() {
/**
* Saves the current views states into the model
* and returns a bundle of the params
- * @see com.mxt.anitrend.util.MediaListUtil
+ * @see MediaListUtil
*/
public abstract Bundle persistChanges();
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CustomSeriesMangaManage.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CustomSeriesMangaManage.java
index b076f7ff8..f9dd43804 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CustomSeriesMangaManage.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/CustomSeriesMangaManage.java
@@ -3,19 +3,20 @@
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
-import android.support.annotation.RequiresApi;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;
+import androidx.annotation.RequiresApi;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.databinding.CustomActionMangaBinding;
import com.mxt.anitrend.util.CompatUtil;
import com.mxt.anitrend.util.KeyUtil;
-import com.mxt.anitrend.util.MediaListUtil;
import com.mxt.anitrend.util.NotifyUtil;
+import com.mxt.anitrend.util.media.MediaListUtil;
/**
* Created by max on 2018/01/03.
@@ -54,7 +55,7 @@ public void onInit() {
/**
* Saves the current views states into the model
* and returns a bundle of the params
- * @see com.mxt.anitrend.util.MediaListUtil
+ * @see MediaListUtil
*/
@Override
public Bundle persistChanges() {
@@ -70,7 +71,7 @@ public Bundle persistChanges() {
model.setHidden(binding.diaCurrentPrivacy.isChecked());
model.setNotes(binding.diaCurrentNotes.getFormattedText());
model.setStatus(KeyUtil.MediaListStatus[binding.diaCurrentStatus.getSelectedItemPosition()]);
- return MediaListUtil.getMediaListParams(model, getMediaListOptions().getScoreFormat());
+ return MediaListUtil.INSTANCE.getMediaListParams(model, getMediaListOptions().getScoreFormat());
}
@Override
@@ -124,13 +125,13 @@ public void onItemSelected(AdapterView> adapterView, View view, int i, long l)
switch (KeyUtil.MediaListStatus[i]) {
case KeyUtil.CURRENT:
if (CompatUtil.INSTANCE.equals(getSeriesModel().getStatus(), KeyUtil.NOT_YET_RELEASED))
- NotifyUtil.makeText(getContext(), R.string.warning_manga_not_publishing, Toast.LENGTH_LONG).show();
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.warning_manga_not_publishing, Toast.LENGTH_LONG).show();
break;
case KeyUtil.PLANNING:
break;
case KeyUtil.COMPLETED:
if (!CompatUtil.INSTANCE.equals(getSeriesModel().getStatus(), KeyUtil.FINISHED))
- NotifyUtil.makeText(getContext(), R.string.warning_manga_publishing, Toast.LENGTH_LONG).show();
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.warning_manga_publishing, Toast.LENGTH_LONG).show();
else {
int total = getSeriesModel().getChapters();
model.setProgress(total);
@@ -144,7 +145,7 @@ public void onItemSelected(AdapterView> adapterView, View view, int i, long l)
break;
default:
if (CompatUtil.INSTANCE.equals(getSeriesModel().getStatus(), KeyUtil.NOT_YET_RELEASED))
- NotifyUtil.makeText(getContext(), R.string.warning_manga_not_publishing, Toast.LENGTH_LONG).show();
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.warning_manga_not_publishing, Toast.LENGTH_LONG).show();
break;
}
}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/FavouriteToolbarWidget.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/FavouriteToolbarWidget.java
index f31967d97..642e71beb 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/FavouriteToolbarWidget.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/FavouriteToolbarWidget.java
@@ -3,14 +3,14 @@
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
import android.util.AttributeSet;
-import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.Toast;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.interfaces.event.RetroCallback;
import com.mxt.anitrend.base.interfaces.view.CustomView;
@@ -19,18 +19,19 @@
import com.mxt.anitrend.model.entity.base.MediaBase;
import com.mxt.anitrend.model.entity.base.StaffBase;
import com.mxt.anitrend.model.entity.base.StudioBase;
-import com.mxt.anitrend.model.entity.container.request.QueryContainerBuilder;
import com.mxt.anitrend.presenter.widget.WidgetPresenter;
import com.mxt.anitrend.util.CompatUtil;
-import com.mxt.anitrend.util.ErrorUtil;
-import com.mxt.anitrend.util.GraphUtil;
import com.mxt.anitrend.util.KeyUtil;
-import com.mxt.anitrend.util.MediaUtil;
import com.mxt.anitrend.util.NotifyUtil;
+import com.mxt.anitrend.util.graphql.AniGraphErrorUtilKt;
+import com.mxt.anitrend.util.graphql.GraphUtil;
+import com.mxt.anitrend.util.media.MediaUtil;
+import io.github.wax911.library.model.request.QueryContainerBuilder;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Response;
+import timber.log.Timber;
/**
* Created by max on 2018/01/31.
@@ -49,6 +50,8 @@ public class FavouriteToolbarWidget extends FrameLayout implements CustomView, R
private QueryContainerBuilder queryContainer;
+ private final String TAG = FavouriteToolbarWidget.class.getSimpleName();
+
public FavouriteToolbarWidget(@NonNull Context context) {
super(context);
onInit();
@@ -133,22 +136,19 @@ public boolean isModelSet() {
@Override
public void onClick(View view) {
- if(presenter.getApplicationPref().isAuthenticated())
- switch (view.getId()) {
- case R.id.widget_flipper:
- if (isModelSet()) {
- if (binding.widgetFlipper.getDisplayedChild() == WidgetPresenter.CONTENT_STATE) {
- binding.widgetFlipper.showNext();
- presenter.requestData(KeyUtil.MUT_TOGGLE_FAVOURITE, getContext(), this);
- }
- else
- NotifyUtil.makeText(getContext(), R.string.busy_please_wait, Toast.LENGTH_SHORT).show();
+ if(presenter.getSettings().isAuthenticated())
+ if (view.getId() == R.id.widget_flipper) {
+ if (isModelSet()) {
+ if (binding.widgetFlipper.getDisplayedChild() == WidgetPresenter.CONTENT_STATE) {
+ binding.widgetFlipper.showNext();
+ presenter.requestData(KeyUtil.MUT_TOGGLE_FAVOURITE, getContext(), this);
} else
- NotifyUtil.makeText(getContext(), R.string.text_activity_loading, Toast.LENGTH_SHORT).show();
- break;
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.busy_please_wait, Toast.LENGTH_SHORT).show();
+ } else
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.text_activity_loading, Toast.LENGTH_SHORT).show();
}
else
- NotifyUtil.makeText(getContext(), R.string.info_login_req, R.drawable.ic_group_add_grey_600_18dp, Toast.LENGTH_SHORT).show();
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.info_login_req, R.drawable.ic_group_add_grey_600_18dp, Toast.LENGTH_SHORT).show();
}
private void setIconType() {
@@ -189,10 +189,11 @@ else if (characterBase != null)
characterBase.toggleFavourite();
setIconType();
} else {
- Log.e(toString(), ErrorUtil.INSTANCE.getError(response));
- NotifyUtil.makeText(getContext(), R.string.text_error_request, Toast.LENGTH_SHORT).show();
+ Timber.tag(TAG).w(AniGraphErrorUtilKt.apiError(response));
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.text_error_request, Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
+ Timber.tag(TAG).w(e);
e.printStackTrace();
}
}
@@ -200,10 +201,10 @@ else if (characterBase != null)
@Override
public void onFailure(@NonNull Call call, @NonNull Throwable throwable) {
try {
- Log.e(toString(), throwable.getLocalizedMessage());
- throwable.printStackTrace();
+ Timber.tag(TAG).e(throwable);
resetFlipperState();
} catch (Exception e) {
+ Timber.tag(TAG).e(e);
e.printStackTrace();
}
}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/FavouriteWidget.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/FavouriteWidget.java
index f3d3943e5..23592bbfe 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/FavouriteWidget.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/FavouriteWidget.java
@@ -1,31 +1,32 @@
package com.mxt.anitrend.base.custom.view.widget;
import android.content.Context;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
import android.util.AttributeSet;
-import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.Toast;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.interfaces.event.RetroCallback;
import com.mxt.anitrend.base.interfaces.view.CustomView;
import com.mxt.anitrend.databinding.WidgetFavouriteBinding;
import com.mxt.anitrend.model.entity.base.UserBase;
-import com.mxt.anitrend.model.entity.container.request.QueryContainerBuilder;
import com.mxt.anitrend.presenter.widget.WidgetPresenter;
import com.mxt.anitrend.util.CompatUtil;
-import com.mxt.anitrend.util.ErrorUtil;
-import com.mxt.anitrend.util.GraphUtil;
import com.mxt.anitrend.util.KeyUtil;
import com.mxt.anitrend.util.NotifyUtil;
+import com.mxt.anitrend.util.graphql.AniGraphErrorUtilKt;
+import com.mxt.anitrend.util.graphql.GraphUtil;
import java.util.List;
+import io.github.wax911.library.model.request.QueryContainerBuilder;
import retrofit2.Call;
import retrofit2.Response;
+import timber.log.Timber;
/**
* Created by max on 2017/10/29.
@@ -36,6 +37,7 @@ public class FavouriteWidget extends FrameLayout implements CustomView, RetroCal
private WidgetPresenter> presenter;
private WidgetFavouriteBinding binding;
private @Nullable List model;
+ private final String TAG = FavouriteWidget.class.getSimpleName();
public FavouriteWidget(Context context) {
super(context);
@@ -99,7 +101,7 @@ public void onClick(View view) {
presenter.requestData(KeyUtil.MUT_TOGGLE_LIKE, getContext(), this);
}
else
- NotifyUtil.makeText(getContext(), R.string.busy_please_wait, Toast.LENGTH_SHORT).show();
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.busy_please_wait, Toast.LENGTH_SHORT).show();
break;
}
}
@@ -134,10 +136,11 @@ public void onResponse(@NonNull Call> call, @NonNull Response> call, @NonNull Response> call, @NonNull Throwable throwable) {
try {
- Log.e(toString(), throwable.getLocalizedMessage());
- throwable.printStackTrace();
+ Timber.tag(TAG).e(throwable);
resetFlipperState();
} catch (Exception e) {
+ Timber.tag(TAG).e(throwable);
e.printStackTrace();
}
}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/FollowStateWidget.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/FollowStateWidget.java
index d41f1d632..afd285a1b 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/FollowStateWidget.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/FollowStateWidget.java
@@ -1,29 +1,30 @@
package com.mxt.anitrend.base.custom.view.widget;
import android.content.Context;
-import android.support.annotation.NonNull;
import android.util.AttributeSet;
-import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.Toast;
+import androidx.annotation.NonNull;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.custom.consumer.BaseConsumer;
import com.mxt.anitrend.base.interfaces.event.RetroCallback;
import com.mxt.anitrend.base.interfaces.view.CustomView;
import com.mxt.anitrend.databinding.WidgetButtonStateBinding;
import com.mxt.anitrend.model.entity.base.UserBase;
-import com.mxt.anitrend.model.entity.container.request.QueryContainerBuilder;
import com.mxt.anitrend.presenter.widget.WidgetPresenter;
import com.mxt.anitrend.util.CompatUtil;
-import com.mxt.anitrend.util.ErrorUtil;
-import com.mxt.anitrend.util.GraphUtil;
import com.mxt.anitrend.util.KeyUtil;
import com.mxt.anitrend.util.NotifyUtil;
+import com.mxt.anitrend.util.graphql.AniGraphErrorUtilKt;
+import com.mxt.anitrend.util.graphql.GraphUtil;
+import io.github.wax911.library.model.request.QueryContainerBuilder;
import retrofit2.Call;
import retrofit2.Response;
+import timber.log.Timber;
/**
* Created by max on 2017/11/16.
@@ -36,6 +37,7 @@ public class FollowStateWidget extends FrameLayout implements CustomView, View.O
private UserBase model;
private WidgetButtonStateBinding binding;
private WidgetPresenter presenter;
+ private final String TAG = FollowStateWidget.class.getSimpleName();
public FollowStateWidget(Context context) {
super(context);
@@ -64,7 +66,7 @@ public void onInit() {
public void setUserModel(UserBase model) {
this.model = model;
- if(presenter.getApplicationPref().isAuthenticated())
+ if(presenter.getSettings().isAuthenticated())
if(!presenter.isCurrentUser(model))
setControlText();
else
@@ -112,7 +114,7 @@ public void onClick(View view) {
presenter.requestData(KeyUtil.MUT_TOGGLE_FOLLOW, getContext(), this);
}
else
- NotifyUtil.makeText(getContext(), R.string.busy_please_wait, Toast.LENGTH_SHORT).show();
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.busy_please_wait, Toast.LENGTH_SHORT).show();
break;
}
}
@@ -134,10 +136,11 @@ public void onResponse(@NonNull Call call, @NonNull Response
presenter.notifyAllListeners(new BaseConsumer<>(KeyUtil.MUT_TOGGLE_FOLLOW, model), false);
setControlText();
} else {
- Log.e(this.toString(), ErrorUtil.INSTANCE.getError(response));
+ Timber.tag(TAG).w(AniGraphErrorUtilKt.apiError(response));
setControlText();
}
} catch (Exception e) {
+ Timber.tag(TAG).w(e);
e.printStackTrace();
}
}
@@ -155,6 +158,7 @@ public void onFailure(@NonNull Call call, @NonNull Throwable throwable
throwable.printStackTrace();
setControlText();
} catch (Exception e) {
+ Timber.tag(TAG).e(e);
e.printStackTrace();
}
}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/FuzzyDateWidget.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/FuzzyDateWidget.java
index f37c91e1a..517c0612b 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/FuzzyDateWidget.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/FuzzyDateWidget.java
@@ -5,18 +5,19 @@
import android.content.Context;
import android.content.DialogInterface;
import android.os.Build;
-import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.DatePicker;
import android.widget.FrameLayout;
+import androidx.annotation.Nullable;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.interfaces.view.CustomView;
import com.mxt.anitrend.databinding.WidgetFuzzyDateBinding;
import com.mxt.anitrend.model.entity.anilist.meta.FuzzyDate;
import com.mxt.anitrend.util.CompatUtil;
-import com.mxt.anitrend.util.DateUtil;
+import com.mxt.anitrend.util.date.DateUtil;
import java.util.Calendar;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/MentionWidget.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/MentionWidget.java
index 6e9be10f9..bb851013e 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/MentionWidget.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/MentionWidget.java
@@ -1,9 +1,10 @@
package com.mxt.anitrend.base.custom.view.widget;
import android.content.Context;
-import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;
+import androidx.appcompat.widget.AppCompatImageView;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.interfaces.view.CustomView;
import com.mxt.anitrend.util.CompatUtil;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/ProfileStatsWidget.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/ProfileStatsWidget.java
index c7550c813..3f93f9971 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/ProfileStatsWidget.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/ProfileStatsWidget.java
@@ -4,53 +4,52 @@
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.support.annotation.RequiresApi;
-import android.support.design.widget.Snackbar;
-import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
-import com.annimon.stream.Stream;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.annotation.RequiresApi;
+import androidx.core.content.ContextCompat;
+
+import com.google.android.material.snackbar.Snackbar;
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.interfaces.event.RetroCallback;
import com.mxt.anitrend.base.interfaces.view.CustomView;
import com.mxt.anitrend.databinding.WidgetProfileStatsBinding;
-import com.mxt.anitrend.model.entity.anilist.UserStats;
-import com.mxt.anitrend.model.entity.anilist.meta.StatusDistribution;
+import com.mxt.anitrend.model.entity.anilist.user.UserStatisticTypes;
import com.mxt.anitrend.model.entity.container.body.ConnectionContainer;
-import com.mxt.anitrend.model.entity.container.request.QueryContainerBuilder;
import com.mxt.anitrend.presenter.widget.WidgetPresenter;
-import com.mxt.anitrend.util.CompatUtil;
-import com.mxt.anitrend.util.ErrorUtil;
-import com.mxt.anitrend.util.GraphUtil;
import com.mxt.anitrend.util.KeyUtil;
+import com.mxt.anitrend.util.graphql.AniGraphErrorUtilKt;
+import com.mxt.anitrend.util.graphql.GraphUtil;
import com.mxt.anitrend.view.activity.detail.MediaListActivity;
-import java.util.List;
import java.util.Locale;
+import io.github.wax911.library.model.request.QueryContainerBuilder;
import retrofit2.Call;
import retrofit2.Response;
+import timber.log.Timber;
/**
* Created by max on 2017/11/26.
* status widget
*/
-public class ProfileStatsWidget extends FrameLayout implements CustomView, View.OnClickListener, RetroCallback> {
+public class ProfileStatsWidget extends FrameLayout implements CustomView, View.OnClickListener, RetroCallback> {
private WidgetProfileStatsBinding binding;
- private WidgetPresenter> presenter;
+ private WidgetPresenter> presenter;
- private UserStats model;
+ @Nullable
+ private UserStatisticTypes model;
private QueryContainerBuilder queryContainer;
private Bundle bundle;
+ private final String TAG = ProfileStatsWidget.class.getSimpleName();
private final String placeHolder = "..";
@@ -98,14 +97,12 @@ public void onInit() {
public void updateUI() {
binding.setClickListener(this);
- binding.userAnimeTime.setText(getAnimeTime(model.getWatchedTime()));
- binding.userMangaChaps.setText(getMangaChaptersCount(model.getChaptersRead()));
-
- if(model.getAnimeStatusDistribution() != null && !model.getAnimeStatusDistribution().isEmpty())
- binding.userAnimeTotal.setText(getCount(model.getAnimeStatusDistribution()));
-
- if(model.getMangaStatusDistribution() != null && !model.getMangaStatusDistribution().isEmpty())
- binding.userMangaTotal.setText(getCount(model.getMangaStatusDistribution()));
+ if (model != null) {
+ binding.userAnimeTime.setText(getAnimeTime(model.getAnime().getMinutesWatched()));
+ binding.userMangaChaps.setText(getMangaChaptersCount(model.getManga().getChaptersRead()));
+ binding.userAnimeTotal.setText(getCount(model.getAnime().getCount()));
+ binding.userMangaTotal.setText(getCount(model.getManga().getCount()));
+ }
}
public void setParams(Bundle bundle) {
@@ -133,10 +130,22 @@ public void onClick(View view) {
Intent intent;
switch (view.getId()) {
case R.id.user_anime_time_container:
- Snackbar.make(this, getContext().getString(R.string.text_user_anime_time, getAnimeTime(model.getWatchedTime())), Snackbar.LENGTH_LONG).show();
+ if (model != null)
+ Snackbar.make(this,
+ getContext().getString(
+ R.string.text_user_anime_time,
+ getAnimeTime(model.getAnime().getMinutesWatched())
+ ), Snackbar.LENGTH_LONG
+ ).show();
break;
case R.id.user_manga_chaps_container:
- Snackbar.make(this, getContext().getString(R.string.text_user_manga_chapters, getMangaChaptersCount(model.getChaptersRead())), Snackbar.LENGTH_LONG).show();
+ if (model != null)
+ Snackbar.make(this,
+ getContext().getString(
+ R.string.text_user_manga_chapters,
+ getMangaChaptersCount(model.getManga().getChaptersRead())
+ ), Snackbar.LENGTH_LONG
+ ).show();
break;
case R.id.user_anime_total_container:
intent = new Intent(getContext(), MediaListActivity.class);
@@ -156,35 +165,36 @@ public void onClick(View view) {
}
@Override
- public void onResponse(@NonNull Call> call, @NonNull Response> response) {
+ public void onResponse(@NonNull Call> call, @NonNull Response> response) {
try {
- ConnectionContainer connectionContainer;
+ ConnectionContainer connectionContainer;
if(response.isSuccessful() && (connectionContainer = response.body()) != null) {
if(!connectionContainer.isEmpty()) {
model = connectionContainer.getConnection();
updateUI();
}
} else
- Log.e(this.toString(), ErrorUtil.INSTANCE.getError(response));
+ Timber.tag(TAG).w(AniGraphErrorUtilKt.apiError(response));
} catch (Exception e) {
+ Timber.tag(TAG).w(e);
e.printStackTrace();
}
}
@Override
- public void onFailure(@NonNull Call> call, @NonNull Throwable throwable) {
+ public void onFailure(@NonNull Call> call, @NonNull Throwable throwable) {
try {
- Log.e(toString(), throwable.getLocalizedMessage());
- throwable.printStackTrace();
+ Timber.tag(TAG).w(throwable);
} catch (Exception e) {
+ Timber.tag(TAG).e(e);
e.printStackTrace();
}
}
- public String getAnimeTime(int animeTime) {
- if(animeTime < 1)
+ public String getAnimeTime(@Nullable Integer animeTime) {
+ if(animeTime == null || animeTime < 1)
return placeHolder;
- float item_time = animeTime / 60;
+ float item_time = animeTime / 60f;
if(item_time > 60) {
item_time /= 24;
if(item_time > 365)
@@ -194,21 +204,15 @@ public String getAnimeTime(int animeTime) {
return getContext().getString(R.string.anime_time_hours, item_time);
}
- public String getMangaChaptersCount(long manga_chap) {
- if(manga_chap < 1)
+ public String getMangaChaptersCount(@Nullable Integer manga_chap) {
+ if(manga_chap == null || manga_chap < 1)
return placeHolder;
if(manga_chap > 1000)
return String.format(Locale.getDefault(), "%.1f K", (float)manga_chap/1000);
return String.format(Locale.getDefault(), "%d", manga_chap);
}
- public String getCount(List statusDistributions) {
- int totalCount = 0;
- if(!CompatUtil.INSTANCE.isEmpty(statusDistributions))
- totalCount = Stream.of(statusDistributions)
- .mapToInt(StatusDistribution::getAmount)
- .sum();
-
+ public String getCount(int totalCount) {
if(totalCount >= 1000)
return String.format(Locale.getDefault(), "%.1f K", (float)totalCount/1000);
return String.format(Locale.getDefault(),"%d", totalCount);
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/ProgressWidget.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/ProgressWidget.java
index dad6ef8ea..8e22fb2cc 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/ProgressWidget.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/ProgressWidget.java
@@ -3,7 +3,6 @@
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
-import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
@@ -11,6 +10,8 @@
import android.view.View;
import android.widget.FrameLayout;
+import androidx.annotation.Nullable;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.interfaces.view.CustomView;
import com.mxt.anitrend.databinding.WidgetProgressBinding;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/RingProgress.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/RingProgress.java
index 047821ea9..e7cfb8745 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/RingProgress.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/RingProgress.java
@@ -14,12 +14,13 @@
import android.graphics.RectF;
import android.graphics.Shader;
import android.os.Build;
-import android.support.annotation.Nullable;
-import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.LinearInterpolator;
+import androidx.annotation.Nullable;
+import androidx.annotation.RequiresApi;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.interfaces.view.CustomView;
import com.mxt.anitrend.model.entity.base.StatsRing;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/ScoreWidget.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/ScoreWidget.java
index 4a8a952a2..424093c31 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/ScoreWidget.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/ScoreWidget.java
@@ -1,13 +1,14 @@
package com.mxt.anitrend.base.custom.view.widget;
import android.content.Context;
-import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextUtils;
import android.text.method.DigitsKeyListener;
import android.util.AttributeSet;
import android.view.View;
+import androidx.annotation.Nullable;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.util.CompatUtil;
import com.mxt.anitrend.util.KeyUtil;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/SeriesStatusWidget.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/SeriesStatusWidget.java
index 8349e3b46..fae3941b8 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/SeriesStatusWidget.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/SeriesStatusWidget.java
@@ -2,14 +2,15 @@
import android.annotation.TargetApi;
import android.content.Context;
-import android.databinding.BindingAdapter;
import android.os.Build;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.FrameLayout;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.databinding.BindingAdapter;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.interfaces.view.CustomView;
import com.mxt.anitrend.model.entity.anilist.Media;
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/StatusContentWidget.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/StatusContentWidget.java
index 8ee5a3a2f..475c18628 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/StatusContentWidget.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/StatusContentWidget.java
@@ -5,11 +5,6 @@
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.support.annotation.RequiresApi;
-import android.support.v7.widget.LinearLayoutManager;
-import android.support.v7.widget.SnapHelper;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
@@ -17,6 +12,12 @@
import android.widget.LinearLayout;
import android.widget.Toast;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.annotation.RequiresApi;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.SnapHelper;
+
import com.annimon.stream.IntPair;
import com.mxt.anitrend.R;
import com.mxt.anitrend.adapter.recycler.detail.ImagePreviewAdapter;
@@ -30,7 +31,7 @@
import com.mxt.anitrend.util.CompatUtil;
import com.mxt.anitrend.util.KeyUtil;
import com.mxt.anitrend.util.NotifyUtil;
-import com.mxt.anitrend.util.RegexUtil;
+import com.mxt.anitrend.util.markdown.RegexUtil;
import com.mxt.anitrend.view.activity.base.ImagePreviewActivity;
import com.mxt.anitrend.view.activity.base.VideoPlayerActivity;
@@ -176,7 +177,7 @@ public void onItemClick(View target, IntPair data) {
getContext().startActivity(intent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
- NotifyUtil.makeText(getContext(), R.string.init_youtube_missing, Toast.LENGTH_SHORT).show();
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.init_youtube_missing, Toast.LENGTH_SHORT).show();
}
break;
}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/StatusDeleteWidget.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/StatusDeleteWidget.java
index 6d0d239bb..930f06cfb 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/StatusDeleteWidget.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/StatusDeleteWidget.java
@@ -1,13 +1,13 @@
package com.mxt.anitrend.base.custom.view.widget;
import android.content.Context;
-import android.support.annotation.NonNull;
import android.util.AttributeSet;
-import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.Toast;
+import androidx.annotation.NonNull;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.custom.consumer.BaseConsumer;
import com.mxt.anitrend.base.interfaces.event.RetroCallback;
@@ -16,16 +16,17 @@
import com.mxt.anitrend.model.entity.anilist.FeedList;
import com.mxt.anitrend.model.entity.anilist.FeedReply;
import com.mxt.anitrend.model.entity.anilist.meta.DeleteState;
-import com.mxt.anitrend.model.entity.container.request.QueryContainerBuilder;
import com.mxt.anitrend.presenter.widget.WidgetPresenter;
import com.mxt.anitrend.util.CompatUtil;
-import com.mxt.anitrend.util.ErrorUtil;
-import com.mxt.anitrend.util.GraphUtil;
import com.mxt.anitrend.util.KeyUtil;
import com.mxt.anitrend.util.NotifyUtil;
+import com.mxt.anitrend.util.graphql.AniGraphErrorUtilKt;
+import com.mxt.anitrend.util.graphql.GraphUtil;
+import io.github.wax911.library.model.request.QueryContainerBuilder;
import retrofit2.Call;
import retrofit2.Response;
+import timber.log.Timber;
public class StatusDeleteWidget extends FrameLayout implements CustomView, RetroCallback, View.OnClickListener {
@@ -34,6 +35,7 @@ public class StatusDeleteWidget extends FrameLayout implements CustomView, Retro
private @KeyUtil.RequestType int requestType;
private FeedList feedList;
private FeedReply feedReply;
+ private final String TAG = StatusDeleteWidget.class.getSimpleName();
public StatusDeleteWidget(Context context) {
super(context);
@@ -105,7 +107,7 @@ public void onClick(View view) {
presenter.requestData(requestType, getContext(), this);
}
else
- NotifyUtil.makeText(getContext(), R.string.busy_please_wait, Toast.LENGTH_SHORT).show();
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.busy_please_wait, Toast.LENGTH_SHORT).show();
break;
}
}
@@ -131,10 +133,11 @@ public void onResponse(@NonNull Call call, @NonNull Response(requestType, feedReply), false);
} else
- NotifyUtil.makeText(getContext(), R.string.text_error_request, Toast.LENGTH_SHORT).show();
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.text_error_request, Toast.LENGTH_SHORT).show();
} else
- Log.e(this.toString(), ErrorUtil.INSTANCE.getError(response));
+ Timber.tag(TAG).w(AniGraphErrorUtilKt.apiError(response));
} catch (Exception e) {
+ Timber.tag(TAG).w(e);
e.printStackTrace();
}
}
@@ -149,7 +152,7 @@ else if (requestType == KeyUtil.MUT_DELETE_FEED_REPLY)
@Override
public void onFailure(@NonNull Call call, @NonNull Throwable throwable) {
try {
- Log.e(toString(), throwable.getLocalizedMessage());
+ Timber.tag(TAG).e(throwable.getLocalizedMessage());
throwable.printStackTrace();
resetFlipperState();
} catch (Exception e) {
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/VoteWidget.java b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/VoteWidget.java
index 69d8a4f72..5ca07b773 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/VoteWidget.java
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/view/widget/VoteWidget.java
@@ -2,34 +2,35 @@
import android.content.Context;
import android.os.Build;
-import android.support.annotation.ColorRes;
-import android.support.annotation.DrawableRes;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;
+import androidx.annotation.ColorRes;
+import androidx.annotation.DrawableRes;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.annotation.RequiresApi;
+
import com.mxt.anitrend.R;
import com.mxt.anitrend.base.custom.view.text.SingleLineTextView;
import com.mxt.anitrend.base.interfaces.event.RetroCallback;
import com.mxt.anitrend.base.interfaces.view.CustomView;
import com.mxt.anitrend.databinding.WidgetVoteBinding;
import com.mxt.anitrend.model.entity.anilist.Review;
-import com.mxt.anitrend.model.entity.container.request.QueryContainerBuilder;
import com.mxt.anitrend.presenter.widget.WidgetPresenter;
import com.mxt.anitrend.util.CompatUtil;
-import com.mxt.anitrend.util.ErrorUtil;
-import com.mxt.anitrend.util.GraphUtil;
import com.mxt.anitrend.util.KeyUtil;
import com.mxt.anitrend.util.NotifyUtil;
+import com.mxt.anitrend.util.graphql.AniGraphErrorUtilKt;
+import com.mxt.anitrend.util.graphql.GraphUtil;
+import io.github.wax911.library.model.request.QueryContainerBuilder;
import retrofit2.Call;
import retrofit2.Response;
+import timber.log.Timber;
/**
* Created by max on 2017/11/05.
@@ -41,7 +42,7 @@ public class VoteWidget extends LinearLayout implements CustomView, View.OnClick
private WidgetPresenter presenter;
private WidgetVoteBinding binding;
private Review model;
-
+ private final String TAG = VoteWidget.class.getSimpleName();
private @ColorRes int colorStyle;
public VoteWidget(@NonNull Context context) {
@@ -75,25 +76,25 @@ private void setParameters(@KeyUtil.ReviewRating String ratingType) {
@Override
public void onClick(View view) {
- if(presenter.getApplicationPref().isAuthenticated()) {
+ if(presenter.getSettings().isAuthenticated()) {
switch (view.getId()) {
case R.id.widget_thumb_up_flipper:
if (binding.widgetThumbUpFlipper.getDisplayedChild() == WidgetPresenter.CONTENT_STATE) {
binding.widgetThumbUpFlipper.showNext();
setParameters(CompatUtil.INSTANCE.equals(model.getUserRating(), KeyUtil.UP_VOTE) ? KeyUtil.NO_VOTE : KeyUtil.UP_VOTE);
} else
- NotifyUtil.makeText(getContext(), R.string.busy_please_wait, Toast.LENGTH_SHORT).show();
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.busy_please_wait, Toast.LENGTH_SHORT).show();
break;
case R.id.widget_thumb_down_flipper:
if (binding.widgetThumbDownFlipper.getDisplayedChild() == WidgetPresenter.CONTENT_STATE) {
binding.widgetThumbDownFlipper.showNext();
setParameters(CompatUtil.INSTANCE.equals(model.getUserRating(), KeyUtil.DOWN_VOTE) ? KeyUtil.NO_VOTE : KeyUtil.DOWN_VOTE);
} else
- NotifyUtil.makeText(getContext(), R.string.busy_please_wait, Toast.LENGTH_SHORT).show();
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.busy_please_wait, Toast.LENGTH_SHORT).show();
break;
}
} else
- NotifyUtil.makeText(getContext(), R.string.info_login_req, R.drawable.ic_group_add_grey_600_18dp, Toast.LENGTH_SHORT).show();
+ NotifyUtil.INSTANCE.makeText(getContext(), R.string.info_login_req, R.drawable.ic_group_add_grey_600_18dp, Toast.LENGTH_SHORT).show();
}
/**
@@ -188,10 +189,11 @@ public void onResponse(@NonNull Call call, @NonNull Response res
this.model.setUserRating(model.getUserRating());
setReviewStatus();
} else {
- Log.e(this.toString(), ErrorUtil.INSTANCE.getError(response));
+ Timber.w(AniGraphErrorUtilKt.apiError(response));
resetFlipperState();
}
} catch (Exception e) {
+ Timber.tag(TAG).w(e);
e.printStackTrace();
}
}
@@ -206,10 +208,10 @@ public void onResponse(@NonNull Call call, @NonNull Response res
@Override
public void onFailure(@NonNull Call call, @NonNull Throwable throwable) {
try {
- Log.e(toString(), throwable.getLocalizedMessage());
- throwable.printStackTrace();
+ Timber.tag(TAG).e(throwable);
resetFlipperState();
} catch (Exception e) {
+ Timber.tag(TAG).e(throwable);
e.printStackTrace();
}
}
diff --git a/app/src/main/java/com/mxt/anitrend/base/custom/viewmodel/ViewModelBase.kt b/app/src/main/java/com/mxt/anitrend/base/custom/viewmodel/ViewModelBase.kt
index da8a084ed..824994c5a 100644
--- a/app/src/main/java/com/mxt/anitrend/base/custom/viewmodel/ViewModelBase.kt
+++ b/app/src/main/java/com/mxt/anitrend/base/custom/viewmodel/ViewModelBase.kt
@@ -1,29 +1,29 @@
package com.mxt.anitrend.base.custom.viewmodel
-import android.arch.lifecycle.MutableLiveData
-import android.arch.lifecycle.ViewModel
import android.content.Context
import android.os.AsyncTask
import android.os.Bundle
-
+import androidx.lifecycle.MutableLiveData
+import androidx.lifecycle.ViewModel
import com.mxt.anitrend.R
import com.mxt.anitrend.base.custom.async.RequestHandler
import com.mxt.anitrend.base.interfaces.event.ResponseCallback
import com.mxt.anitrend.base.interfaces.event.RetroCallback
-import com.mxt.anitrend.util.ErrorUtil
import com.mxt.anitrend.util.KeyUtil
-
-import io.objectbox.android.ObjectBoxLiveData
-import io.objectbox.query.Query
+import com.mxt.anitrend.util.graphql.apiError
+import kotlinx.coroutines.*
import retrofit2.Call
import retrofit2.Response
+import kotlin.coroutines.CoroutineContext
/**
* Created by max on 2017/10/14.
* View model abstraction contains the generic data model
*/
-class ViewModelBase: ViewModel(), RetroCallback {
+class ViewModelBase: ViewModel(), RetroCallback, CoroutineScope {
+
+ private val job: Job = SupervisorJob()
val model by lazy {
MutableLiveData()
@@ -33,17 +33,17 @@ class ViewModelBase: ViewModel(), RetroCallback {
private var mLoader: RequestHandler? = null
- private var emptyMessage: String? = null
- private var errorMessage: String? = null
+ private lateinit var emptyMessage: String
+ private lateinit var errorMessage: String
+ private lateinit var tokenMessage: String
- val params by lazy {
- Bundle()
- }
+ val params = Bundle()
fun setContext(context: Context?) {
context?.apply {
emptyMessage = getString(R.string.layout_empty_response)
errorMessage = getString(R.string.text_error_request)
+ tokenMessage = getString(R.string.text_error_auth_token)
}
}
@@ -65,6 +65,7 @@ class ViewModelBase: ViewModel(), RetroCallback {
* prevent a leak of this ViewModel.
*/
override fun onCleared() {
+ cancel()
if (mLoader?.status != AsyncTask.Status.FINISHED)
mLoader?.cancel(true)
mLoader = null
@@ -86,8 +87,16 @@ class ViewModelBase: ViewModel(), RetroCallback {
val container: T? = response.body()
if (response.isSuccessful && container != null)
model.setValue(container)
- else
- state?.showError(ErrorUtil.getError(response))
+ else {
+ val error = response.apiError()
+ // Hacky fix that I'm ashamed of
+ if (response.code() == 400 && error.contains("Invalid token"))
+ state?.showError(tokenMessage)
+ else if (response.code() == 401)
+ state?.showError(tokenMessage)
+ else
+ state?.showError(error)
+ }
}
/**
@@ -98,7 +107,16 @@ class ViewModelBase: ViewModel(), RetroCallback {
* @param throwable contains information about the error
*/
override fun onFailure(call: Call, throwable: Throwable) {
- state?.showEmpty(throwable.message)
+ state?.showEmpty(throwable.message ?: errorMessage)
throwable.printStackTrace()
}
+
+ /**
+ * The context of this scope.
+ * Context is encapsulated by the scope and used for implementation of coroutine builders that are extensions on the scope.
+ * Accessing this property in general code is not recommended for any purposes except accessing the [Job] instance for advanced usages.
+ *
+ * By convention, should contain an instance of a [job][Job] to enforce structured concurrency.
+ */
+ override val coroutineContext: CoroutineContext = Dispatchers.IO + job
}
diff --git a/app/src/main/java/com/mxt/anitrend/base/interfaces/base/PreferenceConverter.java b/app/src/main/java/com/mxt/anitrend/base/interfaces/base/PreferenceConverter.java
index 65f5340b0..866515471 100644
--- a/app/src/main/java/com/mxt/anitrend/base/interfaces/base/PreferenceConverter.java
+++ b/app/src/main/java/com/mxt/anitrend/base/interfaces/base/PreferenceConverter.java
@@ -1,7 +1,7 @@
package com.mxt.anitrend.base.interfaces.base;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
/**
* Created by max on 2018/09/01.
diff --git a/app/src/main/java/com/mxt/anitrend/base/interfaces/dao/BoxQuery.java b/app/src/main/java/com/mxt/anitrend/base/interfaces/dao/BoxQuery.java
deleted file mode 100644
index 434c79f30..000000000
--- a/app/src/main/java/com/mxt/anitrend/base/interfaces/dao/BoxQuery.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package com.mxt.anitrend.base.interfaces.dao;
-
-import com.mxt.anitrend.model.entity.anilist.Genre;
-import com.mxt.anitrend.model.entity.anilist.MediaTag;
-import com.mxt.anitrend.model.entity.anilist.User;
-import com.mxt.anitrend.model.entity.anilist.WebToken;
-import com.mxt.anitrend.model.entity.base.AuthBase;
-import com.mxt.anitrend.model.entity.base.VersionBase;
-
-import java.util.List;
-
-import io.objectbox.Box;
-
-public interface BoxQuery {
-
- /**
- * Gets the object box from a requested class type.
- *
- *
- * @param classType Type of class which must not be a list instance
- * @return Box of type class requested
- */
- Box getBoxStore(Class classType);
-
- /**
- * Used when the application is logging out a user preferably
- */
- void invalidateBoxStores();
-
- /**
- * Gets current authenticated user
- */
- User getCurrentUser();
-
- /**
- * Get default authentication code
- */
- AuthBase getAuthCode();
-
- /**
- * Get web token
- */
- WebToken getWebToken();
-
- /**
- * Get the application version on github
- */
- VersionBase getRemoteVersion();
-
- /**
- * Gets all saved tags
- */
- List getMediaTags();
-
- /**
- * Gets all saved genres
- */
- List getGenreCollection();
-
- /**
- * Saves current authenticated user
- */
- void saveCurrentUser(User user);
-
- /**
- * Get default authentication code
- */
- void saveAuthCode(AuthBase authBase);
-
- /**
- * Get web token
- */
- void saveWebToken(WebToken webToken);
-
- /**
- * Save the application version on github
- */
- void saveRemoteVersion(VersionBase versionBase);
-
- /**
- * Saves all saved mediaTags
- */
- void saveMediaTags(List mediaTags);
-
- /**
- * Saves all saved genres
- */
- void saveGenreCollection(List genres);
-}
diff --git a/app/src/main/java/com/mxt/anitrend/base/interfaces/dao/BoxQuery.kt b/app/src/main/java/com/mxt/anitrend/base/interfaces/dao/BoxQuery.kt
new file mode 100644
index 000000000..f1941f72f
--- /dev/null
+++ b/app/src/main/java/com/mxt/anitrend/base/interfaces/dao/BoxQuery.kt
@@ -0,0 +1,57 @@
+package com.mxt.anitrend.base.interfaces.dao
+
+import com.mxt.anitrend.model.entity.anilist.Genre
+import com.mxt.anitrend.model.entity.anilist.MediaTag
+import com.mxt.anitrend.model.entity.anilist.User
+import com.mxt.anitrend.model.entity.anilist.WebToken
+import com.mxt.anitrend.model.entity.base.AuthBase
+import com.mxt.anitrend.model.entity.base.VersionBase
+
+import io.objectbox.Box
+
+interface BoxQuery {
+
+ /**
+ * Gets current authenticated user
+ */
+ var currentUser: User?
+
+ /**
+ * Get default authentication code
+ */
+ var authCode: AuthBase?
+
+ /**
+ * Get web token
+ */
+ var webToken: WebToken?
+
+ /**
+ * Get the application version on github
+ */
+ var remoteVersion: VersionBase?
+
+ /**
+ * Gets all saved tags
+ */
+ var mediaTags: List
+
+ /**
+ * Gets all saved genres
+ */
+ var genreCollection: List
+
+ /**
+ * Gets the object box from a requested class type.
+ *
+ *
+ * @param classType Type of class which must not be a list instance
+ * @return Box of type class requested
+ */
+ fun getBoxStore(classType: Class): Box
+
+ /**
+ * Used when the application is logging out a user preferably
+ */
+ fun invalidateBoxStores()
+}
diff --git a/app/src/main/java/com/mxt/anitrend/base/interfaces/event/RecyclerChangeListener.java b/app/src/main/java/com/mxt/anitrend/base/interfaces/event/RecyclerChangeListener.java
index d7d5c4a0f..ba7f5132f 100644
--- a/app/src/main/java/com/mxt/anitrend/base/interfaces/event/RecyclerChangeListener.java
+++ b/app/src/main/java/com/mxt/anitrend/base/interfaces/event/RecyclerChangeListener.java
@@ -1,6 +1,6 @@
package com.mxt.anitrend.base.interfaces.event;
-import android.support.annotation.NonNull;
+import androidx.annotation.NonNull;
import java.util.List;
diff --git a/app/src/main/java/com/mxt/anitrend/base/interfaces/event/ResponseCallback.java b/app/src/main/java/com/mxt/anitrend/base/interfaces/event/ResponseCallback.java
deleted file mode 100644
index 8cbbe3b17..000000000
--- a/app/src/main/java/com/mxt/anitrend/base/interfaces/event/ResponseCallback.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.mxt.anitrend.base.interfaces.event;
-
-/**
- * Created by max on 2017/10/15.
- * Callback for view model to communicate
- * with parent class or activity after a request
- */
-
-public interface ResponseCallback {
-
- void showError(String error);
-
- void showEmpty(String message);
-}
diff --git a/app/src/main/java/com/mxt/anitrend/base/interfaces/event/ResponseCallback.kt b/app/src/main/java/com/mxt/anitrend/base/interfaces/event/ResponseCallback.kt
new file mode 100644
index 000000000..9613f2153
--- /dev/null
+++ b/app/src/main/java/com/mxt/anitrend/base/interfaces/event/ResponseCallback.kt
@@ -0,0 +1,14 @@
+package com.mxt.anitrend.base.interfaces.event
+
+/**
+ * Created by max on 2017/10/15.
+ * Callback for view model to communicate
+ * with parent class or activity after a request
+ */
+
+interface ResponseCallback {
+
+ fun showError(error: String)
+
+ fun showEmpty(message: String)
+}
diff --git a/app/src/main/java/com/mxt/anitrend/base/interfaces/event/RetroCallback.java b/app/src/main/java/com/mxt/anitrend/base/interfaces/event/RetroCallback.java
index c7617dcea..d70185229 100644
--- a/app/src/main/java/com/mxt/anitrend/base/interfaces/event/RetroCallback.java
+++ b/app/src/main/java/com/mxt/anitrend/base/interfaces/event/RetroCallback.java
@@ -1,6 +1,6 @@
package com.mxt.anitrend.base.interfaces.event;
-import android.support.annotation.NonNull;
+import androidx.annotation.NonNull;
import retrofit2.Call;
import retrofit2.Callback;
diff --git a/app/src/main/java/com/mxt/anitrend/binding/ImageExtensions.kt b/app/src/main/java/com/mxt/anitrend/binding/ImageExtensions.kt
new file mode 100644
index 000000000..67df9081f
--- /dev/null
+++ b/app/src/main/java/com/mxt/anitrend/binding/ImageExtensions.kt
@@ -0,0 +1,24 @@
+package com.mxt.anitrend.binding
+
+import androidx.databinding.BindingAdapter
+import com.bumptech.glide.Glide
+import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
+import com.bumptech.glide.request.RequestOptions
+import com.mxt.anitrend.R
+import com.mxt.anitrend.base.custom.view.image.AvatarImageView
+import com.mxt.anitrend.model.entity.anilist.meta.ImageBase
+
+
+@BindingAdapter("avatarUrl")
+fun AvatarImageView.setImage(url: String?) {
+ Glide.with(context).load(url).apply(RequestOptions.centerCropTransform())
+ .apply(RequestOptions.placeholderOf(R.drawable.avatar_placeholder))
+ .transition(DrawableTransitionOptions.withCrossFade(150))
+ .apply(RequestOptions.circleCropTransform())
+ .into(this)
+}
+
+@BindingAdapter("avatarUrl")
+fun AvatarImageView.setImage(imageBase: ImageBase?) {
+ setImage(imageBase?.large)
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/mxt/anitrend/binding/RatingTextExtensions.kt b/app/src/main/java/com/mxt/anitrend/binding/RatingTextExtensions.kt
new file mode 100644
index 000000000..5977079d0
--- /dev/null
+++ b/app/src/main/java/com/mxt/anitrend/binding/RatingTextExtensions.kt
@@ -0,0 +1,21 @@
+package com.mxt.anitrend.binding
+
+import androidx.databinding.BindingAdapter
+import com.mxt.anitrend.base.custom.view.text.RatingTextView
+import com.mxt.anitrend.model.entity.anilist.MediaList
+import com.mxt.anitrend.model.entity.base.MediaBase
+
+
+@BindingAdapter("rating")
+fun RatingTextView.setAverageRating(mediaBase: MediaBase) {
+ setRating(mediaBase)
+ setListStatus(mediaBase)
+ setFavourState(mediaBase.isFavourite)
+}
+
+@BindingAdapter("rating")
+fun RatingTextView.setAverageRating(mediaList: MediaList) {
+ setListStatus()
+ setRating(mediaList)
+ setFavourState(mediaList.media.isFavourite)
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/mxt/anitrend/binding/RichMarkdownExtensions.kt b/app/src/main/java/com/mxt/anitrend/binding/RichMarkdownExtensions.kt
index fcefeec39..b830cfd21 100644
--- a/app/src/main/java/com/mxt/anitrend/binding/RichMarkdownExtensions.kt
+++ b/app/src/main/java/com/mxt/anitrend/binding/RichMarkdownExtensions.kt
@@ -1,45 +1,44 @@
package com.mxt.anitrend.binding
-import android.databinding.BindingAdapter
-import android.support.annotation.StringRes
import android.text.Html
import android.widget.TextView
+import androidx.annotation.StringRes
+import androidx.databinding.BindingAdapter
import com.mxt.anitrend.base.custom.view.text.RichMarkdownTextView
-import com.mxt.anitrend.util.MarkDownUtil
-import com.mxt.anitrend.util.RegexUtil
+import com.mxt.anitrend.util.markdown.MarkDownUtil
+import com.mxt.anitrend.util.markdown.RegexUtil
@BindingAdapter("markDown")
-fun markDown(richMarkdownTextView: RichMarkdownTextView, markdown: String?) {
+fun RichMarkdownTextView.markDown(markdown: String?) {
val strippedText = RegexUtil.removeTags(markdown)
- val markdownSpan = MarkDownUtil.convert(strippedText, richMarkdownTextView.context, richMarkdownTextView)
- richMarkdownTextView.setText(markdownSpan, TextView.BufferType.SPANNABLE)
+ val markdownSpan = MarkDownUtil.convert(strippedText)
+ setText(markdownSpan, TextView.BufferType.SPANNABLE)
}
@BindingAdapter("textHtml")
-fun htmlText(richMarkdownTextView: RichMarkdownTextView, html: String?) {
- val markdownSpan = MarkDownUtil.convert(html, richMarkdownTextView.context, richMarkdownTextView)
- richMarkdownTextView.setText(markdownSpan, TextView.BufferType.SPANNABLE)
+fun RichMarkdownTextView.htmlText(html: String?) {
+ val markdownSpan = MarkDownUtil.convert(html)
+ setText(markdownSpan, TextView.BufferType.SPANNABLE)
}
@BindingAdapter("basicHtml")
-fun basicText(richMarkdownTextView: RichMarkdownTextView, html: String?) {
+fun RichMarkdownTextView.basicText(html: String?) {
val htmlSpan = Html.fromHtml(html)
- richMarkdownTextView.text = htmlSpan
+ text = htmlSpan
}
@BindingAdapter("textHtml")
-fun htmlText(richMarkdownTextView: RichMarkdownTextView, @StringRes resId: Int) {
- val text = richMarkdownTextView.context.getString(resId)
- val markdownSpan = MarkDownUtil.convert(text, richMarkdownTextView.context, richMarkdownTextView)
- richMarkdownTextView.setText(markdownSpan, TextView.BufferType.SPANNABLE)
+fun RichMarkdownTextView.htmlText(@StringRes resId: Int) {
+ val text = context.getString(resId)
+ val markdownSpan = MarkDownUtil.convert(text)
+ setText(markdownSpan, TextView.BufferType.SPANNABLE)
}
@BindingAdapter("richMarkDown")
-fun richMarkDown(richMarkdownTextView: RichMarkdownTextView, markdown: String?) {
- richMarkdownTextView.also {
- val tagsStripped = RegexUtil.removeTags(markdown)
- val userTagsConverted = RegexUtil.findUserTags(tagsStripped)
- val standardMarkdown = RegexUtil.convertToStandardMarkdown(userTagsConverted)
- it.markwon.setMarkdown(it, standardMarkdown)
- }
+fun RichMarkdownTextView.richMarkDown(markdown: String?) {
+ val tagsStripped = RegexUtil.removeTags(markdown)
+ val userTagsConverted = RegexUtil.findUserTags(tagsStripped)
+ val standardMarkdown = RegexUtil.convertToStandardMarkdown(userTagsConverted)
+ markwon.setMarkdown(this, standardMarkdown)
+
}
\ No newline at end of file
diff --git a/app/src/main/java/com/mxt/anitrend/data/DatabaseHelper.kt b/app/src/main/java/com/mxt/anitrend/data/DatabaseHelper.kt
index a59f9e5e0..f0ea9c289 100644
--- a/app/src/main/java/com/mxt/anitrend/data/DatabaseHelper.kt
+++ b/app/src/main/java/com/mxt/anitrend/data/DatabaseHelper.kt
@@ -1,8 +1,5 @@
package com.mxt.anitrend.data
-import android.content.Context
-
-import com.mxt.anitrend.App
import com.mxt.anitrend.base.interfaces.dao.BoxQuery
import com.mxt.anitrend.model.entity.anilist.Genre
import com.mxt.anitrend.model.entity.anilist.MediaTag
@@ -12,23 +9,20 @@ import com.mxt.anitrend.model.entity.base.AuthBase
import com.mxt.anitrend.model.entity.base.NotificationHistory
import com.mxt.anitrend.model.entity.base.UserBase
import com.mxt.anitrend.model.entity.base.VersionBase
-
import io.objectbox.Box
import io.objectbox.BoxStore
+import org.koin.core.KoinComponent
+import org.koin.core.inject
+import java.util.*
/**
* Created by max on 2017/11/02.
* Database helper class
*/
-class DatabaseHelper(context: Context) : BoxQuery {
-
- private val boxStore: BoxStore by lazy {
- (context.applicationContext as App).boxStore
- }
+class DatabaseHelper : BoxQuery, KoinComponent {
- // Frequently used instance variables
- private var user: User? = null
+ private val boxStore by inject()
/**
* Gets the object box from a requested class type.
@@ -55,126 +49,93 @@ class DatabaseHelper(context: Context) : BoxQuery {
/**
* Gets current authenticated user
*/
- override fun getCurrentUser(): User? {
- if (user == null)
- user = getBoxStore(User::class.java).query()
+ override var currentUser: User? = null
+ get() {
+ return getBoxStore(User::class.java).query()
.build().findFirst()
- return user
- }
-
+ }
+ set(value) {
+ field = value
+ if (value != null)
+ getBoxStore(User::class.java).put(value)
+ }
/**
* Get default authentication code
*/
- override fun getAuthCode(): AuthBase? {
- return getBoxStore(AuthBase::class.java)
+ override var authCode: AuthBase? = null
+ get() = getBoxStore(AuthBase::class.java)
.query()
.build()
.findFirst()
- }
+ set(value) {
+ field = value
+ if (value != null) {
+ getBoxStore(AuthBase::class.java).removeAll()
+ getBoxStore(AuthBase::class.java).put(value)
+ }
+ }
/**
* Get web token
*/
- override fun getWebToken(): WebToken? {
- return getBoxStore(WebToken::class.java)
+ override var webToken: WebToken? = null
+ get() = getBoxStore(WebToken::class.java)
.query()
.build()
.findFirst()
- }
-
+ set(value) {
+ field = value
+ if (value != null) {
+ getBoxStore(WebToken::class.java).removeAll()
+ getBoxStore(WebToken::class.java).put(value)
+ }
+ }
/**
* Get the application version on github
*/
- override fun getRemoteVersion(): VersionBase? {
- return getBoxStore(VersionBase::class.java)
- .query()
- .build()
- .findFirst()
- }
-
+ override var remoteVersion: VersionBase? = null
+ get() = getBoxStore(VersionBase::class.java)
+ .query().build().findFirst()
+ set(value) {
+ field = value
+ if (value != null) {
+ val versionBox = getBoxStore(VersionBase::class.java)
+ if (versionBox.count() != 0L)
+ versionBox.removeAll()
+ value.lastChecked = System.currentTimeMillis()
+ versionBox.put(value)
+ }
+ }
/**
* Gets all saved tags
*/
- override fun getMediaTags(): List {
- return getBoxStore(MediaTag::class.java)
+ override var mediaTags: List = Collections.emptyList()
+ get() = getBoxStore(MediaTag::class.java)
.query()
.build()
.findLazy()
- }
-
+ set(value) {
+ field = value
+ if (value.isNotEmpty()) {
+ val tagBox = getBoxStore(MediaTag::class.java)
+ if (tagBox.count() < value.size)
+ tagBox.put(value)
+ }
+ }
/**
* Gets all saved genres
*/
- override fun getGenreCollection(): List {
- return getBoxStore(Genre::class.java)
+ override var genreCollection: List