Search in sources :

Example 1 with Group

use of org.aisen.weibo.sina.sinasdk.bean.Group in project AisenWeiBo by wangdan.

the class OfflineUtils method toggleOffline.

/**
     * 触发一次离线,如果没有设置过离线分组,优先设置后再离线
     *
     * @param context
     */
public static void toggleOffline(final Activity context) {
    if (!AppContext.isLoggedIn())
        return;
    List<Group> groups = SinaDB.getOfflineSqlite().select(new Extra(AppContext.getAccount().getUser().getIdstr(), null), Group.class);
    if (groups.size() == 0) {
        Logger.d(TAG, "离线分组未设置过");
        new AlertDialogWrapper.Builder(context).setMessage(R.string.offline_none_groups_remind).setNegativeButton(R.string.cancel, null).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                showOfflineGroupsModifyDialog(context, new ArrayList<Group>(), new OnOfflineGroupSetCallback() {

                    @Override
                    public void onChanged(List<Group> newGroups) {
                        // 设置离线分组
                        Logger.d(TAG, "设置离线分组%d个", newGroups.size());
                        if (newGroups.size() > 0) {
                            SinaDB.getOfflineSqlite().insert(getLoggedExtra(null), newGroups);
                            toggleOffline(context);
                        }
                    }
                }, R.string.offline_groups_dialog);
            }
        }).show();
    } else {
        OfflineService.startOffline((ArrayList) groups);
    }
}
Also used : Group(org.aisen.weibo.sina.sinasdk.bean.Group) Extra(org.aisen.android.component.orm.extra.Extra) DialogInterface(android.content.DialogInterface)

Example 2 with Group

use of org.aisen.weibo.sina.sinasdk.bean.Group in project AisenWeiBo by wangdan.

the class OfflineUtils method showOfflineGroupsModifyDialog.

/**
     * 显示一个Dialog,用来设置分组
     *
     * @param activity
     * @param selectedGroups
     * @param callback
     * @param titleId
     */
public static void showOfflineGroupsModifyDialog(Activity activity, List<Group> selectedGroups, final OnOfflineGroupSetCallback callback, int titleId) {
    String[] items = new String[AppContext.getAccount().getGroups().getLists().size()];
    final boolean[] editCheckedItems = new boolean[AppContext.getAccount().getGroups().getLists().size()];
    for (int i = 0; i < AppContext.getAccount().getGroups().getLists().size(); i++) {
        Group group = AppContext.getAccount().getGroups().getLists().get(i);
        items[i] = group.getName();
        editCheckedItems[i] = false;
        for (Group groupSelectd : selectedGroups) {
            if (groupSelectd.getId().equals(group.getIdstr())) {
                editCheckedItems[i] = true;
                break;
            }
        }
    }
    AlertDialogWrapper.Builder dialogBuilder = new AlertDialogWrapper.Builder(activity).setTitle(titleId).setMultiChoiceItems(items, editCheckedItems, new DialogInterface.OnMultiChoiceClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            editCheckedItems[which] = isChecked;
        }
    });
    dialogBuilder.setNegativeButton(R.string.cancel, null).setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // 艹,这个控件这里有bug
            GlobalContext.getInstance().getHandler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    List<Group> groups = new ArrayList<Group>();
                    for (int i = 0; i < editCheckedItems.length; i++) {
                        if (editCheckedItems[i]) {
                            groups.add(AppContext.getAccount().getGroups().getLists().get(i));
                        }
                    }
                    callback.onChanged(groups);
                }
            }, 300);
        }
    }).show();
}
Also used : Group(org.aisen.weibo.sina.sinasdk.bean.Group) DialogInterface(android.content.DialogInterface) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with Group

use of org.aisen.weibo.sina.sinasdk.bean.Group in project AisenWeiBo by wangdan.

the class MainActivity method setupFab.

private void setupFab(Bundle savedInstanceState) {
    ArrayList<Group> groupList = new ArrayList<>();
    // 全部微博
    Group group = new Group();
    group.setName(getString(R.string.timeline_all));
    group.setId("statusesFriendsTimeLine");
    groupList.add(group);
    // 互相关注
    group = new Group();
    group.setName(getString(R.string.timeline_bilateral));
    group.setId("statusesBilateralTimeLine");
    groupList.add(group);
    // 发给我的
    group = new Group();
    group.setName(getString(R.string.timeline_tome));
    group.setId("statusesToMe");
    groupList.add(group);
    // 分组微博
    groupList.addAll(AppContext.getAccount().getGroups().getLists());
    fabGroupsFragment = (FabGroupsFragment) getFragmentManager().findFragmentById(R.id.fragmentFabGroups);
    fabGroupsFragment.resetSelectedPosition();
    fabGroupsFragment.setItems(groupList);
    View sheetView = findViewById(R.id.fab_sheet);
    View overlay = findViewById(R.id.overlay);
    int sheetColor = getResources().getColor(R.color.comm_white);
    int fabColor = MDHelper.resolveColor(this, R.attr.colorPrimary, Color.BLACK);
    materialSheetFab = new MaterialSheetFab(fabBtn, sheetView, overlay, sheetColor, fabColor);
    materialSheetFab.setEventListener(new MaterialSheetFabEventListener() {

        @Override
        public void onShowSheet() {
            super.onShowSheet();
            fabGroupsFragment.show();
            MobclickAgent.onEvent(MainActivity.this, "fab_groups");
        }
    });
    materialSheetFab.showFab();
}
Also used : Group(org.aisen.weibo.sina.sinasdk.bean.Group) MaterialSheetFabEventListener(org.aisen.weibo.sina.ui.widget.sheetfab.MaterialSheetFabEventListener) ArrayList(java.util.ArrayList) MaterialSheetFab(org.aisen.weibo.sina.ui.widget.sheetfab.MaterialSheetFab) View(android.view.View)

Example 4 with Group

use of org.aisen.weibo.sina.sinasdk.bean.Group in project AisenWeiBo by wangdan.

the class ProfileAboutFragment method setGroupList.

public void setGroupList() {
    if (mGroupMemberListed == null)
        return;
    if (groupDialog != null && groupDialog.isShowing())
        groupDialog.dismiss();
    String[] items = new String[AppContext.getAccount().getGroups().getLists().size()];
    final boolean[] checkedItems = new boolean[AppContext.getAccount().getGroups().getLists().size()];
    final boolean[] editCheckedItems = new boolean[AppContext.getAccount().getGroups().getLists().size()];
    for (int i = 0; i < AppContext.getAccount().getGroups().getLists().size(); i++) {
        Group group = AppContext.getAccount().getGroups().getLists().get(i);
        items[i] = group.getName();
        checkedItems[i] = false;
        editCheckedItems[i] = false;
        for (GroupListed groupListed : mGroupMemberListed.getLists()) {
            if (groupListed.getIdstr().equals(group.getIdstr())) {
                checkedItems[i] = true;
                editCheckedItems[i] = true;
                break;
            }
        }
    }
    //        View customTitle = View.inflate(getActivity(), R.layout.lay_group_dialogtitle, null);
    //        customTitle.findViewById(R.id.btnSettings).setOnClickListener(new View.OnClickListener() {
    //
    //            @Override
    //            public void onClick(View v) {
    //                // 设置分组
    //                GroupSortFragment.lanuch(getActivity());
    //            }
    //        });
    AlertDialogWrapper.Builder dialogBuilder = new AlertDialogWrapper.Builder(getActivity()).setTitle(R.string.profile_group_setting).setMultiChoiceItems(items, editCheckedItems, new DialogInterface.OnMultiChoiceClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            editCheckedItems[which] = isChecked;
        }
    });
    try {
        try {
            // 解决有些设备版本较低的BUG,没查这个方法的最低版本要求
            dialogBuilder.setOnDismissListener(new DialogInterface.OnDismissListener() {

                @Override
                public void onDismiss(DialogInterface dialog) {
                    groupDialog = null;
                }
            });
        } catch (NoSuchMethodError e) {
            e.printStackTrace();
        }
    } catch (Exception e) {
    }
    groupDialog = dialogBuilder.setNegativeButton(R.string.cancel, null).setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            new SetGroupTask().execute(checkedItems, editCheckedItems);
        }
    }).show();
}
Also used : Group(org.aisen.weibo.sina.sinasdk.bean.Group) GroupListed(org.aisen.weibo.sina.sinasdk.bean.GroupListed) DialogInterface(android.content.DialogInterface) TaskException(org.aisen.android.network.task.TaskException) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper)

Example 5 with Group

use of org.aisen.weibo.sina.sinasdk.bean.Group in project AisenWeiBo by wangdan.

the class PublishStatusFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.menu_publish, menu);
    // 添加分组
    if (AppContext.getAccount().getGroups() == null || AppContext.getAccount().getGroups().getLists().size() == 0) {
    } else {
        SubMenu subMenu = menu.addSubMenu(R.id.publish, 333, 2, GlobalContext.getInstance().getResources().getString(R.string.group_selected_visiable));
        for (int i = 0; i < AppContext.getAccount().getGroups().getLists().size(); i++) {
            Group group = AppContext.getAccount().getGroups().getLists().get(i);
            subMenu.add(100, i, i, group.getName());
        }
    }
}
Also used : Group(org.aisen.weibo.sina.sinasdk.bean.Group) SubMenu(android.view.SubMenu)

Aggregations

Group (org.aisen.weibo.sina.sinasdk.bean.Group)10 DialogInterface (android.content.DialogInterface)3 ArrayList (java.util.ArrayList)3 Extra (org.aisen.android.component.orm.extra.Extra)3 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)2 SubMenu (android.view.SubMenu)1 View (android.view.View)1 HashMap (java.util.HashMap)1 List (java.util.List)1 TaskException (org.aisen.android.network.task.TaskException)1 GroupListed (org.aisen.weibo.sina.sinasdk.bean.GroupListed)1 Groups (org.aisen.weibo.sina.sinasdk.bean.Groups)1 OfflineUtils (org.aisen.weibo.sina.support.utils.OfflineUtils)1 MaterialSheetFab (org.aisen.weibo.sina.ui.widget.sheetfab.MaterialSheetFab)1 MaterialSheetFabEventListener (org.aisen.weibo.sina.ui.widget.sheetfab.MaterialSheetFabEventListener)1