个人中心插件化

This commit is contained in:
Yutousama 2018-04-19 10:50:27 +08:00
parent 1501e1dc94
commit 1fe7c3ba86
9 changed files with 88 additions and 123 deletions

View File

@ -28,6 +28,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

View File

@ -1,8 +1,11 @@
package com.yutou.jianrmg_v2.basemodel.Fragments; package com.yutou.jianrmg_v2.basemodel.Fragments;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -21,12 +24,14 @@ import com.yutou.jianrmg_v2.basemodel.Data.AppData;
import com.yutou.jianrmg_v2.basemodel.Data.UUserdata; import com.yutou.jianrmg_v2.basemodel.Data.UUserdata;
import com.yutou.jianrmg_v2.basemodel.Data.User; import com.yutou.jianrmg_v2.basemodel.Data.User;
import com.yutou.jianrmg_v2.basemodel.R; import com.yutou.jianrmg_v2.basemodel.R;
import com.yutou.jianrmg_v2.basemodel.Tools.Log;
import com.yutou.jianrmg_v2.basemodel.Tools.Utils; import com.yutou.jianrmg_v2.basemodel.Tools.Utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import Interfaces.BaseFragmeneInerface;
import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.BlurTransformation;
import static com.bumptech.glide.request.RequestOptions.bitmapTransform; import static com.bumptech.glide.request.RequestOptions.bitmapTransform;
@ -38,69 +43,50 @@ import static com.bumptech.glide.request.RequestOptions.bitmapTransform;
public class My extends Fragment { public class My extends Fragment {
public static My my; public static My my;
public static My init(){ private BaseFragmeneInerface baseFragmeneInerface;
public static My init(Activity activity){
if(my==null){ if(my==null){
my=new My(); my=new My();
} }
return my; return my;
} }
private View view; public My(){
private User user; try {
private UUserdata udata; this.baseFragmeneInerface = (BaseFragmeneInerface) AppData.plugsin.get("my.jar").loadClass("com.yutou.jianrmg_v2.mglistmodel.MainFragments").newInstance();
private ImageLoader imageLoader; } catch (Exception e) {
e.printStackTrace();
Log.i("个人中心插件加载失败");
baseFragmeneInerface = new BaseFragmeneInerface() {
private Context context;
private TextView uname,item_title; @Override
private ImageView icon,item_icon,image_top; public void init(Context context) {
// private LinearLayout items; this.context = context;
private ListView myItems; }
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
ViewGroup.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
TextView textView = new TextView(context);
textView.setLayoutParams(params);
textView.setGravity(Gravity.CENTER);
textView.setText("未加载插件,请尝试重启");
return textView;
}
@Override
public void setIntent() {
}
};
}
}
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if(view==null){
view=LayoutInflater.from(getContext()).inflate(R.layout.fragment_my,null); return baseFragmeneInerface.onCreateView(inflater, container, savedInstanceState);
uname=view.findViewById(R.id.uname);
icon=view.findViewById(R.id.icon);
item_title=view.findViewById(R.id.item_title);
item_icon=view.findViewById(R.id.item_icon);
image_top=view.findViewById(R.id.image_top);
// items=view.findViewById(R.id.items);
myItems=view.findViewById(R.id._my_items);
}
imageLoader= Utils.initImageLoader(getContext());
initData();
return view;
}
private void initData(){
user= AppData.user;
udata=AppData.userdata;
if(udata==null)
udata=new UUserdata();
udata.setImage("https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=1209476926,1108056910&fm=58");
if(user==null||user.getId()<1){
uname.setText("未登录");
icon.setImageResource(R.mipmap.ic_launcher);
return;
}
try {
uname.setText(user.getName());
imageLoader.displayImage(udata.getImage(),icon);
Glide.with(this).load(udata.getImage()).apply(bitmapTransform(new BlurTransformation(25))).into(image_top);
}catch (Exception e){
e.printStackTrace();
}
myItems.setAdapter(new MyItemGridViewAdapter(getItemData(),getContext()));
}
private List<MyItemGridViewAdapter.ItemData> getItemData(){
List<MyItemGridViewAdapter.ItemData> list=new ArrayList<>();
list.add(new MyItemGridViewAdapter.ItemData(-1,"下载中心"));
list.add(new MyItemGridViewAdapter.ItemData(-1,"收藏夹"));
list.add(new MyItemGridViewAdapter.ItemData(-1,"问题/建议"));
list.add(new MyItemGridViewAdapter.ItemData(-1,"设置"));
/* list.add(new MyItemGridViewAdapter.ItemData(-1,""));
list.add(new MyItemGridViewAdapter.ItemData(-1,""));
list.add(new MyItemGridViewAdapter.ItemData(-1,""));
list.add(new MyItemGridViewAdapter.ItemData(-1,""));*/
return list;
} }
} }

View File

@ -41,7 +41,7 @@ public class MainActivity extends AppCompatActivity {
list.add(Home.init(this)); list.add(Home.init(this));
list.add(GameData.init(this)); list.add(GameData.init(this));
list.add(MGList.init(this)); list.add(MGList.init(this));
list.add(My.init()); list.add(My.init(this));
ViewPagerAdapter adapter=new ViewPagerAdapter(getSupportFragmentManager(),list); ViewPagerAdapter adapter=new ViewPagerAdapter(getSupportFragmentManager(),list);
viewPager.setAdapter(adapter); viewPager.setAdapter(adapter);

View File

@ -1,18 +1,19 @@
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
android { android {
compileSdkVersion 27 compileSdkVersion 26
defaultConfig { defaultConfig {
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 27 targetSdkVersion 26
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {
@ -27,8 +28,17 @@ android {
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:appcompat-v7:26.1.0'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
//
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
//FastJson
implementation 'com.alibaba:fastjson:1.2.41'
//
implementation 'jp.wasabeef:glide-transformations:3.0.0'
api project(path: ':BaseModel')
api project(path: ':ResModl')
} }

View File

@ -68,5 +68,6 @@ dependencies {
api project(path: ':AppHome') api project(path: ':AppHome')
api project(path: ':MgListModel') api project(path: ':MgListModel')
api project(path: ':ResModl') api project(path: ':ResModl')
api project(path: ':UserModel')
} }

View File

@ -1,12 +1,16 @@
package com.yutou.jianrmg_v2.Fragments; package com.yutou.jianrmg_v2.Fragments;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
@ -17,11 +21,13 @@ import com.yutou.jianrmg_v2.basemodel.Data.AppData;
import com.yutou.jianrmg_v2.basemodel.Data.UUserdata; import com.yutou.jianrmg_v2.basemodel.Data.UUserdata;
import com.yutou.jianrmg_v2.basemodel.Data.User; import com.yutou.jianrmg_v2.basemodel.Data.User;
import com.yutou.jianrmg_v2.basemodel.R; import com.yutou.jianrmg_v2.basemodel.R;
import com.yutou.jianrmg_v2.basemodel.Tools.Log;
import com.yutou.jianrmg_v2.basemodel.Tools.Utils; import com.yutou.jianrmg_v2.basemodel.Tools.Utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import Interfaces.BaseFragmeneInerface;
import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.BlurTransformation;
import static com.bumptech.glide.request.RequestOptions.bitmapTransform; import static com.bumptech.glide.request.RequestOptions.bitmapTransform;
@ -33,69 +39,29 @@ import static com.bumptech.glide.request.RequestOptions.bitmapTransform;
public class My extends Fragment { public class My extends Fragment {
public static My my; public static My my;
public static My init(){ private BaseFragmeneInerface baseFragmeneInerface;
public static My init(Activity activity){
if(my==null){ if(my==null){
my=new My(); my=new My();
my.baseFragmeneInerface.init(activity);
} }
return my; return my;
} }
private View view; public My(){
private User user; try {
private UUserdata udata; this.baseFragmeneInerface = (BaseFragmeneInerface) AppData.plugsin.get("my.jar").loadClass("com.yutou.jianrmg_v2.mglistmodel.MainFragments").newInstance();
private ImageLoader imageLoader; } catch (Exception e) {
e.printStackTrace();
private TextView uname,item_title; Log.i("个人中心插件加载失败");
private ImageView icon,item_icon,image_top; baseFragmeneInerface =new com.jianrmg_v2.usermodel.MainFragments();
// private LinearLayout items; }
private ListView myItems; }
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if(view==null){
view=LayoutInflater.from(getContext()).inflate(R.layout.fragment_my,null); return baseFragmeneInerface.onCreateView(inflater, container, savedInstanceState);
uname=view.findViewById(R.id.uname);
icon=view.findViewById(R.id.icon);
item_title=view.findViewById(R.id.item_title);
item_icon=view.findViewById(R.id.item_icon);
image_top=view.findViewById(R.id.image_top);
// items=view.findViewById(R.id.items);
myItems=view.findViewById(R.id._my_items);
}
imageLoader= Utils.initImageLoader(getContext());
initData();
return view;
}
private void initData(){
user= AppData.user;
udata=AppData.userdata;
if(udata==null)
udata=new UUserdata();
udata.setImage("https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=1209476926,1108056910&fm=58");
if(user==null||user.getId()<1){
uname.setText("未登录");
icon.setImageResource(R.mipmap.ic_launcher);
return;
}
try {
uname.setText(user.getName());
imageLoader.displayImage(udata.getImage(),icon);
Glide.with(this).load(udata.getImage()).apply(bitmapTransform(new BlurTransformation(25))).into(image_top);
}catch (Exception e){
e.printStackTrace();
}
myItems.setAdapter(new MyItemGridViewAdapter(getItemData(),getContext()));
}
private List<MyItemGridViewAdapter.ItemData> getItemData(){
List<MyItemGridViewAdapter.ItemData> list=new ArrayList<>();
list.add(new MyItemGridViewAdapter.ItemData(-1,"下载中心"));
list.add(new MyItemGridViewAdapter.ItemData(-1,"收藏夹"));
list.add(new MyItemGridViewAdapter.ItemData(-1,"问题/建议"));
list.add(new MyItemGridViewAdapter.ItemData(-1,"设置"));
/* list.add(new MyItemGridViewAdapter.ItemData(-1,""));
list.add(new MyItemGridViewAdapter.ItemData(-1,""));
list.add(new MyItemGridViewAdapter.ItemData(-1,""));
list.add(new MyItemGridViewAdapter.ItemData(-1,""));*/
return list;
} }
} }

View File

@ -73,18 +73,18 @@ public class LoadingActivity extends AppCompatActivity {
start(); start();
} }
}catch (Exception e){ }catch (Exception e){
e.printStackTrace();
} }
} }
@Override @Override
public void httpError(Exception e) { public void httpError(Exception e) {
e.printStackTrace();
} }
}); });
}catch (Exception e){ }catch (Exception e){
e.printStackTrace();
} }
} }
private void initData(){ private void initData(){
@ -114,17 +114,17 @@ public class LoadingActivity extends AppCompatActivity {
} }
ready(1); ready(1);
}catch (Exception e){ }catch (Exception e){
e.printStackTrace();
} }
} }
@Override @Override
public void httpError(Exception e) { public void httpError(Exception e) {
e.printStackTrace();
} }
}); });
}catch (Exception e){ }catch (Exception e){
e.printStackTrace();
} }
} }
private void initGamePackName(){ private void initGamePackName(){
@ -144,11 +144,11 @@ public class LoadingActivity extends AppCompatActivity {
@Override @Override
public void httpError(Exception e) { public void httpError(Exception e) {
e.printStackTrace();
} }
}); });
}catch (Exception e){ }catch (Exception e){
e.printStackTrace();
} }
} }
private void initUser(){ private void initUser(){
@ -178,7 +178,7 @@ public class LoadingActivity extends AppCompatActivity {
} }
}); });
}catch (Exception e){ }catch (Exception e){
e.printStackTrace();
} }
} }
@ -244,6 +244,7 @@ public class LoadingActivity extends AppCompatActivity {
private int readys=0; private int readys=0;
private void ready(int i){ private void ready(int i){
readys+=i; readys+=i;
Log.i(readys+"");
if(readys==3){ if(readys==3){
handler.postDelayed(new Runnable() { handler.postDelayed(new Runnable() {
@Override @Override

View File

@ -42,7 +42,7 @@ public class MainActivity extends AppCompatActivity {
list.add(Home.init(this)); list.add(Home.init(this));
list.add(GameData.init(this)); list.add(GameData.init(this));
list.add(MGList.init(this)); list.add(MGList.init(this));
list.add(My.init()); list.add(My.init(this));
ViewPagerAdapter adapter=new ViewPagerAdapter(getSupportFragmentManager(),list); ViewPagerAdapter adapter=new ViewPagerAdapter(getSupportFragmentManager(),list);
viewPager.setAdapter(adapter); viewPager.setAdapter(adapter);