Skip to content

Commit

Permalink
弃用datachannel,使用Container(UUID + HashMap)作为传值中间件
Browse files Browse the repository at this point in the history
  • Loading branch information
CeuiLiSA committed Jun 24, 2020
1 parent af31fc9 commit 53724a8
Show file tree
Hide file tree
Showing 21 changed files with 874 additions and 126 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId "ceui.lisa.pixiv"
minSdkVersion 21
targetSdkVersion 28
versionCode 96
versionName "1.9.6"
versionCode 97
versionName "1.9.7"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
android:scheme="https" />
</intent-filter>
</activity>
<activity android:name=".activities.ViewPagerActivity" />
<activity
android:name=".activities.TemplateActivity"
android:windowSoftInputMode="adjustPan" />
Expand Down Expand Up @@ -104,6 +103,7 @@
</activity>
<activity android:name=".activities.UserActivity" />
<activity android:name=".activities.SearchActivity" />
<activity android:name=".activities.VActivity" />
</application>

</manifest>
4 changes: 1 addition & 3 deletions app/src/main/java/ceui/lisa/activities/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;

import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.DeviceUtils;
import com.blankj.utilcode.util.RomUtils;
import com.bumptech.glide.Glide;
import com.google.android.material.navigation.NavigationView;
import com.tbruyelle.rxpermissions2.RxPermissions;
Expand Down Expand Up @@ -319,5 +316,6 @@ protected void onResume() {
initDrawerHeader();
Dev.refreshUser = false;
}
// Container.get().clear();
}
}
67 changes: 67 additions & 0 deletions app/src/main/java/ceui/lisa/activities/VActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package ceui.lisa.activities;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter;


import ceui.lisa.R;
import ceui.lisa.core.PageData;
import ceui.lisa.databinding.ActivityViewPagerBinding;
import ceui.lisa.fragments.FragmentIllust;
import ceui.lisa.core.Container;
import ceui.lisa.fragments.FragmentSingleIllust2;
import ceui.lisa.utils.Params;

public class VActivity extends BaseActivity<ActivityViewPagerBinding> {

private String pageUUID = "";
private int index = 0;

@Override
protected void initBundle(Bundle bundle) {
pageUUID = bundle.getString(Params.PAGE_UUID);
index = bundle.getInt(Params.POSITION);
}

@Override
protected int initLayout() {
return R.layout.activity_view_pager;
}

@Override
protected void initView() {
PageData pageData = Container.get().getPage(pageUUID);
if (pageData != null) {
final int pageSize = pageData.getIllustList() == null ? 0 : pageData.getIllustList().size();
baseBind.viewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager(), 0) {
@NonNull
@Override
public Fragment getItem(int position) {
// return FragmentIllust.newInstance(pageData.getIllustList().get(position));
return FragmentSingleIllust2.newInstance(pageData.getIllustList().get(position));
}

@Override
public int getCount() {
return pageSize;
}
});
if (index < pageSize) {
baseBind.viewPager.setCurrentItem(index);
}
}
}

@Override
protected void initData() {

}

@Override
public boolean hideStatusBar() {
return true;
}
}
31 changes: 14 additions & 17 deletions app/src/main/java/ceui/lisa/adapters/IAdapter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ceui.lisa.adapters;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.ColorStateList;
Expand All @@ -11,7 +10,6 @@

import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
Expand All @@ -21,28 +19,24 @@

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import ceui.lisa.R;
import ceui.lisa.activities.Shaft;
import ceui.lisa.activities.TemplateActivity;
import ceui.lisa.activities.ViewPagerActivity;
import ceui.lisa.activities.VActivity;
import ceui.lisa.core.PageData;
import ceui.lisa.databinding.RecyIllustStaggerBinding;
import ceui.lisa.dialogs.MuteDialog;
import ceui.lisa.fragments.FragmentLikeIllust;
import ceui.lisa.http.NullCtrl;
import ceui.lisa.http.Retro;
import ceui.lisa.interfaces.MultiDownload;
import ceui.lisa.interfaces.OnItemClickListener;
import ceui.lisa.model.ListIllust;
import ceui.lisa.models.IllustsBean;
import ceui.lisa.utils.Common;
import ceui.lisa.utils.DataChannel;
import ceui.lisa.core.Container;
import ceui.lisa.utils.GlideUtil;
import ceui.lisa.utils.Params;
import ceui.lisa.utils.PixivOperate;
import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import jp.wasabeef.glide.transformations.BlurTransformation;

import static ceui.lisa.activities.Shaft.sUserModel;
Expand Down Expand Up @@ -101,7 +95,7 @@ public void onClick(View v) {
bindView.baseBind.likeButton.setImageTintList(
ColorStateList.valueOf(ContextCompat.getColor(mContext, R.color.not_bookmarked)));
} else {
getRelated(target, position);
// getRelated(target, position);
bindView.baseBind.likeButton.setImageTintList(
ColorStateList.valueOf(ContextCompat.getColor(mContext, R.color.has_bookmarked)));
}
Expand All @@ -112,7 +106,7 @@ public void onClick(View v) {
@Override
public boolean onLongClick(View v) {
if (!target.isIs_bookmarked()) {
getRelated(target, position);
// getRelated(target, position);
Intent intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(Params.ILLUST_ID, target.getId());
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "按标签收藏");
Expand Down Expand Up @@ -200,12 +194,15 @@ private void handleClick() {
setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(View v, int position, int viewType) {
DataChannel.get().setIllustList(allIllust);
Intent intent = new Intent(mContext, ViewPagerActivity.class);
intent.putExtra("position", position);
final String uuid = UUID.randomUUID().toString();
final List<IllustsBean> tempList = new ArrayList<>(allIllust);
final PageData pageData = new PageData(uuid, tempList);
Container.get().addPage(pageData);

Intent intent = new Intent(mContext, VActivity.class);
intent.putExtra(Params.POSITION, position);
intent.putExtra(Params.PAGE_UUID, uuid);
mContext.startActivity(intent);
// ((Activity)mContext).overridePendingTransition(R.anim.zoom_enter,
// R.anim.zoom_exit);
}
});
}
Expand Down
46 changes: 23 additions & 23 deletions app/src/main/java/ceui/lisa/adapters/IAdapterWithHeadView.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,29 @@ public void setHeadData(List<IllustsBean> illustsBeans) {
}
}

@Override
public void getRelated(IllustsBean illust, int position) {
Retro.getAppApi().relatedIllust(sUserModel.getResponse().getAccess_token(), illust.getId())
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new NullCtrl<ListIllust>() {
@Override
public void success(ListIllust listIllust) {
if (listIllust.getIllusts() != null) {
final int realP = position + 1;
if (listIllust.getIllusts().size() >= 6) {
List<IllustsBean> related = new ArrayList<>();
for (int i = 0; i < 6; i++) {
related.add(listIllust.getIllusts().get(i));
}
allIllust.addAll(realP, related);
notifyItemRangeInserted(realP, related.size());
notifyItemRangeChanged(realP, allIllust.size() - realP);
}
}
}
});
}
// @Override
// public void getRelated(IllustsBean illust, int position) {
// Retro.getAppApi().relatedIllust(sUserModel.getResponse().getAccess_token(), illust.getId())
// .subscribeOn(Schedulers.newThread())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(new NullCtrl<ListIllust>() {
// @Override
// public void success(ListIllust listIllust) {
// if (listIllust.getIllusts() != null) {
// final int realP = position + 1;
// if (listIllust.getIllusts().size() >= 6) {
// List<IllustsBean> related = new ArrayList<>();
// for (int i = 0; i < 6; i++) {
// related.add(listIllust.getIllusts().get(i));
// }
// allIllust.addAll(realP, related);
// notifyItemRangeInserted(realP, related.size());
// notifyItemRangeChanged(realP, allIllust.size() - realP);
// }
// }
// }
// });
// }

@Override
public void onViewAttachedToWindow(@NonNull RecyclerView.ViewHolder holder) {
Expand Down
30 changes: 20 additions & 10 deletions app/src/main/java/ceui/lisa/adapters/IllustHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.PagerSnapHelper;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import ceui.lisa.activities.RankActivity;
import ceui.lisa.activities.ViewPagerActivity;
import ceui.lisa.adapters.RAdapter;
import ceui.lisa.adapters.ViewHolder;
import ceui.lisa.activities.VActivity;
import ceui.lisa.core.PageData;
import ceui.lisa.databinding.RecyRecmdHeaderBinding;
import ceui.lisa.models.IllustsBean;
import ceui.lisa.utils.DataChannel;
import ceui.lisa.core.Container;
import ceui.lisa.utils.DensityUtil;
import ceui.lisa.utils.Params;
import ceui.lisa.view.LinearItemHorizontalDecoration;

public class IllustHeader extends ViewHolder<RecyRecmdHeaderBinding> {
Expand All @@ -36,10 +35,21 @@ public void show(Context context, List<IllustsBean> illustsBeans) {
baseBind.topRela.startAnimation(animation);
RAdapter adapter = new RAdapter(illustsBeans, context);
adapter.setOnItemClickListener((v, position, viewType) -> {
DataChannel.get().setIllustList(illustsBeans);
Intent intent = new Intent(context, ViewPagerActivity.class);
intent.putExtra("position", position);
final String uuid = UUID.randomUUID().toString();
final List<IllustsBean> tempList = new ArrayList<>(illustsBeans);
final PageData pageData = new PageData(uuid, tempList);
Container.get().addPage(pageData);

Intent intent = new Intent(context, VActivity.class);
intent.putExtra(Params.POSITION, position);
intent.putExtra(Params.PAGE_UUID, uuid);
context.startActivity(intent);


// DataChannel.get().setIllustList(illustsBeans);
// Intent intent = new Intent(context, ViewPagerActivity.class);
// intent.putExtra("position", position);
// context.startActivity(intent);
});
baseBind.ranking.setAdapter(adapter);
}
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/ceui/lisa/adapters/NovelHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import java.util.List;

import ceui.lisa.activities.RankActivity;
import ceui.lisa.activities.TemplateActivity;
import ceui.lisa.activities.ViewPagerActivity;
import ceui.lisa.databinding.RecyRecmdHeaderBinding;
import ceui.lisa.models.IllustsBean;
import ceui.lisa.models.NovelBean;
import ceui.lisa.utils.DataChannel;
import ceui.lisa.utils.DensityUtil;
import ceui.lisa.utils.Params;
import ceui.lisa.view.LinearItemHorizontalDecoration;
Expand Down
63 changes: 63 additions & 0 deletions app/src/main/java/ceui/lisa/core/Container.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package ceui.lisa.core;

import android.text.TextUtils;

import java.util.HashMap;

import ceui.lisa.utils.Common;

public class Container {

private HashMap<String, PageData> pages = new HashMap<>();

public void addPage(PageData pageData) {
if (pageData == null) {
return;
}

if (TextUtils.isEmpty(pageData.getUuid())) {
return;
}

if (pages == null) {
pages = new HashMap<>();
}

pages.put(pageData.getUuid(), pageData);
Common.showLog("Container addPage " + pageData.getUuid());
}

public PageData getPage(String uuid) {
Common.showLog("Container getPage " + uuid);
if (TextUtils.isEmpty(uuid)) {
return null;
}

if (pages == null || pages.size() == 0) {
return null;
}

return pages.get(uuid);
}

public void clear() {
Common.showLog("Container clear ");
if (pages == null) {
pages = new HashMap<>();
return;
}
if (pages.size() != 0) {
pages.clear();
}
}

private Container(){}

private static class SingleTonHolder{
private static Container INSTANCE = new Container();
}

public static Container get(){
return SingleTonHolder.INSTANCE;
}
}
Loading

0 comments on commit 53724a8

Please sign in to comment.