|
|
@@ -14,24 +14,24 @@ import android.widget.TextView;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
-import com.sheep.gamegroup.model.entity.CheckUserLabel;
|
|
|
import com.sheep.gamegroup.model.entity.CreditCard;
|
|
|
import com.sheep.gamegroup.model.entity.DialogConfig;
|
|
|
+import com.sheep.gamegroup.model.entity.LoginEntity;
|
|
|
+import com.sheep.gamegroup.model.entity.LoginUser;
|
|
|
import com.sheep.gamegroup.model.entity.TaskEty;
|
|
|
-import com.sheep.gamegroup.model.entity.UserLabel;
|
|
|
-import com.sheep.gamegroup.model.entity.UserLabelList;
|
|
|
+import com.sheep.gamegroup.model.entity.UserEntity;
|
|
|
import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
import com.sheep.jiuyan.samllsheep.BuildConfig;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
|
import com.umeng.socialize.ShareAction;
|
|
|
import com.umeng.socialize.UMShareListener;
|
|
|
import com.umeng.socialize.bean.SHARE_MEDIA;
|
|
|
import com.umeng.socialize.media.UMImage;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
|
|
|
@@ -173,6 +173,71 @@ public class TestUtil {
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
+ public static void testChangeUser(final Activity activity, TextView test_change) {
|
|
|
+ if (isTest()) {
|
|
|
+ final List<LoginUser> loginUserList = MyDbManager.getInstance().getAllLoginUser();
|
|
|
+ if(ListUtil.isEmpty(loginUserList)){
|
|
|
+ G.showToast("无用户");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ final List<Object> list = ListUtil.emptyList();
|
|
|
+ ListUtil.addAll(list, loginUserList);
|
|
|
+
|
|
|
+ test_change.setVisibility(View.VISIBLE);
|
|
|
+ test_change.setText("切换账号");
|
|
|
+ test_change.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ AlertDialog dialog = new AlertDialog.Builder(activity).setTitle("选择要登录的账号")
|
|
|
+ .setAdapter(new ArrayAdapter<>(activity, android.R.layout.simple_list_item_single_choice, list), new DialogInterface.OnClickListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialogInterface, int which) {
|
|
|
+ Object object = ListUtil.getIndex(list, which);
|
|
|
+ if(object instanceof LoginUser){
|
|
|
+ SpUtils.login(activity, ((LoginUser) object).getToken());
|
|
|
+ Jump2View.getInstance().goHomePageView(activity, null);
|
|
|
+ activity.finish();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }).create();
|
|
|
+ dialog.show();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public static void saveUser(LoginEntity loginEty) {
|
|
|
+ if(loginEty != null && loginEty.getUser() != null) {
|
|
|
+ LoginUser loginUser = new LoginUser();
|
|
|
+ loginUser.setId(loginEty.getUser().getId());
|
|
|
+ loginUser.setToken(loginEty.getToken());
|
|
|
+ loginUser.setServiceName(SheepApp.getInstance().getConnectAddress().getName());
|
|
|
+ loginUser.setNickname(loginEty.getUser().getNickname());
|
|
|
+ MyDbManager.getInstance().saveOrUpdate(loginUser);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public static void addUser(final String token) {
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().getInfo()
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ LogUtil.println("baseMessage onNext "+ JSON.toJSONString(baseMessage));
|
|
|
+ UserEntity userEntity = baseMessage.getData(UserEntity.class);
|
|
|
+ LoginEntity loginEntity = new LoginEntity();
|
|
|
+ loginEntity.setToken(token);
|
|
|
+ loginEntity.setUser(userEntity);
|
|
|
+ saveUser(loginEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ LogUtil.println("baseMessage onError "+JSON.toJSONString(baseMessage));
|
|
|
+ G.showToast(baseMessage);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
public static boolean isTest(){
|
|
|
return BuildConfig.DEBUG || !"sheep".equals(BuildConfig.FLAVOR);
|
|
|
}
|