a
554325746@qq.com
2019-12-25 603cb36a5123e46656b06a5deb8d7ac7ff81307f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.basic.security.fragment;
 
import android.content.Context;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.FrameLayout;
import android.widget.ListView;
 
import com.basic.security.base.BaseApplication;
import com.basic.security.base.BaseFragment;
import com.basic.security.manager.OrgManager;
import com.basic.security.model.ModelAdapter;
import com.basic.security.utils.ResolutionAdaptation;
import com.basic.security.utils.SocketUtil;
 
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;
 
@EFragment
public class OrgFragment extends BaseFragment {
    public static TreeAdapter treeAdapter = new TreeAdapter();
    @ViewById
    public ListView orgs;
 
    public static int getWidestView(Context context, Adapter adapter) {
        int maxWidth = 0;
        View view = null;
        FrameLayout fakeParent = new FrameLayout(context);
        for (int i = 0, count = adapter.getCount(); i < count; i++) {
            view = adapter.getView(i, view, fakeParent);
            view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
            int width = view.getMeasuredWidth();
            if (width > maxWidth) {
                maxWidth = width;
            }
        }
        return maxWidth;
    }
 
    public void findTreeNodeList(TreeAdapter treeAdapter, boolean clearSelectedState, boolean isDialog) {
        afterFindTreeNodeList(treeAdapter);
    }
 
    @UiThread
    public void afterFindTreeNodeList(TreeAdapter treeAdapter) {
        treeAdapter.notifyDataSetChanged();
        ((OrgFragment) this).setOrgWidthInBackground();
    }
 
    public void updateOrgName(String orgId, String orgName) {
        BaseApplication.getApplication().executorService.execute(() -> {
            OrgManager.updateOrgName(orgId, orgName);
            OrgManager.initTreeNodeList(treeAdapter);
            SocketUtil.rpcCallInitTreeNodeList();
            ((OrgFragment) this).setOrgWidthInBackground();
        });
    }
 
    public void deleteOrgById(String orgId) {
        BaseApplication.getApplication().executorService.execute(() -> {
            if (OrgManager.deleteOrgById(orgId)) {
                OrgManager.initTreeNodeList(treeAdapter);
                SocketUtil.rpcCallInitTreeNodeList();
                ((OrgFragment) this).setOrgWidthInBackground();
            }
        });
    }
 
    public void addChildOrg(ModelAdapter parentOrg) {
        BaseApplication.getApplication().executorService.execute(() -> {
            OrgManager.addChildOrg(parentOrg, "");
            OrgManager.initTreeNodeList(treeAdapter);
            SocketUtil.rpcCallInitTreeNodeList();
            ((OrgFragment) this).setOrgWidthInBackground();
        });
    }
 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(ResolutionAdaptation.fragment_org(), container, false);
    }
 
    @UiThread
    public void show() {
        super.show();
        treeAdapter.notifyDataSetChanged();
        setOrgWidthInBackground();
    }
 
    public void setOrgWidthInBackground() {
        if (1 == 1) {
            return;
        }
        BaseApplication.getApplication().executorService.execute(() -> {
            SystemClock.sleep(100);
            setOrgWidth();
        });
    }
 
    @UiThread
    public void setOrgWidth() {
        orgs.getLayoutParams().width = (int) (getWidestView(BaseApplication.getApplication().activity, treeAdapter) * 1.05);
        System1.out.println("OrgFragment.setOrgWidth " + orgs.getLayoutParams().width);
    }
 
    @AfterViews
    public void afterViews() {
        orgs.setAdapter(treeAdapter);
    }
}